/* Дашборд Mini App — стили по макету «Дашборд Mini App.dc.html».
   Вся палитра — переменные темы Telegram; свои только два акцента. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.2));
  --acc-exp: #b3663a; /* расходы: тёплый, не красный */
  --acc-inc: #3f7a58; /* доходы и прогресс целей */
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root { --acc-exp: #d98d5f; --acc-inc: #74c092; }
}
:root[data-theme="dark"] { --acc-exp: #d98d5f; --acc-inc: #74c092; }

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", sans-serif;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  max-width: 430px;
  min-width: 320px;
  margin: 0 auto;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }

/* --- Sticky-шапка ---------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg2);
  border-radius: 10px;
  padding: 3px;
}
.segment button {
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-weight: 600;
  padding: 7px 0;
  border-radius: 8px;
  cursor: pointer;
}
.segment button.active { background: var(--btn); color: var(--btn-text); }

.period-row { display: flex; gap: 6px; align-items: center; }
.chips { display: flex; gap: 6px; flex: 1; }
.chips button {
  border: 0;
  background: var(--bg2);
  color: var(--hint);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.chips button.active { background: var(--btn); color: var(--btn-text); }

.month-nav { display: flex; gap: 4px; }
.month-nav button {
  border: 0;
  background: var(--bg2);
  color: var(--text);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.month-nav button:disabled { opacity: 0.35; cursor: default; }

/* --- Карточки и секции ------------------------------------------------ */

.section { margin-top: 18px; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tappable { cursor: pointer; }

/* --- Сводка ----------------------------------------------------------- */

.summary-period { color: var(--hint); font-size: 12px; }
.summary-main {
  font-size: 30px;
  font-weight: 700;
  color: var(--acc-exp);
  margin: 2px 0 4px;
}
.delta-chip {
  display: inline-block;
  background: var(--bg2);
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--hint);
}
.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.summary-cards .card { padding: 10px 12px; }
.mini-label { color: var(--hint); font-size: 11px; }
.mini-amount { font-size: 15px; font-weight: 600; margin-top: 2px; }
.income .mini-amount { color: var(--acc-inc); }
.rest .mini-amount.pos { color: var(--acc-inc); }
.rest .mini-amount.neg { color: var(--acc-exp); }
.summary-detail { color: var(--hint); font-size: 11px; margin-top: 8px; }

/* --- Карточка динамики / спарклайны ---------------------------------- */

.dyn-card { display: flex; align-items: center; gap: 12px; }
.dyn-info { flex: 1; }
.dyn-sub { color: var(--hint); font-size: 11px; margin-top: 2px; }
.chevron { color: var(--hint); font-size: 16px; }
.sparkline { flex-shrink: 0; }
.sparkline path.line { fill: none; stroke: var(--acc-exp); stroke-width: 2; }
.sparkline path.area { fill: var(--acc-exp); opacity: 0.12; stroke: none; }

/* --- Donut и легенда --------------------------------------------------- */

.donut-wrap { display: flex; justify-content: center; padding: 6px 0 10px; }
.donut-center-sum { font-size: 16px; font-weight: 700; fill: var(--text); }
.donut-center-label { font-size: 9px; fill: var(--hint); }

.legend { list-style: none; }
.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border-bottom: 1px solid var(--sep);
}
.legend li:last-child { border-bottom: 0; }
.legend .emoji { width: 22px; text-align: center; flex-shrink: 0; }
.legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  margin: 0 5px;
}
.legend .l-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .l-right { text-align: right; flex-shrink: 0; }
.legend .l-amount { font-weight: 600; }
.legend .l-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--sep);
  margin-top: 3px;
  width: 64px;
  overflow: hidden;
}
.legend .l-bar > i { display: block; height: 100%; border-radius: 2px; }
.legend .l-pct { color: var(--hint); font-size: 11px; width: 34px; text-align: right; flex-shrink: 0; }
.legend .chevron { width: 12px; text-align: right; }

/* --- Тренды ------------------------------------------------------------ */

.trends { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trend-card .t-head { display: flex; gap: 5px; align-items: baseline; }
.trend-card .t-name {
  flex: 1; min-width: 0;
  font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.trend-card .t-amount { font-size: 15px; font-weight: 600; margin: 4px 0 6px; }
.trend-card .t-arrow { font-size: 11px; font-weight: 600; }
.trend-card .t-arrow.up { color: var(--acc-exp); }
.trend-card .t-arrow.down { color: var(--acc-inc); }
.trend-card .t-arrow.flat { color: var(--hint); }

/* --- Цели -------------------------------------------------------------- */

.goal-card { margin-bottom: 8px; }
.goal-head { display: flex; justify-content: space-between; gap: 8px; }
.goal-name { font-weight: 600; }
.goal-deadline { color: var(--hint); font-size: 11px; }
.goal-track {
  height: 6px;
  border-radius: 3px;
  background: var(--sep);
  margin: 8px 0 6px;
  overflow: hidden;
}
.goal-track > i { display: block; height: 100%; background: var(--acc-inc); border-radius: 3px; }
.goal-nums { display: flex; justify-content: space-between; font-size: 12px; }
.goal-nums .pct { color: var(--acc-inc); font-weight: 600; }
.goal-left { color: var(--hint); font-size: 11px; margin-top: 3px; }

/* --- Вложенные экраны --------------------------------------------------- */

.subbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0 10px;
}
.back-btn {
  border: 0;
  background: transparent;
  color: var(--btn);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 4px 4px 0;
}
.subbar h2 { font-size: 16px; }
.screen-sub { color: var(--hint); font-size: 12px; margin-bottom: 12px; }

/* --- Бар-чарт «Динамика» ------------------------------------------------ */

.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  padding: 10px 0 4px;
}
.bar-month { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.bar-pair { display: flex; align-items: flex-end; gap: 2px; height: 110px; }
.bar-pair i { display: block; width: 9px; border-radius: 3px 3px 0 0; min-height: 4px; }
.bar-pair .b-exp { background: var(--acc-exp); }
.bar-pair .b-inc { background: var(--acc-inc); opacity: 0.55; }
.bar-label { font-size: 10px; color: var(--hint); }
.bars.focused .bar-month { opacity: 0.35; }
.bars.focused .bar-month.focus { opacity: 1; }

.focus-card { margin-top: 8px; }
.focus-row { display: flex; justify-content: space-between; margin-top: 4px; }
.open-btn {
  border: 0;
  background: transparent;
  color: var(--btn);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  padding: 4px 0;
}

.month-list { list-style: none; margin-top: 12px; }
.month-list li {
  display: flex;
  align-items: center;
  min-height: 40px;
  gap: 8px;
  border-bottom: 1px solid var(--sep);
  cursor: pointer;
}
.month-list li:last-child { border-bottom: 0; }
.month-list .m-name { flex: 1; }
.month-list .m-exp { font-weight: 600; }
.month-list .m-rest { width: 84px; text-align: right; font-size: 12px; }
.month-list .m-rest.pos { color: var(--acc-inc); }
.month-list .m-rest.neg { color: var(--acc-exp); }

/* --- Состояния ---------------------------------------------------------- */

.empty { text-align: center; padding: 48px 20px; }
.empty .e-icon { font-size: 40px; }
.empty h3 { font-size: 16px; margin: 12px 0 6px; }
.empty p { color: var(--hint); margin-bottom: 18px; }
.primary-btn {
  border: 0;
  background: var(--btn);
  color: var(--btn-text);
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.9; }
}
.skeleton .sk {
  background: var(--bg2);
  border-radius: var(--radius);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
  margin-top: 12px;
}
.skeleton .sk:nth-child(2) { animation-delay: 0.1s; }
.skeleton .sk:nth-child(3) { animation-delay: 0.2s; }
.skeleton .sk:nth-child(4) { animation-delay: 0.3s; }
.skeleton .sk:nth-child(5) { animation-delay: 0.4s; }

.error-note { text-align: center; color: var(--hint); padding: 40px 20px; }
