/* =========================================================
   سجل متابعة الفيزياء — نظام التصميم
   مستوحى من أسلوب لوحات Linear / Vercel / Stripe / shadcn
   ========================================================= */

:root,
[data-theme="light"] {
    --brand-50: #eef2ff;
    --brand-100: #e0e7ff;
    --brand-200: #c7d2fe;
    --brand-400: #818cf8;
    --brand-500: #6366f1;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;
    --accent: #06b6d4;
    --accent-2: #8b5cf6;

    --bg: #f6f7fb;
    --bg-grad: radial-gradient(1200px 500px at 100% -10%, rgba(99, 102, 241, .08), transparent 60%),
               radial-gradient(900px 400px at 0% 0%, rgba(6, 182, 212, .06), transparent 60%);
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f5f9;
    --elevated: #ffffff;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --border: #e6e8f0;
    --border-strong: #d5d9e4;
    --ring: rgba(99, 102, 241, .28);

    --success: #10b981;
    --success-bg: #ecfdf5;
    --success-text: #047857;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --danger-text: #b91c1c;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --warning-text: #b45309;

    --sidebar-bg: #0c1024;
    --sidebar-bg-2: #141a3a;
    --sidebar-text: #a5b0cf;
    --sidebar-muted: #6b7597;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --sidebar-border: rgba(255, 255, 255, .07);

    --overlay: rgba(15, 23, 42, .35);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 24px -6px rgba(15, 23, 42, .08);
    --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, .28);
    --radius: 14px;
    --radius-lg: 20px;
    color-scheme: light;
}

[data-theme="dark"] {
    --brand-50: rgba(99, 102, 241, .12);
    --brand-100: rgba(99, 102, 241, .2);
    --brand-200: rgba(129, 140, 248, .35);
    --brand-400: #a5b4fc;
    --brand-500: #818cf8;
    --brand-600: #6366f1;
    --brand-700: #a5b4fc;

    --bg: #070a16;
    --bg-grad: radial-gradient(1200px 500px at 100% -10%, rgba(99, 102, 241, .14), transparent 60%),
               radial-gradient(900px 400px at 0% 0%, rgba(6, 182, 212, .08), transparent 60%);
    --surface: #0f1426;
    --surface-2: #131a30;
    --surface-3: #18203a;
    --elevated: #141b31;
    --text: #e8ebf7;
    --text-2: #c3c9de;
    --muted: #8690b0;
    --border: #1f2842;
    --border-strong: #2b3656;
    --ring: rgba(129, 140, 248, .35);

    --success-bg: rgba(16, 185, 129, .12);
    --success-text: #34d399;
    --danger-bg: rgba(239, 68, 68, .12);
    --danger-text: #f87171;
    --warning-bg: rgba(245, 158, 11, .12);
    --warning-text: #fbbf24;

    --sidebar-bg: #060913;
    --sidebar-bg-2: #0b1022;
    --sidebar-border: rgba(255, 255, 255, .06);

    --overlay: rgba(2, 6, 23, .55);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px -8px rgba(0, 0, 0, .55);
    --shadow-lg: 0 30px 70px -10px rgba(0, 0, 0, .7);
    color-scheme: dark;
}

/* ---------- أساسيات ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg-grad), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font-size: 15px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    transition: background-color .3s, color .3s;
}
a { color: var(--brand-600); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 700; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, monospace; font-size: 13.5px; color: var(--text-2); letter-spacing: .5px; }
::selection { background: var(--brand-200); }
.ic { flex-shrink: 0; }

/* ---------- الهيكل ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 272px; flex-shrink: 0;
    background: linear-gradient(185deg, var(--sidebar-bg-2), var(--sidebar-bg) 45%);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    overflow: hidden;
}
.sidebar::before {
    content: ''; position: absolute; top: -140px; left: -160px; width: 380px; height: 380px;
    background: radial-gradient(circle, rgba(99, 102, 241, .28), transparent 65%); pointer-events: none;
}
.brand { position: relative; display: flex; gap: 12px; align-items: center; padding: 22px 20px 18px; }
.brand-logo {
    width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1, #06b6d4);
    box-shadow: 0 8px 24px -6px rgba(99, 102, 241, .65), inset 0 1px 0 rgba(255,255,255,.25);
}
.brand-title { font-weight: 700; font-size: 15.5px; color: #fff; }
.brand-sub { font-size: 12px; color: var(--sidebar-muted); }
.nav-label { position: relative; padding: 14px 24px 6px; font-size: 11.5px; font-weight: 600; color: var(--sidebar-muted); }
.nav { position: relative; padding: 4px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav a {
    position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px;
    color: var(--sidebar-text); font-weight: 500; font-size: 14.5px; transition: background .18s, color .18s;
}
.nav-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255,255,255,.04); transition: .18s; flex-shrink: 0; }
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a:hover .nav-ic { background: rgba(255,255,255,.09); }
.nav a.active { background: linear-gradient(270deg, rgba(99,102,241,.26), rgba(99,102,241,.04)); color: #fff; font-weight: 600; }
.nav a.active .nav-ic { background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff; box-shadow: 0 6px 16px -4px rgba(99,102,241,.7); }
.nav a.active::after { content: ''; position: absolute; right: -12px; top: 12px; bottom: 12px; width: 3px; border-radius: 4px 0 0 4px; background: #a5b4fc; }
.sidebar-foot { position: relative; padding: 14px; border-top: 1px solid var(--sidebar-border); display: flex; flex-direction: column; gap: 12px; }
.term-chip { display: flex; justify-content: space-between; font-size: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--sidebar-border); padding: 8px 12px; border-radius: 10px; }
.term-chip b { color: #fff; font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 2px; }
.avatar { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #8b5cf6, #6366f1); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-meta { flex: 1; display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.user-meta strong { color: #fff; font-size: 14px; font-weight: 600; }
.user-meta small { color: var(--sidebar-muted); font-size: 12px; }
.logout { color: var(--sidebar-text); width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; transition: .18s; }
.logout:hover { background: rgba(239, 68, 68, .16); color: #fca5a5; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 12px 32px;
    background: color-mix(in srgb, var(--bg) 75%, transparent);
    backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar-title h1 { font-size: 20px; }
.crumb { font-size: 12px; color: var(--muted); }
.crumb i { font-style: normal; opacity: .5; margin: 0 4px; }
.topbar-date { color: var(--muted); font-size: 13px; background: var(--surface); border: 1px solid var(--border); padding: 7px 14px; border-radius: 999px; white-space: nowrap; }
.icon-btn, .theme-toggle {
    width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
    color: var(--text-2); display: grid; place-items: center; cursor: pointer; transition: .2s; flex-shrink: 0; padding: 0;
}
.icon-btn:hover, .theme-toggle:hover { border-color: var(--brand-400); color: var(--brand-600); box-shadow: 0 0 0 4px var(--ring); }
.menu-btn { display: none; }
.theme-toggle { position: relative; overflow: hidden; }
.theme-toggle svg { position: absolute; top: 50%; left: 50%; margin: -9.5px 0 0 -9.5px; transition: transform .5s cubic-bezier(.4, 1.6, .5, 1), opacity .3s; }
.theme-toggle .sun { color: #f59e0b; }
.theme-toggle .moon { color: #6366f1; }
[data-theme="dark"] .theme-toggle .moon { color: #a5b4fc; }
.theme-toggle .moon { transform: translateY(0) rotate(0); opacity: 1; }
.theme-toggle .sun { transform: translateY(28px) rotate(-90deg); opacity: 0; }
[data-theme="dark"] .theme-toggle .sun { transform: translateY(0) rotate(0); opacity: 1; }
[data-theme="dark"] .theme-toggle .moon { transform: translateY(-28px) rotate(90deg); opacity: 0; }

.content { padding: 28px 32px 64px; max-width: 1480px; width: 100%; animation: fadeUp .45s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- البطاقات ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px;
}
.section-title { margin: 32px 0 14px; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.section-title::before { content: ''; width: 4px; height: 18px; border-radius: 4px; background: linear-gradient(#6366f1, #06b6d4); }
.empty { text-align: center; color: var(--muted); padding: 36px 0; margin: 0; }

/* ---------- الأزرار ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
    transition: transform .12s, box-shadow .2s, background .2s, color .2s, border-color .2s, filter .2s;
    user-select: none;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.btn-primary {
    color: #fff; background: linear-gradient(180deg, #6366f1, #4f46e5);
    box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 6px 16px -6px rgba(79, 70, 229, .7);
}
.btn-primary:hover { background: linear-gradient(180deg, #4f46e5, #4338ca); box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 10px 24px -8px rgba(79, 70, 229, .85); }
.btn-success { color: #fff; background: linear-gradient(180deg, #10b981, #059669); box-shadow: 0 6px 16px -6px rgba(16, 185, 129, .6); }
.btn-success:hover { filter: brightness(1.07); }
.btn-danger { color: #fff; background: linear-gradient(180deg, #f43f5e, #e11d48); box-shadow: 0 6px 16px -6px rgba(225, 29, 72, .6); }
.btn-danger:hover { filter: brightness(1.07); }
.btn-outline { border-color: var(--border-strong); background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-outline:hover { border-color: var(--brand-400); color: var(--brand-600); }
.btn-soft { background: var(--brand-50); color: var(--brand-700); }
.btn-soft:hover { background: var(--brand-100); }
.btn-soft-danger { background: var(--danger-bg); color: var(--danger-text); }
.btn-soft-danger:hover { background: #ef4444; color: #fff; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-light { background: rgba(255,255,255,.96); color: #4338ca; box-shadow: 0 8px 20px -8px rgba(0,0,0,.35); }
.btn-light:hover { background: #fff; transform: translateY(-1px); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { height: 48px; padding: 0 26px; font-size: 15.5px; border-radius: 13px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* ---------- النماذج ---------- */
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select {
    font: inherit; font-size: 14.5px; height: 42px; padding: 0 14px; width: 100%;
    border: 1px solid var(--border-strong); border-radius: 11px; background-color: var(--surface); color: var(--text);
    transition: border-color .15s, box-shadow .15s, background-color .3s;
}
select {
    appearance: none; -webkit-appearance: none; padding-left: 36px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: left 14px center;
}
input:hover, select:hover { border-color: var(--brand-200); }
input:focus, select:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--ring); }
input:disabled { background-color: var(--surface-3); color: var(--muted); }
input::placeholder { color: var(--muted); opacity: .7; }
[data-theme="dark"] input[type=date]::-webkit-calendar-picker-indicator { filter: invert(.8); }
label { display: flex; flex-direction: column; gap: 7px; font-weight: 600; font-size: 13.5px; color: var(--text-2); }

.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }

.chip { display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px; background: var(--brand-50); color: var(--brand-700); font-size: 12.5px; font-weight: 600; border: 1px solid var(--brand-100); transition: .15s; white-space: nowrap; }
a.chip:hover { border-color: var(--brand-400); }
.chip-active { background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; border-color: transparent; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: right; }
.table th { background: var(--surface-2); font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.actions { white-space: nowrap; }
.table td.actions > * { vertical-align: middle; margin-left: 4px; }
.card > .table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* ---------- الرئيسية ---------- */
.hero {
    position: relative; overflow: hidden; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    background: linear-gradient(120deg, #312e81 0%, #4f46e5 45%, #0891b2 100%);
    color: #fff; border-radius: var(--radius-lg); padding: 30px 34px; margin-bottom: 22px;
    box-shadow: 0 20px 50px -20px rgba(79, 70, 229, .6);
}
.hero::before, .hero::after { content: ''; position: absolute; width: 380px; height: 140px; left: -70px; top: 0; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.15); pointer-events: none; }
.hero::before { transform: rotate(-25deg); }
.hero::after { transform: rotate(35deg); }
.hero > * { position: relative; }
.hero h2 { font-size: 25px; margin-bottom: 6px; }
.hero p { margin: 0; opacity: .85; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
    position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 20px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .2s, box-shadow .2s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat::after { content: ''; position: absolute; width: 96px; height: 96px; border-radius: 50%; left: -26px; top: -26px; opacity: .14; background: var(--c, #6366f1); }
.stat:nth-child(2) { --c: #06b6d4; }
.stat:nth-child(3) { --c: #10b981; }
.stat:nth-child(4) { --c: #8b5cf6; }
.stat-num { font-size: 32px; font-weight: 700; color: var(--text); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 13.5px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.section-card { margin: 0; display: flex; flex-direction: column; gap: 16px; transition: transform .2s, box-shadow .2s, border-color .2s; }
.section-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--brand-200); }
.section-card-head { display: flex; gap: 14px; align-items: center; }
.section-card-head h4 { font-size: 16.5px; }
.section-card-head small { color: var(--muted); }
.section-badge {
    min-width: 62px; height: 52px; padding: 0 10px; border-radius: 14px; display: grid; place-items: center;
    font-weight: 700; font-size: 15px; color: var(--brand-700); background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
    border: 1px solid var(--brand-100); direction: ltr; white-space: nowrap;
}
.section-card-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 9px 6px; text-align: center; display: flex; flex-direction: column; }
.mini span { font-size: 11.5px; color: var(--muted); }
.mini strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(270deg, #06b6d4, #6366f1); }
.section-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.span-2 { grid-column: span 2; }

/* ---------- شريط الأدوات ---------- */
.toolbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.toolbar label { min-width: 210px; }
.toolbar-info { display: flex; gap: 6px; flex-wrap: wrap; margin-inline-start: auto; }
.past-dates { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: -4px 0 18px; }

/* ---------- رصد الدرجات ---------- */
.grades-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.grades-head h3 { font-size: 17px; margin-bottom: 2px; }
.grades-head small { display: block; max-width: 640px; line-height: 1.7; }
.grades-card { padding-bottom: 0; }
.grades-table th, .grades-table td { text-align: center; padding: 8px; }
.grades-table th { color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; z-index: 2; font-size: 13px; }
.grades-table th small { color: var(--muted); font-weight: 500; }
.grades-table .col-name { text-align: right; min-width: 240px; }
.grades-table .col-no { width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stu-name { font-weight: 600; color: var(--text); }
.row-fill { border: 0; background: none; color: var(--brand-600); font: inherit; font-size: 12px; cursor: pointer; padding: 0; opacity: 0; transition: .15s; }
tr:hover .row-fill, .row-fill:focus { opacity: 1; }
.col-tools button { display: inline-flex; align-items: center; gap: 3px; border: 0; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; margin-top: 5px; padding: 2px 9px; border-radius: 99px; background: var(--brand-50); color: var(--brand-700); transition: .15s; }
.col-tools button:hover { background: #6366f1; color: #fff; }
input.score {
    width: 60px; height: 40px; padding: 0 4px; text-align: center; font-weight: 700; font-size: 16px;
    font-variant-numeric: tabular-nums; border-radius: 10px;
}
input.score.full { background-color: var(--success-bg); border-color: rgba(16, 185, 129, .45); color: var(--success-text); }
input.score.mid { background-color: var(--warning-bg); border-color: rgba(245, 158, 11, .45); color: var(--warning-text); }
input.score.low { background-color: var(--danger-bg); border-color: rgba(239, 68, 68, .4); color: var(--danger-text); }
input.score.invalid { background-color: var(--danger-bg); border-color: #ef4444; box-shadow: 0 0 0 4px rgba(239, 68, 68, .2); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
input.score.wide { width: 80px; }
input.note { min-width: 160px; height: 38px; font-size: 13px; }
.col-total .total { display: inline-block; min-width: 56px; padding: 5px 10px; border-radius: 9px; background: var(--brand-50); color: var(--brand-700); font-weight: 700; font-variant-numeric: tabular-nums; }
.grades-table tfoot td { background: var(--surface-2); font-weight: 700; border-top: 1px solid var(--border-strong); }
.sticky-save {
    position: sticky; bottom: 0; z-index: 5; margin: 18px -22px 0; padding: 14px 22px; display: flex; justify-content: flex-end; align-items: center; gap: 14px;
    background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
#dirty-flag { color: var(--warning-text); font-weight: 600; font-size: 13.5px; }

.term-table td.calc, .term-table th.calc { background: var(--surface-2); color: var(--text-2); font-variant-numeric: tabular-nums; }
.term-table th.entry { background: var(--brand-50); color: var(--brand-700); }
.term-table td.calc .times { display: block; font-size: 11px; color: var(--muted); }
.term-table td.calc strong.works { color: var(--brand-700); }

/* ---------- الطلاب ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-sm); width: fit-content; max-width: 100%; }
.tab { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 11px; background: transparent; border: 0; color: var(--text-2); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; transition: .18s; }
.tab:hover { background: var(--surface-3); color: var(--text); }
.tab.active { background: linear-gradient(180deg, #6366f1, #4f46e5); color: #fff; box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .7); }
.tab .count { background: rgba(127,127,127,.16); border-radius: 99px; padding: 0 8px; font-size: 12px; line-height: 20px; }
.tab.active .count { background: rgba(255,255,255,.22); }
.tab-add { color: var(--brand-600); border: 1px dashed var(--brand-200); }
input.search {
    margin-bottom: 14px; max-width: 380px; padding-right: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l4 4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 14px center;
}

.modal { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal.open { display: flex; animation: fade .2s; }
.modal-box { background: var(--elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 26px; width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-lg); animation: pop .3s cubic-bezier(.2, 1.4, .4, 1); }
.modal-box h3 { font-size: 18px; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

/* ---------- الإعدادات ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form h3 { font-size: 17px; }
.form > p { margin: -8px 0 4px; font-size: 13.5px; }
.form .btn { align-self: flex-start; }
.inline-fields { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }

/* ---------- الكشف الرسمي ---------- */
.sheet { overflow-x: auto; background: var(--surface); padding: 30px; border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid var(--border); }
.official-header { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; align-items: center; border-bottom: 3px double var(--border-strong); padding-bottom: 16px; margin-bottom: 18px; font-weight: 600; min-width: 720px; }
.oh-col div { line-height: 1.95; }
.oh-center { text-align: center; }
.oh-left { text-align: left; }
.oh-title { font-size: 22px; font-weight: 700; color: var(--brand-600); }
.oh-class { font-size: 17px; }
.oh-subject { display: inline-block; background: var(--brand-50); color: var(--brand-700); padding: 0 16px; border-radius: 99px; font-size: 14px; }
.oh-sub { font-size: 13px; color: var(--muted); font-weight: 500; }
.sheet-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sheet-table th, .sheet-table td { border: 1px solid var(--border-strong); padding: 7px 9px; text-align: center; }
.sheet-table th { background: var(--brand-50); color: var(--text); font-size: 13.5px; font-weight: 600; }
.sheet-table td.name { text-align: right; white-space: nowrap; }
.sheet-table td.total { font-weight: 700; background: var(--surface-2); }
.sheet-table td.low { color: var(--danger-text); font-weight: 700; }
.sheet-table td.note { font-size: 12px; min-width: 110px; }
.sheet-table tbody tr:nth-child(even) { background: var(--surface-2); }
.sheet-table tfoot td { background: var(--brand-50); font-weight: 700; }
.sheet-table .group-head { background: var(--brand-100); font-size: 14.5px; }
.sheet-table td.works, .sheet-table td.grand { font-weight: 700; background: var(--brand-50); color: var(--brand-700); }
.sheet-table td.grand { background: var(--brand-100); }
.sheet-table td.miss { color: var(--muted); }
.sheet-legend { margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.sheet-sign { display: flex; justify-content: space-between; margin-top: 32px; font-weight: 600; gap: 20px; flex-wrap: wrap; }

/* ---------- تسجيل الدخول ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; overflow-x: hidden; position: relative; }
.login-bg span { position: fixed; border-radius: 50%; filter: blur(70px); opacity: .45; pointer-events: none; animation: float 14s ease-in-out infinite; }
.login-bg span:nth-child(1) { width: 420px; height: 420px; background: #6366f1; top: -120px; right: -80px; }
.login-bg span:nth-child(2) { width: 360px; height: 360px; background: #06b6d4; bottom: -120px; left: -60px; animation-delay: -5s; }
.login-bg span:nth-child(3) { width: 260px; height: 260px; background: #8b5cf6; top: 40%; left: 40%; opacity: .22; animation-delay: -9s; }
[data-theme="dark"] .login-bg span { opacity: .28; }
@keyframes float { 50% { transform: translate(30px, -30px) scale(1.08); } }
.login-top { position: fixed; top: 18px; left: 18px; z-index: 5; }
.login-wrap { position: relative; display: grid; grid-template-columns: 1.05fr 1fr; width: 100%; max-width: 960px; background: var(--surface); border: 1px solid var(--border); border-radius: 26px; overflow: hidden; box-shadow: var(--shadow-lg); animation: pop .5s cubic-bezier(.2, 1.3, .4, 1); }
.login-side { position: relative; overflow: hidden; background: linear-gradient(150deg, #1e1b4b, #4338ca 55%, #0891b2); color: #fff; padding: 46px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.login-side .atom { color: rgba(255,255,255,.85); width: 110px; animation: spin 26s linear infinite; margin-bottom: 8px; }
.login-side h2 { font-size: 27px; }
.login-side p { margin: 0; opacity: .8; line-height: 1.9; font-size: 14.5px; }
.login-year { align-self: flex-start; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2); padding: 3px 14px; border-radius: 99px; font-size: 13px; }
.login-features { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 9px; font-size: 14px; }
.login-features li { display: flex; align-items: center; gap: 10px; opacity: .92; }
.login-features li::before { content: ''; width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; background: rgba(255,255,255,.18) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='white' stroke-width='2.4'%3E%3Cpath d='M2 6.5l2.5 2.5L10 3.5'/%3E%3C/svg%3E") center no-repeat; }
.login-card { padding: 48px 44px; display: flex; flex-direction: column; gap: 16px; justify-content: center; }
.login-logo { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #6366f1, #06b6d4); box-shadow: 0 12px 28px -8px rgba(99,102,241,.7); }
.login-card h1 { font-size: 26px; }
.login-card > p { margin: -8px 0 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- الإشعار السريع ---------- */
.toast { position: fixed; top: 84px; left: 50%; transform: translate(-50%, -10px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 200; box-shadow: var(--shadow-lg); white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =========================================================
   شاشة التحميل + نوافذ النتيجة والتأكيد (خلفية ضبابية)
   ========================================================= */
.overlay {
    position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px;
    background: var(--overlay);
    backdrop-filter: blur(10px) saturate(140%); -webkit-backdrop-filter: blur(10px) saturate(140%);
    opacity: 0; visibility: hidden; transition: opacity .28s ease, visibility .28s;
}
.overlay.show { opacity: 1; visibility: visible; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.92) translateY(12px); } }

.loader-box { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 36px 52px; border-radius: 26px; background: var(--elevated); border: 1px solid var(--border); box-shadow: var(--shadow-lg); transform: scale(.92); transition: transform .35s cubic-bezier(.2, 1.4, .4, 1); }
.overlay.show .loader-box { transform: scale(1); }
.spinner { position: relative; width: 116px; height: 116px; }
.ring {
    position: absolute; inset: 0; border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0 25%, #06b6d4 45%, #6366f1 70%, #8b5cf6 100%);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
            mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    animation: spin 1.1s linear infinite;
}
.ring-2 {
    inset: 12px; opacity: .6; animation-duration: 1.8s; animation-direction: reverse;
    background: conic-gradient(from 90deg, transparent 0 45%, #a5b4fc 80%, #06b6d4 100%);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
            mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
}
.orbit-wrap { position: absolute; inset: 26px; animation: spin 5s linear infinite; color: var(--brand-400); }
.orbit { width: 100%; height: 100%; opacity: .5; display: block; }
.nucleus { position: absolute; top: 50%; left: 50%; width: 12px; height: 12px; margin: -6px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, #6366f1 70%); box-shadow: 0 0 14px #6366f1; animation: pulse 1.2s ease-in-out infinite; }
.electron { position: absolute; top: 50%; left: 50%; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: #06b6d4; box-shadow: 0 0 10px #06b6d4; }
.e1 { animation: orbit1 1.3s linear infinite; }
.e2 { animation: orbit2 1.3s linear infinite; background: #8b5cf6; box-shadow: 0 0 10px #8b5cf6; }
.e3 { animation: orbit3 1.3s linear infinite; background: #f472b6; box-shadow: 0 0 10px #f472b6; }
@keyframes orbit1 { from { transform: rotate(0deg) translateX(28px); } to { transform: rotate(360deg) translateX(28px); } }
@keyframes orbit2 { from { transform: rotate(120deg) translateX(28px); } to { transform: rotate(480deg) translateX(28px); } }
@keyframes orbit3 { from { transform: rotate(240deg) translateX(28px); } to { transform: rotate(600deg) translateX(28px); } }
@keyframes pulse { 50% { transform: scale(1.35); } }
.loader-text { font-weight: 700; font-size: 16px; color: var(--text); }
.loader-dots { display: flex; gap: 6px; margin-top: -8px; }
.loader-dots i { width: 7px; height: 7px; border-radius: 50%; background: #6366f1; animation: dot 1s ease-in-out infinite; }
.loader-dots i:nth-child(2) { animation-delay: .15s; background: #06b6d4; }
.loader-dots i:nth-child(3) { animation-delay: .3s; background: #8b5cf6; }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-6px); opacity: 1; } }

.result-box {
    --tone: #10b981; --tone-bg: var(--success-bg); --tone-text: var(--success-text);
    position: relative; overflow: hidden; width: 100%; max-width: 420px; text-align: center;
    background: var(--elevated); border: 1px solid var(--border); border-radius: 26px; padding: 34px 30px 26px;
    box-shadow: var(--shadow-lg); transform: scale(.85) translateY(20px); opacity: 0;
    transition: transform .45s cubic-bezier(.2, 1.5, .4, 1), opacity .25s;
}
.result-box::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 130px; background: radial-gradient(260px 130px at 50% 0, var(--tone), transparent 75%); opacity: .18; pointer-events: none; }
.overlay.show .result-box { transform: none; opacity: 1; }
.result-box.is-error { --tone: #ef4444; --tone-bg: var(--danger-bg); --tone-text: var(--danger-text); }
.result-box.is-warning { --tone: #f59e0b; --tone-bg: var(--warning-bg); --tone-text: var(--warning-text); }
.result-icon { position: relative; width: 86px; height: 86px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; background: var(--tone-bg); }
.result-icon::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--tone); opacity: 0; }
.overlay.show .result-icon::after { animation: ripple 1.2s .25s ease-out; }
@keyframes ripple { from { opacity: .6; transform: scale(.8); } to { opacity: 0; transform: scale(1.4); } }
.result-icon svg { display: none; width: 60px; height: 60px; fill: none; stroke: var(--tone); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.result-box .i-success { display: block; }
.result-box.is-error .i-success, .result-box.is-warning .i-success { display: none; }
.result-box.is-error .i-error, .result-box.is-warning .i-warning { display: block; }
.result-icon circle { stroke-dasharray: 150; stroke-dashoffset: 150; opacity: .35; }
.result-icon path { stroke-dasharray: 60; stroke-dashoffset: 60; }
.overlay.show .result-icon circle { animation: draw .6s .1s ease forwards; }
.overlay.show .result-icon path { animation: draw .45s .5s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.result-badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 99px; background: var(--tone-bg); color: var(--tone-text); margin-bottom: 10px; }
.result-badge:empty { display: none; }
.result-title { position: relative; font-size: 20px; margin-bottom: 8px; }
.result-msg { position: relative; color: var(--muted); font-size: 14.5px; margin-bottom: 22px; line-height: 1.8; }
.result-msg p { margin: 0 0 4px; }
.result-box [data-close-result] { background: var(--tone); box-shadow: 0 8px 20px -8px var(--tone); }
.result-box [data-close-result]:hover { background: var(--tone); filter: brightness(1.08); }
.result-timer { position: absolute; bottom: 0; left: 0; right: 0; height: 4px; }
.result-timer span { display: block; height: 100%; width: 100%; background: var(--tone); transform-origin: right; transform: scaleX(0); }
.result-box.auto .result-timer span { animation: timer var(--dur, 3.5s) linear forwards; }
@keyframes timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- الشاشات الصغيرة ---------- */
@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
    .sidebar { position: fixed; right: 0; transform: translateX(100%); z-index: 60; transition: transform .3s cubic-bezier(.4, 0, .2, 1); }
    .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
    .sidebar-backdrop { position: fixed; inset: 0; z-index: 55; background: var(--overlay); backdrop-filter: blur(4px); opacity: 0; visibility: hidden; transition: .3s; }
    .sidebar-backdrop.show { opacity: 1; visibility: visible; }
    .menu-btn { display: grid; }
    .content { padding: 18px 16px 48px; }
    .topbar { padding: 10px 16px; }
    .topbar-date, .crumb { display: none; }
    .grid-2, .login-wrap { grid-template-columns: 1fr; }
    .login-side { display: none; }
    .login-card { padding: 36px 26px; }
    .toolbar label { min-width: 0; flex: 1 1 100%; }
    .toolbar-info { margin-inline-start: 0; }
    .hero { padding: 24px; }
}
@media (max-width: 520px) {
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-num { font-size: 26px; }
    .section-card-actions { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- الطباعة (دائماً فاتح) ---------- */
@media print {
    :root, [data-theme="dark"], [data-theme="light"] {
        --surface: #fff; --surface-2: #f8fafc; --text: #000; --text-2: #111; --muted: #444;
        --border: #333; --border-strong: #333; --brand-50: #e0e7ff; --brand-100: #c7d2fe; --brand-600: #1e1b4b; --brand-700: #1e1b4b;
    }
    @page { size: A4 landscape; margin: 10mm; }
    body { background: #fff !important; color: #000; font-size: 12px; }
    .no-print, .sidebar, .topbar, .alert, .toast, .overlay, .sheet-legend, .sidebar-backdrop { display: none !important; }
    .content { padding: 0; animation: none; max-width: none; }
    .sheet { box-shadow: none; border: 0; padding: 0; overflow: visible; background: #fff; }
    .sheet-table th, .sheet-table td { padding: 3px 6px; }
    .sheet-table th, .sheet-table td.works, .sheet-table td.grand, .sheet-table .group-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .official-header { grid-template-columns: 1fr 1.2fr 1fr !important; min-width: 0; }
    .oh-left { text-align: left !important; }
}
