/* Theme tokens: light on :root, dark under system preference and explicit choice. */
:root {
  --bg: #f6f5f1; --panel: #ffffff; --ink: #1f2328; --muted: #6b7078; --line: #d9d7d0; --hairline: #e9e7e0;
  --accent: #c2472e; --today: #fff3cd; --outside: #f0efeb; --weekend: #faf9f6; --family: #6b7078;
  --chip-bg: color-mix(in srgb, var(--pc) 14%, var(--panel)); --clash: #d9480f; --overlap: #c92a2a;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --red: #c92a2a; --school-bg: #eaf3ff; --school-ink: #1c5d99;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --panel: #1e2126; --ink: #e8e6e0; --muted: #9da1a8; --line: #3a3f47; --hairline: #2a2e35;
    --accent: #e0694a; --today: #3a3420; --outside: #191c20; --weekend: #1b1e23; --family: #9da1a8;
    --chip-bg: color-mix(in srgb, var(--pc) 28%, var(--panel)); --clash: #ff922b; --overlap: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.4);
    --red: #ff6b6b; --school-bg: #1b2634; --school-ink: #8fbdf0;
  }
}
:root[data-theme="dark"] {
  --red: #ff6b6b; --school-bg: #1b2634; --school-ink: #8fbdf0;
  --bg: #15181c; --panel: #1e2126; --ink: #e8e6e0; --muted: #9da1a8; --line: #3a3f47; --hairline: #2a2e35;
  --accent: #e0694a; --today: #3a3420; --outside: #191c20; --weekend: #1b1e23; --family: #9da1a8;
  --chip-bg: color-mix(in srgb, var(--pc) 28%, var(--panel)); --clash: #ff922b; --overlap: #ff6b6b;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
/* Column so .layout can take every pixel the header and footer leave over. */
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; display: flex; flex-direction: column; min-height: 100vh; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.icon { width: 34px; padding: 4px 0; text-align: center; font-size: 16px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: var(--hairline); padding: 0 4px; border-radius: 4px; }
h1 { font-size: 18px; margin: 0; white-space: nowrap; }
h2 { font-size: 20px; margin: 0 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }

/* Header */
.top { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 16px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.views, .nav { display: flex; gap: 0; }
.views button, .nav button { border-radius: 0; margin-left: -1px; }
.views button:first-child, .nav button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.views button:last-child, .nav button:last-child { border-radius: 0 6px 6px 0; }
.label { font-weight: 600; font-size: 15px; }
.spacer { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: 4px; }
.pf { --pc: var(--family); border-color: var(--pc); background: var(--chip-bg); padding: 2px 10px; border-radius: 999px; }
.pf::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--pc); margin-right: 6px; vertical-align: 0; }
.pf.off { opacity: .45; background: var(--panel); text-decoration: line-through; }

/* Layout */
/* Full-bleed: the sidebar scales with the viewport, the calendar takes the rest. */
.layout { display: grid; grid-template-columns: 1fr clamp(240px, 20vw, 400px); gap: 16px; padding: 16px; flex: 1; min-height: 0; align-items: stretch; }
body.tasks-hidden .layout { grid-template-columns: 1fr; }
body.tasks-hidden .tasks { display: none; }
.view { min-width: 0; display: flex; flex-direction: column; }
.tasks { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px 14px; align-self: start; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 16px 24px; display: grid; gap: 4px; }
.foot a { color: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty, .error { color: var(--muted); }
.error { color: var(--overlap); }
.notfound { max-width: 480px; margin: 15vh auto; padding: 0 16px; text-align: center; color: var(--muted); }

/* Chips */
.chip { --pc: var(--family); display: flex; align-items: baseline; gap: 4px; width: 100%; text-align: left; padding: 2px 6px; margin: 2px 0; border: 0; border-left: 3px solid var(--pc); border-radius: 4px; background: var(--chip-bg); font-size: 12px; line-height: 1.3; overflow: hidden; }
.chip .em { flex: none; }
.chip .t { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip .ti { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.allday { background: var(--pc); color: #fff; border-left: 0; font-weight: 600; }
.chip[data-clash]::after { content: "⚠"; margin-left: auto; color: var(--clash); flex: none; }
.chip[data-clash="overlap"]::after { color: var(--overlap); }

/* Month */
/* Flex column so the week rows share the leftover height instead of leaving
   dead space under the grid on a tall screen. */
.month { --wk-col: 34px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; flex: 1; }
.dows, .mrow { display: grid; grid-template-columns: var(--wk-col) repeat(7, minmax(0, 1fr)); }
.mrow { flex: 1; }
.dow { padding: 6px 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; border-bottom: 1px solid var(--line); }
.mday { min-height: 110px; padding: 4px; border-right: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); }
.mday:last-child { border-right: 0; }
/* Week number ("vecka") down the left edge; click jumps to that week. */
.wknum { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--muted); text-decoration: none; }
.mrow > .wknum { display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; background: var(--outside); border-right: 1px solid var(--line); border-bottom: 1px solid var(--hairline); }
.mrow > .wknum:hover { color: var(--ink); background: var(--hairline); }
.dow.wkcorner { background: var(--outside); border-right: 1px solid var(--line); }
.wk-gutter .wknum { display: block; padding: 8px 6px 0; text-align: center; }
.mday.weekend { background: var(--weekend); }
.mday.outside { background: var(--outside); }
.mday.outside .dnum { color: var(--muted); }
.mday.today { background: var(--today); }
.dnum { display: inline-block; font-weight: 600; padding: 2px 6px; margin-bottom: 2px; border-radius: 999px; cursor: pointer; }
.dnum:hover { background: var(--hairline); }
.mday.today .dnum { background: var(--accent); color: #fff; }

/* Weekly brief */
.brief { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 16px; margin-bottom: 12px; }
.brief-head { font-weight: 600; margin-bottom: 4px; }
.brief-sec { display: inline-block; vertical-align: top; margin: 4px 24px 0 0; font-size: 13px; }
.brief-sec b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.brief-sec ul { margin: 2px 0 0; padding-left: 18px; }
.brief-sec li { margin: 1px 0; }

/* Week */
.week { --hour: 44px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.wk-head, .wk-alldays, .wk-body { display: grid; grid-template-columns: 48px repeat(7, minmax(0, 1fr)); }
.wk-head { border-bottom: 1px solid var(--line); }
.wk-dayhead { padding: 8px 4px; text-align: center; cursor: pointer; border-left: 1px solid var(--hairline); }
.wk-dayhead .wd { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.wk-dayhead .dn { display: inline-block; font-weight: 600; padding: 0 6px; border-radius: 999px; }
.wk-dayhead.today .dn { background: var(--accent); color: #fff; }
.wk-alldays { border-bottom: 1px solid var(--line); min-height: 8px; }
.wk-allday { padding: 2px; border-left: 1px solid var(--hairline); }
.wk-body { position: relative; height: calc(var(--span) / 60 * var(--hour)); overflow: hidden; }
.wk-gutter { position: relative; }
.hour { position: absolute; top: calc(var(--top) / 60 * var(--hour)); right: 6px; transform: translateY(-50%); font-size: 11px; color: var(--muted); }
.hour:first-child { transform: none; top: 2px; }
.wk-col { position: relative; border-left: 1px solid var(--hairline); background:
  repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), var(--hairline) calc(var(--hour) - 1px), var(--hairline) var(--hour)); }
.wk-col.today { background-color: var(--today); }
/* Overlapping events share the column side by side: --c/--n from overlapColumns. */
.wk-ev { position: absolute; left: calc(var(--c, 0) / var(--n, 1) * (100% - 4px) + 2px); width: calc((100% - 4px) / var(--n, 1) - 1px); top: calc(var(--top) / 60 * var(--hour)); height: calc(var(--dur) / 60 * var(--hour)); }
.wk-ev .chip { height: 100%; margin: 0; align-items: flex-start; flex-wrap: wrap; box-shadow: var(--shadow); }
.wk-ev .chip .ti { white-space: normal; }

/* Day */
.day { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.badge { font-size: 12px; background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 8px; vertical-align: middle; }
.ev { --pc: var(--family); border-left: 4px solid var(--pc); background: var(--chip-bg); border-radius: 6px; padding: 8px 12px; margin: 8px 0; cursor: pointer; }
.ev-title { font-weight: 600; font-size: 15px; }
.ev-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); margin-top: 2px; }
.ev-notes { margin-top: 4px; }
.clash-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; color: #fff; background: var(--clash); border-radius: 4px; padding: 1px 6px; vertical-align: middle; }

/* School view */
.school { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 16px 16px; align-self: start; width: 100%; }
.sch-hours { border-bottom: 1px solid var(--hairline); padding-bottom: 10px; }
.sch-kid { --pc: var(--family); border-left: 3px solid var(--pc); border-radius: 4px; background: var(--chip-bg); padding: 4px 10px; margin: 4px 0; font-weight: 600; font-size: 13px; }
.sch-kid .sch-days { font-weight: 400; color: var(--muted); margin-left: 10px; }
details.sch-kid summary { cursor: pointer; list-style: none; }
details.sch-kid summary::-webkit-details-marker { display: none; }
.sch-more { float: right; font-weight: 400; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sch-more::before { content: "▸ "; }
details[open] .sch-more::before { content: "▾ "; }
.sch-tt { display: grid; gap: 2px; padding: 8px 0 4px; font-weight: 400; }
.sch-tt-day { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 2px 0; border-top: 1px solid var(--hairline); }
.sch-tt-day b { flex: 0 0 34px; }
.sch-lesson { white-space: nowrap; }
.sch-lesson .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.sch-lesson .room { color: var(--muted); font-size: 11px; }
.sch-week { display: flex; align-items: baseline; gap: 10px; }
.sch-week .wknum { font-size: 13px; font-weight: 700; color: var(--accent); }
.sch-week .sch-range { font-weight: 400; }
.sch-lov { background: var(--school-bg); color: var(--school-ink); border-radius: 6px; padding: 4px 10px; margin: 6px 0; font-weight: 600; font-size: 13px; }
.sch-term { color: var(--muted); font-style: italic; font-size: 12px; margin: 6px 0; }
.sch-item { --pc: var(--family); display: grid; grid-template-columns: 96px 1fr auto; gap: 8px; align-items: baseline; width: 100%; text-align: left; background: var(--chip-bg); border: 0; border-left: 3px solid var(--pc); border-radius: 6px; padding: 6px 10px; margin: 4px 0; font-size: 13px; cursor: pointer; }
.sch-item.prov .sch-title { font-weight: 600; }
.sch-item .sch-when { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sch-item .sch-who { color: var(--muted); }
.sch-item input { margin: 0 2px 0 0; vertical-align: -1px; }
label.sch-item { cursor: default; }

/* Tasks */
.task { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--hairline); }
.task input { margin: 0; }
.task-meta { grid-column: 2; font-size: 12px; color: var(--muted); }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.tasks-sec.overdue .task-title { color: var(--overlap); }
.tasks-sec.donesec { opacity: .7; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 0; max-width: min(92vw, 460px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-inner { padding: 20px; }
.dlg-inner h3 { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0 0 4px; }
.dlg-date { margin: 0 0 8px; color: var(--muted); }
.dlg-src { font-size: 12px; color: var(--muted); margin: 14px 0; }

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .tasks { position: static; max-height: none; }
  .month { flex: 0 1 auto; --wk-col: 22px; }
  .mday { min-height: 72px; padding: 2px; }
  .mrow > .wknum { padding-top: 4px; font-size: 10px; }
  .sch-item { grid-template-columns: 78px 1fr; }
  .sch-item .sch-who { grid-column: 2; }
  .chip { font-size: 11px; padding: 1px 4px; }
  .chip .t { display: none; }
  .week { --hour: 36px; }
  .wk-head, .wk-alldays, .wk-body { grid-template-columns: 42px repeat(7, minmax(0, 1fr)); }
  .hour { font-size: 10px; right: 3px; }
  .wk-ev .chip .em { display: none; }
  .label { width: 100%; order: 10; }
}

/* Run sheet */
.runsheet { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px 10px; margin: 8px 0 14px; }
.runsheet h3 { margin-top: 4px; }
.runsheet ol { list-style: none; margin: 0; padding: 0; }
.runsheet li { display: grid; grid-template-columns: 48px auto 1fr; gap: 10px; padding: 3px 0; align-items: baseline; }
.rs-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.rs-mode { color: var(--muted); white-space: nowrap; }

/* Holidays and school breaks */
.mday.red .dnum, .wk-dayhead.red .dn, .day h2.red { color: var(--red); }
.mday.today.red .dnum { color: #fff; }
.mday.school, .wk-allday.school { background: var(--school-bg); }
.mday.today.school { background: var(--today); }
.school-label { font-size: 11px; font-weight: 600; color: var(--school-ink); text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; }
.hol { font-size: 12px; padding: 1px 6px; color: var(--muted); }
.hol.public { color: var(--red); font-weight: 600; }
.hol.eve { color: var(--red); }
.day-info { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: -6px 0 12px; }
.day-info .hol, .day-info .school-label { padding: 0; font-size: 14px; text-transform: none; letter-spacing: 0; }

/* Away parents */
.plane { font-size: 12px; margin-left: 4px; cursor: default; }
.wk-dayhead .plane { margin-left: 6px; }
.rs-adults { color: var(--muted); margin: 2px 0 6px; }
.rs-adults.danger { color: var(--overlap); font-weight: 600; }
.chip[data-clash="no-adult"]::after { color: var(--overlap); content: "⛔"; }
