:root {
  --bg: #f5f0e7;
  --surface: #fffdf8;
  --surface-2: #f0e9dc;
  --ink: #1c2a2d;
  --muted: #667679;
  --line: #e4dbcb;
  --primary: #0f6e6e;
  --primary-ink: #ffffff;
  --primary-soft: #dcecea;
  --accent: #d9613a;
  --good: #2b8a57;
  --good-soft: #dcefe3;
  --bad: #b8432d;
  --bad-soft: #f6e0da;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 6px 20px rgba(60, 40, 10, .07);
  --radius: 16px;
  --tab-h: 62px;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f10;
    --surface: #151b1d;
    --surface-2: #1d2629;
    --ink: #eef1ec;
    --muted: #94a3a6;
    --line: #263135;
    --primary: #45bdb2;
    --primary-ink: #04201e;
    --primary-soft: #14302f;
    --accent: #f08a63;
    --good: #4fc282;
    --good-soft: #14301f;
    --bad: #f0866c;
    --bad-soft: #3a1f19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.4; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
.ic { display: inline-flex; vertical-align: middle; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.center { text-align: center; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; }
.page { padding: 18px 16px calc(var(--tab-h) + 96px); }
.page.no-tabs { padding-bottom: 60px; }

/* ---- buttons & fields ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 16px; font-weight: 600; min-height: 44px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; background: transparent; border-radius: 50%; color: inherit; }
.icon-btn:active { background: var(--surface-2); }

label.field { display: block; }
label.field > span { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: 0 0 5px 2px; text-transform: uppercase; letter-spacing: .04em; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea, input:not([type]) {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); min-height: 46px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-amount { display: grid; grid-template-columns: 1fr 112px; gap: 10px; }
.big-amount label:first-child input { font-size: 1.7rem; font-weight: 600; padding: 12px; font-family: var(--font-display); }
.big-amount label:last-child input { font-weight: 700; padding: 11px 6px; height: 100%; min-height: 62px; }
.big-amount { align-items: end; }

/* ---- cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card, .card + .list, .list + .card { margin-top: 12px; }
.section-title { font-family: var(--font-body); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 22px 4px 8px; }
.empty { text-align: center; padding: 34px 18px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ---- header / brand ---- */
.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 8px 0; }
.brand { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.brand em { color: var(--accent); font-style: normal; }

/* ---- auth ---- */
.auth { padding: 8vh 22px 40px; max-width: 420px; margin: 0 auto; }
.auth .brand { font-size: 2.4rem; }
.auth p.lead { color: var(--muted); margin: 8px 0 26px; }
.tabs-inline { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs-inline button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs-inline button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.form-error { color: var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 9px 12px; font-size: .92rem; }

/* ---- trip list ---- */
.trip-card { display: block; width: 100%; text-align: left; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); margin-top: 14px; }
.trip-cover { height: 96px; position: relative; color: #fff; padding: 12px 14px; display: flex; flex-direction: column; justify-content: flex-end; }
.trip-cover h2 { font-size: 1.45rem; text-shadow: 0 1px 8px rgba(0,0,0,.25); }
.trip-cover .status { position: absolute; top: 10px; right: 12px; font-size: .78rem; font-weight: 700; background: rgba(255,255,255,.9); color: #1c2a2d; border-radius: 99px; padding: 3px 10px; }
.trip-cover::after { content: ""; position: absolute; inset: 0; background: radial-gradient(120% 90% at 100% 0%, rgba(255,255,255,.28), transparent 55%); pointer-events: none; }
.trip-body { padding: 12px 14px; display: flex; align-items: center; gap: 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 99px; font-size: .82rem; font-weight: 700; background: var(--surface-2); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

/* ---- trip page ---- */
.trip-head { padding: 0; }
.trip-head .row { margin-left: -10px; }
.trip-title { font-size: 1.7rem; line-height: 1.15; padding: 2px 4px 0; }
.trip-sub { color: var(--muted); padding: 4px 4px 0; font-size: .95rem; }
.avatars { display: flex; padding: 10px 4px 0; }
.avatars .avatar { margin-right: -6px; border: 2px solid var(--bg); }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; font-weight: 700; flex: none; }
.av0 { background: #0f6e6e; } .av1 { background: #d9613a; } .av2 { background: #6b5bd2; } .av3 { background: #c2892a; }
.av4 { background: #2f7fd3; } .av5 { background: #b34584; } .av6 { background: #5a8a2c; } .av7 { background: #7d6a5a; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar .inner { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tabbar button { border: 0; background: transparent; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: .74rem; font-weight: 600; color: var(--muted); }
.tabbar button.on { color: var(--primary); }
.fab { position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 21; height: 56px; padding: 0 20px 0 16px; border-radius: 28px; border: 0; background: var(--accent); color: #fff; font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 6px 20px rgba(217, 97, 58, .4); }

/* ---- itinerary ---- */
.day { margin-top: 22px; }
.day-head { display: flex; align-items: baseline; gap: 10px; margin: 0 4px 8px; }
.day-head h3 { font-size: 1.15rem; }
.day-head span { color: var(--muted); font-size: .85rem; }
.item { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.item .tile { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.item .time { font-size: .8rem; font-weight: 700; color: var(--primary); }
.item .t { font-weight: 700; }
.item .meta { font-size: .86rem; color: var(--muted); margin-top: 2px; }
.item .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.import-banner { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; border: 1.5px dashed color-mix(in srgb, var(--primary) 55%, transparent); background: var(--primary-soft); border-radius: var(--radius); padding: 14px; color: var(--ink); }
.import-banner .ic { color: var(--primary); }

/* ---- expenses ---- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary .big { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; line-height: 1.1; }
.summary .lbl { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.over > i { background: var(--bad); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 2px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 14px; font-weight: 600; font-size: .88rem; }
.filters button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.exp { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; margin-bottom: 8px; }
.exp .tile { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; background: color-mix(in srgb, var(--c, #888) 16%, transparent); color: var(--c, #888); }
.exp .d { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp .amt { text-align: right; flex: none; }
.exp .amt b { font-variant-numeric: tabular-nums; }
.stay-note { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: .92rem; padding: 9px 12px; border-radius: 12px; margin-bottom: 8px; }
.exp.unpaid { border-style: dashed; }
.exp.unpaid .amt b { color: var(--accent); }
.date-head { font-size: .8rem; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .06em; }
.cat-Lodging { --c: #7b6cd9; } .cat-Flights { --c: #2f7fd3; } .cat-Transport { --c: #d19418; } .cat-FoodDrink { --c: #d9613a; }
.cat-Activities { --c: #2f9f78; } .cat-Shopping { --c: #c94f8a; } .cat-Groceries { --c: #74a02a; } .cat-Fees { --c: #7d8a8d; } .cat-Other { --c: #8d7d6e; }

/* ---- balances ---- */
.person { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .n { font-weight: 700; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.settle { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.settle .who { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.settle .pay { flex: 1; font-size: 1.1rem; }
.settle:last-child { border-bottom: 0; }
.arrow { color: var(--muted); }
.allset { text-align: center; padding: 18px 8px; }
.allset .ic { color: var(--good); }

/* ---- sheets ---- */
.scrim { position: fixed; inset: 0; background: rgba(10, 14, 15, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 94dvh; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: rise .22s cubic-bezier(.2, .8, .2, 1); }
.sheet-head { display: flex; align-items: center; padding: 10px 10px 6px 20px; }
.sheet-head h2 { font-size: 1.3rem; flex: 1; }
.sheet-body { overflow-y: auto; padding: 4px 20px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; background: var(--bg); }
.sheet-foot .btn { flex: 1; }
@media (min-width: 720px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 22px; max-height: 88dvh; }
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: .92rem; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick button { display: inline-flex; align-items: center; gap: 7px; border: 1.5px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px 5px 5px; font-weight: 600; }
.pick button.on { border-color: var(--primary); background: var(--primary-soft); }
.pick.cats { gap: 6px; }
.pick.cats button { padding: 6px 11px; font-size: .9rem; gap: 6px; }
.pick.cats button.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 15%, transparent); }
.pick.types button { padding: 7px 12px; }
.custom-row { display: flex; align-items: center; gap: 10px; }
.custom-row input { width: 120px; text-align: right; }
.remain { font-size: .88rem; font-weight: 700; }
.receipt-thumb { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.drop { border: 1.5px dashed var(--line); border-radius: 14px; padding: 16px; text-align: center; color: var(--muted); background: var(--surface); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.checkrow { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin-bottom: 8px; }
.checkrow input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; accent-color: var(--primary); }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 8px 8px 8px 12px; font-size: .9rem; word-break: break-all; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 90px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 90; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; font-weight: 600; font-size: .92rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }
.loading { display: flex; justify-content: center; padding: 70px 0; }
.review-badge { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
