/* Expense splitter. Two layouts share one markup:
   journey   a trip ledger on the left, a dark "settle up" ticket pinned on the right
   household result first, then a ruled household ledger
   System fonts only; no external request. */

:root {
  --radius: 10px;
  --gap: 1rem;
  font-size: 100%;
}
body[data-layout="journey"] {
  --bg: #e6eef0;
  --surface: #ffffff;
  --ink: #0f2430;
  --muted: #3f5a65;
  --line: #a3b9c2;
  --accent: #0b5f6b;
  --accent-ink: #ffffff;
  --accent-hover: #073f47;
  --owed: #145c33;
  --owes: #9c3416;
  --dark: #10303b;
  --on-dark: #eaf5f7;
  --on-dark-muted: #b9d4da;
  --focus: #0b5f6b;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --display: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}
body[data-layout="household"] {
  --bg: #f1f4f8;
  --surface: #ffffff;
  --ink: #1a2233;
  --muted: #465064;
  --line: #bfc7d4;
  --accent: #26305c;
  --accent-ink: #ffffff;
  --accent-hover: #151c3d;
  --mark: #f0b429;
  --owed: #0b6150;
  --owes: #8a2650;
  --dark: #26305c;
  --on-dark: #ffffff;
  --on-dark-muted: #d0d6ee;
  --focus: #26305c;
  --font: system-ui, "Segoe UI", "Helvetica Neue", sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--font);
  overflow-wrap: anywhere;
}
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.hint { color: var(--muted); font-size: .9rem; margin-bottom: .5rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: .5rem; top: -4rem; background: var(--accent); color: var(--accent-ink); padding: .6rem 1rem; border-radius: var(--radius); z-index: 10; }
.skip:focus { top: .5rem; }

/* ---- masthead ---- */
.masthead { max-width: 72rem; margin: 0 auto; padding: 2rem 1rem 1rem; }
.masthead h1 { font-size: clamp(1.9rem, 6vw, 3.4rem); max-width: 18ch; }
.lede { font-size: 1.1rem; max-width: 60ch; }
.assume { color: var(--muted); max-width: 66ch; font-size: .95rem; }
.notice { display: inline-block; border-left: 4px solid var(--accent); background: var(--surface); padding: .5rem .75rem; max-width: 66ch; font-size: .95rem; }
.nojs { max-width: 40rem; margin: 1rem auto 3rem; padding: 1rem; background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius); }

#app, .foot { max-width: 72rem; margin: 0 auto; padding: 0 1rem; }
#app[hidden] { display: none; }
.foot { padding-bottom: 3rem; color: var(--muted); font-size: .9rem; }

/* ---- shared parts ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; min-width: 0; }
.panel > h2 { font-size: 1.5rem; }
.banner { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center; border: 2px dashed var(--accent); border-radius: var(--radius); background: var(--surface); padding: .8rem 1rem; margin-bottom: var(--gap); }
.banner h2 { font-size: 1.1rem; margin: 0; }
.banner p { margin: 0; flex: 1 1 16rem; }
.status { position: sticky; top: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 0 -1rem .5rem; padding: .35rem 1rem; background: var(--dark); color: var(--on-dark); font-weight: 600; }
.status:has(#status-text:empty) { height: 0; margin: 0; padding: 0; overflow: hidden; }
.status button { background: var(--surface); }
.status button:hover { background: var(--accent); }
html { scroll-padding-top: 4.5rem; }
.board { display: grid; gap: var(--gap); }
.col { display: contents; }
.e-foot { display: flex; flex-wrap: wrap; gap: 0 .5rem; justify-content: space-between; align-items: flex-start; }
.e-foot details { flex: 1 1 14rem; min-width: 0; }

button, .file-button {
  font: inherit; font-weight: 600; min-height: 2.75rem; padding: .5rem 1rem; border-radius: 8px; cursor: pointer;
  border: 2px solid var(--accent); background: var(--surface); color: var(--accent);
}
button:hover, .file-button:hover { background: var(--accent); color: var(--accent-ink); }
button:disabled { border-color: var(--line); color: var(--muted); cursor: not-allowed; background: var(--surface); }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
button.quiet { border-color: transparent; background: transparent; text-decoration: underline; padding: .25rem .6rem; }
button.quiet:hover { background: var(--accent); color: var(--accent-ink); }
.file-button { display: inline-flex; align-items: center; }
#import-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#import-file:focus-visible + .file-button, .file-button:has(+ #import-file:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row-actions { display: flex; flex-wrap: wrap; gap: .25rem; }

label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type="text"], input:not([type]), input[inputmode], select, textarea {
  font: inherit; width: 100%; min-height: 2.75rem; padding: .5rem .65rem; color: var(--ink); background: #fff;
  border: 2px solid #6b7b86; border-radius: 8px;
}
textarea { resize: vertical; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--owes); }
.field { margin-bottom: .75rem; min-width: 0; }
.row { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.field-error { color: var(--owes); font-weight: 600; margin: .25rem 0 0; }
.field-error:empty { display: none; }
.inline-form { display: grid; gap: .5rem; grid-template-columns: 1fr auto; align-items: end; margin-top: .75rem; }
.inline-form .field { margin: 0; }
.inline-form .field-error { grid-column: 1 / -1; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .75rem; margin: 0 0 .75rem; min-width: 0; }
legend { font-weight: 700; padding: 0 .35rem; }
.choice { display: flex; gap: .5rem; align-items: center; font-weight: 500; min-height: 2.75rem; margin: 0; }
.choice input { width: 1.25rem; height: 1.25rem; flex: none; accent-color: var(--accent); }
.beneficiaries { margin-top: .5rem; display: grid; gap: .1rem; }
.ben { display: flex; gap: .75rem; align-items: center; justify-content: space-between; }
.ben .weight { width: 6rem; }
.ben .weight[hidden] { display: none; }
.confirm { border: 2px solid var(--owes); border-radius: var(--radius); padding: .75rem; margin-top: .75rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.confirm[hidden] { display: none; }
.confirm p { flex: 1 1 100%; margin: 0; }
.empty { color: var(--muted); font-style: italic; }
.empty[hidden] { display: none; }

.people { list-style: none; margin: 0 0 .5rem; padding: 0; display: grid; gap: .25rem; }
.person { display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: .15rem 0; }
.person .name { font-weight: 700; }
.person.editing { display: grid; grid-template-columns: 1fr auto auto; }
.person.editing .field-error { grid-column: 1 / -1; }

.expense-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.expense { border: 1px solid var(--line); border-radius: 8px; padding: .75rem; }
.expense.is-editing { border: 2px solid var(--accent); }
.e-head { display: flex; flex-wrap: wrap; gap: .25rem 1rem; justify-content: space-between; align-items: baseline; }
.e-title { font-size: 1.05rem; }
.e-amt { font-variant-numeric: tabular-nums; font-weight: 800; }
.e-meta { color: var(--muted); margin: .15rem 0 .35rem; }
details summary { cursor: pointer; font-weight: 600; min-height: 2.75rem; display: flex; align-items: center; }
.alloc { list-style: none; margin: 0 0 .5rem; padding: 0; font-variant-numeric: tabular-nums; }
.alloc li { display: flex; flex-wrap: wrap; gap: 0 .5rem; padding: .15rem 0; border-bottom: 1px dotted var(--line); }
.alloc small { color: var(--muted); }
.list-title { margin-top: 1.25rem; }

.summary { font-weight: 600; }
.balances, .transfers { list-style: none; margin: 0 0 1rem; padding: 0; }
.bal { display: grid; grid-template-columns: 1fr auto; gap: 0 .75rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.bal .name { font-weight: 700; }
.bal .state { grid-column: 1; color: var(--muted); }
.bal .amt { grid-row: 1 / span 2; grid-column: 2; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.bal[data-state="owed"] .amt { color: var(--owed); }
.bal[data-state="owes"] .amt { color: var(--owes); }
.bar { grid-column: 1 / -1; height: .45rem; background: #dbe4e8; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: var(--w, 0%); background: currentColor; }
.bal[data-state="owed"] .bar { color: var(--owed); }
.bal[data-state="owes"] .bar { color: var(--owes); }
.bal[data-state="settled"] .bar { display: none; }
.transfers { counter-reset: t; }
.transfers li { padding: .6rem 0; border-bottom: 1px dashed var(--line); font-weight: 700; font-variant-numeric: tabular-nums; }
.file-preview { margin: .5rem 0 1rem; }
pre { margin: 0; padding: .75rem; background: #eef2f5; border: 1px solid var(--line); border-radius: 8px; max-height: 18rem; overflow: auto; font: .85rem/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- journey: ledger left, dark ticket right ---- */
body[data-layout="journey"] .masthead h1 { letter-spacing: -.02em; font-weight: 800; max-width: 26ch; }
body[data-layout="journey"] .panel { border-radius: 14px; }
body[data-layout="journey"] #result { background: var(--dark); color: var(--on-dark); border-color: var(--dark); border-radius: 14px 14px 4px 4px; --focus: #ffffff; position: relative; }
body[data-layout="journey"] #result::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 10px; background: radial-gradient(circle at 10px 0, var(--bg) 6px, transparent 6.5px) 0 0 / 20px 10px repeat-x; }
body[data-layout="journey"] #result .hint, body[data-layout="journey"] #result .bal .state, body[data-layout="journey"] #result .empty { color: var(--on-dark-muted); }
body[data-layout="journey"] #result .bal, body[data-layout="journey"] #result .transfers li { border-color: #3f6573; }
body[data-layout="journey"] #result .bal[data-state="owed"] .amt, body[data-layout="journey"] #result .bal[data-state="owed"] .bar { color: #7fe0a4; }
body[data-layout="journey"] #result .bal[data-state="owes"] .amt, body[data-layout="journey"] #result .bal[data-state="owes"] .bar { color: #ffb199; }
body[data-layout="journey"] #result .bar { background: #24505f; }
body[data-layout="journey"] #result h3 { margin-top: .5rem; }
body[data-layout="journey"] #result .transfers li::before { content: "→ "; color: var(--on-dark-muted); }
body[data-layout="journey"] .board { display: flex; flex-direction: column; }
body[data-layout="journey"] #people { order: 1; }
body[data-layout="journey"] #result { order: 2; }
body[data-layout="journey"] #expenses { order: 3; }
body[data-layout="journey"] #share { order: 4; }
body[data-layout="journey"] #data { order: 5; }
@media (min-width: 62rem) {
  body[data-layout="journey"] .board { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
  body[data-layout="journey"] .col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
}

/* ---- household: statement first, then a ruled ledger ---- */
body[data-layout="household"] .masthead { border-bottom: 6px solid var(--mark); background: var(--dark); color: var(--on-dark); max-width: none; padding-left: max(1rem, calc((100% - 70rem) / 2)); padding-right: max(1rem, calc((100% - 70rem) / 2)); }
body[data-layout="household"] .masthead .assume { color: var(--on-dark-muted); }
body[data-layout="household"] .masthead .notice { color: var(--ink); border-left-color: var(--mark); }
body[data-layout="household"] .masthead h1 { font-weight: 700; font-style: italic; }
body[data-layout="household"] #app { padding-top: 1.25rem; }
body[data-layout="household"] .board { grid-template-columns: minmax(0, 1fr); }
body[data-layout="household"] #result { order: 1; border: 2px solid var(--ink); border-radius: 2px; }
body[data-layout="household"] #people { order: 2; }
body[data-layout="household"] #expenses { order: 3; }
body[data-layout="household"] #share { order: 4; }
body[data-layout="household"] #data { order: 5; }
body[data-layout="household"] .board { display: flex; flex-direction: column; }
body[data-layout="household"] .panel { border-radius: 2px; }
body[data-layout="household"] .panel > h2 { border-bottom: 3px double var(--ink); padding-bottom: .25rem; }
body[data-layout="household"] button.primary { background: var(--mark); border-color: var(--ink); color: var(--ink); }
body[data-layout="household"] button.primary:hover { background: #ffd26e; border-color: var(--ink); color: var(--ink); }
body[data-layout="household"] .transfers li { font-family: var(--display); font-size: 1.35rem; font-weight: 700; }
body[data-layout="household"] .bal { grid-template-columns: 1fr auto; }
body[data-layout="household"] .bar { display: none; }
body[data-layout="household"] .people { display: flex; flex-wrap: wrap; gap: .5rem; }
body[data-layout="household"] .person { border: 1px solid var(--ink); border-radius: 99px; padding: .15rem .35rem .15rem .9rem; }
body[data-layout="household"] .expense-list { gap: 0; border-top: 2px solid var(--ink); }
body[data-layout="household"] .expense { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: .75rem .25rem; }
body[data-layout="household"] .expense.is-editing { background: #fff6d9; outline: 2px solid var(--ink); }
body[data-layout="household"] .e-title { font-family: var(--display); font-size: 1.15rem; }
body[data-layout="household"] .e-amt { font-family: var(--display); font-size: 1.15rem; }
@media (min-width: 62rem) {
  body[data-layout="household"] .balances { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0 2rem; }
  body[data-layout="household"] #share, body[data-layout="household"] #data { display: block; }
}

@media (max-width: 30rem) {
  .masthead { padding-top: 1rem; padding-bottom: .5rem; }
  .masthead h1 { font-size: 1.75rem; }
  .lede { font-size: 1rem; }
  .assume, .notice { font-size: .85rem; }
  .inline-form { grid-template-columns: 1fr; }
  .ben { flex-wrap: wrap; }
  .panel { padding: .85rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar i { transition: width .25s ease; }
}
@media print {
  .skip, .actions, .inline-form, #expense-form { display: none; }
}
