/* ============================================================
   School Management Software — design system
   ============================================================ */
:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface-2: #fafbfe;
  --line:      #e3e7f0;
  --line-2:    #eef1f7;
  --ink:       #16192a;
  --ink-2:     #5b6379;
  --ink-3:     #8b93a7;
  --brand:     #3d5afe;
  --brand-ink: #2a3eb1;
  --brand-wash:#eef1ff;
  --ok:        #10a37f;
  --ok-wash:   #e6f6f1;
  --warn:      #d98324;
  --warn-wash: #fdf3e5;
  --bad:       #dc3d4b;
  --bad-wash:  #fdecee;
  --info:      #2f83c5;
  --info-wash: #e8f2fa;
  --purple:    #7c4dff;
  --purple-wash:#f1ebff;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(20,25,45,.05), 0 6px 20px -8px rgba(20,25,45,.14);
  --shadow-lg: 0 20px 50px -16px rgba(20,25,45,.32);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Consolas, "Courier New", monospace;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
table { border-collapse: collapse; width: 100%; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #ccd3e2; border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b3bccf; background-clip: content-box; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--surface);
}
.login-art {
  background: linear-gradient(150deg, #2a3eb1 0%, #3d5afe 45%, #7c4dff 100%);
  color: #fff;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-art::after {
  content: "";
  position: absolute;
  inset: auto -120px -180px auto;
  width: 460px; height: 460px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.login-art h1 { font-size: 34px; line-height: 1.2; max-width: 12ch; }
.login-art p { color: rgba(255,255,255,.82); max-width: 40ch; }
.login-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 17px; }
.login-stats { display: flex; gap: 32px; position: relative; z-index: 1; }
.login-stats b { display: block; font-size: 26px; font-weight: 700; }
.login-stats span { color: rgba(255,255,255,.7); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-card { width: 100%; max-width: 380px; }
.login-card > h2 { font-size: 24px; margin-bottom: 6px; }
.login-card > p.sub { color: var(--ink-2); margin: 0 0 26px; }

.role-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--surface-2); border: 1px solid var(--line); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.role-tabs button {
  border: 0; background: transparent; padding: 9px 4px; border-radius: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; transition: .15s;
}
.role-tabs button:hover { color: var(--ink); }
.role-tabs button.on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

.demo-note { background: var(--brand-wash); border: 1px solid #d9e0ff; border-radius: var(--radius-sm); padding: 11px 13px; font-size: 12.5px; color: var(--brand-ink); margin-bottom: 18px; }
.demo-note code { font-family: var(--mono); background: rgba(255,255,255,.7); padding: 1px 5px; border-radius: 4px; }
.demo-accounts { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.demo-accounts h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin-bottom: 10px; }
.demo-row { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.demo-row:hover { background: var(--surface-2); }
.demo-row .mono { font-family: var(--mono); color: var(--ink-2); }
.demo-row .fill { margin-left: auto; color: var(--brand); font-weight: 600; font-size: 11.5px; }

/* ---------- Form controls ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=email], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--radius-sm); outline: 0; transition: .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(61,90,254,.12); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--ink-3); }
textarea { resize: vertical; min-height: 84px; }
select { appearance: none; background-repeat: no-repeat; background-position: right 9px center; background-size: 15px; padding-right: 30px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
fieldset { border: 0; padding: 0; margin: 0 0 4px; }
fieldset > legend { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); padding: 14px 0 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 13px;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #d3daea; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(.93); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn svg { width: 15px; height: 15px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: #151a2e; color: #aeb6cc; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow: hidden;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 11px; padding: 18px 18px 16px;
  color: #fff; font-weight: 700; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, #3d5afe, #7c4dff); color: #fff;
  display: grid; place-items: center; font-size: 15px;
}
.brand small { display: block; font-size: 10.5px; font-weight: 500; color: #7d87a3; letter-spacing: .04em; }
.nav { flex: 1; overflow-y: auto; padding: 12px 10px 20px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); background-clip: content-box; }
.nav-group { font-size: 10px; text-transform: uppercase; letter-spacing: .09em; color: #5d6683; padding: 14px 10px 6px; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8.5px 10px; border-radius: 8px;
  color: #aeb6cc; font-size: 13.2px; font-weight: 500; margin-bottom: 1px; transition: .13s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: var(--brand); color: #fff; font-weight: 600; box-shadow: 0 4px 14px -4px rgba(61,90,254,.7); }
.nav a svg { width: 16px; height: 16px; flex: none; opacity: .9; }
.nav a .pill { margin-left: auto; background: rgba(255,255,255,.12); color: #fff; font-size: 10.5px; padding: 1px 6px; border-radius: 20px; font-weight: 700; }
.nav a.on .pill { background: rgba(255,255,255,.25); }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.07); }
.who { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; background: rgba(255,255,255,.05); }
.who .nm { min-width: 0; }
.who .nm b { display: block; color: #fff; font-size: 12.8px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .nm span { font-size: 11px; color: #7d87a3; text-transform: capitalize; }
.who .out { margin-left: auto; background: transparent; border: 0; color: #7d87a3; cursor: pointer; padding: 5px; border-radius: 6px; display: grid; }
.who .out:hover { color: #fff; background: rgba(255,255,255,.08); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; background: rgba(244,246,251,.85);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding: 14px 26px; display: flex; align-items: center; gap: 14px;
}
.topbar h1 { font-size: 19px; }
.topbar .crumb { font-size: 12px; color: var(--ink-3); }
.topbar .spacer { flex: 1; }
.topbar .tools { display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; }
.content { padding: 22px 26px 50px; flex: 1; }

/* ---------- Cards / layout ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.card-head h3 { font-size: 14.5px; }
.card-head .sub { font-size: 12px; color: var(--ink-3); }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }

/* ---------- Stat tiles ---------- */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 650; }
.stat .val { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; margin: 5px 0 2px; }
.stat .foot { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; }
.stat .ic { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.stat .ic svg { width: 17px; height: 17px; }
.delta { font-weight: 650; font-size: 12px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { font-size: 13px; }
table.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); font-weight: 700; padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tr.clickable { cursor: pointer; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .muted { color: var(--ink-3); }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.empty svg { width: 36px; height: 36px; opacity: .4; margin-bottom: 10px; }
.empty b { display: block; color: var(--ink-2); font-size: 14px; margin-bottom: 3px; }

/* ---------- Bits ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 650; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok    { background: var(--ok-wash);    color: #0a7d60; border-color: #c7ebe0; }
.badge.warn  { background: var(--warn-wash);  color: #9c5c10; border-color: #f4dfc0; }
.badge.bad   { background: var(--bad-wash);   color: #b32b38; border-color: #f6ccd1; }
.badge.info  { background: var(--info-wash);  color: #1f6396; border-color: #c8e0f2; }
.badge.brand { background: var(--brand-wash); color: var(--brand-ink); border-color: #d6ddff; }
.badge.purple{ background: var(--purple-wash);color: #5a2fd0; border-color: #ddd0ff; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; letter-spacing: -.01em;
}
.avatar.lg { width: 62px; height: 62px; font-size: 21px; }
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .nm b { display: block; font-weight: 600; font-size: 13px; }
.person .nm span { font-size: 11.5px; color: var(--ink-3); }

.bar { height: 6px; border-radius: 4px; background: var(--line-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--brand); }
.meter-row { display: flex; align-items: center; gap: 9px; }
.meter-row .v { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2); min-width: 40px; text-align: right; }

.toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { position: relative; flex: 1; min-width: 190px; max-width: 320px; }
.toolbar .search input { padding-left: 32px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-3); }
.toolbar select { width: auto; min-width: 120px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 9px 13px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 9px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); font-size: 12.5px; }
.kv dd { margin: 0; font-weight: 550; }

.list-item { display: flex; align-items: flex-start; gap: 11px; padding: 11px 16px; border-bottom: 1px solid var(--line-2); }
.list-item:last-child { border-bottom: 0; }
.list-item .t { font-weight: 600; font-size: 13px; }
.list-item .d { font-size: 12px; color: var(--ink-2); }
.list-item .when { margin-left: auto; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(16,20,38,.45); backdrop-filter: blur(2px);
  display: grid; place-items: center; z-index: 200; padding: 24px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column;
  animation: pop .16s ease-out;
}
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1080px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 12px; }
.modal-head h3 { font-size: 16px; }
.modal-head .x { margin-left: auto; background: transparent; border: 0; cursor: pointer; color: var(--ink-3); padding: 5px; border-radius: 6px; display: grid; }
.modal-head .x:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 13px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 9px; justify-content: flex-end; background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 400; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: #1b2036; color: #fff; padding: 11px 15px; border-radius: 9px; font-size: 13px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 9px; animation: slide .2s ease-out;
  max-width: 340px;
}
.toast.ok  { background: #0f7f63; }
.toast.bad { background: #c0313e; }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }

/* ---------- Attendance grid ---------- */
.att-grid td.mark { padding: 5px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 11px; font-size: 12px; font-weight: 650; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button.on.P { background: var(--ok); color: #fff; }
.seg button.on.A { background: var(--bad); color: #fff; }
.seg button.on.L { background: var(--warn); color: #fff; }
.seg button.on.H { background: var(--info); color: #fff; }

/* ---------- Timetable ---------- */
.tt { font-size: 12px; }
.tt th, .tt td { border: 1px solid var(--line); padding: 0; }
.tt th { background: var(--surface-2); padding: 9px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.tt td { height: 62px; vertical-align: top; }
.tt .slot { height: 100%; padding: 7px 8px; display: flex; flex-direction: column; gap: 2px; border-radius: 3px; }
.tt .slot b { font-size: 12px; font-weight: 650; }
.tt .slot span { font-size: 10.5px; opacity: .85; }
.tt .free { color: var(--ink-3); display: grid; place-items: center; height: 100%; font-size: 11px; }
.tt .break td { height: 30px; background: var(--surface-2); text-align: center; color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .08em; }

/* ---------- Receipt / grade card ---------- */
.doc { background: #fff; padding: 30px; font-size: 13px; }
.doc-head { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 18px; }
.doc-head h2 { font-size: 20px; }
.doc-head p { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); }
.doc-title { text-align: center; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; font-size: 12px; background: var(--surface-2); padding: 7px; border-radius: 5px; margin-bottom: 18px; }
.doc table { font-size: 12.5px; margin-bottom: 16px; }
.doc table th { background: var(--surface-2); text-align: left; padding: 8px 10px; border: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.doc table td { padding: 8px 10px; border: 1px solid var(--line); }
.doc .sign { display: flex; justify-content: space-between; margin-top: 44px; font-size: 11.5px; color: var(--ink-2); }
.doc .sign div { border-top: 1px solid var(--ink-3); padding-top: 5px; min-width: 150px; text-align: center; }

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .modal-foot, .modal-head, .toasts, .no-print { display: none !important; }
  .modal-back { position: static; padding: 0; background: none; display: block; }
  .modal { max-width: none; max-height: none; box-shadow: none; border-radius: 0; }
  .modal-body { overflow: visible; padding: 0; }
  .app { display: block; }
  .content { padding: 0; }
}

/* ---------- Charts ---------- */
.chart svg { display: block; width: 100%; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 5px; }
.donut-center b { font-size: 22px; font-weight: 700; display: block; }
.donut-center span { font-size: 11px; color: var(--ink-3); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g3, .g-2-1, .g-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 100; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .menu-toggle { display: grid; }
  .scrim { position: fixed; inset: 0; background: rgba(16,20,38,.4); z-index: 99; }
  .g2, .g4, .form-grid { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
