/* Our Life OS. Layout: one column of working panels; bottom tab bar on phones,
   top tab bar on wide screens. Teal is the household colour, marigold marks
   what needs attention, red is only for overdue. */
:root {
  --bg: #f3f5f4; --surface: #ffffff; --surface-2: #eef2f1; --ink: #14302e; --muted: #5b6f6c; --line: #d9e1df;
  --teal: #1f5c57; --teal-soft: #e2eeec; --on-teal: #f4fbfa;
  --accent: #c9820f; --accent-soft: #fbefd9; --on-accent: #1b1205;
  --bad: #b4372b; --bad-soft: #f8e3e0; --good: #2f7a4c; --good-soft: #e1f1e7;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 12px; --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1918; --surface: #162423; --surface-2: #1c2e2c; --ink: #e4efed; --muted: #93a9a5; --line: #2a3d3b;
    --teal: #7cc3bb; --teal-soft: #1d3532; --on-teal: #0f1918;
    --accent: #eba73a; --accent-soft: #3a2c14; --on-accent: #1b1205;
    --bad: #f08a7e; --bad-soft: #3b1f1c; --good: #7fcf9c; --good-soft: #17301f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.5;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--f-display); margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-family: var(--f-body); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
p { margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.pad { padding: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- splash and sign-in ---------- */
.splash, .signin {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.brand { font-family: var(--f-display); font-weight: 700; font-size: 1.4rem; color: var(--teal); }
.signin-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.signin-card h1 { color: var(--teal); }
.signin-card form { display: flex; flex-direction: column; gap: 10px; }
.code-input { font-family: var(--f-mono); font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; }

/* ---------- shell ---------- */
.shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 920px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .brand { font-size: 1.15rem; }
.status { font-size: 0.8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.status.off .dot { background: var(--accent); }
main { flex: 1; width: 100%; max-width: 920px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); display: flex; flex-direction: column; gap: 16px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav a {
  height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--teal); }
.nav .badge { position: relative; }
.nav .badge[data-n]::after {
  content: attr(data-n); position: absolute; top: -4px; right: -10px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--bad); color: #fff; font-size: 0.65rem; line-height: 16px; text-align: center;
}
@media (min-width: 760px) {
  .nav { position: sticky; top: calc(env(safe-area-inset-top) + 53px); bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); background: var(--bg);
         display: flex; justify-content: center; gap: 4px; padding: 0 16px; }
  .nav a { height: 48px; flex-direction: row; gap: 8px; font-size: 0.9rem; padding: 0 14px; border-bottom: 2px solid transparent; }
  .nav a[aria-current="page"] { border-bottom-color: var(--teal); }
  .nav a svg { width: 18px; height: 18px; }
  main { padding-bottom: 48px; }
}

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.hero { background: var(--teal); color: var(--on-teal); border-radius: 16px; padding: 18px; display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.hero .big { font-family: var(--f-display); font-size: 2.6rem; font-weight: 700; line-height: 1; }
.hero .big small { display: block; font-family: var(--f-body); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; margin-top: 4px; }
.hero p { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); background: var(--bg); color: var(--muted); border-radius: 999px; padding: 4px 10px; font-size: 0.85rem; }
.chip b { color: var(--ink); font-variant-numeric: tabular-nums; }
.chip.warn { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.chip.warn b { color: var(--bad); }
.chip.soon { border-color: var(--accent); background: var(--accent-soft); }

.seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.seg::-webkit-scrollbar { display: none; }
.seg button { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- forms ---------- */
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
label.check { display: flex; gap: 10px; align-items: center; font-size: 0.95rem; }
label.check input { width: 20px; height: 20px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; cursor: pointer; background: var(--accent); color: var(--on-accent); }
.btn.teal { background: var(--teal); color: var(--on-teal); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.small { padding: 7px 12px; font-size: 0.85rem; }
.quick { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.quick-more { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.error { color: var(--bad); font-size: 0.9rem; }
.note { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; }

/* ---------- item list ---------- */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; padding: 12px 2px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item.over { box-shadow: inset 3px 0 0 var(--bad); padding-left: 12px; }
.item.soon { box-shadow: inset 3px 0 0 var(--accent); padding-left: 12px; }
.tick { width: 26px; height: 26px; margin-top: 1px; border-radius: 8px; border: 2px solid var(--teal); background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0; }
.tick[aria-checked="true"] { background: var(--teal); }
.tick[aria-checked="true"]::after { content: ""; width: 7px; height: 12px; border: solid var(--surface); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.item-body { min-width: 0; cursor: pointer; background: none; border: 0; padding: 0; text-align: left; }
.item-title { overflow-wrap: anywhere; }
.done .item-title { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.meta .over { color: var(--bad); font-weight: 600; }
.meta .soon { color: var(--accent); font-weight: 600; }
.who { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; background: var(--teal-soft); color: var(--teal); }
.tag { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.lock { font-size: 0.75rem; }
.empty { color: var(--muted); padding: 16px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 6px 0; }

/* ---------- progress, budget ---------- */
.bar { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--teal); border-radius: 6px; }
.bar.warn > span { background: var(--bad); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
td input { padding: 6px 8px; }
td input.n { width: 100px; text-align: right; font-family: var(--f-mono); font-size: 0.85rem; }
td input.c { width: 170px; }
td input.p { width: 120px; }
tfoot td { font-weight: 700; border-bottom: 0; }
.over-budget { color: var(--bad); }
.over-budget input { border-color: var(--bad); color: var(--bad); }
.budget { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.budget-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.budget-row.is-over { box-shadow: inset 3px 0 0 var(--bad); }
.budget-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.budget-top input { font-weight: 600; }
.budget-confirm { display: flex; gap: 6px; }
.budget-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .budget-fields { grid-template-columns: 1fr 1fr; } }

/* ---------- activity ---------- */
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.feed li { display: grid; grid-template-columns: 32px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.feed li:first-child { border-top: 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--teal-soft); color: var(--teal); display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; }
.feed time { font-size: 0.8rem; color: var(--muted); }

/* ---------- sheet (edit item) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8, 20, 19, 0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92%; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
}
@media (min-width: 760px) { .scrim { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 30;
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 14px; font-size: 0.9rem; display: flex; gap: 12px; align-items: center;
  max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; }
@media (min-width: 760px) { .toast { bottom: 24px; } }

@media (max-width: 420px) {
  .hero { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .tick, .btn, .seg button { transition: background-color 0.15s, color 0.15s; }
}
