:root {
  --bg: #ffffff;
  --surface: #f4f4f5;
  --text: #18181b;
  --muted: #6b7280;
  --line: #e4e4e7;
  --accent: #2563eb;
  --danger: #dc2626;
  --both: #64748b;
  --tabs-h: 52px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #1d2023;
    --text: #ececee;
    --muted: #9ca3af;
    --line: #2c3035;
    --accent: #3b82f6;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input, select, textarea {
  font: inherit;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  min-width: 0;
}
textarea { resize: vertical; }

/* ---------- buttons */

.btn {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 500;
  white-space: nowrap;
}
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { display: block; width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn:disabled { opacity: .5; }

.error { color: var(--danger); font-size: 14px; min-height: 20px; }
.status { color: var(--muted); font-size: 14px; min-height: 20px; }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 14px 16px; }

/* ---------- login */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 14px; }
.login h1 { font-size: 24px; }
.login label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }

/* ---------- layout */

#app {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 8px;
}
.bar h1 { font-size: 19px; font-weight: 650; }
#month-title { min-width: 9.5em; text-align: center; }
.spacer { flex: 1; }

.nav-btn {
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: none;
  font-size: 26px; line-height: 1;
  padding: 0 0 4px;
}
.nav-btn:active { background: var(--surface); }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  max-width: 213px;
  height: var(--tabs-h);
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.tabs button.active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

/* ---------- filters */

.filters { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.filter {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  padding: 4px 11px 4px 9px;
  font-size: 13px;
}
.filter .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.filter[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.filter[aria-pressed="false"] .dot { background: none; box-shadow: inset 0 0 0 1.5px var(--muted); }

/* ---------- month grid */

.dow, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.dow span { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.grid { border-top: 1px solid var(--line); touch-action: pan-y; }

.cell {
  min-height: 78px;
  padding: 3px 2px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  text-align: left;
  overflow: hidden;
}
.cell .num {
  align-self: center;
  width: 24px; height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 50%;
  font-size: 13px;
}
.cell.other .num { color: var(--muted); opacity: .55; }
.cell.other .chip { opacity: .55; }
.cell.today .num { background: var(--accent); color: #fff; font-weight: 600; }
.cell.selected { background: var(--surface); }
.cell.busy { opacity: .5; }
.grid.painting .cell:active { background: var(--surface); }

.chip {
  display: block;
  font-size: 10.5px;
  line-height: 15px;
  padding: 0 3px 0 5px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  background: var(--surface);
  background: color-mix(in srgb, var(--c) 18%, transparent);
  box-shadow: inset 2px 0 0 var(--c);
}
.chip.work { background: var(--c); color: #fff; box-shadow: none; padding-left: 4px; }
.more { font-size: 10.5px; line-height: 13px; color: var(--muted); padding-left: 4px; }

/* ---------- shift painting */

.paint-bar { padding: 0 12px 10px; display: grid; gap: 6px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  display: grid;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  padding: 5px 10px;
  font-size: 13px;
}
.preset span { color: var(--muted); font-size: 12px; }
.preset[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- event lists */

.day-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 16px; }
.day-head h2, .group { font-size: 14px; font-weight: 600; }
.group { padding: 16px 16px 4px; color: var(--muted); }

.row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  padding: 8px 16px;
  text-align: left;
}
.row:active { background: var(--surface); }
.row-bar { flex: none; width: 4px; border-radius: 2px; background: var(--c); }
.row-main { display: grid; min-width: 0; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); }

/* ---------- dialogs */

dialog { border: 0; padding: 0; background: var(--bg); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }

.sheet {
  width: 100vw; height: 100dvh;
  max-width: none; max-height: none;
  margin: 0;
}
.sheet form { display: flex; flex-direction: column; height: 100%; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 16px; font-weight: 600; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px 14px calc(env(safe-area-inset-bottom) + 24px);
}
.title-input { font-size: 18px; font-weight: 500; }

@media (min-width: 600px) {
  .sheet { width: 480px; height: auto; max-height: 90vh; margin: auto; border-radius: 12px; }
  .sheet form { max-height: 90vh; }
}

.field { display: flex; align-items: center; gap: 8px; }
.field .label { flex: none; width: 52px; font-size: 14px; color: var(--muted); }
.field input[type="date"], .field select { flex: 1; }
.field input[type="date"], .field input[type="time"] { padding-left: 8px; padding-right: 6px; }
.field input[type="time"] { flex: none; width: 126px; }
.field input[type="number"] { flex: none; width: 70px; }
.repeat { display: grid; gap: 12px; padding-left: 10px; border-left: 2px solid var(--line); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; margin: 0; }

.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { flex: 1; min-width: 0; position: relative; }
.seg label + label { border-left: 1px solid var(--line); }
.seg input, .days input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  padding: 8px 6px;
  text-align: center;
  font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seg input:checked + span { background: var(--text); color: var(--bg); }
.seg input:focus-visible + span, .days input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.days { display: flex; flex: 1; gap: 4px; }
.days label { flex: 1; position: relative; }
.days span {
  display: block;
  padding: 7px 0;
  text-align: center;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.days input:checked + span { background: var(--text); border-color: var(--text); color: var(--bg); }

.choice { width: min(320px, calc(100vw - 48px)); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.choice h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.choice #choice-buttons { display: grid; gap: 8px; }

/* ---------- settings */

.card { padding: 14px 16px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.card h2 { font-size: 14px; font-weight: 600; color: var(--muted); }
.line { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 8px; justify-items: start; }
.stack input { width: 100%; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--c); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--c); }

.card > * { min-width: 0; }
.preset-rows { display: grid; gap: 14px; }
.preset-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.preset-row .p-name { grid-column: 1 / -1; }
.preset-row input[type="time"] { width: 100%; padding-left: 8px; padding-right: 6px; }
.feed-url { width: 100%; font-size: 13px; color: var(--muted); }

/* ---------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
}
