:root {
    color-scheme: light;
    --ink: #172033;
    --muted: #687386;
    --soft-muted: #8c96a8;
    --line: #e3e8f0;
    --surface: #ffffff;
    --canvas: #f5f7fb;
    --indigo: #4f46e5;
    --indigo-dark: #4338ca;
    --indigo-soft: #eef0ff;
    --green: #087f5b;
    --green-soft: #e8f7f1;
    --red: #be394b;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid #a5b4fc; outline-offset: 2px; }
.topbar { background: rgba(255,255,255,.93); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1160px; min-height: 66px; margin: auto; padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.back-link { color: #586275; font-size: 12px; font-weight: 600; text-decoration: none; }
.back-link:hover, .page-footer a:hover { color: var(--indigo); }
.header-actions { display: flex; align-items: center; gap: 9px; }
.button { min-height: 40px; padding: 9px 14px; border: 1px solid transparent; border-radius: 10px; font-weight: 650; font-size: 13px; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.button-primary { color: #fff; background: var(--indigo); box-shadow: 0 3px 8px rgba(79,70,229,.16); }
.button-primary:hover:not(:disabled) { background: var(--indigo-dark); }
.button-secondary { color: #354056; background: #fff; border-color: #dce2ec; }
.button-secondary:hover { background: #f8f9fc; border-color: #c8d0df; }
.button-small { min-height: 34px; padding: 7px 11px; font-size: 12px; }
.count-pill { display: inline-grid; min-width: 19px; height: 19px; margin-left: 5px; place-items: center; border-radius: 99px; background: #eef0ff; color: var(--indigo); font-size: 11px; }
.page-shell { width: min(1160px, 100% - 40px); margin: 0 auto; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 36px; padding: 42px 2px 24px; }
.eyebrow { margin: 0 0 8px; color: #626f87; font-size: 10px; font-weight: 750; letter-spacing: .12em; }
h1, h2, p { margin-top: 0; }
.hero h1 { margin: 0; font-size: clamp(31px, 4.6vw, 46px); line-height: 1.12; letter-spacing: -.045em; }
.hero h1 span { color: var(--indigo); }
.hero-copy { max-width: 570px; margin: 13px 0 0; color: var(--muted); font-size: 15px; line-height: 1.65; }
.local-note { display: flex; flex: 0 0 290px; align-items: flex-start; gap: 11px; padding: 14px; border: 1px solid #d9eee5; border-radius: 13px; background: #f2fbf7; }
.local-note-icon { display: grid; width: 22px; height: 22px; flex: 0 0 22px; place-items: center; border-radius: 50%; color: var(--green); background: #d9f2e7; font-size: 13px; font-weight: 800; }
.local-note strong, .local-note span:not(.local-note-icon) { display: block; }
.local-note strong { margin: 1px 0 4px; color: #215b49; font-size: 12px; }
.local-note div span { color: #57766b; font-size: 11px; line-height: 1.45; }
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 18px; padding: 0 2px 14px; }
.toolbar-actions { display: flex; align-items: center; gap: 18px; }
.toolbar { flex-wrap: wrap; }
.summary-name { flex: 1 1 220px; max-width: 320px; }
.summary-name span { font-size: 10px; font-weight: 450; }
@media (max-width: 560px) { .summary-name { flex: none; width: 100%; max-width: none; } }
.currency-picker { display: grid; gap: 6px; color: #606c7e; font-size: 11px; font-weight: 650; }
.currency-picker select { min-width: 218px; min-height: 37px; padding: 7px 31px 7px 10px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 9px; font-size: 12px; }
.save-status { color: var(--soft-muted); font-size: 11px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 17px; }
.stat-card { min-width: 0; padding: 15px 17px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; }
.stat-label { display: block; margin-bottom: 7px; color: var(--soft-muted); font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.stat-card strong { display: block; overflow: hidden; color: #202b40; font-size: 22px; font-weight: 720; letter-spacing: -.03em; text-overflow: ellipsis; white-space: nowrap; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(270px, .9fr); align-items: start; gap: 17px; }
.main-column, .side-column { display: grid; gap: 17px; }
.panel { min-width: 0; padding: 21px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 4px 15px rgba(27,39,68,.025); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 19px; }
.panel-heading .eyebrow { margin-bottom: 5px; }
.panel-heading h2, .settlement-card h2, .dialog-heading h2 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.compact-heading { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, .9fr) minmax(0, .8fr); gap: 12px; }
.field { display: grid; align-content: start; gap: 7px; color: #586477; font-size: 11px; font-weight: 700; }
.field-wide { grid-column: span 1; }
.field-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.field input, .field select, .search-field input, .inline-input input { width: 100%; min-width: 0; height: 41px; padding: 9px 11px; color: var(--ink); background: #fbfcfe; border: 1px solid #dfe4ed; border-radius: 9px; font-size: 13px; font-weight: 450; }
.field input::placeholder, .search-field input::placeholder, .inline-input input::placeholder { color: #a0a8b6; }
.field select { padding-right: 25px; }
#currencyCode { flex: 0 0 auto; color: #9ba4b3; font-size: 9px; font-weight: 700; white-space: nowrap; }
.split-fieldset { min-width: 0; margin: 19px 0 0; padding: 15px; border: 1px solid #e6e9f1; border-radius: 12px; background: #fafbfe; }
.split-fieldset legend { padding: 0 6px; color: #586477; font-size: 11px; font-weight: 700; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; background: #edf0f6; border-radius: 9px; }
.segment { min-height: 32px; padding: 6px 11px; color: #697488; background: transparent; border: 0; border-radius: 7px; font-size: 11px; font-weight: 650; }
.segment.active { color: var(--indigo); background: #fff; box-shadow: 0 1px 4px rgba(30,41,59,.1); }
.split-panel { margin-top: 13px; }
.submode-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.submode-label { color: #7b8494; font-size: 10px; }
.submode-buttons { display: flex; gap: 12px; }
.text-button { padding: 3px 0; color: #7b8494; background: none; border: 0; font-size: 11px; font-weight: 600; }
.text-button:hover { color: var(--indigo); }
.text-button.active { color: var(--indigo); }
.people-checklist, .custom-share-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.person-choice { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 9px 10px; color: #4d586b; background: #fff; border: 1px solid #e4e8ef; border-radius: 9px; font-size: 12px; }
.person-choice input { width: 15px; height: 15px; margin: 0; accent-color: var(--indigo); }
.person-choice span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-share-list { gap: 8px; }
.custom-share-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(92px, .8fr); align-items: center; gap: 8px; padding: 7px 9px; background: #fff; border: 1px solid #e4e8ef; border-radius: 9px; }
.custom-share-row span { overflow: hidden; color: #4d586b; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.custom-share-row input { width: 100%; height: 32px; padding: 6px 8px; text-align: right; border: 1px solid #e3e7ee; border-radius: 7px; font-size: 12px; }
.field-hint { margin: 8px 0 0; color: #828b9b; font-size: 10px; }
.field-hint.is-valid { color: var(--green); }
.field-hint.is-invalid { color: var(--red); }
.item-rows { display: grid; gap: 9px; }
.item-row { padding: 11px; background: #fff; border: 1px solid #e2e6ee; border-radius: 10px; }
.item-row-top { display: grid; grid-template-columns: minmax(0,1fr) 115px 30px; gap: 8px; }
.item-row-top input { min-width: 0; height: 34px; padding: 7px 9px; border: 1px solid #e2e6ee; border-radius: 7px; font-size: 11px; }
.item-row-top input[type=number] { text-align: right; }
.icon-button { width: 31px; height: 31px; display: grid; place-items: center; color: #8791a1; background: transparent; border: 0; border-radius: 7px; font-size: 20px; }
.icon-button:hover { color: var(--red); background: #fff0f1; }
.item-people { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.item-people-label { margin-right: 3px; color: #8791a1; font-size: 10px; }
.item-person { display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px; color: #667184; background: #f8f9fc; border: 1px solid #e7eaf0; border-radius: 6px; font-size: 10px; }
.item-person input { margin: 0; accent-color: var(--indigo); }
.item-total { display: flex; justify-content: space-between; margin-top: 11px; padding: 10px 11px; color: #454f65; background: var(--indigo-soft); border-radius: 8px; font-size: 11px; }
.item-total strong { color: var(--indigo-dark); }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 14px; }
.form-error { min-height: 16px; margin: 0 auto 0 0; color: var(--red); font-size: 11px; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.session-panel { display: grid; gap: 12px; margin-bottom: 18px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.session-panel strong { display: block; margin-bottom: 5px; font-size: 12px; overflow-wrap: anywhere; }
.session-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.session-actions .text-button { min-height: 40px; }
.file-button { position: relative; cursor: pointer; }
.file-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.file-button:focus-within { outline: 2px solid var(--indigo); outline-offset: 2px; }
.join-field { display: grid; gap: 7px; margin: 18px 0 10px; }
.join-field input { min-height: 42px; width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.people-dialog.sharing-dialog { width: min(520px, calc(100% - 30px)); overflow-y: auto; }
.sharing-dialog .form-error { margin-top: 12px; line-height: 1.5; }
.sharing-choice { padding: 16px 0; }
.sharing-choice + .sharing-choice { border-top: 1px solid var(--line); }
.sharing-choice h3 { margin: 0; font-size: 15px; }
.sharing-choice .join-field { margin-top: 12px; }
.sharing-privacy { margin-bottom: 0; }
.sharing-more { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.sharing-more summary { padding: 5px 0; cursor: pointer; color: #4d586e; font-size: 12px; font-weight: 650; }
.sharing-more .button, .sharing-more .text-button { margin: 5px 0; }
.sharing-availability { margin: 0; padding: 12px; border: 1px solid #eed5aa; border-radius: 9px; background: #fff8e9; color: #795518; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.session-actions > *, .sharing-dialog .session-actions > * { min-width: 0; max-width: 100%; white-space: normal; }
@media (max-width: 560px) {
    .sharing-dialog .session-actions { align-items: stretch; flex-direction: column; }
    .sharing-dialog .session-actions > *, .sharing-choice > .button { width: 100%; }
    .sharing-dialog .join-field input { font-size: 16px; }
    .sharing-more summary { display: flex; align-items: center; gap: 8px; min-height: 44px; }
    .sharing-more summary::before { content: '+'; }
    .sharing-more[open] > summary::before { content: '−'; }
}
.history-panel { padding-bottom: 8px; }
.history-heading { margin-bottom: 12px; }
.search-field { width: min(230px, 50%); }
.search-field input { height: 36px; background: #fff; font-size: 11px; }
.table-wrap { min-width: 0; }
table { width: 100%; border-collapse: collapse; text-align: left; }
thead th { padding: 9px 8px; color: #9099a9; border-bottom: 1px solid #e9ecf2; font-size: 9px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
tbody td { padding: 12px 8px; color: #596477; border-bottom: 1px solid #eff1f5; font-size: 11px; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.expense-name { display: block; max-width: 210px; color: #293448; font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.expense-meta { display: block; margin-top: 4px; color: #939bab; font-size: 10px; }
.split-details { min-width: 130px; max-width: 230px; color: #758094; line-height: 1.5; }
.split-details span { display: block; }
.mobile-cell-label { display: none !important; }
.cell-value { display: block; min-width: 0; overflow-wrap: anywhere; }
.amount-cell { text-align: right; white-space: nowrap; }
.table-actions { display: flex; justify-content: flex-end; gap: 4px; }
.table-action { padding: 4px 6px; color: #7d8799; background: transparent; border: 0; border-radius: 5px; font-size: 10px; }
.table-action:hover { color: var(--indigo); background: #f0f1ff; }
.table-action.delete:hover { color: var(--red); background: #fff0f1; }
.empty-state { display: grid; justify-items: center; gap: 6px; padding: 32px 15px 27px; color: #8b94a3; text-align: center; }
.empty-state strong { color: #596477; font-size: 12px; }
.empty-state span:last-child { max-width: 330px; font-size: 10px; line-height: 1.5; }
.empty-icon { display: grid; width: 35px; height: 35px; margin-bottom: 3px; place-items: center; color: var(--indigo); background: var(--indigo-soft); border-radius: 11px; font-size: 21px; }
.muted-copy { margin: 0; color: #8b94a3; font-size: 11px; line-height: 1.5; }
.balances-list { display: grid; gap: 8px; }
.balance-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 11px; background: #f8f9fc; border: 1px solid #eef0f4; border-radius: 9px; }
.balance-name { min-width: 0; color: #424d61; font-size: 11px; font-weight: 650; overflow-wrap: anywhere; }
.balance-value { text-align: right; white-space: nowrap; }
.balance-value strong { display: block; font-size: 12px; }
.balance-value span { display: block; margin-top: 3px; color: #929aaa; font-size: 9px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral { color: #687386; }
.settlement-card { padding: 20px; color: #f7f8ff; background: #28265e; border-radius: 15px; box-shadow: 0 5px 18px rgba(37,35,91,.11); }
.settlement-card .eyebrow { color: #b4b7e5; }
.settlement-card h2 { margin-bottom: 15px; font-size: 18px; }
.settlements-list { display: grid; gap: 8px; }
.settlement-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px; background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.09); border-radius: 9px; }
.settlement-route { min-width: 0; color: #f8f8ff; font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.settlement-route span { color: #c0c2e8; padding: 0 4px; }
.settlement-amount { color: #9be4c5; font-size: 12px; font-weight: 700; white-space: nowrap; }
.settlement-empty { margin: 0; color: #ced0ed; font-size: 11px; line-height: 1.55; }
.danger-link { color: #a94d5b; }
.danger-link:hover { color: #9a2639; }
.page-footer { display: flex; justify-content: space-between; gap: 12px; max-width: 1160px; margin: 28px auto 0; padding: 18px 24px 24px; color: #929aaa; border-top: 1px solid var(--line); font-size: 10px; }
.page-footer a { color: #667184; font-weight: 600; text-decoration: none; }
.people-dialog { width: min(440px, calc(100% - 30px)); max-height: min(85vh, 700px); padding: 23px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 25px 80px rgba(21,31,55,.23); }
.people-dialog::backdrop { background: rgba(25,32,51,.4); backdrop-filter: blur(3px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; }
.dialog-copy { margin: 10px 0 15px; color: #798395; font-size: 11px; line-height: 1.55; }
.participant-list { display: grid; gap: 7px; max-height: 225px; overflow-y: auto; }
.participant-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 10px; background: #f8f9fc; border: 1px solid #eaedf2; border-radius: 9px; }
.participant-row span { color: #4d586b; font-size: 12px; overflow-wrap: anywhere; }
.participant-row .text-button { flex: 0 0 auto; color: #a64b59; }
.add-person-form { margin-top: 16px; }
.inline-input { display: flex; gap: 7px; }
.inline-input input { flex: 1; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 15px; padding-top: 14px; border-top: 1px solid #edf0f4; }
.toast { position: fixed; z-index: 5; right: 20px; bottom: 20px; max-width: min(380px, calc(100vw - 40px)); padding: 12px 15px; color: #fff; background: #1f2937; border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,.22); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.noscript-note { margin: 12px; padding: 12px; color: #7f1d1d; background: #fff1f2; border-radius: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 820px) {
    .hero { align-items: start; flex-direction: column; gap: 18px; padding-top: 31px; }
    .local-note { flex-basis: auto; width: min(100%, 470px); }
    .content-grid { grid-template-columns: minmax(0,1fr); }
    .side-column { grid-template-columns: repeat(2, minmax(0,1fr)); align-items: start; }
}
@media (max-width: 680px) {
    table, tbody { display: block; width: 100%; }
    thead { display: none; }
    tbody { display: grid; gap: 9px; }
    tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "expense paid" "details details" "amount actions"; align-items: center; gap: 9px 12px; padding: 12px; border: 1px solid #e9ecf2; border-radius: 11px; background: #fff; }
    tbody td { display: block; min-width: 0; padding: 0; border: 0; font-size: 11px; }
    tbody td.expense-cell { grid-area: expense; }
    tbody td:nth-child(2) { grid-area: paid; max-width: 115px; text-align: right; }
    tbody td.split-details { grid-area: details; max-width: none; min-width: 0; padding-top: 8px; border-top: 1px solid #eff1f5; }
    tbody td.amount-cell { grid-area: amount; text-align: left; }
    tbody td.table-actions { grid-area: actions; align-self: end; }
    .mobile-cell-label { display: block !important; margin-bottom: 3px; color: #939bab; font-size: 9px; font-weight: 650; letter-spacing: .04em; text-align: inherit; text-transform: uppercase; }
    .expense-name { max-width: none; }
    .split-details .split-detail-content { color: #758094; }
    .amount-cell .cell-value { color: #293448; font-size: 12px; font-weight: 700; white-space: normal; }
    .empty-match-cell { grid-column: 1 / -1; padding: 10px; text-align: center; }
}
@media (max-width: 560px) {
    .topbar-inner { align-items: flex-start; flex-direction: column; padding: 12px 18px; }
    .header-actions { width: 100%; }
    .header-actions .button { flex: 1; padding-inline: 8px; font-size: 11px; }
    .page-shell { width: calc(100% - 28px); }
    .hero { padding: 28px 1px 20px; }
    .hero h1 { font-size: 34px; }
    .hero-copy { font-size: 13px; }
    .toolbar { align-items: start; flex-direction: column; gap: 8px; }
    .toolbar-actions { width: 100%; justify-content: space-between; gap: 12px; }
    .currency-picker { width: 100%; }
    .currency-picker select { width: 100%; }
    .stats-grid { gap: 7px; }
    .stat-card { padding: 12px 10px; border-radius: 11px; }
    .stat-label { min-height: 22px; font-size: 8px; line-height: 1.35; }
    .stat-card strong { font-size: 17px; }
    .panel { padding: 16px 13px; border-radius: 13px; }
    .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
    .field-wide { grid-column: 1 / -1; }
    .split-fieldset { padding: 12px 9px; }
    .segment { padding-inline: 8px; font-size: 10px; }
    .submode-row { align-items: flex-start; flex-direction: column; }
    .submode-buttons { align-self: flex-end; }
    .people-checklist, .custom-share-list { grid-template-columns: minmax(0,1fr); }
    .item-row-top { grid-template-columns: minmax(0,1fr) 88px 28px; gap: 5px; }
    .side-column { grid-template-columns: minmax(0,1fr); }
    .history-heading { align-items: flex-start; flex-direction: column; }
    .search-field { width: 100%; }
    .history-panel { padding-right: 10px; padding-left: 10px; }
    .form-actions { align-items: stretch; flex-direction: column; }
    .form-actions .button { width: 100%; }
    .page-footer { align-items: flex-start; flex-direction: column; margin-top: 19px; padding-inline: 16px; }
    .submode-buttons .text-button { min-height: 36px; }
    .table-action { padding: 8px; }
}

@media (max-width: 400px) {
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .field-wide { grid-column: auto; }
    .item-row-top { grid-template-columns: minmax(0, 1fr) 72px 28px; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
