/* Clearhead AI: mobile-first, one hand, 44pt targets, follows the system light/dark setting. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #15171a;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --done: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --overdue: #dc2626;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1b1d21;
    --surface-2: #25282d;
    --text: #eceef1;
    --muted: #9aa1ab;
    --line: #2c3036;
    --accent: #4f8cff;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- boot ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-mark { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 34px; font-weight: 700; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; padding: calc(var(--safe-top) + 8px) 0 calc(var(--nav-h) + var(--safe-bottom) + 84px); }
.page { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 8px; }
.page-header h1 { font-size: 30px; line-height: 1.1; margin: 0; font-weight: 750; letter-spacing: -.02em; }
.page-header .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.back { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); background: none; border: 0; padding: 0; font-size: 17px; cursor: pointer; }

.offline-pill { position: fixed; top: calc(var(--safe-top) + 6px); left: 50%; transform: translateX(-50%); z-index: 30; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: 13px; box-shadow: var(--shadow); }

/* ---------- bottom nav ---------- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); height: calc(var(--nav-h) + var(--safe-bottom)); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
.nav a .ico { font-size: 21px; line-height: 1; }
.nav a.active { color: var(--accent); }
.nav .dot { position: absolute; top: 6px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; display: grid; place-items: center; }

.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); z-index: 21; width: 58px; height: 58px; border-radius: 29px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 32px; line-height: 1; box-shadow: 0 6px 20px rgba(37,99,235,.35); cursor: pointer; }

/* ---------- cards and rows ---------- */
.section { margin: 18px 0 8px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin: 0 4px 6px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card + .card { margin-top: 10px; }
.card-pad { padding: 14px 16px; }

.row-wrap { position: relative; overflow: hidden; }
.row-wrap::before, .row-wrap::after { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; padding: 0 20px; color: #fff; font-weight: 650; z-index: 0; }
.row-wrap::before { content: "✓ Done"; left: 0; right: 50%; background: var(--done); }
.row-wrap::after { content: "Snooze ⏾"; right: 0; left: 50%; justify-content: flex-end; background: var(--warn); }
.row { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); touch-action: pan-y; }
.card > .row-wrap:last-child .row, .card > .row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; cursor: pointer; }
.row-title { font-size: 16px; overflow-wrap: anywhere; }
.row-title.done { color: var(--muted); text-decoration: line-through; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.row-meta .overdue { color: var(--overdue); font-weight: 600; }
.row-meta .today { color: var(--accent); font-weight: 600; }
.row-actions { display: flex; gap: 4px; }

.check { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0; color: transparent; font-size: 15px; }
.check:before { content: ""; position: absolute; width: 44px; height: 44px; }
.check.on { background: var(--done); border-color: var(--done); color: #fff; }
.check.big { width: 32px; height: 32px; border-radius: 9px; }
.check.p3 { border-color: var(--danger); }
.check.p2 { border-color: var(--warn); }

.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; font-size: 18px; cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }

.top3 .row { min-height: 64px; }
.top3 .rank { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: 13px; font-weight: 700; }

.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); color: var(--text); font-size: 15px; cursor: pointer; }
.chip.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.small { min-height: 30px; padding: 0 10px; font-size: 13px; box-shadow: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .big { font-size: 40px; margin-bottom: 6px; }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); margin: 10px 0; font-size: 14px; }
.banner.warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); }
.banner .x { margin-left: auto; }

/* ---------- forms ---------- */
.field { display: block; margin: 0 0 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 6px; font-weight: 600; }
.input, select.input, textarea.input { width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 10px 12px; font-size: 16px; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea.input { min-height: 96px; resize: vertical; }
.input.title { font-size: 20px; font-weight: 600; border: 0; background: transparent; padding: 6px 0; min-height: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 16px; cursor: pointer; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: .5; }
.error { color: var(--danger); font-size: 14px; margin: 8px 2px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 2px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.kv { display: flex; justify-content: space-between; align-items: center; min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.kv:last-child { border-bottom: 0; }
.kv .v { color: var(--muted); text-align: right; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 10px; user-select: all; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; animation: fade .15s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg); border-radius: 18px 18px 0 0; padding: 10px 16px calc(var(--safe-bottom) + 16px); max-height: 92vh; overflow-y: auto; animation: rise .2s ease; max-width: 640px; margin: 0 auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { font-size: 20px; margin: 4px 0 12px; }
.sheet-actions { display: grid; gap: 8px; }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.quick-add { display: flex; gap: 8px; }
.quick-add .input { flex: 1; }
.parse-preview { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 2px 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-bottom) + 86px); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; display: flex; gap: 14px; align-items: center; animation: rise .2s ease; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; min-height: 32px; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.totals div { padding: 12px 4px; }
.totals .n { font-size: 20px; font-weight: 750; }
.totals .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.search { margin: 4px 0 10px; }

/* ---------- budget ---------- */
.budget-hero .hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.budget-hero .n { font-size: 30px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.pill { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 650; white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--done) 16%, var(--surface)); color: var(--done); }
.pill.watch { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.pill.over { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); }
.pill.none { background: var(--surface-2); color: var(--muted); }
.status-ok { color: var(--done); font-weight: 600; }
.status-watch { color: var(--warn); font-weight: 600; }
.status-over { color: var(--danger); font-weight: 600; }
.bbar { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2); overflow: visible; }
.bbar.thin { height: 6px; border-radius: 3px; margin: 6px 0 2px; }
.bbar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--done); transition: width .25s ease; }
.bbar-fill.watch { background: var(--warn); }
.bbar-fill.over { background: var(--danger); }
.bbar-fill.none { background: var(--muted); }
.bbar-tick { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .55; border-radius: 1px; }
.cat-row { align-items: flex-start; }
.cat-icon { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; color: #fff; margin-top: 2px; }
.cat-line { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cat-amount { color: var(--muted); font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount-input { display: flex; align-items: center; gap: 4px; font-size: 40px; font-weight: 700; margin: 4px 0 14px; }
.amount-input span { color: var(--muted); }
.amount-input input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 40px; font-weight: 700; outline: none; font-variant-numeric: tabular-nums; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 12px 16px calc(var(--safe-bottom) + 12px); background: #fee2e2; color: #7f1d1d; z-index: 1000; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ---------- bank sync ---------- */
.btn.small { min-height: 40px; padding: 0 14px; font-size: 15px; }
.dup { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dup:last-child { border-bottom: 0; }
.dup-line { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bank-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.bank-head b { font-size: 17px; }
.status-warn { color: var(--warn); font-weight: 600; }
.money-total { display: flex; gap: 18px; flex-wrap: wrap; }
.money-total .n { font-size: 26px; font-weight: 750; letter-spacing: -.02em; }

/* ---------- Add to Home Screen guide ---------- */
.install-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.install-steps li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; line-height: 1.35; }
.install-steps .step-icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--surface); color: var(--accent); border: 1px solid var(--line); font-weight: 700; }

/* Sheet header: title plus an always-visible close button */
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
.sheet-head h2 { margin: 4px 0; }
.sheet-close { min-width: 44px; min-height: 44px; font-size: 18px; color: var(--muted); }

/* ---------- Smart setup ---------- */
.smart-row { gap: 12px; align-items: center; }
.smart-row input[type=checkbox], .smart-row input[type=radio] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.amount-mini { width: 96px; min-height: 40px; text-align: right; flex: none; }
.smart-total { display: grid; gap: 6px; margin-top: 10px; }
.status-ok { color: var(--done); }
.status-over { color: var(--danger); }
.status-watch { color: var(--warn); font-weight: 600; }
