/* =========================================================
   App shell, sidebar, topbar, dashboard widgets
   ========================================================= */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 260px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); position: fixed; inset: 0 auto 0 0; z-index: 1040; display: flex; flex-direction: column; transition: width .2s ease, transform .25s ease; }
.app-main { flex: 1; min-width: 0; margin-left: 260px; display: flex; flex-direction: column; min-height: 100vh; transition: margin .2s ease; }
.sidebar-brand { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 1.1rem; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-link { display: flex; align-items: center; gap: .7rem; color: #fff; min-width: 0; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--teal); color: #fff; display: grid; place-items: center; font-size: 1.1rem; flex-shrink: 0; }
.brand-logo { height: 36px; max-width: 40px; object-fit: contain; border-radius: 8px; background: #fff; padding: 2px; }
.brand-text { font-weight: 800; font-size: 1rem; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { color: var(--sidebar-text); }
.sidebar-close:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .7rem 1rem; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.12) transparent; }
.nav-group-label { font-size: .72rem; font-weight: 600; color: #7E84B2; padding: 1rem .75rem .35rem; white-space: nowrap; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-item-link { position: relative; display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-radius: 10px; color: var(--sidebar-text); font-weight: 600; font-size: .875rem; white-space: nowrap; }
.nav-item-link i { font-size: 1.05rem; width: 1.25rem; text-align: center; flex-shrink: 0; }
.nav-item-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item-link.active { background: rgba(255,255,255,.09); color: #fff; }
.nav-item-link.active::before { content: ""; position: absolute; left: -.7rem; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #2DD4BF; }
.nav-item-link.active i { color: #5EEAD4; }
.sidebar-foot { padding: .9rem 1.2rem; font-size: .75rem; color: #7E84B2; border-top: 1px solid rgba(255,255,255,.06); white-space: nowrap; overflow: hidden; }
.sidebar-backdrop { display: none; }

/* Collapsed (desktop) */
body.sidebar-collapsed .sidebar { width: 76px; }
body.sidebar-collapsed .app-main { margin-left: 76px; }
body.sidebar-collapsed .brand-text, body.sidebar-collapsed .nav-item-link span, body.sidebar-collapsed .nav-group-label, body.sidebar-collapsed .sidebar-foot { display: none; }
body.sidebar-collapsed .nav-item-link { justify-content: center; padding: .65rem; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
body.sidebar-collapsed .nav-list { margin-bottom: .5rem; }

/* Topbar */
.topbar { height: 68px; background: rgba(255,255,255,.92); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 1020; }
.topbar-title { font-weight: 800; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-search { position: relative; flex: 1; max-width: 420px; }
.topbar-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar-search input { width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: .55rem .9rem .55rem 2.3rem; font-size: .875rem; outline: 0; }
.topbar-search input:focus { border-color: var(--primary-600); background: #fff; box-shadow: 0 0 0 4px rgba(67,56,202,.1); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.notif-dot { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 800; display: grid; place-items: center; border: 2px solid #fff; }
.profile-btn { display: flex; align-items: center; gap: .6rem; border: 0; background: none; padding: .25rem .4rem; border-radius: 12px; color: var(--text); }
.profile-btn:hover { background: var(--surface-2); }
.profile-meta { flex-direction: column; align-items: flex-start; line-height: 1.2; text-align: left; }
.profile-meta strong { font-size: .85rem; }
.profile-meta small { font-size: .72rem; color: var(--muted); }
.notif-menu { width: 360px; max-width: calc(100vw - 1.5rem); padding: 0; overflow: hidden; }
.notif-menu-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: .7rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); cursor: pointer; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: #F7F7FF; }
.notif-item .n-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; }
.notif-item .n-title { font-weight: 700; font-size: .85rem; display: block; }
.notif-item .n-text { font-size: .8rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-item .n-time { font-size: .72rem; color: var(--muted); }
.notif-menu-foot { display: block; text-align: center; padding: .7rem; font-weight: 700; font-size: .85rem; }

.content { padding: 1.5rem 1.75rem 2rem; flex: 1; width: 100%; max-width: 1600px; margin: 0 auto; }
.app-footer { display: flex; justify-content: space-between; padding: 1rem 1.75rem; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--border); }
.flash { margin-bottom: 1rem; }

/* Page header */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: -.02em; }
.page-sub { color: var(--muted); margin: .2rem 0 0; font-size: .875rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---- Dashboard ---- */
.welcome { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.welcome h1 { font-size: 1.6rem; font-weight: 800; margin: 0; letter-spacing: -.02em; }
.welcome p { margin: .25rem 0 0; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: center; box-shadow: var(--shadow-sm); color: inherit; min-width: 0; }
a.stat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); color: inherit; }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; flex-shrink: 0; background: var(--primary-soft); color: var(--primary); }
.stat-icon.teal { background: var(--teal-soft); color: var(--teal); }
.stat-icon.orange { background: var(--warning-soft); color: var(--warning); }
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-icon.blue { background: var(--info-soft); color: var(--info); }
.stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; display: block; }
.stat-value { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; display: block; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-note { font-size: .75rem; color: var(--muted); }

.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 1rem; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; } .span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 230px; }

/* Today rail — the signature element */
.today-rail { background: var(--sidebar); color: #E5E7F7; border-radius: var(--radius-lg); padding: 1.25rem 1.25rem 1.1rem; margin-bottom: 1.25rem; position: relative; overflow: hidden; }
.today-rail-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.today-rail-head h2 { color: #fff; font-size: 1.05rem; margin: 0; font-weight: 800; }
.today-rail-head span { color: var(--sidebar-text); font-size: .8rem; }
.today-rail-head a { color: #5EEAD4; font-weight: 700; font-size: .85rem; }
.rail-track { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .35rem; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; position: relative; }
.rail-item { flex: 0 0 230px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: .8rem .9rem; position: relative; }
.rail-item .rail-time { font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; font-size: .95rem; }
.rail-item .rail-subject { font-weight: 700; color: #E5E7F7; margin-top: .3rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-item .rail-meta { font-size: .78rem; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-item.is-live { border-color: rgba(94,234,212,.55); background: rgba(15,143,131,.18); }
.rail-item.is-done { opacity: .6; }
.rail-item .rail-state { position: absolute; top: .75rem; right: .8rem; font-size: .7rem; font-weight: 800; color: #5EEAD4; }
.rail-item .rail-state.muted { color: var(--sidebar-text); }
.rail-empty { color: var(--sidebar-text); font-size: .9rem; padding: .5rem 0; }
.rail-actions { margin-top: .6rem; display: flex; gap: .4rem; }
.rail-actions .btn { padding: .25rem .6rem; font-size: .75rem; }
.btn-rail { background: #2DD4BF; color: #0B2B33; border: 0; }
.btn-rail:hover { background: #5EEAD4; color: #0B2B33; }
.btn-rail-ghost { background: rgba(255,255,255,.1); color: #fff; border: 0; }
.btn-rail-ghost:hover { background: rgba(255,255,255,.18); color: #fff; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; gap: .75rem; padding: .7rem 1.25rem; border-bottom: 1px solid var(--border); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .ml-main { flex: 1; min-width: 0; }
.mini-list .ml-title { font-weight: 700; font-size: .875rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.mini-list .ml-sub { font-size: .78rem; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-list .ml-end { text-align: right; font-weight: 700; font-size: .85rem; white-space: nowrap; }

/* Profile header */
.profile-hero { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.profile-hero h1 { font-size: 1.4rem; margin: 0; font-weight: 800; }
.profile-hero .meta { color: var(--muted); font-size: .875rem; display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-top: .2rem; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .55rem 1rem; font-size: .875rem; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; font-weight: 600; color: var(--text); word-break: break-word; }
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .8rem .9rem; }
.metric span { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; }
.metric strong { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Attendance marking */
.att-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); }
.att-row:last-child { border-bottom: 0; }
.att-toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-shrink: 0; }
.att-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.att-toggle label { padding: .35rem .7rem; border-radius: 8px; font-weight: 700; font-size: .78rem; cursor: pointer; color: var(--muted); user-select: none; }
.att-toggle input:checked + label.st-present { background: var(--success); color: #fff; }
.att-toggle input:checked + label.st-absent { background: var(--danger); color: #fff; }
.att-toggle input:checked + label.st-late { background: #EA8A0C; color: #fff; }
.att-toggle input:checked + label.st-leave { background: var(--info); color: #fff; }
.att-toggle input:focus-visible + label { outline: 2px solid var(--primary); }
.att-summary { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; font-weight: 600; }
.att-summary span b { font-variant-numeric: tabular-nums; }

/* Calendar heat for attendance */
.att-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.att-cal .d { aspect-ratio: 1; border-radius: 6px; background: #EEF1F6; font-size: .7rem; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.att-cal .d.present { background: var(--success-soft); color: var(--success); }
.att-cal .d.absent { background: var(--danger-soft); color: var(--danger); }
.att-cal .d.late { background: var(--warning-soft); color: var(--warning); }
.att-cal .d.leave { background: var(--info-soft); color: var(--info); }
.att-cal .h { font-size: .68rem; color: var(--muted); text-align: center; font-weight: 700; }

/* Timetable grid */
.tt-wrap { overflow-x: auto; }
.tt-grid { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: .75rem; min-width: 1000px; }
.tt-day h3 { font-size: .85rem; font-weight: 800; margin: 0 0 .5rem; color: var(--text-2); }
.tt-day.is-today h3 { color: var(--primary); }
.tt-slot { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 10px; padding: .6rem .7rem; margin-bottom: .5rem; font-size: .8rem; }
.tt-slot:nth-child(3n) { border-left-color: var(--teal); }
.tt-slot:nth-child(3n+1) { border-left-color: #7C3AED; }
.tt-slot .t { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }
.tt-slot .s { font-weight: 700; color: var(--text-2); display: block; }
.tt-slot .m { color: var(--muted); display: block; }
.tt-empty { color: var(--muted); font-size: .8rem; padding: .6rem; border: 1px dashed var(--border); border-radius: 10px; text-align: center; }

/* Material cards */
.material-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.material-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.material-card .mc-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 1.2rem; background: var(--primary-soft); color: var(--primary); }
.material-card .mc-icon.video { background: var(--danger-soft); color: var(--danger); }
.material-card h3 { font-size: .95rem; margin: 0; font-weight: 800; }
.material-card p { font-size: .8rem; color: var(--muted); margin: 0; flex: 1; }

/* Test taking */
.exam-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.exam-top { position: sticky; top: 68px; z-index: 10; background: var(--bg); padding: .75rem 0; margin-bottom: .5rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.exam-timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.35rem; background: var(--sidebar); color: #fff; padding: .4rem .9rem; border-radius: 10px; display: inline-flex; align-items: center; gap: .5rem; }
.exam-timer.warn { background: var(--danger); }
.q-card .q-num { font-size: .8rem; font-weight: 700; color: var(--muted); }
.q-card .q-text { font-size: 1.1rem; font-weight: 700; margin: .4rem 0 1.1rem; white-space: pre-wrap; }
.q-option { display: flex; align-items: center; gap: .8rem; border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; margin-bottom: .6rem; cursor: pointer; font-weight: 600; background: #fff; }
.q-option:hover { border-color: var(--border-strong); background: var(--surface-2); }
.q-option input { position: absolute; opacity: 0; }
.q-option .q-letter { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border-strong); display: grid; place-items: center; font-weight: 800; flex-shrink: 0; font-size: .85rem; }
.q-option.selected { border-color: var(--primary); background: var(--primary-soft); }
.q-option.selected .q-letter { background: var(--primary); color: #fff; border-color: var(--primary); }
.q-option:focus-within { outline: 2px solid rgba(55,48,163,.35); }
.q-palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.q-palette button { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--border); background: #fff; font-weight: 700; font-size: .8rem; color: var(--text-2); }
.q-palette button.answered { background: var(--success); color: #fff; border-color: var(--success); }
.q-palette button.review { background: #7C3AED; color: #fff; border-color: #7C3AED; }
.q-palette button.answered.review { box-shadow: inset 0 -4px 0 var(--success); }
.q-palette button.current { outline: 2px solid var(--primary); outline-offset: 2px; }
.legend { display: grid; gap: .35rem; font-size: .78rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; }
.answer-review .opt { padding: .45rem .7rem; border-radius: 8px; margin-bottom: .3rem; font-size: .875rem; border: 1px solid transparent; }
.answer-review .opt.correct { background: var(--success-soft); color: var(--success); font-weight: 700; }
.answer-review .opt.wrong { background: var(--danger-soft); color: var(--danger); font-weight: 700; }

/* Child switcher (parent) */
.child-switch { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.child-chip { display: flex; align-items: center; gap: .55rem; padding: .35rem .8rem .35rem .4rem; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--text-2); font-weight: 700; font-size: .85rem; }
.child-chip:hover { border-color: var(--border-strong); color: var(--text); }
.child-chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* Receipt / invoice */
.doc-sheet { max-width: 820px; margin: 0 auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2.25rem; }
.doc-head { display: flex; justify-content: space-between; gap: 1.5rem; border-bottom: 2px solid var(--primary); padding-bottom: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.doc-org { font-weight: 800; font-size: 1.25rem; color: var(--primary); }
.doc-title { font-weight: 800; font-size: 1.4rem; margin: 0; }
.doc-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .9rem; }
.doc-table th { text-align: left; background: var(--surface-2); padding: .6rem .75rem; font-size: .78rem; color: var(--muted); }
.doc-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.doc-total { font-size: 1.2rem; font-weight: 800; }
.paid-stamp { display: inline-block; border: 2px solid var(--success); color: var(--success); font-weight: 800; padding: .2rem .8rem; border-radius: 8px; transform: rotate(-4deg); letter-spacing: .05em; }

/* Settings */
.settings-nav .nav-link { color: var(--text-2); font-weight: 700; border-radius: 10px; padding: .6rem .9rem; display: flex; gap: .6rem; align-items: center; }
.settings-nav .nav-link.active { background: var(--primary-soft); color: var(--primary); }

/* Error pages */
.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 2rem; }
.error-code { font-size: 5rem; font-weight: 800; color: var(--primary); line-height: 1; letter-spacing: -.04em; }
