/* =========================================================================
   Digital Attendance & Parent Notification System
   Mobile-first stylesheet. No build step, no external fonts, no CDN.
   Designed for one-handed use on a teacher's phone in bright daylight.
   ========================================================================= */

:root {
  --ink: #16211f;
  --ink-2: #46565a;
  --muted: #6e7f83;
  --line: #dde5e4;
  --bg: #f4f7f6;
  --surface: #ffffff;

  --accent: #0b6b62;
  --accent-dark: #085048;
  --accent-soft: #e3f1ee;

  --ok: #0f7b4f;
  --ok-soft: #e4f4ec;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #b54708;
  --warn-soft: #fdf1e3;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 40, 38, .06), 0 6px 20px rgba(16, 40, 38, .06);
  --tap: 46px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8efee;
    --ink-2: #b6c5c4;
    --muted: #8ea1a2;
    --line: #2b3937;
    --bg: #101816;
    --surface: #18221f;
    --accent: #4cc0ab;
    --accent-dark: #6fd2c0;
    --accent-soft: #123330;
    --ok: #5ec98c;
    --ok-soft: #12291f;
    --bad: #ff8f82;
    --bad-soft: #2c1a18;
    --warn: #f0a868;
    --warn-soft: #2b2016;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-dark); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text-ok { color: var(--ok); }
.text-bad { color: var(--bad); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- layout */
.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
  padding: 0 16px 24px;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}

.topbar__mark {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  flex: none;
}

.topbar__name { font-size: 1rem; letter-spacing: -.01em; }

@media (max-width: 480px) {
  .topbar__name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

.topbar__nav {
  display: flex;
  gap: 2px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar__nav::-webkit-scrollbar { display: none; }

.topbar__nav a {
  padding: 8px 11px;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
}
.topbar__nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); }

/* --------------------------------------------------------------- usermenu */
.usermenu { position: relative; flex: none; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }

.usermenu__initials {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
}

.usermenu__panel {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  width: 236px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.usermenu__panel a { display: block; padding: 8px 0; font-size: .9rem; }
.usermenu__name { margin: 0; font-weight: 700; }
.usermenu__role { margin: 2px 0 8px; font-size: .8rem; color: var(--muted); }

.envstrip {
  margin: 0;
  padding: 6px 16px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: .78rem;
  text-align: center;
}

/* -------------------------------------------------------------- pagehead */
.pagehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 18px;
}
.pagehead--tight { margin-bottom: 12px; }
.pagehead__eyebrow { margin: 0 0 2px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pagehead__title { font-size: 1.45rem; letter-spacing: -.02em; }
.pagehead__sub { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); color: #fff; }
.btn--ghost { border-color: var(--line); color: var(--ink-2); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: 1rem; }
.btn--tiny { min-height: 34px; padding: 0 12px; font-size: .8rem; border-color: var(--line); }

/* ---------------------------------------------------------------- alerts */
.alert {
  margin: 0 0 16px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  font-size: .9rem;
}
.alert--ok    { background: var(--ok-soft);   border-color: var(--ok);   color: var(--ok); }
.alert--error { background: var(--bad-soft);  border-color: var(--bad);  color: var(--bad); }
.alert--warn  { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

/* ---------------------------------------------------------------- fields */
.stack { display: grid; gap: 14px; }

.field { display: block; }
.field__label {
  display: block;
  margin-bottom: 5px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-2);
}
.field__input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}
.field__input:focus { border-color: var(--accent); }
textarea.field__input { min-height: 64px; resize: vertical; }
.field--inline { flex: 1 1 150px; min-width: 130px; }

.checkline { display: flex; align-items: center; gap: 9px; font-size: .9rem; color: var(--ink-2); }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 18px;
}
.filterbar .btn { min-height: var(--tap); }

.inline-form { display: inline; }

/* ------------------------------------------------------------------ auth */
.auth { display: grid; place-items: center; min-height: 78vh; padding: 20px 0; }
.auth__card {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth__mark {
  display: block;
  width: 40px; height: 40px;
  margin-bottom: 16px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}
.auth__title { font-size: 1.3rem; letter-spacing: -.02em; }
.auth__sub { margin: 6px 0 20px; color: var(--muted); font-size: .9rem; }
.auth__demo {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font-size: .82rem;
  color: var(--muted);
}
.auth__demo-title { margin: 0 0 6px; font-weight: 700; color: var(--ink-2); }
.auth__demo ul { margin: 0; padding-left: 18px; }
.auth__demo li { margin-bottom: 3px; }

/* ----------------------------------------------------------------- cards */
.cardgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card--done { border-left: 4px solid var(--ok); }
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card__eyebrow { margin: 0 0 2px; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.card__title { font-size: 1.1rem; }
.card__meta { margin: 0; font-size: .82rem; color: var(--muted); }
.card__actions { display: flex; gap: 8px; margin-top: auto; }
.card__actions .btn { flex: 1; }

/* ----------------------------------------------------------------- pills */
.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--line);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill--ok, .pill--sent { background: var(--ok-soft); color: var(--ok); }
.pill--pending, .pill--queued { background: var(--warn-soft); color: var(--warn); }
.pill--failed { background: var(--bad-soft); color: var(--bad); }
.pill--skipped { background: var(--line); color: var(--muted); }
.pill--button { border: 0; cursor: pointer; font: inherit; font-size: .74rem; font-weight: 700; padding: 6px 14px; }

/* ----------------------------------------------------------------- stats */
.statrow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.card .statrow { margin-bottom: 0; border: 0; padding: 0; background: none; }
.statrow--lg { padding: 16px; }
.stat { text-align: center; }
.stat__value { display: block; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.statrow--lg .stat__value { font-size: 1.7rem; }
.stat__value--ok { color: var(--ok); }
.stat__value--bad { color: var(--bad); }
.stat__label { display: block; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------------------------------------------------------------- panels */
.panel {
  padding: 16px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel--narrow { max-width: 420px; }
.panel__title { font-size: 1rem; margin-bottom: 10px; }
.panel .filterbar { margin-bottom: 0; }

.provider { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.provider__label { margin: 0; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.provider__name { margin: 2px 0 0; font-weight: 700; }

.kv { list-style: none; margin: 12px 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.kv li:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv--inline { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.kv--inline li { border: 0; padding: 0; gap: 6px; }

/* ---------------------------------------------------------------- tables */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ---------------------------------------------------- marking (the core) */
.markform { padding-bottom: 88px; }

.bulkbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: .82rem;
  color: var(--muted);
}
.bulkbar__label { font-weight: 600; }

.roster { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }

.roster__item {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "who" "seg" "rem";
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

@media (min-width: 560px) {
  .roster__item {
    grid-template-columns: 1fr auto;
    grid-template-areas: "who seg" "rem rem";
    gap: 8px 12px;
  }
}
.roster__item[data-state="absent"]  { border-color: var(--bad); background: var(--bad-soft); }
.roster__item[data-state="late"]    { border-color: var(--warn); }
.roster__item[data-state="excused"] { border-color: var(--muted); }

.roster__who {
  grid-area: who;
  min-width: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 7px;
}
.roster__roll {
  min-width: 22px;
  font-size: .76rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.roster__name { font-weight: 600; flex: 1 1 auto; min-width: 0; }
.roster__parent { flex: none; font-size: .74rem; color: var(--muted); }

@media (min-width: 560px) {
  .roster__who { display: block; }
  .roster__roll { display: inline-block; margin-right: 7px; }
  .roster__parent { display: block; margin-top: 2px; }
}

.segmented {
  grid-area: seg;
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--bg);
  border-radius: 10px;
}
.segmented__opt { position: relative; flex: 1 1 0; }

@media (min-width: 560px) {
  .segmented__opt { flex: none; }
}
.segmented__opt input {
  position: absolute;
  opacity: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}
.segmented__opt span {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 9px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
  white-space: nowrap;
}
.segmented__opt input:checked + span { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented__opt--present input:checked + span { color: var(--ok); }
.segmented__opt--absent  input:checked + span { color: var(--bad); }
.segmented__opt--late    input:checked + span { color: var(--warn); }
.segmented__opt--excused input:checked + span { color: var(--ink-2); }
.segmented__opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

.roster__remark {
  grid-area: rem;
  display: none;
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.roster__item[data-state="absent"] .roster__remark,
.roster__item[data-state="late"] .roster__remark,
.roster__item[data-state="excused"] .roster__remark,
.roster__remark:not(:placeholder-shown) { display: block; }

.submitbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 20px rgba(16, 40, 38, .08);
}
.submitbar__counts { display: flex; flex-direction: column; gap: 2px; font-size: .78rem; color: var(--muted); flex: none; }
.tally { white-space: nowrap; }
.tally b { font-size: .95rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.submitbar .btn--lg { flex: 1 1 auto; }

@media (max-width: 400px) {
  .submitbar .btn--lg { font-size: .9rem; padding: 0 12px; }
}
.tally--ok b { color: var(--ok); }
.tally--bad b { color: var(--bad); }

@media (min-width: 520px) {
  .submitbar__counts { flex-direction: row; gap: 16px; }
}

/* --------------------------------------------------------------- receipt */
.receipt { max-width: 520px; margin: 0 auto; text-align: center; }
.receipt__badge {
  display: grid;
  place-items: center;
  width: 66px; height: 66px;
  margin: 8px auto 16px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
}
.receipt__title { font-size: 1.4rem; letter-spacing: -.02em; }
.receipt__sub { margin: 6px 0 20px; color: var(--muted); font-size: .9rem; }
.receipt__panel {
  margin-bottom: 14px;
  padding: 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.receipt__panel--alert { border-left: 4px solid var(--bad); }
.receipt__h2 { font-size: .95rem; margin-bottom: 8px; }
.receipt__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }

.absentlist { list-style: none; margin: 0; padding: 0; }
.absentlist li { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.absentlist li:last-child { border-bottom: 0; }
.absentlist__roll { min-width: 28px; font-weight: 700; color: var(--muted); font-size: .78rem; }
.absentlist__name { flex: 1; }
.absentlist__phone { font-size: .78rem; color: var(--muted); }

/* -------------------------------------------------------------- messages */
.msglist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.msg {
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
}
.msg--sent { border-left-color: var(--ok); }
.msg--failed { border-left-color: var(--bad); }
.msg--skipped { border-left-color: var(--muted); }
.msg--queued { border-left-color: var(--warn); }
.msg__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 7px; }
.msg__who { font-weight: 600; font-size: .92rem; }
.msg__meta { margin-left: auto; font-size: .76rem; color: var(--muted); }
.msg__body { margin: 0; font-size: .87rem; color: var(--ink-2); line-height: 1.45; }
.msg__foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 9px; }
.msg__error { font-size: .78rem; color: var(--bad); }

/* ----------------------------------------------------------------- empty */
.empty {
  padding: 44px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty h1, .empty h2 { font-size: 1.1rem; margin-bottom: 6px; }
.empty p { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.empty__code { margin: 0 0 8px; font-size: 2.6rem; font-weight: 800; color: var(--line); letter-spacing: -.03em; }

/* ----------------------------------------------------------------- print */
@media print {
  .topbar, .submitbar, .footer, .envstrip, .btn, .filterbar { display: none !important; }
  body { background: #fff; }
  .panel, .card { box-shadow: none; border-color: #ccc; }
}

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