/* ─── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
    --primary:       #2563eb;
    --primary-dark:  #1d4ed8;
    --primary-light: rgba(37,99,235,0.08);
    --success:       #10b981;
    --warning:       #f59e0b;
    --danger:        #ef4444;
    --info:          #06b6d4;

    --bg-app:        #f0f4f8;
    --bg-panel:      #ffffff;

    --text-primary:  #111827;
    --text-secondary:#374151;
    --text-muted:    #6b7280;

    --border-color:  #e5e7eb;

    --radius-sm:     8px;
    --radius-md:     12px;
    --radius-lg:     16px;

    --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:     0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg:     0 8px 24px rgba(0,0,0,0.12);
    --shadow-xl:     0 16px 48px rgba(0,0,0,0.15);

    --sidebar-width: 260px;
    --header-height: 72px;
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Force light rendering of native controls (select dropdowns, etc.) so option
   text stays visible even when the OS / browser is in dark mode. */
html { font-size: 15px; color-scheme: light; }
body {
    font-family: 'Outfit', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;   /* off-canvas drawer must not create a horizontal scrollbar */
}

/* ─── App Layout ────────────────────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: #1e293b;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    border-right: 1px solid rgba(255,255,255,0.05);
}

.brand-section {
    padding: 24px 20px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}
.brand-logo {
    width: 42px; height: 42px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: white; flex-shrink: 0;
}
.brand-name {
    font-size: 0.95rem; font-weight: 700; color: white; line-height: 1.3;
}
.brand-name span {
    display: block; font-size: 0.75rem; color: rgba(255,255,255,0.5); font-weight: 400; margin-top: 2px;
}

.nav-menu { list-style: none; padding: 12px 10px; flex: 1; }
.nav-item { margin-bottom: 2px; }
.nav-item a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.88rem; font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-item a:hover { background: rgba(255,255,255,0.07); color: white; }
.nav-item.active a { background: var(--primary); color: white; }
.nav-item a i { width: 16px; text-align: center; font-size: 0.9rem; }

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,0.07);
}
.user-profile {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 8px; margin-bottom: 8px;
}
.profile-avatar {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 800; color: white; flex-shrink: 0;
}
.profile-info { overflow: hidden; }
.profile-name { display: block; font-size: 0.85rem; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-role { display: block; font-size: 0.75rem; color: rgba(255,255,255,0.5); }
.btn-logout {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 9px 12px;
    background: rgba(239,68,68,0.1); border: none;
    color: #f87171; border-radius: var(--radius-sm);
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    transition: background 0.15s;
}
.btn-logout:hover { background: rgba(239,68,68,0.2); }

/* ─── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;          /* allow content to shrink instead of overflowing */
    max-width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.page-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 0 32px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky; top: 0;
    z-index: 50;
    gap: 16px;
}
.page-title h1 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.page-title p  { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.content-body { padding: 28px 32px; flex: 1; }

/* ─── Mobile menu toggle (hidden on desktop) ──────────────────────────────────── */
.menu-toggle {
    display: none;
    background: none; border: none; cursor: pointer;
    font-size: 1.4rem; color: var(--text-primary);
    padding: 6px 8px; line-height: 1; flex-shrink: 0;
}
.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    opacity: 0; visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

/* ─── Responsive: phones, tablets & narrow/half-screen windows ─────────────────── */
@media (max-width: 1024px) {
    .menu-toggle { display: inline-flex; align-items: center; }

    /* Content takes the full width — no room reserved for the sidebar. */
    .main-content { margin-left: 0 !important; margin-right: 0 !important; }

    /* Sidebar slides in as an overlay drawer instead of taking layout space. */
    .sidebar {
        width: 82%; max-width: 300px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 0 0 40px rgba(0,0,0,0.45);
    }
    html[dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0) !important; }

    .page-header { padding: 0 16px; height: auto; min-height: var(--header-height); }
    .page-title h1 { font-size: 1rem; }
    .content-body { padding: 18px 14px; }
    .panel { padding: 18px; }

    /* Two-column layouts stack on narrow/half-screen widths. */
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .page-title p { display: none; }
}

/* ─── Mobile robustness ───────────────────────────────────────────────────────
   Two things break phone layouts: (1) inline multi-column grids that a media
   query can't reach, and (2) long unbreakable text (emails/codes/URLs) that
   forces the page wider — which makes mobile Safari zoom out and then NONE of the
   responsive breakpoints match, so every screen renders as squeezed desktop.
   These rules stack all multi-column grids and force long text to wrap. */
@media (max-width: 700px) {
    /* Any inline 2-/3-column grid collapses to ONE column. `!important` beats the
       element's own inline grid-template-columns. */
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:repeat(2"],
    [style*="grid-template-columns: repeat(2"],
    [style*="grid-template-columns:repeat(3"],
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }

    /* Wide data TABLES scroll sideways inside their own box instead of squeezing
       or breaking text character-by-character. Keeping each cell on ONE line makes
       the table hold its natural width, so the horizontal scroll kicks in. */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    .custom-table th, .custom-table td { white-space: nowrap; }

    /* The page itself never scrolls sideways on a phone. */
    body { max-width: 100%; overflow-x: clip; }
}

/* ─── Panel ─────────────────────────────────────────────────────────────────── */
.panel {
    background: var(--bg-panel);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 24px;
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; gap: 12px;
}
.panel-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }

/* ─── Metrics Grid ──────────────────────────────────────────────────────────── */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.metric-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s;
}
.metric-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.metric-icon {
    width: 48px; height: 48px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; flex-shrink: 0;
}
.metric-info { display: flex; flex-direction: column; }
.metric-value { font-size: 1.6rem; font-weight: 800; color: var(--text-primary); line-height: 1.1; }
.metric-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; margin-top: 4px; }

/* ─── Dashboard Grid ─────────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ─── Table ─────────────────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }
.custom-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.custom-table th {
    padding: 10px 14px; background: var(--bg-app);
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.4px; color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.custom-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    vertical-align: middle;
}
.custom-table tbody tr:last-child td { border-bottom: none; }
.custom-table tbody tr:hover { background: var(--bg-app); }

/* ─── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 700;
}
.badge-success   { background: rgba(16,185,129,0.1);  color: var(--success); }
.badge-warning   { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-danger    { background: rgba(239,68,68,0.1);   color: var(--danger); }
.badge-info      { background: rgba(6,182,212,0.1);   color: var(--info); }
.badge-secondary { background: rgba(107,114,128,0.1); color: var(--text-muted); }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; padding: 9px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem; font-weight: 600; cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none; transition: all 0.15s;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-app); color: var(--text-secondary); border-color: var(--border-color); }
.btn-secondary:hover { background: var(--border-color); }
.btn-danger { background: rgba(239,68,68,0.1); color: var(--danger); border-color: rgba(239,68,68,0.2); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { background: #059669; }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.form-control {
    width: 100%; padding: 9px 13px;
    border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    font-size: 0.9rem; color: var(--text-primary); background: var(--bg-panel);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}
.form-control:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.form-control::placeholder { color: var(--text-muted); }
/* Keep <select> option lists readable in every browser/OS theme (incl. RTL/dark). */
select.form-control { color: var(--text-primary); background-color: var(--bg-panel); color-scheme: light; }
.form-control option,
.form-control optgroup { color: #111827; background-color: #ffffff; }

/* ─── Timer ─────────────────────────────────────────────────────────────────── */
.timer-container { text-align: center; padding: 28px 0; }
.timer-digits {
    font-size: 3.5rem; font-weight: 800; font-variant-numeric: tabular-nums;
    color: var(--primary); letter-spacing: 2px; line-height: 1;
    font-family: 'Courier New', monospace;
}
.timer-label { font-size: 0.82rem; color: var(--text-muted); margin-top: 8px; font-weight: 600; }

/* ─── Course Cards ──────────────────────────────────────────────────────────── */
.course-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all 0.2s;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.course-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
    border-color: var(--primary);
}
.course-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.course-code { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; color: var(--primary); background: var(--primary-light); padding: 4px 10px; border-radius: 20px; }
.qr-icon { font-size: 1.4rem; color: var(--text-muted); }
.course-card:hover .qr-icon { color: var(--primary); }
.course-name { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); line-height: 1.4; margin-bottom: 4px; }
.scan-cta {
    margin-top: 16px; padding: 9px 14px;
    background: var(--primary); color: white;
    border-radius: var(--radius-sm);
    font-size: 0.83rem; font-weight: 700;
    text-align: center; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.course-card:hover .scan-cta { background: var(--primary-dark); }

/* ─── Code ───────────────────────────────────────────────────────────────────── */
code {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    background: var(--bg-app);
    padding: 2px 7px;
    border-radius: 4px;
    color: var(--primary);
}
