/* Spento design tokens. Cream paper, deep green primary, warm tan highlight.
   Text pairs meet WCAG AA (4.5:1) on both bg and surface. */
:root {
  --bg: #f2ead8;
  --surface: #fbf7ee;
  --ink: #1d2620;
  --muted: #5d5a50;
  --accent: #24382e;
  --accent-hover: #34513f;
  --accent-soft: rgba(36, 56, 46, .09);
  --tan: #cdab88;
  --tan-strong: #8b6a45;
  --line: #e6dcc6;
  --border: #d3c7ac;
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, .08);
  --success: #2f6a2a;
  --warning: #8a5a00;
  --focus: rgba(36, 56, 46, .22);
  --radius-sm: 10px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(29, 38, 32, .06);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; -webkit-tap-highlight-color: transparent; }
a, button, input, select, label { touch-action: manipulation; }

h1, h2 { margin: 0; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; margin-bottom: .875rem; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  padding-top: calc(.75rem + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--accent);
}
.brand-mark { width: 28px; height: 28px; flex: none; }
#user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 14px;
}
.settings-link {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}
.settings-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.menu { position: relative; flex: none; }
.menu-panel {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  z-index: 2;
  min-width: 11rem;
  padding: .25rem;
  display: grid;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.menu-panel[hidden] { display: none; }
.menu-panel > a, .menu-panel > button {
  display: block;
  width: 100%;
  padding: .75rem .875rem;
  text-align: left;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: calc(6rem + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
}

.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
.view:not([hidden]) { animation: view-in .2s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

/* Month selector: a compact pill above the views. */
.month-row { display: flex; justify-content: flex-start; }
.month-row label {
  display: flex;
  align-items: center;
  gap: .625rem;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.month-row input { width: auto; min-width: 11rem; border-radius: 999px; padding-left: 1rem; padding-right: 1rem; }

/* Bottom navigation (mobile); a floating bar on wide screens. */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
}
.tabbar a:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
.tabbar a:active { background: var(--accent-soft); }
.tabbar svg {
  width: 32px;
  height: 32px;
  padding: 4px;
  border-radius: 999px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: background-color .15s;
}
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tabbar a[aria-current="page"] svg { background: var(--accent-soft); }

@media (min-width: 720px) {
  .tabbar {
    left: 50%;
    right: auto;
    bottom: 1rem;
    width: min(calc(100% - 2rem), 720px);
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(29, 38, 32, .12);
  }
}

/* Cards and sections */
section, .card { min-width: 0; overflow-x: auto; }
.view > section:not(.cards) {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* Summary cards. */
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}
.card {
  display: grid;
  gap: .25rem;
  padding: 1rem 1.125rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card span { font-size: 13px; font-weight: 500; color: var(--muted); }
.card p {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.card.total { background: var(--accent); border-color: var(--accent); grid-column: 1 / -1; }
@media (min-width: 560px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card.total { grid-column: auto; }
}
.card.total span { color: rgba(242, 234, 216, .8); }
.card.total p { color: var(--bg); }

/* Forms */
form { display: grid; gap: 1rem; }
.form-grid { grid-template-columns: 1fr; gap: 1rem; }
.wide { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}

label {
  display: grid;
  gap: .375rem;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.member-filter { max-width: 260px; margin-bottom: 1rem; }

input:not([type="checkbox"]), select {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  font-weight: 400;
  width: 100%;
  min-height: 44px;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #6f6b61; }
input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 0;
  padding: 0;
  flex: none;
  accent-color: var(--accent);
}

.split-toggle, .remember {
  display: flex;
  align-items: center;
  gap: .625rem;
  font-size: 15px;
  font-weight: 400;
}

fieldset {
  display: grid;
  gap: .75rem;
  min-width: 0;
  margin: 0;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
legend { padding: 0 .375rem; font-size: 13px; font-weight: 600; color: var(--muted); }
#tx-split-rows { display: grid; gap: .5rem; }
.split-row {
  display: grid;
  grid-template-columns: 1fr 6rem auto;
  align-items: center;
  gap: .5rem;
  font-size: 15px;
  font-weight: 400;
}
.split-row input { text-align: right; }

/* Buttons */
button {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  min-height: 44px;
  padding: .5rem .875rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .1s;
}
button:hover { background: var(--accent-soft); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }

/* Login */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  background: var(--bg);
}
.login {
  width: 100%;
  max-width: 360px;
  gap: 1rem;
  padding: 2rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}
.brand { display: grid; place-items: center; margin: 0 auto .25rem; }
.brand svg { width: 64px; height: 64px; }
.login .error { color: var(--danger); }
.input-row { position: relative; }
.login .input-row input { padding-left: 2.75rem; }
.input-row:has(.icon-button) input { padding-right: 3rem; }
.field-icon {
  position: absolute;
  left: .9rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.icon-button {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 44px;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--muted);
}
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.login button.primary { width: 100%; min-height: 48px; font-size: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.error { min-height: 1em; margin: 0; color: var(--danger); font-size: 14px; font-weight: 500; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.insight {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 14px;
}
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num.negative { color: var(--danger); }
.num.income { color: var(--success); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: .75rem .5rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
td { font-size: 15px; }

/* Status tags */
.tag {
  display: inline-flex;
  align-items: center;
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag-success { color: var(--success); background: rgba(47, 106, 42, .1); }
.tag-warning { color: var(--warning); background: rgba(138, 90, 0, .1); }

/* Budgets */
.budget-tabs {
  display: inline-flex;
  gap: 4px;
  margin: 0 0 1rem;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.budget-tabs button {
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.budget-tabs button[aria-selected="true"] {
  background: var(--accent);
  color: var(--surface);
}
#budget-list {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: grid;
  gap: .75rem;
}
#budget-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem .75rem;
  align-items: center;
  padding: .875rem 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
}
#budget-list li > div { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
#budget-list progress {
  grid-column: 1 / -1;
  width: 100%;
  height: 8px;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
#budget-list progress::-webkit-progress-bar { background: var(--line); border-radius: 999px; }
#budget-list progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
#budget-list progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
#budget-list li.personal { border-left-color: var(--tan-strong); }
#budget-list li.personal progress::-webkit-progress-value { background: var(--tan-strong); }
#budget-list li.personal progress::-moz-progress-bar { background: var(--tan-strong); }
#budget-list li.over { color: var(--danger); }
#budget-list li.over progress::-webkit-progress-value { background: var(--danger); }
#budget-list li.over progress::-moz-progress-bar { background: var(--danger); }
#category-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: .5rem;
}
#category-list li {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
#category-list li > div, #category-list .error { grid-column: 1 / -1; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
#category-list .error:empty { display: none; }
#category-list li > button { background: var(--surface); border-color: var(--line); }

/* Expenses */
#tx-list, #inc-list, #recurring-list, #tr-list, #upcoming-list { list-style: none; margin: 0; padding: 0; display: grid; }
#tx-list > li:not(.tx), #inc-list > li:not(.tx), #recurring-list > li:not(.tx), #tr-list > li:not(.tx), #upcoming-list > li:not(.tx) { padding: .5rem 0; color: var(--muted); }
.tx {
  display: grid;
  gap: .25rem;
  padding: .875rem 0;
  border-bottom: 1px solid var(--line);
}
#tx-list .tx:first-child, #inc-list .tx:first-child, #recurring-list .tx:first-child, #tr-list .tx:first-child, #upcoming-list .tx:first-child { padding-top: 0; }
#tx-list .tx:last-child, #inc-list .tx:last-child, #recurring-list .tx:last-child, #tr-list .tx:last-child, #upcoming-list .tx:last-child { border-bottom: 0; }
.tx-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
  font-weight: 600;
}
.tx-desc { min-width: 0; overflow-wrap: anywhere; }
.tx-top .num { font-size: 16px; font-weight: 700; }
.tx-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.tx button { justify-self: start; margin-top: .25rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .75rem; }

/* Per-person shares of one expense, with paid status. */
.shares {
  display: grid;
  gap: .5rem;
  margin-top: .375rem;
  padding: .625rem .75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.share { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem .625rem; font-size: 14px; }
.share-text { flex: 1 1 12rem; min-width: 0; overflow-wrap: anywhere; }
.share-pay { flex: 1 1 100%; display: flex; align-items: center; gap: .5rem; }
.share-pay input { flex: 0 1 9rem; min-width: 0; min-height: 40px; }
.link-button {
  min-height: 40px;
  padding: .25rem .5rem;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
}

/* Chart */
.chart { width: 100%; height: auto; display: block; margin: .5rem 0 .75rem; }
.chart .bar { fill: var(--accent); }
.chart .bar.over { fill: var(--danger); }
.chart .limit { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart .axis { fill: var(--muted); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Home: week picker and each person's spend against their monthly personal budget */
.week-home { display: grid; gap: 1.25rem; }
.week-home h2 { margin: 0; }
.week-nav { display: flex; align-items: center; gap: .5rem; }
.week-nav select { flex: 1; min-width: 0; min-height: 44px; }
.week-nav button {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
}
.week-nav button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.week-nav button:disabled { opacity: .4; cursor: default; }
#weekly-list { display: grid; gap: 1rem; }
.week-person {
  display: grid;
  gap: .75rem;
  padding: 1.125rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 4px solid var(--tan-strong);
  border-radius: var(--radius-sm);
}
.week-person header { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.week-person h3 { margin: 0; font-size: 15px; font-weight: 600; }
.week-amount { font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.week-track { display: flex; height: 12px; border-radius: 999px; background: var(--line); overflow: hidden; }
.week-track .seg { height: 100%; }
.week-track .seg.earlier { background: var(--tan); }
.week-track .seg.week { background: var(--accent); }
.week-track.over .seg.week { background: var(--danger); }
.week-meta { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.week-meta.over { color: var(--danger); font-weight: 600; }
.week-cats { list-style: none; margin: .25rem 0 0; padding: 0; display: grid; gap: .625rem; }
.week-cats li { display: grid; grid-template-columns: 1fr auto; gap: .25rem .5rem; font-size: 14px; }
.week-cat-amount { text-align: right; font-variant-numeric: tabular-nums; }
.week-cat-track { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.week-cat-fill { display: block; height: 100%; background: var(--accent); }
.week-cat-track.over .week-cat-fill { background: var(--danger); }
.week-cat-used { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.week-cat-used.over { color: var(--danger); font-weight: 600; }
