:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #1b1f1d;
  --muted: #6a706c;
  --line: #e4e2db;
  --accent: #1f3d34;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece7;
  --late: #b42318;
  --late-soft: #fdecea;
  --soon: #9a5b00;
  --soon-soft: #fdf1dc;
  --ok: #1d6b45;
  --ok-soft: #e2f2e8;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --card: #1b1e1c;
    --ink: #eceeea;
    --muted: #9aa19c;
    --line: #2c302d;
    --accent: #9fd1bb;
    --accent-ink: #10201a;
    --accent-soft: #23332c;
    --late: #ff8a7a;
    --late-soft: #3a1f1b;
    --soon: #f3bf63;
    --soon-soft: #362a15;
    --ok: #7fd3a4;
    --ok-soft: #1c3226;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
}

.crumb { color: var(--muted); font-weight: 500; }
.crumb:not(:empty)::before { content: "/"; margin-right: 8px; opacity: 0.5; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-left));
}

h1, h2, h3 { margin: 0; letter-spacing: -0.015em; }

.page-title { font-size: 28px; font-weight: 700; margin: 8px 0 4px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 16px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 17px;
  font-weight: 650;
  margin: 0 0 8px;
}

.section-title .count { font-size: 14px; font-weight: 500; color: var(--muted); }

/* Hub */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 120px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.tile:active { transform: scale(0.98); }
.tile-icon { font-size: 26px; line-height: 1; margin-bottom: auto; }
.tile-title { font-weight: 650; }
.tile-blurb { font-size: 13px; color: var(--muted); }
.tile-soon { opacity: 0.55; box-shadow: none; }

/* Hero */
.hero { background: var(--accent); color: var(--accent-ink); border: 0; padding: 20px; }
.hero .eyebrow { margin: 0; font-size: 14px; opacity: 0.8; font-weight: 500; }
.hero .big { margin: 4px 0 0; font-size: 36px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.hero .big-sub { margin: 2px 0 0; font-size: 18px; font-weight: 600; opacity: 0.9; }
.hero .hero-meta { margin: 8px 0 0; font-size: 14px; opacity: 0.8; }

/* Bill rows */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.list > .row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-weight: 600; overflow-wrap: anywhere; }
.row-meta { font-size: 14px; color: var(--muted); }
.row-note { font-size: 13px; color: var(--muted); font-style: italic; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.amt { font-weight: 650; white-space: nowrap; }
.row.late .row-meta { color: var(--late); }
.row.soon .row-meta { color: var(--soon); }
.row.is-paid .amt { color: var(--muted); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: capitalize;
}
.pill.paid, .pill.added { background: var(--ok-soft); color: var(--ok); }
.pill.late { background: var(--late-soft); color: var(--late); }
.pill.approved, .pill.soon { background: var(--soon-soft); color: var(--soon); }

.empty { padding: 8px 0 4px; color: var(--muted); }

details.more > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 0 2px;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more[open] > summary { margin-bottom: 4px; }

/* Buttons */
.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  min-height: 44px;
  font: inherit;
  font-weight: 650;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:focus-visible, .icon-btn:focus-visible, .tile:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 6;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
  border-radius: 999px;
  padding: 14px 22px;
}

/* Month view */
.month-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.month-head h2 { font-size: 18px; text-align: center; flex: 1; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  font-weight: 600;
  text-decoration: none;
}
.icon-btn.disabled { opacity: 0.35; pointer-events: none; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; min-width: 0; }
.stat-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { display: block; font-weight: 700; font-size: 15px; white-space: nowrap; }

@media (max-width: 479px) {
  .stats { grid-template-columns: 1fr; gap: 0; background: var(--bg); border-radius: 12px; padding: 4px 12px; }
  .stat { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-radius: 0; }
  .stat + .stat { border-top: 1px solid var(--line); }
}
.stat.topay .stat-value { color: var(--late); }
.stat.paid .stat-value { color: var(--ok); }
.currency-label { font-size: 13px; color: var(--muted); margin: 4px 0; }

/* Forms */
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 15px; }
.field .hint { font-size: 13px; color: var(--muted); }
input, select {
  font: inherit;
  font-size: 17px; /* 16px+ stops iPhone zooming in */
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.form-actions { display: flex; gap: 12px; }
.form-actions .btn { flex: 1; }
.form-error { color: var(--late); font-weight: 600; margin: 0; }

/* Status */
.loading { padding: 48px 0; text-align: center; color: var(--muted); }
.error-box { text-align: center; padding: 32px 16px; }
.error-box p { margin: 0 0 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}
.toast.error { background: var(--late); color: #fff; }

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: no-preference) {
  .tile, .btn { transition: transform 0.12s ease, opacity 0.12s ease; }
}
