/* Палитра: validated dark-mode reference (dataviz) */
:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --blue: #3987e5;
  --green: #0ca30c;
  --accent: var(--blue);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { background: var(--bg); }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }

/* ---- заглушка вне Telegram ---- */
#notTelegram { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.nt-box { text-align: center; color: var(--ink-2); line-height: 1.5; }
.nt-emoji { font-size: 40px; margin-bottom: 12px; }

/* ---- hero ---- */
.hero { padding: 20px 4px 18px; }
.hero-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.hero-value { font-size: 40px; font-weight: 700; letter-spacing: -0.5px; }
.hero-sub { margin-top: 6px; font-size: 13px; color: var(--ink-2); }
.hero-sub .up { color: var(--green); }

/* ---- карточки ---- */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
}
.card:active { opacity: 0.8; }
.card.wide { grid-column: 1 / -1; }
.card-label { font-size: 12px; color: var(--muted); }
.card-value { font-size: 20px; font-weight: 650; }
.card-sub { font-size: 13px; color: var(--ink-2); font-weight: 400; }
.card-hint { font-size: 11px; color: var(--muted); }

/* ---- панели ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-top: 10px;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 8px; }
.panel h2 { font-size: 14px; font-weight: 600; }
.panel-note { font-size: 12px; color: var(--muted); text-align: right; }

/* ---- линейный график ---- */
.line-chart { position: relative; height: 170px; }
.line-chart svg { display: block; width: 100%; height: 100%; }
.line-chart .empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; text-align: center; line-height: 1.5;
}
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font-size: 12px; color: var(--ink);
  pointer-events: none; white-space: nowrap;
}
.chart-tip small { color: var(--muted); display: block; font-size: 10px; }

/* ---- монеты ---- */
.coins { margin-top: 10px; border-top: 1px solid var(--grid); padding-top: 8px; }
.coin-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.coin-row .name { color: var(--ink-2); }
.coin-row .name b { color: var(--ink); font-weight: 600; }
.coin-row .usd { font-variant-numeric: tabular-nums; }

/* ---- бары категорий ---- */
.cat-row { margin-bottom: 10px; }
.cat-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.cat-head .name { color: var(--ink-2); text-transform: capitalize; }
.cat-head .val { color: var(--ink); font-variant-numeric: tabular-nums; }
.cat-track { height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; }
.cat-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.cat-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* ---- операции ---- */
.tx-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.tx-row:last-child { border-bottom: none; }
.tx-main { flex: 1; min-width: 0; }
.tx-cat { font-size: 14px; text-transform: capitalize; }
.tx-note { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-right { text-align: right; }
.tx-amount { font-size: 14px; font-variant-numeric: tabular-nums; }
.tx-amount.income { color: var(--green); }
.tx-date { font-size: 11px; color: var(--muted); }
.tx-del {
  background: none; border: none; color: var(--muted); font-size: 16px;
  padding: 4px 6px; cursor: pointer;
}

/* ---- FAB ---- */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.fab:active { transform: scale(0.95); }
.bottom-pad { height: 70px; }

/* ---- шторки ---- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
  max-width: 560px; margin: 0 auto;
}
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--axis); margin: 2px auto 4px; }
.sheet h3 { font-size: 16px; }

.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg-btn {
  flex: 1; padding: 8px; border: none; background: none; color: var(--muted);
  font-size: 14px; border-radius: 8px; cursor: pointer;
}
.seg-btn.active { background: var(--surface); color: var(--ink); font-weight: 600; }

.input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font-size: 15px; color: var(--ink); width: 100%;
}
.input:focus { outline: none; border-color: var(--accent); }
.input.amount { font-size: 24px; font-weight: 650; text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--bg); color: var(--ink-2);
  border-radius: 16px; padding: 6px 11px; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  padding: 13px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.primary:active { opacity: 0.85; }
