/* «Лови» — спокойный финтех × cozy-island. Тёмная/светлая тема Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #16171a);
  --card: var(--tg-theme-secondary-bg-color, #1f2026);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #5b8def);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --green: #34c759; --yellow: #ff9500; --red: #ff375f; --teal: #2dd4bf;
  --radius: 16px;
}
* { 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, BlinkMacSystemFont, "SF Pro", "Segoe UI", Roboto, sans-serif;
  font-size: 16px; overscroll-behavior-y: none;
}
body { padding-bottom: 96px; }
.hidden { display: none !important; }

/* Шапка */
#app-header {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center;
  justify-content: space-between; padding: 12px 16px;
  background: var(--bg); border-bottom: 1px solid rgba(255,255,255,.06);
}
.hdr-logo { font-weight: 700; font-size: 18px; }
.hdr-right { display: flex; align-items: center; gap: 8px; }
.chip {
  background: var(--card); border-radius: 999px; padding: 5px 10px; font-size: 13px;
  font-weight: 600; white-space: nowrap;
}
.icon-btn {
  background: var(--card); border: none; color: var(--text); width: 34px; height: 34px;
  border-radius: 10px; font-size: 16px; cursor: pointer;
}

#app-main { padding: 16px; max-width: 520px; margin: 0 auto; }
.screen-title { font-size: 22px; margin: 4px 0 14px; }

/* Кольцо дня */
.day-ring-wrap { display: flex; flex-direction: column; align-items: center; margin: 8px 0 14px; }
#day-ring { display: flex; justify-content: center; }
.level-line { margin-top: 8px; color: var(--hint); font-size: 13px; font-weight: 600; }
.ring-sub { font-size: 11px; color: var(--hint); }

/* Реакция бота */
.reaction {
  text-align: center; min-height: 22px; font-style: italic; color: var(--text);
  margin-bottom: 14px; font-size: 15px; transition: opacity .2s; opacity: 0;
}
.reaction.show { opacity: 1; }

/* Пресет-плитки */
.presets-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 16px; }
.preset-tile {
  flex: 0 0 auto; background: var(--card); border: none; color: var(--text);
  border-radius: 14px; padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px;
}
.preset-tile .pt-emoji { font-size: 22px; }
.preset-tile .pt-amount { color: var(--hint); font-size: 12px; }
.preset-tile:active { transform: scale(.94); }

/* Лента дня */
.today-head { display: flex; justify-content: space-between; align-items: baseline;
  color: var(--hint); font-size: 13px; margin-bottom: 8px; padding: 0 2px; }
#today-total { font-weight: 700; color: var(--text); font-size: 15px; }
.feed { display: flex; flex-direction: column; gap: 8px; }
.tx-card {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: 14px; padding: 12px 14px;
}
.tx-emoji {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 20px; flex: 0 0 38px;
}
.tx-body { flex: 1; min-width: 0; }
.tx-title { font-weight: 600; font-size: 15px; }
.tx-sub { color: var(--hint); font-size: 12px; }
.tx-amount { font-weight: 700; font-size: 16px; white-space: nowrap; }
.tx-del { background: none; border: none; color: var(--hint); font-size: 16px; cursor: pointer; padding: 4px; }
.tx-card.nospend { justify-content: center; color: var(--teal); font-weight: 700; }
.feed-empty { text-align: center; color: var(--hint); padding: 24px 0; }

.nospend-btn {
  width: 100%; margin-top: 16px; background: transparent; border: 1px dashed var(--teal);
  color: var(--teal); border-radius: 14px; padding: 14px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.nospend-btn:active { background: rgba(45,212,191,.1); }

/* Карточки общих экранов */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-title { font-weight: 700; font-size: 15px; margin-bottom: 12px; }
.wide-btn {
  width: 100%; background: var(--accent); color: var(--accent-text); border: none;
  border-radius: 14px; padding: 15px; font-size: 16px; font-weight: 700; cursor: pointer; margin-top: 4px;
}
.wide-btn.ghost { background: var(--card); color: var(--text); }
.wide-btn.small { padding: 11px; font-size: 14px; }
.wide-btn:active { transform: scale(.98); }

/* Бар-чарты категорий */
.catbar { margin-bottom: 10px; }
.catbar-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.catbar-track { height: 8px; background: rgba(255,255,255,.08); border-radius: 999px; overflow: hidden; }
.catbar-fill { height: 100%; border-radius: 999px; }

/* Конверты */
.envelope { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.env-ring { flex: 0 0 auto; }
.env-body { flex: 1; min-width: 0; }
.env-title { font-weight: 600; font-size: 14px; }
.env-sub { color: var(--hint); font-size: 12px; }
.env-over { color: var(--red); }

/* Инсайты */
#insights-card .ins-msg { font-size: 14px; margin-bottom: 6px; }
#insights-card .ins-msg:last-child { margin-bottom: 0; }

/* Управление категориями */
.cat-manage-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.cat-manage-row:last-child { border-bottom: none; }
.cat-manage-row .cm-emoji { font-size: 20px; }
.cat-manage-row .cm-title { flex: 1; font-size: 15px; }
.cat-manage-row .cm-kind { color: var(--hint); font-size: 12px; }
.cat-manage-row .cm-del { background: none; border: none; color: var(--red); cursor: pointer; font-size: 16px; padding: 4px; }

/* Сегменты / инпуты */
.seg { display: flex; gap: 8px; }
.seg-btn { flex: 1; background: rgba(255,255,255,.06); border: none; color: var(--text);
  border-radius: 12px; padding: 12px 6px; font-size: 13px; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: var(--accent-text); }
.inp {
  width: 100%; background: rgba(255,255,255,.06); border: 1px solid transparent; color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 16px; margin-top: 8px;
}
.inp:focus { outline: none; border-color: var(--accent); }
.inp-sm { width: 80px; }
.row-2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.lbl { color: var(--hint); font-size: 14px; }
.hint { color: var(--hint); font-size: 12px; margin-top: 8px; }

.preset-manage-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.preset-manage-row .pm-emoji { font-size: 20px; }
.preset-manage-row .pm-title { flex: 1; }
.preset-manage-row .pm-amount { color: var(--hint); }
.preset-manage-row .pm-del { background: none; border: none; color: var(--red); cursor: pointer; font-size: 16px; }

/* Нижние вкладки */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex;
  background: var(--bg); border-top: 1px solid rgba(255,255,255,.07);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--hint); padding: 8px 0 10px;
  font-size: 20px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 11px; }
.tab.active { color: var(--accent); }

/* FAB */
#fab {
  position: fixed; right: 18px; bottom: 76px; z-index: 31; width: 58px; height: 58px;
  border-radius: 50%; background: var(--accent); color: var(--accent-text); border: none;
  font-size: 30px; font-weight: 300; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
#fab:active { transform: scale(.92); }

/* Оверлей ввода */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; }
.add-sheet {
  width: 100%; max-width: 520px; margin: 0 auto; background: var(--bg);
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
.add-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 10px; }
.amount-hero { text-align: center; font-size: 46px; font-weight: 800; margin: 6px 0 14px; }
.amount-hero .cur { font-size: 24px; color: var(--hint); margin-left: 6px; }
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.cat-chip {
  background: rgba(255,255,255,.06); border: 1px solid transparent; color: var(--text);
  border-radius: 999px; padding: 8px 12px; font-size: 14px; cursor: pointer;
}
.cat-chip.active { border-color: var(--accent); background: rgba(91,141,239,.18); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.np-key {
  background: var(--card); border: none; color: var(--text); border-radius: 12px;
  padding: 16px 0; font-size: 22px; font-weight: 600; cursor: pointer;
}
.np-key:active { background: var(--accent); color: var(--accent-text); }
.add-actions { display: flex; flex-direction: column; gap: 8px; }

/* ===== Переиспользуемые компоненты HLui ===== */
/* Кольцо */
.ring { position: relative; display: inline-grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring-bg { stroke: rgba(255,255,255,.1); }
.ring-fg { transition: stroke-dashoffset .5s ease, stroke .3s; stroke-linecap: round; }
.ring-check { position: absolute; font-weight: 700; font-size: 18px; }
#day-ring .ring-check { font-size: 15px; }

/* Тост */
#toast {
  position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); z-index: 60;
  background: #2c2d34; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px;
  transition: opacity .2s; display: flex; align-items: center; gap: 12px; max-width: 90%;
}
.toast-action { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; }

/* Календарь-heatmap */
.cal { overflow-x: auto; }
.cal-months { display: flex; }
.cal-corner { width: 22px; flex: 0 0 22px; }
.cal-month { flex: 0 0 13px; font-size: 9px; color: var(--hint); white-space: nowrap; }
.cal-body { display: flex; }
.cal-weekdays { display: flex; flex-direction: column; }
.cal-wd { height: 13px; font-size: 9px; color: var(--hint); width: 22px; }
.cal-grid { display: flex; gap: 2px; }
.cal-col { display: flex; flex-direction: column; gap: 2px; }
.hm-cell { width: 11px; height: 11px; border-radius: 2px; background: rgba(255,255,255,.06); }
.hm-cell.nospend { box-shadow: inset 0 0 0 1px var(--teal); }
.cal-caption { color: var(--hint); font-size: 11px; margin-top: 8px; }

/* Конфетти */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
.confetti-piece {
  position: absolute; width: 8px; height: 8px; border-radius: 2px;
  animation: confetti-fly 1s ease-out forwards;
}
@keyframes confetti-fly {
  to { transform: translate(var(--dx), var(--dy)) rotate(360deg); opacity: 0; }
}

/* Празднование */
#celebrate {
  position: fixed; inset: 0; z-index: 65; display: grid; place-content: center; text-align: center;
  background: rgba(0,0,0,.55); opacity: 0; transition: opacity .25s;
}
#celebrate.show { opacity: 1; }
.celebrate-emoji { font-size: 64px; }
.celebrate-streak { font-size: 22px; font-weight: 800; margin: 6px 0; }
.celebrate-num { color: var(--yellow); }
.celebrate-text { color: var(--hint); }

/* Тренд-бары (charts.js рисует .bar-col/.bar) */
#trend-chart { display: flex; align-items: flex-end; gap: 6px; height: 100px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar-val { font-size: 10px; color: var(--hint); }
.bar { width: 70%; min-height: 3px; background: var(--accent); border-radius: 6px 6px 0 0; }
.bar-label { font-size: 10px; color: var(--hint); }
