:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1c1c1a; --muted: #6b6b66; --line: #e4e2db;
  --accent: #1f6f5f; --accent-ink: #ffffff; --pos: #1f6f5f; --neg: #b3402e; --warn: #9a6b00;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --card: #1e1e1b; --ink: #ecebe6; --muted: #9c9b94; --line: #33332f;
    --accent: #4fb39b; --accent-ink: #0f1b18; --pos: #4fb39b; --neg: #e2735f; --warn: #d9a83a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; padding-bottom: 96px;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

header.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
header.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
header.top h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
header.top .who { font-size: 13px; color: var(--muted); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
header.top .who strong { color: var(--ink); }

nav.tabs { display: flex; gap: 4px; padding: 8px 16px 0; max-width: 640px; margin: 0 auto; }
nav.tabs button {
  flex: 1; background: none; border: none; border-bottom: 2px solid transparent;
  padding: 8px 0 10px; color: var(--muted); font-weight: 600;
}
nav.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

main { padding-top: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.fab {
  position: fixed; right: 20px; bottom: 24px; z-index: 6;
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 999px;
  height: 56px; padding: 0 22px; font-size: 16px; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

/* expense list */
.day { margin: 18px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.exp { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.exp:first-of-type { border-top: none; }
.exp .title { font-weight: 600; }
.exp .sub { font-size: 13px; color: var(--muted); grid-column: 1; }
.exp .mine { grid-column: 2; text-align: right; font-size: 13px; }
.exp.payment .title { color: var(--muted); font-weight: 500; }

/* balances */
.bal { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.bal:first-of-type { border-top: none; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.settle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.settle:first-of-type { border-top: none; }

/* forms and sheets */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 16px 28px; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
label.f { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; }
input.i, select.i { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
input.i:focus, select.i:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.amount-wrap { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.amount-wrap input { font-size: 22px; font-weight: 700; text-align: right; }
.amount-wrap span { font-weight: 600; color: var(--muted); }
.seg { display: flex; gap: 6px; margin-top: 4px; }
.seg button { flex: 1; padding: 8px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.people { margin-top: 6px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.person:first-child { border-top: none; }
.person label { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.person input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.person input.share { width: 96px; text-align: right; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.person .calc { width: 96px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum { margin-top: 8px; font-size: 13px; text-align: right; }
.sum.bad { color: var(--neg); font-weight: 600; }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }
.err { color: var(--neg); font-size: 14px; margin-top: 10px; min-height: 1.2em; }

/* login */
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
.login p { margin: 0 0 20px; color: var(--muted); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.names button { padding: 16px 8px; border: 1px solid var(--line); background: var(--card); border-radius: 12px; font-weight: 600; font-size: 16px; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; z-index: 20; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.links { display: flex; gap: 14px; justify-content: center; margin: 20px 0; font-size: 14px; }
.itin { display: block; text-decoration: none; color: inherit; }
.itin .row { padding: 2px 0; }
.itin .go { color: var(--accent); font-weight: 600; }
