:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee8;
  --text: #1d1f22;
  --muted: #6b6f76;
  --line: #e2e0d8;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --today: #fff4d6;
  --today-line: #f0d68a;
  --warn-bg: #fff1e6;
  --warn-ink: #8a4b14;
  --cal-school: #2b7fb8;
  --cal-jewish: #a87b00;
  --cal-sports: #23864f;
  --cal-family: var(--text);
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 1px 1px rgb(0 0 0 / 0.03);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a;
    --surface: #1f2125;
    --surface-2: #26292e;
    --text: #e9e9e6;
    --muted: #9a9ea6;
    --line: #33363c;
    --accent: #6fbfa5;
    --accent-ink: #0f1f1a;
    --accent-soft: #1f342d;
    --today: #33301f;
    --today-line: #6b5f2a;
    --warn-bg: #3a2a1c;
    --warn-ink: #f0c08c;
    --cal-school: #87ceeb;
    --cal-jewish: #ffd700;
    --cal-sports: #5fd394;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.tabs a {
  padding: 6px 11px; border-radius: 999px; text-decoration: none;
  color: var(--muted); font-weight: 550; font-size: 0.92rem; white-space: nowrap;
}
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 520px) {
  .brand { display: none; }
  .tabs { margin: 0 auto; }
}

.banner { margin: 10px 16px 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.9rem; }
.page { max-width: 880px; margin: 0 auto; padding: 14px 16px 40px; }
.page.wide { max-width: 1400px; }
.loading { padding: 40px 0; text-align: center; }

h1 { font-size: 1.35rem; margin: 6px 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 26px 0 8px; }

/* ---------- action row ---------- */
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 6px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer; box-shadow: var(--shadow);
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }
.btn.quiet { font-weight: 500; color: var(--muted); font-size: 0.85rem; min-height: 36px; padding: 6px 10px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.select {
  min-height: 40px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); max-width: 100%;
}
.reason { font-size: 0.85rem; color: var(--muted); margin: 0; }
.note { font-size: 0.88rem; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); margin: 10px 0; }
.note.test { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- day lists ---------- */
.day { margin-top: 18px; }
.day-head {
  display: flex; align-items: baseline; gap: 8px;
  font-weight: 700; padding: 0 2px 6px;
}
.day-head .date { color: var(--muted); font-weight: 500; font-size: 0.9rem; }
.day-head .pill { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; background: var(--today-line); color: #3d3200; padding: 1px 7px; border-radius: 999px; }
.items { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: grid; grid-template-columns: 92px 1fr; gap: 2px 12px; padding: 10px 12px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item.allday { padding-top: 7px; padding-bottom: 7px; }
.item .time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.9rem; padding-top: 1px; }
.item .what { min-width: 0; }
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .kid { display: inline-block; margin-left: 6px; font-size: 0.78rem; font-weight: 700; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 0 6px; vertical-align: 1px; }
.item .meta { grid-column: 2; font-size: 0.84rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 12px; }
.item .meta a { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 2px; overflow-wrap: anywhere; }
.item.now { background: var(--accent-soft); }
@media (max-width: 420px) { .item { grid-template-columns: 78px 1fr; gap: 2px 8px; } .item .time { font-size: 0.82rem; } }

.cal-school { color: var(--cal-school); }
.cal-jewish { color: var(--cal-jewish); }
.cal-sports { color: var(--cal-sports); }
.cal-family { color: var(--cal-family); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; color: var(--muted); margin: 18px 2px 0; }
.legend b { font-size: 1rem; }

/* ---------- panels / forms ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-top: 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.controls label { display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .n { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 0.8rem; color: var(--muted); }
.kv { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 8px; }
.kv td, .kv th { padding: 6px 4px; border-top: 1px solid var(--line); text-align: left; }
.kv th { color: var(--muted); font-weight: 600; font-size: 0.8rem; border-top: 0; }
.kv td.num { text-align: right; font-variant-numeric: tabular-nums; }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 130px; margin-top: 14px; }
.bar { display: grid; grid-template-rows: auto 1fr auto; height: 100%; text-align: center; font-size: 0.78rem; color: var(--muted); }
.bar .fill { align-self: end; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bar .v { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

.table-wrap { overflow-x: auto; margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.data { border-collapse: collapse; font-size: 0.82rem; min-width: 100%; }
.data th, .data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.data th { position: sticky; top: 0; background: var(--surface-2); }

/* ---------- month / monitor grid ---------- */
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.cell { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 7px; min-height: 92px; min-width: 0; }
.cell.today { background: var(--today); border-color: var(--today-line); }
.cell .d { display: block; font-weight: 700; font-size: 0.85rem; color: var(--accent); text-decoration: none; margin-bottom: 4px; }
.cell .d:hover { text-decoration: underline; }
.cell .ev { font-size: 0.74rem; line-height: 1.3; padding: 1px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell .ev .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 3px; }
.cell .none { font-size: 0.74rem; color: var(--muted); }
@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; gap: 0; }
  .cell { border-radius: 0; border-width: 0 0 1px; min-height: 0; padding: 9px 4px; display: grid; grid-template-columns: 92px 1fr; gap: 0 10px; }
  .cell .d { margin: 0; }
  .cell .ev, .cell .none { grid-column: 2; font-size: 0.84rem; white-space: normal; }
  .grid { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
}

body.monitor .topbar { display: none; }
body.monitor .page { max-width: none; padding: 12px; }
body.monitor .cell { min-height: 120px; }
body.monitor .cell .ev { font-size: 0.82rem; }
.monitor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.monitor-head h1 { margin: 0; font-size: 1.5rem; }
.clock { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.center { text-align: center; margin-top: 16px; }
