
:root {
  color-scheme: light;
  --canvas: #f3f6f2;
  --surface: #fff;
  --ink: #192d26;
  --muted: #52665e;
  --line: #dce5de;
  --quiet: #eaf1ec;
  --accent: #15563f;
  --page-width: 760px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 16px/1.45 system-ui, sans-serif;
}
main, .app-header {
  width: 100%;
  max-width: var(--page-width);
  margin-inline: auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}
.app-header { display: flex; align-items: center; gap: 14px; }
.brand { color: var(--accent); font-size: 23px; font-weight: 780; letter-spacing: -.8px; }
h1, h2, h3 { line-height: 1.18; }
h1 { margin: 12px 0 20px; font-size: clamp(29px, 6vw, 42px); }
h2 { margin: 0 0 14px; font-size: 21px; }
h3 { margin: 0 0 8px; font-size: 17px; }
p { margin: 8px 0; }
strong, output { font-variant-numeric: tabular-nums; }
small, .hint, .neutral { color: var(--muted); font-size: .875rem; }
a { color: var(--accent); }
button, .button, .action-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 15px; border: 0; border-radius: 12px;
  color: #fff; background: var(--accent); font: inherit; font-weight: 650;
  text-decoration: none; cursor: pointer;
}
button:active, .button:active, .action-link:active { filter: brightness(.91); }
button:disabled { opacity: .6; cursor: default; }
.quiet { color: var(--accent); background: var(--quiet); }
:focus-visible { outline: 2px solid #95733a; outline-offset: 3px; }
label { display: block; min-width: 0; font-weight: 570; margin: 10px 0; }
input, select {
  display: block; width: 100%; min-width: 0; min-height: 44px;
  margin-top: 5px; padding: 7px 10px; border: 1px solid #aeBfb3; border-radius: 11px;
  background: #fff; color: var(--ink); font: inherit; font-size: 16px;
}
input[type=checkbox] { display: inline-block; width: 20px; height: 20px; min-height: 0; margin: 0; vertical-align: middle; accent-color: var(--accent); }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
section {
  margin: 0 0 14px; padding: 15px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.row, summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.row { padding: 8px 0; }
.row:last-child { border-bottom: 0; }
summary { min-height: 44px; padding: 8px 0; cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display:none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.group-shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100vh; height: 100dvh; overflow: hidden; }
.group-shell > .app-header, .tabs { max-width: none; width: 100%; background: var(--surface); }
.group-shell > .app-header { padding-block: calc(5px + env(safe-area-inset-top)) 5px; border-bottom: 1px solid var(--line); }
.group-title { flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; font-weight: 650; }
html:has(.group-shell) { overscroll-behavior-y: none; }
.header-actions { display: flex; flex: none; gap: 6px; }
.header-icon { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 11px; font-size: 25px; text-decoration: none; }
.group-shell > main { min-height: 0; padding-block: 10px; overflow: auto; overscroll-behavior: contain; }
.tabs {
  display: grid; grid-template-columns: repeat(3,minmax(0,1fr)) 48px; align-items: center; gap: 4px;
  padding: 5px max(9px,env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(9px,env(safe-area-inset-left));
  border-top: 1px solid var(--line);
}
.tabs a { display: grid; place-items: center; min-height: 44px; padding: 6px 2px; border-radius: 10px; text-align: center; text-decoration: none; font-weight: 650; font-size: clamp(14px,4vw,16px); }
.tabs a[aria-current] { background: var(--quiet); }
.fab { width: 44px; height: 44px; padding: 0; font-size: 26px; }
.groups-heading, .balance-heading, .settle-amount { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.balance-heading h2 { margin: 0; }
.balance-heading .button { padding-inline: 9px; }
.account-menu { position: relative; }
.account-menu summary { width: 44px; display: grid; place-items: center; font-size: 22px; background: var(--quiet); border: 0; border-radius: 11px; }
.account-menu form { position: absolute; right: 0; top: 50px; display: grid; gap: 10px; min-width: 154px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; z-index: 1; }
.group-list a { min-height: 48px; text-decoration: none; font-weight: 650; }
.create-group > summary { color: var(--accent); font-weight: 650; border: 0; }

.estimate-control { display: flex; justify-content: flex-end; margin-top: 4px; padding: 2px 0 5px; border-bottom: 1px solid var(--line); }
.estimate-control label { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: .9rem; }
.estimate-control select { width: auto; margin: 0; }
.balance-person { display: grid; grid-template-columns: minmax(0,.92fr) minmax(0,1.05fr) minmax(0,1.18fr); min-height: 52px; gap: 6px; }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.native-balances { display: flex; flex-wrap: wrap; gap: 4px; }
.native-balances strong, .estimate-total { padding: 3px 4px; border-radius: 7px; font-size: .86rem; overflow-wrap: break-word; }
.estimate-total { min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: flex-end; gap: 0 3px; text-align: right; font-weight: 650; }
.estimate-number { min-width: 0; }
.estimate-code { white-space: nowrap; }
.estimate-total small { flex: 0 0 100%; }
.estimate-total small { display: block; font-size: .75rem; font-weight: 400; }
.positive { color: #165736; background: #e8f3ec; }
.negative { color: #8d2b24; background: #fbedea; }
.my-tasks, .invite-panel, .settle-missing { padding: 12px; margin: 10px 0; background: var(--quiet); border-radius: 12px; }
.my-tasks a { display: flex; margin-top: 4px; justify-content: flex-start; }
.invite-panel > .invite-create { display: flex; margin-top: 10px; }
.invite-create label { min-width: 105px; }
#notice:not(:empty), #status:not(:empty) { padding: 8px 10px; margin: 0 0 8px; border-radius: 9px; background: var(--quiet); }
#status:empty { display: none; }
.journal-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.journal-heading h2 { margin: 0; }
.journal-download { width: 44px; padding: 0; }
.journal-item { border-bottom: 1px solid var(--line); scroll-margin: 12px; }
.journal-item:last-child { border-bottom: 0; }
.journal-item > summary { min-height: 62px; justify-content: flex-start; border-bottom: 0; }
.journal-item > summary > strong { margin-left: auto; white-space: nowrap; }
.op-icon { display: grid; place-items: center; flex: 0 0 36px; height: 36px; border-radius: 10px; font-size: 20px; background: var(--quiet); }
.op-icon.transfer { background: #e9effb; color: #254880; }
.op-icon.exchange { background: #fcf1dc; color: #704b11; }
.op-text, .settle-amount > strong:first-child { min-width: 0; overflow-wrap: anywhere; }
.op-text > * { display: block; }
.ai-badge { display: inline-block; padding: 0 5px; border-radius: 5px; background: var(--quiet); color: var(--accent); font-weight: 650; }
.event-details { padding: 12px; margin-bottom: 10px; background: var(--canvas); border: 1px solid var(--line); border-radius: 12px; }
.event-meta { color: var(--muted); font-size: .875rem; }
.answer,.inline-controls { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.answer label,.inline-controls label { flex: 1; min-width: 108px; margin: 0; }
.answer { margin-bottom: 10px; }
.difference { font-weight: 650; }
.equal-preview, .revision-history, .pairwise, .settle-breakdown { margin: 8px 0; }
.equal-preview table { width: 100%; margin-bottom: 12px; border-collapse: collapse; }
.equal-preview th,.equal-preview td { text-align: left; padding: 7px 3px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.journal-item > summary::after,.settle-breakdown > summary::after,.pairwise > summary::after,.receipt-details > summary::after,.settle-missing-debts > summary::after {
  content: ""; flex: 0 0 7px; height: 7px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); margin: 0 3px 4px 0;
}
details[open] > summary::after { transform: rotate(225deg); margin-bottom: 0; }
.change { margin-top: 8px; }
.settle-line { margin: 10px 0; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.settle-line > .inline-controls, .settle-snapshot { margin-top: 12px; }
.settle-item { border-top: 1px solid var(--line); padding: 6px 0; }
.settle-item ol { margin: 4px 0; padding-left: 24px; }
.settle-snapshot { display: grid; gap: 12px; }
.settle-snapshot .row strong { white-space: nowrap; }
@media (min-width:540px) { .settle-snapshot { grid-template-columns: repeat(2,minmax(0,1fr)); } }
.settle-missing { background: #fff4dc; }
.settle-missing-rates { display: flex; flex-wrap: wrap; gap: 5px 7px; padding: 0; margin: 0; list-style: none; }
.settle-missing-rates li { padding: 2px 7px; border: 1px solid #e8d2a3; border-radius: 6px; font-size: .88rem; font-weight: 650; }
.settle-missing-debts summary { border: 0; font-size: .9rem; }
.settle-missing + h2 { margin-top: 16px; }
.install-paysplit { padding: 7px 12px; margin: 12px 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.install-paysplit summary { font-weight: 650; }
.install-paysplit p { font-size: .875rem; }
@media(display-mode:standalone) { .install-paysplit { display: none; } }

/* Only the form body and long participant list scroll. */
#entry {
  width: min(100% - 24px, 580px); max-height: calc(100dvh - 24px);
  margin: auto; padding: 0; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px;
}
#entry[open] { display: flex; flex-direction: column; overflow: hidden; }
#entry::backdrop { background: #162e2760; }
.editor-header, .editor-footer { flex: none; padding: 8px 16px; }
.editor-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.editor-header h2 { margin: 0; }
.editor-header button { width: 44px; padding: 0; font-size: 24px; }
.editor-footer { border-top: 1px solid var(--line); }
.editor-footer #save { width: 100%; min-height: 48px; }
#event { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px 16px; overscroll-behavior: contain; }
#event label { margin: 0; font-size: .9rem; }
#event input, #event select { margin-top: 3px; }
#event [name=amount],#event [name=received] { font-size: 20px; font-weight: 650; }
.operation-buttons,.operation-people,.money-fields,.grid,.entry-meta { display: grid; gap: 9px; }
.operation-buttons { grid-template-columns: repeat(3,minmax(0,1fr)); padding: 3px; gap: 3px; border-radius: 13px; background: var(--quiet); }
.operation-buttons button { padding: 5px 3px; background: transparent; border-radius: 10px; }
.operation-buttons button[aria-pressed=true] { color: #fff; background: var(--accent); }
.operation-people,.grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
.operation-people,.money-fields,.entry-meta { margin-top: 10px; }
.operation-people:has(>[hidden]) > label:first-child { grid-column: 1/-1; }
.money-fields { grid-template-columns: minmax(0,1fr) minmax(90px,.5fr); align-items: end; }
#event fieldset[data-for=expense] { position: relative; margin-top: 8px; }
#event fieldset[data-for=expense] > legend { display: flex; align-items: center; min-height: 44px; padding: 0; font-weight: 650; }
.split-tools { position: absolute; top: -44px; right: 0; }
.share-list { max-height: 227px; overflow: auto; overscroll-behavior: contain; border-block: 1px solid var(--line); }
.share { display: grid; grid-template-columns: minmax(0,1fr) minmax(86px,.52fr); align-items: center; gap: 8px; min-height: 44px; border-bottom: 1px solid var(--line); }
.share:last-child { border: 0; }
#event .share label { display: flex; align-items: center; min-height: 44px; gap: 8px; }
.share label span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share label input { flex: none; }
#event .share input[inputmode] { min-height: 38px; margin: 0; }
#receipt-fields > summary {
  position: absolute; top: -44px; right: 92px; gap: 5px;
  min-height: 44px; padding: 5px 2px; border: 0;
  color: var(--accent); font-size: .81rem;
}
#receipt-fields[open] { margin-top: 6px; }
#receipt-currency:empty { display: none; }
#receipt-currency:not(:empty) { font-weight: 650; }
.entry-meta { grid-template-columns: minmax(105px,.8fr) minmax(0,1fr); align-items: end; }
#when-toggle { width: 100%; display: grid; justify-items: start; line-height: 1.15; padding: 4px 9px; gap: 2px; font-size: .86rem; }
#date-format { font-size: .81rem; white-space: nowrap; font-weight: 500; }
#when-fields:has(#when-toggle[aria-expanded=true]) { grid-column: 1/-1; }
#when-inputs { margin-top: 7px; }
html:has(#entry[open]) { overflow: hidden; }
@media(max-width:540px) {
  #entry { position: fixed; inset: var(--editor-offset,0px) 0 auto; width: 100%; max-width: none; height: var(--editor-height,100dvh); max-height: none; margin: 0; border: 0; border-radius: 0; }
  .editor-header { padding-top: calc(7px + env(safe-area-inset-top)); }
  .editor-footer { padding-bottom: calc(7px + env(safe-area-inset-bottom)); }
  .balance-heading h2 { font-size: 18px; }
  .balance-heading .button { font-size: .9rem; }
  .balance-person .person-name { font-size: .91rem; }
  .estimate-total { font-size: .79rem; }
}
