/* ═══════════ Семейный бюджет · стили ═══════════ */
:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --income: #16a34a;
  --expense: #ef4444;
  --radius: 16px;
  --tab-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input {
  font-family: inherit; font-size: 16px; width: 100%;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #94a3b8; }
h1, h2, h3 { margin: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* ═══════════ вход ═══════════ */
.login {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 32px 24px;
  background: linear-gradient(160deg, #eef4ff 0%, #f2f4f8 60%);
}
.login-logo {
  width: 76px; height: 76px; border-radius: 22px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff; font-size: 40px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 26px rgba(59,130,246,.35); margin-bottom: 18px;
}
.login h1 { font-size: 24px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 6px 0 26px; }
.login input { max-width: 340px; margin-bottom: 12px; }
.login .btn-primary, .login .btn-ghost { max-width: 340px; width: 100%; }
.login-msg { color: var(--expense); font-size: 14px; max-width: 340px; text-align: center; min-height: 20px; margin-top: 10px; }

/* ═══════════ кнопки ═══════════ */
.btn-primary {
  border: 0; background: var(--accent); color: #fff;
  padding: 14px 20px; border-radius: 12px; font-size: 16px; font-weight: 600;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .55; }
.btn-ghost {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 13px 20px; border-radius: 12px; font-size: 15px; margin-top: 10px;
}
.btn-link { border: 0; background: none; color: var(--accent); font-size: 14px; margin-top: 18px; }
.btn-danger {
  border: 1px solid #fecaca; background: #fff5f5; color: var(--expense);
  padding: 13px 20px; border-radius: 12px; font-size: 15px; font-weight: 600; width: 100%;
}

/* ═══════════ каркас приложения ═══════════ */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.who { font-size: 13px; color: var(--muted); background: var(--bg); padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); }
.banner {
  background: #fff7ed; color: #c2410c; font-size: 13px;
  padding: 8px 16px; border-bottom: 1px solid #fed7aa;
}
.content { flex: 1; padding: 16px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 84px); max-width: 640px; width: 100%; margin: 0 auto; }

/* ═══════════ переключатель месяца ═══════════ */
.month-switch {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.ms-label { font-size: 17px; font-weight: 700; }
.ms-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff;
  font-size: 20px; color: var(--muted); line-height: 1;
}
.ms-btn:active { background: var(--bg); }

/* ═══════════ карточки сумм ═══════════ */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.card-label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }
.card-value { font-size: 22px; font-weight: 800; letter-spacing: -.4px; }
.card-income .card-value { color: var(--income); }
.card-expense .card-value { color: var(--expense); }

/* ═══════════ графики ═══════════ */
.chart-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.chart-card h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.chart-wrap { position: relative; height: 250px; }
.chart-wrap-line { height: 200px; }
.chart-empty { text-align: center; color: #94a3b8; font-size: 14px; padding: 26px 0; }

/* ═══════════ фильтры ═══════════ */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips-wrap { max-height: 148px; overflow-y: auto; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.color-chip { width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 2px solid transparent; }
.color-chip.active { border-color: var(--text); transform: scale(1.08); }

/* ═══════════ история ═══════════ */
.day-group { margin-bottom: 16px; }
.day-head {
  display: flex; justify-content: space-between; font-size: 13px;
  color: var(--muted); font-weight: 600; padding: 0 4px 8px;
  text-transform: capitalize;
}
.tx-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  margin-bottom: 8px; box-shadow: 0 1px 2px rgba(15,23,42,.05);
}
.tx-row:active { background: #f8fafc; }
.tx-emoji {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-size: 15px; font-weight: 600; }
.tx-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { font-size: 15.5px; font-weight: 700; white-space: nowrap; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.history-empty { text-align: center; color: #94a3b8; padding: 40px 0; font-size: 15px; }

/* ═══════════ настройки ═══════════ */
.set-block {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.set-block h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.row2 input { min-width: 0; }
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 10px; border-radius: 12px; background: var(--bg);
}
.cat-row:active { background: var(--line); }
.cat-dot {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.cat-name { flex: 1; font-size: 15px; font-weight: 500; }
.cat-edit { color: #94a3b8; font-size: 15px; }
.btn-add-cat {
  margin-top: 10px; width: 100%; border: 1px dashed var(--line);
  background: none; color: var(--accent); padding: 11px;
  border-radius: 12px; font-size: 14.5px; font-weight: 600;
}
.conn-info { font-size: 14px; color: var(--muted); line-height: 1.5; margin-bottom: 12px; }
.set-footer { text-align: center; color: #cbd5e1; font-size: 12px; padding: 8px 0 4px; }

/* ═══════════ FAB + таббар ═══════════ */
.fab {
  position: fixed; right: 18px; z-index: 40;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 8px 22px rgba(37,99,235,.45);
}
.fab:active { transform: scale(.94); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  display: flex; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; padding-top: 6px;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ═══════════ листы ═══════════ */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.sheet {
  position: relative; width: 100%; max-width: 640px; margin: 0 auto;
  background: #fff; border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 24px);
  max-height: 92dvh; overflow-y: auto;
  animation: slideUp .24s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 19px; margin-bottom: 16px; }
.sheet .chips { margin-bottom: 14px; }
.sheet input { margin-bottom: 14px; }
.amount-input {
  font-size: 38px !important; font-weight: 800; text-align: center;
  padding: 16px 12px !important; letter-spacing: -1px;
  border-radius: 16px !important; background: var(--bg) !important;
}
.kind-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px;
}
.kind-btn {
  padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; font-size: 15px; font-weight: 600; color: var(--muted);
}
.kind-btn.active[data-kind="expense"] { background: #fef2f2; border-color: var(--expense); color: var(--expense); }
.kind-btn.active[data-kind="income"]  { background: #f0fdf4; border-color: var(--income); color: var(--income); }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn-primary { flex: 1; }
.sheet-error { color: var(--expense); font-size: 14px; margin-bottom: 10px; }

/* ═══════════ тост ═══════════ */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 90px);
  z-index: 80; background: #0f172a; color: #fff;
  padding: 11px 20px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(15,23,42,.35); max-width: 86vw; text-align: center;
}

@media (min-width: 640px) {
  .content { padding-top: 24px; }
}
