﻿@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700&family=BioRhyme:wght@400;500;600;700&family=Spline+Sans+Mono:wght@400;500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@500;600;700&display=swap');

:root {
  --display: "Bricolage Grotesque", Georgia, serif;
  --body: "BioRhyme", system-ui, serif;
  --mono: "Spline Sans Mono", ui-monospace, monospace;
  --hand: "Caveat", "Segoe Script", "Comic Sans MS", cursive;

  --linen: #ffede1;
  --ivory: #f9fbf2;
  --light-cyan: #d7f9ff;
  --baby-blue-ice: #afcbff;
  --prussian-blue: #0e1c36;

  --bg: var(--linen);
  --surface: var(--ivory);
  --surface-2: color-mix(in srgb, var(--light-cyan) 45%, var(--ivory));
  --ink: var(--prussian-blue);
  --ink-soft: color-mix(in srgb, var(--prussian-blue) 84%, var(--ivory));
  --muted: color-mix(in srgb, var(--prussian-blue) 64%, var(--ivory));
  --border: color-mix(in srgb, var(--prussian-blue) 16%, var(--ivory));
  --border-soft: color-mix(in srgb, var(--prussian-blue) 9%, var(--ivory));
  --primary: var(--prussian-blue);
  --primary-hover: color-mix(in srgb, var(--prussian-blue) 88%, black);
  --primary-contrast: var(--ivory);
  --accent: var(--baby-blue-ice);
  --accent-contrast: var(--prussian-blue);
  --accent-soft: var(--light-cyan);
  --danger: #bd4836;
  --danger-soft: #f6e0d9;
  --warn: #ce8a2e;
  --success: #1f6e59;
  --success-soft: #dcebe0;
  --info: #3d6e95;
  --info-soft: #e0e9f0;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 40px -22px rgba(14, 28, 54, .35);
  --shadow-soft: 0 10px 28px -18px rgba(14, 28, 54, .28);
  --maxw: 1080px;

  /* Spacing scale - every gap/margin between distinct widgets (stat cards,
     cards, grids, toolbars) should come from this list rather than one-off
     rem values, so the rhythm between blocks reads as intentional. */
  --space-1: .4rem;
  --space-2: .6rem;
  --space-3: .9rem;
  --space-4: 1.1rem;
  --space-widget: 1.25rem;  /* space between sibling widgets on a page */
  --space-6: 2rem;
}

[data-theme="dark"] {
  --bg: #081120;
  --surface: var(--prussian-blue);
  --surface-2: #14294a;
  --ink: var(--ivory);
  --ink-soft: color-mix(in srgb, var(--ivory) 88%, var(--light-cyan));
  --muted: color-mix(in srgb, var(--ivory) 55%, var(--prussian-blue));
  --border: color-mix(in srgb, var(--ivory) 20%, var(--prussian-blue));
  --border-soft: color-mix(in srgb, var(--ivory) 11%, var(--prussian-blue));
  --primary: var(--baby-blue-ice);
  --primary-hover: color-mix(in srgb, var(--baby-blue-ice) 85%, white);
  --primary-contrast: var(--prussian-blue);
  --accent: var(--light-cyan);
  --accent-contrast: var(--prussian-blue);
  --accent-soft: #1c3a63;
  --danger: #e0896f;
  --danger-soft: #3d241b;
  --warn: #e0a94e;
  --success: #82cfb2;
  --success-soft: #1d2f26;
  --info: #8fb3d1;
  --info-soft: #22303c;
  --shadow: 0 22px 52px -24px rgba(0,0,0,.72);
  --shadow-soft: 0 12px 32px -20px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  font-size: 15.5px;
  line-height: 1.55;
  letter-spacing: .005em;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(58rem 36rem at 110% -12%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 55%),
    radial-gradient(48rem 34rem at -12% 112%, color-mix(in srgb, var(--primary) 15%, transparent), transparent 55%);
  background-attachment: fixed;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

[data-theme="dark"] body::before { mix-blend-mode: screen; opacity: .6; }

h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; line-height: 1.12; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 3.6vw, 2.6rem); }
h2 { font-size: clamp(1.25rem, 2.4vw, 1.7rem); }
h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
small { color: var(--muted); }

.mono { font-family: var(--mono); font-size: .9em; letter-spacing: 0; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }

/* buttons */
.btn {
  --btn-bg: var(--surface-2);
  --btn-ink: var(--ink);
  appearance: none;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font: 500 .95rem/1 var(--body);
  padding: .68rem 1.05rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  box-shadow: var(--shadow-soft);
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { --btn-bg: var(--primary); --btn-ink: var(--primary-contrast); border-color: transparent; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.accent { --btn-bg: var(--accent); --btn-ink: var(--accent-contrast); border-color: transparent; }
.btn.danger { --btn-bg: var(--danger-soft); --btn-ink: var(--danger); border-color: transparent; }
.btn.ghost { --btn-bg: transparent; --btn-ink: var(--muted); box-shadow: none; }
.btn.block { width: 100%; justify-content: center; }
.btn.small { padding: .45rem .7rem; font-size: .85rem; box-shadow: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
/* forms */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: 0 0 .32rem; letter-spacing: .03em; text-transform: uppercase; }
.field { margin-bottom: 1rem; }
input, select, textarea {
  width: 100%;
  padding: .66rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: 400 .95rem/1.4 var(--body);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
textarea { min-height: 92px; resize: vertical; }

/* dropdowns */
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23857a63' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
  background-size: 15px;
  padding-right: 2.3rem;
  cursor: pointer;
}
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a89c81' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
select:hover { border-color: var(--muted); }

/* file picker */
input[type="file"] { padding: .45rem; cursor: pointer; }
input[type="file"]::file-selector-button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font: 500 .85rem var(--body);
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-right: .8rem;
  transition: background .15s, color .15s;
}
input[type="file"]::file-selector-button:hover { background: var(--primary); color: var(--primary-contrast); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: end; margin-bottom: var(--space-widget); }
.chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-family: var(--mono); padding: .3rem .65rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface-2); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* cards */
.card {
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 88%, var(--surface-2)));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow-soft);
}
.card + .card { margin-top: var(--space-widget); }
/* Cards placed side-by-side in a grid get their spacing from the grid's
   own `gap` - a leftover top margin here would push only the 2nd/4th
   card down and break the row alignment. */
.grid-2 > .card + .card,
.chart-grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .9rem; }
.card-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-widget); align-items: start; }

/* Every direct child of the page content area (h1, intro text, stat grid,
   cards, toolbars...) is a "widget" from a layout point of view, so they
   all share one consistent top margin instead of each element bringing
   its own bottom-margin at a slightly different value. */
.content > * + * { margin-top: var(--space-widget); }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); margin-bottom: 0; }
.stat {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.stat:nth-child(2) { animation-delay: .06s; }
.stat:nth-child(3) { animation-delay: .12s; }
.stat:nth-child(4) { animation-delay: .18s; }
.stat .label { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat .value { font-family: var(--display); font-size: 2rem; line-height: 1; margin-top: .3rem; color: var(--ink-soft); }
.stat .hint { font-size: .78rem; color: var(--muted); margin-top: .15rem; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 520px; }
thead th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .7rem .85rem; font-weight: 700; border-bottom: 1px solid var(--border); background: var(--surface-2); }
tbody td { padding: .72rem .85rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

/* list rows */
.att-row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; padding: .75rem 0; border-bottom: 1px solid var(--border-soft); }
.att-row:last-child { border-bottom: 0; }
.att-row .name { font-weight: 500; min-width: 130px; }
.att-row .spacer { flex: 1; }

/* attendance calendar (weekday header + one scrollable strip per student) */
.cal { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -.1rem; padding: 0 .1rem; }
.cal-row { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--border-soft); min-width: max-content; }
.cal-row:last-child { border-bottom: 0; }
.cal-row .name { position: sticky; left: 0; z-index: 1; background: var(--surface); font-weight: 500; width: 150px; min-width: 150px; max-width: 150px; flex: 0 0 150px; padding-right: .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-row.cal-head { border-bottom: 1px solid var(--border); padding-bottom: .4rem; margin-bottom: .15rem; }
.cal-row.cal-head .name { background: transparent; }

/* attendance dots */
.dots { display: grid; grid-template-columns: repeat(var(--cal-days, 31), 20px); gap: 4px; }
.dot { aspect-ratio: 1; border-radius: 5px; background: var(--border-soft); border: 1px solid var(--border-soft); transition: transform .12s ease; }
.dot:hover { transform: scale(1.18); }
.dot.P, .dot.p { background: var(--success); border-color: var(--success); }
.dot.A, .dot.a { background: var(--danger); border-color: var(--danger); }
.dot.L, .dot.l { background: var(--warn); border-color: var(--warn); }
.dot.H, .dot.h { background: var(--muted); border-color: var(--muted); }
.dot.V, .dot.v { background: var(--info); border-color: var(--info); }
.dot.skip { background: transparent; border-style: dashed; color: var(--muted); }
.dots .dot { display: flex; align-items: center; justify-content: center; font-size: .62rem; font-family: var(--mono); color: var(--muted); }
.dot.P, .dot.p, .dot.A, .dot.a, .dot.L, .dot.l, .dot.H, .dot.h, .dot.V, .dot.v { color: var(--ivory); opacity: .95; }
/* weekday header above the dots grid */
.wdrow { display: grid; grid-template-columns: repeat(var(--cal-days, 31), 20px); gap: 4px; }
.wdrow .wd { text-align: center; font-size: .62rem; font-family: var(--mono); color: var(--muted); letter-spacing: 0; }
.wdrow .wd.we { color: var(--ink-soft); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .78rem; color: var(--muted); margin-top: .9rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

/* weekly-grouped attendance calendar */
.att-weekgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(198px, 1fr)); gap: .8rem; align-items: start; }
.att-week {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: .8rem .7rem .9rem;
}
.att-week-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.att-week-label { font-family: var(--display); font-weight: 600; font-size: .84rem; color: var(--ink-soft); }
.att-week-range { font-family: var(--mono); font-size: .68rem; color: var(--muted); white-space: nowrap; }
.att-week-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.att-day { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .2rem 0; border-radius: 8px; }
.att-day.is-sun { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.att-day-dow { font-family: var(--mono); font-size: .58rem; letter-spacing: .02em; color: var(--muted); text-transform: uppercase; }
.att-day.is-sun .att-day-dow { color: var(--ink-soft); font-weight: 700; }
.att-day-num {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: .72rem; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.att-day-bar { width: 60%; height: 3px; border-radius: 999px; background: var(--border-soft); }
.att-day-num.status-P, .att-day-bar.status-P { background: var(--success); border-color: var(--success); color: var(--ivory); }
.att-day-num.status-A, .att-day-bar.status-A { background: var(--danger); border-color: var(--danger); color: var(--ivory); }
.att-day-num.status-L, .att-day-bar.status-L { background: var(--warn); border-color: var(--warn); color: var(--ivory); }
.att-day-num.status-H, .att-day-bar.status-H { background: var(--muted); border-color: var(--muted); color: var(--ivory); }
.att-day-num.status-V, .att-day-bar.status-V { background: var(--info); border-color: var(--info); color: var(--ivory); }
.att-day-num.status-skip { background: transparent; border-style: dashed; }
.att-day-bar.status-skip { background: transparent; }

/* chart cards (admin analytics) */
.chart-card { position: relative; height: 260px; }
.chart-card canvas { max-width: 100%; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-widget); }
.rank-row { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--border-soft); }
.rank-row:last-child { border-bottom: 0; }
.rank-row .n { font-family: var(--mono); font-size: .78rem; color: var(--muted); width: 1.4em; flex: none; }
.rank-row .name { font-weight: 500; flex: 1; min-width: 0; }
.rank-row .rate { font-family: var(--display); font-weight: 600; }
.rank-bar { height: 6px; border-radius: 999px; background: var(--border-soft); overflow: hidden; margin-top: .3rem; }
.rank-bar > i { display: block; height: 100%; background: var(--success); border-radius: inherit; }
.rank-row.low .rate { color: var(--danger); }
.rank-row.low .rank-bar > i { background: var(--danger); }

/* pills */
.pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .74rem; font-family: var(--mono); padding: .25rem .6rem; border-radius: 999px; border: 1px solid transparent; }
.pill.paid, .pill.submitted, .pill.graded, .pill.P { background: var(--success-soft); color: var(--success); }
.pill.pending, .pill.A, .pill.late { background: var(--danger-soft); color: var(--danger); }
.pill.L { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.pill.H { background: var(--surface-2); color: var(--muted); }
.pill.V { background: var(--info-soft); color: var(--info); }
.pill.default { background: var(--surface-2); color: var(--muted); }

/* accounts page */
.acct-name { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.acct-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--primary); color: var(--primary-contrast);
  font-family: var(--display); font-weight: 700; font-size: .8rem;
}
.acct-name .who { min-width: 0; }
.acct-name .who .email { display: block; font-size: .76rem; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.pill.role-admin { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.pill.role-teacher { background: var(--info-soft); color: var(--info); }
.pill.role-student { background: var(--success-soft); color: var(--success); }
.pill.role-parent { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.role-accountant { background: var(--surface-2); color: var(--muted); }

/* announce / fee / empty */
.announce { border-left: 3px solid var(--accent); padding: .8rem 1rem; background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-bottom: .8rem; }
.announce .meta { font-size: .76rem; color: var(--muted); font-family: var(--mono); margin-bottom: .25rem; }
.fee-row { display: grid; grid-template-columns: 1fr auto; gap: .9rem; align-items: center; padding: .85rem 0; border-bottom: 1px solid var(--border-soft); }
.fee-row:last-child { border-bottom: 0; }
.fee-row .amount { font-family: var(--display); font-size: 1.25rem; color: var(--ink-soft); }
.empty { text-align: center; color: var(--muted); padding: 1.8rem 1rem; font-size: .92rem; }
.empty .big { font-family: var(--display); font-size: 1.3rem; color: var(--ink-soft); display: block; margin-bottom: .2rem; }
/* Homework - a nostalgic composition-notebook / diary page. Every assignment
   reads like an entry written in a school diary: a handwritten date, a
   stamped subject label, a title, and the instructions written on ruled
   paper, with the classic red margin running down the left edge. */
.hw-list { display: flex; flex-direction: column; gap: var(--space-widget); }

.hw-entry {
  position: relative;
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 90%, var(--surface-2)));
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 1.15rem 1.25rem 1.2rem 1.5rem;
  overflow: hidden;
}
.hw-entry.overdue {
  background: linear-gradient(180deg, color-mix(in srgb, var(--danger-soft) 42%, var(--surface)), var(--surface));
  border-left-color: var(--danger);
  box-shadow: var(--shadow);
}

.hw-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .9rem; flex-wrap: wrap;
  border-bottom: 1px dashed var(--border);
  padding-bottom: .7rem; margin-bottom: .85rem;
}
.hw-date { display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; min-width: 0; }
.hw-dow {
  font-family: var(--hand); font-weight: 700; font-size: 1.42rem; line-height: 1;
  color: var(--danger);
}
.hw-date-line {
  font-family: var(--hand); font-weight: 600; font-size: 1.18rem; line-height: 1.1;
  color: var(--ink-soft); white-space: nowrap;
}
.hw-date-line sup { font-size: .58em; }
.hw-subject {
  align-self: center; flex: none;
  font-family: var(--mono); font-size: .7rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
  padding: .32rem .7rem; border-radius: 999px; white-space: nowrap;
}

.hw-title { font-family: var(--display); font-size: 1.2rem; font-weight: 600; color: var(--ink); margin: 0 0 .6rem; }

.hw-body {
  color: var(--ink-soft);
  line-height: 2;
  margin: 0 0 .95rem;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(2em - 1px),
    color-mix(in srgb, var(--border) 78%, transparent) calc(2em - 1px),
    color-mix(in srgb, var(--border) 78%, transparent) 2em
  );
}

.hw-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  border-top: 1px dashed var(--border); padding-top: .85rem;
}
.hw-due { font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.hw-due.bad { color: var(--danger); font-weight: 600; }
.hw-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; }
.hw-actions .toolbar { margin: 0; }

/* layout */
.app { min-height: 100vh; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.rail {
  position: sticky; top: 0; height: 100vh;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-right: 1px solid var(--border);
  padding: 1.3rem 1rem;
  display: flex; flex-direction: column;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: 0 .4rem; }
.brand .mark { width: 38px; height: 38px; border-radius: 11px; background: var(--primary); color: var(--primary-contrast); display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 1.05rem; flex: none; }
.brand .name { font-family: var(--display); font-weight: 600; font-size: 1.08rem; line-height: 1.1; }
.brand .sub { font-size: .66rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-family: var(--mono); }
.userbox { margin: .7rem .35rem .3rem; padding: .7rem .7rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.userbox .u-name { font-weight: 600; font-size: .93rem; }
.userbox .u-role { font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: .25rem; margin-top: 1rem; flex: 1; overflow-y: auto; }
.nav button {
  appearance: none; background: transparent; border: 0; text-align: left;
  padding: .72rem .8rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); font: 500 .93rem var(--body); cursor: pointer;
  display: flex; align-items: center; gap: .6rem; width: 100%;
  transition: background .15s, color .15s;
}
.nav button svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.nav button:hover { background: var(--surface-2); }
.nav button.active { background: var(--primary); color: var(--primary-contrast); }
/* Collapsible nav groups (e.g. the "Fee" menu) */
.nav-group { display: flex; flex-direction: column; }
.nav-group-toggle .chev { width: 14px; height: 14px; margin-left: auto; opacity: .7; flex: none; transition: transform .18s ease; }
.nav-group.open > .nav-group-toggle .chev { transform: rotate(180deg); }
.nav-group-children { display: none; flex-direction: column; gap: .15rem; margin-top: .15rem; position: relative; }
.nav-group.open > .nav-group-children { display: flex; }
.nav-group-children::before { content: ""; position: absolute; left: 1.05rem; top: .25rem; bottom: .25rem; width: 2px; background: var(--border-soft); border-radius: 2px; }
.nav button.sub { padding-left: 1.85rem; font-weight: 500; }
.nav button.sub svg { opacity: .65; }
.rail .foot { margin-top: .6rem; padding: 0 .35rem; }
.rail .foot button { width: 100%; justify-content: center; }

/* Collapsible navigation rail (desktop) */
.rail-toggle {
  appearance: none; background: transparent; border: 0; cursor: pointer;
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: .3rem; border-radius: var(--radius-sm);
  align-self: flex-end; margin-bottom: .4rem; flex: none;
  transition: background .15s, color .15s;
}
.rail-toggle:hover { background: var(--surface-2); color: var(--ink); }

@media (min-width: 981px) {
  .app.rail-collapsed { grid-template-columns: 96px minmax(0, 1fr); }
  .app.rail-collapsed .rail { padding: 1.1rem .55rem; }
  .app.rail-collapsed .rail-toggle { align-self: center; margin-bottom: .6rem; }
  .app.rail-collapsed .brand { justify-content: center; gap: 0; padding: 0; }
  .app.rail-collapsed .brand .brand-id { display: none; }
  .app.rail-collapsed .userbox { display: none; }
  .app.rail-collapsed .nav button { justify-content: center; padding: .72rem 0; text-align: center; }
  .app.rail-collapsed .nav .nav-label { display: none; }
  .app.rail-collapsed .nav-group-toggle .chev { display: none; }
  /* Children are hidden while collapsed; clicking the group expands the rail. */
  .app.rail-collapsed .nav-group-children { display: none; }
  .app.rail-collapsed .rail .foot { padding: 0; }
  .app.rail-collapsed .rail .foot button { justify-content: center; }
  .app.rail-collapsed .rail .foot .nav-label { display: none; }
}

.main { position: relative; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .8rem;
  padding: .85rem 1.5rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar .crumbs { font-size: .82rem; color: var(--muted); font-family: var(--mono); }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 1.6rem clamp(1rem, 3vw, 2rem); max-width: var(--maxw); width: 100%; margin: 0 auto; }
.content .view { animation: rise .45s cubic-bezier(.2,.7,.2,1) both; }

/* theme toggle */
.theme-btn { appearance: none; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); width: 38px; height: 38px; border-radius: 11px; cursor: pointer; display: grid; place-items: center; flex: none; transition: border-color .15s; }
.theme-btn:hover { border-color: var(--primary); }

/* toast */
.toast-wrap { position: fixed; top: 1rem; right: 1rem; z-index: 90; display: flex; flex-direction: column; gap: .6rem; }
.toast { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-left: 3px solid var(--primary); padding: .7rem .9rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .9rem; max-width: 300px; animation: pop .3s ease both; }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { from { opacity: 0; transform: translateX(12px) scale(.98); } to { opacity: 1; transform: none; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* loading skeletons - shown until a page's first fetch resolves, so a stat
   card reads as "still loading" instead of looking identical to a real 0 */
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skel { position: relative; color: transparent !important; pointer-events: none; }
.skel::after {
  content: ""; position: absolute; inset: .12em 35% .12em 0; border-radius: 6px;
  background: linear-gradient(90deg, var(--border-soft) 25%, var(--border) 37%, var(--border-soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
.stat .hint.skel::after { inset: .1em 45% .1em 0; }
.spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--muted); animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-inline { display: flex; align-items: center; gap: .55rem; padding: .9rem .2rem; color: var(--muted); font-size: .88rem; }

/* password fields with a show/hide toggle */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 2.5rem; }
.pw-toggle {
  position: absolute; right: .3rem; top: 50%; transform: translateY(-50%);
  appearance: none; background: transparent; border: 0; color: var(--muted);
  width: 2rem; height: 2rem; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center;
}
.pw-toggle:hover { color: var(--ink); background: var(--surface-2); }

/* shared error/success text under a form or field, replacing scattered
   inline `style="color:var(--danger)"` divs */
.field-error, .field-success, .field-note {
  font-size: .85rem; margin-top: .5rem; display: flex; align-items: center; gap: .4rem;
}
.field-error { color: var(--danger); }
.field-success { color: var(--success); }
.field-note { color: var(--muted); }

/* confirmation modal - replaces native confirm()/prompt() for destructive
   or sensitive actions so it matches the app's look and can't be silently
   auto-dismissed by a mobile popup blocker */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 95; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: color-mix(in srgb, var(--prussian-blue) 55%, transparent);
  opacity: 0; transition: opacity .18s ease;
}
.modal-backdrop.show { opacity: 1; }
.modal-backdrop .modal { width: 100%; max-width: 420px; transform: translateY(10px) scale(.98); transition: transform .18s ease; margin: 0; }
.modal-backdrop.show .modal { transform: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: var(--space-widget); }
.modal .field-error { margin-top: .3rem; }

/* a subtle fading edge on horizontally-scrollable tables, so clipped
   columns read as "scroll for more" rather than as cut-off content */
.table-wrap { position: relative; }
.table-wrap::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 28px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 85%, transparent));
  pointer-events: none; opacity: 0; transition: opacity .15s ease; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.table-wrap.scrollable::after { opacity: 1; }

/* login */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.4rem; }
.login-card { width: 100%; max-width: 420px; }

/* responsive */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; left: 0; top: 0; transform: translateX(-104%); transition: transform .25s ease; width: min(288px, 86vw); box-shadow: var(--shadow); }
  .rail.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .rail-toggle { display: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  .scrim.show { opacity: 1; pointer-events: auto; }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  body { font-size: 15px; }
  .field-row, .field-row-3, .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 1.1rem .95rem 3.2rem; }
  .topbar { padding: .7rem .95rem; flex-wrap: wrap; row-gap: .5rem; }
  .topbar .crumbs { order: 1; }
  .topbar .spacer { order: 2; flex-basis: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .stat { padding: .8rem .85rem; }
  .stat .value { font-size: 1.55rem; }
  .att-row { gap: .5rem; }
  .att-row .name { min-width: 0; width: 100%; }
  .fee-row { grid-template-columns: 1fr; }
  .dots, .wdrow { grid-template-columns: repeat(var(--cal-days, 31), 17px); }
  .cal-row .name { width: 82px; min-width: 82px; max-width: 82px; flex: 0 0 82px; font-size: .84rem; }
  .holiday-scope { grid-template-columns: 1fr; }
  .card { padding: 1rem .95rem; }
  .toolbar { gap: .5rem; }
  .toolbar > * { flex: 1 1 auto; min-width: 0; }
  .toast-wrap { top: auto; bottom: .8rem; right: .8rem; left: .8rem; }
  .toast { max-width: none; }

  /* weekly attendance: 3-per-row on very tight screens, still centers Sunday */
  .att-weekgrid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .55rem; }
  .att-week { padding: .65rem .5rem .75rem; }
  .att-day-num { width: 22px; height: 22px; font-size: .64rem; }
  .att-day-dow { font-size: .53rem; }
  .att-week-days { gap: .18rem; }

  .chart-card { height: 220px; }

  /* accounts table -> stacked cards */
  .acct-table thead { display: none; }
  .acct-table, .acct-table tbody, .acct-table tr, .acct-table td { display: block; width: 100%; }
  .acct-table { min-width: 0; }
  .acct-table tr { border-bottom: 1px solid var(--border); padding: .7rem 0; }
  .acct-table tr[id^="edit-"] { border-bottom: 0; padding-top: 0; }
  .acct-table td { border-bottom: 0; padding: .28rem 0; }
  .acct-table td[data-label]:not(.acct-actions)::before {
    content: attr(data-label);
    display: block; font-size: .66rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--muted); margin-bottom: .15rem;
  }
  .acct-table td.acct-actions { display: flex; gap: .5rem; margin-top: .3rem; }
  .acct-name .who .email { max-width: none; }

  /* homework diary entries stack on small screens */
  .hw-entry { padding: 1rem 1rem 1.05rem 1.25rem; }
  .hw-head { align-items: flex-start; flex-direction: column; gap: .5rem; }
  .hw-date { gap: .35rem; }
  .hw-dow, .hw-date-line { font-size: 1.3rem; }
  .hw-date-line { white-space: normal; }
  .hw-subject { align-self: flex-start; }
  .hw-foot { flex-direction: column; align-items: stretch; gap: .7rem; }
  .hw-actions { justify-content: flex-start; }
  .hw-actions .toolbar { width: 100%; gap: .5rem; }
  .hw-actions .toolbar input[type="file"] { max-width: none; flex: 1 1 auto; }
  .hw-actions .toolbar .btn { flex: 0 0 auto; }

  /* results tables -> stacked cards so the Subject column is never cut off */
  .results-table { min-width: 0; }
  .results-table thead { display: none; }
  .results-table, .results-table tbody, .results-table tr { display: block; width: 100%; }
  .results-table td { display: block; width: 100%; border-bottom: 0; padding: .28rem 0; }
  .results-table tr { border-bottom: 1px solid var(--border); padding: .65rem 0; }
  .results-table tr:last-child { border-bottom: 0; }
  .results-table td.strong { font-size: 1rem; color: var(--ink); padding-top: .1rem; }
  .results-table td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: .66rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--muted); margin-bottom: .15rem;
  }
  .results-table td.empty { padding: 1.8rem 1rem; }
}
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .att-weekgrid { grid-template-columns: 1fr; }
  .att-day-num { width: 26px; height: 26px; font-size: .7rem; }
}
