/* ==================================================================
   Personal Finance Tracker — стили
   Дизайн: минималистичная темная тема в духе банковских приложений.
   Токены палитры определены как CSS-переменные в :root.
   ================================================================== */

:root {
  --bg: #12141c;
  --surface-1: #1a1d28;
  --surface-2: #232734;
  --surface-3: #2c3140;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);

  --text-primary: #f2f3f7;
  --text-secondary: #9297aa;
  --text-muted: #5b6072;

  --accent: #7c6ff0;
  --accent-dim: rgba(124, 111, 240, 0.16);
  --income: #34d6b5;
  --income-dim: rgba(52, 214, 181, 0.16);
  --danger: #ff6b6d;
  --danger-dim: rgba(255, 107, 109, 0.16);
  --warning: #ffb84d;
  --warning-dim: rgba(255, 184, 77, 0.16);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 96px;
  min-height: 100vh;
}

.screen { display: none; padding-top: 20px; animation: fadeIn 0.2s ease; }
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar-eyebrow {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.topbar-balance {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-top: 2px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ---------- Stats grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface-1);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--border);
}
.stat-card.wide { grid-column: 1 / -1; }
.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.stat-value.small { font-size: 15px; font-weight: 600; }

/* ---------- Budget ring ---------- */
.budget-ring-section {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.budget-ring { width: 84px; height: 84px; flex-shrink: 0; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--surface-3); stroke-width: 10; }
.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.6s cubic-bezier(.4,0,.2,1), stroke 0.3s;
}
.budget-ring-section .ring-center {
  position: absolute;
  left: 18px;
  width: 84px;
  height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-percent { font-size: 17px; font-weight: 800; }
.ring-caption { font-size: 10px; color: var(--text-secondary); }
.budget-detail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}
.budget-detail span { font-weight: 700; margin-right: 6px; }
.budget-detail small { color: var(--text-secondary); font-size: 12px; }

/* ---------- Section titles ---------- */
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 10px;
}

/* ---------- Quick add ---------- */
.quick-add {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 20px;
}
.type-toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 14px;
}
.type-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 13px;
  padding: 9px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.type-btn.active { background: var(--surface-3); color: var(--text-primary); }
.type-btn[data-type="expense"].active { color: var(--danger); }
.type-btn[data-type="income"].active { color: var(--income); }
.type-btn[data-type="transfer"].active { color: var(--accent); }

.amount-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}
.amount-input {
  width: 100%;
  max-width: 220px;
  text-align: center;
  background: transparent;
  border: none;
  outline: none;
  font-size: 44px;
  font-weight: 800;
  color: var(--text-primary);
  -moz-appearance: textfield;
}
.amount-input::-webkit-outer-spin-button,
.amount-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.currency-suffix { font-size: 24px; font-weight: 700; color: var(--text-secondary); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}
.chip-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.chip-btn.ghost { background: transparent; color: var(--text-secondary); border-style: dashed; }

.chip-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.chip-search-row .text-input { flex: 1; }

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.field-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  min-width: 58px;
}

.text-input, .select-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
  width: 100%;
  outline: none;
}
.text-input:focus, .select-input:focus, .amount-input:focus { border-color: var(--accent); }
.select-input.compact { width: auto; padding: 8px 10px; font-size: 13px; }

#qa-comment { margin-bottom: 14px; }

.primary-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  padding: 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn.income { background: var(--income); }
.primary-btn.transfer { background: var(--accent); }

.secondary-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.secondary-btn.danger { color: var(--danger); border-color: var(--danger); }

/* ---------- Transaction list ---------- */
.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
}
.tx-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-title { font-size: 14px; font-weight: 700; }
.tx-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-size: 15px; font-weight: 800; white-space: nowrap; }
.tx-amount.expense { color: var(--danger); }
.tx-amount.income { color: var(--income); }
.tx-amount.transfer { color: var(--accent); }

/* ---------- Insights ---------- */
.insights-list { display: flex; flex-direction: column; gap: 8px; }
.insight-item {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Analytics ---------- */
.callout {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  line-height: 1.5;
}
.chart-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}
.chart-section canvas { width: 100%; display: block; }
.pie-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; }
.pie-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.pie-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.top-list-section { margin-bottom: 18px; }
.top10-list { display: flex; flex-direction: column; gap: 6px; }
.top10-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.top10-rank { width: 18px; color: var(--text-muted); font-weight: 700; }
.top10-bar-track { flex: 1; height: 6px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.top10-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.top10-amount { font-weight: 700; white-space: nowrap; }

/* ---------- History filters ---------- */
.filters { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.filters-row { display: flex; gap: 8px; }
.filters-row .select-input { flex: 1; }

/* ---------- Settings ---------- */
.settings-block {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}
.accounts-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.account-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.account-row .name { flex: 1; font-weight: 700; font-size: 14px; }
.account-row .balance { font-weight: 700; font-size: 14px; color: var(--text-secondary); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-label { cursor: pointer; }
.settings-categories { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-cat-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 10px 7px 12px; font-size: 12px;
}
.settings-cat-chip button {
  border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(26, 29, 40, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 20px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end;
  z-index: 100;
}
.modal {
  background: var(--surface-1);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .primary-btn, .modal-actions .secondary-btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-40px);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: all 0.25s ease;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------- Utility ---------- */
.text-danger { color: var(--danger); }
.text-income { color: var(--income); }
.empty-state { text-align: center; color: var(--text-muted); font-size: 13px; padding: 30px 10px; }

@media (min-width: 481px) {
  body { background: #0a0b10; }
  .app { background: var(--bg); min-height: 100vh; box-shadow: 0 0 60px rgba(0,0,0,0.4); }
}
