@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* Палитра */
  --bg-app: #121212;
  --bg-gradient: radial-gradient(circle at top, #1e1e1e 0%, #000000 100%);
  
  --bg-card: #242424;
  --bg-input: #333333;
  --primary: #FCE000;
  --text-on-primary: #000000;
  --text-main: #FFFFFF;
  --text-muted: #9E9E9E;
  
  --danger: #FF5252;
  --success: #4CD964;
  --warning: #FFD600;

  /* Размеры */
  --nav-height: 70px;
  --header-height: 60px;
  --radius-lg: 16px;
  --radius-md: 12px;
  
  --safe-area-bottom: env(safe-area-inset-bottom, 20px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* === ХИРУРГИЧЕСКОЕ ВМЕШАТЕЛЬСТВО: BODY === */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  
  /* ВКЛЮЧАЕМ НАТИВНЫЙ СКРОЛЛ */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Плавность для iPhone */
  position: relative; /* Убираем fixed */
  
  color: var(--text-main);
  font-family: 'Inter', sans-serif;
}

/* Фиксированный фон (чтобы не дергался при скролле) */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg-gradient);
  z-index: -1; /* На задний план */
  pointer-events: none;
}

/* --- ТИПОГРАФИКА --- */
h1 { font-size: 24px; font-weight: 700; margin: 0; color: var(--text-main); }
h2 { font-size: 20px; font-weight: 700; margin: 0 0 12px 0; color: var(--text-main); }
h3 { 
  font-size: 13px; font-weight: 600; color: var(--text-muted); 
  text-transform: none; margin: 0 0 8px 0; 
}
.muted { color: var(--text-muted); font-size: 13px; }
.center { text-align: center; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }

/* --- ЭЛЕМЕНТЫ ИНТЕРФЕЙСА --- */
.btn {
  width: 100%; padding: 14px; border-radius: var(--radius-md); border: none;
  font-size: 16px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: var(--text-on-primary); }
.btn.secondary { background: var(--bg-input); color: var(--text-main); }
.btn.danger { background: rgba(255, 82, 82, 0.15); color: var(--danger); }
.btn.lg { padding: 18px; font-size: 18px; }
.btn.sm { padding: 10px; font-size: 14px; }

.icon-btn {
  background: transparent; border: none; color: var(--text-main); 
  font-size: 24px; padding: 8px; cursor: pointer;
}

/* Поля ввода */
input, select {
  width: 100%; background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  padding: 16px 16px 16px 48px;
  border-radius: var(--radius-md);
  font-size: 16px; outline: none; transition: all 0.2s;
}
input:focus { border-color: var(--primary); background: #2a2a2a; }

.input-group { display: flex; flex-direction: column; gap: 16px; width: 100%; margin-bottom: 24px; }
.input-wrap { display: flex; flex-direction: column; gap: 6px; }
.input-wrap label { font-size: 12px; color: var(--text-muted); margin-left: 2px;}

.input-icon { position: relative; width: 100%; }
.input-icon i {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 20px; pointer-events: none;
}
.input-icon.lg input { padding: 20px 16px 20px 50px; font-size: 24px; font-weight: 700; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.row-spread { display: flex; justify-content: space-between; align-items: center; font-size: 15px; margin: 8px 0; }
.divider { height: 1px; background: #333; margin: 12px 0; }

.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 16px; margin-bottom: 12px; border: none;
}

/* --- ХИРУРГИЧЕСКОЕ ВМЕШАТЕЛЬСТВО: LAYOUT --- */

/* Экран входа */
.auth-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg-gradient);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.logo-area { margin-bottom: 40px; }
.logo-area i { font-size: 64px; color: var(--primary); margin-bottom: 16px; display: block; }
.auth-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; }

/* Шапка (Фиксированная) */
.top-bar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-height);
  background: rgba(18, 18, 18, 0.95); /* Полупрозрачность */
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; z-index: 1000; 
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.date-selector input { background: transparent; border: none; font-size: 18px; font-weight: 700; width: auto; padding: 0; }

/* ОБЛАСТЬ КОНТЕНТА (Исправленная) */
.content-area {
  /* Убрали фиксированную высоту */
  height: auto; 
  overflow: visible;
  
  /* Отступы, чтобы контент не прятался под барами */
  padding-top: calc(var(--header-height) + 20px);
  padding-bottom: calc(var(--nav-height) + var(--safe-area-bottom) + 30px);
  padding-left: 16px;
  padding-right: 16px;
  margin-top: 0;
}

/* Нижнее меню (Фиксированное) */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-area-bottom));
  background: #191919; 
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex; justify-content: space-around;
  padding-bottom: var(--safe-area-bottom);
  z-index: 1000;
}
.nav-item {
  background: none; border: none; color: #666;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 4px;
}
.nav-item i { font-size: 24px; margin-bottom: 2px;}
.nav-item span { font-size: 10px; font-weight: 500; }
.nav-item.active { color: var(--text-main); }
.nav-item.active i { color: var(--primary); }

/* Анимация вкладок */
.tab-section { display: none; }
.tab-section.active { display: block; animation: fadeUp 0.3s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- КОМПОНЕНТЫ --- */

/* Hero Card */
.hero-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 20px; text-align: left; margin-bottom: 16px; border: 1px solid #333;
}
.hero-label { color: var(--text-muted); font-size: 14px; margin-bottom: 4px; }
.hero-value { font-size: 40px; font-weight: 800; margin-bottom: 12px; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-item {
  background: var(--bg-card); border-radius: var(--radius-md); 
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
}
.stat-item i { font-size: 20px; color: var(--primary); }
.stat-val { font-size: 18px; font-weight: 700; }

/* Chips Scroll */
.chips-scroll {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px;
  flex-wrap: nowrap; scrollbar-width: none;
}
.chips-scroll::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; white-space: nowrap; padding: 10px 16px;
  border-radius: 10px; border: none; background: var(--bg-input);
  color: var(--text-muted); font-weight: 500; cursor: pointer;
}
.chip.active { background: var(--text-main); color: #000; font-weight: 600; }

/* Lists */
.fees-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid #333;
}
.segments-list, .history-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.segment-item, .hist-card {
  background: var(--bg-card); padding: 12px 16px; border-radius: var(--radius-md);
  display: flex; justify-content: space-between; align-items: center;
}

/* Goal Widget */
.goal-card { background: var(--bg-card); border: 1px solid #333; padding: 16px; margin-bottom: 16px; }
.goal-title { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.progress-track { width: 100%; height: 6px; background: #333; border-radius: 4px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.5s;}
.goal-percent { color: var(--primary); font-weight: 700; font-size: 12px; }

/* Toast */
#toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 3000; width: 90%; max-width: 400px; }
.toast {
  background: #333; color: white; padding: 14px 20px; border-radius: 12px;
  margin-top: 8px; text-align: center; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border-left: 4px solid var(--primary); font-size: 14px;
}

/* --- ГРАФИКИ (Charts) --- */
.chart-container {
  width: 220px; height: 220px; margin: 20px auto; position: relative;
}

/* 1. Главный график (Yandex Style - Single Color) */
.donut-chart {
  width: 100%; height: 100%; border-radius: 50%; position: relative;
  background: #333333; display: flex; align-items: center; justify-content: center;
}
.donut-chart::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--primary) var(--percent-deg), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 12px), #fff calc(100% - 11px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 12px), #fff calc(100% - 11px));
  z-index: 1;
}
.chart-dot-wrapper {
  position: absolute; inset: 0; transform: rotate(var(--percent-deg)); z-index: 3; pointer-events: none;
}
.chart-dot {
  position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
  width: 8px; height: 8px; background: #FFFFFF; border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

/* 2. График истории (Multi Color) */
.donut-chart-multi {
  width: 100%; height: 100%; border-radius: 50%; position: relative;
  background: #333; display: flex; align-items: center; justify-content: center;
}
/* Дырка для обоих графиков */
.donut-hole {
  width: calc(100% - 24px); height: calc(100% - 24px);
  background: var(--bg-app); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 2;
}

.chart-val { font-size: 42px; font-weight: 800; color: var(--text-main); line-height: 1; margin-bottom: 4px; }
.chart-label { font-size: 14px; color: var(--text-muted); font-weight: 500; }

.chart-legend { display: flex; gap: 16px; justify-content: center; margin-bottom: 20px; flex-wrap: wrap;} 
.legend-item { font-size: 12px; display: flex; align-items: center; gap: 6px;}
.dot { width: 8px; height: 8px; border-radius: 50%; }
/* --- Cities autocomplete --- */
.city-suggest{
  margin-top: 8px;
  background: #1c1c1c;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
}
.city-suggest .city-item{
  padding: 10px 12px;
  cursor: pointer;
  display:flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.city-suggest .city-item:last-child{ border-bottom:none; }
.city-suggest .city-item:hover{ background: rgba(252,224,0,0.08); }
.city-suggest .city-name{ font-weight: 600; }
.city-suggest .city-region{ color: var(--text-muted); font-size: 12px; }

/* --- Rating list --- */
.rating-list{ display:flex; flex-direction:column; gap:10px; }
.rating-row{
  background: var(--bg-card);
  border-radius: 14px;
  padding: 12px 14px;
  display:flex;
  justify-content: space-between;
  align-items:center;
  border: 1px solid rgba(255,255,255,0.06);
}
.rating-left{ display:flex; flex-direction:column; gap:4px; }
.rating-city{ font-weight: 800; }
.rating-sub{ color: var(--text-muted); font-size: 12px; }
.rating-right{ text-align:right; display:flex; flex-direction:column; gap:4px; }
.rating-main{ font-weight:800; font-size: 16px; }
.rating-mini{ color: var(--text-muted); font-size: 12px; }
.expenses-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.expense-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 12px 12px;
}

.expense-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.expense-title {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 62vw;
}

.expense-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.expense-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.expense-amount {
  font-weight: 700;
  color: #ff5252;
}

.icon-mini {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
