/* Wepala – iPhone-first, light/dark via prefers-color-scheme. */
:root {
  --bg: #ffffff;
  --bg2: #f2f2f7;
  --fg: #111;
  --muted: #6b6b70;
  --line: #d9d9de;
  --accent: #0072b2;
  --danger: #c0392b;
  --warn: #d55e00;
  --gap: #d55e00;
  --asleep-bg: #eceef4;
  --all-bg: repeating-linear-gradient(135deg, #e6e6ea 0 6px, #f6f6f8 6px 12px);
  --act-bg: repeating-linear-gradient(45deg, rgba(0,0,0,.14) 0 3px, rgba(0,0,0,.04) 3px 6px);
  --bar-h: 48px;
  --tab-h: 52px;
  --head-h: 32px;
  --radius: 12px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --bg2: #1c1c1e;
    --fg: #f2f2f7;
    --muted: #9a9aa0;
    --line: #3a3a3e;
    --accent: #56b4e9;
    --asleep-bg: #15151c;
    --all-bg: repeating-linear-gradient(135deg, #2a2a2e 0 6px, #1c1c1e 6px 12px);
    --act-bg: repeating-linear-gradient(45deg, rgba(255,255,255,.22) 0 3px, rgba(255,255,255,.06) 3px 6px);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
input, select { font-size: 16px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; }
input[type=color] { width: 44px; padding: 2px; flex: 0 0 44px; }
input[type=checkbox] { width: auto; min-height: 0; width: 22px; height: 22px; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h3 { font-size: 17px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.errors { color: var(--danger); margin: 8px 0; padding-left: 18px; font-size: 14px; }
.errors:empty { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; flex: 0 0 auto; }

/* Layout */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar { flex: 0 0 auto; padding-top: var(--sat); background: var(--bg2); border-bottom: 1px solid var(--line); }
.topbar-inner { height: var(--bar-h); display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.topbar .title { flex: 1; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ribbon { background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 2px 6px; border-radius: 4px; }
.offline { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.content { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 24px; }
.tabbar { flex: 0 0 auto; display: flex; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: var(--sab); }
.tabbar[hidden] { display: none; }
.tab { flex: 1; height: var(--tab-h); border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 500; }
.tab.active { color: var(--accent); font-weight: 700; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg); text-decoration: none; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-secondary { width: 100%; }
.btn-danger { color: var(--danger); }
.btn-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.btn-link { background: none; border: 0; color: var(--accent); }
.btn-small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn-icon { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; border-radius: 10px; color: var(--fg); }
.btn-icon:disabled { opacity: .3; }
.btn-person { width: 100%; font-weight: 600; font-size: 18px; border: 0; }
.card { background: var(--bg2); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 14px; color: var(--muted); flex: 1; }
.field > input, .field > select, .field .readonly { color: var(--fg); }
.field-row { display: flex; gap: 8px; align-items: flex-end; }
.field-row > .field { min-width: 0; }
.readonly { min-height: 44px; display: flex; align-items: center; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 10px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg { flex: 1; min-height: 40px; border: 0; background: var(--bg2); color: var(--fg); }
.seg.active { background: var(--accent); color: #fff; font-weight: 600; }
.loading, .fatal { text-align: center; padding: 40px 16px; color: var(--muted); }
.fatal h1, .fatal h2 { color: var(--fg); }
.logo { font-size: 32px; letter-spacing: -.02em; margin-top: 8px; }
.person-row input[type=text] { flex: 1; }
.nap-row { align-items: center; }
.nap-row select { flex: 1; }
.people-list, .nap-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.result input { margin: 8px 0; font-size: 13px; }

/* Day view */
.day-header { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.date-btn { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; font-weight: 700; font-size: 18px; }
.date-btn .date-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; min-height: 0; padding: 0; border: 0; }
.today-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.banner { padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; font-size: 15px; }
.banner-now { background: var(--accent); color: #fff; }
.banner-next { background: var(--bg2); }
.chips-wrap { margin-bottom: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: stretch; flex: 0 0 auto; border: 2px solid var(--chip, var(--line)); border-radius: 999px; background: var(--bg2); overflow: hidden; font-size: 14px; min-height: 36px; }
.chip.active { background: var(--chip); color: #fff; }
.chip-main { border: 0; background: none; color: inherit; padding: 4px 6px 4px 12px; white-space: nowrap; }
.chip-x { border: 0; background: none; color: inherit; padding: 0 8px; display: inline-flex; align-items: center; }
.chip-x .icon { width: 14px; height: 14px; }
.chip-add { border: 2px dashed var(--line); padding: 4px 12px; gap: 4px; color: var(--muted); align-items: center; }
.chip-add .icon { width: 16px; height: 16px; }
.place-hint { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 8px 10px; background: var(--bg2); border-radius: 10px; font-size: 14px; }
.place-hint span { flex: 1; }

.grid {
  /* Row height: nominal 44px (60 min) / 32px (30 min); shrinks so a 60-min day fits one screen, never below 32px. */
  --chrome: calc(var(--bar-h) + var(--tab-h) + var(--sat) + var(--sab) + 230px);
  --row-h: max(32px, min(var(--row-nominal), calc((100dvh - var(--chrome)) / var(--rows))));
  position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: pan-y; }
.grid-row { position: relative; display: grid; grid-template-columns: 44px 36px repeat(var(--cols), minmax(0, 1fr)); height: var(--row-h); border-top: 1px solid var(--line); }
.grid-head { height: var(--head-h); border-top: 0; background: var(--bg2); font-weight: 600; font-size: 13px; }
.grid-row.asleep { background: var(--asleep-bg); }
.grid-row.now .cell.time { color: var(--accent); font-weight: 700; }
.grid-row.now::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.grid-row.past .cell.time, .grid-row.past .cell.status { opacity: .55; }
.cell { display: flex; align-items: center; justify-content: center; min-width: 0; overflow: hidden; position: relative; }
.cell.time { font-size: 12px; color: var(--muted); justify-content: flex-end; padding-right: 6px; }
.cell.status { color: var(--muted); border-right: 1px solid var(--line); }
.cell.status .icon { width: 16px; height: 16px; }
.cell.head { padding: 0 2px; font-size: 13px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; display: block; line-height: var(--head-h); text-align: center; }
.cell.head.mine { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.cell.person { border-left: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.cell.person.mine:not(.care) { background: rgba(127,127,127,.06); }
.cell.person.care { z-index: 1; }
.care-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.cell.person.has-act { justify-content: flex-start; }
.cell.person.has-act .care-label { max-width: 40%; }
.grid.placing .cell.person.place { box-shadow: inset 0 0 0 2px var(--accent); background: rgba(0,114,178,.08); }
.grid.placing .cell.person:not(.place) { opacity: .5; }
.warn-icon { width: 14px; height: 14px; position: absolute; top: 2px; right: 2px; color: var(--warn); }
.cell.person.care .warn-icon { color: inherit; }
.band { position: absolute; left: 80px; right: 0; top: 0; bottom: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; }
.all-band { background: var(--all-bg); color: var(--fg); font-weight: 600; }
.gap-band { border: 2px dashed var(--gap); border-radius: 6px; margin: 2px; color: var(--gap); font-size: 12px; font-weight: 600; }
.grid-row.past .gap-band { opacity: .35; }
.grid-row.all .cell.person { border-left-color: transparent; }
.activity { position: absolute; z-index: 2; background: var(--act-bg), var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; font-size: 11px; line-height: 1.2; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; touch-action: pan-y; }
.activity.conflict { border-color: var(--warn); border-width: 2px; }
.activity .warn-icon { position: static; }
.activity-label { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.day-footer { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.gap-summary { color: var(--gap); font-weight: 600; margin: 0; }
.warn-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.warn-list li { display: flex; gap: 6px; align-items: flex-start; padding: 8px 10px; background: var(--bg2); border-radius: 8px; }
.warn-list li.warn .icon { color: var(--warn); }

/* Overview */
.ov-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ov-table { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
.ov-table th { font-weight: 600; padding: 4px 2px; vertical-align: top; position: relative; min-width: 40px; }
.ov-table th.today { color: var(--accent); }
.ov-time { color: var(--muted); font-size: 11px; text-align: right; padding-right: 4px; white-space: nowrap; }
.ov-cell { width: 40px; height: 22px; border-radius: 4px; text-align: center; font-weight: 600; position: relative; background: var(--bg2); }
.ov-cell.gap { background: none; border: 1.5px dashed var(--gap); }
.ov-cell.gap.past { opacity: .3; }
.ov-cell.all { background: var(--all-bg); }
.ov-cell .icon { width: 14px; height: 14px; }
.ov-moon { position: absolute; right: 1px; top: 1px; width: 10px; height: 10px; opacity: .8; }
.badge { position: absolute; top: -2px; right: -2px; background: var(--warn); color: #fff; font-size: 10px; border-radius: 999px; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; }

/* Balance */
.bal-row { margin: 14px 0; }
.bal-head { display: flex; align-items: center; gap: 8px; }
.bal-sum { margin-left: auto; font-variant-numeric: tabular-nums; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.bar { display: flex; height: 14px; border-radius: 7px; background: var(--bg2); overflow: hidden; margin: 6px 0 4px; }
.bar-wake { height: 100%; }
.bar-nap { height: 100%; opacity: .4; }

/* Sheet, toast, overlay */
.sheet-host[hidden], .toast-host[hidden] { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg); border-radius: 16px 16px 0 0; padding: 8px 16px calc(16px + var(--sab)); max-height: 85dvh; overflow-y: auto; box-shadow: 0 -4px 24px rgba(0,0,0,.2); }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.sheet-actions .btn { width: 100%; }
.toast-host { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + var(--sab) + 12px); z-index: 30; display: flex; justify-content: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; max-width: 100%; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast .btn { min-height: 32px; background: var(--bg); color: var(--fg); border-color: transparent; }
.toast .btn-icon { width: 32px; height: 32px; color: inherit; }
.overlay { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.me-card { width: 100%; max-width: 360px; background: var(--bg); }
.me-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
