/*
 * Project Samarthya — stylesheet.
 *
 * Deliberately plain. The brief asked for bare-minimum UI, and the real design
 * constraints here are physical, not visual:
 *
 *   - Doctors work standing up, on tablets, without breaks. Tap targets are large
 *     (44px minimum) and spacing is generous, because a mis-tap costs more time than
 *     a slightly bigger screen does.
 *   - The same page runs on a phone, a tablet and a laptop, so everything is fluid.
 *   - A school hall is bright. Contrast is high; nothing relies on subtle greys.
 *   - No web fonts, no images, no external anything — this must work with the
 *     network unplugged.
 */

:root {
  --ink: #14181f;
  --ink-soft: #5b6470;
  --line: #d4d9e0;
  --bg: #ffffff;
  --bg-soft: #f5f7fa;
  --brand: #1a5fb4;
  --brand-dark: #144a8c;
  --ok: #0a7a2f;
  --ok-bg: #e6f5eb;
  --warn: #a56500;
  --warn-bg: #fff8e6;
  --bad: #c11414;
  --bad-bg: #fdeaea;
  --radius: 6px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-soft);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Stops iOS inflating text in landscape, which would reflow the form mid-entry. */
  -webkit-text-size-adjust: 100%;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1rem;
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; letter-spacing: .01em; }
.topbar .brand span { font-weight: 400; opacity: .7; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a {
  color: #fff; text-decoration: none; padding: .35rem .7rem;
  border-radius: var(--radius); font-size: .92rem; opacity: .85;
}
.topbar nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.topbar nav a.on { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .88rem; opacity: .8; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.wrap.narrow { max-width: 680px; }

h1 { font-size: 1.4rem; margin: 0 0 .3rem; }
h2 { font-size: 1.1rem; margin: 1.8rem 0 .6rem; }
.lede { color: var(--ink-soft); margin: 0 0 1.4rem; }

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1.1rem;
}

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

label, .flabel {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .3rem;
}
.hint { color: var(--ink-soft); font-size: .82rem; font-weight: 400; margin-top: .2rem; }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=tel], input[type=search], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(26,95,180,.35);
  outline-offset: 0;
  border-color: var(--brand);
}
textarea { min-height: 5rem; resize: vertical; }

.field { margin-bottom: 1.15rem; }

/* Numeric input with its unit fixed alongside. The unit is a label, never a
   dropdown: making the doctor choose "cm" every time would cost a tap per field. */
.numwrap { display: flex; align-items: stretch; }
.numwrap input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.numwrap .unit {
  display: flex; align-items: center; padding: 0 .8rem;
  background: var(--bg-soft);
  border: 1px solid var(--line); border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .92rem; color: var(--ink-soft); white-space: nowrap;
}

/* Blood pressure: two linked boxes rather than free text, so 120/80 cannot be
   typed as "120 over 80" or transposed without the server noticing. */
.bpwrap { display: flex; align-items: center; gap: .5rem; }
.bpwrap input { text-align: center; }
.bpwrap .slash { font-size: 1.4rem; color: var(--ink-soft); }

/* Tap chips replace radio buttons and dropdowns throughout. One tap, no menu,
   and a target big enough to hit without looking. */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: .45rem .9rem;
  border: 1.5px solid var(--line); border-radius: 99px;
  background: #fff; color: var(--ink);
  font-size: .97rem; cursor: pointer; user-select: none;
  transition: none;   /* instant feedback; animation reads as lag under a fast hand */
}
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.chip.on.neutral { background: var(--ok); border-color: var(--ok); }

.computed {
  font-size: 1.35rem; font-weight: 700;
  padding: .5rem .8rem; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.computed .band { font-size: .85rem; font-weight: 600; margin-left: .5rem; color: var(--ink-soft); }

.fieldgroup {
  border-left: 3px solid var(--line);
  padding-left: .9rem;
  margin-bottom: 1rem;
}
.fieldgroup > .grouptitle {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-soft); font-weight: 700; margin-bottom: .7rem;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: .55rem 1.3rem;
  border: 0; border-radius: var(--radius);
  background: var(--brand); color: #fff;
  font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
  /* Labels stay on one line. "+ Student" wrapping to "+ / Student" halves the
     effective tap target and makes a row of actions look broken. */
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary, button.secondary {
  background: #fff; color: var(--ink); border: 1px solid var(--line);
}
.btn.secondary:hover, button.secondary:hover { background: var(--bg-soft); }
.btn.danger, button.danger { background: var(--bad); }
.btn.big { font-size: 1.1rem; padding: .8rem 1.8rem; }
.btn.full { width: 100%; }

.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.2rem; }

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */

.msg { padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; border-left: 3px solid; }
.msg.ok { background: var(--ok-bg); border-color: var(--ok); color: #08561f; }
.msg.warn { background: var(--warn-bg); border-color: var(--warn); color: #7a4b00; }
.msg.bad { background: var(--bad-bg); border-color: var(--bad); color: #8e1010; }
.msg ul { margin: .4rem 0 0; padding-left: 1.1rem; }

.field.haserror input, .field.haserror textarea { border-color: var(--bad); }
.field .err { color: var(--bad); font-size: .85rem; margin-top: .25rem; font-weight: 600; }
.field .warnmsg { color: var(--warn); font-size: .85rem; margin-top: .25rem; font-weight: 600; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
th { background: var(--bg-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
tbody tr:hover { background: var(--bg-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 99px;
  font-size: .78rem; font-weight: 700;
}
.badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.part { background: var(--warn-bg); color: var(--warn); }
.badge.todo { background: var(--bg-soft); color: var(--ink-soft); }
.badge.ref  { background: var(--bad-bg); color: var(--bad); }

/* --------------------------------------------------------------------------
   Station app
   -------------------------------------------------------------------------- */

.station-head {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.station-head .stname { font-weight: 700; font-size: 1.05rem; }
.station-head .evname { color: var(--ink-soft); font-size: .88rem; }

/* The sync indicator is never hidden. A doctor must be able to tell at a glance
   that nothing is stuck on the device, without being interrupted by it. */
.syncdot {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .3rem .7rem; border-radius: 99px;
  font-size: .83rem; font-weight: 600;
}
.syncdot::before { content: ''; width: .6rem; height: .6rem; border-radius: 50%; background: currentColor; }
.syncdot.synced { background: var(--ok-bg); color: var(--ok); }
.syncdot.pending { background: var(--warn-bg); color: var(--warn); }
.syncdot.offline { background: var(--bad-bg); color: var(--bad); }

/* Who am I, and how do I get out — present on every screen including the picker,
   because tablets get handed between people during a camp. */
.userbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .7rem .9rem; margin-bottom: 1.2rem;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
}

/* The school is the heading on the picker, not a footnote: it is the first thing a
   doctor arriving at a camp needs to confirm before recording anything. */
.schoolhead { border-left: 4px solid var(--brand); padding-left: .8rem; }
.schoolhead .schoolname { font-size: 1.15rem; font-weight: 700; line-height: 1.25; }
.schoolhead .schoolmeta { color: var(--ink-soft); font-size: .87rem; margin-top: .15rem; }

/* Station picker row. "Station 4" means nothing to someone walking in, so the row
   spells out the sections it covers. */
.qrow.stationpick { align-items: flex-start; padding: .8rem .9rem; }
.stnum {
  flex-shrink: 0; width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: .95rem;
}
.stbody { display: flex; flex-direction: column; gap: .25rem; min-width: 0; flex: 1; }
.stlabel { font-weight: 600; }
.stsections { color: var(--ink-soft); font-size: .86rem; line-height: 1.35; }
.sttags { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .1rem; }

/* Station / All-records switch in the header. */
.sh-tabs { display: flex; gap: .25rem; }
.sh-tabs .tab {
  min-height: 36px; padding: .3rem .8rem; font-size: .88rem; font-weight: 600;
  background: transparent; color: var(--ink-soft); border: 1px solid transparent;
}
.sh-tabs .tab:hover { background: var(--bg-soft); color: var(--ink); }
.sh-tabs .tab.on { background: var(--brand); color: #fff; }

.sh-id { min-width: 0; }
.sh-user { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.sh-user .whoami { font-size: .85rem; color: var(--ink-soft); }
button.small, .btn.small { min-height: 34px; padding: .25rem .7rem; font-size: .85rem; }

tr.rowlink { cursor: pointer; }

/* Field marks. A hard-required field stops the save; an "expected" one does not —
   the distinction has to be visible or a doctor will not know which blanks they are
   allowed to leave when the queue is backing up. */
.req { color: var(--bad); font-weight: 700; }
.exp {
  font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--warn); background: var(--warn-bg);
  padding: .05rem .35rem; border-radius: 3px; vertical-align: middle;
}

/* What a station still owes for someone, shown inline on the queue row so it is
   actionable without opening the record. */
.gaps {
  display: block; font-size: .78rem; color: var(--bad); font-weight: 600;
  margin-top: .1rem; white-space: normal;
}

.queue { display: grid; gap: .5rem; }
/* A queue row is a <button>, so it inherits `color:#fff` from the base button rule.
   The colour MUST be restated here or every row renders white-on-white — invisible to
   a reader while still present in the DOM, so no automated check would notice. */
.qrow {
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem .9rem; background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-align: left; width: 100%; min-height: var(--tap);
  /* Undoes the nowrap on plain buttons: a queue row is a multi-line block, and
     keeping it on one line forces the page to scroll sideways on a phone. */
  white-space: normal;
}
.qrow:hover { border-color: var(--brand); background: #fff; }
.qrow .qid { font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.qrow .qname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qrow .qmeta { color: var(--ink-soft); font-size: .85rem; white-space: nowrap; }
.qrow.done { opacity: .55; }

/* The ID a student reads out. Large and monospaced so it can be checked at a
   glance and read aloud across a noisy hall without ambiguity. */
.bigid {
  font-size: 1.6rem; font-weight: 700; letter-spacing: .02em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.searchbar input { font-size: 1.15rem; flex: 1 1 12rem; min-width: 0; }

.disclaimer {
  color: var(--ink-soft); font-size: .8rem; text-align: center;
  padding: 1.5rem 1rem .5rem; font-style: italic;
}

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-soft); }

.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--ink-soft); font-size: .85rem; margin-top: .2rem; }

/* Distribution readout for the dashboard. No canvas, no charting library — it has to
   render with the network unplugged.

   The label sits ABOVE its bar rather than beside it. Side-by-side looks tidier in
   isolation, but these cards sit in a responsive grid roughly 280px wide: a fixed
   label column plus a value column left the track with no room at all and the bars
   vanished entirely. Stacking means the track always spans the full card, at any
   width, on any device. */
.bar { margin-bottom: .7rem; font-size: .9rem; }
.bar .barhead {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: .6rem; margin-bottom: .25rem;
}
.bar .barlabel { min-width: 0; overflow-wrap: anywhere; }
.bar .barval { flex-shrink: 0; font-variant-numeric: tabular-nums; font-weight: 700; }
.bar .bartrack { background: var(--bg-soft); border-radius: 99px; height: .6rem; overflow: hidden; }
.bar .barfill { height: 100%; background: var(--brand); border-radius: 99px; min-width: 2px; }

@media (max-width: 640px) {
  .wrap { padding: 1rem .7rem 3rem; }
  .topbar { gap: .5rem; }
  .bar .barlabel { width: 7rem; font-size: .82rem; }
}

@media print {
  .topbar, .station-head, .actions, .searchbar { display: none; }
  body { background: #fff; }
  .card { border: 1px solid #999; break-inside: avoid; }
}
