/* ============================================================
   Семейные финансы — «тёплый премиальный fintech»
   Палитра: кремовый фон, изумруд (деньги/доверие), охра (акцент)
   Шрифты: Fraunces (display) + Manrope (body)
   ============================================================ */

:root {
  --bg: #F3F7F5;
  --bg-tint: #E7EFEB;
  --surface: #FFFFFF;
  --surface-2: #F5F9F7;
  --ink: #17231D;
  --ink-soft: #4A554E;
  --muted: #8C8A7E;
  --emerald: #0B5D4E;
  --emerald-700: #084439;
  --emerald-100: #DCEBE5;
  --accent: #D98E32;
  --accent-soft: #F6E4C9;
  --danger: #C0552B;
  --danger-soft: #F5DACB;
  --warn: #D98E32;
  --line: rgba(27, 38, 33, 0.10);
  --line-strong: rgba(27, 38, 33, 0.18);
  --shadow-sm: 0 1px 2px rgba(27, 38, 33, .06), 0 2px 8px rgba(27, 38, 33, .05);
  --shadow-md: 0 6px 24px rgba(11, 93, 78, .10), 0 2px 8px rgba(27, 38, 33, .06);
  --shadow-lg: 0 20px 50px rgba(11, 93, 78, .16);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 26px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", -apple-system, "Segoe UI", sans-serif;
}

/* Тёмная тема */
:root[data-theme="dark"] {
  --bg: #12160F;
  --bg-tint: #1C2119;
  --surface: #1A1F17;
  --surface-2: #232A1F;
  --ink: #ECEAE0;
  --ink-soft: #B6BBAE;
  --muted: #8A8F80;
  --emerald: #3FA98D;
  --emerald-700: #2E7D6B;
  --emerald-100: #1E332C;
  --accent: #E0A458;
  --accent-soft: #3A2E1A;
  --danger: #E07A50;
  --danger-soft: #3A251C;
  --line: rgba(236, 234, 224, 0.10);
  --line-strong: rgba(236, 234, 224, 0.18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 550px at 88% -12%, rgba(11, 93, 78, .07), transparent 60%),
    radial-gradient(800px 460px at -12% 112%, rgba(63, 169, 141, .06), transparent 55%);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
a { color: var(--emerald); }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
  background: var(--surface);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { min-width: 0; }
.topbar .brand span:not(.logo) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--emerald), var(--emerald-700));
  color: #fff; font-size: 1.05rem; box-shadow: var(--shadow-sm);
}
.who { display: flex; align-items: center; gap: 12px; color: var(--ink-soft); font-size: .92rem; }
.who .chip { padding: 5px 12px; border-radius: 999px; background: var(--emerald-100); color: var(--emerald-700); font-weight: 600; }
.who a { text-decoration: none; color: var(--muted); }
.who a:hover { color: var(--danger); }

.wrap { max-width: 1080px; margin: 0 auto;
  padding: 26px 20px calc(80px + env(safe-area-inset-bottom)); }

/* ---------- Auth ---------- */
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 34px 30px; box-shadow: var(--shadow-lg);
}
.auth-card .logo-lg {
  width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--emerald), var(--emerald-700));
  color: #fff; font-size: 1.5rem; margin-bottom: 18px; box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: 1.7rem; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 22px; font-size: .95rem; }
.auth-card .foot { text-align: center; margin-top: 18px; color: var(--muted); font-size: .92rem; }

/* ---------- Forms ---------- */
label.fld { display: block; font-size: .82rem; color: var(--ink-soft); font-weight: 600; margin: 0 0 6px 2px; }
.input, input:not([type]), input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select {
  width: 100%; padding: 12px 14px; font-family: var(--font-body); font-size: 1rem;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.input:focus, input:focus, select:focus {
  border-color: var(--emerald); background: #fff;
  box-shadow: 0 0 0 4px rgba(11, 93, 78, .12);
}
.stack > * + * { margin-top: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; font-family: var(--font-body); font-weight: 700; font-size: .98rem;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  transition: transform .08s ease, box-shadow .15s, background .15s; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(140deg, var(--emerald), var(--emerald-700)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: var(--shadow-md); }
.btn-accent { background: var(--accent); color: #3a2708; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-icon { width: 46px; height: 46px; padding: 0; border-radius: 50%; }
.btn-sm { padding: 8px 12px; font-size: .85rem; }

/* ---------- Flash ---------- */
.flash { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash .msg {
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: #6b4409; border: 1px solid rgba(217, 142, 50, .35);
  font-size: .93rem; animation: slidein .35s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin: 22px 0 20px; overflow-x: auto; padding-bottom: 4px; }
.tab {
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-soft); font-weight: 600; font-size: .9rem;
  cursor: pointer; white-space: nowrap; transition: all .15s;
}
.tab:hover { border-color: var(--emerald); }
.tab.active { background: var(--emerald); color: #fff; border-color: var(--emerald); box-shadow: var(--shadow-sm); }
.panel { display: none; animation: fade .3s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card h3 { font-size: 1.15rem; margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: .86rem; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Hero stats ---------- */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; margin-bottom: 6px; }
@media (max-width: 720px) { .hero { grid-template-columns: 1fr; } }
.hero-main {
  background: linear-gradient(150deg, var(--emerald), var(--emerald-700));
  color: #fff; border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.hero-main::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(217,142,50,.35), transparent 70%);
}
.hero-main .greeting { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; margin-bottom: 14px; }
.hero-main .greeting:empty { display: none; }
.hero-main .lbl { opacity: .8; font-size: .82rem; letter-spacing: .04em; text-transform: uppercase; }
.hero-main .big { font-family: var(--font-display); font-size: 2.5rem; font-weight: 600; margin: 4px 0 12px; }
.hero-row { display: flex; gap: 20px; }
.hero-row .k { opacity: .8; font-size: .8rem; }
.hero-row .v { font-size: 1.15rem; font-weight: 700; }

.health {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 22px; display: flex; gap: 18px; align-items: center; box-shadow: var(--shadow-sm);
}
.gauge { --p: 0; --c: var(--emerald); width: 96px; height: 96px; flex: 0 0 96px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--emerald-100) 0);
  display: grid; place-items: center; position: relative; }
.gauge::before { content: ""; position: absolute; inset: 10px; background: var(--surface); border-radius: 50%; }
.gauge .g-val { position: relative; font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; }
.health .h-label { font-family: var(--font-display); font-size: 1.3rem; }
.health .h-sub { color: var(--muted); font-size: .88rem; }
.safe-pill { margin-top: 8px; display: inline-block; padding: 6px 12px; border-radius: 999px;
  background: var(--accent-soft); color: #6b4409; font-weight: 700; font-size: .9rem; }

/* ---------- Quick add ---------- */
.qa-row { display: flex; gap: 10px; }
.qa-row .input { font-size: 1.1rem; padding: 14px 16px; }
.qa-tools { display: flex; gap: 10px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: .9rem; cursor: pointer; }
.mic-live { color: var(--danger); font-weight: 700; display: none; align-items: center; gap: 6px; }
.mic-live.on { display: inline-flex; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* Модальное окно предпросмотра голоса */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: flex;
  align-items: center; justify-content: center; padding: 18px;
  background: rgba(23, 35, 29, .55); backdrop-filter: blur(3px); animation: fade .2s ease; }
.modal-card { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 22px; width: 100%; max-width: 460px;
  box-shadow: var(--shadow-lg); max-height: 90vh; overflow-y: auto; }
.preview-op { display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--surface-2); }
.preview-op select { flex: 1.4; min-width: 0; padding: 8px 10px; }
.preview-op input { flex: 1; min-width: 0; padding: 8px 10px; }
.preview-op .rm { background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 1rem; padding: 4px 8px; border-radius: 8px; flex: 0 0 auto; }
.preview-op .rm:hover { color: var(--danger); background: var(--danger-soft); }

/* Фильтр периода */
.period-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 18px; }
.pchip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-soft); font-weight: 600; font-size: .85rem;
  text-decoration: none; transition: all .15s; }
.pchip:hover { border-color: var(--emerald); color: var(--emerald); }
.pchip.on { background: var(--emerald); color: #fff; border-color: var(--emerald); }
.pcustom { display: flex; gap: 6px; align-items: center; margin: 0 0 0 auto; flex-wrap: wrap; }

/* Быстрые кнопки частых трат */
.quick-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip-btn { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-soft); font-family: var(--font-body);
  font-weight: 600; font-size: .85rem; cursor: pointer; transition: all .15s; }
.chip-btn:hover { border-color: var(--emerald); color: var(--emerald); background: var(--surface-2); }

/* Segmented toggle (Семейная / Личная) */
.seg { display: inline-flex; background: var(--bg-tint); border-radius: 999px; padding: 4px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 8px 16px; border-radius: 999px;
  font-family: var(--font-body); font-weight: 700; font-size: .86rem; color: var(--ink-soft);
  cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.seg button.active { background: #fff; color: var(--emerald); box-shadow: var(--shadow-sm); }
.seg button.active.priv-active { color: var(--accent); }
.mic-btn.listening { background: var(--danger) !important; color: #fff !important; animation: pulse 1.2s infinite; }

/* ---------- Transactions ---------- */
.txn { display: flex; align-items: center; gap: 14px; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.txn:last-child { border-bottom: none; }
.txn .ic { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 1.2rem; }
.txn .meta { flex: 1; min-width: 0; }
.txn .meta .t1 { font-weight: 600; }
.txn .meta .t2 { color: var(--muted); font-size: .82rem; }
.txn .amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn .amt.inc { color: var(--emerald); }
.badge { font-size: .7rem; padding: 3px 9px; border-radius: 999px; font-weight: 700; }
.badge.fam { background: var(--emerald-100); color: var(--emerald-700); }
.badge.priv { background: var(--bg-tint); color: var(--ink-soft); }
.txn form { margin: 0; }
.x-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px 8px; border-radius: 8px; }
.x-btn:hover { color: var(--danger); background: var(--danger-soft); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Budgets ---------- */
.bud { padding: 14px 0; border-bottom: 1px solid var(--line); }
.bud:last-child { border-bottom: none; }
.bud .bud-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.bud .bud-name { font-weight: 600; }
.bud .bud-nums { font-size: .86rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 999px; background: var(--bg-tint); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; transition: width .6s ease; }
.lvl-ok > span { background: var(--emerald); }
.lvl-warn > span { background: var(--accent); }
.lvl-over > span { background: var(--danger); }
.bud .bud-alert { font-size: .8rem; margin-top: 6px; font-weight: 600; }
.lvl-warn .bud-alert { color: #6b4409; }
.lvl-over .bud-alert { color: var(--danger); }

/* ---------- Goals ---------- */
.goal { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--surface-2); }
.goal .g-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.goal .g-ic { font-size: 1.6rem; }
.goal .g-name { font-weight: 700; }
.goal .g-dl { color: var(--muted); font-size: .8rem; }
.goal .g-nums { display: flex; justify-content: space-between; font-size: .86rem; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.goal .g-forms { display: flex; gap: 8px; margin-top: 12px; }
.goal .g-forms input { padding: 8px 10px; }

/* ---------- Chat ---------- */
.chat-log { display: flex; flex-direction: column; gap: 12px; max-height: 420px; overflow-y: auto; padding: 4px; margin-bottom: 14px; }
.bubble { max-width: 84%; padding: 12px 15px; border-radius: 16px; font-size: .94rem; white-space: pre-wrap; line-height: 1.5; }
.bubble.me { align-self: flex-end; background: var(--emerald); color: #fff; border-bottom-right-radius: 5px; }
.bubble.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.ai.think { color: var(--muted); font-style: italic; }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.suggest button { font-size: .82rem; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); cursor: pointer; }
.suggest button:hover { border-color: var(--emerald); color: var(--emerald); }

.chart-box { position: relative; height: 300px; }
.section-title { font-family: var(--font-display); font-size: 1.4rem; margin: 4px 2px 2px; }
.ai-note { font-size: .82rem; color: var(--muted); margin-top: 8px; }
.ai-off { background: var(--accent-soft); border: 1px solid rgba(217,142,50,.35); color: #6b4409;
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: 14px; }
