/*
 * Pakkelogg design system.
 *
 * Field-first: outdoors, one-handed, in glare. So: a light, high-contrast
 * default theme; near-black text (AAA / 7:1); one accent for the primary
 * action; large (>=48px) tap targets in the thumb zone; state never signalled
 * by colour alone (text + shape back every colour cue). Hand-rolled, no
 * framework.
 */

/* ---- Design tokens ------------------------------------------------------ */
:root {
  /* Surfaces — light, warm, non-glossy so it reads in sunlight. */
  --bg:            #f7f7f5;
  --surface:       #ffffff;
  --surface-sunk:  #eeeeec;
  --border:        #c9c9c4;
  --border-strong: #8a8a83;

  /* Ink — near-black on light for AAA contrast. */
  --ink:          #14140f; /* ~16:1 on --bg  */
  --ink-soft:     #3d3d36; /* ~9:1  on --bg  */
  --ink-faint:    #55554d; /* ~7:1  on --bg  */

  /* Accent — the single primary-action colour (deep blue, AAA on white text). */
  --accent:        #1f4bd8;
  --accent-strong: #17389f;
  --accent-ink:    #ffffff;

  /* Semantic. */
  --success:       #0f6d3d; /* exam-ready / done */
  --success-strong:#0a4f2c;
  --warn:          #8a4b00; /* dormant, going-inactive */
  --danger:        #a11020; /* destructive admin actions */

  /* Level-bar snag levels (5-6): a distinct, high-contrast marker. */
  --snag:          #8a4b00;

  --radius:       12px;
  --radius-sm:    8px;
  --tap:          48px;   /* minimum tap target */
  --tap-lg:       60px;   /* primary field actions (thumb zone) */
  --gap:          16px;
  --container:    640px;

  --shadow:       0 1px 2px rgba(20, 20, 15, .08), 0 2px 8px rgba(20, 20, 15, .06);
  --focus:        0 0 0 3px #ffffff, 0 0 0 6px var(--accent);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Reset / base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  /* Room for the fixed bottom tab bar + iOS home indicator. */
  padding-bottom: calc(var(--tap-lg) + 24px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 .6em; }

a { color: var(--accent-strong); }

/* Visible, generous focus everywhere — field use with gloves/glare. */
:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--radius-sm);
}

img, svg { max-width: 100%; height: auto; }

/* ---- Accessibility helpers --------------------------------------------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
  box-shadow: var(--focus);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---- Layout ------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--gap);
}

/* ---- Top bar ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 12px var(--gap);
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  min-height: var(--tap);
}
.brand-mark { color: var(--accent); font-size: 1.1rem; }
.brand-name { letter-spacing: .2px; }
.topbar-admin {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 12px;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.topbar-admin[aria-current="page"] { color: var(--accent-strong); }

/* ---- Flash message ------------------------------------------------------ */
.flash {
  max-width: var(--container);
  margin: var(--gap) auto 0;
  padding: 12px 16px;
  background: #e9f0ff;
  border: 1px solid var(--accent);
  border-left-width: 5px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-weight: 600;
}

/* ---- Cards -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.student-card {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 12px;
  overflow: hidden;
}
.student-card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
}
.student-card-body:hover { background: var(--surface-sunk); }
.student-name {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.student-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--ink-faint);
  font-size: .95rem;
}
/* The dedicated per-card log affordance (right edge, thumb-reachable). */
.student-card-log {
  flex: 0 0 auto;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  min-width: 64px;
  flex-direction: column;
  gap: 2px;
}
.student-card-log .btn-icon { font-size: 1.4rem; line-height: 1; }
.student-card-log .btn-text { font-size: .8rem; }

/* ---- Level bar (the product's visual signature) ------------------------ */
.levelbar { margin: 4px 0; }
.levelbar-track {
  display: flex;
  gap: 4px;
  height: 14px;
}
.seg {
  flex: 1 1 0;
  border-radius: 3px;
  background: var(--surface);
  border: 2px solid var(--border-strong); /* outlined empties stay visible in glare */
}
.seg-filled {
  background: var(--accent);
  border-color: var(--accent-strong);
}
/* Snag levels (5-6): a hatched top marker + warm border so "the hard ones"
   read without relying on colour alone. */
.seg-snag {
  border-color: var(--snag);
}
.seg-snag.seg-filled {
  background: var(--accent);
  /* diagonal notch signalling a snag segment, independent of colour */
  background-image: repeating-linear-gradient(
    45deg, transparent, transparent 3px,
    rgba(255, 255, 255, .55) 3px, rgba(255, 255, 255, .55) 5px);
}
/* Exam-ready: whole bar switches to the success colour. */
.seg-exam.seg-filled {
  background: var(--success);
  border-color: var(--success-strong);
}
.seg-exam.seg-snag.seg-filled {
  background-image: repeating-linear-gradient(
    45deg, transparent, transparent 3px,
    rgba(255, 255, 255, .55) 3px, rgba(255, 255, 255, .55) 5px);
}
.levelbar-text {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0;
  font-size: .95rem;
}
.levelbar-num { font-weight: 700; color: var(--ink); }

/* ---- Tags / badges ------------------------------------------------------ */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag-exam   { background: #dcefe4; color: var(--success-strong); border-color: var(--success); }
.tag-done   { background: var(--surface-sunk); color: var(--ink-soft); border-color: var(--border-strong); }
.tag-dormant{ background: #f4e7d3; color: var(--warn); border-color: var(--warn); }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-sunk); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-strong); }

.btn-log {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
}
.btn-log:hover { background: var(--accent-strong); }

.btn-success {
  background: var(--success);
  border-color: var(--success-strong);
  color: #fff;
}
.btn-success:hover { background: var(--success-strong); }

.btn-danger {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

/* Big primary field action — the "Log Level N" button lives in the thumb zone. */
.btn-lg {
  width: 100%;
  min-height: var(--tap-lg);
  font-size: 1.15rem;
  border-radius: var(--radius);
}
.btn-block { width: 100%; }

/* ---- Forms -------------------------------------------------------------- */
.field { margin-bottom: var(--gap); }
.field > label,
.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: var(--ink);
}
.field-hint { display: block; margin-top: 4px; color: var(--ink-faint); font-size: .9rem; }
.req { color: var(--danger); }

input[type="text"],
input[type="search"],
input[type="date"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
textarea { min-height: 96px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
}

/* Checkbox / radio scaled up + wrapped in a full-width tap row. */
.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: var(--tap);
  padding: 8px 0;
  cursor: pointer;
}
.check input[type="checkbox"],
.check input[type="radio"] {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin-top: 2px;
  accent-color: var(--accent);
}

/* Radio-as-choice group (e.g. Level up vs Repeat) — never two look-alikes. */
.choice {
  display: block;
  padding: 16px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  margin-bottom: 12px;
}
.choice:has(input:checked) {
  border-color: var(--accent);
  background: #eef2ff;
}
.choice:has(input:focus-visible) { box-shadow: var(--focus); }
.choice-title { font-weight: 700; font-size: 1.1rem; }
.choice input { position: absolute; opacity: 0; }

/* ---- Field/validation errors ------------------------------------------- */
.form-error,
.error {
  padding: 12px 16px;
  margin-bottom: var(--gap);
  background: #fbe7e9;
  border: 1px solid var(--danger);
  border-left-width: 5px;
  border-radius: var(--radius-sm);
  color: #6b0a16;
  font-weight: 600;
}

/* ---- Snag section (only present in the DOM at levels 5-6) --------------- */
.snag-section {
  margin: var(--gap) 0;
  padding: var(--gap);
  border: 2px solid var(--snag);
  border-radius: var(--radius);
  background: #fbf3e6;
}
.snag-section > h3 { margin-top: 0; color: var(--warn); }

/* ---- Set back (corrective: log a pack returning a student to a lower level) --- */
.setback {
  margin: var(--gap) 0;
  border: 2px solid var(--warn);
  border-radius: var(--radius);
  background: #faf4ea;
  padding: 0 14px;
}
.setback > summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  gap: 8px;
  padding: 10px 2px;
  font-weight: 700;
  color: var(--warn);
  cursor: pointer;
}
.setback[open] > summary {
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.setback-hint { color: var(--ink-soft); margin: 0 0 12px; font-size: .95rem; }
.setback fieldset { border: 0; margin: 0; padding: 0; }
.setback .choice { margin-bottom: 8px; padding: 12px 14px; }

/* ---- Page header / actions --------------------------------------------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: var(--gap);
  flex-wrap: wrap;
}

/* Filter chips row. */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: var(--gap); }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
.chip[aria-current="page"],
.chip.chip-active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

/* ---- Timeline (student detail) ----------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
}
.timeline-item.is-snag { border-left: 5px solid var(--snag); }
.timeline-item.is-levelup { border-left: 5px solid var(--accent); }
.timeline-meta { color: var(--ink-faint); font-size: .9rem; }

/* ---- Empty state -------------------------------------------------------- */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-soft);
}
.empty h2 { color: var(--ink); }

/* ---- Bottom tab bar (3 items, elevated accent centre) ------------------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: end;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(20, 20, 15, .06);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap-lg);
  padding: 8px 4px;
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 600;
}
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab-label { font-size: .78rem; }
.tab-active { color: var(--accent-strong); }
.tab-active .tab-icon { color: var(--accent); }

/* Elevated, accented centre CTA. */
.tab-primary {
  color: var(--accent-ink);
}
.tab-primary .tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-top: -22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.9rem;
  box-shadow: var(--shadow);
  border: 3px solid var(--surface);
}
.tab-primary .tab-label { color: var(--accent-strong); }
.tab-primary.tab-active .tab-icon { background: var(--accent-strong); }

/* ---- Utilities ---------------------------------------------------------- */
.stack > * + * { margin-top: var(--gap); }
.muted { color: var(--ink-faint); }
.row { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; }

/* ---- Wider screens (admin on a laptop) ---------------------------------- */
@media (min-width: 720px) {
  body { font-size: 17px; }
  .container { padding: 24px var(--gap); }
}

/* Respect reduced-motion / high-contrast preferences. */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .btn:active { transform: none; }
}
@media (prefers-contrast: more) {
  :root { --border: var(--border-strong); }
  .seg { border-width: 3px; }
}
