/* STEMquest Class Tracker. Brand colours taken from stemquest.ca:
   blue #005DAC, light blue #4086C1, orange #FF9900, green #3A854B, page grey #F6F6F8, text #303030 */
:root {
  --blue: #005dac;
  --blue-2: #4086c1;
  --blue-soft: #e6f0f9;
  --orange: #ff9900;
  --orange-soft: #fff3e0;
  --green: #3a854b;
  --green-soft: #e7f3ea;
  --red: #c62828;
  --bg: #f6f6f8;
  --card: #ffffff;
  --text: #303030;
  --muted: #6b6f76;
  --line: #e2e4e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 61, 113, .07);
  --head: 'Palanquin Dark', 'Roboto', system-ui, sans-serif;
  --body: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ink-blue: #005dac;     /* blue used for text */
  --orange-ink: #8a5300;   /* orange used for text */
  --input: #ffffff;
  --grey-soft: #eef0f2;
  --hover: #fafbfc;
  --absent: #fafafa;
  color-scheme: light;
}
/* Dark mode: same STEMquest blue/orange/green, on a deep navy background. */
:root[data-theme='dark'] {
  --blue: #1a6fc0;
  --blue-2: #5a9fd8;
  --blue-soft: #16304b;
  --orange-soft: #3a2a12;
  --green: #3f9a55;
  --green-soft: #173323;
  --red: #ef6b6b;
  --bg: #0e1622;
  --card: #172231;
  --text: #e6ebf1;
  --muted: #9aa6b4;
  --line: #2a3a4e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .25);
  --ink-blue: #7fb9ee;
  --orange-ink: #ffbe5c;
  --input: #101a27;
  --grey-soft: #243246;
  --hover: #1d2a3b;
  --absent: #131d2a;
  color-scheme: dark;
}
/* The logo's blue lettering needs a light backing on dark backgrounds. */
:root[data-theme='dark'] .brand img,
:root[data-theme='dark'] .auth-logo { background: #fff; border-radius: 10px; padding: 3px 8px; }
:root[data-theme='dark'] .auth { background: radial-gradient(1200px 500px at 50% -10%, #16304b, transparent), var(--bg); }
.theme-btn { appearance: none; border: 0; background: transparent; cursor: pointer; font-size: 1.15rem; padding: 8px; border-radius: 999px; line-height: 1; }
.theme-btn:hover { background: var(--blue-soft); }
.auth-theme { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px; z-index: 5; }
.seg { display: inline-flex; background: var(--grey-soft); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { appearance: none; border: 0; font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 9px; cursor: pointer; background: transparent; color: var(--text); }
.seg button.on { background: var(--card); color: var(--ink-blue); box-shadow: var(--shadow); }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: var(--head); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; color: var(--ink-blue); }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--ink-blue); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: var(--card); border-bottom: 3px solid var(--orange);
}
.brand img { height: 40px; display: block; }
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav a { text-decoration: none; font-weight: 500; padding: 8px 12px; border-radius: 999px; color: var(--text); font-size: .95rem; }
.topnav a.active { background: var(--blue-soft); color: var(--ink-blue); }
.topnav .me { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; }

.app { max-width: 980px; margin: 0 auto; padding: 22px 16px 80px; }
.app.bare { max-width: none; padding: 0; }
.loading { color: var(--muted); padding: 60px 0; text-align: center; }

/* ---------- avatars ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--blue-soft); display: inline-grid; place-items: center;
  color: var(--ink-blue); font-family: var(--head); font-weight: 700; overflow: hidden;
}
.avatar.sm { width: 32px; height: 32px; font-size: .85rem; }
.avatar.lg { width: 96px; height: 96px; font-size: 2rem; }

/* ---------- cards, buttons, forms ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; text-decoration: none; min-height: 44px;
  background: var(--blue); color: #fff; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.orange { background: var(--orange); color: #1f1300; }
.btn.green { background: var(--green); }
.btn.ghost { background: transparent; color: var(--ink-blue); border: 2px solid var(--blue-soft); }
.btn.danger { background: transparent; color: var(--red); border: 2px solid #f5d0d0; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: default; }

label.field { display: block; }
label.field > span { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 5px; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--input); min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue-2); box-shadow: 0 0 0 3px var(--blue-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.error { color: var(--red); font-weight: 500; min-height: 1.2em; font-size: .92rem; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 500px at 50% -10%, var(--blue-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { display: block; width: 240px; max-width: 80%; margin: 0 auto 6px; }
.mascots { display: flex; justify-content: center; gap: 4px; margin: 4px 0 10px; }
.mascots img { height: 74px; }
.auth h1 { text-align: center; font-size: 1.4rem; }
.auth .switch { text-align: center; margin-top: 14px; }

/* ---------- home ---------- */
.hello { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.hello img.mascot { height: 70px; }
.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.class-card { display: block; text-decoration: none; color: inherit; border-top: 5px solid var(--blue); position: relative; }
.class-card.p-spike_essential { border-top-color: var(--orange); }
.class-card.p-scratch { border-top-color: var(--green); }
.class-card.p-other { border-top-color: var(--blue-2); }
.class-card h3 { margin-bottom: 2px; }
.class-card .mascot { position: absolute; right: 12px; top: 12px; height: 54px; }
.class-card .meta { padding-right: 56px; }
.chip { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--blue-soft); color: var(--ink-blue); }
.chip.orange { background: var(--orange-soft); color: var(--orange-ink); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.grey { background: var(--grey-soft); color: var(--muted); }
.empty { text-align: center; padding: 36px 18px; }
.empty img { height: 110px; }

/* ---------- class page ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-weight: 500; }
.cols { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a.item, .list .item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 2px; text-decoration: none; color: inherit; }
.list a.item:hover { background: var(--hover); }
.kid-dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none;
  background: var(--orange-soft); color: var(--orange-ink); }
.inline-add { display: flex; gap: 8px; margin-top: 10px; }
.inline-add input { flex: 1; }

/* ---------- weekly tracker ---------- */
.week-head { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.build-field { display: flex; align-items: center; gap: 10px; background: var(--orange-soft); border-radius: 12px; padding: 8px 12px; }
.build-field b { font-family: var(--head); color: var(--orange-ink); font-size: 1.15rem; white-space: nowrap; }
.build-field input { border: 0; background: transparent; font-size: 1.15rem; font-weight: 500; padding: 6px 4px; box-shadow: none; }
.build-field input:focus { box-shadow: none; }
/* "Build done this class" tick, sitting inside the Build field */
.done-check {
  position: relative; flex: none; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 7px 12px; border-radius: 999px; border: 2px solid var(--orange); color: var(--orange-ink);
  font-weight: 700; font-size: .9rem; white-space: nowrap; background: var(--card); user-select: none;
}
.done-check input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; min-height: 0; }
.done-check.on { background: var(--green); border-color: var(--green); color: #fff; }
.done-check:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--blue-soft); }
.savebar {font-size: .88rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.savebar.saving { color: var(--blue-2); }
.savebar.saved { color: var(--green); }
.savebar.err { color: var(--red); }
.counts { display: flex; gap: 8px; flex-wrap: wrap; }
.kid {
  display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center;
  padding: 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--card);
}
.kid + .kid { margin-top: 10px; }
.kid.absent { background: var(--absent); }
.kid.absent .kid-fields { opacity: .45; }
.present-btn {
  width: 46px; height: 46px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); cursor: pointer;
  font-size: 1.3rem; display: grid; place-items: center; color: var(--muted);
}
.kid.here .present-btn { background: var(--green); border-color: var(--green); color: #fff; }
.kid-name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kid-name a { color: inherit; text-decoration: none; }
.kid-name a:hover { text-decoration: underline; }
.kid-fields { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }
.kid-fields label span { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; display: block; margin-bottom: 3px; }
.kid-fields input { min-height: 40px; padding: 8px 10px; }
.kid-note { grid-column: 1 / -1; }
.kid-note textarea { min-height: 42px; padding: 8px 10px; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.prev-plan { background: var(--blue-soft); border-radius: 12px; padding: 10px 14px; font-size: .93rem; }
.prev-plan b { color: var(--ink-blue); }

/* ---------- history table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }

/* ---------- manager dashboard ---------- */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--green); font-weight: 700; }
.live::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.dash-class { border-left: 5px solid var(--blue); }
.dash-class.fresh { animation: flash 2.5s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--orange); } 100% { box-shadow: var(--shadow); } }
.dash-class .who { display: flex; align-items: center; gap: 8px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.feed li { padding: 8px 0; font-size: .92rem; }

/* ---------- birthday parties ---------- */
.avatar.xs { width: 22px; height: 22px; font-size: .62rem; }
.party-card { border-top-color: var(--orange); }
.party-emoji { position: absolute; right: 14px; top: 10px; font-size: 2.3rem; }
.host-note { background: var(--orange-soft); border-left: 4px solid var(--orange); border-radius: 10px; padding: 10px 14px; font-size: .95rem; }
.host-note b { color: var(--orange-ink); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 9.5em 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline .t { font-weight: 700; color: var(--ink-blue); }
.lootbag { font-size: 1.2rem; font-weight: 700; }
table.guests td { vertical-align: middle; }
table.guests input[data-f=comment] { min-height: 36px; padding: 6px 9px; }
.waiver input { width: 22px; height: 22px; min-height: 0; accent-color: var(--green); cursor: pointer; }
.pill-check { position: relative; cursor: pointer; }
.pill-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill-check span { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); font-weight: 500; }
.pill-check input:checked + span { background: var(--blue-soft); border-color: var(--blue-2); color: var(--ink-blue); }
.pill-check input:focus-visible + span { box-shadow: 0 0 0 3px var(--blue-soft); }
.sched-row { display: grid; grid-template-columns: 8.5em 8.5em 1fr auto; gap: 8px; margin-bottom: 8px; }
@media (max-width: 560px) {
  .sched-row { grid-template-columns: 1fr 1fr auto; }
  .sched-row [data-s=text] { grid-column: 1 / 3; grid-row: 2; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- party sheet import ---------- */
.import-box { border: 2px dashed var(--blue-2); border-radius: 12px; padding: 12px 14px; background: var(--blue-soft); }
.import-result { margin-top: 10px; font-size: .92rem; display: grid; gap: 4px; }
.import-result .warn { color: var(--orange-ink); font-weight: 500; }

/* ---------- staff page ---------- */
.staff-row { padding-bottom: 10px; }
.staff-actions { padding-left: 42px; gap: 6px; }
.temp-pw { font-size: 1.1rem; font-weight: 700; background: var(--card); padding: 6px 10px; border-radius: 8px; user-select: all; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px);
  background: #1d2733; color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 500; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 50; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .cols, .summary-grid { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .week-head { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
  .brand img { height: 32px; }
  .topnav .label { display: none; }
  .topnav a { font-size: 1.15rem; }
  .topnav a { padding: 8px 9px; }
}
@media (max-width: 420px) {
  .kid-fields { grid-template-columns: 1fr 1fr; }
  .kid-fields label.step { grid-column: 1 / -1; }
  .grid2 { grid-template-columns: 1fr; }
}
