/* Masinop — design tokens
   Pisara green (chalkboard) for structure, Lapis yellow (pencil) as the one marker colour:
   current page, today, HPS row, keyboard focus. Everything else stays quiet. */
@font-face {
  font-family: 'DM Sans';
  src: url('../fonts/DMSans.woff') format('woff');
  font-weight: 100 1000;
  font-display: swap;
}
:root {
  --fs: 18px;
  --bg: #f1f4f2;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --ink: #16302a;
  --ink-2: #4b5e58;
  --line: #dbe3df;
  --line-strong: #c3cfca;
  --brand: #1f5e52;
  --brand-hover: #184c42;
  --brand-ink: #ffffff;
  --brand-soft: #e2eeea;
  --lapis: #f2b33d;
  --lapis-ink: #5a3d00;
  --lapis-soft: #fdf3dc;
  --bad: #b3332a;
  --bad-soft: #fbe9e7;
  --ok: #1d7a4b;
  --ok-soft: #e1f2e8;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --side: 256px;
  --shadow-pop: 0 12px 32px rgba(22, 48, 42, .18);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1816;
  --surface: #16211e;
  --surface-2: #1b2824;
  --ink: #e4ece8;
  --ink-2: #a2b4ad;
  --line: #2a3a35;
  --line-strong: #3a4d47;
  --brand: #5fb8a3;
  --brand-hover: #79c7b4;
  --brand-ink: #0c1513;
  --brand-soft: #1d3530;
  --lapis: #e8b450;
  --lapis-ink: #ffe6b0;
  --lapis-soft: #3a3020;
  --bad: #f08c80;
  --bad-soft: #3b2320;
  --ok: #7fd3a6;
  --ok-soft: #1c3427;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: var(--fs); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-optical-sizing: auto; line-height: 1.5; font-feature-settings: 'tnum' 0;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-underline-offset: 3px; }
h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.015em; margin: 0; }
h2 { font-size: 1.2rem; line-height: 1.3; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 .6rem; }
h3 { font-size: 1rem; font-weight: 650; margin: 0 0 .4rem; }
p { margin: .35rem 0; max-width: 72ch; }
.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
.num, table { font-variant-numeric: tabular-nums; }
code { font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
:focus-visible { outline: 3px solid var(--lapis); outline-offset: 2px; border-radius: 6px; }

/* icons */
.ic { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }
.ic.lg { width: 1.75rem; height: 1.75rem; }
.ic.xl { width: 2.25rem; height: 2.25rem; }

/* ---------- app layout: side rail + content ---------- */
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: .25rem;
  padding: 1.25rem .9rem; background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .25rem .5rem 1.25rem; text-decoration: none; color: var(--ink); }
.brand .mark {
  width: 2.6rem; height: 2.6rem; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 1.3rem;
  box-shadow: inset 0 -5px 0 var(--lapis);
}
.brand b { display: block; font-size: 1.15rem; letter-spacing: -0.01em; }
.brand small { display: block; color: var(--ink-2); font-size: .78rem; line-height: 1.25; max-width: 11rem; }
.nav { display: flex; flex-direction: column; gap: .15rem; }
.nav a, .navbtn {
  position: relative; display: flex; align-items: center; gap: .75rem; padding: .7rem .85rem;
  border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font-weight: 550;
  background: none; border: none; cursor: pointer; text-align: left; width: 100%; min-height: 48px;
}
.nav a:hover, .navbtn:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.nav a[aria-current="page"]::before {
  content: ''; position: absolute; left: -0.9rem; top: 22%; bottom: 22%; width: 5px; border-radius: 0 4px 4px 0; background: var(--lapis);
}
.nav .ic { width: 1.45rem; height: 1.45rem; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: .75rem; }

.content { min-width: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 1.75rem 2.25rem 4rem; }
main.wide { max-width: none; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.pagehead p { margin: .35rem 0 0; color: var(--ink-2); }
.pagehead .actions { margin: 0; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.35rem 1.5rem; margin-bottom: 1.25rem; }
.card > h2:first-child { margin-top: 0; }
.card.flat { background: var(--surface-2); }
.section-title { display: flex; align-items: center; gap: .55rem; }
.section-title .ic { color: var(--brand); }

/* home */
.hello { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.25rem; margin-bottom: 1.5rem; }
.today-card {
  background: var(--brand); color: var(--brand-ink); border-radius: var(--r-lg); padding: 1.5rem 1.6rem;
  display: flex; flex-direction: column; gap: .9rem; position: relative; overflow: hidden;
}
.today-card .date { font-size: 2.1rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.today-card .date small { display: block; font-size: 1rem; font-weight: 500; opacity: .85; letter-spacing: 0; margin-top: .3rem; }
.today-card .stat { font-size: 1.05rem; opacity: .95; }
.today-card .btn { align-self: flex-start; background: var(--lapis); color: #3b2800; border-color: var(--lapis); }
.today-card .btn:hover { filter: brightness(1.05); }
.today-card::after {
  content: ''; position: absolute; right: -40px; bottom: -40px; width: 180px; height: 180px; border-radius: 50%;
  border: 26px solid rgba(255,255,255,.07);
}
[data-theme="dark"] .today-card { background: #1c4a42; color: #e8f3ef; }
[data-theme="dark"] .today-card::after { border-color: rgba(255,255,255,.05); }
.class-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.4rem 1.5rem; }
.class-card .big { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .2rem 1rem; margin-top: .6rem; color: var(--ink-2); }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; color: var(--ink); font-weight: 550; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.tile {
  display: flex; align-items: flex-start; gap: .95rem; text-align: left; cursor: pointer; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 1.1rem 1.15rem; min-height: 96px;
  transition: border-color .15s, background .15s;
}
.tile:hover { border-color: var(--brand); background: var(--surface-2); }
.tile .tic { width: 3rem; height: 3rem; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.tile .tic .ic { width: 1.7rem; height: 1.7rem; }
.tile .label { display: block; font-weight: 650; font-size: 1.05rem; }
.tile .sub { display: block; color: var(--ink-2); font-size: .88rem; margin-top: .15rem; }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; margin: .9rem 0 .35rem; font-size: .95rem; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .7rem .85rem; border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); min-height: 48px; transition: border-color .15s;
}
textarea { min-height: 9rem; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--lapis); outline-offset: 0; border-color: var(--brand); }
input[type=checkbox] { width: 1.25rem; height: 1.25rem; accent-color: var(--brand); vertical-align: -0.2em; }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 550; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > * { flex: 1 1 210px; }
.actions { display: flex; gap: .65rem; flex-wrap: wrap; align-items: center; margin-top: 1.25rem; }
details > summary { cursor: pointer; font-weight: 650; padding: .4rem 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; cursor: pointer; text-decoration: none;
  padding: .65rem 1.15rem; border-radius: var(--r-sm); border: 1.5px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-weight: 650; min-height: 48px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.link { border: none; background: none; color: var(--brand); padding: .25rem .35rem; min-height: auto; text-decoration: underline; text-underline-offset: 3px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ic { width: 1.3rem; height: 1.3rem; }

/* steps (setup wizard) */
.steps { display: flex; gap: .5rem; margin-bottom: 1.5rem; flex-wrap: wrap; counter-reset: s; }
.steps span { display: inline-flex; align-items: center; gap: .45rem; padding: .35rem .8rem .35rem .4rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: .88rem; font-weight: 600; }
.steps span::before { counter-increment: s; content: counter(s); width: 1.6rem; height: 1.6rem; border-radius: 50%; display: grid; place-items: center; background: var(--line); color: var(--ink); font-size: .8rem; }
.steps span.on { background: var(--brand-soft); color: var(--brand); }
.steps span.on::before { background: var(--brand); color: var(--brand-ink); }
.steps span.done::before { background: var(--ok); color: #fff; }

/* callouts */
.banner { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding: .8rem 1rem; border-radius: var(--r-md); margin: 0 0 1rem; font-weight: 550; }
.banner > .ic { width: 1.5rem; height: 1.5rem; }
.banner .btn { min-height: 40px; padding: .4rem .9rem; margin-left: auto; }
.banner.warn { background: var(--lapis-soft); color: var(--lapis-ink); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
#banner { padding: 1rem 2.25rem 0; max-width: 1180px; margin: 0 auto; }
#banner:empty { display: none; }

/* ---------- tables ---------- */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); max-height: 74vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .92rem; }
th, td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: .45rem .55rem; text-align: center; white-space: nowrap; }
th:last-child, td:last-child { border-right: none; }
th { background: var(--surface-2); color: var(--ink-2); font-weight: 650; font-size: .82rem; position: sticky; top: 0; z-index: 2; }
thead tr:nth-child(2) th { top: 2.3rem; }
tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
td.name, th.name { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 15rem; font-weight: 550; }
th.name { z-index: 3; background: var(--surface-2); }
tr.group td { background: var(--surface-2); font-weight: 700; text-align: left; color: var(--brand); font-size: .85rem; }
tr.group .gl { position: sticky; left: .55rem; }
td.calc { color: var(--ink-2); background: var(--surface-2); }
td.ig { font-weight: 650; }
td.tg { font-weight: 800; font-size: 1.05rem; }
td.fail { color: var(--bad); background: var(--bad-soft); }
.list td { text-align: left; }
.grid input {
  width: 3.8rem; min-height: 38px; padding: .3rem; text-align: center; border: 1.5px solid var(--line-strong);
  border-radius: 8px; font-size: .95rem; background: var(--surface); font-variant-numeric: tabular-nums;
}
.grid input.hps { background: var(--lapis-soft); border-color: var(--lapis); font-weight: 700; color: var(--ink); }
.grid input.bad { border-color: var(--bad); background: var(--bad-soft); }
.grid select { min-height: 38px; padding: .3rem .4rem; }

.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 650; background: var(--surface-2); color: var(--ink-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--lapis-soft); color: var(--lapis-ink); }

.code { font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 700; letter-spacing: .1em; background: var(--lapis-soft); border: 2px dashed var(--lapis); color: var(--ink); padding: .8rem 1.2rem; border-radius: var(--r-md); display: inline-block; }

/* ---------- auth screens (welcome, setup, lock, restore) ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-box { width: 100%; max-width: 640px; }
.auth-box.narrow { max-width: 400px; }
.auth .brand { justify-content: center; padding-bottom: 1.5rem; }
.auth .card { padding: 2rem; box-shadow: 0 1px 0 var(--line); }
.auth h1 { margin-bottom: .5rem; }
.choice { display: grid; gap: .75rem; margin-top: 1.5rem; }
.choice .tile { min-height: auto; }
.pin { font-size: 2rem; letter-spacing: .6em; text-align: center; font-weight: 700; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 50; max-width: 90vw;
  display: flex; align-items: center; gap: .6rem; background: var(--ink); color: var(--bg);
  padding: .8rem 1.2rem; border-radius: var(--r-md); box-shadow: var(--shadow-pop); font-weight: 600;
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.updatebar { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 60; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-pop); border-radius: var(--r-md); padding: .7rem .8rem .7rem 1.1rem; display: flex; align-items: center; gap: 1rem; }

/* segmented options (theme, font size) */
.seg { display: inline-flex; border: 1.5px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.seg button { border: none; background: transparent; padding: .55rem 1rem; font-weight: 650; cursor: pointer; min-height: 46px; display: inline-flex; align-items: center; gap: .4rem; color: var(--ink-2); }
.seg button + button { border-left: 1.5px solid var(--line-strong); }
.seg button.on { background: var(--brand-soft); color: var(--brand); }
.seg button.on.a { background: var(--bad); color: #fff; }
.seg button.on.t { background: var(--lapis); color: #3b2800; }
.seg button.on.p { background: var(--ok-soft); color: var(--ok); }

/* ---------- attendance ---------- */
.att td.mk { cursor: pointer; min-width: 2.2rem; font-weight: 800; user-select: none; }
.att td.mk:hover { background: var(--brand-soft); }
.att td.mA { background: var(--bad-soft); color: var(--bad); }
.att td.mT { background: var(--lapis-soft); color: var(--lapis-ink); }
.att td.off, .att th.off { background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--bg) 6px 12px); color: var(--ink-2); }
.att th.dayh { cursor: pointer; line-height: 1.15; min-width: 2.2rem; }
.att th.today { background: var(--lapis); color: #3b2800; }
tr.tot td { background: var(--surface-2); font-weight: 700; }
.today-row { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.today-row:last-child { border-bottom: none; }
.today-row .who { font-weight: 600; }
.counts { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-top: .6rem; }
.counts div { font-size: .9rem; color: var(--ink-2); }
.counts b { display: block; font-size: 1.8rem; color: var(--ink); line-height: 1.1; }

/* ---------- mobile: bottom tab bar ---------- */
@media (max-width: 900px) {
  :root { --fs: 17px; }
  .layout { grid-template-columns: 1fr; }
  .side {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 30; flex-direction: row;
    padding: .35rem .4rem calc(.35rem + env(safe-area-inset-bottom)); border-right: none; border-top: 1px solid var(--line);
  }
  .side .brand, .side-foot, .nav .wide-only { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: .15rem; font-size: .72rem; padding: .4rem .25rem; min-height: 56px; justify-content: center; text-align: center; }
  .nav a[aria-current="page"]::before { left: 25%; right: 25%; top: -0.36rem; bottom: auto; width: auto; height: 4px; border-radius: 0 0 4px 4px; }
  main { padding: 1.25rem 1rem 6.5rem; }
  #banner { padding: .75rem 1rem 0; }
  .hello { grid-template-columns: 1fr; }
  .pagehead { align-items: flex-start; }
  h1 { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- printing ---------- */
.printbar { display: flex; gap: .75rem; align-items: center; padding: 1rem 1.25rem; flex-wrap: wrap; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.printbar label { margin: 0; display: inline-flex; align-items: center; gap: .5rem; }
.printbar select { width: auto; min-height: 44px; }
.paper-wrap { padding: 1.5rem; overflow: auto; }
.paper { background: #fff; color: #000; margin: 0 auto; box-shadow: 0 2px 12px rgba(0,0,0,.12); }
@media print {
  body { background: #fff; }
  .side, #banner, .printbar, .noprint, .actions, .pagehead .actions { display: none !important; }
  .layout { display: block; }
  main { padding: 0; max-width: none; }
  .tablewrap { max-height: none; overflow: visible; border: none; }
  .paper-wrap { padding: 0; }
  .paper { box-shadow: none; margin: 0; }
}

/* printable SF2 (always black on white, independent of theme) */
/* the .paper wrapper supplies the margins */
.sf2 { padding: 0; font-family: Arial, Helvetica, sans-serif; font-size: 8.5pt; color: #000; }
.sf2 .ttl { text-align: center; font-weight: 700; font-size: 13pt; }
.sf2 .sub { text-align: center; font-style: italic; font-size: 8pt; margin-bottom: 6px; }
.sf2 table { border-collapse: collapse; width: 100%; font-size: inherit; }
.sf2 th, .sf2 td { border: 1px solid #000; background: #fff; color: #000; position: static; white-space: nowrap; }
.sf2 tbody tr:hover td { background: #fff; }
.sf2 .hdr td { border: none; padding: 2px 6px; text-align: left; }
.sf2 .hdr b { border-bottom: 1px solid #000; padding: 0 6px; }
.sf2 .grid2 th, .sf2 .grid2 td { padding: 1px 2px; font-size: 7.5pt; height: 15px; }
.sf2 .grid2 th { background: #e8e8e8; font-weight: 700; }
.sf2 .grid2 .nm { text-align: left; min-width: 2.4in; }
.sf2 .grid2 th.d { width: 18px; font-size: 6.5pt; }
.sf2 .grid2 .rm { text-align: left; min-width: 1.3in; white-space: normal; font-size: 6.5pt; }
.sf2 .grid2 td.late { background: linear-gradient(135deg, #888 50%, #fff 50%); }
.sf2 .grid2 td.na { background: #ddd; }
.sf2 .grid2 tr.tt td { font-weight: 700; background: #f2f2f2; }
.sf2 .foot { display: grid; grid-template-columns: 1fr 3.6in; gap: 12px; margin-top: 8px; }
.sf2 .sum th, .sf2 .sum td { padding: 1px 4px; font-size: 7.5pt; }
.sf2 .sum td.lb { text-align: left; white-space: normal; }
.sf2 .sign { margin-top: 10px; font-size: 8pt; text-align: center; }
@media print { .sf2 .grid2 tr { page-break-inside: avoid; } }
