:root {
  color-scheme: light;
  --navy: #0b172a;
  --navy-2: #13233c;
  --blue: #2d6cdf;
  --teal: #0ea5a8;
  --ink: #182235;
  --muted: #718096;
  --line: #dce4ee;
  --surface: #ffffff;
  --bg: #f2f5f9;
  --soft: #edf3ff;
  --green: #14804a;
  --red: #c83b45;
  --amber: #b86d00;
  --radius: 18px;
  --shadow: 0 12px 34px rgba(11, 23, 42, .09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; max-width: 820px; margin: 0 auto; background: var(--bg); padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: calc(16px + env(safe-area-inset-top)) 18px 14px; color: white; background: linear-gradient(145deg, var(--navy), #17365f); box-shadow: 0 8px 24px rgba(11,23,42,.18); }
.eyebrow { color: #8eb5ff; font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin: 3px 0 0; font-size: 1.55rem; letter-spacing: -.03em; }
h2 { margin: 4px 0 0; font-size: 1.35rem; }
h3 { margin-bottom: 8px; font-size: 1rem; }

.icon-btn { width: 46px; height: 46px; border: 0; border-radius: 15px; background: var(--blue); color: white; font-size: 1.75rem; line-height: 1; box-shadow: 0 8px 20px rgba(45,108,223,.35); }
main { padding: 16px; }

.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.filter-row label, .field { display: grid; gap: 7px; color: var(--muted); font-size: .82rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 13px; background: white; color: var(--ink); padding: 12px 13px; min-height: 46px; outline: none; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(45,108,223,.13); }

.hero-balance { position: relative; overflow: hidden; color: white; background: linear-gradient(135deg, var(--navy-2), #1d4474); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.hero-balance::after { content: ""; position: absolute; width: 180px; height: 180px; right: -75px; top: -90px; border: 28px solid rgba(102,183,255,.13); border-radius: 50%; }
.hero-balance small { color: #b9c8df; font-weight: 700; }
.hero-balance strong { display: block; margin: 8px 0 14px; font-size: clamp(2rem, 10vw, 3.2rem); letter-spacing: -.06em; }
.balance-meta { display: flex; gap: 16px; flex-wrap: wrap; color: #d6e2f3; font-size: .9rem; }
.balance-meta b { color: white; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 20px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; box-shadow: 0 6px 16px rgba(11,23,42,.045); }
.metric span { display: block; color: var(--muted); font-size: .8rem; font-weight: 700; }
.metric strong { display: block; margin-top: 7px; font-size: 1.15rem; }
.metric.danger strong { color: var(--red); }
.metric.good strong { color: var(--green); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 2px 10px; }
.section-head h2 { font-size: 1.05rem; }
.text-btn { border: 0; background: none; color: var(--blue); font-weight: 800; padding: 8px 0; }

.list { display: grid; gap: 10px; }
.record { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; box-shadow: 0 5px 16px rgba(11,23,42,.04); }
.record-top, .record-bottom { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.record-title { font-weight: 850; line-height: 1.25; }
.record-sub { color: var(--muted); font-size: .86rem; margin-top: 4px; }
.amount { white-space: nowrap; font-weight: 850; }
.record-bottom { margin-top: 13px; align-items: center; color: var(--muted); font-size: .82rem; }
.status { padding: 5px 9px; border-radius: 999px; background: var(--soft); color: var(--blue); font-weight: 800; }
.status.paid { background: #e7f6ee; color: var(--green); }
.status.unpaid { background: #fff0ef; color: var(--red); }
.kebab { border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; padding: 5px 8px; }

.empty { text-align: center; background: white; border: 1px dashed #becadd; border-radius: 22px; padding: 30px 20px; color: var(--muted); }
.empty-mark { width: 58px; height: 58px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 18px; background: var(--soft); color: var(--blue); font-size: 1.55rem; font-weight: 900; }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

.bottom-nav { position: fixed; z-index: 30; left: 50%; bottom: 0; width: min(820px, 100%); transform: translateX(-50%); display: grid; grid-template-columns: repeat(5, 1fr); padding: 9px 8px calc(9px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); border-top: 1px solid var(--line); backdrop-filter: blur(16px); }
.nav-item { border: 0; background: transparent; color: #7c899b; display: grid; justify-items: center; gap: 4px; padding: 3px 2px; }
.nav-item span { font-size: 1.25rem; line-height: 1; }
.nav-item b { font-size: .67rem; }
.nav-item.active { color: var(--blue); }

.sheet-dialog { width: min(100%, 820px); max-width: 820px; max-height: 92vh; margin: auto auto 0; border: 0; border-radius: 26px 26px 0 0; padding: 0; background: white; color: var(--ink); }
.sheet-dialog::backdrop, .confirm-dialog::backdrop { background: rgba(3,12,25,.57); backdrop-filter: blur(3px); }
.sheet-dialog form { padding: 20px 18px calc(22px + env(safe-area-inset-bottom)); overflow: auto; max-height: 92vh; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.dialog-head .eyebrow { color: var(--blue); }
.close-btn { border: 0; background: var(--bg); border-radius: 12px; width: 40px; height: 40px; font-size: 1.5rem; }
.form-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 10px; }
.field.full { grid-column: 1 / -1; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.btn { min-height: 48px; border-radius: 14px; border: 0; font-weight: 850; padding: 12px 16px; }
.btn.primary { background: var(--blue); color: white; }
.btn.secondary { background: #edf1f6; color: var(--ink); }
.btn.danger { background: var(--red); color: white; }
.btn.block { width: 100%; }

.confirm-dialog { border: 0; border-radius: 22px; max-width: 360px; padding: 22px; }
.confirm-dialog p { color: var(--muted); }

.settings-grid { display: grid; gap: 12px; }
.settings-card { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; }
.settings-card p { color: var(--muted); font-size: .88rem; margin-bottom: 14px; }
.settings-actions { display: grid; gap: 8px; }
.mini-list { display: grid; gap: 8px; margin-top: 12px; }
.mini-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.mini-item small { color: var(--muted); }

.tax-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tax-grid label { display: grid; gap: 5px; color: var(--muted); font-size: .75rem; font-weight: 750; }
.tax-grid select { padding: 8px; min-height: 40px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--navy); color: white; border-radius: 12px; padding: 11px 15px; opacity: 0; pointer-events: none; transition: .22s ease; box-shadow: var(--shadow); font-weight: 700; font-size: .88rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.privacy-note { padding: 12px 14px; border-radius: 14px; background: #ecf8f7; color: #206365; font-size: .84rem; line-height: 1.45; }
.red { color: var(--red); }
[hidden] { display: none !important; }
button:disabled { opacity: .55; cursor: wait; }
.auth-card { max-width: 440px; margin: 32px auto; padding: 26px; background: white; border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card .eyebrow { color: var(--blue); }
.auth-card h2 { margin: 12px 0; font-size: 1.7rem; }
.auth-card p { line-height: 1.5; color: #52627a; }
.auth-card form { display: grid; gap: 18px; }
.auth-card .field { font-size: 14px; }
.auth-card input { font-size: 16px; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-top: 16px; }
#authMessage { margin: 0; font-size: 14px; }
.sync-status { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; line-height: 1.5; margin-bottom: 16px; color: #206365; }
.sync-warning { background: #fff2d8; color: #6e4400; padding: 12px; border-radius: 14px; }
.sync-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.settings-card { overflow-wrap: anywhere; }

@media (min-width: 700px) {
  main { padding: 24px; }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .sheet-dialog { margin: auto; border-radius: 26px; }
  .form-fields { gap: 15px; }
}
