/* ============ School Team - design system ============ */
:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f8;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border: #e4e8f0;
  --border-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --accent: #0ea5a4;
  --accent-soft: #e6fffb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --warn: #f59e0b;
  --warn-soft: #fffbeb;
  --ok: #10b981;
  --ok-soft: #ecfdf5;
  --info: #3b82f6;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 2px 8px rgba(15,23,42,.05);
  --shadow-lg: 0 12px 34px rgba(15,23,42,.16);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 250px;
  --topbar-h: 62px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #090e1a;
  --surface: #121a2b;
  --surface-2: #172137;
  --surface-3: #1e2a44;
  --text: #e6ebf4;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --border: #253150;
  --border-strong: #33415f;
  --primary: #6366f1;
  --primary-600: #818cf8;
  --primary-soft: #1c2340;
  --accent: #2dd4bf;
  --accent-soft: #10302e;
  --danger: #f87171;
  --danger-soft: #2a1620;
  --warn: #fbbf24;
  --warn-soft: #2a2113;
  --ok: #34d399;
  --ok-soft: #0f2a22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
p { margin: 0; }
.icon { flex: none; vertical-align: middle; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Auth ============ */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
  background: linear-gradient(150deg, #4f46e5 0%, #6d28d9 45%, #0ea5a4 120%);
  color: #fff; padding: 56px 60px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.auth-hero::after { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: rgba(255,255,255,.08); right: -160px; bottom: -180px; }
.auth-hero::before { content: ""; position: absolute; width: 320px; height: 320px; border-radius: 50%; background: rgba(255,255,255,.06); left: -120px; top: -120px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 1.3rem; position: relative; z-index: 1; }
.auth-brand .logo { width: 42px; height: 42px; border-radius: 12px; background: rgba(255,255,255,.2); display: grid; place-items: center; backdrop-filter: blur(4px); }
.auth-hero-body { position: relative; z-index: 1; }
.auth-hero-body h2 { font-size: 2.4rem; line-height: 1.1; margin-bottom: 16px; }
.auth-hero-body p { font-size: 1.05rem; opacity: .9; max-width: 420px; }
.auth-features { display: flex; flex-direction: column; gap: 14px; margin-top: 30px; }
.auth-feature { display: flex; align-items: center; gap: 12px; opacity: .95; }
.auth-feature .tick { width: 26px; height: 26px; border-radius: 8px; background: rgba(255,255,255,.18); display: grid; place-items: center; flex: none; }
.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 1.7rem; margin-bottom: 6px; }
.auth-card .lead { color: var(--text-muted); margin-bottom: 26px; }
.auth-switch { margin-top: 20px; color: var(--text-muted); font-size: .92rem; text-align: center; }
.role-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.role-opt { border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 14px; cursor: pointer; text-align: center; transition: .15s; background: var(--surface); }
.role-opt:hover { border-color: var(--primary); }
.role-opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.role-opt .ttl { font-weight: 600; }
.role-opt .desc { font-size: .78rem; color: var(--text-muted); }
.demo-hint { margin-top: 22px; font-size: .82rem; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 12px 14px; color: var(--text-muted); }
.demo-hint b { color: var(--text); }
.demo-hint .demo-row { cursor: pointer; padding: 2px 0; }
.demo-hint .demo-row:hover { color: var(--primary); }

/* ============ Forms ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea, .search-input input {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-family: inherit; font-size: .95rem; transition: .15s;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field .hint { display: block; font-size: .78rem; color: var(--text-muted); margin-top: 5px; }
.field-check .check, .check { display: flex; align-items: center; gap: 9px; font-size: .9rem; cursor: pointer; font-weight: 500; }
.check input { width: auto; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .87rem; margin-top: 4px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-family: inherit; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: .82rem; }
.btn-lg { padding: 13px 20px; font-size: 1rem; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: none; background: transparent; color: var(--text-muted); cursor: pointer; transition: .15s; position: relative; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ============ App shell ============ */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 18px 20px; font-weight: 800; font-size: 1.12rem; }
.sidebar-brand .logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(140deg, var(--primary), var(--accent)); display: grid; place-items: center; color: #fff; flex: none; }
.sidebar-brand .school { font-size: .72rem; font-weight: 500; color: var(--text-muted); }
.nav { flex: 1; overflow-y: auto; padding: 8px 12px; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 700; padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text-muted);
  font-weight: 600; font-size: .9rem; cursor: pointer; margin-bottom: 2px; transition: .13s; position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-item .nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.user-chip:hover { background: var(--surface-2); }
.user-chip .meta { overflow: hidden; }
.user-chip .nm { font-weight: 600; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .rl { font-size: .72rem; color: var(--text-muted); text-transform: capitalize; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; padding: 0 22px;
}
.topbar .menu-btn { display: none; }
.search-input { flex: 1; max-width: 440px; position: relative; }
.search-input .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-input input { padding-left: 38px; background: var(--surface-2); border-color: transparent; }
.search-input input:focus { background: var(--surface); }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.content { padding: 26px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* dropdowns */
.dropdown { position: absolute; top: calc(100% + 8px); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 300px; z-index: 60; overflow: hidden; animation: pop .15s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.dropdown-head { padding: 13px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.dropdown-head a { font-size: .8rem; font-weight: 600; cursor: pointer; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: flex; gap: 11px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: .1s; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: var(--primary-soft); }
[data-theme="dark"] .notif-item.unread { background: var(--surface-2); }
.notif-item .ni-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-3); color: var(--primary); }
.notif-item .ni-txt { font-size: .85rem; }
.notif-item .ni-time { font-size: .74rem; color: var(--text-faint); margin-top: 2px; }
.menu-list { padding: 6px; }
.menu-list .mi { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--text); }
.menu-list .mi:hover { background: var(--surface-2); }
.menu-list .mi.danger { color: var(--danger); }
.badge-dot { position: absolute; top: 8px; right: 8px; min-width: 16px; height: 16px; background: var(--danger); color: #fff; border-radius: 8px; font-size: .64rem; font-weight: 700; display: grid; place-items: center; padding: 0 4px; border: 2px solid var(--surface); }

/* ============ Cards / layout ============ */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); margin-top: 4px; font-size: .92rem; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 15px; }
.stat .s-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat .s-val { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.stat .s-label { color: var(--text-muted); font-size: .84rem; margin-top: 3px; }
.tint-primary { background: var(--primary-soft); color: var(--primary); }
.tint-accent { background: var(--accent-soft); color: var(--accent); }
.tint-warn { background: var(--warn-soft); color: var(--warn); }
.tint-ok { background: var(--ok-soft); color: var(--ok); }
.tint-danger { background: var(--danger-soft); color: var(--danger); }
.tint-info { background: #e0edff; color: var(--info); }
[data-theme="dark"] .tint-info { background: #16233f; }

/* class card */
.class-card { overflow: hidden; cursor: pointer; transition: .18s; display: flex; flex-direction: column; }
.class-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.class-card .cc-banner { height: 78px; background: linear-gradient(130deg, var(--primary), var(--accent)); position: relative; }
.class-card .cc-banner.v1 { background: linear-gradient(130deg, #6366f1, #ec4899); }
.class-card .cc-banner.v2 { background: linear-gradient(130deg, #0ea5a4, #3b82f6); }
.class-card .cc-banner.v3 { background: linear-gradient(130deg, #f59e0b, #ef4444); }
.class-card .cc-banner.v4 { background: linear-gradient(130deg, #8b5cf6, #6366f1); }
.class-card .cc-subject { position: absolute; top: 12px; left: 14px; background: rgba(255,255,255,.22); color: #fff; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; backdrop-filter: blur(3px); }
.class-card .cc-body { padding: 16px; flex: 1; }
.class-card .cc-title { font-weight: 700; font-size: 1.05rem; }
.class-card .cc-teacher { color: var(--text-muted); font-size: .85rem; margin-top: 3px; }
.class-card .cc-desc { color: var(--text-muted); font-size: .85rem; margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.class-card .cc-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 16px; color: var(--text-muted); font-size: .8rem; }
.class-card .cc-foot span { display: flex; align-items: center; gap: 5px; }

/* list rows */
.list { display: flex; flex-direction: column; gap: 10px; }
.row-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 15px; transition: .15s; }
.row-card.clickable { cursor: pointer; }
.row-card.clickable:hover { border-color: var(--border-strong); transform: translateX(2px); }
.row-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 650; font-weight: 600; }
.row-sub { color: var(--text-muted); font-size: .84rem; margin-top: 2px; }
.row-side { display: flex; align-items: center; gap: 10px; flex: none; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--surface-3); color: var(--text-muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge.info { background: #e0edff; color: var(--info); }
[data-theme="dark"] .badge.info { background: #16233f; }
.badge.muted { background: var(--surface-3); color: var(--text-muted); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-status { text-transform: capitalize; }

/* avatar */
.avatar { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }
.on-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); border: 2px solid var(--surface); position: absolute; bottom: 0; right: 0; }
.av-wrap { position: relative; display: inline-block; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab { padding: 11px 15px; font-weight: 600; font-size: .9rem; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* empty / spinner */
.empty { text-align: center; padding: 54px 20px; color: var(--text-faint); }
.empty .icon { color: var(--border-strong); margin-bottom: 12px; }
.empty p { margin-top: 6px; }
.spinner-wrap { display: grid; place-items: center; padding: 60px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Modal ============ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 100; opacity: 0; transition: opacity .2s; padding: 20px; }
.modal-backdrop.show { opacity: 1; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 500px; max-height: 90vh; display: flex; flex-direction: column; transform: translateY(10px) scale(.98); transition: transform .2s; }
.modal-backdrop.show .modal { transform: none; }
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.confirm-text { color: var(--text-muted); }

/* ============ Toast ============ */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 12px 16px; font-size: .88rem; font-weight: 500; min-width: 240px; max-width: 360px; transform: translateX(120%); transition: transform .3s cubic-bezier(.2,.9,.3,1.2); }
.toast.show { transform: none; }
.toast.success { border-left-color: var(--ok); color: var(--text); }
.toast.success .icon { color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.error .icon { color: var(--danger); }

/* ============ Dashboard ============ */
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
.section-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.section-title a { font-size: .82rem; font-weight: 600; }
.welcome { background: linear-gradient(130deg, var(--primary), var(--accent)); color: #fff; border-radius: var(--radius); padding: 24px 26px; margin-bottom: 22px; position: relative; overflow: hidden; }
.welcome::after { content: ""; position: absolute; width: 240px; height: 240px; border-radius: 50%; background: rgba(255,255,255,.1); right: -70px; top: -90px; }
.welcome h2 { font-size: 1.5rem; position: relative; }
.welcome p { opacity: .9; margin-top: 6px; position: relative; }
.mini-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.mini-item:last-child { border-bottom: none; }
.mini-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.mini-main { flex: 1; min-width: 0; }
.mini-title { font-weight: 600; font-size: .9rem; }
.mini-sub { color: var(--text-muted); font-size: .8rem; margin-top: 2px; }

/* ============ Chat / messages ============ */
.chat-layout { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - var(--topbar-h) - 52px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.thread-list { border-right: 1px solid var(--border); overflow-y: auto; }
.thread-list .tl-head { padding: 16px; font-weight: 700; border-bottom: 1px solid var(--border); }
.thread { display: flex; gap: 11px; padding: 13px 16px; cursor: pointer; border-bottom: 1px solid var(--border); transition: .1s; }
.thread:hover { background: var(--surface-2); }
.thread.active { background: var(--primary-soft); }
.thread .t-main { flex: 1; min-width: 0; }
.thread .t-name { font-weight: 600; font-size: .88rem; display: flex; justify-content: space-between; gap: 6px; }
.thread .t-name .t-time { font-weight: 400; color: var(--text-faint); font-size: .72rem; }
.thread .t-last { color: var(--text-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread .t-unread { background: var(--primary); color: #fff; font-size: .68rem; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.chat-panel { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 11px; font-weight: 700; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
.msg { max-width: 72%; padding: 9px 14px; border-radius: 14px; font-size: .9rem; box-shadow: var(--shadow); }
.msg .m-author { font-size: .74rem; font-weight: 700; margin-bottom: 3px; color: var(--primary); }
.msg .m-time { font-size: .68rem; opacity: .7; margin-top: 3px; text-align: right; }
.msg.them { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.me .m-time { color: rgba(255,255,255,.8); }
.chat-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 22px; background: var(--surface-2); color: var(--text); font-family: inherit; font-size: .92rem; }
.chat-input input:focus { outline: none; border-color: var(--primary); }
.chat-empty { display: grid; place-items: center; height: 100%; color: var(--text-faint); }

/* ============ Comments / discussion ============ */
.comment { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment .c-main { flex: 1; }
.comment .c-head { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.comment .c-head .c-name { font-weight: 700; }
.comment .c-head .c-time { color: var(--text-faint); font-size: .76rem; }
.comment .c-body { margin-top: 5px; font-size: .9rem; }
.comment-box { display: flex; gap: 10px; margin-top: 8px; }
.comment-box textarea { flex: 1; padding: 10px 13px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); resize: none; background: var(--surface); color: var(--text); font-family: inherit; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.data th { text-align: left; padding: 12px 16px; background: var(--surface-2); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
.cell-user { display: flex; align-items: center; gap: 10px; }

/* attendance grid */
.att-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.att-row .att-name { flex: 1; font-weight: 500; }
.seg { display: inline-flex; border: 1.5px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { border: none; background: var(--surface); color: var(--text-muted); padding: 6px 12px; font-size: .8rem; font-weight: 600; cursor: pointer; font-family: inherit; }
.seg button.on-present { background: var(--ok); color: #fff; }
.seg button.on-absent { background: var(--danger); color: #fff; }
.seg button.on-late { background: var(--warn); color: #fff; }
.seg button.on-excused { background: var(--info); color: #fff; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: .74rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; padding: 6px 0; }
.cal-cell { min-height: 96px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 7px; font-size: .8rem; }
.cal-cell.other { opacity: .4; }
.cal-cell.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.cal-cell .cd { font-weight: 700; margin-bottom: 4px; }
.cal-ev { font-size: .72rem; padding: 2px 6px; border-radius: 5px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.cal-ev.assignment { background: var(--warn-soft); color: var(--warn); }
.cal-ev.quiz { background: var(--primary-soft); color: var(--primary); }
.cal-ev.lesson { background: var(--accent-soft); color: var(--accent); }
.cal-ev.event { background: var(--info); color: #fff; }

/* progress bar */
.progress { height: 8px; background: var(--surface-3); border-radius: 5px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 5px; transition: width .5s; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 10px; }
.bars .bar { flex: 1; background: linear-gradient(var(--primary), var(--accent)); border-radius: 5px 5px 0 0; min-height: 3px; position: relative; transition: height .5s; }
.bars .bar span { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: .66rem; color: var(--text-faint); }

/* file chip */
.file-chip { display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.file-chip .fk { font-size: .64rem; font-weight: 800; padding: 3px 6px; border-radius: 5px; background: var(--primary-soft); color: var(--primary); letter-spacing: .03em; }
.file-chip .fn { font-weight: 600; font-size: .86rem; }
.file-chip .fs { color: var(--text-faint); font-size: .76rem; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mt-lg { margin-top: 26px; }
.mb { margin-bottom: 16px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap-gap { display: flex; flex-wrap: wrap; gap: 8px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.code-chip { font-family: ui-monospace, Menlo, monospace; background: var(--surface-3); padding: 2px 8px; border-radius: 6px; font-weight: 700; letter-spacing: .05em; }

/* ============ Responsive ============ */
.backdrop-nav { display: none; }
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .backdrop-nav.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
  .topbar .menu-btn { display: inline-grid; }
  .search-input { display: none; }
  .search-input.mobile-show { display: block; position: absolute; left: 12px; right: 12px; top: 11px; max-width: none; }
  .dash-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-h) - 32px); }
  .chat-layout.show-panel .thread-list { display: none; }
  .chat-layout:not(.show-panel) .chat-panel { display: none; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .content { padding: 18px 15px 90px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat { padding: 14px; }
  .stat .s-val { font-size: 1.35rem; }
  h1 { font-size: 1.3rem; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .cal-cell { min-height: 64px; }
  .cal-ev { font-size: .6rem; }
}

/* accessibility */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
.fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Parent dashboard ---------- */
.dash-children { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.child-card { margin: 0; }

/* ---------- Report card ---------- */
.report-card { max-width: 900px; margin: 0 auto; }
.rc-sheet { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.rc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding-bottom: 14px; border-bottom: 2px solid var(--border); }
.rc-school { font-size: 1.35rem; font-weight: 800; color: var(--primary); letter-spacing: -.01em; }
.rc-title { font-size: .9rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 2px; }
.rc-stamp { font-size: .78rem; white-space: nowrap; }
.rc-student { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
.rc-name { font-size: 1.1rem; font-weight: 700; }
.rc-class { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; background: var(--surface-2); page-break-inside: avoid; }
.rc-class-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.rc-class-head h3 { margin: 0; font-size: 1.02rem; }
.rc-grade { font-size: .9rem; font-weight: 700; white-space: nowrap; }
.rc-tables { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.rc-att { margin-top: 12px; font-size: .82rem; }
.rc-remark { margin-top: 12px; }
.rc-remark-label { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: 6px; }
.rc-remark textarea { width: 100%; resize: vertical; }
.rc-remark-save { margin-top: 8px; }
.rc-remark-text { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.rc-foot { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: .76rem; text-align: center; }
@media (max-width: 700px) { .rc-tables { grid-template-columns: 1fr; } }

@media print {
  body * { visibility: hidden; }
  #report, #report * { visibility: visible; }
  #report { position: absolute; left: 0; top: 0; width: 100%; margin: 0; padding: 0; }
  .no-print { display: none !important; }
  .rc-sheet { box-shadow: none !important; border: none !important; padding: 0 !important; }
  .rc-class { background: #fff !important; break-inside: avoid; }
  .report-card { max-width: none; }
  @page { margin: 14mm; }
}
