/* styles.css — Полностью автономная тёмная тема в стиле Telegram.
 * Не зависит от внешних CDN (Tailwind/шрифты) — работает офлайн.
 */

:root {
  --tg-accent: #2AABEE;
  --tg-bg: #17212B;
  --tg-text: #F1F1F1;
  --tg-hint: #7D8B99;
  --card-bg: #212E3B;
  --card-border: rgba(255, 255, 255, 0.06);
  --good: #4FC3F7;
  --warn: #FFD54F;
  --danger: #F15C5C;
  --success: #4CD964;
  --radius: 16px;
}

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

.hidden { display: none !important; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* ===================== Анимации ===================== */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn   { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn    { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }
@keyframes slideUp  { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDown{ from { transform: translateY(0); opacity: 1; } to { transform: translateY(100%); opacity: 0; } }
@keyframes shimmer  { 0% { background-position: -400px 0; } 100% { background-position: 400px 0; } }

.anim-fade-in-up { animation: fadeInUp .45s cubic-bezier(.22,1,.36,1) both; }
.anim-fade-in    { animation: fadeIn .3s ease both; }
.anim-pop-in     { animation: popIn .35s cubic-bezier(.22,1,.36,1) both; }

/* ===================== Экран ===================== */
.screen { min-height: 100vh; }

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Шапка */
.header { position: sticky; top: 0; z-index: 20; background: var(--tg-bg); padding: 24px 20px 16px; }
.header-inner { max-width: 480px; margin: 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.brand-title { font-size: 22px; font-weight: 800; letter-spacing: -.5px; margin: 0; line-height: 1.2; }
.brand-sub { font-size: 13px; margin-top: 3px; color: var(--tg-hint); }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.icon-btn {
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.08);
  border: none; border-radius: 12px;
  color: var(--tg-text); cursor: pointer;
  transition: transform .12s, background .2s;
}
.icon-btn:active { transform: scale(.94); background: rgba(255,255,255,.14); }
.icon-btn svg, [data-icon] svg { width: 20px; height: 20px; display: block; }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: rgba(241,92,92,.15); }

/* Заголовок списка с кнопкой массового удаления */
.btn-delete-filtered {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(241,92,92,.12); border: 1px solid rgba(241,92,92,.35);
  color: var(--danger); border-radius: 10px; padding: 6px 10px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  margin-left: auto; transition: transform .12s, background .2s;
}
.btn-delete-filtered:active { transform: scale(.95); background: rgba(241,92,92,.25); }
.btn-delete-filtered svg { width: 14px; height: 14px; }

/* Текст подтверждения */
.confirm-text { font-size: 15px; line-height: 1.5; color: var(--tg-text); margin: 4px 0 20px; }

/* Сводка */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.summary-item {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 16px; padding: 12px; cursor: pointer;
  transition: transform .15s, border-color .2s, box-shadow .2s;
}
.summary-item:active { transform: scale(.97); }
.summary-item.active {
  border-color: var(--tg-accent);
  box-shadow: 0 0 0 1px var(--tg-accent), 0 6px 18px rgba(42,171,238,.25);
}
.summary-item.active .stat-label { color: var(--tg-accent); font-weight: 700; }
.stat-num { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 11px; margin-top: 2px; color: var(--tg-hint); white-space: nowrap; }

/* Список */
.list { padding: 4px 16px 120px; }
.group { margin-bottom: 24px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 0 4px; margin-bottom: 12px; }
.group-dot { width: 8px; height: 8px; border-radius: 50%; }
.group-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--tg-hint); }
.group-count { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }

/* Пустое состояние */
.empty { text-align: center; padding-top: 64px; }
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-title { font-weight: 700; font-size: 18px; }
.empty-sub { font-size: 14px; margin-top: 6px; padding: 0 32px; color: var(--tg-hint); }

/* ===================== Карточка заметки + свайп ===================== */
.note-swipe { position: relative; overflow: hidden; border-radius: var(--radius); margin-bottom: 12px; }
.note-swipe-bg { position: absolute; inset: 0; display: flex; align-items: stretch; justify-content: flex-end; }
.swipe-action {
  width: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #fff; font-size: 11px; font-weight: 600; cursor: pointer; border: none;
}
.swipe-action svg { width: 20px; height: 20px; }
.swipe-complete { background: var(--success); }
.swipe-delete   { background: var(--danger); }

.note-card {
  position: relative; background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  transition: transform .25s cubic-bezier(.22,1,.36,1);
  will-change: transform; touch-action: pan-y;
}
.note-main { display: flex; align-items: flex-start; gap: 12px; }
.note-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.note-body { flex: 1; min-width: 0; }
.note-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.note-top-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.note-complete-btn {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(76,217,100,.15); border: 1px solid rgba(76,217,100,.4);
  color: var(--success); cursor: pointer; flex-shrink: 0;
  transition: transform .12s, background .2s;
}
.note-complete-btn:active { transform: scale(.9); background: rgba(76,217,100,.3); }
.note-complete-btn svg { width: 16px; height: 16px; }
.note-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-status { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; flex-shrink: 0; white-space: nowrap; }
.note-amount { font-size: 18px; font-weight: 700; margin-top: 2px; color: var(--tg-accent); }
.note-meta { font-size: 12px; margin-top: 4px; color: var(--tg-hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-meta svg { width: 13px; height: 13px; display: inline; vertical-align: -2px; }
.note-recur { font-size: 12px; margin-top: 4px; color: var(--tg-accent); }
.note-recur svg { width: 13px; height: 13px; display: inline; vertical-align: -2px; }

/* ===================== Кнопки ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; font-weight: 600; font-family: inherit; font-size: 15px;
  cursor: pointer; transition: transform .12s, opacity .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, #2AABEE, #1E9BE0); color: #fff; box-shadow: 0 8px 20px rgba(42,171,238,.35); }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { background: rgba(255,255,255,.08); color: var(--tg-text); }
.btn-block { width: 100%; padding: 15px; }
.btn-md { padding: 12px 16px; }

/* ===================== Поля ===================== */
.field { margin-bottom: 20px; }
.field-label { display: block; font-size: 13px; margin-bottom: 8px; color: var(--tg-hint); }
.field-input {
  width: 100%; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px; padding: 12px 14px; color: var(--tg-text); font-size: 15px; font-family: inherit;
  transition: border-color .2s, box-shadow .2s; outline: none;
}
.field-input:focus { border-color: var(--tg-accent); box-shadow: 0 0 0 3px rgba(42,171,238,.18); }
.field-input::placeholder { color: var(--tg-hint); }
.field-row { display: flex; gap: 10px; }
.field-row .grow { flex: 1; }

select.field-input { appearance: none; -webkit-appearance: none; cursor: pointer; }
select.field-input option { background: var(--card-bg); color: var(--tg-text); }

input[type="date"].field-input::-webkit-calendar-picker-indicator { filter: invert(.6); cursor: pointer; }

/* Поле даты с иконкой календаря (открывает datepicker) */
.date-input {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237D8B99' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='18' x='3' y='4' rx='2'/%3E%3Cpath d='M16 2v4'/%3E%3Cpath d='M8 2v4'/%3E%3Cpath d='M3 10h18'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
  padding-right: 38px;
}

/* ===================== Календарь ===================== */
.datepicker-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.datepicker-title { flex: 1; text-align: center; font-size: 16px; font-weight: 700; }
.datepicker-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  margin-bottom: 6px; text-align: center; font-size: 11px; font-weight: 600; color: var(--tg-hint);
}
.datepicker-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dp-empty { height: 38px; }
.dp-day {
  height: 38px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 10px; color: var(--tg-text);
  font-size: 14px; cursor: pointer; transition: background .15s, transform .1s;
}
.dp-day:active { transform: scale(.9); }
.dp-day:hover { background: rgba(255,255,255,.06); }
.dp-day.today { color: var(--tg-accent); font-weight: 700; }
.dp-day.selected { background: var(--tg-accent); color: #fff; font-weight: 700; }

/* ===================== Переключатели ===================== */
.switch {
  position: relative; width: 48px; height: 28px; border-radius: 999px;
  background: rgba(255,255,255,.15); transition: background .25s; flex-shrink: 0; cursor: pointer;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 999px; background: #fff; transition: transform .25s cubic-bezier(.22,1,.36,1);
}
.switch.on { background: var(--tg-accent); }
.switch.on::after { transform: translateX(20px); }

.switch-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px;
}
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-title { font-weight: 600; }
.switch-sub { font-size: 12px; margin-top: 2px; color: var(--tg-hint); }
.switch-extra { margin-top: 14px; }

/* ===================== Форма ===================== */
.form-screen { position: fixed; inset: 0; z-index: 40; overflow-y: auto; background: var(--tg-bg); }
.form-inner { max-width: 480px; margin: 0 auto; padding: 24px 20px 40px; }
.form-top { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.form-title { font-size: 20px; font-weight: 700; margin: 0; flex: 1; }

/* ===================== Модалки ===================== */
.modal-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.modal-sheet {
  position: relative; width: 100%; max-width: 480px; margin: 0 auto;
  background: var(--card-bg); border-radius: 24px 24px 0 0; padding: 20px 24px 28px;
  animation: slideUp .38s cubic-bezier(.22,1,.36,1) both;
}
.grabber { width: 40px; height: 4px; border-radius: 999px; background: rgba(255,255,255,.2); margin: 0 auto 16px; }
.modal-title { font-size: 18px; font-weight: 700; margin: 0 0 16px; }
.modal-actions { display: flex; gap: 12px; margin-top: 8px; }
.modal-actions .btn { flex: 1; padding: 13px; }

/* Палитра цветов категории */
.color-palette { display: flex; gap: 8px; align-items: center; }
.color-dot {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform .15s, border-color .15s;
}
.color-dot.sel { border-color: #fff; transform: scale(1.12); }

/* Карусель иконок категорий */
.icon-carousel { display: flex; align-items: center; gap: 6px; }
.carousel-arrow {
  width: 36px; height: 44px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.06); border: none; border-radius: 10px;
  color: var(--tg-text); cursor: pointer; transition: background .2s, transform .12s;
}
.carousel-arrow:active { transform: scale(.92); background: rgba(255,255,255,.14); }
.carousel-arrow svg { width: 18px; height: 18px; }

.icon-carousel-track {
  flex: 1; display: flex; gap: 8px; overflow-x: auto;
  scroll-snap-type: x mandatory; padding: 4px 2px;
  scrollbar-width: none; -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch; touch-action: pan-x;
}
.icon-carousel-track::-webkit-scrollbar { display: none; }

.icon-choice {
  flex: 0 0 auto; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: rgba(255,255,255,.06); border: 2px solid transparent;
  border-radius: 12px; cursor: pointer; scroll-snap-align: center;
  transition: transform .12s, border-color .15s, background .15s;
}
.icon-choice:active { transform: scale(.92); }
.icon-choice.sel { border-color: var(--tg-accent); background: rgba(42,171,238,.18); }

/* ===================== Тост ===================== */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 999;
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  background: #2c3a47; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.35); max-width: 88%; text-align: center;
}

/* ===================== FAB ===================== */
.fab-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; pointer-events: none;
  max-width: 480px; margin: 0 auto; padding: 0 24px 24px; display: flex; justify-content: flex-end;
}
.fab {
  pointer-events: auto; width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, #2AABEE, #1E9BE0); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 26px rgba(42,171,238,.4);
  transition: transform .12s;
}
.fab:active { transform: scale(.93); }
.fab svg { width: 28px; height: 28px; }

/* ===================== Экран входа (dev) ===================== */
.login-overlay {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: var(--tg-bg);
}
.login-card {
  background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 20px;
  padding: 30px 26px; max-width: 360px; width: 100%; text-align: center;
  animation: popIn .4s cubic-bezier(.22,1,.36,1) both;
}
.login-icon { font-size: 42px; }
.login-title { font-size: 20px; font-weight: 800; margin: 14px 0 6px; }
.login-sub { font-size: 14px; color: var(--tg-hint); margin: 0 0 20px; line-height: 1.5; }
.login-sub code { background: rgba(255,255,255,.1); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.login-field { margin-bottom: 12px; }
.login-hint { font-size: 12px; color: var(--tg-hint); margin-top: 12px; line-height: 1.4; }

/* ===================== Скелетон ===================== */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,.05) 25%, rgba(255,255,255,.12) 50%, rgba(255,255,255,.05) 75%);
  background-size: 800px 100%; animation: shimmer 1.4s infinite linear;
  border-radius: var(--radius); height: 112px; margin-bottom: 12px;
}

/* Адаптивность */
@media (max-width: 420px) {
  .brand-title { font-size: 19px; }
  .stat-num { font-size: 20px; }
}

/* ===================== Нижняя навигация ===================== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--card-bg); border-top: 1px solid var(--card-border);
  padding: 6px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  max-width: 480px; margin: 0 auto;
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--tg-hint); font-family: inherit;
  font-size: 11px; font-weight: 600; padding: 6px 0; cursor: pointer;
  transition: color .2s;
}
.tab-btn svg { width: 22px; height: 22px; }
.tab-btn.active { color: var(--tg-accent); }

/* FAB поднимаем выше таббара */
.fab-wrap { bottom: 74px; }

/* ===================== Экран бюджета ===================== */
.period-row { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.period-row .icon-btn { width: 38px; height: 38px; }
.period-seg {
  flex: 1; display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(255,255,255,.06); border-radius: 12px; padding: 4px;
}
.seg {
  background: none; border: none; color: var(--tg-hint); font-family: inherit;
  font-size: 13px; font-weight: 600; padding: 8px 0; border-radius: 9px; cursor: pointer;
  transition: background .2s, color .2s;
}
.seg.active { background: var(--tg-accent); color: #fff; }

.budget-card {
  margin-top: 16px; background: linear-gradient(135deg, #2AABEE, #1E9BE0);
  border-radius: 20px; padding: 20px; color: #fff;
  box-shadow: 0 12px 28px rgba(42,171,238,.35);
}
.budget-card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.budget-label { font-size: 12px; opacity: .85; }
.budget-amount { font-size: 32px; font-weight: 800; margin-top: 2px; letter-spacing: -.5px; }
.budget-side { text-align: right; }
.budget-remaining { font-size: 18px; font-weight: 700; margin-top: 2px; }
.budget-remaining.negative { color: #FFD54F; }

.budget-progress {
  height: 8px; border-radius: 999px; background: rgba(255,255,255,.25); margin: 16px 0; overflow: hidden;
}
.budget-progress-fill {
  height: 100%; border-radius: 999px; background: #fff; transition: width .5s cubic-bezier(.22,1,.36,1); width: 0;
}
.budget-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.budget-stat { display: flex; flex-direction: column; gap: 2px; }
.budget-stat-label { font-size: 12px; opacity: .85; }
.budget-stat-value { font-size: 16px; font-weight: 700; }
.budget-stat-sub { font-size: 12px; opacity: .8; }

/* ===================== Экран трат ===================== */
.month-title {
  flex: 1; text-align: center; font-size: 16px; font-weight: 700;
  text-transform: capitalize;
}
.exp-summary {
  margin-top: 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.exp-sum-col {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 16px; padding: 14px 12px; text-align: center;
}
.exp-sum-label { font-size: 12px; color: var(--tg-hint); }
.exp-sum-value { font-size: 18px; font-weight: 800; margin-top: 4px; }

.exp-card { margin-bottom: 12px; }
.exp-head {
  display: flex; align-items: center; gap: 8px; padding: 0 4px; margin: 20px 0 10px;
}
.exp-head:first-child { margin-top: 4px; }
.exp-day { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--tg-hint); }
.exp-day-total { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--tg-hint); }

/* Категории в менеджере */
.cat-manager-list { max-height: 46vh; overflow-y: auto; }
.cat-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 6px;
  border-bottom: 1px solid var(--card-border);
}
.cat-row:last-child { border-bottom: none; }
.cat-row-icon { font-size: 20px; }
.cat-row-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-req-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; flex-shrink: 0;
  background: var(--tg-accent); color: #fff;
}
.cat-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.cat-row-actions .icon-btn { width: 34px; height: 34px; }
.cat-row-actions .icon-btn svg { width: 16px; height: 16px; }

/* Отступ между карточками в списках «Траты» и «Бюджет» — как в списке заметок */
#budget-notes .note-card + .note-card,
.exp-card .note-card + .note-card { margin-top: 12px; }
