/**
 * Swissapp · Admin Console — Main Styles
 * Design system aligné sur admin_invoices, palette Swiss Red 🇨🇭
 */

/* =====================================================
   VARIABLES
   ===================================================== */
:root {
    --primary: #D52B1E;
    --primary-dark: #B81F13;
    --primary-light: #E85A4F;
    --primary-50: rgba(213, 43, 30, 0.05);
    --primary-100: rgba(213, 43, 30, 0.10);
    --primary-200: rgba(213, 43, 30, 0.20);

    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --info: #2563eb;
    --purple: #7c3aed;

    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e5e7eb;
    --border-soft: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 30px rgba(15, 23, 42, 0.12);

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    --sidebar-w: 256px;
}

/* =====================================================
   BASE
   ===================================================== */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02','cv03','cv04','cv11';
}

.num, .stat-value, .pack-price { font-variant-numeric: tabular-nums; }
.mono { font-family: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace; font-size: 0.82rem; }

/* =====================================================
   BUTTONS
   ===================================================== */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), #f96256);
    color: white;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 0.85rem;
    box-shadow: 0 4px 4px rgb(0 0 0 / 20%);
    transition: all 0.18s;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    line-height: 1.2;
    white-space: nowrap;
    font-family: inherit;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 6px rgb(0 0 0 / 25%);
}
.btn-primary:disabled { background: #D1D5DB; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
    background-color: #F3F4F6;
    color: var(--text-primary);
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-lg);
    transition: all 0.18s;
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
    line-height: 1.2;
}
.btn-secondary:hover { background-color: #E5E7EB; }

.btn-outline {
    background: white;
    color: var(--text-secondary);
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.18s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
    line-height: 1.2;
}
.btn-outline:hover { color: var(--primary); border-color: var(--primary-light); background: var(--primary-50); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.15s;
    font-family: inherit;
}
.btn-ghost:hover { background: var(--border-soft); color: var(--text-primary); }

.btn-danger {
    background-color: var(--danger);
    color: white;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-lg);
    transition: all 0.18s;
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
    line-height: 1.2;
}
.btn-danger:hover { background-color: #b91c1c; }

.btn-google {
    background: white;
    color: #374151;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
    font-weight: 500;
    border: 2px solid var(--border-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    transition: all 0.2s;
    width: 100%;
    font-size: 0.875rem;
    font-family: inherit;
}
.btn-google:hover { background-color: #f9fafb; border-color: #d1d5db; box-shadow: var(--shadow-md); }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }
.btn-icon {
    width: 32px; height: 32px; padding: 0;
    border: none; background: transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.btn-icon:hover { background: var(--border-soft); color: var(--text-primary); }
.btn-icon.is-danger:hover { background: #fee2e2; color: var(--danger); }

/* =====================================================
   CARDS
   ===================================================== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-bottom: 1rem;
}
.card-header {
    padding: 0.875rem 1.125rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: white;
    flex-wrap: wrap;
}
.card-header h3 {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.card-body { padding: 1.125rem; }
.card-body.is-flush { padding: 0; }

/* =====================================================
   FORMS
   ===================================================== */
.form-group { margin-bottom: 0.875rem; }
.form-label, .form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}
.input-field, select.input-field, textarea.input-field {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 0.85rem;
    transition: all 0.18s;
    background: white;
    color: var(--text-primary);
    font-family: inherit;
}
.input-field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.input-field::placeholder { color: var(--text-muted); }
.input-field:disabled { background: var(--bg-primary); color: var(--text-muted); cursor: not-allowed; }
textarea.input-field { min-height: 80px; resize: vertical; }
select.input-field { cursor: pointer; padding-right: 2rem; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.6rem center; background-size: 1rem;
}

.input-search {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.65rem center;
    background-size: 1rem;
    padding-left: 2.1rem !important;
}

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.75rem; }

/* =====================================================
   APP LAYOUT
   ===================================================== */
.app-shell { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
    flex-shrink: 0;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.125rem 1.125rem 0.875rem;
}
.sidebar-logo {
    width: 38px; height: 38px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800;
    box-shadow: 0 6px 16px rgba(213, 43, 30, 0.3);
}
.sidebar-brand { font-weight: 700; color: var(--text-primary); line-height: 1.1; display: flex; flex-direction: column; }
.sidebar-brand small {
    font-weight: 500; color: var(--text-muted); font-size: 0.7rem;
    text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.5rem; }
.nav-section {
    font-size: 0.66rem; font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.08em;
    padding: 0.875rem 0.875rem 0.375rem;
}
.sidebar-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    transition: all 0.15s ease;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none; background: none; width: 100%;
    text-align: left; font-family: inherit;
}
.sidebar-item i { width: 1.15rem; text-align: center; flex-shrink: 0; font-size: 0.85rem; }
.sidebar-item:hover { background-color: var(--primary-50); color: var(--primary); }
.sidebar-item.active { background-color: var(--primary-100); color: var(--primary); font-weight: 600; }

.sidebar-user {
    border-top: 1px solid var(--border-color);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.sidebar-avatar {
    width: 36px; height: 36px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
    flex-shrink: 0; object-fit: cover;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info b {
    display: block; font-size: 0.85rem; font-weight: 600;
    color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user-info small {
    font-size: 0.72rem; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: block;
}

/* MAIN */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-color);
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); margin: 0; }
.topbar-subtitle { font-size: 0.76rem; color: var(--text-muted); margin-top: -2px; }
.menu-btn {
    display: none;
    background: white; border: 1px solid var(--border-color); color: var(--text-primary);
    width: 36px; height: 36px; border-radius: var(--radius-md);
    cursor: pointer; align-items: center; justify-content: center;
}
.wrap { padding: 1.25rem 1.5rem; max-width: 1440px; margin: 0 auto; width: 100%; }

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 25;
    backdrop-filter: blur(2px);
}

/* =====================================================
   STATS
   ===================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.875rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 1rem 1.125rem;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    transition: all 0.15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 1rem;
}
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.stat-label { font-size: 0.76rem; color: var(--text-muted); font-weight: 500; margin-top: 2px; }
.stat-delta { font-size: 0.7rem; color: var(--success); font-weight: 600; margin-top: 1px; }
.stat-delta.is-down { color: var(--danger); }

/* =====================================================
   TABLES
   ===================================================== */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th, .data-table td {
    padding: 0.7rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
.data-table th {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg-primary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: sticky; top: 0; z-index: 1;
}
.data-table tbody tr { transition: background 0.12s; }
.data-table tbody tr:hover { background: var(--bg-primary); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.is-clickable { cursor: pointer; }
.data-table .col-num { font-variant-numeric: tabular-nums; text-align: right; }
.data-table .col-actions { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.scroll-thin::-webkit-scrollbar { width: 6px; height: 6px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* User row avatar */
.row-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.72rem;
    flex-shrink: 0; object-fit: cover;
}
.row-user { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }
.row-user-meta { min-width: 0; }
.row-user-meta b { display: block; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-user-meta small { display: block; color: var(--text-muted); font-size: 0.74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =====================================================
   STATUS BADGES
   ===================================================== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.18rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--border-soft);
    color: var(--text-secondary);
    white-space: nowrap;
}
.status-success { background: #dcfce7; color: #166534; }
.status-warning { background: #fef3c7; color: #92400e; }
.status-info    { background: #dbeafe; color: #1e40af; }
.status-danger  { background: #fee2e2; color: #991b1b; }
.status-purple  { background: #f3e8ff; color: #6b21a8; }
.status-primary { background: var(--primary-100); color: var(--primary); }
.status-neutral { background: var(--border-soft); color: var(--text-secondary); }

/* =====================================================
   MODALS
   ===================================================== */
.popup-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
    backdrop-filter: blur(6px);
    animation: fadeIn 0.18s ease-out;
}
.popup-container {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 540px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.18s ease-out;
}
.popup-container.popup-lg { max-width: 800px; }
.popup-container.popup-sm { max-width: 400px; }
.popup-container.popup-xl { max-width: 1100px; }
.popup-header {
    padding: 1rem 1.125rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    background: white;
}
.popup-header h2, .popup-header h3 {
    font-size: 1rem; font-weight: 700; color: var(--text-primary); margin: 0;
    display: flex; align-items: center; gap: 0.5rem;
}
.popup-close {
    background: none; border: none; color: var(--text-muted); font-size: 1.4rem;
    cursor: pointer; width: 32px; height: 32px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.popup-close:hover { background: var(--border-soft); color: var(--text-primary); }
.popup-body { padding: 1.125rem; overflow-y: auto; flex: 1; }
.popup-footer {
    padding: 0.85rem 1.125rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    background: var(--bg-primary);
}

/* =====================================================
   LOGIN
   ===================================================== */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, #fef2f2 0%, #ffffff 50%, #fff1f2 100%);
}
.login-card {
    background: white;
    width: 100%;
    max-width: 420px;
    padding: 2.25rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .icon {
    width: 56px; height: 56px;
    border-radius: var(--radius-xl);
    margin: 0 auto 1rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 800;
    color: white;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 12px 30px rgba(213, 43, 30, 0.30);
}
.login-logo h1 { font-size: 1.4rem; font-weight: 800; color: var(--text-primary); margin: 0 0 0.25rem; }
.login-logo p { font-size: 0.875rem; color: var(--text-secondary); margin: 0; }
.login-divider {
    text-align: center; color: var(--text-muted); font-size: 0.72rem;
    margin: 1.25rem 0; position: relative;
    text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
}
.login-divider::before, .login-divider::after {
    content: ''; position: absolute; top: 50%; height: 1px;
    background: var(--border-color); width: calc(50% - 24px);
}
.login-divider::before { left: 0; }
.login-divider::after  { right: 0; }
.login-error {
    background: #fee2e2; color: #991b1b;
    padding: 0.75rem 0.875rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    margin-top: 1rem;
    border: 1px solid #fecaca;
    display: flex; align-items: center; gap: 0.5rem;
}

/* =====================================================
   PAGINATION
   ===================================================== */
.pagination {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1.125rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    font-size: 0.82rem; color: var(--text-secondary);
    flex-wrap: wrap; gap: 0.5rem;
}
.pagination-controls { display: flex; align-items: center; gap: 0.25rem; }
.pagination button {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-md);
    cursor: pointer; font-family: inherit;
    font-size: 0.82rem; font-weight: 500;
    transition: all 0.15s;
}
.pagination button:hover:not(:disabled) {
    color: var(--primary); border-color: var(--primary-light);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .pg-current {
    background: var(--primary-100); color: var(--primary); border-color: var(--primary-100);
    font-weight: 700;
}

/* =====================================================
   TABS (used in users detail, diagnostics)
   ===================================================== */
.tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    padding: 0 1rem;
    background: white;
}
.tab {
    background: none; border: none;
    padding: 0.85rem 0.875rem;
    font-family: inherit;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* =====================================================
   USER DETAIL (inline)
   ===================================================== */
.detail-head {
    display: flex; gap: 1rem; align-items: flex-start;
    padding: 1.125rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}
.detail-avatar {
    width: 64px; height: 64px;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.2rem;
    box-shadow: 0 6px 18px rgba(213, 43, 30, 0.25);
    object-fit: cover;
    flex-shrink: 0;
}
.detail-info { flex: 1; min-width: 200px; }
.detail-info h2 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); margin: 0; }
.detail-info p { font-size: 0.85rem; color: var(--text-muted); margin: 2px 0 6px; }
.detail-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* KV grid for detail view */
.kv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}
.kv {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.625rem 0.875rem;
}
.kv label { display: block; font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.kv b { font-size: 0.92rem; color: var(--text-primary); }

/* =====================================================
   EMPTY / LOADING / SPINNERS
   ===================================================== */
.loading-spinner {
    width: 2.5rem; height: 2.5rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
.spinner-sm {
    width: 1rem; height: 1rem;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 60px; height: 60px;
    margin: 0 auto 0.75rem;
    border-radius: var(--radius-xl);
    background: var(--border-soft);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 1.4rem;
}
.empty-state-title { font-weight: 700; color: var(--text-secondary); margin-bottom: 0.25rem; font-size: 0.92rem; }
.empty-state-desc { font-size: 0.82rem; }

/* =====================================================
   TOAST
   ===================================================== */
.toast-container {
    position: fixed; top: 1rem; right: 1rem;
    z-index: 1000;
    display: flex; flex-direction: column; gap: 0.5rem;
    pointer-events: none;
}
.toast {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem 1rem;
    border-left: 4px solid var(--primary);
    min-width: 240px; max-width: 360px;
    display: flex; align-items: center; gap: 0.625rem;
    animation: slideInRight 0.25s ease-out;
    pointer-events: auto;
    font-size: 0.85rem; font-weight: 500;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info    { border-left-color: var(--info); }
.toast i { font-size: 1rem; flex-shrink: 0; }
.toast.toast-success i { color: var(--success); }
.toast.toast-error i   { color: var(--danger); }
.toast.toast-warning i { color: var(--warning); }
.toast.toast-info i    { color: var(--info); }

/* =====================================================
   DIAGNOSTICS
   ===================================================== */
.diag-error-row {
    border-bottom: 1px solid var(--border-soft);
    padding: 0.75rem 1rem;
    transition: background 0.12s;
}
.diag-error-row:hover { background: var(--bg-primary); }
.diag-error-row.is-open { background: var(--bg-primary); }
.diag-stack {
    background: #0f172a; color: #e2e8f0;
    padding: 0.875rem; border-radius: var(--radius-md);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    white-space: pre-wrap; word-break: break-all;
    overflow-x: auto;
    margin-top: 0.5rem;
}
.diag-context { background: #1e293b; color: #cbd5e1; }

/* =====================================================
   ANIMATIONS
   ===================================================== */
@keyframes fadeIn   { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn  { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.animate-fade-in   { animation: fadeIn 0.4s ease-out forwards; }
.animate-slide-up  { animation: slideUp 0.4s ease-out forwards; }
.animate-scale-in  { animation: scaleIn 0.3s ease-out forwards; }

/* Sidebar / Body scrollbars */
.sidebar-nav::-webkit-scrollbar, .popup-body::-webkit-scrollbar { width: 6px; height: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb, .popup-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 1024px) {
    .menu-btn { display: inline-flex; }
    .sidebar {
        position: fixed; left: 0; top: 0;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 0 0 40px rgba(0,0,0,0.15);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.show { display: block; }
}
@media (max-width: 640px) {
    .wrap { padding: 1rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-card { padding: 0.75rem; gap: 0.5rem; }
    .stat-value { font-size: 1.1rem; }
    .login-card { padding: 1.75rem; }
    .popup-footer { flex-direction: column-reverse; }
    .popup-footer button { width: 100%; }
}
