:root {
  color-scheme: dark;
  --bg: #0b141e;
  --card: #122131;
  --card-strong: #172b3e;
  --ink: #ecf3f8;
  --sub: #abbccc;
  --line: #34485b;
  --accent: #94caee;
  --accent-strong: #c5e6fa;
  --leave-bg: #284e69;
  --work-bg: #173c3b;
  --radius: 16px;
  --page-gutter: 10px;
  --font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
body.light { color-scheme: light; --bg: #edf2f7; --card: #fff; --card-strong: #f3f7fa; --ink: #162536; --sub: #435a70; --line: #b7c6d4; --accent: #285d83; --accent-strong: #164b70; --leave-bg: #d8e8f3; --work-bg: #d8eee5; }

header, main { width: calc(100% - (var(--page-gutter) * 2)); margin: 0 auto; }
header { padding: calc(14px + env(safe-area-inset-top)) 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
header a { color: var(--ink); font-weight: 700; text-decoration: none; }
header span { color: var(--sub); font-size: 12px; white-space: nowrap; }
main { padding: 28px 0 calc(48px + env(safe-area-inset-bottom)); }
section { margin: 0 0 24px; padding: clamp(20px, 2.5vw, 32px); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 18ch; margin-bottom: 18px; font-size: clamp(28px, 4vw, 44px); line-height: 1.2; letter-spacing: -.025em; }
h2 { margin-bottom: 14px; font-size: clamp(20px, 2.2vw, 28px); line-height: 1.25; letter-spacing: -.015em; }
h3 { margin-bottom: 10px; font-size: 17px; line-height: 1.35; }
p { color: var(--sub); font-size: 14px; }
.eyebrow { margin-bottom: 8px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 24px 0; }
.stats > div { min-width: 0; padding: 16px; background: var(--card-strong); border: 1px solid var(--line); border-radius: 12px; }
.stats strong { display: block; margin-bottom: 4px; font-size: clamp(22px, 3vw, 32px); line-height: 1.15; }
.stats span { color: var(--sub); font-size: 12px; }

button, input, select, textarea { min-height: 44px; max-width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: var(--bg); color: var(--ink); font: inherit; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: var(--accent-strong); font-weight: 650; }
button:disabled { cursor: default; opacity: .5; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input, select, textarea { width: 100%; }
label { display: block; margin: 14px 0; color: var(--sub); font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; }
.check input, .scheduleRow input[type="checkbox"] { width: 20px; min-height: 20px; padding: 0; }
.timeRow { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.calendarUpload { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 18px 0 22px; }
.uploadIndicator { display: inline-flex; align-items: center; gap: 7px; color: var(--accent); font-size: 13px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .55s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.month { margin: 28px 0 0; }
.month h3 { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.weekdays, .days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.weekdays { margin: 12px 0 6px; color: var(--sub); font-size: 12px; font-weight: 700; text-align: center; }
.days > span:not(.day) { min-height: 116px; }
.day { min-width: 0; min-height: 116px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px; color: var(--ink); font-size: 14px; line-height: 1.2; text-align: center; overflow: hidden; }
.dayDate { display: block; min-height: 20px; font-size: 15px; font-weight: 750; line-height: 1.3; }
.dayLine { display: block; width: 100%; min-height: 15px; color: inherit; font-size: 10px; line-height: 1.35; white-space: nowrap; overflow-wrap: normal; font-variant-numeric: tabular-nums; }
.day.leave { background: var(--leave-bg); border-color: #86bbdd; }
.day.work { background: var(--work-bg); border-color: #69b5a2; }
.day.muted { opacity: .58; }
.day.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.day.today { box-shadow: inset 0 -3px 0 var(--accent); }

#dateEditor { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); scroll-margin-top: 20px; }
.weeklyRow { padding: 12px 0; border-bottom: 1px solid var(--line); }
.weeklyRow .timeRow { margin-top: 8px; }
.scheduleGroup { margin: 26px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }
.scheduleRow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) 28px 44px; gap: 8px; align-items: center; margin: 10px 0; }
.siriItem { padding: 14px 0; border-bottom: 1px solid var(--line); }
.buttonState { color: var(--accent); font-size: 11px; font-weight: 600; white-space: nowrap; }
.hasState { display: inline-flex; align-items: center; gap: 8px; }
.siriItem strong { display: block; margin-bottom: 6px; }
.siriItem input { margin: 4px 0 8px; font-size: 12px; }
#notice { padding: 12px 14px; background: var(--card-strong); border-radius: 10px; overflow-wrap: anywhere; }
#results { padding-left: 22px; font-size: 14px; }
footer { padding: 8px 0; text-align: center; }
a { color: var(--accent); }
[hidden] { display: none !important; }

@media (max-width: 560px) {
  :root { --page-gutter: 10px; }
  main { padding-top: 20px; }
  section { padding: 20px; }
  .stats { gap: 10px; }
  .stats > div { padding: 12px; }
  .weekdays, .days { gap: 3px; }
  .day, .days > span:not(.day) { min-height: 102px; }
  .day { padding: 6px 2px; }
  .dayDate { font-size: 14px; }
  .day small { font-size: 9px; }
  .scheduleRow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 24px 38px; gap: 5px; }
}

@media (prefers-reduced-motion: no-preference) { button { transition: background-color .15s ease, border-color .15s ease; } }

section { padding: 20px; }
#calendars { margin-inline: -20px; }
.month h3 { padding-inline: 20px; }
.day { padding-inline: 0; }
.day .dayLine { font-size: clamp(9px, 2.4vw, 12px); letter-spacing: -.03em; }
.currentWeek { margin-block: 20px; }
.currentWeek table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; font-variant-numeric: tabular-nums; }
.currentWeek th, .currentWeek td { padding: 10px 2px; border-bottom: 1px solid var(--line); text-align: center; overflow-wrap: anywhere; }
.currentWeek th { color: var(--sub); font-weight: 600; }
.stats strong { overflow-wrap: anywhere; }

/* Flat sections share the same edge; font settings also apply to calendar labels. */
body { font-size: var(--font-size); }
section { padding: 20px 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; }
.stats > div { padding: 10px 0; border: 0; border-radius: 0; background: transparent; }
#notice { padding: 10px 0; background: transparent; border-radius: 0; border-bottom: 1px solid var(--line); }
#calendars { margin-inline: 0; overflow-x: auto; }
.month { min-width: calc(var(--font-size) * 63 + 2px); }
.month h3 { padding-inline: 0; }
.weekdays, .days { gap: 0; }
.weekdays { margin-bottom: 0; border: 1px solid var(--line); border-bottom: 0; }
.weekdays > span { padding: 8px 0; border-right: 1px solid var(--line); }
.weekdays > span:last-child { border-right: 0; }
.days { border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.days > .day, .days > span:not(.day) {
  min-height: calc(var(--font-size) * 10);
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.days > .day { padding: 8px 4px; gap: 4px; overflow: hidden; }
.days > .day > * { flex-shrink: 0; }
.days > .day.selected { outline-offset: -2px; }
.day.leave, .day.work, body.light .day.leave, body.light .day.work, body.light .day.muted { background: transparent; color: var(--ink); }
.day.leave { border-bottom-color: #86bbdd; }
.day.work { border-bottom-color: #69b5a2; }
p, label, .stats span, .currentWeek table, #results, .day .dayLine, .buttonState, .weekdays { font-size: var(--font-size); }
.day .dayLine { min-height: 1.5em; line-height: 1.5; letter-spacing: normal; white-space: nowrap; }
.dayDate { font-size: calc(var(--font-size) + 2px); }
h3 { font-size: calc(var(--font-size) + 3px); }
.cellLine { display: block; }
.hasState { flex-wrap: wrap; }

#calendars {
  --week-row-height: max(52px, calc(var(--font-size) * 4));
  --week-title-height: 36px;
  height: calc((var(--week-row-height) * 7 + var(--week-title-height)) * 3);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  overscroll-behavior-y: contain;
}
.calendarWeek { min-height: calc(var(--week-row-height) * 7 + var(--week-title-height)); }
.calendarWeek .weekTitle {
  display: flex;
  align-items: center;
  height: var(--week-title-height);
  margin: 0;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  font-size: var(--font-size);
  font-variant-numeric: tabular-nums;
}
.weekDay {
  position: relative;
  display: grid;
  grid-template-columns: 4.5ch minmax(0, 1fr) auto;
  column-gap: 2ch;
  align-items: center;
  width: 100%;
  max-width: none;
  height: var(--week-row-height);
  padding: 4px 6px 4px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: var(--font-size);
  font-weight: 400;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.weekDay::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 2px;
  background: #b8c1ca;
}
.weekDay.leave::before { background: #39c879; }
.weekDay.work::before { background: #f05b64; }
.weekDay.unavailable::before { background: #555d66; }
.weekDate { white-space: nowrap; text-align: left; }
.weekDetails { min-width: 0; display: flex; flex-wrap: wrap; column-gap: .3em; align-items: center; line-height: 1.5; }
.weekTime { white-space: nowrap; font-size: .85em; }
.weekReceipt { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 6px; max-width: 11em; font-size: .8em; text-align: right; }
.weekReceipt > span { white-space: nowrap; }
.weekDay.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.weekDay.today .weekDate { font-weight: 700; color: var(--accent); }
body:has(#dateDialog[open]) { overflow: hidden; }
#dateDialog {
  position: fixed;
  inset: 0;
  width: calc(100% - 20px);
  max-width: 480px;
  max-height: calc(100dvh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 16px 48px #0006;
  font-size: var(--font-size);
}
#dateDialog::backdrop { background: #0009; }
#dateDialog #dateEditor { margin: 0; padding-top: 12px; border: 0; }
#dateDialog .closeEditor { display: block; margin-left: auto; }
#dateDialog label { display: grid; gap: 8px; }
@media (max-width: 560px) {
  .weekReceipt { flex-direction: column; max-width: 5em; }
}
