/*
  app.css — finance-helper Mini App styling (bank-app dark look).
  What it does: defines the near-black themed surface, elevated cards (radius 16,
    pad 16), period pill chip, summary card + donut layout, category legend,
    day-grouped transaction rows, debt progress bar, and loading skeletons.
  Inputs: Telegram theme via var(--tg-theme-*) with dark fallbacks; safe-area via
    var(--tg-safe-area-inset-*) / var(--tg-content-safe-area-inset-*). app.js sets
    those vars on :root and swaps state classes (.is-loading / .is-error / .is-empty).
  Outputs: none (pure styling). Semantic colours are the ONLY hardcoded ones:
    #FF3B30 expense, #FF9500 debt (spec §4 — income green intentionally omitted,
    income ring is hidden in expenses-only mode).
*/

:root {
  /* Telegram theme with sensible dark bank-app fallbacks. */
  --bg:        var(--tg-theme-bg-color, #0d0d0f);
  --card:      var(--tg-theme-secondary-bg-color, #1a1a1e);
  --text:      var(--tg-theme-text-color, #f2f2f7);
  --hint:      var(--tg-theme-hint-color, #8e8e93);
  --link:      var(--tg-theme-link-color, #2ea6ff);
  --section:   var(--tg-theme-section-bg-color, #1a1a1e);
  --separator: var(--tg-theme-section-separator-color, rgba(255,255,255,.08));

  /* Hardcoded semantic colours (spec §4). */
  --expense: #FF3B30;
  --debt:    #FF9500;

  /* Safe-area insets (Telegram exposes these; 0 fallback). */
  --sa-top:    var(--tg-safe-area-inset-top, 0px);
  --sa-bottom: var(--tg-safe-area-inset-bottom, 0px);
  --sa-left:   var(--tg-safe-area-inset-left, 0px);
  --sa-right:  var(--tg-safe-area-inset-right, 0px);
  --csa-top:    var(--tg-content-safe-area-inset-top, 0px);
  --csa-bottom: var(--tg-content-safe-area-inset-bottom, 0px);

  --radius:   16px;
  --radius-pill: 20px;
  --pad:      16px;
  --gap:      12px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding:
    calc(var(--sa-top) + var(--csa-top) + 12px)
    calc(var(--sa-right) + 12px)
    calc(var(--sa-bottom) + var(--csa-bottom) + 24px)
    calc(var(--sa-left) + 12px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---------- generic card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: var(--pad);
}

.hint { color: var(--hint); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- period pill chip ---------- */
.period-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}
.period-pill {
  appearance: none;
  border: none;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.period-pill .caret { color: var(--hint); font-size: 12px; }

/* period dropdown (native-ish list) */
.period-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}
.period-menu button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 12px var(--pad);
  border-radius: 10px;
  cursor: pointer;
}
.period-menu button[aria-current="true"] { color: var(--link); font-weight: 600; }
.period-menu button:active { background: rgba(255,255,255,.06); }
/* period accordion: year headers + their collapsible months (Denis 2026-07-18) */
.period-year-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.period-year-head .caret { color: var(--hint); font-size: 12px; }
.period-months { padding-left: 8px; }

/* ---------- summary card (C1) ---------- */
.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pad);
}
.summary .total-label {
  color: var(--hint);
  font-size: 14px;
  margin-bottom: 4px;
}
.summary .total-value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.summary .donut-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  flex: 0 0 auto;
}
.summary .donut-wrap canvas { width: 96px !important; height: 96px !important; }
.summary .donut-fallback {
  display: none;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background:
    conic-gradient(var(--expense) 0 62%, rgba(255,255,255,.08) 62% 100%);
  -webkit-mask: radial-gradient(circle 30px at center, transparent 98%, #000 100%);
          mask: radial-gradient(circle 30px at center, transparent 98%, #000 100%);
}

/* ---------- category breakdown legend (C4) ---------- */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin: 6px 4px 2px;
}
.legend { display: flex; flex-direction: column; }
.legend-item { border-bottom: 1px solid var(--separator); }
.legend-item:last-child,
.legend-rest > .legend-item:last-child { border-bottom: none; }
.legend-row {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}
.legend-row[disabled] { cursor: default; }
.legend-row:active { background: rgba(255,255,255,.04); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.legend-emoji { font-size: 18px; width: 22px; text-align: center; flex: 0 0 auto; }
.legend-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-pct { color: var(--hint); font-size: 14px; min-width: 40px; text-align: right; }
.legend-amt { font-weight: 600; min-width: 74px; text-align: right; }
.legend-caret { color: var(--hint); font-size: 11px; width: 12px; text-align: center; flex: 0 0 auto; }

/* per-category transaction drawer */
.legend-drawer { display: none; padding: 2px 0 10px 42px; }
.legend-item.open .legend-drawer { display: block; }
.legend-txn {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
}
.legend-txn-raw { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-txn-date { flex: 0 0 auto; width: 52px; text-align: right; font-size: 12px; }
.legend-txn-amt { flex: 0 0 auto; min-width: 72px; text-align: right; color: var(--expense); font-weight: 600; white-space: nowrap; }

/* «показать все» collapsed tail of the category list */
.legend-rest { display: none; }
.legend-rest.open { display: block; }

/* ---------- transaction list by day (C3) ---------- */
.day-group { padding: 4px 0 0; }
.day-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 4px 6px;
}
.day-header .day-date { font-weight: 600; font-size: 15px; }
.day-header .day-net { color: var(--expense); font-weight: 600; font-variant-numeric: tabular-nums; }

.txn-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--separator);
}
.txn-row:last-child { border-bottom: none; }
.txn-emoji {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex: 0 0 auto;
}
.txn-body { flex: 1 1 auto; min-width: 0; }
.txn-raw {
  font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.txn-cat { color: var(--hint); font-size: 13px; }
.txn-amt {
  color: var(--expense);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  white-space: nowrap;
}

.show-more {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--link);
  font: inherit;
  font-size: 14px;
  padding: 10px 4px;
  cursor: pointer;
  text-align: left;
}

/* ---------- debt progress card (C5) ---------- */
.debt-card .debt-title { font-weight: 600; margin-bottom: 10px; }
.debt-bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.debt-bar > span {
  display: block;
  height: 100%;
  background: var(--debt);
  border-radius: 4px;
}
.debt-sub { color: var(--hint); font-size: 13px; margin-top: 8px; }

/* ---------- states: loading / error / empty ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,.05);
  border-radius: 8px;
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.sk-line { height: 14px; margin: 8px 0; }
.sk-line.lg { height: 30px; width: 55%; }
.sk-line.sm { width: 40%; }
.sk-donut { width: 96px; height: 96px; border-radius: 50%; flex: 0 0 auto; }

.state-msg {
  text-align: center;
  padding: 40px var(--pad);
  color: var(--hint);
}
.state-msg .state-title { color: var(--text); font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.state-msg .retry {
  appearance: none;
  margin-top: 16px;
  border: none;
  background: var(--card);
  color: var(--link);
  font: inherit;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}
