/* ==========================================================================
   FinBot Mini App — Emerald Glass Design System (v1)
   Только оформление. Логика, API и расчёты — в app.js / backend.
   ========================================================================== */

/* ---------------------------------------------------------------- TOKENS */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Inter", "Segoe UI", Roboto, Arial, sans-serif;

  /* Emerald palette (общая для обеих тем) */
  --emerald-950: #042219;
  --emerald-900: #063a2b;
  --emerald-800: #08573f;
  --emerald-700: #0a7a58;
  --emerald-600: #10a376;
  --emerald-500: #25cf95;
  --emerald-300: #8cefc6;
  --emerald-100: #d9f8ea;

  /* Radius */
  --r-xs: 10px;
  --r-sm: 14px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 30px;
  --r-pill: 999px;

  /* Spacing (4px grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  /* Typography scale */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 22px;
  --fs-hero: clamp(32px, 9.6vw, 44px);

  /* Blur levels */
  --blur-sm: 10px;
  --blur-md: 18px;

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --duration-fast: 140ms;
  --duration-base: 220ms;

  /* Layout */
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html[data-theme="dark"], :root:not([data-theme]) {
  color-scheme: dark;
  --bg: #06100d;
  --bg-deep: #030806;
  --bg-elev: #0b1914;          /* непрозрачная поверхность для sheet/tabbar-fallback */
  --glow-1: rgba(22, 170, 118, .22);
  --glow-2: rgba(10, 110, 80, .18);

  --surface-1: rgba(255, 255, 255, .035);
  --surface-2: rgba(255, 255, 255, .06);
  --surface-3: rgba(255, 255, 255, .09);

  --glass: linear-gradient(160deg, rgba(26, 58, 47, .62), rgba(12, 30, 24, .62));
  --glass-premium: linear-gradient(155deg, rgba(24, 140, 100, .50) 0%, rgba(9, 70, 51, .70) 48%, rgba(5, 36, 27, .86) 100%);
  --glass-accent: linear-gradient(150deg, rgba(37, 207, 149, .16), rgba(10, 90, 64, .26));

  --text-strong: #f3fff9;
  --text: #dcece5;
  --muted: #8fada1;
  --text-on-accent: #032116;
  --text-on-premium: #effff8;
  --muted-on-premium: rgba(225, 255, 240, .72);

  --success: #3ddc9f;
  --warning: #f2bd62;
  --danger: #f3707c;

  --line: rgba(190, 255, 225, .10);
  --line-strong: rgba(190, 255, 225, .18);
  --line-accent: rgba(90, 236, 170, .34);

  --btn-primary-bg: linear-gradient(180deg, #33dba2 0%, #17b585 100%);
  --btn-primary-fg: #032116;
  --btn-soft-bg: rgba(37, 207, 149, .12);
  --btn-soft-fg: #8cefc6;

  --shadow-1: 0 8px 24px rgba(0, 0, 0, .22);
  --shadow-2: 0 18px 48px rgba(0, 0, 0, .38);
  --shadow-emerald: 0 12px 30px rgba(16, 180, 125, .22);
  --inner-hl: inset 0 1px 0 rgba(255, 255, 255, .07);

  --tabbar-bg: rgba(7, 18, 14, .78);
  --sk: rgba(255, 255, 255, .06);
  --sk-hi: rgba(255, 255, 255, .11);

  /* совместимость со старыми inline-стилями в app.js */
  --accent: var(--emerald-500);
  --accent-soft: rgba(37, 207, 149, .13);
  --green: var(--success);
  --red: var(--danger);
  --amber: var(--warning);
  --card: rgba(20, 44, 36, .72);
  --card-2: rgba(255, 255, 255, .06);
  --shadow: var(--shadow-1);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef5f1;
  --bg-deep: #e3eee8;
  --bg-elev: #ffffff;
  --glow-1: rgba(37, 207, 149, .20);
  --glow-2: rgba(16, 163, 118, .12);

  --surface-1: rgba(6, 58, 43, .035);
  --surface-2: rgba(6, 58, 43, .055);
  --surface-3: rgba(6, 58, 43, .08);

  --glass: linear-gradient(160deg, rgba(255, 255, 255, .86), rgba(255, 255, 255, .70));
  --glass-premium: linear-gradient(155deg, #13a074 0%, #0a6f51 50%, #064a36 100%);
  --glass-accent: linear-gradient(150deg, rgba(37, 207, 149, .16), rgba(16, 163, 118, .08));

  --text-strong: #06170f;
  --text: #13281f;
  --muted: #587266;
  --text-on-accent: #ffffff;
  --text-on-premium: #f3fff9;
  --muted-on-premium: rgba(235, 255, 246, .78);

  --success: #0c9467;
  --warning: #b87408;
  --danger: #d23d4b;

  --line: rgba(6, 58, 43, .09);
  --line-strong: rgba(6, 58, 43, .16);
  --line-accent: rgba(16, 163, 118, .35);

  --btn-primary-bg: linear-gradient(180deg, #12a577 0%, #0b8661 100%);
  --btn-primary-fg: #ffffff;
  --btn-soft-bg: rgba(16, 163, 118, .10);
  --btn-soft-fg: #08704f;

  --shadow-1: 0 6px 20px rgba(6, 58, 43, .07);
  --shadow-2: 0 16px 40px rgba(6, 58, 43, .12);
  --shadow-emerald: 0 12px 28px rgba(10, 122, 88, .22);
  --inner-hl: inset 0 1px 0 rgba(255, 255, 255, .7);

  --tabbar-bg: rgba(248, 252, 250, .86);
  --sk: rgba(6, 58, 43, .06);
  --sk-hi: rgba(6, 58, 43, .11);

  --accent: #0c8f67;
  --accent-soft: rgba(16, 163, 118, .11);
  --green: var(--success);
  --red: var(--danger);
  --amber: var(--warning);
  --card: #ffffff;
  --card-2: rgba(6, 58, 43, .05);
  --shadow: var(--shadow-1);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

/* Фоновое emerald-свечение. pointer-events: none — никогда не перехватывает касания */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(120% 60% at 0% -10%, var(--glow-1), transparent 60%),
    radial-gradient(90% 50% at 110% 10%, var(--glow-2), transparent 65%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

#app { min-height: 100vh; min-height: 100dvh; }

button { font-family: inherit; }
.num, .value, .tx__amount, .hero__value { font-variant-numeric: tabular-nums; }

.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor;
       stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- BOOT */
.boot {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
}
.boot__logo { font-size: 38px; animation: pulse 1.6s ease-in-out 3; }
.boot__text { color: var(--muted); font-size: 14px; }
@keyframes pulse { 0%,100% { opacity: .45; } 50% { opacity: 1; } }

/* ------------------------------------------------------------ ONBOARDING */
.onb {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; gap: 16px;
  padding: calc(20px + var(--safe-t)) 20px calc(24px + var(--safe-b));
}
.onb__progress { height: 4px; background: var(--surface-3); border-radius: var(--r-pill); overflow: hidden; }
.onb__bar { height: 100%; width: 0; background: var(--emerald-500); border-radius: var(--r-pill);
            transition: width .35s var(--ease); }
.onb__body { flex: 1; }
.onb__body h1 { font-size: 27px; line-height: 1.15; margin: 18px 0 8px; letter-spacing: -.5px; color: var(--text-strong); }
.onb__lead { color: var(--muted); margin: 0 0 22px; font-size: 15px; }
.onb__extra { margin-top: 14px; display: grid; gap: 10px; }

/* ---------------------------------------------------------------- CHIPS */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 10px 15px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 15px; font-family: inherit; cursor: pointer;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease);
}
.chip:active { transform: scale(.97); }
.chip.is-on {
  background: var(--btn-primary-bg); border-color: transparent; color: var(--btn-primary-fg);
  box-shadow: var(--shadow-emerald);
}
.chip--wide { width: 100%; justify-content: space-between; }
.chip--sm { min-height: 38px; padding: 7px 13px; font-size: 14px; border-radius: var(--r-pill); }
.chip--ai {
  min-height: 38px; padding: 7px 13px 7px 11px; font-size: 13.5px; border-radius: var(--r-pill);
  background: var(--accent-soft); border-color: var(--line-accent); color: var(--btn-soft-fg);
}
.chip--ai .ico { width: 15px; height: 15px; }
.chip--cat { min-height: 40px; padding: 8px 12px; font-size: 14px; border-radius: var(--r-sm); }

/* -------------------------------------------------------------- BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 13px 18px;
  border: none; border-radius: var(--r-sm);
  font-size: 15px; font-weight: 650; font-family: inherit; letter-spacing: -.1px;
  cursor: pointer; text-decoration: none;
  transition: transform var(--duration-fast) var(--ease), opacity var(--duration-fast), box-shadow var(--duration-base);
}
.btn:active { transform: scale(.98); }
.btn:disabled, .btn.is-loading { opacity: .55; cursor: default; }
.btn--primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); box-shadow: var(--shadow-emerald), var(--inner-hl); }
.btn--soft { background: var(--btn-soft-bg); color: var(--btn-soft-fg); }
.btn--ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn--danger { background: transparent; color: var(--danger); border: 1px solid var(--line-strong); }
.btn--block { width: 100%; display: flex; }
.btn--sm { min-height: 40px; padding: 8px 13px; font-size: 14px; border-radius: var(--r-pill); }
.btn--sm .ico { width: 16px; height: 16px; }
.btn + .btn--block, .btn--block + .btn--block { margin-top: 10px; }

.iconbtn {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--muted); font-size: 15px; cursor: pointer;
}

.link-btn {
  background: none; border: none; padding: 8px 2px; min-height: 36px;
  color: var(--btn-soft-fg); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 2px;
}
.link-btn .ico { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- SHELL */
.shell { padding-bottom: calc(var(--tabbar-h) + 28px + var(--safe-b)); }
.view {
  padding: calc(14px + var(--safe-t)) 16px 8px;
  max-width: 620px; margin: 0 auto;
}
.view > * { animation: rise var(--duration-base) var(--ease) both; }
.view > *:nth-child(2) { animation-delay: 30ms; }
.view > *:nth-child(3) { animation-delay: 60ms; }
.view > *:nth-child(4) { animation-delay: 90ms; }
.view > *:nth-child(5) { animation-delay: 120ms; }
.view > *:nth-child(n+6) { animation-delay: 150ms; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* --------------------------------------------------------------- TABBAR */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-width: 620px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(6px + var(--safe-b));
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .tabbar { background: var(--tabbar-bg); -webkit-backdrop-filter: blur(var(--blur-md)) saturate(140%);
            backdrop-filter: blur(var(--blur-md)) saturate(140%); }
}
.tab {
  position: relative;
  min-height: 52px; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; border-radius: var(--r-sm);
  color: var(--muted); font-size: 11px; font-weight: 550; font-family: inherit; cursor: pointer;
  transition: color var(--duration-fast) var(--ease);
}
.tab svg { width: 23px; height: 23px; transition: transform var(--duration-base) var(--ease); }
.tab.is-active { color: var(--text-strong); }
.tab.is-active svg { color: var(--emerald-500); transform: translateY(-1px); }
.tab.is-active::before {
  content: ""; position: absolute; top: 2px; left: 50%; width: 34px; height: 30px;
  transform: translateX(-50%); border-radius: var(--r-pill);
  background: var(--accent-soft); z-index: -1;
}

/* ------------------------------------------------------------------ FAB */
.fab {
  position: fixed; z-index: 21;
  right: max(16px, calc((100vw - 620px) / 2 + 16px));
  bottom: calc(var(--tabbar-h) + 16px + var(--safe-b));
  width: 56px; height: 56px; border-radius: 18px; border: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  box-shadow: var(--shadow-emerald), var(--shadow-1), var(--inner-hl);
  cursor: pointer; transition: transform var(--duration-fast) var(--ease);
}
.fab:active { transform: scale(.93); }
body[data-page="assistant"] .fab { display: none; }

/* ----------------------------------------------------------- TYPOGRAPHY */
.page-head { display: flex; align-items: center; gap: 10px; min-height: 48px; margin: 2px 0 12px; }
.page-head .page-title { margin: 0; flex: 1; min-width: 0; }
.page-head__action { flex: none; }
.page-title { font-size: 26px; line-height: 1.15; font-weight: 750; letter-spacing: -.6px;
              color: var(--text-strong); margin: 4px 0 14px; }
.back {
  width: 40px; height: 40px; flex: none; margin-left: -6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); cursor: pointer;
}
.back .ico { width: 20px; height: 20px; }

.section-title { font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase;
                 letter-spacing: .7px; margin: 22px 2px 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 8px; }
.section-head .section-title { margin: 0; }

.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .2px; }
.label { color: var(--muted); font-size: 13px; }
.value { font-size: 30px; font-weight: 750; letter-spacing: -.8px; margin: 4px 0 0; color: var(--text-strong); }
.value--sm { font-size: 21px; letter-spacing: -.4px; }
.card-title { font-size: var(--fs-lg); font-weight: 700; margin: 0 0 6px; color: var(--text-strong); letter-spacing: -.2px; }
.card-text { margin: 0 0 16px; color: var(--muted); font-size: 14.5px; }
.footnote { text-align: center; color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row + .row { margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 12px; }

.pos { color: var(--success); }
.neg { color: var(--danger); }
.muted { color: var(--muted); }

/* ------------------------------------------------------ SURFACES / CARDS */
/* Level 2 — standard glass */
.card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-1), var(--inner-hl);
}
.card--list { padding-top: 4px; padding-bottom: 4px; }

/* Level 3 — premium glass (баланс, ключевое состояние) */
.card--premium, .card--hero {
  background: var(--glass-premium);
  border: 1px solid rgba(160, 255, 215, .22);
  border-radius: var(--r-lg);
  color: var(--text-on-premium);
  padding: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-2), var(--shadow-emerald), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.card--premium::after, .card--hero::after {
  content: ""; position: absolute; pointer-events: none;
  top: -40%; right: -25%; width: 70%; height: 90%;
  background: radial-gradient(closest-side, rgba(140, 239, 198, .20), transparent);
}
.card--premium .label, .card--hero .label { color: var(--muted-on-premium); }
.card--premium .value, .card--hero .value { color: var(--text-on-premium); }
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  html[data-theme="dark"] .card--premium, html[data-theme="dark"] .card--hero {
    -webkit-backdrop-filter: blur(var(--blur-sm)); backdrop-filter: blur(var(--blur-sm));
  }
}

/* Level 4 — accent emerald glass (AI, цели, позитивные состояния) */
.card--accent {
  background: var(--glass-accent);
  border: 1px solid var(--line-accent);
}

/* ------------------------------------------------------------- HOME HERO */
.hero__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero__top .eyebrow { color: var(--muted-on-premium); }
.pill {
  display: inline-flex; align-items: center; min-height: 26px; padding: 3px 10px;
  border-radius: var(--r-pill); font-size: 12px; font-weight: 600;
  background: rgba(255, 255, 255, .12); color: var(--text-on-premium);
  border: 1px solid rgba(255, 255, 255, .14);
}
.hero__value {
  margin: 8px 0 2px; font-size: var(--fs-hero); line-height: 1.05; font-weight: 780;
  letter-spacing: -1.4px; color: var(--text-on-premium);
  overflow-wrap: anywhere;
}
.hero__safe {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  padding: 9px 12px; border-radius: var(--r-sm);
  background: rgba(0, 0, 0, .16); border: 1px solid rgba(255, 255, 255, .10);
  font-size: 13.5px; color: var(--muted-on-premium);
}
.hero__safe b { margin-left: auto; color: var(--text-on-premium); font-size: 15px; }
.hero__safe .ico { width: 16px; height: 16px; color: var(--emerald-300); }

.flow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.flow__item { min-width: 0; }
.flow__label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted-on-premium); }
.flow__item b { display: block; margin-top: 3px; font-size: 16px; font-weight: 700; letter-spacing: -.3px;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-on-premium); }
.flow__item b.neg { color: #ffb3ba; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot--in { background: var(--emerald-300); }
.dot--out { background: rgba(255, 255, 255, .55); }

.split { display: flex; gap: 3px; height: 6px; margin-top: 14px; border-radius: var(--r-pill); overflow: hidden; }
.split span { display: block; min-width: 4px; border-radius: var(--r-pill); transition: flex var(--duration-base) var(--ease); }
.split__in { background: var(--emerald-300); }
.split__out { background: rgba(255, 255, 255, .42); }
.split-caption { margin-top: 6px; font-size: 12px; color: var(--muted-on-premium); }

/* -------------------------------------------------------- QUICK ACTIONS */
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.qa {
  min-height: 68px; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-md);
  color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer;
  box-shadow: var(--inner-hl);
  transition: transform var(--duration-fast) var(--ease), border-color var(--duration-fast);
}
.qa:active { transform: scale(.96); }
.qa .ico { width: 22px; height: 22px; color: var(--emerald-500); }
.qa--primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); border-color: transparent;
               box-shadow: var(--shadow-emerald), var(--inner-hl); }
.qa--primary .ico { color: var(--btn-primary-fg); }
.qa--ai { border-color: var(--line-accent); background: var(--glass-accent); }

/* ----------------------------------------------------------- AI INSIGHT */
.ai__head { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700;
            text-transform: uppercase; letter-spacing: .6px; color: var(--btn-soft-fg); margin-bottom: 8px; }
.ai__head .ico { width: 16px; height: 16px; }
.ai__title { font-weight: 700; font-size: 16px; color: var(--text-strong); margin-bottom: 4px; letter-spacing: -.2px; }
.ai__body { color: var(--text); font-size: 14.5px; }
.ai details { margin-top: 10px; }
.ai summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 0; min-height: 32px; }
.ai details p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.ai__more-item { padding-top: 10px; margin-top: 10px; border-top: 1px solid var(--line); }
.ask-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.view > .ask-row { margin: 0 0 14px; }

/* insight — совместимость со старой разметкой */
.insight { border-left: 3px solid var(--emerald-500); padding-left: 12px; margin-bottom: 14px; }
.insight:last-child { margin-bottom: 0; }
.insight__title { font-weight: 650; margin-bottom: 4px; color: var(--text-strong); }
.insight__body { color: var(--muted); font-size: 14px; }
.insight__why { margin-top: 8px; font-size: 12.5px; color: var(--btn-soft-fg);
                background: var(--accent-soft); padding: 8px 10px; border-radius: var(--r-xs); }

/* ---------------------------------------------------------- ONBOARD CTA */
.onboard__icon {
  width: 44px; height: 44px; border-radius: 14px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--emerald-500);
}
.onboard__icon .ico { width: 22px; height: 22px; }

/* ---------------------------------------------------------- TRANSACTION */
.tx {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 60px; padding: 11px 0;
  background: none; border: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.tx + .tx { border-top: 1px solid var(--line); }
.tx:active { opacity: .7; }
.tx__icon {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.tx--income .tx__icon { background: var(--accent-soft); border-color: var(--line-accent); }
.tx__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx__title { font-weight: 620; font-size: 15px; color: var(--text-strong);
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx__sub { color: var(--muted); font-size: 12.5px; margin-top: 2px;
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx__amount { flex: none; text-align: right; font-weight: 700; font-size: 15.5px; letter-spacing: -.2px;
              white-space: nowrap; color: var(--text-strong); display: flex; flex-direction: column; align-items: flex-end; }
.tx__amount.pos { color: var(--success); }
.tx__type { font-size: 11.5px; font-weight: 500; color: var(--muted); margin-top: 2px; letter-spacing: 0; }

/* ------------------------------------------------------------- PROGRESS */
.bar { height: 8px; background: var(--surface-3); border-radius: var(--r-pill); overflow: hidden; margin-top: 10px; }
.bar--lg { height: 10px; }
.bar__fill {
  height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--emerald-600), var(--emerald-500) 60%, var(--emerald-300));
  transition: width .5s var(--ease);
}
.bar__fill--warn { background: var(--warning); }
.bar__fill--over { background: var(--danger); }

.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 9px; border-radius: var(--r-pill);
         font-size: 12.5px; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge--ok { background: var(--accent-soft); color: var(--btn-soft-fg); }
.badge--warn { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); }
.badge--over { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.note { margin-top: 10px; padding: 9px 11px; border-radius: var(--r-xs); font-size: 13px; }
.note--warn { background: color-mix(in srgb, var(--warning) 12%, transparent); color: var(--warning); }
.note--danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ------------------------------------------------------- GOALS / BUDGETS */
.goal__top, .budget__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.goal__title, .budget__name { font-weight: 680; font-size: 16px; color: var(--text-strong);
                              min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal__pct { font-weight: 750; font-size: 18px; color: var(--emerald-500); letter-spacing: -.3px; }
.goal__amount { margin-top: 6px; color: var(--muted); font-size: 14px; }
.goal__amount b { color: var(--text-strong); font-size: 18px; letter-spacing: -.3px; }
.goal__meta, .budget__nums { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
                             margin-top: 10px; font-size: 13px; color: var(--muted); }
.budget__nums b { color: var(--text-strong); font-weight: 650; }

.mini { display: block; width: 100%; padding: 12px 0; background: none; border: none; color: inherit;
        font: inherit; text-align: left; cursor: pointer; }
.mini + .mini { border-top: 1px solid var(--line); }
.mini .bar { margin-top: 8px; height: 6px; }
.mini__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14.5px; }
.mini__row span:first-child { font-weight: 600; color: var(--text-strong); min-width: 0;
                              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini__row .muted { font-size: 13px; white-space: nowrap; }
.card .mini:first-child { padding-top: 2px; }
.card .mini:last-child { padding-bottom: 2px; }

/* -------------------------------------------------------------- ACCOUNT */
.acc { display: flex; align-items: center; gap: 12px; }
.acc__icon { width: 42px; height: 42px; flex: none; border-radius: 13px; display: flex; align-items: center;
             justify-content: center; font-size: 19px; background: var(--surface-2); border: 1px solid var(--line); }
.acc__main { flex: 1; min-width: 0; }
.acc__name { font-weight: 650; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc__bal { font-weight: 720; font-size: 16px; color: var(--text-strong); white-space: nowrap; }

/* ------------------------------------------------------ SEARCH / FILTERS */
.search { position: relative; margin-bottom: 10px; }
.search .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .search__input { padding-left: 44px; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; margin-bottom: 4px;
           scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.filters::-webkit-scrollbar { display: none; }
.filters .chip { flex: none; }
.filters-more { margin: 4px 0 6px; }

/* ----------------------------------------------------- EMPTY / ERROR / LOADING */
.empty {
  text-align: center; padding: 34px 20px 26px; color: var(--muted);
  background: var(--glass); border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
  margin-bottom: 12px;
}
.empty--inline { padding: 22px 16px; margin-top: 10px; }
.empty__icon { font-size: 34px; margin-bottom: 10px; line-height: 1; }
.empty__title { font-size: 17px; font-weight: 700; color: var(--text-strong); margin-bottom: 6px; letter-spacing: -.2px; }
.empty__text { font-size: 14.5px; max-width: 340px; margin: 0 auto; }
.empty__actions { margin-top: 18px; display: grid; gap: 10px; }
.empty--error .empty__icon { color: var(--warning); }

.skeleton { display: grid; gap: 12px; }
.sk-card { display: grid; gap: 12px; }
.sk-row { display: flex; gap: 10px; }
.sk-row .sk { flex: 1; }
.sk {
  height: 12px; border-radius: 8px;
  background: linear-gradient(90deg, var(--sk) 0%, var(--sk-hi) 50%, var(--sk) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.card--premium .sk { background: linear-gradient(90deg, rgba(255,255,255,.10), rgba(255,255,255,.18), rgba(255,255,255,.10));
                     background-size: 200% 100%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ------------------------------------------------------------ MORE MENU */
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 13px 16px; margin-bottom: 8px;
  color: var(--text-strong); font-size: 15px; font-weight: 560; font-family: inherit; text-align: left; cursor: pointer;
  box-shadow: var(--inner-hl);
  transition: transform var(--duration-fast) var(--ease);
}
.menu-item:active { transform: scale(.985); background: var(--surface-3); }
.menu-item__icon {
  width: 36px; height: 36px; flex: none; border-radius: 11px; font-size: 18px;
  display: flex; align-items: center; justify-content: center; background: var(--surface-2);
}
.menu-item__chev { margin-left: auto; color: var(--muted); }

/* ---------------------------------------------------------------- FORMS */
.field { margin-bottom: 14px; }
.field[hidden] { display: none; }
.field__label { display: block; color: var(--muted); font-size: 13px; font-weight: 550; margin-bottom: 7px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  color: var(--text-strong); font-size: 16px; font-family: inherit;
  -webkit-appearance: none; appearance: none;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
select.input {
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus { outline: none; border-color: var(--emerald-500); box-shadow: 0 0 0 3px var(--accent-soft); }
.input--amount { font-size: 32px; font-weight: 750; letter-spacing: -.8px; text-align: center; min-height: 64px; }

.amount-field { position: relative; margin-bottom: 16px; }
.amount-field .input--amount { padding-left: 76px; padding-right: 76px; }
.amount-field__cur {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  min-height: 40px; padding: 6px 10px; border-radius: 11px;
  background: var(--surface-3); border: 1px solid var(--line); color: var(--text-strong);
  font: inherit; font-size: 14px; font-weight: 650; -webkit-appearance: none; appearance: none; cursor: pointer;
}

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 14px;
       padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.seg__btn {
  min-height: 42px; padding: 8px 6px;
  background: transparent; border: none; border-radius: 11px;
  color: var(--muted); font-size: 14.5px; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast);
}
.seg__btn.is-on { background: var(--btn-primary-bg); color: var(--btn-primary-fg); box-shadow: var(--inner-hl); }

.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; max-height: 148px; overflow-y: auto; padding: 1px; }

details.advanced { margin: 4px 0 14px; }
details.advanced summary {
  display: flex; align-items: center; min-height: 40px; padding: 6px 0;
  color: var(--btn-soft-fg); font-size: 14px; font-weight: 600; cursor: pointer; list-style: none;
}
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::after { content: "›"; margin-left: 8px; font-size: 18px; transition: transform var(--duration-fast); }
details.advanced[open] summary::after { transform: rotate(90deg); }

.ai-entry {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px;
  margin-bottom: 14px; padding: 11px 14px;
  background: var(--glass-accent); border: 1px solid var(--line-accent); border-radius: var(--r-md);
  color: var(--text-strong); text-align: left; font: inherit; cursor: pointer;
}
.ai-entry:active { transform: scale(.99); }
.ai-entry__icon { width: 36px; height: 36px; flex: none; border-radius: 11px; display: flex; align-items: center;
                  justify-content: center; background: var(--btn-primary-bg); color: var(--btn-primary-fg); }
.ai-entry__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ai-entry__text b { font-size: 15px; }
.ai-entry__text span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-entry > .ico { color: var(--muted); }

/* --------------------------------------------------------- BOTTOM SHEET */
/* Скрытие — нативным атрибутом hidden. .sheet не задаёт display, чтобы hidden
   работал; правило ниже — дополнительная страховка только для этого элемента. */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet[hidden] { display: none; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(1, 8, 5, .58); animation: fade var(--duration-base) ease both; }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1;
  max-width: 620px; margin: 0 auto;
  max-height: 90vh; max-height: 90dvh;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 8px 18px calc(22px + var(--safe-b));
  background: var(--bg-elev);
  border: 1px solid var(--line-strong); border-bottom: none;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: 0 -18px 48px rgba(0, 0, 0, .35);
  animation: sheet-up .26s var(--ease) both;
}
html[data-theme="dark"] .sheet__panel {
  background: linear-gradient(180deg, #10241d 0%, var(--bg-elev) 140px);
}
@keyframes sheet-up { from { transform: translateY(24px); } to { transform: none; } }
.sheet__handle { width: 40px; height: 4px; background: var(--line-strong); border-radius: var(--r-pill); margin: 2px auto 10px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet__head h2 { margin: 0; font-size: 20px; font-weight: 720; letter-spacing: -.3px; color: var(--text-strong); }
.sheet__body { padding-bottom: 6px; }
.sheet__body > .card { background: var(--surface-1); box-shadow: none; }
html.sheet-open, html.sheet-open body { overflow: hidden; }

/* ---------------------------------------------------------------- TOAST */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + 86px + var(--safe-b));
  max-width: min(88vw, 480px); padding: 12px 16px;
  background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  color: var(--text-strong); font-size: 14px; text-align: center;
  pointer-events: none;
  box-shadow: var(--shadow-2);
  animation: fade var(--duration-base) ease both;
}
.toast[hidden] { display: none; }
html.sheet-open .toast { top: calc(12px + var(--safe-t)); bottom: auto; }

/* ------------------------------------------------------------ ASSISTANT */
.chat { display: flex; flex-direction: column; gap: 10px; min-height: 30vh; }
.bubble { padding: 11px 14px; border-radius: 18px; max-width: 88%; white-space: pre-wrap; font-size: 14.5px;
          animation: rise var(--duration-base) var(--ease) both; }
.bubble--bot { background: var(--glass); border: 1px solid var(--line); align-self: flex-start;
               border-bottom-left-radius: 6px; color: var(--text); }
.bubble--me { background: var(--btn-primary-bg); color: var(--btn-primary-fg); align-self: flex-end;
              border-bottom-right-radius: 6px; font-weight: 520; }
.chat__input {
  position: sticky; bottom: calc(var(--tabbar-h) + 10px + var(--safe-b)); z-index: 5;
  display: flex; gap: 8px; margin-top: 14px; padding: 6px;
  background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
}
.chat__input .input { border: none; background: transparent; box-shadow: none; }
.chat__input .btn { min-height: 46px; }
.chat-examples { margin-top: 12px; }

/* ----------------------------------------------------------- RESPONSIVE */
@media (max-width: 360px) {
  .view { padding-left: 12px; padding-right: 12px; }
  .card--premium, .card--hero { padding: 16px; }
  .flow__item b { font-size: 14.5px; }
  .quick { gap: 6px; }
  .qa { min-height: 62px; font-size: 11.5px; }
  .tab { font-size: 10px; }
  .page-title { font-size: 23px; }
}
@media (min-width: 700px) {
  .onb { max-width: 560px; margin: 0 auto; }
  .view { padding-top: calc(22px + var(--safe-t)); }
}
@media (hover: hover) {
  .btn:hover, .qa:hover, .menu-item:hover, .chip:hover { filter: brightness(1.05); }
}

/* ------------------------------------------------------- REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
