/* spenber: clean, list-first, one accent. Mobile first (375–430 px). */

:root {
  --bg: #ffffff;
  --bg-sub: #f5f6f8;        /* page wells, pressed rows, inputs */
  --surface: #ffffff;       /* sheets and dialogs */
  --fg: #1b1d21;
  --fg-2: #5e636b;          /* secondary text */
  --fg-3: #959aa3;          /* hints, chevrons */
  --line: #e7e8eb;          /* hairlines */
  --line-strong: #d6d8dc;   /* input borders */
  --accent: #2f6be4;
  --accent-press: #2559c4;
  --accent-tint: #ebf1fd;
  --on-accent: #ffffff;
  --pos: #12935a;           /* owed to you */
  --neg: #e0531f;           /* you owe */
  --danger: #d4342a;
  --danger-tint: #fdeeec;
  --warn: #9a6700;
  --warn-tint: #fdf4dc;
  --scrim: rgba(15, 17, 21, 0.38);
  --shadow: 0 10px 40px rgba(15, 17, 21, 0.16);

  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", Roboto, sans-serif;
  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 26px;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --gutter: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;
  --bar-h: 56px;
  --tabs-h: 56px;
  --max: 560px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --bg-sub: #1c1d21;
    --surface: #1c1d21;
    --fg: #ecedf0;
    --fg-2: #a4a8b0;
    --fg-3: #6f737b;
    --line: #2a2c31;
    --line-strong: #3a3d43;
    --accent: #6a9bff;
    --accent-press: #8bb1ff;
    --accent-tint: rgba(106, 155, 255, 0.14);
    --on-accent: #0d1424;
    --pos: #3ccf8a;
    --neg: #ff7b52;
    --danger: #ff6b5f;
    --danger-tint: rgba(255, 107, 95, 0.13);
    --warn: #f0c35a;
    --warn-tint: rgba(240, 195, 90, 0.12);
    --scrim: rgba(0, 0, 0, 0.55);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}
html.no-scroll { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--fs-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.icon { flex: none; display: block; }
.num, .amount { font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-2); font-size: var(--fs-sm); }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.noscript { padding: var(--s4); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app {
  max-width: var(--max);
  margin: 0 auto;
  padding-bottom: calc(var(--s6) + env(safe-area-inset-bottom));
}
body.has-tabs #app { padding-bottom: calc(var(--tabs-h) + var(--s6) + env(safe-area-inset-bottom)); }

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--s1);
  min-height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--s2) 0 var(--gutter);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.bar.has-back { padding-left: var(--s1); }
.bar-titles { flex: 1; min-width: 0; }
.bar-title {
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar.has-back .bar-title { font-size: var(--fs-lg); font-weight: 600; }
.bar-sub {
  font-size: var(--fs-xs);
  color: var(--fg-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-actions { display: flex; align-items: center; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
}
.icon-btn:active { background: var(--bg-sub); }
.bar-back { color: var(--fg); }

/* ---------- banners ---------- */

.banners:empty { display: none; }
.banner {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--s3) var(--gutter);
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: var(--fs-sm);
  line-height: 1.4;
}
.banner-danger { background: var(--danger-tint); color: var(--danger); }
.banner-warn { background: var(--warn-tint); color: var(--warn); }
.banner-text { flex: 1; font-weight: 500; }
.banner-action { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; white-space: nowrap; }
button.banner:active { filter: brightness(0.97); }

/* ---------- sections and lists ---------- */

.page-body { padding-top: var(--s2); }

.section { margin-top: var(--s5); }
.section:first-child { margin-top: var(--s3); }
.section-title {
  padding: 0 var(--gutter) var(--s2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-2);
}
.section-foot {
  padding: var(--s2) var(--gutter) 0;
  font-size: var(--fs-sm);
  color: var(--fg-2);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.list > li { position: relative; }
.page-body > .list:first-child { border-top: 0; }
/* Hairline between rows, inset to the text like a native list. */
.list > li + li::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--gutter);
  right: 0;
  border-top: 1px solid var(--line);
  pointer-events: none;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 52px;
  padding: var(--s3) var(--gutter);
  border: 0;
  background: transparent;
  color: var(--fg);
  text-align: left;
}
.row-tap { cursor: pointer; }
.row-tap:active { background: var(--bg-sub); }
.row-lead { flex: none; display: flex; align-items: center; justify-content: center; min-width: 24px; color: var(--fg-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title {
  font-size: var(--fs-md);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub { font-size: var(--fs-sm); color: var(--fg-2); line-height: 1.35; }
.row-right { flex: none; display: flex; align-items: center; gap: var(--s2); color: var(--fg-2); text-align: right; max-width: 60%; }
.row-chev { flex: none; color: var(--fg-3); margin-right: -4px; }
.row .value { font-size: var(--fs-md); color: var(--fg-2); display: inline-flex; align-items: center; gap: var(--s2); }
.row.tone-accent, .row.tone-accent .row-lead { color: var(--accent); }
.row.tone-danger, .row.tone-danger .row-lead { color: var(--danger); }
.row.is-selected .row-title { font-weight: 600; }
.row.is-selected .avatar { background: var(--accent-tint); color: var(--accent); }
.check { color: var(--accent); }

/* ---------- avatar, chips, amounts ---------- */

.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-sub);
  color: var(--fg-2);
  font-size: var(--fs-md);
  font-weight: 600;
}
.avatar-square { border-radius: 12px; background: var(--accent-tint); color: var(--accent); font-size: var(--fs-lg); }

.chips { display: inline-flex; flex-wrap: wrap; gap: var(--s1); margin-left: var(--s2); vertical-align: 1px; }
.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  background: var(--bg-sub);
  color: var(--fg-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
.chip-danger { background: var(--danger-tint); color: var(--danger); }
.chip-accent { background: var(--accent-tint); color: var(--accent); }

.amount { font-weight: 600; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--fg-2); }

/* ledger list: my net on the right */
.ledger-row { min-height: 72px; }
.ledger-row .row-title { font-weight: 600; }
.net { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.net-label { font-size: var(--fs-xs); font-weight: 500; }
.net .amount { font-size: var(--fs-md); }
.net-none { font-size: var(--fs-sm); color: var(--fg-3); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--fs-md);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: background-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:not(:disabled):active { background: var(--accent-press); }
.btn-secondary { background: var(--accent-tint); color: var(--accent); }
.btn-secondary:not(:disabled):active { filter: brightness(0.96); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-plain { background: transparent; color: var(--fg-2); }
.btn-plain:active { background: var(--bg-sub); }
.btn-small { width: auto; min-height: var(--tap); padding: 0 var(--s4); font-size: var(--fs-sm); border-radius: 10px; }

.page-actions { padding: var(--s5) var(--gutter) 0; display: flex; flex-direction: column; gap: var(--s3); }

/* ---------- forms ---------- */

.form { display: flex; flex-direction: column; gap: var(--s4); padding: 0 var(--gutter); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 500; color: var(--fg-2); }
.field-hint { font-size: var(--fs-sm); color: var(--fg-2); }
.field-error { font-size: var(--fs-sm); color: var(--danger); }
.field-error:empty { display: none; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 11px var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px; /* 16 px stops iOS from zooming on focus */
  line-height: 1.4;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--fg-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.input:disabled { opacity: 0.6; }
.field.has-error .input { border-color: var(--danger); }
.input-area { min-height: 96px; resize: none; font-size: var(--fs-sm); word-break: break-all; }
input[type="date"].input { min-width: 0; }

.lead-text { padding: var(--s3) var(--gutter) 0; color: var(--fg-2); font-size: var(--fs-sm); }

.or {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin: var(--s5) var(--gutter) 0;
  color: var(--fg-3);
  font-size: var(--fs-sm);
}
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* join: the trip being joined */
.join-trip { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--gutter) 0; }
.join-trip .avatar { width: 52px; height: 52px; border-radius: 14px; font-size: var(--fs-xl); }
.join-trip-name { font-size: var(--fs-xl); font-weight: 650; }
.join-trip-sub { font-size: var(--fs-sm); color: var(--fg-2); }

/* ---------- empty state ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  padding: 72px var(--s5) 0;
  text-align: center;
}
.empty-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--accent-tint);
  color: var(--accent);
  margin-bottom: var(--s2);
}
.empty-title { font-size: var(--fs-xl); font-weight: 650; }
.empty-text { color: var(--fg-2); font-size: var(--fs-md); max-width: 300px; }
.empty .btn { margin-top: var(--s4); max-width: 320px; }

.version { padding: var(--s6) var(--gutter) 0; text-align: center; font-size: var(--fs-xs); color: var(--fg-3); }

/* ---------- failures ---------- */

.failures { display: flex; flex-direction: column; gap: var(--s3); padding: 0 var(--gutter); }
.failure { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s3) var(--s4); }
.failure-head { display: flex; align-items: center; gap: var(--s2); }
.failure-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.failure-time { font-size: var(--fs-xs); color: var(--fg-3); white-space: nowrap; }
.failure-reason { margin-top: var(--s2); font-size: var(--fs-sm); color: var(--danger); }
.failure-line { margin-top: var(--s1); font-size: var(--fs-sm); color: var(--fg); }
.failure-k { display: inline-block; min-width: 5.5em; color: var(--fg-2); }
.failure-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); margin-top: var(--s3); }

/* ---------- badges and notices ---------- */

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg-sub);
  color: var(--fg-2);
}
.badge-accent { background: var(--accent-tint); color: var(--accent); }
.badge-text { font-size: var(--fs-md); font-weight: 600; }

.notice {
  display: flex;
  gap: var(--s3);
  margin: var(--s3) var(--gutter) 0;
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  line-height: 1.45;
}
.notice-warn { background: var(--warn-tint); color: var(--warn); }
.notice-danger { background: var(--danger-tint); color: var(--danger); }
.notice-icon { flex: none; padding-top: 1px; }
.notice-text { flex: 1; min-width: 0; font-weight: 500; }
.notice-sub { margin-top: 2px; font-weight: 400; opacity: 0.9; }
.form > .notice { margin: 0; }

.row-wrap .row-title { white-space: normal; overflow: visible; }
.row-wrap .row-sub { white-space: pre-wrap; word-break: break-word; }
.muted-row .row-title { color: var(--fg-3); }

.btn-danger-soft { background: var(--danger-tint); color: var(--danger); }
.btn-danger-soft:active { filter: brightness(0.96); }

@keyframes spin { to { transform: rotate(360deg); } }
.spin .icon { animation: spin 0.9s linear infinite; }

/* ---------- expense list ---------- */

.filters {
  display: flex;
  gap: var(--s2);
  padding: var(--s2) var(--gutter) var(--s1);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: var(--tap);
  padding: 2px var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--bg);
  color: var(--fg);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.15;
}
.pill small { font-size: 11px; font-weight: 500; color: var(--fg-3); }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pill[aria-pressed="true"] small { color: var(--on-accent); opacity: 0.8; }

.filter-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  margin: var(--s2) var(--gutter) 0;
  padding: 0 0 0 var(--s3);
  border-radius: 10px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.filter-note .btn-plain { color: var(--accent); gap: 4px; }

.day { margin-top: var(--s4); }
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 var(--gutter) var(--s2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-2);
}
.day-total { font-weight: 500; color: var(--fg-3); font-variant-numeric: tabular-nums; }

.xrow { min-height: 64px; }
.xsub { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--s1); }
.xsub .chips { margin-left: 2px; }
.xinvalid { flex-basis: 100%; color: var(--danger); font-size: var(--fs-xs); }
.xamt { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.xamt .amount { color: var(--fg); font-size: var(--fs-md); }
.xamt-sub { font-size: var(--fs-xs); color: var(--fg-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.xrow.is-invalid .xamt .amount { color: var(--fg-3); text-decoration: line-through; }

.empty-small { padding-top: var(--s6); }
.page-list .page-body { padding-bottom: 80px; }

.fab {
  position: fixed;
  right: max(var(--gutter), calc((100vw - var(--max)) / 2 + var(--gutter)));
  bottom: calc(var(--tabs-h) + var(--s4) + env(safe-area-inset-bottom));
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 6px 18px rgba(47, 107, 228, 0.35);
}
.fab:active { background: var(--accent-press); }

/* ---------- expense and transfer forms ---------- */

.form-page { padding-top: var(--s3); gap: var(--s5); }
.field-amount .amount-block { display: flex; flex-direction: column; gap: var(--s3); }
.field-amount .rate-stale { margin: 0; color: var(--warn); }
.field-amount .rate-stale[hidden] { display: none; }
.amount-line {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  padding: 0 2px;
  border-bottom: 2px solid var(--line-strong);
}
.amount-line:focus-within { border-color: var(--accent); }
.field-amount.has-error .amount-line { border-color: var(--danger); }
.amount-sym { font-size: var(--fs-xl); font-weight: 600; color: var(--fg-2); }
.amount-input {
  flex: 1;
  min-width: 0;
  height: 60px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 34px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  outline: none;
}
.amount-input::placeholder { color: var(--fg-3); }

.seg { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--bg-sub); }
.seg button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--fg-2);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgba(15, 17, 21, 0.14); }

.choices { display: flex; flex-wrap: wrap; gap: var(--s2); }
.choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--bg);
  color: var(--fg);
  font-size: var(--fs-md);
  font-weight: 500;
}
.choices-cat .choice { padding-left: var(--s2); }
.choice .badge { width: 26px; height: 26px; border-radius: 8px; background: transparent; color: inherit; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.choice:disabled { opacity: 0.35; cursor: default; }
.choice-static { cursor: default; }
.field.has-error .choices .choice:not([aria-pressed="true"]):not(:disabled) { border-color: var(--danger); }

.split { display: flex; flex-direction: column; gap: var(--s2); }
.split-body { display: flex; flex-direction: column; }
.split-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 56px;
  padding: var(--s1) 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  text-align: left;
}
.split-row .avatar { width: 34px; height: 34px; font-size: var(--fs-sm); }
.split-tap:active { background: var(--bg-sub); }
.split-row.is-off .split-name, .split-row.is-off .split-amt { color: var(--fg-3); }
.split-name { flex: 1; min-width: 0; font-size: var(--fs-md); }
.split-amt { color: var(--fg-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.split-sym { color: var(--fg-3); }
.split-input { width: 116px; min-height: var(--tap); padding: 8px var(--s3); text-align: right; font-variant-numeric: tabular-nums; }
.tick {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  color: transparent;
}
.tick.on { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.split-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  padding-top: var(--s1);
  font-size: var(--fs-sm);
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}
.split-foot.is-ok .split-left { color: var(--pos); font-weight: 600; }
.split-foot.is-bad .split-left { color: var(--neg); font-weight: 600; }

.input-note { min-height: 72px; resize: none; }

.form-foot {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 0 calc(-1 * var(--gutter));
  padding: var(--s3) var(--gutter) calc(var(--s3) + env(safe-area-inset-bottom));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.form-actions { padding-top: var(--s2); }
#app:has(.page-form) { padding-bottom: 0; }

/* ---------- detail ---------- */

.hero { display: flex; flex-direction: column; align-items: center; gap: var(--s1); padding: var(--s5) var(--gutter) var(--s2); text-align: center; }
.hero .badge { width: 56px; height: 56px; border-radius: 16px; margin-bottom: var(--s2); }
.hero-title { font-size: var(--fs-xl); font-weight: 650; line-height: 1.3; word-break: break-word; }
.hero-amount { font-size: 34px; font-weight: 700; line-height: 1.2; }
.hero-sub { font-size: var(--fs-sm); color: var(--fg-2); font-variant-numeric: tabular-nums; }
.hero-chips { display: flex; gap: var(--s1); margin-top: var(--s1); }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); padding: var(--s4) var(--gutter) 0; }
.hist-row .row-title { font-size: var(--fs-sm); line-height: 1.45; }
.hist-pending .row-title { color: var(--fg-2); font-size: var(--fs-sm); }

/* ---------- settlement ---------- */

.net-row { min-height: 60px; }
.pair { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.pair .icon { color: var(--fg-3); }
.suggest-row { min-height: 64px; }
.suggest-right { display: flex; align-items: center; gap: var(--s3); }
.suggest-right .amount { color: var(--fg); }
.suggest-row .btn-small { padding: 0 var(--s3); }
.page-actions-row { flex-direction: row; }
.page-actions-row .btn { flex: 1; }

/* ---------- analysis ---------- */

.range { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3) var(--gutter) 0; }
.filters-flush { margin: 0 calc(-1 * var(--gutter)); padding-top: 0; }

.stat { padding: var(--s5) var(--gutter) var(--s1); }
.stat-label { font-size: var(--fs-sm); font-weight: 600; color: var(--fg-2); }
.stat-value { display: block; margin-top: 2px; font-size: 34px; font-weight: 700; line-height: 1.2; }
.stat-sub { margin-top: 2px; font-size: var(--fs-sm); color: var(--fg-2); font-variant-numeric: tabular-nums; }

.cat-row { min-height: 64px; }
.hbar { display: block; height: 6px; margin-top: 6px; border-radius: 3px; background: var(--bg-sub); overflow: hidden; }
.hbar-fill { display: block; height: 100%; min-width: 3px; border-radius: 3px; background: var(--accent); }
.person-amt { color: var(--fg); }

.vbars {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 0 var(--s3);
  overflow-x: auto;
  scrollbar-width: none;
}
.vbars::-webkit-scrollbar { display: none; }
.vbar {
  flex: 1 0 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: var(--tap);
  padding: var(--s1) 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-2);
}
.vbar:active { background: var(--bg-sub); }
.vbar-value { height: 14px; font-size: 10px; line-height: 14px; color: var(--fg-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.vbar-track { position: relative; display: block; width: 22px; height: 140px; border-radius: 6px; background: var(--bg-sub); }
.vbar-fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 6px; background: var(--accent); }
.vbar-label { font-size: var(--fs-xs); font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
.vbar-sub { margin-top: -4px; font-size: 10px; color: var(--fg-3); }

/* ---------- tabs ---------- */

#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
#tabs a {
  flex: 1;
  max-width: calc(var(--max) / 4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tabs-h);
  color: var(--fg-3);
  font-size: 11px;
  font-weight: 500;
}
#tabs a[aria-current="page"] { color: var(--accent); }
#tabs a:active { opacity: 0.7; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s5) + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 10px var(--s4);
  border-radius: 22px;
  background: #24262b;
  color: #f4f5f7;
  font-size: var(--fs-sm);
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}
body.has-tabs .toast { bottom: calc(var(--tabs-h) + var(--s3) + env(safe-area-inset-bottom)); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-color-scheme: dark) {
  .toast { background: #eceef1; color: #17181b; }
}

/* ---------- sheet and dialog ---------- */

.sheet-backdrop, .dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 0.2s;
}
.sheet-backdrop.open, .dialog-backdrop.open { opacity: 1; }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: var(--max);
  max-height: 88vh;
  max-height: 88dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-handle { width: 36px; height: 5px; margin: var(--s2) auto 0; border-radius: 3px; background: var(--line-strong); flex: none; }
.sheet-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s2) var(--s1) var(--gutter); flex: none; }
.sheet-title { flex: 1; font-size: var(--fs-lg); font-weight: 600; }
.sheet-head .icon-btn { color: var(--fg-2); }
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--s2) 0 calc(var(--s5) + env(safe-area-inset-bottom));
}
.sheet-body > .form { padding-top: var(--s2); }
.sheet-body > div > .list { border-top: 1px solid var(--line); }

.dialog-backdrop { z-index: 50; display: flex; align-items: center; justify-content: center; padding: var(--s5); }
.dialog {
  width: 100%;
  max-width: 340px;
  padding: var(--s5) var(--s5) var(--s4);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: scale(0.96);
  transition: transform 0.2s;
}
.dialog-backdrop.open .dialog { transform: none; }
.dialog-title { font-size: var(--fs-lg); font-weight: 650; margin-bottom: var(--s2); }
.dialog-text { color: var(--fg-2); font-size: var(--fs-md); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-top: var(--s5); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
