:root {
  --paper: #f3f6f5;
  --ink: #0e1a16;
  --muted: #5b6b66;
  --line: rgba(6, 37, 31, 0.08);
  --card: #ffffff;
  --forest: #06251f;
  --forest-2: #0d3d34;
  --mint: #1f8a70;
  --mint-bright: #3ddc97;
  --gold: #1f8a70;
  --gold-soft: #e4f6ef;
  --coral: #b42318;
  --ok: #0f766e;
  --shadow: 0 1px 2px rgba(6, 37, 31, 0.04), 0 12px 32px rgba(6, 37, 31, 0.05);
  --radius: 20px;
  --nav-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --max: 430px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 420px at 50% -80px, #d7efe6 0%, transparent 58%),
    var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(var(--max), 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 18px 18px calc(var(--nav-h) + var(--safe-b) + 18px);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.brand img, .mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
}
.mark {
  background: var(--forest);
  color: var(--mint-bright);
  display: grid;
  place-items: center;
  font-family: "Sora", sans-serif;
  font-weight: 600;
  font-size: 16px;
}
.brand h1 {
  font-family: "Sora", sans-serif;
  font-size: 1.05rem;
  margin: 0;
  letter-spacing: -0.04em;
  font-weight: 600;
}
.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

select, input, textarea, button {
  font: inherit;
}
.month-pick {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.hero {
  background:
    linear-gradient(180deg, rgba(61, 220, 151, 0.12), transparent 42%),
    linear-gradient(160deg, #08332b, #06251f 72%);
  color: #edf8f3;
  border-radius: 28px;
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -48px;
  top: -60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(61, 220, 151, 0.22), transparent 70%);
  pointer-events: none;
}
.hero .kicker {
  opacity: 0.68;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 500;
}
.hero .big {
  font-family: "Sora", sans-serif;
  font-size: 2.15rem;
  margin: 8px 0 6px;
  letter-spacing: -0.04em;
  font-weight: 600;
}
.hero .sub { opacity: 0.72; font-size: 0.86rem; line-height: 1.4; }
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}
.hero-grid div {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 12px 14px;
}
.hero-grid span { display: block; font-size: 0.68rem; opacity: 0.62; letter-spacing: 0.04em; text-transform: uppercase; }
.hero-grid strong { font-size: 0.98rem; font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card.wide { grid-column: 1 / -1; }
.card h3 {
  margin: 0 0 10px;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.card .val {
  font-family: "Sora", sans-serif;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  font-weight: 600;
}
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--coral); }

.progress {
  height: 6px;
  background: #e8efec;
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0;
}
.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--mint-bright), var(--mint));
}
.progress > i.over {
  background: linear-gradient(90deg, #e08b7a, var(--coral));
}
.alert {
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 0.92rem;
  font-weight: 500;
}
.alert.warn {
  background: #fff4e5;
  color: #9a6700;
}
.alert.danger {
  background: #f8e6e4;
  color: var(--coral);
}
.bars { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.bar-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.86rem;
}
.bar {
  height: 10px;
  background: #e8efec;
  border-radius: 99px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--mint-bright), var(--mint));
}
.bar i.over { background: var(--coral); }
.bar-row em { font-style: normal; font-variant-numeric: tabular-nums; color: var(--muted); }
.year-bars {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
  height: 120px;
  align-items: end;
  margin-top: 8px;
}
.year-col { display: flex; flex-direction: column; align-items: center; height: 100%; }
.year-stack {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}
.year-stack b, .year-stack i {
  display: block;
  width: 50%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}
.year-stack b { background: var(--mint); }
.year-stack i { background: #c45c3e; opacity: 0.85; }
.year-col small { font-size: 0.62rem; color: var(--muted); margin-top: 4px; }
.chart-key { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.key.in { background: var(--mint); }
.key.out { background: #c45c3e; }

.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.list { display: flex; flex-direction: column; gap: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .btn, .tab {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: #e8efec;
  color: var(--ink);
  font-weight: 500;
}
.chip.active, .tab.active {
  background: var(--forest);
  color: #edf8f3;
}
.btn.primary {
  background: var(--forest);
  color: #edf8f3;
}
.btn.gold { background: var(--mint); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: #f8e6e4; color: var(--coral); }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 16px; border-radius: 14px; font-weight: 600; }
button { cursor: pointer; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
input[type="text"], input[type="number"], input[type="date"], input[type="month"], textarea, select.field {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 138, 112, 0.28);
  border-color: var(--mint);
}

.nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(var(--max), 100%);
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 6px calc(10px + var(--safe-b));
  z-index: 20;
}
.nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: center;
  padding: 4px 0;
}
.nav a.add-link { color: transparent; font-size: 0; }
.nav a.active { color: var(--forest); font-weight: 650; }
.nav svg { display: block; margin: 0 auto 3px; }
.nav .add {
  width: 48px;
  height: 48px;
  margin: -20px auto 0;
  border-radius: 50%;
  background: var(--forest);
  color: var(--mint-bright);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(6, 37, 31, 0.28);
}

.hidden { display: none !important; }
.section-title {
  font-family: "Sora", sans-serif;
  font-size: 1.28rem;
  margin: 4px 0 14px;
  letter-spacing: -0.04em;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.tx {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.tx .ico {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--gold-soft);
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--mint);
}
.tx .amt.in { color: var(--ok); font-weight: 600; }
.tx .amt.out { color: var(--coral); font-weight: 600; }

.empty {
  text-align: center;
  padding: 24px 8px;
  color: var(--muted);
}

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(6, 21, 18, 0.48);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet .panel {
  width: min(var(--max), 100%);
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(22px + var(--safe-b));
  max-height: 92dvh;
  overflow: auto;
}
.sr-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.scan-card h3 { margin-top: 0; }
.scan-drop {
  position: relative;
  border: 1px dashed rgba(31, 138, 112, 0.45);
  background: #eef7f3;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
  text-align: center;
}
.scan-drop.compact { padding: 12px; }
.scan-drop input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.scan-preview {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 12px;
}
.scan-row {
  display: grid;
  grid-template-columns: auto 1fr 90px;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.scan-row select { grid-column: 2 / -1; }
.scan-keep {
  flex-direction: row !important;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}
.scan-sum {
  font-family: "Sora", sans-serif;
  font-weight: 600;
  margin: 8px 0 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.table th, .table td {
  text-align: left;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.kind {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: #e8efec;
  text-transform: capitalize;
}
.kind.cash { background: #dcefe8; }
.kind.budget { background: var(--gold-soft); }
.kind.sinking { background: #f8e6e4; }

@media (min-width: 800px) {
  :root { --max: 920px; }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .card.wide { grid-column: span 2; }
  .hero { grid-column: 1 / -1; }
}

body.locked .app,
body.locked .nav { display: none; }
.gate {
  display: none;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.locked .gate { display: flex !important; }
.gate-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-card img {
  width: 56px;
  height: 56px;
  border-radius: 16px;
}
.gate-card h1 {
  font-family: "Sora", sans-serif;
  margin: 14px 0 8px;
  letter-spacing: -0.04em;
}
.gate-card p {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0 0 20px;
}
.gate-card .form { text-align: left; }
.auth-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}
.text-link {
  background: none;
  border: 0;
  color: var(--mint);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
#login-hint { margin: 0 0 10px; }
input[name="code"] {
  letter-spacing: 0.28em;
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}

