:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --text: #17231f;
  --muted: #5f6f6a;
  --border: #dde5e2;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --accent: #f59e0b;
  --pos: #15803d;
  --neg: #b91c1c;
  --pos-bg: #e8f6ec;
  --neg-bg: #fdf0e3;
  --me: #eef8f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1614; --surface: #17211e; --text: #e6efec; --muted: #93a39e; --border: #2a3733;
    --primary: #2dd4bf; --primary-ink: #042f2b; --pos: #4ade80; --neg: #f87171;
    --pos-bg: #13301f; --neg-bg: #3a2513; --me: #1b2c28; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: .2rem 0 .4rem; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.container { max-width: 880px; margin: 0 auto; padding: 16px 16px 64px; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
#nav { display: flex; align-items: center; gap: 14px; font-size: .95rem; }

.hero { text-align: center; padding: 24px 8px 8px; }
.hero h1 { font-size: 1.9rem; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin: 0 0 16px;
}
.card.narrow { max-width: 440px; margin: 16px auto; }
.card.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.link-card { color: var(--text); transition: border-color .15s; }
.link-card:hover { border-color: var(--primary); }
.list { margin-bottom: 16px; }
.list .card { margin-bottom: 10px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--muted); margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; font-weight: 500; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--neg); }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: wait; }
button.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }
button.icon {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); cursor: pointer; font-size: 1rem;
}
button.icon.danger:hover { color: var(--neg); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: .8rem; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }

.callout { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.callout.ok { background: var(--pos-bg); }
.callout.warn { background: var(--neg-bg); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tfoot td { font-weight: 700; border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: var(--me); }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

ul.transfers, ul.expenses, ul.people { list-style: none; margin: 0; padding: 0; }
ul.transfers li {
  display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
}
ul.transfers li .arrow { color: var(--accent); font-weight: 700; }
ul.transfers li strong { font-variant-numeric: tabular-nums; }
ul.transfers li.me, ul.expenses li.me, ul.people li.me { background: var(--me); }
ul.expenses li { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-bottom: 1px solid var(--border); border-radius: 8px; }
.grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
ul.people li { padding: 10px 8px; border-bottom: 1px solid var(--border); border-radius: 8px; }
form.person { display: flex; align-items: center; gap: 10px; }
form.person input[name=name] { flex: 1; min-width: 0; }
form.person .nights { flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
form.person .nights input { width: 80px; }
ul.people .row-actions { margin-top: 8px; }
.badge { font-size: .75rem; background: var(--me); color: var(--primary); border-radius: 999px; padding: 3px 10px; font-weight: 600; }

.invite { border-color: var(--primary); }
.invite dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 14px; }
.invite dt { color: var(--muted); }
.invite dd { margin: 0; overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: 2px 6px; border-radius: 6px; }

details.card summary { cursor: pointer; list-style: none; }
details.card summary h2 { display: inline; margin: 0; }
details.card summary::after { content: " ▾"; color: var(--muted); }
details[open].card summary { margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--neg); color: #fff; }

@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .form.grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  form.person { flex-wrap: wrap; }
  form.person input[name=name] { flex-basis: 100%; }
  ul.transfers li { grid-template-columns: 1fr auto 1fr; }
  ul.transfers li strong { grid-column: 1 / -1; }
  h1 { font-size: 1.4rem; }
}

.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 8px; }
.picker .btn { min-height: 52px; }
.whoami { text-align: right; color: var(--muted); }
.page-head { gap: 12px; flex-wrap: wrap; }
.invite code { display: block; overflow-wrap: anywhere; word-break: break-all; padding: 8px 10px; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand img { border-radius: 8px; display: block; }
.hero-logo { border-radius: 20px; box-shadow: 0 8px 24px rgba(15,118,110,.25); margin-bottom: 8px; }
