/* ── Variables ── */
:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #4338ca;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 250px;
    --topbar-height: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition: 150ms ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    display: flex;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}
.sidebar-brand {
    padding: 20px 16px;
    border-bottom: 1px solid var(--gray-700);
}
.sidebar-brand h2 {
    font-size: 1.25rem;
    font-weight: 700;
}
.sidebar-brand span { color: var(--primary-light); }
.sidebar-nav {
    list-style: none;
    padding: 8px 0;
    flex: 1;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-300);
    font-size: .95rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    text-decoration: none;
}
.nav-link:hover {
    background: var(--gray-800);
    color: #fff;
    text-decoration: none;
}
.nav-link.active {
    color: #fff;
    background: rgba(79,70,229,.15);
    border-left-color: var(--primary);
}

/* ── Main ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.top-bar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.top-bar h1 {
    font-size: 1.25rem;
    font-weight: 600;
    flex: 1;
}
.top-bar-actions { display: flex; gap: 8px; }
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-600);
}
.page-content {
    padding: 24px;
    flex: 1;
}

/* ── Cards ── */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

/* ── Stat cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon.blue { background: #dbeafe; color: var(--info); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.yellow { background: #fef3c7; color: var(--warning); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #ede9fe; color: var(--primary); }
.stat-info h4 {
    font-size: .8rem;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.stat-info .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}
th {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-500);
    background: var(--gray-50);
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--gray-50); }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: capitalize;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: .875rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-outline {
    background: #fff;
    border-color: var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-50); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-icon {
    padding: 6px;
    border-radius: 6px;
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--gray-500);
    transition: all var(--transition);
}
.btn-icon:hover { background: var(--gray-100); color: var(--gray-700); }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 4px;
}
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: .9rem;
    color: var(--gray-800);
    background: #fff;
    transition: border-color var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
select.form-control { appearance: auto; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}
.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* ── Search bar ── */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.search-bar .form-control { max-width: 320px; }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
}
.modal-close:hover { color: var(--gray-700); }
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: 6px;
    color: #fff;
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn .25s ease;
    max-width: 380px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Detail sections ── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 24px;
}
.detail-item label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-500);
    font-weight: 600;
}
.detail-item .value {
    font-size: .95rem;
    color: var(--gray-800);
    margin-top: 2px;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-400);
}
.empty-state svg { margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: 1rem; }

/* ── Loading ── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
.loading-center {
    display: flex;
    justify-content: center;
    padding: 48px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tabs ── */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 16px;
    gap: 0;
}
.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    color: var(--gray-500);
    transition: all var(--transition);
}
.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .search-bar .form-control { max-width: none; flex: 1; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ── Auth pages ── */
.sidebar.hidden { display: none; }
.main-content.auth-mode { margin-left: 0; }
.main-content.auth-mode .top-bar { display: none; }

.auth-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--gray-900) 0%, var(--primary-dark) 100%);
    padding: 24px;
    z-index: 9999;
}
.auth-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px 36px 32px;
    width: 100%;
    max-width: 400px;
}
.auth-brand {
    text-align: center;
    margin-bottom: 28px;
}
.auth-brand h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--gray-900);
}
.auth-brand span { color: var(--primary); }
.auth-brand p {
    color: var(--gray-500);
    font-size: .9rem;
    margin-top: 4px;
}
.auth-message {
    background: #fef3c7;
    color: #92400e;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: .85rem;
    margin-bottom: 16px;
    text-align: center;
}
.auth-error {
    color: var(--danger);
    font-size: .85rem;
    margin-top: 10px;
    text-align: center;
}
.auth-footer {
    text-align: center;
    margin-top: 16px;
    font-size: .85rem;
}

/* ── Sidebar footer / user area ── */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--gray-700);
}
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .9rem;
    flex-shrink: 0;
}
.user-details { overflow: hidden; }
.user-name {
    font-size: .9rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    font-size: .75rem;
    color: var(--gray-400);
}
.sidebar-footer .btn-logout {
    width: 100%;
    margin-top: 8px;
    color: #fff;
    background: transparent;
    border: 1px solid var(--gray-600);
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .85rem;
    transition: background var(--transition);
}
.sidebar-footer .btn-logout:hover {
    background: var(--gray-700);
}

/* ── User management table ── */
.user-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
