:root {
  --brand: #0b4f8a;
  --brand-ink: #ffffff;
  --accent: #f2a900;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #637083;
  --line: #dde3ea;
  --today: #fff6dc;
  --chip: #e7eef6;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4a90d0;
    --brand-ink: #0d1117;
    --bg: #0f141a;
    --card: #18202a;
    --ink: #e6ebf1;
    --muted: #94a3b5;
    --line: #2a3542;
    --today: #33300f;
    --chip: #223040;
    --danger: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted, .hint { color: var(--muted); }
.hint { font-size: 13px; font-weight: normal; }

/* header */
.app-header { background: var(--brand); color: var(--brand-ink); padding: env(safe-area-inset-top) 16px 0; }
.header-inner { max-width: 1100px; margin: 0 auto; padding: 14px 0; display: flex; gap: 12px 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.app-header h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.app-header h1 span { color: var(--accent); }
.school-btn {
  display: flex; align-items: center; gap: 12px; min-height: 48px; width: min(380px, 100%); padding: 6px 14px;
  background: rgba(255, 255, 255, .14); color: inherit; border: 1px solid rgba(255, 255, 255, .35); border-radius: 12px; text-align: left;
}
.school-btn:hover { background: rgba(255, 255, 255, .22); }
.school-btn-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.school-btn-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; opacity: .8; }
.school-btn-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.caret { width: 14px; height: 10px; flex: none; }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 32px; }

/* kid chips */
.kid-bar { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 18px; }
.chip-wrap { display: inline-flex; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; min-height: 40px;
  font-weight: 600; font-size: 14px;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip-wrap .chip.on { border-radius: 999px 0 0 999px; }
.chip-edit { border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); border-left-color: rgba(255,255,255,.3); border-radius: 0 999px 999px 0; padding: 8px 12px 8px 10px; min-height: 40px; }
.chip.add { border-style: dashed; color: var(--brand); }
.chip.ghost { color: var(--muted); font-weight: 500; margin-left: auto; }

/* hero */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 24px; }
.hero:empty { display: none; }
.hero-card {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); width: 100%;
  display: flex; flex-direction: column; justify-content: flex-start;
}
.hero-card p { margin: 0; }
.hero-when { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: none; }
.hero-main { font-size: 19px; font-weight: 700; margin: 6px 0 4px !important; }
.hero-sides { font-size: 13px; color: var(--muted); }
.hero-tag { align-self: flex-start; margin-top: 8px !important; font-size: 12px; background: var(--chip); border-radius: 6px; padding: 1px 6px; }
.hero-evs { list-style: none; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line); font-size: 13px; }
.hero-evs li { margin: 4px 0; }

/* tabs + month nav */
.tab-bar { display: flex; gap: 4px; background: var(--chip); padding: 4px; border-radius: 12px; width: max-content; margin: 0 auto 14px; }
.tab-btn { border: 0; background: transparent; padding: 8px 28px; min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.month-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 14px; }
.nav-btn { border: 1px solid var(--line); background: var(--card); width: 44px; height: 44px; flex: none; border-radius: 50%; font-size: 22px; line-height: 1; }
.month-label { border: 0; background: none; font-size: 18px; font-weight: 700; min-width: 170px; min-height: 44px; }

/* calendar */
.weekday-row, .calendar { display: grid; gap: 8px; }
.weekday-row { margin-bottom: 6px; }
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cols-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekday-row span { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.calendar.loading { opacity: .5; }
.cell {
  min-height: 92px; text-align: left; vertical-align: top; display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px;
}
.cell.empty { background: transparent; border: 0; }
.cell.past { opacity: .55; }
.cell.today { background: var(--today); border-color: var(--accent); }
.cell.wkend { background: transparent; }
.cell.blank .num { color: var(--muted); }
.num { font-weight: 700; font-size: 13px; }
.num .dow { display: none; }
.entrees, .evs { list-style: none; margin: 0; padding: 0; }
.entrees li { margin-bottom: 3px; line-height: 1.25; }
.entrees b { color: var(--muted); font-weight: 600; }
.evs li { font-size: 12px; line-height: 1.25; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.evs .t { color: var(--muted); font-weight: 600; }
.evs .more { color: var(--brand); font-weight: 600; }
.cancelled { text-decoration: line-through; opacity: .7; }
.badge { display: inline-block; background: var(--chip); color: var(--muted); border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 600; text-decoration: none; }
.badge.big { font-size: 15px; padding: 4px 10px; }
.status { text-align: center; color: var(--muted); padding: 20px 16px; }
.updated { text-align: center; color: var(--muted); font-size: 12px; margin: 20px 0 0; }

@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: stretch; padding: 14px 0 16px; }
  .app-header h1 { font-size: 21px; }
  .school-btn { width: 100%; min-height: 54px; padding: 8px 16px; }
  .school-btn-name { font-size: 17px; }
  main { padding: 20px 16px 32px; }
  .kid-bar { gap: 10px; margin-bottom: 20px; }
  .chip { min-height: 44px; padding: 10px 16px; font-size: 15px; }
  .chip-edit { min-height: 44px; padding: 10px 14px 10px 12px; }
  .hero { gap: 16px; margin-bottom: 28px; }
  .hero-card { padding: 18px; }
  .hero-main { font-size: 20px; }
  .hero-sides, .hero-evs { font-size: 14px; }
  .tab-bar { width: 100%; margin-bottom: 16px; }
  .tab-btn { flex: 1; min-height: 44px; font-size: 16px; }
  .month-nav { justify-content: space-between; margin-bottom: 16px; }
  .weekday-row { display: none; }
  .calendar { display: flex; flex-direction: column; gap: 10px; }
  .cell { min-height: 0; flex-direction: row; align-items: baseline; gap: 14px; padding: 14px 16px; font-size: 15px; border-radius: 12px; }
  .cell.empty, .cell.blank.wkend, .cell.past.blank { display: none; }
  .num { min-width: 60px; flex-shrink: 0; font-size: 15px; }
  .num .dow { display: inline; color: var(--muted); font-weight: 600; }
  .entrees li { margin-bottom: 6px; line-height: 1.35; }
  .entrees li:last-child, .evs li:last-child { margin-bottom: 0; }
  .evs li { font-size: 14px; line-height: 1.35; margin-bottom: 6px; -webkit-line-clamp: 3; }
  .chip.ghost { margin-left: 0; }
  .app-footer { padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); line-height: 1.6; }
}

/* dialogs */
.sheet {
  border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 24px)); max-height: 88vh;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.sheet::backdrop { background: rgba(10, 15, 25, .45); }
@media (max-width: 640px) {
  .sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; max-height: 90vh; }
}
.sheet-header { position: sticky; top: 0; background: var(--card); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); z-index: 1; }
.sheet-header h2 { margin: 0; font-size: 18px; }
.sheet-close { border: 0; background: var(--chip); width: 40px; height: 40px; flex: none; border-radius: 50%; font-size: 20px; line-height: 1; }
.sheet-body { padding: 16px 18px 24px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.sheet-body h3 { font-size: 15px; margin: 18px 0 8px; }
.sheet-body > :first-child, .day-school > h3:first-child { margin-top: 0; }
.sheet-body h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 4px; }
.day-school + .day-school { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 18px; }
.day-events { margin-top: 22px; }
.mgroup { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 5px 0; }
.mtype { color: var(--muted); font-size: 13px; }
.other-menus { margin-top: 14px; }
.other-menus summary { color: var(--brand); cursor: pointer; font-size: 14px; padding: 8px 0; }
.ev-list { list-style: none; padding: 0; margin: 0; }
.ev-list li { display: grid; grid-template-columns: 72px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ev-time { font-weight: 600; font-size: 13px; }
.ev-title { font-weight: 600; }
.ev-meta { color: var(--muted); font-size: 13px; }
.ev-meta { margin-top: 2px; }
.ev-links { font-size: 14px; margin-top: 6px; display: flex; gap: 6px 16px; flex-wrap: wrap; }
.ev-links a { padding: 4px 0; }

/* forms */
.field { display: block; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.field input:not([type="checkbox"]), .field select, .inline-form input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-weight: normal;
  font-size: 16px; /* under 16px, iOS zooms the page on focus */
}
fieldset.field { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
fieldset legend { padding: 0; margin-bottom: 8px; }
.act-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 0 12px;
  max-height: 240px; overflow-y: auto; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-weight: normal;
}
.act-list .hint { grid-column: 1 / -1; margin: 4px 0; }
.chk { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-size: 15px; line-height: 1.3; cursor: pointer; min-width: 0; }
.chk input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--brand); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { margin-top: 0; text-transform: uppercase; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 10px 18px; min-height: 44px; font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); margin-right: auto; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.code-big { font: 700 30px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .12em; text-align: center; background: var(--chip); border-radius: 10px; padding: 12px; margin: 6px 0 10px; }
.error { color: var(--danger); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10; max-width: calc(100vw - 32px);
}

.app-footer { max-width: 1100px; margin: 0 auto; padding: 8px 16px 32px; text-align: center; color: var(--muted); font-size: 13px; }
.app-footer p { margin: 6px 0; }
.app-footer a { display: inline-block; padding: 4px 0; }

/* school chooser */
#schoolSheet[open] { display: flex; flex-direction: column; overflow: hidden; }
#schoolSheet .sheet-header { border-bottom: 0; padding-bottom: 6px; }
.sheet-search { padding: 4px 18px 12px; border-bottom: 1px solid var(--line); }
.sheet-search input {
  width: 100%; min-height: 44px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.school-list { overflow-y: auto; flex: 1; padding-top: 8px; }
.school-list h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 6px; }
.school-list h3:first-child { margin-top: 8px; }
.school-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 48px;
  padding: 12px 14px; border: 0; border-radius: 10px; background: transparent; text-align: left; font-size: 16px;
}
.school-row:hover { background: var(--chip); }
.school-row.on { background: var(--chip); color: var(--brand); font-weight: 700; }
.check { font-size: 18px; }
@media (max-width: 640px) { #schoolSheet { height: 85vh; } }
