:root {
  --bg: #fafafa;
  --card: #fff;
  --fg: #111;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-fg: #fff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0c;
    --card: #141416;
    --fg: #f4f4f5;
    --muted: #9ca3af;
    --line: #26262b;
    --accent: #60a5fa;
    --accent-fg: #0b0b0c;
    --danger: #f87171;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); line-height: 1.4; }
#app { max-width: 640px; margin: 0 auto; padding: 16px 16px 64px; }
h1 { font-size: 1.25rem; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; background: var(--card); }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 7px; font: inherit; font-weight: 500; min-height: 44px; cursor: pointer; }
.tabs button[aria-current="page"] { background: var(--accent); color: var(--accent-fg); }

.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 11rem; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 0.875rem; }
.error { color: var(--danger); font-size: 0.875rem; }

.list { list-style: none; margin: 0; padding: 0; }
.item { padding: 8px 0; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.done { opacity: 0.7; }
.field { flex-basis: 100%; display: grid; gap: 4px; }
.field input { width: 100%; }
.add select, .item select { flex: 1 1 10rem; min-width: 0; max-width: 100%; }

input, select { font: inherit; color: inherit; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px; }
input[type="number"] { width: 5.5rem; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
select option { color: #111; }
label { font-size: 0.875rem; color: var(--muted); }
.item label { font-size: 1rem; color: var(--fg); }

button { font: inherit; cursor: pointer; }
.primary { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 8px; padding: 12px 16px; min-height: 44px; font-weight: 600; }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-height: 44px; }
.icon { background: transparent; border: 0; color: var(--muted); font-size: 1.25rem; width: 44px; height: 44px; border-radius: 8px; }
.link { background: none; border: 0; color: var(--muted); padding: 8px 0; display: inline-flex; align-items: center; gap: 6px; }
.link .edit-icon { display: inline-flex; }

.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--danger); }
.banner { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); font-size: 0.875rem; }
.banner.warn { border-color: var(--danger); color: var(--danger); }
.gate { max-width: 420px; margin: 12vh auto 0; }
.muted a { color: var(--accent); text-underline-offset: 3px; }

.handle { width: 32px; touch-action: none; cursor: grab; }
.handle:active { cursor: grabbing; }
.list.is-dragging { user-select: none; -webkit-user-select: none; }
.item.dragging { position: relative; z-index: 10; background: var(--card); border: 1px solid var(--accent); border-radius: 8px; padding-left: 8px; padding-right: 8px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); cursor: grabbing; }
.item.dragging .handle { color: var(--accent); }
.summary > summary { cursor: pointer; list-style: none; }
.summary > summary::-webkit-details-marker { display: none; }
.summary > summary::after { content: '▸'; color: var(--muted); }
.summary[open] > summary::after { content: '▾'; }
.summary > summary h2 { flex: 1; }
.summary > .list { margin-top: 12px; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.day { display: grid; gap: 2px; justify-items: center; align-content: center; padding: 8px 2px; min-height: 56px; background: transparent; color: var(--fg); border: 1px solid var(--line); border-radius: 8px; }
.day-name { font-size: 0.8125rem; font-weight: 600; }
.day-date { font-size: 0.6875rem; color: var(--muted); text-align: center; }
.day.today { border-color: var(--accent); }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.day[aria-pressed="true"] .day-date { color: inherit; }
.day:disabled { opacity: 0.35; cursor: not-allowed; }

.confirm { color: var(--fg); gap: 12px; flex-wrap: nowrap; }

/* Plan rows stay on one line on a phone: the name truncates so minutes and the remove button never wrap. */
.plan-item { flex-wrap: nowrap; gap: 6px; }
.plan-item .grow { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-item input[type="number"] { width: 4.5rem; flex: none; }
.plan-item .icon { width: 36px; flex: none; }
.plan-item .badge { flex: none; }
.summary { display: block; }
