:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d1b16;
  --muted: #6d685c;
  --line: #e3dfd4;
  --accent: #0e7c6b;
  --accent-ink: #ffffff;
  --accent-soft: #d9efe9;
  --pos: #11804a;
  --neg: #c2410c;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(30, 25, 10, .06), 0 4px 16px rgba(30, 25, 10, .06);
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1d18;
    --surface-2: #29271f;
    --text: #f1eee6;
    --muted: #a39d8e;
    --line: #34322a;
    --accent: #3cc4a9;
    --accent-ink: #062a23;
    --accent-soft: #173a33;
    --pos: #4ade80;
    --neg: #fb923c;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 24px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.sheet h2 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 17px; margin: 0; }
[hidden] { display: none !important; }

main, .top { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: calc(env(safe-area-inset-top) + 14px); display: flex; flex-direction: column; gap: 6px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.me-chip { align-self: flex-start; background: none; border: 0; padding: 0; color: var(--muted); font-size: 14px; }
.me-chip b { color: var(--text); }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-shrink: 0; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); min-width: 36px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.big button { padding: 8px 12px; font-size: 16px; }

/* Summary */
.summary { margin-top: 14px; background: var(--accent); color: var(--accent-ink); border-radius: var(--radius); padding: 16px 18px; }
.summary .big { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.summary .label { font-size: 14px; opacity: .85; }
.summary .meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 13px; opacity: .9; flex-wrap: wrap; }
.summary button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; text-underline-offset: 2px; font-size: 13px; }

/* Cards & lists */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.pad { padding: 14px 16px; }
.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 4px 6px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; background: none; width: 100%; text-align: left; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
button.item:active { background: var(--surface-2); }
.item .ico { width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.item .mid { flex: 1; min-width: 0; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { text-align: right; flex-shrink: 0; }
.item .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 40px; }

/* Avatars */
.av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; }

/* Balances */
.bal-bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; position: relative; overflow: hidden; }
.bal-bar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.settle-amt { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Buttons */
.btn { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; padding: 11px 16px; border-radius: 11px; }
.btn.small { padding: 7px 12px; font-size: 15px; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: none; color: var(--danger); border: 1px solid var(--line); }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); font-weight: 600; font-size: 14px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 12px; }
.row.gap { gap: 10px; flex-wrap: wrap; }
.row.gap.tiny { gap: 16px; margin: -2px 0 6px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.hint.center { text-align: center; min-height: 18px; }
.error { color: var(--danger); font-size: 14px; min-height: 0; margin: 8px 0 0; }
.error:empty { display: none; }

/* Rates */
.rate-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
input[type="number"], input.text, input[type="date"] {
  background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr auto 1fr 1fr; align-items: center;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 0; }
.tabs button span { font-size: 20px; }
.tabs button[aria-current="page"] { color: var(--accent); }
.tabs .add {
  width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--accent-ink);
  font-size: 32px; font-weight: 400; line-height: 1; margin: 0 14px; transform: translateY(-14px);
  box-shadow: 0 6px 18px rgba(14, 124, 107, .35); justify-content: center;
}

/* Sheets (dialogs) */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 94dvh;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-body { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 6px; }

.amount-row { display: flex; align-items: center; gap: 10px; }
input.amount { font-size: 32px; font-weight: 700; padding: 8px 12px; text-align: right; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row label { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.split-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
.split-row .share { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.split-row input[type="number"] { width: 110px; padding: 7px 10px; text-align: right; }

.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.who-grid button { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 20px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); display: flex; gap: 12px; align-items: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; }
@media (prefers-color-scheme: dark) { .toast button { color: #0e7c6b; } }
