/* ============================================================
   SchoolAdmin — نظام التحضير الذكي
   Modern green/white design system (RTL)
   ============================================================ */

:root {
    --green-50:  #f0fdf4;
    --green-100: #dcfce7;
    --green-200: #bbf7d0;
    --green-300: #86efac;
    --green-400: #4ade80;
    --green-500: #22c55e;
    --green-600: #16a34a;
    --green-700: #15803d;
    --green-800: #166534;
    --green-900: #14532d;

    --gray-50:  #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    --red: #e11d48;
    --amber: #f59e0b;
    --sky: #0ea5e9;
    --violet: #8b5cf6;

    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow: 0 8px 24px -8px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .04);
    --shadow-lg: 0 24px 48px -16px rgba(16, 24, 40, .24), 0 6px 16px -8px rgba(16, 24, 40, .12);
    --ring: 0 0 0 4px rgba(34, 197, 94, .16);
    --sidebar-w: 264px;
    --transition: .18s cubic-bezier(.4, 0, .2, 1);
    --transition-slow: .3s cubic-bezier(.4, 0, .2, 1);
}

/* Base icon sizing: every inline SVG gets a sane size by default.
   Without this, unstyled SVGs fall back to their intrinsic 300×150 and
   blow up into giant logos. */
.ico,
svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}
.empty-state > svg,
.empty-state .ico {
    width: 54px;
    height: 54px;
}
.auth-logo .ico,
.auth-logo svg {
    width: 38px;
    height: 38px;
}
.sidebar-brand .logo svg,
.sidebar-brand .logo .ico {
    width: 26px;
    height: 26px;
}
.page-head h1 svg,
.page-head > svg,
.card-header h2 svg,
.page-title svg {
    width: 24px;
    height: 24px;
}
.stat-value svg { width: 26px; height: 26px; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: "Cairo", "Segoe UI", Tahoma, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    font-size: 15px;
    line-height: 1.7;
    direction: rtl;
}

a { color: var(--green-700); text-decoration: none; }
a:hover { color: var(--green-800); }

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

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--green-800), var(--green-900));
    color: #fff;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }

.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 20px; border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand .logo {
    width: 42px; height: 42px; border-radius: 12px; background: #fff;
    display: grid; place-items: center; overflow: hidden; flex-shrink: 0;
}
.sidebar-brand .logo img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand .brand-text { min-width: 0; line-height: 1.45; }
.sidebar-brand .brand-text b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand .brand-text span { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { padding: 12px 10px 40px; flex: 1; }
.nav-group-title {
    font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    opacity: .55; padding: 14px 14px 6px;
}
.nav-cat {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.85); font-weight: 600; font-size: 14.5px;
    margin-bottom: 3px; transition: var(--transition); cursor: pointer;
    user-select: none;
}
.nav-cat:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-cat > svg:first-of-type { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 1.9; }
.nav-cat span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-cat-chevron { width: 16px; height: 16px; opacity: .6; transition: transform .2s ease; flex-shrink: 0; }
.nav-cat.open .nav-cat-chevron { transform: rotate(90deg); }
.nav-sub {
    overflow: hidden; max-height: 0; transition: max-height .25s ease;
}
.nav-sub .nav-link { padding-inline-start: 40px; font-size: 13.5px; font-weight: 500; }
.nav-sub .nav-link.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: none; }
.nav-divider { height: 1px; background: rgba(255,255,255,.1); margin: 8px 8px; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.85); font-weight: 600; font-size: 14.5px;
    margin-bottom: 3px; transition: var(--transition); min-width: 0;
}
.nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-link.active { background: #fff; color: var(--green-800); box-shadow: var(--shadow-sm); }
.nav-link .ico { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 1.9; }
.nav-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link .badge-count { margin-inline-start: auto; }

.main {
    flex: 1;
    margin-inline-start: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 64px; background: #fff; border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; gap: 12px; padding: 0 20px;
    position: sticky; top: 0; z-index: 30;
}
.topbar-title { min-width: 0; margin-inline-end: 4px; text-align: end; }
.topbar-title h1 {
    font-size: 17px; font-weight: 800; color: var(--gray-900);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw;
}
.topbar .page-sub { font-size: 12px; color: var(--gray-500); font-weight: 500; white-space: nowrap; }
.topbar-spacer { flex: 1; }

.icon-btn {
    width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--gray-200);
    background: #fff; display: grid; place-items: center; cursor: pointer; color: var(--gray-600);
    position: relative; transition: var(--transition); flex-shrink: 0;
}
.icon-btn:hover { background: var(--gray-50); border-color: var(--green-300); color: var(--green-700); }
.icon-btn .badge-dot {
    position: absolute; top: 5px; inset-inline-end: 5px; min-width: 17px; height: 17px;
    padding: 0 4px; background: var(--red); color: #fff; border-radius: 20px;
    display: grid; place-items: center; font-size: 10px; font-weight: 800; border: 2px solid #fff;
}

.user-chip {
    display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 6px;
    border-radius: 40px; border: 1px solid var(--gray-200); background: #fff; cursor: pointer;
    transition: var(--transition); max-width: 200px;
}
.user-chip:hover { border-color: var(--green-300); background: var(--green-50); }
.user-chip .avatar {
    width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--green-500), var(--green-700));
    color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-chip .uc-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; text-align: start; }
.user-chip .u-name { font-size: 13px; font-weight: 700; color: var(--gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .u-role { font-size: 11px; color: var(--gray-500); white-space: nowrap; }

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: calc(100% + 8px); inset-inline-start: 0;
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); min-width: 230px; padding: 8px; z-index: 60; display: none;
    max-height: 78vh; overflow-y: auto;
}
.dropdown-menu-user { min-width: 260px; }
.dropdown.open .dropdown-menu { display: block; animation: pop .14s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
    color: var(--gray-700); font-weight: 600; font-size: 14px; cursor: pointer; width: 100%;
    border: 0; background: none; text-align: start;
}
.dropdown-item:hover { background: var(--green-50); color: var(--green-800); }
.dropdown-item.danger:hover { background: #fff1f2; color: var(--red); }
.dropdown-divider { height: 1px; background: var(--gray-200); margin: 6px 4px; }
.dropdown-user { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.avatar-lg { width: 46px; height: 46px; font-size: 17px; }
.dropdown-title { font-weight: 800; padding: 10px 12px; border-bottom: 1px solid var(--gray-100); margin-bottom: 6px; color: var(--gray-900); }
.dropdown-empty { padding: 18px 12px; text-align: center; color: var(--gray-400); font-size: 13px; font-weight: 600; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-500); flex-shrink: 0; }
.dropdown-menu-bell { min-width: 280px; }

.content { padding: 24px; flex: 1; min-width: 0; }
.menu-toggle { display: none; }

/* ----------------------------- Cards ----------------------------- */
.card {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-header h2 { font-size: 16px; font-weight: 800; color: var(--gray-900); }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--gray-200); background: var(--gray-50); border-radius: 0 0 var(--radius) var(--radius); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat-card {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 18px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow-sm);
    transition: var(--transition); position: relative; overflow: hidden;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--green-200); }
.stat-card::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--green-500); }
.stat-card.s-amber::before { background: var(--amber); }
.stat-card.s-rose::before { background: var(--red); }
.stat-card.s-sky::before { background: var(--sky); }
.stat-card.s-violet::before { background: var(--violet); }
.stat-icon {
    width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
    background: var(--green-50); color: var(--green-700); flex-shrink: 0;
}
.stat-icon .ico { width: 22px; height: 22px; }
.stat-card.s-amber .stat-icon { background: #fffbeb; color: #b45309; }
.stat-card.s-rose .stat-icon { background: #fff1f2; color: var(--red); }
.stat-card.s-sky .stat-icon { background: #f0f9ff; color: #0369a1; }
.stat-card.s-violet .stat-icon { background: #f5f3ff; color: #6d28d9; }
.stat-value { font-size: 25px; font-weight: 800; line-height: 1.15; color: var(--gray-900); }
.stat-label { font-size: 13px; color: var(--gray-500); font-weight: 600; }

/* ----------------------------- Buttons ----------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: 11px; font-weight: 700; font-size: 14px;
    border: 1px solid transparent; cursor: pointer; transition: var(--transition);
    font-family: inherit; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); color: #fff; box-shadow: 0 6px 16px rgba(22,163,74,.3); }
.btn-outline { background: #fff; color: var(--green-700); border-color: var(--green-300); }
.btn-outline:hover { background: var(--green-50); }
.btn-ghost { background: transparent; color: var(--gray-700); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: #fff; color: var(--red); border-color: #fecdd3; }
.btn-danger:hover { background: #fff1f2; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { padding: 13px 26px; font-size: 15.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon {
    width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--gray-200); background: #fff;
    display: grid; place-items: center; cursor: pointer; color: var(--gray-600); transition: var(--transition);
}
.btn-icon:hover { border-color: var(--green-400); color: var(--green-700); background: var(--green-50); }
.btn-icon.btn-danger:hover { border-color: #fecdd3; color: var(--red); background: #fff1f2; }
.btn-icon .ico { width: 16px; height: 16px; }

.card-footer-floating {
    position: sticky; bottom: 12px; z-index: 20; background: rgba(255,255,255,.95);
    backdrop-filter: blur(6px); border: 1px solid var(--gray-200); border-radius: 14px;
    box-shadow: var(--shadow); padding: 12px 16px; display: flex; gap: 10px; margin-top: 8px;
}

/* ----------------------------- Forms ----------------------------- */
.form-row { margin-bottom: 16px; }
.form-label { display: block; font-weight: 700; font-size: 13.5px; color: var(--gray-700); margin-bottom: 7px; line-height: 1.6; }
.form-label .req { color: var(--red); }
.form-control, .form-select, textarea.form-control {
    width: 100%; padding: 11px 14px; border: 1.5px solid var(--gray-300); border-radius: 11px;
    font-family: inherit; font-size: 14.5px; background: #fff; color: var(--gray-800);
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    outline: none; border-color: var(--green-500); box-shadow: 0 0 0 4px rgba(34,197,94,.14);
}
.form-control::placeholder { color: var(--gray-400); }
textarea.form-control { resize: vertical; min-height: 90px; }
.picker { position: relative; }
.picker-menu {
    position: absolute; z-index: 40; inset-inline: 0; top: calc(100% + 4px);
    max-height: 320px; overflow: auto; background: #fff; border: 1px solid var(--gray-200);
    border-radius: 11px; box-shadow: 0 14px 34px rgba(0,0,0,.16); padding: 6px;
}
.picker-item {
    padding: 9px 12px; border-radius: 8px; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.picker-item:hover, .picker-item.active { background: var(--green-50); }
.picker-item .pclass { color: var(--gray-500); font-size: 12px; white-space: nowrap; }
.picker-empty { padding: 12px; color: var(--gray-500); text-align: center; font-size: 13px; }
.pass-eye {
    position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px; border: 0; background: none; cursor: pointer; color: var(--gray-400);
    display: grid; place-items: center; border-radius: 9px;
}
.pass-eye:hover { color: var(--green-700); background: var(--green-50); }
.pass-eye .ico { width: 18px; height: 18px; }
.form-hint { font-size: 12px; color: var(--gray-500); margin-top: 5px; }
.form-error { font-size: 12.5px; color: var(--red); margin-top: 5px; font-weight: 600; }
.form-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
.form-check input { width: 18px; height: 18px; accent-color: var(--green-600); }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 48px; height: 27px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0; background: var(--gray-300); border-radius: 27px; transition: .22s;
}
.switch .slider::before {
    content: ""; position: absolute; height: 21px; width: 21px; inset-inline-start: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: .22s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .slider { background: var(--green-500); }
.switch input:checked + .slider::before { transform: translateX(-21px); }
[dir="rtl"] .switch input:checked + .slider::before { transform: translateX(-21px); }

/* ----------------------------- Tables ----------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data {
    width: 100%; border-collapse: collapse; background: #fff; font-size: 14px;
}
table.data th {
    background: var(--green-50); color: var(--green-800); font-weight: 800; font-size: 13px;
    text-align: start; padding: 13px 14px; white-space: nowrap; border-bottom: 2px solid var(--green-100);
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
table.data tbody tr:hover { background: var(--green-50); }
table.data tbody tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; }
.mini-btn {
    width: 33px; height: 33px; border-radius: 9px; border: 1px solid var(--gray-200); background: #fff;
    display: grid; place-items: center; cursor: pointer; color: var(--gray-600); transition: var(--transition);
}
.mini-btn:hover { border-color: var(--green-400); color: var(--green-700); background: var(--green-50); }
.mini-btn.danger:hover { border-color: #fecdd3; color: var(--red); background: #fff1f2; }

/* ----------------------------- Badges / pills ----------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 30px;
    font-size: 12.5px; font-weight: 700; line-height: 1.6;
}
.badge-green  { background: var(--green-100); color: var(--green-800); }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-rose   { background: #ffe4e6; color: #9f1239; }
.badge-sky    { background: #e0f2fe; color: #075985; }
.badge-violet { background: #ede9fe; color: #5b21b6; }
.badge-slate  { background: var(--gray-200); color: var(--gray-700); }
.badge-emerald { background: var(--green-100); color: var(--green-800); }
.badge-ok   { background: var(--green-100); color: var(--green-800); }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-bad  { background: #ffe4e6; color: #9f1239; }
.badge-vio  { background: #ede9fe; color: #5b21b6; }

.chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; border-radius: 30px;
    background: #fff; border: 1.5px solid var(--gray-200); font-size: 13px; font-weight: 600;
    cursor: pointer; transition: var(--transition); color: var(--gray-600);
}
.chip:hover { border-color: var(--green-300); }
.chip.active { background: var(--green-600); border-color: var(--green-600); color: #fff; }

/* ----------------------------- Alerts ----------------------------- */
.alert {
    display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border-radius: var(--radius);
    margin-bottom: 18px; font-weight: 600; font-size: 14px;
}
.alert-success { background: var(--green-50); color: var(--green-800); border: 1px solid var(--green-200); }
.alert-error   { background: #fff1f2; color: #9f1239; border: 1px solid #fecdd3; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ----------------------------- Login / centered ----------------------------- */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background: radial-gradient(1200px 600px at 80% -10%, var(--green-100), transparent),
                radial-gradient(900px 500px at 0% 110%, var(--green-100), transparent),
                var(--gray-50);
}
.auth-card {
    width: 100%; max-width: 430px; background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg);
    padding: 38px 34px; border: 1px solid var(--gray-200);
}
.auth-logo {
    width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 18px;
    background: linear-gradient(135deg, var(--green-500), var(--green-700));
    display: grid; place-items: center; color: #fff; box-shadow: 0 12px 28px rgba(22,163,74,.35);
}
.auth-title { text-align: center; font-size: 23px; font-weight: 800; color: var(--gray-900); }
.auth-sub { text-align: center; color: var(--gray-500); font-size: 14px; margin-bottom: 26px; }

/* ----------------------------- Misc ----------------------------- */
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 20px; font-weight: 800; color: var(--gray-900); }
.page-head .spacer { flex: 1; }
.muted { color: var(--gray-500); }
.small { font-size: 12.5px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--gray-500); }
.empty-state svg { color: var(--gray-300); margin-bottom: 12px; display: inline-block; }

/* Pagination */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 38px; height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--gray-200);
    background: #fff; display: grid; place-items: center; font-weight: 700; color: var(--gray-700);
}
.pagination .active { background: var(--green-600); color: #fff; border-color: var(--green-600); }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
    padding: 11px 18px; font-weight: 700; color: var(--gray-500); border: none; background: none;
    cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; font-family: inherit;
    font-size: 14.5px; border-radius: 9px 9px 0 0;
}
.tab:hover { color: var(--green-700); background: var(--green-50); }
.tab.active { color: var(--green-700); border-bottom-color: var(--green-600); }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 24px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #fff; border-radius: 18px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; }
.modal-header h3 { font-size: 17px; font-weight: 800; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; gap: 10px; justify-content: flex-start; }

/* Toast — fixed at the top-centre, auto fades */
.toast-box {
    position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 300;
    display: flex; flex-direction: column; gap: 10px; align-items: center;
    pointer-events: none; width: min(92vw, 460px);
}
.toast {
    pointer-events: auto; width: 100%;
    background: var(--gray-900); color: #fff; padding: 13px 18px; border-radius: 12px; font-weight: 600;
    box-shadow: var(--shadow-lg); font-size: 14px; line-height: 1.6;
    opacity: 0; transform: translateY(-14px) scale(.97); transition: opacity .28s ease, transform .28s ease;
    display: flex; align-items: center; gap: 10px; text-align: start;
}
.toast.show { opacity: 1; transform: none; }
.toast.success { background: var(--green-700); }
.toast.error { background: #e11d48; }
.toast.info { background: #1e40af; }
.toast.warning { background: #b45309; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 35; display: none;
}
.sidebar-overlay.open { display: block; }

/* ----------------------------- Print ----------------------------- */
.print-only { display: none; }
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .card { box-shadow: none; border: none; }
    .print-only { display: block; }
    .page-break { page-break-after: always; }
    table.data th { background: #eee !important; }
}

/* ----------------------------- Responsive ----------------------------- */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .sidebar { transform: translateX(100%); }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: none; }
    .main { margin-inline-start: 0; }
    .menu-toggle { display: grid; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .content { padding: 14px; }
    .topbar { padding: 0 10px; height: 58px; gap: 8px; }
    .topbar-title h1 { max-width: 34vw; font-size: 15px; }
    .user-chip { padding: 3px; }
    .user-chip .uc-text { display: none; }
    .user-chip .avatar { width: 34px; height: 34px; }
    .toast-box { width: 94vw; }
}

/* ----------------------------- Mobile refinement ----------------------------- */
@media (max-width: 640px) {
    .content { padding: 12px; }
    .card-body { padding: 15px; }
    .card-header { padding: 13px 15px; }
    .grid { gap: 13px; }
    .page-head { gap: 10px; margin-bottom: 14px; }
    .page-head h1 { font-size: 18px; }
    .page-head .spacer { flex-basis: 100%; height: 0; }
    .page-head > .btn, .page-head .btn-block { width: 100%; }
    .btn { padding: 11px 15px; }
    .form-control, .form-select, textarea.form-control { font-size: 16px; }
    .stat-card { padding: 15px; }
    .table-wrap { -webkit-overflow-scrolling: touch; }
    .modal { width: 96vw; }
    .dropdown-menu { min-width: 180px; }
}

/* ----------------------------- Theme toggle button ----------------------------- */
.theme-toggle .ico { width: 20px; height: 20px; }
.theme-toggle .ico-moon { display: none; }
[data-theme="dark"] .theme-toggle .ico-sun { display: none; }
[data-theme="dark"] .theme-toggle .ico-moon { display: block; }
.auth-theme-toggle {
    position: fixed; top: 18px; inset-inline-end: 18px; z-index: 30;
    width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
    background: #fff; border: 1px solid var(--gray-200); box-shadow: var(--shadow); color: var(--green-700); cursor: pointer;
}
.auth-theme-toggle:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
[data-theme="dark"] .auth-theme-toggle { background: #111a2e; border-color: #1e293b; color: #86efac; }

/* ----------------------------- Smooth page navigation ----------------------------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.content > * { animation: fadeUp .28s ease both; }
.content > *:nth-child(2) { animation-delay: .03s; }
.content > *:nth-child(3) { animation-delay: .06s; }
@media (prefers-reduced-motion: reduce) {
    .content > * { animation: none; }
    * { transition: none !important; }
}
a, .btn { transition: color var(--transition), background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition); }
.card { transition: box-shadow var(--transition), border-color var(--transition); }

/* Progressive cross-document page transitions (Chromium) */
@view-transition { navigation: auto; }
@keyframes fadeOut { to { opacity: 0; } }
::view-transition-old(root) { animation: fadeOut .16s ease both; }
::view-transition-new(root) { animation: fadeUp .26s ease both; }
@media (prefers-reduced-motion: reduce) {
    @view-transition { navigation: none; }
    ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ----------------------------- Dark theme (comfortable) ----------------------------- */
[data-theme="dark"] {
    --gray-50:  #0e1116;
    --gray-100: #161b22;
    --gray-200: #262d36;
    --gray-300: #38414d;
    --gray-400: #6e7a89;
    --gray-500: #8b949e;
    --gray-600: #a9b4c0;
    --gray-700: #c2ccd6;
    --gray-800: #d0d9e2;
    --gray-900: #dbe3ea;
    --green-50:  #0f2417;
    --green-100: #12261b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.55);
    --shadow: 0 6px 18px rgba(0,0,0,.5);
    --shadow-lg: 0 18px 42px rgba(0,0,0,.65);
}
[data-theme="dark"] body { background: #0e1116; color: #c2ccd6; }
[data-theme="dark"] a { color: #7ee2a8; }
[data-theme="dark"] a:hover { color: #9ff0c0; }

[data-theme="dark"] .topbar,
[data-theme="dark"] .card,
[data-theme="dark"] .stat,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .dropdown-menu,
[data-theme="dark"] .modal,
[data-theme="dark"] .auth-card,
[data-theme="dark"] .pagination a,
[data-theme="dark"] .pagination span { background: #161b22; border-color: #262d36; }
[data-theme="dark"] .picker-menu { background: #161b22; border-color: #262d36; }
[data-theme="dark"] .picker-item:hover, [data-theme="dark"] .picker-item.active { background: #13301f; }

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] textarea.form-control,
[data-theme="dark"] table.data,
[data-theme="dark"] .btn-outline,
[data-theme="dark"] .btn-danger,
[data-theme="dark"] .mini-btn,
[data-theme="dark"] .btn-icon,
[data-theme="dark"] .icon-btn,
[data-theme="dark"] .user-chip,
[data-theme="dark"] .chip,
[data-theme="dark"] .seg-btn {
    background: #1b222b;
    border-color: #2b333e;
    color: #c2ccd6;
}
[data-theme="dark"] .form-control::placeholder { color: #6e7a89; }
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus { border-color: #3f8f5f; box-shadow: 0 0 0 3px rgba(74,222,128,.14); }
[data-theme="dark"] .card-footer,
[data-theme="dark"] .btn-ghost:hover,
[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .icon-btn:hover,
[data-theme="dark"] .btn-outline:hover { background: #1f2731; }
[data-theme="dark"] .dropdown-item:hover { color: #7ee2a8; }
[data-theme="dark"] .dropdown-divider,
[data-theme="dark"] .card-header,
[data-theme="dark"] .card-footer,
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer,
[data-theme="dark"] .topbar { border-color: #262d36; }
[data-theme="dark"] table.data th { background: #1b222b; color: #7ee2a8; border-bottom-color: #2b333e; }
[data-theme="dark"] table.data td { border-bottom-color: #232a33; }
[data-theme="dark"] table.data tbody tr:hover { background: #1a212a; }
[data-theme="dark"] .page-head h1,
[data-theme="dark"] .card-header h2,
[data-theme="dark"] .stat-value,
[data-theme="dark"] .topbar-title h1,
[data-theme="dark"] .auth-title,
[data-theme="dark"] .dropdown-title,
[data-theme="dark"] .dropdown-user .u-name { color: #e6edf3; }

[data-theme="dark"] .sidebar { background: linear-gradient(180deg, #05170f, #04120b); }
[data-theme="dark"] .nav-link.active { background: rgba(74,222,128,.14); color: #9ff0c0; }

[data-theme="dark"] .stat-icon { background: #12261b; color: #7ee2a8; }
[data-theme="dark"] .stat-card::before { background: #3f8f5f; }
[data-theme="dark"] .stat-card.s-amber .stat-icon { background: #2a2413; color: #e3c56a; }
[data-theme="dark"] .stat-card.s-rose .stat-icon { background: #2a171b; color: #f0a6b0; }
[data-theme="dark"] .stat-card.s-sky .stat-icon { background: #0f2533; color: #7cc4e8; }
[data-theme="dark"] .stat-card.s-violet .stat-icon { background: #1e1a2e; color: #b9a6ee; }

[data-theme="dark"] .badge-green,
[data-theme="dark"] .badge-emerald,
[data-theme="dark"] .badge-ok { background: #12261b; color: #7ee2a8; }
[data-theme="dark"] .badge-slate { background: #1f2731; color: #adbac7; }
[data-theme="dark"] .badge-amber,
[data-theme="dark"] .badge-warn { background: #2a2413; color: #e3c56a; }
[data-theme="dark"] .badge-rose,
[data-theme="dark"] .badge-bad { background: #2a171b; color: #f0a6b0; }
[data-theme="dark"] .badge-sky { background: #0f2533; color: #7cc4e8; }
[data-theme="dark"] .badge-violet,
[data-theme="dark"] .badge-vio { background: #1e1a2e; color: #b9a6ee; }

[data-theme="dark"] .alert-success { background: #12261b; color: #7ee2a8; border-color: #245035; }
[data-theme="dark"] .alert-error   { background: #2a171b; color: #f0a6b0; border-color: #4d2730; }
[data-theme="dark"] .alert-info    { background: #0f2533; color: #9ecbe6; border-color: #24455a; }
[data-theme="dark"] .alert-warning { background: #2a2413; color: #e3c56a; border-color: #4a3f1e; }

[data-theme="dark"] .auth-wrap { background: radial-gradient(1200px 600px at 80% -10%, #10202f, transparent), radial-gradient(900px 500px at 0% 110%, #10202f, transparent), #0e1116; }
[data-theme="dark"] .toast { background: #1c232c; color: #e6edf3; }
[data-theme="dark"] .card-footer-floating { background: rgba(22,27,34,.96); border-color: #262d36; }

/* ============================================================
   Premium polish — cohesive finish across every screen.
   Uses existing tokens so it adapts to both themes automatically.
   ============================================================ */
html { scroll-behavior: smooth; }

body {
    background:
        radial-gradient(1000px 520px at 100% -10%, var(--green-50), transparent),
        radial-gradient(800px 460px at -10% 110%, var(--green-50), transparent),
        var(--gray-100);
    background-attachment: fixed;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--green-200); color: var(--green-900); }

/* Refined scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb {
    background: var(--gray-300); border-radius: 9px;
    border: 3px solid transparent; background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--gray-400); background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* Accessible focus ring */
.btn:focus-visible, .icon-btn:focus-visible, .btn-icon:focus-visible, .mini-btn:focus-visible,
.nav-link:focus-visible, .nav-cat:focus-visible, .tab:focus-visible, .chip:focus-visible,
a:focus-visible, .form-check input:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

/* Topbar — crisp hairline + soft depth */
.topbar { box-shadow: 0 1px 0 var(--gray-200), 0 6px 18px -14px rgba(16, 24, 40, .35); }
[data-theme="dark"] .topbar { box-shadow: 0 1px 0 #262d36, 0 8px 20px -14px rgba(0, 0, 0, .9); }

/* Cards */
.card { transition: box-shadow var(--transition-slow), border-color var(--transition-slow), transform var(--transition-slow); }
.card-header { background: linear-gradient(180deg, var(--green-50), transparent); }
[data-theme="dark"] .card-header { background: transparent; }
.card-header > .ico { color: var(--green-600); }
.stat-value { letter-spacing: -.02em; }
.page-head h1 { letter-spacing: -.01em; }

/* Buttons — subtle depth + tactile press */
.btn-primary {
    background-image: linear-gradient(180deg, var(--green-500), var(--green-600));
    box-shadow: 0 1px 2px rgba(16, 24, 40, .12), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn-primary:hover {
    background-image: linear-gradient(180deg, var(--green-600), var(--green-700));
    box-shadow: 0 8px 20px -8px rgba(22, 163, 74, .55), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn-primary:active, .btn:active { transform: translateY(1px); }

/* Segmented buttons (attendance status toggle) */
.seg-btn {
    padding: 8px 14px; border-radius: 10px; border: 1.5px solid var(--gray-200); background: #fff;
    font-size: 13.5px; font-weight: 700; cursor: pointer; color: var(--gray-600); font-family: inherit;
    transition: background .15s, border-color .15s, color .15s;
}
.seg { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.seg-btn:hover { border-color: var(--green-300); }

/* Inactive buttons are neutral (gray/white) — only the active one gets its status color */
.seg-btn.st-ok      { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }
.seg-btn.st-warn    { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }
.seg-btn.st-info    { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }
.seg-btn.st-bad     { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }
.seg-btn.st-vio     { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }
.seg-btn.st-neutral { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }

/* Active button shows its status color */
.seg-btn.active.st-ok      { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.seg-btn.active.st-warn    { background: var(--amber); border-color: var(--amber); color: #fff; }
.seg-btn.active.st-info    { background: var(--sky); border-color: var(--sky); color: #fff; }
.seg-btn.active.st-bad     { background: var(--red); border-color: var(--red); color: #fff; }
.seg-btn.active.st-vio     { background: var(--violet); border-color: var(--violet); color: #fff; }
.seg-btn.active.st-neutral { background: var(--gray-700); border-color: var(--gray-700); color: #fff; }

/* Status table on student/teacher views — buttons fit in cells */
.status-table .seg-btn { min-width: 70px; padding: 7px 10px; font-size: 12px; }

/* Dark theme for seg-buttons (non-active) */
[data-theme="dark"] .seg-btn.st-ok      { background: var(--gray-800); color: var(--gray-300); border-color: var(--gray-600); }
[data-theme="dark"] .seg-btn.st-warn    { background: var(--gray-800); color: var(--gray-300); border-color: var(--gray-600); }
[data-theme="dark"] .seg-btn.st-info    { background: var(--gray-800); color: var(--gray-300); border-color: var(--gray-600); }
[data-theme="dark"] .seg-btn.st-bad     { background: var(--gray-800); color: var(--gray-300); border-color: var(--gray-600); }
[data-theme="dark"] .seg-btn.st-vio     { background: var(--gray-800); color: var(--gray-300); border-color: var(--gray-600); }
[data-theme="dark"] .seg-btn.st-neutral { background: var(--gray-800); color: var(--gray-300); border-color: var(--gray-600); }
.btn-outline, .btn-ghost, .btn-danger { box-shadow: var(--shadow-sm); }
.btn-ghost { box-shadow: none; }
.icon-btn:hover, .btn-icon:hover, .mini-btn:hover { transform: translateY(-1px); }

/* Inputs */
.form-control:hover:not(:focus), .form-select:hover:not(:focus) { border-color: var(--gray-400); }
.form-control:focus, .form-select:focus { box-shadow: var(--ring); }

/* Tables */
table.data tbody tr { transition: background var(--transition); }
table.data { border-radius: var(--radius); }

/* Sidebar nav — smoother reveal + active accent */
.nav-cat, .nav-link { transition: background var(--transition), color var(--transition); }
.nav-link.active { position: relative; }
.nav-link.active::after {
    content: ""; position: absolute; inset-inline-end: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 20px; border-radius: 3px; background: var(--green-600);
}
.nav-cat-chevron { transition: transform var(--transition-slow); }

/* Badges */
.badge { letter-spacing: .01em; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35); }
[data-theme="dark"] .badge { box-shadow: none; }

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

/* ============================================================
   Responsive overhaul — phone / tablet / laptop / desktop.
   Loaded LAST so it wins over the earlier media queries above.
   The most important part is neutralising the inline desktop
   widths (min-width / grid-template-columns / flex) that views
   set in style="" — those are what overflow and overlap on phones.
   ============================================================ */

/* Nothing may cause sideways scroll; long Latin IDs wrap. */
html, body { max-width: 100%; overflow-x: hidden; }
.main, .content, .card, .table-wrap { max-width: 100%; min-width: 0; }
img, svg, video, canvas { max-width: 100%; }
.card, td, th, .page-head, .stat-label, .badge,
.nav-cat span, .nav-link span, .topbar-title h1 { overflow-wrap: anywhere; }

/* ---- Laptop / small desktop (<= 1100px): 2-up grids ---- */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- Tablet (<= 860px): sidebar collapses, keep 2-up where sane ---- */
@media (max-width: 860px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .page-head { align-items: flex-start; row-gap: 10px; }
    .page-head h1 { font-size: 19px; }

    /* Tabs scroll sideways instead of squashing/overlapping. */
    .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { flex: 0 0 auto; }

    table.data th, table.data td { padding: 10px 11px; font-size: 13.5px; }

    /* Dropdowns must never fall off the screen edge. */
    .dropdown-menu { max-width: calc(100vw - 20px); }
}

/* ---- Phone (<= 640px) ---- */
@media (max-width: 640px) {
    /* Kill inline desktop constraints — the root cause of overflow. */
    [style*="min-width"] { min-width: 0 !important; }
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

    /* Filter / action rows stack vertically, full width. */
    .card-body > form.flex { flex-direction: column; align-items: stretch; }
    .card-body > form.flex > * { width: 100%; }

    /* Stat cards: two per row, tighter. */
    .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-card { padding: 14px; gap: 12px; }
    .stat-icon { width: 40px; height: 40px; border-radius: 11px; }
    .stat-value { font-size: 21px; }

    /* Page header: title first, then full-width buttons. */
    .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
    .page-head .spacer { display: none; }
    .page-head > .btn, .page-head > .flex { width: 100%; }
    .page-head .flex { flex-wrap: wrap; }
    .page-head .flex > .btn { flex: 1 1 auto; }

    /* Tables: finger-friendly scroll, tighter cells. */
    .table-wrap { border-radius: var(--radius-sm); }
    table.data { font-size: 13px; }
    table.data th, table.data td { padding: 9px 10px; }

    /* Chip checkboxes — larger touch targets on mobile */
    .chip input[type="checkbox"] { width: 20px; height: 20px; margin-inline-end: 4px; }

    /* Editable attendance status cells — stack controls vertically on mobile */
    .status-table td { padding: 6px 8px; }
    .status-table .status-select,
    .status-table .save-status-btn { width: 100%; font-size: 13px; padding: 4px 6px; }
    .status-edit-form { flex-direction: column; gap: 4px; }

    /* Larger, finger-friendly attendance buttons on mobile */
    .seg-btn { padding: 10px 14px; font-size: 14px; min-height: 40px; }

    /* Modal fills the screen better. */
    .modal { width: 94vw; max-height: 88vh; border-radius: 16px; }
    .modal-body { padding: 18px; }

    .toast-box { top: 8px; }
}

/* ---- Very small phones (<= 400px): single column everywhere ---- */
@media (max-width: 400px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .content { padding: 10px; }
    .stat-card { padding: 12px; }
    .topbar-title h1 { font-size: 14px; max-width: 42vw; }
}

