/* ============================================
   ПЕРЕМЕННЫЕ И ТЕМЫ
   ============================================ */

:root {
  --accent: #10B981;
  --accent-dark: #059669;
  --accent-light: #34D399;
  --danger: #EF4444;

  --radius-card: 20px;
  --radius-btn: 14px;
  --radius-input: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root,
[data-theme="light"] {
  --bg-gradient: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 50%, #A7F3D0 100%);
  --blob-1: #10B981;
  --blob-2: #34D399;
  --blob-3: #6EE7B7;
  --blob-opacity: 0.35;

  --text: #064E3B;
  --text-muted: #047857;
  --text-soft: rgba(6, 78, 59, 0.6);

  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-shadow: 0 8px 32px rgba(6, 78, 59, 0.08);

  --input-bg: rgba(255, 255, 255, 0.7);
  --input-border: rgba(6, 78, 59, 0.1);
  --input-focus: var(--accent);

  --divider: rgba(6, 78, 59, 0.08);
}

[data-theme="dark"] {
  /* Серая тёмная тема в стиле iOS dark — нейтральная, без синевы */
  --bg-gradient: linear-gradient(135deg, #1C1C1E 0%, #2C2C2E 50%, #1C1C1E 100%);
  --blob-1: #10B981;
  --blob-2: #34D399;
  --blob-3: #6B7280;
  --blob-opacity: 0.18;

  --text: #F2F2F7;
  --text-muted: #A1A1AA;
  --text-soft: rgba(242, 242, 247, 0.55);

  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

  --input-bg: rgba(255, 255, 255, 0.06);
  --input-border: rgba(255, 255, 255, 0.12);
  --input-focus: var(--accent-light);

  --divider: rgba(255, 255, 255, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-gradient: linear-gradient(135deg, #1C1C1E 0%, #2C2C2E 50%, #1C1C1E 100%);
    --blob-1: #10B981;
    --blob-2: #34D399;
    --blob-3: #6B7280;
    --blob-opacity: 0.18;
    --text: #F2F2F7;
    --text-muted: #A1A1AA;
    --text-soft: rgba(242, 242, 247, 0.55);
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --input-bg: rgba(255, 255, 255, 0.06);
    --input-border: rgba(255, 255, 255, 0.12);
    --input-focus: var(--accent-light);
    --divider: rgba(255, 255, 255, 0.08);
  }
}

/* ============================================
   СБРОС И БАЗА
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; overscroll-behavior-y: contain; }

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-gradient);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ============================================
   ФОНОВЫЕ РАЗМЫТЫЕ ПЯТНА
   ============================================ */

.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: var(--blob-opacity);
}

.blob-1 { width: 400px; height: 400px; background: var(--blob-1); top: -100px; left: -100px; }
.blob-2 { width: 350px; height: 350px; background: var(--blob-2); bottom: 10%; right: -80px; }
.blob-3 { width: 300px; height: 300px; background: var(--blob-3); top: 40%; left: 30%; }

/* ============================================
   ЭКРАНЫ
   ============================================ */

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 20px);
  max-width: 520px;
  margin: 0 auto;
  animation: fadeIn 0.25s ease;
}

.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   ШАПКА
   ============================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  min-height: 40px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.app-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  text-align: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  color: var(--text);
  transition: transform 0.15s, background 0.2s;
  flex-shrink: 0;
}

.icon-btn:active { transform: scale(0.92); }
.icon-btn-danger { color: var(--danger); }

/* ============================================
   GLASS-КАРТОЧКА
   ============================================ */

.card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  box-shadow: var(--glass-shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* Карточка-контейнер для row-btn — убираем внутренний паддинг, кнопки сами их держат */
.card-rows {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

/* ============================================
   ГЛАВНАЯ: КАРТОЧКА БАЛАНСА
   ============================================ */

.balance-card {
  padding: 28px 24px;
  text-align: center;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.85), rgba(5, 150, 105, 0.85));
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  box-shadow: 0 10px 30px rgba(16, 185, 129, 0.25);
}

.balance-label {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.balance-amount {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 6px;
  word-break: break-all;
}

.balance-meta {
  font-size: 13px;
  opacity: 0.85;
  font-weight: 500;
}

/* ============================================
   СЕКЦИИ И СПИСКИ
   ============================================ */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 4px 12px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.link-btn {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-dark);
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.2s;
}

[data-theme="dark"] .link-btn { color: var(--accent-light); }
.link-btn:active { background: var(--glass-bg); }

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 100px;
}

/* Запись в списке */
.record {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.15s;
  text-align: left;
  width: 100%;
}

.record:active { transform: scale(0.98); }

.record-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.record-main {
  flex: 1;
  min-width: 0;
}

.record-category {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-sub {
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-amount {
  font-weight: 800;
  font-size: 16px;
  color: var(--accent-dark);
  white-space: nowrap;
}

[data-theme="dark"] .record-amount { color: var(--accent-light); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-soft);
  font-size: 14px;
}

.empty-emoji {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ============================================
   FAB — КНОПКА "+"
   ============================================ */

.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.45);
  transition: transform 0.15s;
  z-index: 100;
}

.fab:active { transform: scale(0.92); }

@media (min-width: 520px) {
  .fab {
    right: calc(50vw - 260px + 24px);
  }
}

/* ============================================
   ФОРМЫ
   ============================================ */

.form-card { padding: 8px; }

.field {
  display: block;
  padding: 14px 12px;
  border-bottom: 1px solid var(--divider);
}

.field:last-of-type { border-bottom: none; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.field-hint {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}

.field input[type="text"],
.field input[type="date"],
.field select {
  width: 100%;
  background: transparent;
  border: none;
  padding: 4px 0;
  font-size: 17px;
  font-weight: 600;
  outline: none;
}

.field input::placeholder { color: var(--text-soft); font-weight: 500; }

.field input[type="date"] {
  color-scheme: light;
  font-weight: 600;
}

[data-theme="dark"] .field input[type="date"] { color-scheme: dark; }

.amount-input {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.amount-input input {
  flex: 1;
  font-size: 32px !important;
  font-weight: 800 !important;
  padding: 0 !important;
}

.amount-currency {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-soft);
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-25%) rotate(45deg);
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-soft);
  border-bottom: 2px solid var(--text-soft);
  pointer-events: none;
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 24px !important;
  cursor: pointer;
}

.field select option {
  background: #fff;
  color: #111;
}

[data-theme="dark"] .field select option { background: #064E3B; color: #F0FDF4; }

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 16px;
  border-radius: var(--radius-btn);
  margin-top: 20px;
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
  transition: transform 0.15s;
}

.btn-primary:active { transform: scale(0.98); }

.inline-input {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-input input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 500;
  outline: none;
  transition: border-color 0.2s;
}

.inline-input input:focus { border-color: var(--input-focus); }

.btn-inline {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: var(--radius-input);
  white-space: nowrap;
  transition: transform 0.15s;
}

.btn-inline:active { transform: scale(0.95); }

/* ============================================
   НАСТРОЙКИ: КНОПКИ-СТРОКИ
   ============================================ */

.row-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  border-bottom: 1px solid var(--divider);
  transition: background 0.15s;
}

.row-btn > span:first-child {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-btn > svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.row-btn:last-child { border-bottom: none; }
.row-btn:active { background: var(--glass-border); }
.row-btn-danger { color: var(--danger); }

.app-version {
  text-align: center;
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 20px;
  font-weight: 500;
}

/* ============================================
   КАТЕГОРИИ: СПИСОК
   ============================================ */

.category-row {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.category-name {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.cat-action-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: background 0.15s, color 0.2s;
}

.cat-action-btn:active { background: var(--glass-border); }
.cat-action-btn.danger { color: var(--danger); }

/* ============================================
   ТОСТ
   ============================================ */

.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 100px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 1000;
  max-width: calc(100vw - 40px);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   АДАПТИВ
   ============================================ */

@media (max-width: 360px) {
  .balance-amount { font-size: 34px; }
  .app-title { font-size: 20px; }
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
/* ============================================
   СТАТИСТИКА
   ============================================ */

/* Шапка главной — контейнер для иконок */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Переключатель периода */
.period-switch {
  display: flex;
  gap: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-btn, 14px);
  padding: 4px;
  margin-bottom: 16px;
}

.period-btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  border: none;
  background: transparent;
  border-radius: 10px;
  transition: all 0.2s;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}

.period-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.period-btn:not(.active):active {
  background: var(--glass-border);
}

/* Сводка */
.stats-summary {
  text-align: center;
  padding: 24px 20px;
}

.stats-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stats-amount {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent-dark);
  letter-spacing: -1px;
  margin-bottom: 6px;
  word-break: break-all;
  line-height: 1.1;
}

[data-theme="dark"] .stats-amount { color: var(--accent-light, #6EE7B7); }

.stats-meta {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
}

/* Столбчатая диаграмма */
.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 3px;
  height: 160px;
  padding: 8px 0 26px;
  position: relative;
}

.chart-bar {
  flex: 1;
  min-width: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  position: relative;
  height: 100%;
}

.chart-bar-fill {
  width: 100%;
  max-width: 28px;
  background: linear-gradient(180deg, var(--accent-light, #6EE7B7), var(--accent-dark, #059669));
  border-radius: 6px 6px 2px 2px;
  min-height: 2px;
  transition: height 0.4s ease;
}

.chart-bar-fill.empty {
  background: var(--input-border, rgba(0,0,0,0.08));
  opacity: 0.5;
}

.chart-bar-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-soft);
  position: absolute;
  bottom: -22px;
  white-space: nowrap;
  left: 50%;
  transform: translateX(-50%);
}

.chart-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-soft);
  font-size: 14px;
  width: 100%;
}

/* Категории — строки с прогресс-баром */
.cat-stat {
  padding: 14px 16px;
  border-bottom: 1px solid var(--divider);
}

.cat-stat:last-child { border-bottom: none; }

.cat-stat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  gap: 10px;
}

.cat-stat-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-stat-amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-dark);
  white-space: nowrap;
}

[data-theme="dark"] .cat-stat-amount { color: var(--accent-light, #6EE7B7); }

.cat-stat-bar {
  height: 6px;
  background: var(--input-border, rgba(0,0,0,0.08));
  border-radius: 3px;
  overflow: hidden;
}

.cat-stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  border-radius: 3px;
  transition: width 0.5s ease;
}

.cat-stat-percent {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
  margin-top: 4px;
}

@media (max-width: 360px) {
  .stats-amount { font-size: 30px; }
  .chart-bars { height: 140px; }
  .period-btn { font-size: 12px; padding: 9px 6px; }
}

/* ============================================
   ГРУППИРОВКА ЗАПИСЕЙ ПО МЕСЯЦАМ
   ============================================ */

.month-group {
  margin-bottom: 12px;
}

/* Текущий месяц — без шапки, записи показаны напрямую */
.month-group-current {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Свёрнутая шапка месяца (аккордеон) */
.month-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  text-align: left;
  transition: transform 0.15s, background 0.2s;
  color: var(--text);
}

.month-header:active { transform: scale(0.98); }

.month-header-main {
  flex: 1;
  min-width: 0;
}

.month-header-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 2px;
  text-transform: capitalize;
}

.month-header-meta {
  font-size: 13px;
  color: var(--text-soft);
}

.month-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.month-header-amount {
  font-weight: 800;
  font-size: 16px;
  color: var(--accent-dark);
  white-space: nowrap;
}

[data-theme="dark"] .month-header-amount { color: var(--accent-light); }

.month-chevron {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: transform 0.25s ease;
}

.month-group.expanded .month-chevron {
  transform: rotate(90deg);
}

/* Контейнер с записями свёрнутого месяца */
.month-records {
  display: none;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding-left: 4px;
}

.month-group.expanded .month-records {
  display: flex;
  animation: fadeIn 0.25s ease;
}

/* ============================================
   СРАВНЕНИЕ С ПРОШЛЫМ МЕСЯЦЕМ (в карточке баланса)
   ============================================ */

.balance-compare {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 6px;
  font-weight: 600;
}

.balance-compare-arrow {
  font-size: 12px;
  line-height: 1;
}

.balance-compare.up { color: #BBF7D0; }
.balance-compare.down { color: #FECACA; }
.balance-compare.same { color: rgba(255, 255, 255, 0.75); }