/* ШАГО — мини-приложение. Цвета по умолчанию ниже — запасной вариант для разработки без
   Telegram; внутри Telegram их на лету переопределяет app.js из Telegram.WebApp.themeParams
   (инлайн-стиль на :root сильнее любого правила файла). data-theme="dark" на <html> —
   из Telegram.WebApp.colorScheme; media-запрос — запасной вариант по теме системы. */

:root {
  color-scheme: light;
  --tg-bg: #ffffff;
  --tg-text: #0b0b0d;
  --tg-hint: #8b8d97;
  --tg-section-bg: #f5f5f7;
  --tg-secondary-bg: #efeff3;
  --tg-separator: rgba(11, 11, 13, 0.09);

  --accent: #128c86;
  --accent-ink: #ffffff;
  --gold: #f2a33b;
  --gold-ink: #2b1700;

  --status-good: #0ca30c;
  --status-critical: #d03b3b;

  --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100;
  --cat-5: #e87ba4; --cat-6: #008300; --cat-7: #4a3aa7; --cat-other: #898781;

  --dops-bg: #0d1117; --dops-card: #131a22; --dops-border: #21262d;
  --dops-text: #e6edf3; --dops-muted: #8b949e;
  --dops-green: #3fb950; --dops-amber: #d29922; --dops-red: #f85149;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --radius: 14px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --tg-bg: #17212b;
    --tg-text: #f1f3f5;
    --tg-hint: #8d98a3;
    --tg-section-bg: #1f2a36;
    --tg-secondary-bg: #0e151c;
    --tg-separator: rgba(255, 255, 255, 0.09);
    --accent: #35b8ae;
    --accent-ink: #06201e;
    --gold: #f2b35c;
    --gold-ink: #2b1700;
    --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
    --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-other: #8b949e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --tg-bg: #17212b;
  --tg-text: #f1f3f5;
  --tg-hint: #8d98a3;
  --tg-section-bg: #1f2a36;
  --tg-secondary-bg: #0e151c;
  --tg-separator: rgba(255, 255, 255, 0.09);
  --accent: #35b8ae;
  --accent-ink: #06201e;
  --gold: #f2b35c;
  --gold-ink: #2b1700;
  --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
  --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-other: #8b949e;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font-family: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.content {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + 24px);
}

.screen { display: none; max-width: 480px; margin: 0 auto; }
.screen.active { display: block; }

.muted { color: var(--tg-hint); }
.center { text-align: center; }
.pad { padding: 32px 0; }

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--tg-hint);
  margin: 22px 2px 8px;
}
.section-title:first-child { margin-top: 0; }

.page-title { font-size: 22px; font-weight: 700; margin: 2px 0 16px; }

/* ── главная ── */
.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 600; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.greeting { font-size: 13px; color: var(--tg-hint); }
.name { font-size: 18px; font-weight: 700; }

.card {
  background: var(--tg-section-bg);
  border-radius: var(--radius);
  padding: 16px;
}

.weather-card {
  background: linear-gradient(135deg, var(--accent) 0%, var(--gold) 100%);
  color: #fff;
  min-height: 92px;
  display: flex;
  align-items: center;
}
.weather-main { display: flex; align-items: center; gap: 12px; }
.weather-icon { font-size: 34px; line-height: 1; }
.weather-temp { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: proportional-nums; }
.weather-what { font-size: 13px; opacity: 0.92; }
.weather-range { font-size: 13px; opacity: 0.92; margin-top: 2px; }
.weather-card .muted { color: rgba(255, 255, 255, 0.85); }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat-tile {
  background: var(--tg-section-bg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: 72px;
}
.stat-tile.skeleton { opacity: 0.5; }
.stat-tile-wide {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-tile-wide .stat-label { margin-top: 0; text-align: right; }
.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
  line-height: 1.15;
}
.stat-label { font-size: 12.5px; color: var(--tg-hint); margin-top: 2px; }

/* ── списки (задачи / напоминания / записи финансов) ── */
.list { background: var(--tg-section-bg); border-radius: var(--radius); overflow: hidden; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--tg-separator);
}
.list-row:last-child { border-bottom: none; }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-title { font-size: 15px; line-height: 1.35; word-break: break-word; }
.row-title.done { text-decoration: line-through; color: var(--tg-hint); }
.row-sub { font-size: 12.5px; color: var(--tg-hint); margin-top: 2px; }
.row-sub.warn { color: var(--status-critical); }

.check-circle {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--tg-hint); background: none; padding: 0; cursor: pointer;
}
.check-circle.done { border-color: var(--status-good); background: var(--status-good); }
.check-circle.done::after { content: "✓"; color: #fff; font-size: 13px; line-height: 20px; }

.trash-btn {
  flex: none; width: 30px; height: 30px; border: none; background: none;
  color: var(--tg-hint); font-size: 15px; cursor: pointer; border-radius: 50%;
}
.trash-btn:active { background: var(--tg-separator); }

.cat-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }

.empty-hint { padding: 28px 16px; text-align: center; color: var(--tg-hint); font-size: 14px; }

.task-group + .task-group { margin-top: 18px; }

/* ── формы: композер задач, разворачиваемые формы напоминаний/финансов ── */
.field {
  width: 100%;
  background: var(--tg-secondary-bg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 15px;
  color: var(--tg-text);
}
.field::placeholder { color: var(--tg-hint); }
.field-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.field-row .field { flex: 1 1 auto; }

.toggle-chip {
  flex: none; display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--tg-hint); white-space: nowrap; padding: 4px;
}
.toggle-chip input { width: 17px; height: 17px; accent-color: var(--accent); }

.btn {
  border: none; border-radius: var(--radius-sm); padding: 11px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { opacity: 0.85; }
.btn-ghost { background: none; color: var(--tg-hint); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.add-row {
  width: 100%; display: flex; align-items: center; gap: 8px;
  background: none; border: none; padding: 13px 4px; margin-top: 10px;
  color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer;
}
.add-row[hidden] { display: none; }
.add-row-icon {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-size: 17px; flex: none;
}
.add-form {
  background: var(--tg-section-bg); border-radius: var(--radius); padding: 14px; margin-top: 4px;
}

.segmented {
  display: flex; background: var(--tg-secondary-bg); border-radius: var(--radius-sm); padding: 3px;
}
.segmented-opt {
  flex: 1 1 0; border: none; background: none; color: var(--tg-text); padding: 8px 10px;
  font-size: 14px; font-weight: 600; border-radius: 8px; cursor: pointer;
}
.segmented-opt.active { background: var(--accent); color: var(--accent-ink); }
.segmented-sm .segmented-opt { padding: 6px 8px; font-size: 13px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.chip {
  border: 1px solid var(--tg-separator); background: var(--tg-secondary-bg); color: var(--tg-text);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; display: flex;
  align-items: center; gap: 6px;
}
.chip .cat-dot { width: 8px; height: 8px; }
.chip.active { border-color: transparent; background: var(--chip-color, var(--accent)); color: #fff; }

/* композер задач — приклеен к низу страницы «Задачи» */
.composer { margin-top: 16px; }
.composer-row { display: flex; gap: 8px; margin-top: 8px; }
.composer-row .field { flex: 1 1 auto; }
.btn-send { flex: none; }

/* ── финансы ── */
.month-switch { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 12px; }
.month-label { font-size: 15px; font-weight: 600; min-width: 140px; text-align: center; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--tg-section-bg);
  color: var(--tg-text); font-size: 18px; cursor: pointer;
}

.balance-card { text-align: center; }
.balance-value { font-size: 32px; font-weight: 700; font-variant-numeric: proportional-nums; }
.balance-value.good { color: var(--status-good); }
.balance-value.critical { color: var(--status-critical); }
.balance-row { display: flex; justify-content: center; gap: 18px; margin-top: 8px; font-size: 13px; }
.balance-sub { display: flex; align-items: center; gap: 6px; color: var(--tg-hint); }
.balance-sub b { color: var(--tg-text); font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-good { background: var(--status-good); }
.dot-critical { background: var(--status-critical); }

.balance-adjust-toggle {
  display: block; width: 100%; background: none; border: none; margin-top: 10px;
  color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px;
}
.balance-adjust-form {
  background: var(--tg-secondary-bg); border-radius: var(--radius-sm); padding: 12px; margin-top: 8px;
  text-align: left;
}

.cat-section { margin-top: 18px; }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 7px 2px; }
.cat-name { flex: 1 1 auto; font-size: 13.5px; }
.cat-amount { font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--tg-hint); }
.cat-bar-track { height: 6px; border-radius: 4px; background: var(--tg-separator); margin: 2px 0 10px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 4px; }

.finance-row-cat { font-size: 12.5px; color: var(--tg-hint); margin-top: 2px; }

/* ── DevOps: отдельная тёмная тема вкладки — не зависит от темы Telegram ── */
section.screen[data-screen="devops"] {
  background: var(--dops-bg);
  margin: -16px -16px calc(-1 * (var(--tabbar-h) + 24px));
  padding: 16px 16px calc(var(--tabbar-h) + 24px);
  min-height: 100%;
  color: var(--dops-text);
}
.devops-wrap { max-width: 480px; margin: 0 auto; }
.devops-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.devops-title { color: var(--dops-text); }
.devops-sub { color: var(--dops-muted); font-size: 13px; margin: -8px 0 16px; }
.devops-filter-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--dops-border);
  background: var(--dops-card); color: var(--dops-text); font-size: 16px; cursor: pointer;
}

/* ── стек карточек, листаем кнопками ──
   Карточки позади «выглядывают» снизу — они той же ширины, но короче (top растёт, высота
   фиксирована через calc), поэтому верхняя карточка их не закрывает целиком. */
.swipe-stack { position: relative; height: min(58vh, 460px); }
.swipe-card {
  position: absolute; left: 0; right: 0; top: 0; height: calc(100% - 26px);
  overflow-y: auto; display: flex; flex-direction: column;
  background: var(--dops-card); border: 1px solid var(--dops-border);
  border-radius: calc(var(--radius) + 4px); padding: 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  transition: transform 0.26s cubic-bezier(.2, .8, .2, 1), opacity 0.26s, top 0.26s, left 0.26s, right 0.26s;
}
.swipe-card[data-pos="0"] { z-index: 3; top: 0; left: 0; right: 0; }
.swipe-card[data-pos="1"] { z-index: 2; top: 12px; left: 8px; right: 8px; }
.swipe-card[data-pos="2"] { z-index: 1; top: 22px; left: 16px; right: 16px; opacity: 0.7; }

.swipe-actions { display: flex; justify-content: center; gap: 22px; margin-top: 16px; }
.swipe-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--dops-border);
  background: var(--dops-card); font-size: 21px; cursor: pointer;
}
.swipe-btn-nope { color: var(--dops-red); }
.swipe-btn-like { color: var(--dops-green); }

/* ── нижняя шторка: фильтры ленты ── */
/* flex-колонка: заголовок с крестиком и подсказка — фиксированы, чипы скроллятся сами,
   так что кнопка закрытия никогда не уезжает за край маленького экрана. */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 75vh;
  display: flex; flex-direction: column;
  background: var(--dops-card); color: var(--dops-text); border: 1px solid var(--dops-border);
  border-bottom: none; border-radius: 16px 16px 0 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-title { font-size: 15px; font-weight: 700; }
.sheet-close {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--dops-bg); color: var(--dops-text); font-size: 15px; cursor: pointer;
}
.sheet-hint { flex: none; color: var(--dops-muted); font-size: 13px; margin: 4px 0 2px; }
.sheet .chip-row { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 2px; }
.sheet .chip { border-color: var(--dops-border); background: var(--dops-bg); color: var(--dops-text); }
.sheet .chip.active { background: var(--dops-green); border-color: transparent; color: #04140a; }
.sheet-reset {
  flex: none; display: block; width: 100%; background: none; border: none; margin-top: 10px;
  color: var(--dops-muted); font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px;
}

.feed-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.feed-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--dops-amber);
  background: rgba(210, 153, 34, 0.12);
  border-radius: 6px;
  padding: 3px 7px;
}
.feed-title { font-size: 14px; font-weight: 700; color: var(--dops-text); }
.feed-text { font-size: 14.5px; line-height: 1.45; color: var(--dops-text); white-space: pre-wrap; }
.feed-text code {
  font-family: var(--font-mono); font-size: 13px; background: rgba(255, 255, 255, 0.08);
  border-radius: 4px; padding: 1px 5px;
}
.feed-options { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13.5px; color: var(--dops-muted); }
.feed-options li { padding: 3px 0; }
.feed-options li::before { content: "– "; }

.feed-solution-toggle {
  margin-top: 10px; background: none; border: 1px dashed var(--dops-border); color: var(--dops-green);
  font-family: var(--font-mono); font-size: 12.5px; border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.feed-solution {
  margin-top: 8px; font-size: 13.5px; color: var(--dops-text); border-left: 2px solid var(--dops-green);
  padding-left: 10px;
}

/* ── нижняя навигация ── */
.tabbar {
  position: relative;
  flex: none;
  display: flex;
  background: var(--tg-secondary-bg);
  border-top: 1px solid var(--tg-separator);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 5;
}
.tab {
  flex: 1 1 0; background: none; border: none; color: var(--tg-hint);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 10px; font-size: 11px; height: var(--tabbar-h); cursor: pointer;
}
.tab-icon { font-size: 20px; line-height: 1; filter: grayscale(0.6); opacity: 0.75; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { filter: none; opacity: 1; }

/* ── служебное ── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 14px); transform: translate(-50%, 8px);
  background: var(--tg-text); color: var(--tg-bg); padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: 86%; text-align: center; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.gate {
  position: fixed; inset: 0; background: var(--tg-bg); color: var(--tg-text);
  display: flex; align-items: center; justify-content: center; padding: 32px; z-index: 30;
}
.gate[hidden] { display: none; }    /* [hidden] и класс с display делят специфичность — явно фиксируем */
.gate-text { max-width: 320px; text-align: center; font-size: 15px; line-height: 1.5; color: var(--tg-hint); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
