:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #1c2540;
  --ink-2: #4a5270;
  --muted: #8a8fa3;
  --line: #e6e1d8;
  --accent: #d9482b;
  --accent-soft: #fbe7e1;
  --navy: #1c2540;
  --good: #2f7d4f;
  --good-soft: #e3f1e8;
  --bad: #b83a2a;
  --bad-soft: #f8e3df;
  --gold: #b7862c;
  --gold-soft: #f6ecd7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(28, 37, 64, .06), 0 4px 16px rgba(28, 37, 64, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151f;
    --surface: #1a2030;
    --surface-2: #161b28;
    --ink: #eef0f6;
    --ink-2: #b9bfd2;
    --muted: #7d849b;
    --line: #2a3145;
    --accent: #f06446;
    --accent-soft: #3a2420;
    --good: #5cc287;
    --good-soft: #1d3327;
    --bad: #f07a68;
    --bad-soft: #3a2420;
    --gold: #e0b45a;
    --gold-soft: #33291a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--navy);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand > div { min-width: 0; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,.1); border: 0; color: #fff; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.status-pill {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 99px;
  background: rgba(255,255,255,.14); white-space: nowrap;
}
.status-pill.offline { background: var(--gold); color: #1c1c1c; }

/* ---------- layout ---------- */
main {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  outline: none;
}
.section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 26px 4px 10px;
}
.section-title:first-child { margin-top: 4px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card.flush { padding: 0; overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px;
  text-decoration: none; font-size: 11px; font-weight: 600; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--accent); color: #fff; font-weight: 650; cursor: pointer;
}
.btn.secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 0; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
  font-size: 16px; /* stops iOS zoom on focus */
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: none;
  font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.error { color: var(--bad); font-size: 14px; margin: 4px 0 12px; min-height: 1em; }

/* ---------- auth ---------- */
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth h1 { font-size: 26px; margin: 0 0 4px; }
.auth p { margin: 0 0 22px; color: var(--ink-2); }

/* ---------- itinerary ---------- */
.hero {
  background: var(--navy); color: #fff; border-radius: var(--radius);
  padding: 18px; margin-bottom: 12px; position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -46px; top: -46px; width: 128px; height: 128px;
  border-radius: 50%; background: var(--accent); opacity: .9;
}
.hero > * { position: relative; z-index: 1; }
.hero .kicker, .hero .big { padding-right: 64px; }
.hero .kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .7; }
.hero .big { font-size: 28px; font-weight: 800; margin: 2px 0 4px; }
.hero .sub { opacity: .85; font-size: 14px; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.hero .chip { background: rgba(255,255,255,.14); padding: 5px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }

.day { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.day > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 14px 16px;
}
.day > summary::-webkit-details-marker { display: none; }
.day .date-badge {
  flex: none; width: 48px; text-align: center; border-radius: 12px; padding: 6px 0;
  background: var(--surface-2); border: 1px solid var(--line);
}
.day .date-badge .dow { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.day .date-badge .dnum { font-size: 20px; font-weight: 800; line-height: 1.1; }
.day.today .date-badge { background: var(--accent); border-color: var(--accent); color: #fff; }
.day.today .date-badge .dow { color: rgba(255,255,255,.85); }
.day.past { opacity: .62; }
.day .area { font-weight: 700; }
.day .meta { font-size: 13px; color: var(--muted); }
.day .chev { margin-left: auto; width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; transition: transform .2s; flex: none; }
.day[open] .chev { transform: rotate(180deg); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; vertical-align: 1px; }
.tag.booked { background: var(--good-soft); color: var(--good); }
.tag.today { background: var(--accent-soft); color: var(--accent); }
.tag.est { background: var(--gold-soft); color: var(--gold); }

.stops { list-style: none; margin: 0; padding: 0 16px 14px 16px; }
.stop { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.stop .t { font-size: 13px; font-weight: 700; color: var(--ink-2); padding-top: 1px; }
.stop .n { font-weight: 600; }
.stop .note { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.stop .map { font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; display: inline-block; margin-top: 4px; }

.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv th, .kv td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.kv tr:first-child th, .kv tr:first-child td { border-top: 0; }
.kv th { font-weight: 600; color: var(--ink-2); width: 38%; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.prayer { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.prayer th, .prayer td { padding: 8px 6px; text-align: center; border-top: 1px solid var(--line); white-space: nowrap; }
.prayer thead th { border-top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.prayer td:first-child, .prayer th:first-child { text-align: left; padding-left: 14px; }
.prayer tr.today td { background: var(--accent-soft); font-weight: 700; }
.tips { margin: 0; padding-left: 18px; }
.tips li { margin: 6px 0; }

/* ---------- budget ---------- */
.settle {
  border-radius: var(--radius); padding: 18px; margin-bottom: 12px;
  background: var(--good-soft); color: var(--good);
}
.settle.owing { background: var(--navy); color: #fff; }
.settle .kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .75; }
.settle .line { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }
.settle .sub { font-size: 13px; opacity: .8; }
.people { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.person { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.person .name { font-weight: 700; margin-bottom: 6px; }
.person .stat { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); margin: 3px 0; font-variant-numeric: tabular-nums; }
.person .bal { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-weight: 800; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.totals { display: flex; gap: 10px; margin-bottom: 4px; }
.totals .card { flex: 1; margin: 0; padding: 12px 14px; }
.totals .lab { font-size: 12px; color: var(--muted); font-weight: 600; }
.totals .val { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }

.exp-group { font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 4px 6px; text-transform: uppercase; letter-spacing: .06em; }
.exp {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-top: 1px solid var(--line); cursor: pointer; background: var(--surface);
}
.exp:first-child { border-top: 0; }
.exp .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); flex: none; font-size: 17px; }
.exp .body { flex: 1; min-width: 0; }
.exp .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp .sub { font-size: 12px; color: var(--muted); }
.exp .amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.exp .amt small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.exp.settled .title, .exp.settled .amt { text-decoration: line-through; color: var(--muted); }
.check {
  width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line); background: var(--surface);
  display: grid; place-items: center; flex: none; cursor: pointer; padding: 0;
}
.check svg { width: 16px; height: 16px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
.check.on { background: var(--good); border-color: var(--good); }
.check.on svg { opacity: 1; }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(84px + var(--safe-bottom)); z-index: 15;
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(217, 72, 43, .35);
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; }
.filters { display: flex; gap: 8px; margin: 18px 0 6px; align-items: center; }
.pill-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.pill-btn.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---------- checklist ---------- */
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--good); border-radius: 99px; transition: width .3s; }
.chk-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 8px; }
.chk-head h3 { margin: 0; font-size: 15px; }
.chk-head span { font-size: 12px; color: var(--muted); font-weight: 600; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .txt { flex: 1; cursor: pointer; }
.item.done .txt { text-decoration: line-through; color: var(--muted); }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.add-row .input[name=text] { flex: 1 1 100%; }
.add-row select.input { flex: 1; width: auto; }
.add-row .btn { flex: 0 0 96px; }
.nowrap { white-space: nowrap; }
main[data-tab=budget] { padding-bottom: calc(170px + var(--safe-bottom)); }
.day { scroll-margin-top: 78px; }

/* ---------- sheet & toast ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 26, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 640px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + var(--safe-bottom));
  animation: up .22s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet .actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(92px + var(--safe-bottom));
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); max-width: calc(100% - 32px);
  display: flex; gap: 12px; align-items: center;
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.loading { text-align: center; padding: 48px 0; color: var(--muted); }
