/* ---- Design tokens ------------------------------------------------------
   Palette: deep navy chrome, emerald brand/accent (money), amber for "owed", red for danger.
   Type: the iPhone's own SF Pro (system-ui) -- crisp, no third-party font request. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-hover: #0b5f58;
  --brand-soft: #e6f4f1;
  --on-brand: #ffffff;
  --chrome: #0f1e3d;
  --chrome-text: #e8eefc;
  --chrome-muted: #9fb0d3;
  --owed: #b45309;       --owed-soft: #fef3c7;
  --paid: #15803d;       --paid-soft: #dcfce7;
  --danger: #b91c1c;     --danger-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.05);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #131c2e; --surface-2: #182339; --text: #e8eefc; --text-2: #b6c2dc;
    --muted: #8a9ac0; --line: #243049; --brand: #2dd4bf; --brand-hover: #5eead4; --brand-soft: #12302f;
    --on-brand: #04201d; --chrome: #0a1020; --chrome-text: #e8eefc; --chrome-muted: #8a9ac0;
    --owed: #fbbf24; --owed-soft: #3a2a0a; --paid: #4ade80; --paid-soft: #0f2d1a;
    --danger: #f87171; --danger-soft: #3b1414; --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

/* ---- Base --------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.5 var(--font);
       -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
h1 { font-size: 1.6rem; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; margin: .25rem 0 1.1rem; }
h2 { font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 1.6rem 0 .6rem; }
p { margin: 0 0 .8rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
b, strong { font-weight: 650; }
.muted { color: var(--muted); font-size: .88rem; }

/* ---- Header & navigation ------------------------------------------------ */
header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
         padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
         background: var(--chrome); color: var(--chrome-text); }
header .brand { color: #fff; font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
header .brand:hover { text-decoration: none; }
header .spacer { flex: 1; }
header form { margin: 0; }
.who-am-i { font-size: .9rem; color: var(--chrome-text); display: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600;
         letter-spacing: .02em; background: rgba(255,255,255,.12); color: var(--chrome-text); margin-left: 6px; }
main .badge { background: var(--brand-soft); color: var(--brand); margin: 0; }
header .btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.18); color: #fff; }
header .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

.menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0;
            border-radius: 10px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.1); color: #fff;
            font-size: 1.3rem; line-height: 1; cursor: pointer; }

.shell { display: block; }
main { max-width: 780px; margin: 0 auto; padding: 18px 16px 48px; }
.shell.single main { max-width: 420px; margin: 8vh auto 0; padding-bottom: 24px; }

/* Sidebar: plain text groups, one open at a time. On phones it opens above the page when the menu button is pressed. */
nav { display: none; background: var(--surface); border-bottom: 1px solid var(--line); padding: 6px 0; overflow: hidden; }
body.menu-open nav { display: block; }
nav a, .nav-title { display: flex; align-items: center; justify-content: space-between; box-sizing: border-box; width: 100%;
                    padding: 11px 18px; font: inherit; font-size: .95rem; text-align: left; }
.nav-home { font-weight: 650; color: var(--text); }
.nav-title { border: 0; background: none; color: var(--text); font-weight: 650; cursor: pointer; }
.nav-title::after { content: "\203A"; font-size: 1.2rem; line-height: 1; color: var(--muted); transition: transform .15s; }
.nav-title[aria-expanded="true"]::after { transform: rotate(90deg); }
.nav-title[aria-expanded="true"] { color: var(--brand); }
.nav-items[hidden] { display: none; }
.nav-items a { padding: 9px 18px 9px 32px; color: var(--muted); font-weight: 500; white-space: nowrap;
               overflow: hidden; text-overflow: ellipsis; }
nav a:hover, .nav-title:hover { text-decoration: none; background: var(--brand-soft); }
nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
nav .pill { margin-left: 8px; padding: 0 7px; border-radius: 999px; background: var(--danger); color: #fff;
            font-size: .72rem; font-style: normal; font-weight: 700; }

@media (min-width: 900px) {
  .menu-btn { display: none; }
  .who-am-i { display: inline; }
  .shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 56px); }
  .shell.single { display: block; }
  nav { display: block; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; overflow-x: hidden;
        border-bottom: 0; border-right: 1px solid var(--line); padding: 10px 0; }
  main { max-width: none; width: 100%; min-width: 0; padding: 28px 36px 48px; }
  .shell.single main { max-width: 420px; margin: 8vh auto 0; }
}

/* ---- Cards, rows -------------------------------------------------------- */
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 14px 16px; margin: 0 0 10px; color: var(--text); box-shadow: var(--shadow); }
a.card:hover { text-decoration: none; border-color: var(--brand); }
a.card:active { transform: scale(.995); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 5px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row > span:first-child { color: var(--text-2); }
.who { display: flex; align-items: center; gap: 12px; }
.warn { color: var(--owed); } .ok { color: var(--paid); }

.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.cards3 .card { margin: 0; padding: 12px 14px; }
.cards3 .muted { font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.cards3 b { display: block; font-size: 1.15rem; margin-top: 2px; letter-spacing: -.01em; }
.cards3 .card:last-child { background: var(--brand); border-color: var(--brand); }
.cards3 .card:last-child .muted, .cards3 .card:last-child b { color: var(--on-brand); }

.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; }
.chip.ok { background: var(--paid-soft); color: var(--paid); }
.chip.warn { background: var(--owed-soft); color: var(--owed); }

img { max-width: 100%; max-height: 260px; border-radius: 10px; margin-top: 8px; display: block; border: 1px solid var(--line); }
img.thumb { width: 44px; height: 44px; object-fit: cover; margin: 0; border-radius: 50%; }

/* ---- Buttons ------------------------------------------------------------ */
.btn { display: inline-block; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
       color: var(--text); font: 600 .92rem var(--font); cursor: pointer; margin: 2px 6px 2px 0; }
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--danger); } .btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 5px 12px; font-size: .82rem; }

/* ---- Forms -------------------------------------------------------------- */
input, select, textarea { width: 100%; font: 400 1rem var(--font); color: var(--text); padding: 11px 12px;
        border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; background: var(--surface); }
input[type=file] { border: 0; padding: 6px 0; background: none; font-size: .9rem; }
input[type=file]::file-selector-button { font: 600 .85rem var(--font); padding: 7px 14px; margin-right: 12px; border-radius: 8px;
        border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
input[type=file]::file-selector-button:hover { border-color: var(--brand); }
form.card { max-width: 600px; }
input[type=checkbox] { width: auto; accent-color: var(--brand); }
form div { margin-bottom: 12px; }
form label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.helptext { display: block; font-size: .8rem; color: var(--muted); margin-top: 3px; }
.errorlist { list-style: none; margin: 4px 0; padding: 0; font-size: .85rem; color: var(--danger); font-weight: 600; }
.msg { padding: 11px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.msg.error { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.msg.success { color: var(--paid); background: var(--paid-soft); border-color: transparent; }

/* ---- Tabs & tables ------------------------------------------------------ */
.tabs { display: inline-flex; padding: 3px; gap: 2px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.tabs a { padding: 7px 18px; border-radius: 9px; color: var(--text-2); font-weight: 600; font-size: .9rem; }
.tabs a:hover { text-decoration: none; }
.tabs a.on { background: var(--brand); color: var(--on-brand); }

.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 11px 14px; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); }
th a { color: var(--muted); } th a:hover { color: var(--brand); text-decoration: none; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tfoot th { font-size: .9rem; letter-spacing: 0; text-transform: none; color: var(--text); background: var(--brand-soft); border-top: 2px solid var(--brand); border-bottom: 0; }
td:nth-child(n+3), th:nth-child(n+3) { font-variant-numeric: tabular-nums; }

@media (max-width: 520px) {
  h1 { font-size: 1.4rem; }
  .cards3 { grid-template-columns: 1fr 1fr; } .cards3 .card:last-child { grid-column: 1 / -1; }
}

/* ---- Login ---- */
.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand h1 { margin: 10px 0 2px; }
.logo { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; font-size: 1.8rem; font-weight: 700;
        background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow); }
.btn.block { display: block; width: 100%; margin: 6px 0 0; padding: 12px; }
form.card { margin-left: auto; margin-right: auto; }

/* reports */
table.report td.num, table.report th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.report tr.section td { background: #eef3fb; font-weight: 600; }
table.report tr.subtotal td { font-weight: 600; border-top: 1px solid #ccd6e6; }
table.report tr.total td { font-weight: 700; }
table.report tr.note td { color: #5b6573; font-style: italic; }
form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
form.inline input, form.inline select { width: auto; }
@media print {
  header, nav, .noprint, .btn { display: none !important; }
  .shell { display: block; } main { padding: 0; }
  body { font-size: 11pt; }
}
