/* PESU Dashboard — "attendance register" look: ruled paper, ink, and the red margin line as the attendance target. */

/* Self-hosted (SIL OFL, see /fonts/OFL.txt): no third-party font requests, works offline. Variable font: 400–700. */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f2f5f8;
  --sheet: #ffffff;
  --ink: #1b2430;
  --ink-soft: #5b6878;
  --rule: #d5dde6;
  --margin: #d64545;        /* exercise-book margin line = attendance target */
  --present: #237a4b;
  --pending: #a8700f;
  --pen: #2f5bd3;           /* fountain-pen blue: actions */
  --pen-ink: #ffffff;
  --row: 56px;
  --radius: 10px;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12161c;
    --sheet: #181d25;
    --ink: #e7ebf1;
    --ink-soft: #9aa6b5;
    --rule: #2b3340;
    --margin: #f06b6b;
    --present: #52c58b;
    --pending: #e3b04b;
    --pen: #7ea4ff;
    --pen-ink: #0d1424;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { max-width: 620px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: var(--paper);
}
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; margin-right: auto; }
.wordmark span { color: var(--margin); }
.iconbtn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--sheet);
}
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn.busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  background: var(--sheet); border: 1px solid var(--rule);
}
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: 48px; width: 250px; z-index: 10;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 10px 30px rgba(20, 30, 45, 0.18);
}
.menu-panel p { margin: 0 0 2px; }
.menu-panel .who { font-weight: 700; }
.menu-panel hr { border: 0; border-top: 1px solid var(--rule); margin: 12px 0; }
.menu-panel a, .menu-panel button.link { display: block; width: 100%; text-align: left; padding: 8px 0; background: none; border: 0; color: var(--pen); text-decoration: none; }

.status-line { font-size: 13px; color: var(--ink-soft); margin: -2px 0 12px; min-height: 19px; }
.status-line.error { color: var(--margin); }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--sheet); border-top: 1px solid var(--rule);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border: 0; background: none; color: var(--ink-soft); font-size: 12px; border-radius: 8px;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--ink); font-weight: 700; }
.tab[aria-current="page"] svg { color: var(--pen); }
@media (min-width: 720px) {
  .shell { padding-bottom: 40px; }
  .tabs {
    position: static; display: flex; gap: 4px; padding: 0; margin: 4px 0 18px;
    background: none; border: 0;
  }
  .tab { flex-direction: row; gap: 8px; padding: 8px 14px; font-size: 15px; }
  .tab svg { width: 18px; height: 18px; }
  .tab[aria-current="page"] { background: var(--sheet); box-shadow: inset 0 0 0 1px var(--rule); }
}

/* ---------- Page headings ---------- */
.view h1 { font-size: 26px; line-height: 1.15; margin: 6px 0 2px; letter-spacing: -0.015em; }
.view .sub { margin: 0 0 16px; color: var(--ink-soft); }

/* ---------- The register sheet: ruled rows with a red margin ---------- */
.sheet {
  --gutter: 76px;
  position: relative;
  background: var(--sheet);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px var(--rule);
  overflow: hidden;
}
.sheet::before { /* the margin line */
  content: ""; position: absolute; top: 0; bottom: 0; left: var(--gutter);
  width: 2px; background: var(--margin); opacity: 0.55;
}
.line {
  position: relative;
  display: grid; grid-template-columns: var(--gutter) 1fr auto; align-items: center;
  min-height: var(--row); padding: 8px 14px 8px 0;
  border-top: 1px solid var(--rule);
}
.line:first-child { border-top: 0; }
.line .time { padding: 0 12px 0 14px; font-size: 14px; line-height: 1.2; }
.line .time small { display: block; color: var(--ink-soft); font-size: 12px; }
.line .what { padding-left: 14px; min-width: 0; }
.line .what b { display: block; font-weight: 600; overflow-wrap: anywhere; }
.line .what span { display: block; font-size: 13px; color: var(--ink-soft); }
.line.free { min-height: 38px; }
.line.free .what span { font-style: italic; }
.line.now { background: color-mix(in srgb, var(--pen) 7%, transparent); }

/* Register marks */
.mark {
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: 17px;
  display: inline-grid; place-items: center; font-weight: 700; font-size: 15px;
  border: 1.5px solid currentColor;
}
.mark.p { color: var(--present); }
.mark.a { color: var(--margin); }
.mark.wait { color: var(--pending); font-size: 12px; font-weight: 600; border-style: dashed; }
.mark.now { color: var(--pen); font-size: 12px; font-weight: 600; }
.mark.later { color: var(--ink-soft); border-color: transparent; font-weight: 400; font-size: 13px; }

.empty { padding: 28px 18px; text-align: center; color: var(--ink-soft); }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

/* ---------- Attendance ---------- */
.target {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 14px;
}
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--rule); border-radius: 999px; background: var(--sheet); }
.stepper button { width: 40px; height: 36px; border: 0; background: none; font-size: 20px; line-height: 1; }
.stepper output { min-width: 52px; text-align: center; font-weight: 700; }
.overall { margin: 0 0 14px; }
.overall strong { font-size: 20px; }

.subjects { position: relative; background: var(--sheet); border-radius: var(--radius); box-shadow: inset 0 0 0 1px var(--rule); overflow: hidden; }
.subjects::after { /* the target line running through every subject */
  content: ""; position: absolute; top: 0; bottom: 0;
  left: calc(16px + (100% - 32px) * var(--target, 0.75));
  width: 2px; margin-left: -1px; background: var(--margin); opacity: 0.35; pointer-events: none;
}
.subject { padding: 14px 16px; border-top: 1px solid var(--rule); }
.subject:first-child { border-top: 0; }
.subject-head { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: baseline; }
.subject-head b { font-weight: 600; overflow-wrap: anywhere; }
.subject-head small { display: block; color: var(--ink-soft); font-size: 13px; }
.pct { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.pct.low { color: var(--margin); }
.bar { position: relative; height: 8px; margin: 10px 0 8px; border-radius: 4px; background: var(--rule); }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--ink); }
.bar.low i { background: var(--margin); }
.bar::after { /* solid tick where the line crosses this bar */
  content: ""; position: absolute; top: -4px; bottom: -4px; left: calc(var(--target, 0.75) * 100%);
  width: 2px; margin-left: -1px; background: var(--margin);
}
.advice { font-size: 14px; }
.advice.low { color: var(--margin); font-weight: 600; }

/* ---------- Timetable day picker ---------- */
.days { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 0 0 14px; }
.day {
  padding: 8px 0; border-radius: 8px; border: 1px solid var(--rule); background: var(--sheet); color: var(--ink-soft);
}
.day.today { color: var(--ink); font-weight: 700; }
.day[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login {
  position: relative;
  width: min(100%, 400px);
  background: var(--sheet); border-radius: 14px; box-shadow: inset 0 0 0 1px var(--rule);
  padding: 26px 22px 22px 44px;
}
.login::before { /* exercise-book margin */
  content: ""; position: absolute; top: 0; bottom: 0; left: 26px;
  width: 2px; background: var(--margin); opacity: 0.55;
}
.login h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -0.02em; }
.login h1 span { color: var(--margin); }
.login .lede { margin: 0 0 18px; color: var(--ink-soft); }
.field { display: block; margin: 0 0 14px; }
.field span { display: block; font-size: 14px; margin-bottom: 4px; }
.field input {
  width: 100%; height: 46px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--paper);
}
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 18px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--pen); }
.ts-slot:not(:empty) { margin: 0 0 14px; }
.primary {
  width: 100%; height: 48px; border: 0; border-radius: 10px;
  background: var(--pen); color: var(--pen-ink); font-weight: 700; font-size: 16px;
}
.primary:disabled { opacity: 0.65; cursor: progress; }
.form-error { color: var(--margin); font-weight: 600; margin: 12px 0 0; min-height: 1em; }
.fineprint { font-size: 13px; color: var(--ink-soft); margin: 16px 0 0; }
.fineprint a { color: var(--pen); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
