:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-soft: #f9f9f7;
  --text: #181a1d;
  --muted: #6c7078;
  --line: #e6e6e1;
  --accent: #1c6b5a;
  --accent-dark: #145145;
  --accent-soft: #e8f4f0;
  --danger: #b63f4f;
  --danger-soft: #fff0f2;
  --person-1: #3478d4;
  --person-1-soft: color-mix(in srgb, var(--person-1) 14%, white);
  --person-2: #df6aa0;
  --person-2-soft: color-mix(in srgb, var(--person-2) 15%, white);
  --shadow: 0 14px 34px rgba(33, 36, 40, .07);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg); touch-action: manipulation; }
body { margin: 0; min-height: 100%; background: var(--bg); -webkit-font-smoothing: antialiased; touch-action: manipulation; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
svg { width: 1.35em; height: 1.35em; fill: currentColor; }
.app-shell { min-height: 100vh; padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; padding: calc(16px + env(safe-area-inset-top)) 20px 14px; background: rgba(245,245,242,.88); backdrop-filter: blur(20px); border-bottom: 1px solid rgba(230,230,225,.75); }
.topbar h1 { margin: 2px 0 0; font-size: clamp(1.55rem, 5vw, 2rem); letter-spacing: -.035em; }
.eyebrow, .section-kicker { margin: 0; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
main { width: min(100%, 980px); margin: 0 auto; padding: 18px 16px 40px; }
.view { display: none; animation: fade-in .2s ease; }
.view.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
.card, .hero-card { background: var(--surface); border: 1px solid rgba(228,228,222,.9); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card { padding: 20px; }
.hero-card { padding: 22px; display: grid; grid-template-columns: auto 1fr; gap: 14px 16px; align-items: center; overflow: hidden; position: relative; }
.hero-card::after { content: ""; position: absolute; width: 170px; height: 170px; right: -70px; top: -85px; border-radius: 50%; background: var(--accent-soft); }
.hero-icon { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 16px; color: var(--accent); background: var(--accent-soft); }
.hero-icon svg { width: 27px; height: 27px; }
.hero-card h2, .card h2 { margin: 2px 0 4px; letter-spacing: -.025em; font-size: 1.2rem; }
.hero-card p, .settings-intro, .privacy-card p { color: var(--muted); margin: 0; line-height: 1.55; font-size: .92rem; }
.source-grid { grid-column: 1 / -1; display: grid; gap: 12px; position: relative; z-index: 1; margin-top: 6px; }
.source-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.paste-source { display: grid; gap: 8px; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-soft); }
.paste-source-title { display: flex; align-items: center; gap: 7px; font-size: .78rem; font-weight: 800; color: var(--text); }
.paste-source-title svg { color: var(--accent); }
.paste-source textarea { width: 100%; min-height: 148px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text); padding: 11px 12px; outline: none; line-height: 1.45; font-size: 16px; }
.paste-source textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.paste-source-help { color: var(--muted); font-size: .7rem; line-height: 1.35; }
.primary-action, .secondary-action, .small-button, .secondary-wide, .wide-primary, .secondary-danger { border-radius: 14px; min-height: 48px; border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; text-decoration: none; }
.primary-action, .wide-primary { background: var(--accent); color: white; box-shadow: 0 8px 18px rgba(28,107,90,.2); }
.primary-action:active, .wide-primary:active { background: var(--accent-dark); transform: translateY(1px); }
.secondary-action, .secondary-wide { color: var(--text); background: var(--surface-soft); border: 1px solid var(--line); }
.secondary-action.compact { min-height: 38px; padding: 0 12px; font-size: .84rem; }
.wide-primary, .secondary-wide { width: 100%; padding: 0 18px; }
.wide-primary { margin-top: 18px; }
.small-button { min-height: 36px; padding: 0 12px; color: var(--accent); background: var(--accent-soft); font-size: .82rem; }
.button-reset { padding: 0 22px; }
.icon-button, .close-button { border: 0; background: var(--surface); color: var(--text); width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; box-shadow: 0 4px 15px rgba(0,0,0,.06); }
.close-button { box-shadow: none; background: var(--surface-soft); font-size: 1.6rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-heading h2 { margin-top: 4px; }
.text-button { border: 0; background: transparent; font-weight: 700; padding: 8px; }
.text-button.danger { color: var(--danger); }
.inline-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.compact-source-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { color: var(--muted); font-size: .76rem; line-height: 1.35; }
.image-list { display: grid; gap: 10px; }
.image-card { display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; padding: 10px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 16px; align-items: center; }
.image-card img { width: 72px; height: 82px; object-fit: cover; border-radius: 10px; background: #eee; }
.image-meta strong { display: block; font-size: .9rem; }
.image-meta span { color: var(--muted); font-size: .76rem; }
.image-controls { display: flex; flex-direction: column; gap: 4px; }
.mini-icon { border: 0; width: 30px; height: 30px; border-radius: 9px; background: #fff; color: var(--muted); display: grid; place-items: center; }
.file-card { padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-soft); }
.file-card strong { display: block; margin-bottom: 5px; }
.file-card pre { margin: 0; font: .75rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; max-height: 130px; overflow: hidden; color: var(--muted); }
.status-banner { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; background: #fffdf3; border: 1px solid #ede2b2; padding: 13px; border-radius: 18px; margin-bottom: 14px; }
.status-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: #f3e7a8; font-weight: 900; }
.status-copy strong, .status-copy span { display: block; }
.status-copy span { color: var(--muted); font-size: .78rem; margin: 2px 0 7px; }
.progress-track { height: 5px; background: rgba(0,0,0,.08); border-radius: 99px; overflow: hidden; }
.progress-track.large { height: 8px; margin-top: 12px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.processing-card { display: flex; align-items: center; gap: 16px; }
.processing-card > div:last-child { flex: 1; }
.processing-card p { margin: 5px 0 0; color: var(--muted); }
.spinner { width: 42px; height: 42px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: .75rem; color: var(--muted); font-weight: 700; }
.field input, .field select { width: 100%; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); color: var(--text); min-height: 47px; padding: 0 12px; outline: none; font-size: 16px; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money-input { position: relative; }
.money-input input { padding-right: 38px; }
.money-input span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.badge, .count-badge { border-radius: 99px; padding: 6px 10px; background: var(--accent-soft); color: var(--accent); font-size: .7rem; font-weight: 800; white-space: nowrap; }
.count-badge { min-width: 29px; text-align: center; }
.count-badge.muted { background: #efefec; color: var(--muted); }
.gesture-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 13px; }
.legend-chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 99px; padding: 6px 9px; background: var(--surface-soft); color: var(--muted); font-size: .72rem; font-weight: 650; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.items-list { display: grid; gap: 8px; }
.item-row { position: relative; display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; min-height: 64px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-soft); padding: 9px 12px 9px 8px; touch-action: manipulation; user-select: none; -webkit-user-select: none; transition: background .15s ease, border-color .15s ease, transform .1s ease; }
.item-row:active { transform: scale(.995); }
.item-row.person-1 { background: var(--person-1-soft); border-color: color-mix(in srgb, var(--person-1) 35%, white); }
.item-row.person-2 { background: var(--person-2-soft); border-color: color-mix(in srgb, var(--person-2) 35%, white); }
.item-row.requires-review { border-color: #e4a73b; box-shadow: inset 0 0 0 1px rgba(228,167,59,.12); }
.item-flags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.item-flag { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 3px 7px; font-size: .62rem; font-weight: 800; line-height: 1.2; }
.item-flag.warning { background: #fff3d9; color: #8a5b00; }
.item-flag.learned { background: var(--accent-soft); color: var(--accent-dark); }
.item-flag.confirmed { background: #edf6ee; color: #26723a; }
.item-price-wrap { display: grid; justify-items: end; gap: 5px; }
.review-price-button { border: 0; border-radius: 9px; padding: 5px 7px; background: #fff3d9; color: #8a5b00; font-size: .66rem; font-weight: 800; }
.review-price-button.confirmed { background: #edf6ee; color: #26723a; }
.edit-item-button { border: 0; background: rgba(255,255,255,.75); width: 34px; height: 34px; border-radius: 11px; color: var(--muted); display: grid; place-items: center; }
.item-copy strong { display: block; font-size: .88rem; line-height: 1.25; }
.item-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }
.item-price { text-align: right; font-weight: 850; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-owner { font-size: .65rem; color: var(--muted); margin-top: 3px; font-weight: 700; }
.sum-check { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; display: grid; gap: 7px; }
.sum-check > div { display: flex; justify-content: space-between; gap: 12px; font-size: .84rem; }
.sum-check span { color: var(--muted); }
#differenceRow.ok strong { color: var(--accent); }
#differenceRow.error strong { color: var(--danger); }
.validation-message { margin-top: 12px; font-size: .8rem; line-height: 1.45; border-radius: 12px; padding: 10px 12px; background: var(--accent-soft); color: var(--accent-dark); }
.validation-message.error { background: var(--danger-soft); color: var(--danger); }
.price-review-summary { margin-top: 12px; border-radius: 13px; padding: 11px 12px; background: #fff7e8; border: 1px solid #f0d7a8; color: #7b5308; font-size: .78rem; line-height: 1.45; }
.confirmation-field { display: flex; align-items: flex-start; gap: 10px; margin-top: 15px; padding: 12px; border: 1px solid #f0d7a8; border-radius: 14px; background: #fff7e8; }
.confirmation-field input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }
.confirmation-field span { display: grid; gap: 3px; }
.confirmation-field strong { font-size: .82rem; }
.confirmation-field small { color: #7b5308; line-height: 1.35; }
.split-summary { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 0; overflow: hidden; }
.summary-cell { padding: 15px 9px; text-align: center; border-right: 1px solid var(--line); }
.summary-cell:last-child { border-right: 0; }
.summary-cell span { display: block; color: var(--muted); font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-cell strong { display: block; margin-top: 4px; font-size: .95rem; }
.summary-cell.common { background: var(--surface-soft); }
.sticky-save { position: sticky; bottom: calc(83px + env(safe-area-inset-bottom)); z-index: 10; box-shadow: 0 14px 30px rgba(28,107,90,.3); }
.sticky-save:disabled { opacity: .45; box-shadow: none; cursor: not-allowed; }
.table-card { padding: 18px 0 0; overflow: hidden; }
.table-card .section-heading { padding: 0 18px; }
.receipt-table-wrap { overflow-x: auto; }
.receipt-table { width: 100%; border-collapse: collapse; min-width: 760px; font-size: .82rem; }
.receipt-table th { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 750; background: var(--surface-soft); text-align: left; padding: 10px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.receipt-table td { padding: 13px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
.receipt-table tbody tr.clickable { cursor: pointer; }
.receipt-table tbody tr.clickable:active { background: var(--accent-soft); }
.receipt-table .total-cell { font-weight: 900; }
.receipt-table tr.paid { color: #9b9da1; background: #f4f4f2; }
.empty-state { text-align: center; color: var(--muted); padding: 34px 18px 40px; }
.empty-state strong { color: var(--text); display: block; margin-bottom: 5px; }
.people-settings { display: grid; gap: 14px; margin: 16px 0; }
.person-setting { border: 1px solid var(--line); border-radius: 18px; padding: 15px; background: var(--surface-soft); }
.person-header-fields { display: grid; grid-template-columns: 1fr 68px; gap: 10px; }
.color-input { padding: 5px !important; }
.cards-editor { margin-top: 15px; display: grid; gap: 8px; }
.cards-editor-title { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .76rem; font-weight: 800; }
.card-setting-row { display: grid; grid-template-columns: 1fr 92px 34px; gap: 7px; }
.card-setting-row input { min-height: 42px; border: 1px solid var(--line); border-radius: 11px; padding: 0 10px; background: #fff; min-width: 0; }
.remove-card { border: 0; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }
.privacy-list { display: grid; gap: 11px; }
.privacy-list > div { display: flex; gap: 10px; align-items: flex-start; }
.check { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 900; flex: 0 0 auto; }
.bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.94); border-top: 1px solid var(--line); backdrop-filter: blur(24px); }
.nav-item { min-height: 57px; border: 0; border-radius: 15px; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: .68rem; font-weight: 750; }
.nav-item svg { width: 23px; height: 23px; }
.nav-item.active { color: var(--accent); background: var(--accent-soft); }
.modal { border: 0; padding: 0; background: transparent; width: min(calc(100% - 24px), 560px); max-height: calc(100vh - 24px); }
.modal::backdrop { background: rgba(10,12,14,.45); backdrop-filter: blur(3px); }
.modal-card { display: block; background: var(--surface); border-radius: 24px; padding: 20px; box-shadow: 0 24px 70px rgba(0,0,0,.24); max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.modal-header h2 { margin: 4px 0 0; }
.modal-actions { margin-top: 18px; display: flex; justify-content: space-between; gap: 10px; }
.secondary-danger { padding: 0 15px; background: var(--danger-soft); color: var(--danger); }
.receipt-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.detail-box { padding: 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 14px; }
.detail-box span { display: block; color: var(--muted); font-size: .7rem; }
.detail-box strong { display: block; margin-top: 4px; font-size: .88rem; }
.settlement-sentence { padding: 16px; border-radius: 16px; background: var(--accent-soft); color: var(--accent-dark); font-size: 1rem; font-weight: 750; line-height: 1.45; margin: 16px 0; }
.detail-items { max-height: 250px; overflow-y: auto; border: 1px solid var(--line); border-radius: 15px; }
.detail-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: .8rem; }
.detail-item:last-child { border-bottom: 0; }
.detail-item span:last-child { font-weight: 800; white-space: nowrap; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(94px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); padding: 11px 15px; color: white; background: #222629; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: .82rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 720px) {
  main { padding-top: 26px; }
  .hero-card { grid-template-columns: auto 1fr; }
  .source-grid { grid-template-columns: minmax(250px, .7fr) minmax(360px, 1.3fr); }
  .source-actions { grid-template-columns: 1fr; }
  .inline-actions { align-items: flex-start; flex-direction: column; }
  .topbar { padding-left: max(24px, calc((100vw - 980px)/2)); padding-right: max(24px, calc((100vw - 980px)/2)); }
  .bottom-nav { left: 50%; right: auto; transform: translateX(-50%); width: 430px; bottom: 16px; border: 1px solid var(--line); border-radius: 22px; padding-bottom: 8px; box-shadow: var(--shadow); }
  .app-shell { padding-bottom: 110px; }
  .sticky-save { bottom: 105px; }
  .toast { bottom: 115px; }
}
@media (max-width: 410px) {
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .source-actions { grid-template-columns: 1fr; }
  .inline-actions { align-items: flex-start; flex-direction: column; }
  .status-banner { grid-template-columns: auto 1fr; }
  .status-banner .small-button { grid-column: 1 / -1; }
}
.field-warning { color: #8a5b00; font-size: .7rem; line-height: 1.35; }
.field-warning-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 9px; border-radius: 10px; background: #fff7e8; border: 1px solid #f0d7a8; }
.inline-confirm-button { flex: 0 0 auto; border: 0; border-radius: 8px; padding: 6px 8px; background: #8a5b00; color: white; font-size: .68rem; font-weight: 800; }
.memory-clear-button { margin-top: 14px; color: var(--danger); }
