/* ===================================
   Design System — Performance Eval
   Source: DESIGN.md
   =================================== */

/* ===================================
   CSS Variables & Theme Configuration
   =================================== */
:root {
    /* Light mode */
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #f59e0b;
    --accent-hover: #d97706;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --background: #fafafa;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --navbar-height: 64px;
    --sidebar-width: 250px;
    --bottom-nav-height: 60px;
}

[data-theme="dark"] {
    --primary: #f8fafc;
    --primary-light: #e2e8f0;
    --background: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-light: #334155;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

/* ===================================
   Reset & Base Styles
   =================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    text-decoration: none;
    color: var(--accent);
    transition: color 0.2s;
}

a:hover {
    color: var(--accent-hover);
}

button {
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}

ul {
    list-style: none;
}

code, pre {
    font-family: "DM Mono", "SF Mono", Consolas, monospace;
}

/* ===================================
   Typography
   =================================== */
h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
}

h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 6px;
}

p {
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ===================================
   Container
   =================================== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ===================================
   Animations
   =================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

main > * {
    animation: fadeIn 0.3s ease-out;
}

/* ===================================
   Navigation Bar
   =================================== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.navbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 24px;
    max-width: 100%;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-brand a {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    transition: color 0.2s;
}

.navbar-brand a:hover {
    color: var(--accent);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Logo Icon */
.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--accent);
    color: var(--primary);
    border-radius: var(--radius-sm);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--border-light);
    transition: background 0.2s, transform 0.2s;
    font-size: 16px;
}

.theme-toggle:hover {
    background: var(--border);
    transform: scale(1.05);
}

.theme-toggle .theme-icon {
    display: none;
    line-height: 1;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .sun-icon {
    display: block;
}

/* ===================================
   User Dropdown
   =================================== */
.user-dropdown {
    position: relative;
    display: inline-block;
}

.user-avatar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px 4px 4px;
    border-radius: 20px;
    background: var(--border-light);
    cursor: pointer;
    transition: background 0.2s;
}

.user-avatar:hover {
    background: var(--border);
}

.user-avatar-circle {
    width: 28px;
    height: 28px;
    background: var(--accent);
    color: var(--primary);
    border-radius: 50%;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.user-avatar-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.user-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    overflow: hidden;
    z-index: 1001;
}

.user-dropdown.active .user-dropdown-menu {
    display: block;
}

.user-dropdown-item {
    display: block;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
}

.user-dropdown-item:hover {
    background: var(--border-light);
    color: var(--text);
}

.user-dropdown-divider {
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

.role-badge {
    background: var(--primary);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* ===================================
   Sidebar (Desktop)
   =================================== */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

.sidebar-links {
    padding: 16px 0;
}

.sidebar-group-label {
    display: block;
    padding: 20px 24px 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.sidebar-group-items {
    list-style: none;
}

.sidebar-group {
    list-style: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: var(--text-muted);
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
    text-decoration: none;
}

.sidebar-link:hover {
    background: var(--border-light);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--border-light);
    color: var(--accent);
    border-left: 3px solid var(--accent);
    padding-left: 21px;
}

.sidebar-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1;
}

.sidebar-text {
    font-size: 14px;
}

/* ===================================
   Main Content Area
   =================================== */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    min-height: calc(100vh - var(--navbar-height));
    padding: 32px 0;
    transition: margin-left 0.3s ease;
}

.content-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ===================================
   Page Header
   =================================== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}

.page-header-content h1 {
    margin: 0;
}

.page-header-content p {
    margin: 4px 0 0;
    font-size: 14px;
    color: var(--text-muted);
}

/* ===================================
   Buttons
   =================================== */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
    cursor: pointer;
    border: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
}

.btn-primary {
    background: var(--accent);
    color: var(--primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: var(--primary);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--text-muted);
    color: var(--surface);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

/* ===================================
   Form Controls
   =================================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

select.form-control {
    appearance: auto;
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-group input[type="checkbox"] {
    margin-right: 8px;
}

/* ===================================
   Cards
   =================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.card-body {
    /* padding handled by .card container */
}

/* ===================================
   Tables
   =================================== */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.data-table thead {
    background: var(--border-light);
}

table.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

table.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}

table.data-table tbody tr:hover {
    background: var(--border-light);
}

table.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ===================================
   Badges (Status Indicators)
   =================================== */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Role badges */
.badge-admin {
    background: #eff6ff;
    color: #1e40af;
}

.badge-user {
    background: #f1f5f9;
    color: #475569;
}

/* Status badges */
.badge-success,
.badge-active,
.badge-approved {
    background: #f0fdf4;
    color: #166534;
}

.badge-danger,
.badge-inactive,
.badge-declined {
    background: #fef2f2;
    color: #991b1b;
}

.badge-pending {
    background: #fffbeb;
    color: #92400e;
}

.badge-released {
    background: #eff6ff;
    color: #1e40af;
}

/* ===================================
   Alerts
   =================================== */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    border-left: 4px solid;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-success {
    background: #f0fdf4;
    border-color: var(--success);
    color: #166534;
}

.alert-danger {
    background: #fef2f2;
    border-color: var(--danger);
    color: #991b1b;
}

.alert-warning {
    background: #fffbeb;
    border-color: var(--warning);
    color: #92400e;
}

.alert-info {
    background: #eff6ff;
    border-color: var(--info);
    color: #1e40af;
}

/* ===================================
   Flash Messages (Fixed Overlay)
   =================================== */
.flash-messages {
    position: fixed;
    top: calc(var(--navbar-height) + 8px);
    right: 20px;
    z-index: 10000;
    max-width: 350px;
}

.flash-message {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    font-size: 14px;
    border-left: 4px solid transparent;
}

.flash-message.success {
    background: #f0fdf4;
    border-color: var(--success);
    color: #166534;
}

.flash-message.danger {
    background: #fef2f2;
    border-color: var(--danger);
    color: #991b1b;
}

.flash-message.info {
    background: #eff6ff;
    border-color: var(--info);
    color: #1e40af;
}

.flash-message.warning {
    background: #fffbeb;
    border-color: var(--warning);
    color: #92400e;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===================================
   Stats Cards
   =================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ===================================
   Empty State
   =================================== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 14px;
    margin: 0;
}

.empty-state a {
    color: var(--accent);
    font-weight: 500;
}

.empty-state a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ===================================
   Pagination
   =================================== */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 24px;
}

.pagination a,
.pagination span {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    transition: background 0.2s;
}

.pagination a:hover {
    background: var(--border-light);
}

.pagination .active {
    background: var(--accent);
    color: var(--primary);
}

/* ===================================
   Mobile Sidebar
   =================================== */
.mobile-sidebar {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1001;
    padding-top: var(--navbar-height);
    box-shadow: var(--shadow-lg);
}

.mobile-sidebar.active {
    transform: translateX(0);
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 1000;
}

.mobile-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ===================================
   Mobile Menu Toggle (Hamburger)
   =================================== */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    cursor: pointer;
    background: none;
    border: none;
}

.mobile-menu-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: transform 0.3s, opacity 0.3s;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* ===================================
   Login Page
   =================================== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    width: 64px;
    height: 64px;
    background: var(--accent);
    color: var(--primary);
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
}

/* ===================================
   Utilities
   =================================== */
.hidden {
    display: none !important;
}

.no-scroll {
    overflow: hidden !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.mt-4 {
    margin-top: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

.gap-2 {
    gap: 8px;
}

.gap-4 {
    gap: 16px;
}

.flex {
    display: flex;
}

.flex-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

/* ===================================
   Responsive — Mobile (< 768px)
   =================================== */
@media (max-width: 767px) {
    .navbar-container {
        padding: 0 16px;
    }

    .navbar-right .user-avatar-name {
        display: none;
    }

    /* Hide desktop sidebar on mobile */
    .sidebar {
        display: none;
    }

    /* Show mobile sidebar toggle */
    .mobile-menu-toggle {
        display: flex;
    }

    .mobile-sidebar {
        display: block;
    }

    .mobile-overlay {
        display: block;
    }

    .main-content {
        margin-left: 0;
        margin-bottom: 0;
        padding: 24px 0;
    }

    .content-wrapper {
        padding: 0 16px;
    }

    h1 {
        font-size: 24px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 20px;
    }

    table.data-table {
        display: block;
        overflow-x: auto;
    }

    .login-card {
        padding: 24px;
    }
}

/* ===================================
   Responsive — Tablet (768px–1024px)
   =================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
    }

    .sidebar-link {
        padding: 10px 16px;
    }

    .sidebar-link.active {
        padding-left: 13px;
    }
}
