/* Expensiz — calm, precise, native-feeling. Mobile first; desktop ≥768px. */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --fg: #17191f;
  --muted: #6a7080;
  --border: #e2e5eb;
  --accent: #2f5be7;
  --accent-fg: #ffffff;
  --danger: #c43d3d;
  --ok: #1f8a4c;
  --tint: #eef2fe;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --card: #1a1d25;
    --fg: #e9ebf1;
    --muted: #9aa1b1;
    --border: #2b3040;
    --accent: #5a78f2;
    --accent-fg: #ffffff;
    --danger: #ef6b6b;
    --ok: #4cc27a;
    --tint: #1d2437;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
.app { max-width: 640px; margin: 0 auto; padding: 0 16px; }
main { padding: 16px 0 32px; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 17px; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.h { font-size: 13px; font-weight: 600; color: var(--muted); margin: 20px 0 8px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); line-height: 1.6; }
.note, .hint, .help { font-size: 13px; color: var(--muted); }
.help { font-size: 14px; margin: -4px 0 12px; }
.hint { margin-top: 6px; }
.note { margin-top: 8px; }

/* ---------- header ---------- */
#header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  margin: 0 -16px;
  padding: env(safe-area-inset-top) 16px 10px;
  border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px;
}
.brand { grid-area: 1 / 1; display: flex; align-items: center; min-height: 48px; font-weight: 700; font-size: 17px; color: var(--fg); text-decoration: none; }
.you { grid-area: 1 / 2; position: relative; font-size: 12px; color: var(--muted); text-decoration: none; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); white-space: nowrap; }
.you::before { content: ""; position: absolute; inset: -8px 0; } /* 44px+ hit area, same visual */
.balance { grid-area: 2 / 1 / 3 / 3; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
body:not([data-screen="app"]) :is(#header, .tabs) { display: none !important; }

/* ---------- nav: bottom tab bar on mobile, header links on desktop ---------- */
.tabs a { color: var(--muted); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 767px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card); border-top: 1px solid var(--border);
  }
  .tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 500; }
  main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (min-width: 768px) {
  .tabs {
    position: fixed; top: env(safe-area-inset-top, 0px); left: 0; right: 0; z-index: 11;
    height: 52px; max-width: 640px; margin: 0 auto; padding: 0 16px;
    display: flex; justify-content: flex-end; align-items: center; gap: 4px;
    pointer-events: none;
  }
  .tabs a { pointer-events: auto; display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; font-size: 15px; font-weight: 500; }
  .tabs a:hover { background: var(--tint); }
  .tabs a[aria-current="page"] { text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 2px; }
  .tabs svg { display: none; }
  .brand { min-height: 52px; }
  .you { grid-area: 2 / 2; }
  .balance { grid-area: 2 / 1; }
}

/* ---------- cards, fields, controls ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.card > h2 { margin-bottom: 12px; }
.field { display: block; margin-bottom: 12px; }
.lbl { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.lbl em { font-style: normal; font-weight: 400; }

input, button, select, textarea {
  font: inherit; font-size: 16px; min-height: 48px; padding: 0 12px; margin: 0;
  border: 1px solid var(--border); border-radius: 10px; width: 100%;
  background: var(--card); color: var(--fg);
}
textarea { padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.4; resize: vertical; }
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
:is(input, button, select, textarea, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { cursor: pointer; font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.danger { color: var(--danger); }
.link { width: auto; min-height: 44px; border: 0; background: none; color: var(--accent); padding: 0 10px; font-weight: 500; }
.tall { min-height: 64px; font-size: 18px; font-weight: 600; margin-top: 12px; border-color: var(--accent); color: var(--accent); }

.money { display: flex; align-items: center; position: relative; }
.money .prefix { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.money input { padding-left: 30px; }
.err { display: none; color: var(--danger); font-size: 13px; margin-top: 4px; }
.err:not(:empty) { display: block; }
.errs { margin: 12px 0 0; padding-left: 20px; color: var(--danger); font-size: 14px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(max-content, 1fr); gap: 3px; padding: 3px; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.seg button { min-height: 36px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; color: var(--fg); font-size: 15px; font-weight: 500; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.ratio { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; margin-top: 8px; }
.ratio label { font-size: 13px; color: var(--muted); }
.ratio input { margin-top: 4px; }
.ratio .colon { padding-bottom: 12px; font-weight: 600; color: var(--muted); }
.preview { margin-top: 8px; font-size: 14px; min-height: 20px; }
.static { min-height: 48px; display: flex; align-items: center; padding: 0 12px; border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn-row button { padding: 0 8px; font-size: 15px; }
.file { display: flex; align-items: center; justify-content: center; min-height: 48px; margin-top: 8px; border: 1px dashed var(--border); border-radius: 10px; cursor: pointer; color: var(--muted); font-size: 15px; }
.file:hover { color: var(--fg); }

/* ---------- just added ---------- */
.recent-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.recent-list li { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 8px 6px 8px 16px; border-top: 1px solid var(--border); font-size: 15px; }
.recent-list li:first-child { border-top: 0; }
.rec-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- expenses list ---------- */
.month-nav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; margin-bottom: 12px; }
.month-nav button { width: 44px; min-height: 44px; padding: 0; font-size: 24px; line-height: 1; }
.month-nav h2 { text-align: center; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat small { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.stat { min-width: 0; }
.stat b { display: block; font-size: clamp(14px, 4.4vw, 22px); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.totals .muted { font-size: 13px; margin-top: 8px; }
.day { font-size: 12px; font-weight: 600; color: var(--muted); margin: 16px 0 6px; }
.group { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px; border: 0; border-top: 1px solid var(--border); border-radius: 0; background: transparent; text-align: left; color: inherit; font-weight: 400; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--bg); }
.row.settle { background: var(--tint); }
.row-main { flex: 1; min-width: 0; }
.row .title, .row .meta, .row .amt { display: block; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row-side { text-align: right; white-space: nowrap; }
.row .amt { font-weight: 600; }

/* ---------- settle ---------- */
.center { text-align: center; }
.big { font-size: 22px; font-weight: 600; }
.huge { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; overflow-wrap: anywhere; }

/* ---------- import preview ---------- */
.tbl-wrap { overflow-x: auto; margin-top: 12px; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; font-size: 14px; width: 100%; white-space: nowrap; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); font-size: 12px; }
th.num, td.num { text-align: right; }
tr.bad td { color: var(--danger); }
.summary { font-size: 14px; margin: 10px 0 12px; }

/* ---------- full-screen sections (login, pick who) ---------- */
.screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 0; }
.screen .card { width: 100%; max-width: 360px; margin: 0; padding: 24px; }
.screen h1 { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 16px; }

/* ---------- dialog ---------- */
dialog { background: var(--card); color: var(--fg); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin-bottom: 12px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.actions .primary { grid-column: 1 / -1; }
@media (max-width: 767px) {
  dialog { position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: none; max-height: 90dvh; overflow: auto; border: 0; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
}
@media (min-width: 768px) {
  dialog { width: min(480px, 90vw); max-height: 90vh; overflow: auto; border-radius: 16px; border: 1px solid var(--border); }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 10px 16px;
  background: var(--fg); color: var(--bg); border-radius: 10px; font-size: 14px;
  box-shadow: 0 2px 8px rgb(0 0 0 / .12);
}
@media (min-width: 768px) { #toast { bottom: 24px; } }

[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
