/* Home Hub — iOS-style look, light & dark, honours the iPhone text-size setting. */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --fill: #e9e9ee;
  --fill-2: #f2f2f7;
  --text: #000000;
  --text-2: #6c6c70;
  --text-3: #aeaeb2;
  --sep: rgba(60, 60, 67, 0.18);
  --accent: #0a6cd6;
  --accent-text: #ffffff;
  --green: #1f9d55;
  --red: #d70015;
  --orange: #b25f00;
  --radius: 14px;
  --tab-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --fill: #2c2c2e;
    --fill-2: #1c1c1e;
    --text: #ffffff;
    --text-2: #98989f;
    --text-3: #636366;
    --sep: rgba(84, 84, 88, 0.6);
    --accent: #3d9bff;
    --green: #32d74b;
    --red: #ff453a;
    --orange: #ffb340;
  }
}

/* Dynamic Type: Safari maps this to the user's iPhone text size. */
html { font: -apple-system-body; -webkit-text-size-adjust: 100%; }
@supports not (font: -apple-system-body) { html { font-size: 17px; } }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
button:disabled { opacity: 0.45; cursor: default; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.icon { flex: none; vertical-align: -0.2em; }

/* ---------------------------------------------------------------- screens */

.screen {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 8px) 16px 0;
}
.top { display: flex; align-items: flex-end; gap: 8px; padding: 8px 0 12px; }
.top h1 { flex: 1; margin: 0; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.bottom-space { height: calc(var(--tab-h) + var(--safe-b) + 96px); }
.shell.has-sheet { overflow: hidden; }

.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; border-radius: 22px; color: var(--accent);
}
.icon-btn.small { min-width: 36px; min-height: 36px; }
.icon-btn:active { background: var(--fill); }
.dot-badge {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 18px; text-align: center;
}

/* ---------------------------------------------------------------- tab bar & FAB */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.65rem; font-weight: 500; color: var(--text-2);
}
.tabbar button.on { color: var(--accent); }
.tab-icon { position: relative; }
.tab-icon .dot-badge { top: -6px; right: -12px; }

.fab {
  position: fixed; z-index: 21; right: 18px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 29px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}
.fab:active { transform: scale(0.96); }

/* ---------------------------------------------------------------- groups, cells, cards */

.group { margin: 0 0 22px; }
.group-header {
  margin: 0 16px 6px; font-size: 0.8rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--text-2);
}
.group-footer { margin: 6px 16px 0; font-size: 0.8rem; color: var(--text-2); }
.group-body { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.cell {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 10px 16px;
  position: relative;
}
.group-body > .cell + .cell::before, .group-body > * + .cell::before, .group-body > .cell + *::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep);
}
.tappable:active { background: var(--fill); }
.cell.muted, .muted { color: var(--text-2); }
.faint { color: var(--text-3); margin: 4px 0; }
.chev { color: var(--text-3); margin-left: auto; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.cell.stack { align-items: stretch; }
.row { display: flex; align-items: center; gap: 8px; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.center { text-align: center; align-items: center; }
.left { text-align: left; }
.pad { padding: 0 16px; }
.spacer { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { font-size: 0.8rem; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.strike { text-decoration: line-through; color: var(--text-2); }
.ok { color: var(--green); font-weight: 600; }
.error-text { color: var(--red); }
.destructive { color: var(--red); justify-content: center; }
.link-row { color: var(--accent); }
.note { color: var(--text-2); font-size: 0.85rem; margin: 0 16px 16px; }
.note.center { text-align: center; }

.card {
  display: block; width: 100%; background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 14px;
}
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text); }
.card-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.card-head .icon { color: var(--accent); }
.card p { margin: 4px 0; }
.card .list .cell { padding-left: 0; padding-right: 0; }
.card .list .cell + .cell::before { left: 0; content: ""; position: absolute; top: 0; right: 0; border-top: 0.5px solid var(--sep); }

.briefing { display: flex; align-items: center; gap: 12px; text-align: left; }
.briefing .sun { font-size: 1.8rem; }
.countdown { margin-top: 6px; }
.add-link { margin-top: 6px; display: inline-block; }
.plain-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 4px 0; text-align: left; }
.plain-row .time { width: 3.6em; font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 0.9rem; }

/* ---------------------------------------------------------------- tasks & events */

.task-row { gap: 10px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 2px 0; }
.row-main .title { overflow-wrap: anywhere; }
.rolled { color: var(--orange); font-weight: 600; }
.urgent { color: var(--red); font-weight: 800; }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 14px; border: 2px solid var(--text-3);
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
}
.check.done { background: var(--green); border-color: var(--green); }
.owner { display: inline-flex; align-items: center; gap: 4px; }
.owner-label { font-size: 0.8rem; color: var(--text-2); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 4px 12px; }

.event-row { align-items: flex-start; text-align: left; }
.event-time { width: 3.4em; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.event-time b { font-size: 0.95rem; }
.event-time small { color: var(--text-2); }
.event-bar { width: 4px; align-self: stretch; border-radius: 2px; }

.day { padding: 12px 14px; }
.day.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.day.past { opacity: 0.6; }
.day-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.pill { font-size: 0.65rem; font-weight: 800; color: #fff; background: var(--accent); border-radius: 8px; padding: 2px 6px; }
.day .check { width: 22px; height: 22px; }

.week-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }

/* month grid */
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dow { font-size: 0.7rem; color: var(--text-2); padding: 4px 0; }
.month-grid .day {
  position: relative; padding: 0; height: 40px; border-radius: 20px; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center; background: none; margin: 0;
}
.month-grid .day.other { color: var(--text-3); }
.month-grid .day.today { color: var(--accent); font-weight: 700; }
.month-grid .day.sel { background: var(--accent); color: #fff; font-weight: 700; }
.month-grid .dot { position: absolute; bottom: 5px; width: 5px; height: 5px; border-radius: 3px; background: var(--text-3); }
.month-grid .day.sel .dot { background: #fff; }

/* ---------------------------------------------------------------- controls */

.seg {
  display: flex; background: var(--fill); border-radius: 9px; padding: 2px; margin: 0 0 14px; gap: 2px;
}
.cell .seg { margin: 0; flex: 1; }
.seg button {
  flex: 1; min-height: 34px; border-radius: 7px; font-size: 0.85rem; font-weight: 500; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
}
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 18px;
  background: var(--fill); border: 1.5px solid transparent; font-size: 0.9rem;
}
.chip.on { color: #fff; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px;
  border-radius: 12px; background: var(--fill); color: var(--accent); font-weight: 600; text-align: center;
}
.btn.small { min-height: 34px; padding: 0 12px; font-size: 0.85rem; border-radius: 10px; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn:active { opacity: 0.8; }
.button-row { display: flex; gap: 10px; justify-content: center; margin: 4px 16px 22px; flex-wrap: wrap; }
.button-row .btn { flex: 1; min-width: 40%; }
.link { color: var(--accent); font-weight: 500; }
.link.strong { font-weight: 700; }
.link.small { font-size: 0.8rem; }

.input {
  width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; padding: 6px 0; font-size: 1rem;
}
textarea.input { resize: vertical; line-height: 1.4; }
select.input { -webkit-appearance: none; appearance: none; text-align: right; color: var(--accent); padding-right: 2px; }
input[type="date"].input, input[type="time"].input { text-align: right; color: var(--accent); min-height: 34px; }
.field { justify-content: space-between; }
.field-label { flex: none; min-width: 7em; }
.field .input { flex: 1; text-align: right; }
.row-inputs { display: flex; gap: 8px; flex: 1; justify-content: flex-end; }
.row-inputs .input { width: auto; flex: 1; }
.inline-select { border: 0; background: transparent; color: var(--accent); font-size: inherit; }
.ing-row { gap: 6px; }
.qty-in { max-width: 3.6em; }
.unit-in { max-width: 4em; }
.label-in { max-width: 8em; color: var(--text-2); }
.add-row { gap: 10px; color: var(--accent); }
.add-row .input { color: var(--text); }
.qty, .qty-right { color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 3.5em; }
.qty-right { min-width: 0; text-align: right; }
.suggestion { color: var(--accent); }
.step { align-items: flex-start; }
.step b { color: var(--accent); width: 1.4em; flex: none; }
.stepper { display: inline-flex; gap: 1px; background: var(--sep); border-radius: 9px; overflow: hidden; }
.stepper button { width: 44px; height: 34px; background: var(--fill); font-size: 1.2rem; text-align: center; }

.toggle-row { cursor: pointer; }
.switch {
  -webkit-appearance: none; appearance: none; flex: none; width: 51px; height: 31px; border-radius: 16px;
  background: var(--fill); position: relative; transition: background 0.2s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; width: 100%; }
.weekdays button { min-height: 36px; border-radius: 8px; background: var(--fill); font-size: 0.8rem; font-weight: 600; text-align: center; }
.weekdays button.on { background: var(--accent); color: #fff; }

.level {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 3px 9px; border-radius: 10px;
  background: var(--fill); white-space: nowrap;
}
.level-plenty { color: #00835f; background: rgba(0, 158, 115, 0.15); }
.level-enough { color: #0062a0; background: rgba(0, 114, 178, 0.15); }
.level-low { color: #9a5d00; background: rgba(230, 159, 0, 0.2); }
.level-none { color: #b84f00; background: rgba(213, 94, 0, 0.18); }
@media (prefers-color-scheme: dark) {
  .level-plenty { color: #4fd1a5; } .level-enough { color: #6cc3f5; } .level-low { color: #ffc456; } .level-none { color: #ff8f4d; }
}
.level-select { position: relative; display: inline-flex; }
.level-select select { position: absolute; inset: 0; opacity: 0; width: 100%; font-size: 16px; }
.pin { color: var(--orange); }

.meal-row { gap: 6px; }
.meal-row .row-main { flex-direction: row; align-items: center; gap: 12px; }
.meal-day { width: 2.8em; display: flex; flex-direction: column; font-weight: 600; }
.meal-day small { color: var(--text-2); font-weight: 400; }
.meal-day.today { color: var(--accent); }
.hero { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius); margin-bottom: 16px; }
.inbox-row { gap: 6px; }
.note-line { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.note-line + .note-line { border-top: 0.5px solid var(--sep); }
.briefing-text { white-space: pre-wrap; font: inherit; margin: 0 16px 16px; line-height: 1.5; }
.token { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; word-break: break-all; background: var(--fill); padding: 8px; border-radius: 8px; }

.empty { text-align: center; color: var(--text-2); padding: 32px 24px; }
.empty .icon { color: var(--text-3); }
.empty h3 { color: var(--text); margin: 10px 0 6px; font-size: 1.1rem; }
.empty p { margin: 0 0 16px; }
.big-emoji { font-size: 1.8rem; }

/* ---------------------------------------------------------------- banners & toast */

.banners { margin: 0 0 8px; }
.banner { margin: 0 0 8px; padding: 10px 12px; border-radius: 10px; font-size: 0.85rem; display: flex; gap: 8px; justify-content: space-between; }
.banner.warn { background: rgba(255, 159, 10, 0.16); color: var(--orange); }
.banner.info { background: rgba(10, 132, 255, 0.12); color: var(--accent); }
.banner.error { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-b) + 90px); max-width: 90vw;
  background: rgba(30, 30, 30, 0.92); color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 0.9rem;
}

/* ---------------------------------------------------------------- sheets */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: flex-end; justify-content: center; animation: fade 0.2s ease;
}
.sheet {
  width: 100%; max-width: 720px; height: calc(100% - var(--safe-t) - 10px);
  background: var(--bg); border-radius: 14px 14px 0 0; display: flex; flex-direction: column;
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 14px 16px 10px; border-bottom: 0.5px solid var(--sep);
}
.sheet-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; text-align: center; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-head .link:last-child { justify-self: end; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px calc(var(--safe-b) + 40px); }
.sheet-body > .seg { margin-bottom: 18px; }
.action-sheet { width: 100%; max-width: 520px; padding: 0 10px calc(var(--safe-b) + 10px); animation: rise 0.22s ease; }
.action-group { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 8px; max-height: 70vh; overflow-y: auto; }
.action-title { margin: 0; padding: 12px 16px; text-align: center; color: var(--text-2); font-size: 0.8rem; border-bottom: 0.5px solid var(--sep); }
.action { display: block; width: 100%; min-height: 56px; text-align: center; color: var(--accent); font-size: 1.05rem; }
.action + .action { border-top: 0.5px solid var(--sep); }
.action.destructive { color: var(--red); }
.action.cancel { background: var(--card); border-radius: 14px; font-weight: 600; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------------------------------------------------------------- setup */

.setup { padding-bottom: calc(var(--safe-b) + 40px); }
.setup-head { text-align: center; padding: 24px 16px 20px; }
.setup-head h1 { margin: 8px 0 6px; font-size: 1.6rem; }
.setup-head p { margin: 0; }
.logo { font-size: 3rem; }
.steps { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; }
.steps code, .note code { background: var(--fill); padding: 1px 5px; border-radius: 5px; }
