/* UZEX AI — палитра «Lapis & Gold»: лазурит и бирюза Регистана, золото для денежных сумм. */
/* Onest (OFL) лежит локально в fonts/: кириллица, латиница и узбекские ўқғҳ / oʻ gʻ */
@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/onest-cyrillic-ext.woff2) format("woff2"); unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/onest-cyrillic.woff2) format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/onest-latin-ext.woff2) format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/onest-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
:root {
  --bg: #f7f9fb;
  --side: #eef3f7;
  --surface: #ffffff;
  --surface-2: #eaf0f5;
  --hover: rgba(11, 99, 206, .07);
  --border: #dfe7ee;
  --border-strong: #c6d3df;
  --text: #0b1620;
  --muted: #53616f;
  --faint: #8f9ba7;
  --accent: #0b63ce;
  --accent-hover: #0952ad;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefc;
  --brand: linear-gradient(135deg, #0b63ce 0%, #0ea5b7 100%);   /* логотип, кнопка отправки */
  --brand-ink: #ffffff;
  --brand-shine: linear-gradient(90deg, #0b63ce, #0ea5b7, #3b8fe8, #0b63ce);  /* перелив «AI», пока идёт ответ */
  --num: #0b4fa6;                                              /* объёмы и количества в ответе */
  --gold: #a16207;    --gold-soft: #fdf3d7;                     /* деньги: сум, USD */
  --ok: #0f7a4a;      --ok-soft: #e1f3e8;
  --warn: #a35a00;    --warn-soft: #fbefd9;
  --bad: #b42318;     --bad-soft: #fbe6e3;
  --shadow-sm: 0 1px 2px rgba(11, 22, 32, .05);
  --shadow: 0 1px 2px rgba(11, 22, 32, .04), 0 8px 24px -8px rgba(11, 99, 206, .14);
  --shadow-lift: 0 2px 4px rgba(11, 22, 32, .05), 0 16px 40px -12px rgba(11, 99, 206, .24);
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --side-w: 268px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070d17; --side: #050a12; --surface: #0d1726; --surface-2: #142236; --hover: rgba(120, 180, 255, .07);
    --border: #1c2a3f; --border-strong: #2b3e59;
    --text: #e8eef6; --muted: #97a6b8; --faint: #62748a;
    --accent: #3b9eff; --accent-hover: #63b3ff; --accent-ink: #04101f; --accent-soft: #0c2a4a;
    --brand: linear-gradient(135deg, #1d6fe0 0%, #14b8c6 100%);
    --brand-shine: linear-gradient(90deg, #1d6fe0, #14b8c6, #7cc4ff, #1d6fe0);
    --num: #7cc4ff; --gold: #f2c14e; --gold-soft: #33280c;
    --ok: #4ad295; --ok-soft: #10301f; --warn: #f0a443; --warn-soft: #33240f; --bad: #ff8070; --bad-soft: #3a1915;
    --shadow-sm: none; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px -12px rgba(29, 111, 224, .28);
    --shadow-lift: 0 2px 4px rgba(0,0,0,.45), 0 18px 44px -12px rgba(29, 111, 224, .42);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #070d17; --side: #050a12; --surface: #0d1726; --surface-2: #142236; --hover: rgba(120, 180, 255, .07);
  --border: #1c2a3f; --border-strong: #2b3e59;
  --text: #e8eef6; --muted: #97a6b8; --faint: #62748a;
  --accent: #3b9eff; --accent-hover: #63b3ff; --accent-ink: #04101f; --accent-soft: #0c2a4a;
  --brand: linear-gradient(135deg, #1d6fe0 0%, #14b8c6 100%);
  --brand-shine: linear-gradient(90deg, #1d6fe0, #14b8c6, #7cc4ff, #1d6fe0);
  --num: #7cc4ff; --gold: #f2c14e; --gold-soft: #33280c;
  --ok: #4ad295; --ok-soft: #10301f; --warn: #f0a443; --warn-soft: #33240f; --bad: #ff8070; --bad-soft: #3a1915;
  --shadow-sm: none; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px -12px rgba(29, 111, 224, .28);
  --shadow-lift: 0 2px 4px rgba(0,0,0,.45), 0 18px 44px -12px rgba(29, 111, 224, .42);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15.5px/1.6 var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app { display: flex; height: 100vh; height: 100dvh; }
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.col { width: 100%; max-width: 800px; margin: 0 auto; padding: 0 20px; }

/* ---------------------------------------------------------------- боковая панель */
.side {
  width: var(--side-w); flex: none; display: flex; flex-direction: column; gap: 6px;
  background: var(--side); border-right: 1px solid var(--border); padding: 10px 10px 12px;
  transition: margin-left .28s var(--ease), transform .28s var(--ease);
}
.side-collapsed .side { margin-left: calc(-1 * var(--side-w)); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 8px 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); }
.logo * { transform-box: fill-box; transform-origin: center; }
.logo .lg-line, .logo .lg-hi { fill: none; stroke: var(--brand-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; }
.logo .lg-hi { opacity: 0; stroke-dasharray: .3 1; }
.logo .lg-dot { fill: var(--brand-ink); stroke: none; }
.logo .lg-ring { fill: none; stroke: var(--brand-ink); stroke-width: 1.2; opacity: 0; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.brand-title em { font-style: normal; color: var(--accent); background: var(--brand); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

/* «живой график»: в покое знак неподвижен.
   Загрузка (.logo-in) и наведение — линия прорисовывается, точка «последней цены» всплывает;
   пока модель отвечает (.busy) — по линии бежит импульс, точка пульсирует, «AI» переливается */
@media (prefers-reduced-motion: no-preference) {
  .logo-in .logo .lg-line { animation: logo-draw .7s var(--ease) both; }
  .logo-in .logo .lg-dot { animation: logo-dot .35s .55s cubic-bezier(.34, 1.56, .64, 1) both; }
  .brand:hover .logo .lg-line { animation: logo-draw-h .6s var(--ease) both; }
  .brand:hover .logo .lg-dot { animation: logo-dot-h .3s .45s cubic-bezier(.34, 1.56, .64, 1) both; }
  .busy .brand .logo .lg-line { animation: logo-dim .3s both; }
  .busy .brand .logo .lg-hi { opacity: 1; animation: logo-comet 1.1s cubic-bezier(.45, 0, .55, 1) infinite; }
  .busy .brand .logo .lg-ring { animation: logo-ring 1.4s ease-out infinite; }
  .busy .brand-title em { background: var(--brand-shine); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; animation: logo-shine 2.4s linear infinite; }
}
@keyframes logo-draw { from { stroke-dashoffset: 1; } }
@keyframes logo-draw-h { from { stroke-dashoffset: 1; } }
@keyframes logo-dot { from { transform: scale(0); } }
@keyframes logo-dot-h { from { transform: scale(0); } }
@keyframes logo-dim { to { opacity: .45; } }
@keyframes logo-comet { from { stroke-dashoffset: .3; } to { stroke-dashoffset: -1; } }
@keyframes logo-ring { from { transform: scale(1); opacity: .9; } to { transform: scale(2.8); opacity: 0; } }
@keyframes logo-shine { to { background-position: 200% 0; } }

.new-chat {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-sm); transition: border-color .15s, transform .12s var(--ease);
}
.new-chat:hover { border-color: var(--accent); }
.new-chat:active { transform: scale(.98); }
.new-chat svg { color: var(--accent); }

.history { flex: 1; overflow-y: auto; margin: 8px -4px 0; padding: 0 4px; scrollbar-width: thin; }
.h-group { font-size: 12px; font-weight: 600; color: var(--faint); padding: 14px 10px 4px; }
.h-group:first-child { padding-top: 4px; }
.h-item { position: relative; display: flex; align-items: center; border-radius: 9px; }
.h-item:hover, .h-item.on { background: var(--hover); }
.h-item.on .h-open { color: var(--text); font-weight: 500; }
.h-open {
  flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 7px 10px; font-size: 14px;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 9px;
}
.h-item:hover .h-open { color: var(--text); }
.h-open .pend { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: 1px; animation: pulse 1.2s ease-in-out infinite; }
/* «⋯» у строки: видно при наведении, у открытого чата и пока открыто меню */
.h-more {
  flex: none; width: 28px; height: 28px; margin-right: 4px; border: 0; border-radius: 7px; background: none; color: var(--muted);
  display: grid; place-items: center; opacity: 0; transition: opacity .12s, color .12s, background .12s;
}
.h-more svg { width: 18px; height: 18px; stroke-width: 3; }
.h-item:hover .h-more, .h-item.on .h-more, .h-item.menu-open .h-more, .h-more:focus-visible { opacity: 1; }
.h-more:hover, .h-item.menu-open .h-more { color: var(--text); background: var(--hover); }
.h-item.menu-open { background: var(--hover); }
@media (hover: none) { .h-more { opacity: .7; } }

/* окно переименования */
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -4px -6px 14px 0; }
.dialog-head h3 { margin: 0; }
.icon-btn {
  flex: none; width: 32px; height: 32px; border: 0; border-radius: 9px; background: none; color: var(--muted);
  display: grid; place-items: center; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg, .field-clear svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.field { position: relative; }
.field input {
  width: 100%; height: 46px; padding: 0 40px 0 14px; font: 15px var(--font); color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: 12px; outline: 0;
  transition: border-color .15s, background .15s, box-shadow .2s var(--ease);
}
.field input:hover { border-color: var(--border); }
.field input:focus { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px;
  border: 0; border-radius: 8px; background: none; color: var(--faint); display: grid; place-items: center;
}
.field-clear:hover { color: var(--text); background: var(--hover); }
.field-clear svg { width: 15px; height: 15px; }
.field-meta { display: flex; justify-content: space-between; gap: 12px; margin: 8px 2px 20px; font-size: 12px; color: var(--faint); }
#rnCount { font-variant-numeric: tabular-nums; transition: color .15s; }
#rnCount.near { color: var(--warn); }
@media (hover: none) { .field-meta span:first-child { visibility: hidden; } }

/* уведомление внизу экрана */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 14px; border-radius: 14px; background: var(--text); color: var(--bg);
  font-size: 14px; box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .45);
  animation: toast-in .24s var(--ease) both;
}
.toast[hidden] { display: none; }
.toast.out { animation: toast-out .18s ease both; }
.toast svg { flex: none; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.toast span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast button {
  flex: none; height: 30px; padding: 0 12px; border: 0; border-radius: 9px; background: none;
  color: inherit; font-size: 14px; font-weight: 600; opacity: .85; transition: background .15s, opacity .15s;
}
.toast button:hover { opacity: 1; background: color-mix(in srgb, var(--bg) 14%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px) scale(.97); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 6px); } }

/* выпадающее меню */
.menu {
  position: fixed; z-index: 40; min-width: 200px; padding: 5px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-lift); animation: pop .14s var(--ease) both;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--text); font-size: 14px; text-align: left;
}
.menu-item svg { width: 16px; height: 16px; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: 0; }
.menu-item.danger, .menu-item.danger svg { color: var(--bad); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--bad-soft); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }

/* окно подтверждения */
.dialog {
  width: min(420px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px -16px rgba(0, 0, 0, .35);
}
.dialog[open] { animation: pop .2s var(--ease) both; }
.dialog::backdrop { background: rgba(10, 12, 14, .45); animation: fade .2s ease both; }
.dialog form { padding: 22px 22px 18px; }
.dialog h3 { margin: 0 0 8px; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.dialog p { margin: 0 0 22px; color: var(--muted); font-size: 14.5px; line-height: 1.5; overflow-wrap: anywhere; }
.dialog p b { color: var(--text); font-weight: 600; }
.dialog-acts { display: flex; justify-content: flex-end; gap: 8px; }
.btn {
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 600; transition: background .15s, border-color .15s, filter .15s, transform .12s var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.danger { background: var(--bad); color: var(--surface); border-color: transparent; }
.btn.primary:hover, .btn.danger:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .35; cursor: default; transform: none; filter: none; }
.h-search { position: relative; margin-top: 2px; }
.h-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); pointer-events: none; }
.h-search input {
  width: 100%; height: 36px; padding: 0 10px 0 33px; font: 13.5px var(--font); color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 10px; outline: 0; transition: background .15s, border-color .15s;
}
.h-search input::placeholder { color: var(--faint); }
.h-search input:hover { background: var(--hover); }
.h-search input:focus { background: var(--surface); border-color: var(--border-strong); }
.h-empty { font-size: 13px; color: var(--faint); padding: 10px; line-height: 1.5; }
/* низ панели — строка «профиля», как в ChatGPT / Claude; по клику меню над ней */
.side-foot { padding-top: 8px; border-top: 1px solid var(--border); }
.me {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 12px;
  background: none; color: var(--text); text-align: left; transition: background .15s;
}
.me:hover, .me[aria-expanded="true"] { background: var(--hover); }
.me:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.me-ava {
  position: relative; flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: #fff;
  box-shadow: 0 0 0 2px var(--side), 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}
.me-ava svg { width: 17px; height: 17px; }
.me-dot {
  position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--faint); border: 2px solid var(--side); transition: background .3s;   /* серая — пока не проверили */
}
.me[data-net="on"] .me-dot { background: var(--ok); }
.me[data-net="on"] .me-dot::after {                   /* «пульс» — сервис на связи */
  content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--ok);
  animation: ping 2.6s cubic-bezier(0, 0, .2, 1) infinite;
}
.me[data-net="off"] .me-dot { background: var(--bad); }
.me-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.me-txt b { font-size: 13.5px; font-weight: 600; }
.me-txt small { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.me-chev { width: 16px; height: 16px; color: var(--faint); transition: color .15s; }
.me:hover .me-chev, .me[aria-expanded="true"] .me-chev { color: var(--text); }
@keyframes ping { 0% { transform: scale(.5); opacity: .9; } 75%, 100% { transform: scale(1.9); opacity: 0; } }

.menu-note { display: flex; gap: 10px; padding: 8px 10px 9px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.menu-note svg { width: 16px; height: 16px; margin-top: 1px; color: var(--ok); }
.menu-item:disabled { opacity: .45; pointer-events: none; }

.scrim { position: fixed; inset: 0; z-index: 19; background: rgba(10, 12, 14, .42); animation: fade .2s ease both; }

/* ---------------------------------------------------------------- шапка */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 58px; padding: 0 16px; flex: none;
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
body:not(.home) .top { border-bottom-color: var(--border); }
.top-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.top-left .brand { margin-left: 6px; }
.top-left .logo { width: 26px; height: 26px; }
:root:not(.side-collapsed) .top-left > * { display: none; }      /* панель открыта — всё это есть в ней */
.top-actions { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); transition: color .15s; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; transition: background .15s, border-color .15s;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn.flat { border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn.flat:hover { background: var(--hover); color: var(--text); }
/* строка «Язык» в меню профиля: иконка, подпись, справа переключатель */
.menu-row {
  display: flex; align-items: center; gap: 10px; padding: 5px 5px 5px 10px; min-height: 40px;
  font-size: 14px; color: var(--text);
}
.menu-row > svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.menu-row .lang { margin-left: auto; }
/* язык — «биржевое табло»: подсвеченная плашка ездит под выбранным кодом */
.lang {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: 30px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  transition: border-color .15s;
}
.lang:hover { border-color: var(--border-strong); }
.lang::before {
  content: ""; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 7px;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 38%, transparent),
              0 0 14px -2px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .38s cubic-bezier(.3, 1.35, .5, 1);
}
.lang[data-on="uz"]::before { transform: translateX(100%); }
.lang button {
  position: relative; z-index: 1; min-width: 34px; padding: 0 9px; border: 0; background: none; border-radius: 7px;
  font: 600 12.5px/1 var(--font); letter-spacing: .06em; font-variant-numeric: tabular-nums;
  color: var(--muted); transition: color .2s;
}
.lang button:hover { color: var(--text); }
.lang button.on { color: var(--accent); }
.lang button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* тема — солнце ⇄ месяц; иконка показывает текущую тему */
.theme-btn:hover { color: var(--accent); }
.sun-moon { overflow: visible; }
.sun-moon .sm-core { fill: currentColor; stroke: none; transform-box: view-box; transform-origin: 12px 12px; }
.sun-moon .sm-bite { transform-box: view-box; transform: translate(8px, -8px); }
.sun-moon .sm-rays { transform-box: view-box; transform-origin: 12px 12px; }
.sun-moon .sm-core, .sun-moon .sm-bite, .sun-moon .sm-rays {
  transition: transform .5s cubic-bezier(.3, 1.3, .5, 1), opacity .25s;
}
:root[data-theme="dark"] .sm-core { transform: scale(1.7); }
:root[data-theme="dark"] .sm-bite { transform: none; }
:root[data-theme="dark"] .sm-rays { transform: rotate(-60deg) scale(.4); opacity: 0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sm-core { transform: scale(1.7); }
  :root:not([data-theme="light"]) .sm-bite { transform: none; }
  :root:not([data-theme="light"]) .sm-rays { transform: rotate(-60deg) scale(.4); opacity: 0; }
}

/* смена темы: новая тема расходится кругом от кнопки (View Transitions; круг рисует JS) */
:root.vt-theme::view-transition-old(root),
:root.vt-theme::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* мобильная: панель — выезжающий ящик поверх чата */
@media (max-width: 900px) {
  .side {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; margin-left: 0 !important;
    width: min(300px, 86vw); transform: translateX(-100%); box-shadow: none;
  }
  body.drawer .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .top-left > * { display: inline-flex !important; }
  .top { padding: 0 10px 0 8px; }
}
@media (max-width: 420px) { .top-left .brand-title { display: none; } }

/* ---------------------------------------------------------------- главная */
main { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 0 12px; display: flex; flex-direction: column; }
main > .col { flex: 1; display: flex; flex-direction: column; }
/* главная по центру: заголовок → поле → сетка 2×2 из карточек-примеров */
.hero { margin: auto 0; padding: 24px 0 32px; text-align: center; position: relative; isolation: isolate; }
.hero::before {                                   /* мягкое свечение за заголовком — без картинок */
  content: ""; position: absolute; z-index: -1; left: 50%; top: -40px; width: min(640px, 100%); height: 280px;
  transform: translateX(-50%); pointer-events: none; opacity: .55;
  background: radial-gradient(closest-side, var(--accent-soft), transparent);
}
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted);
  border: 1px solid var(--border); background: var(--surface); padding: 4px 12px 4px 10px; border-radius: 999px; margin-bottom: 18px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hero h1 {
  font-size: clamp(28px, 4.4vw, 40px); line-height: 1.12; letter-spacing: -.03em; font-weight: 700;
  margin: 0 auto 12px; max-width: 30ch; text-wrap: balance;
}
.lead { color: var(--muted); font-size: 16px; margin: 0 auto 28px; max-width: 48ch; text-wrap: balance; }
body.home .ask { text-align: left; }
body.home .hint { display: none; }

.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 0; text-align: left; }
.ex {
  display: flex; flex-direction: column; gap: 8px; min-width: 0; text-align: left;
  border: 1px solid var(--border); background: var(--surface); border-radius: 16px;
  padding: 12px 14px 14px; color: var(--muted); font-size: 14px; line-height: 1.4;
  transition: border-color .2s var(--ease), color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
  animation: rise .4s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms);
}
.ex-top { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--faint); }
.ex-ic { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.ex-ic svg { width: 15px; height: 15px; }
.ex-ic.t-price, .ex-ic.t-export { background: var(--gold-soft); color: var(--gold); }
.ex-ic.t-top, .ex-ic.t-broker { background: var(--ok-soft); color: var(--ok); }
.ex-q { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-wrap: pretty; }
@media (hover: hover) {
  .ex:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); transform: translateY(-2px); }
}
.ex:active { transform: scale(.98); }

/* Telegram-бот: кнопка в шапке + карточка под примерами (QR для телефона на ПК) */
.tg-btn { color: var(--muted); text-decoration: none; }
.tg-btn svg { fill: currentColor; stroke: none; }
.tg-btn:hover { color: #229ed9; }
.tg-card {
  display: flex; align-items: center; gap: 14px; margin: 12px 0 0; padding: 12px 12px 12px 14px; text-align: left;
  border: 1px solid var(--border); border-radius: 16px; color: var(--text); text-decoration: none;
  background: linear-gradient(100deg, color-mix(in srgb, #229ed9 9%, var(--surface)), var(--surface) 60%);
  transition: border-color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
  animation: rise .4s var(--ease) both; animation-delay: 220ms;
}
.tg-ic {
  width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(160deg, #37aee2, #1e96c8); box-shadow: 0 6px 16px -6px rgba(34, 158, 217, .6);
}
.tg-ic svg { width: 22px; height: 22px; fill: #fff; margin-left: -2px; }
.tg-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.tg-txt small { font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--faint); }
.tg-txt b { font-size: 17px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; }
.tg-sub { font-size: 13px; color: var(--muted); }
.tg-go {
  display: inline-flex; align-items: center; gap: 4px; flex: none; height: 32px; padding: 0 12px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: #fff; background: #229ed9; transition: background .15s;
}
.tg-go svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s var(--ease); }
.tg-qr { flex: none; width: 76px; height: 76px; padding: 2px; border-radius: 10px; background: #fff; border: 1px solid var(--border); }
.tg-qr svg { display: block; width: 100%; height: 100%; fill: none; stroke: #0b1620; stroke-width: 1; }
@media (hover: hover) {
  .tg-card:hover { border-color: color-mix(in srgb, #229ed9 45%, var(--border)); transform: translateY(-2px); box-shadow: var(--shadow); }
  .tg-card:hover .tg-go { background: #1a8bc2; }
  .tg-card:hover .tg-go svg { transform: translate(1px, -1px); }
}
.tg-card:active { transform: scale(.99); }
.tg-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 600px) {
  .tg-qr, .tg-sub { display: none; }                 /* на телефоне QR не нужен — просто нажать */
  .tg-card { padding: 10px 12px; gap: 12px; }
  .tg-ic { width: 38px; height: 38px; }
  .tg-ic svg { width: 19px; height: 19px; }
  .tg-txt b { font-size: 15.5px; }
  .tg-txt small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tg-go { width: 32px; padding: 0; justify-content: center; }   /* только стрелка — подпись не влезает */
  .tg-go > span { display: none; }
}
@media (max-width: 600px) {
  .col { padding: 0 16px; }
  .hero { padding: 8px 0 24px; }
  .eyebrow { margin-bottom: 14px; }
  .lead { font-size: 15.5px; margin-bottom: 20px; }
  /* на телефоне — компактный список: иконка темы + вопрос + стрелка */
  .examples { grid-template-columns: 1fr; gap: 0; margin: 12px 0 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
  .ex { flex-direction: row; align-items: center; gap: 12px; border: 0; border-radius: 0; padding: 11px 14px; background: none; color: var(--text); font-size: 14.5px; }
  .ex + .ex { border-top: 1px solid var(--border); }
  .ex::after { content: "→"; margin-left: auto; color: var(--faint); }
  .ex-top { font-size: 0; gap: 0; }                 /* подпись темы прячем, иконка остаётся */
}

/* ---------------------------------------------------------------- поле ввода */
.dock { flex: none; padding: 6px 0 max(12px, env(safe-area-inset-bottom)); }
body.home .dock { display: none; }
.box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 8px 8px 8px 18px; box-shadow: var(--shadow);
  transition: border-color .2s var(--ease), box-shadow .25s var(--ease), transform .25s var(--ease);
}
.box:hover { border-color: var(--border-strong); }
.box:focus-within { border-color: var(--border-strong); box-shadow: var(--shadow-lift); transform: translateY(-1px); }
@media (prefers-reduced-motion: reduce) { .box:focus-within { transform: none; } }
/* фокус показывает сама .box — у поля свою обводку убираем (перебивает глобальный :focus-visible) */
textarea, textarea:focus-visible { outline: 0; }
textarea {
  flex: 1 0 100%; min-width: 0; border: 0; resize: none; background: transparent; color: var(--text);
  font: 16px/1.5 var(--font); max-height: 180px; padding: 7px 0;
}
textarea::placeholder { color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.home .box { padding: 12px 10px 12px 20px; border-radius: 20px; }
body.home textarea { font-size: 17px; }
#send {
  width: 38px; height: 38px; border-radius: 12px; border: 0; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; transition: background .15s, transform .12s var(--ease), opacity .15s;
}
#send:not(:disabled):hover { filter: brightness(1.08) saturate(1.1); }
#send:active { transform: scale(.94); }
#send:disabled { opacity: .35; cursor: default; }
#send .i-stop { display: none; }
#send.stop { background: var(--text); color: var(--bg); }
#send.stop .i-send { display: none; }
#send.stop .i-stop { display: block; fill: currentColor; stroke: none; width: 16px; height: 16px; }
/* голос: микрофон слева от отправки; во время записи поле сменяется полосой с волной */
.mic, .mic-x {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 12px; background: none; color: var(--muted);
  display: grid; place-items: center; transition: color .12s, background .12s, transform .12s var(--ease);
}
.mic > * { grid-area: 1 / 1; }
.mic:hover, .mic-x:hover { color: var(--text); background: var(--surface-2); }
.mic:active, .mic-x:active { transform: scale(.92); }
.mic .i-ok, .mic .spin, .mic-x { display: none; }
.mic svg { width: 19px; height: 19px; }
.spin {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
/* режим ответа: ползунок на 3 положения во второй строке поля, слева от микрофона */
.mode {
  --p: 50%; display: flex; align-items: center; gap: 7px; height: 38px; margin: 0 auto 0 -6px; padding: 0 8px 0 6px;
  border-radius: 12px; color: var(--faint); font-size: 13px; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background .15s;
}
.mode:hover { background: var(--surface-2); }
.mode svg { width: 16px; height: 16px; transition: color .2s, transform .25s var(--ease); }
.mode[data-m="fast"] .m-fast, .mode[data-m="smart"] .m-smart { color: var(--accent); transform: scale(1.12); }
.mode-name { min-width: 62px; color: var(--muted); font-weight: 500; transition: color .2s; }
.mode[data-m="smart"] .mode-name { color: var(--accent); }
.mode input {
  -webkit-appearance: none; appearance: none; width: 74px; height: 22px; margin: 0; background: transparent; cursor: pointer;
}
.mode input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 11px; }
.mode input::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: var(--brand) 0 0 / var(--p) 100% no-repeat, var(--border);
  transition: background-size .2s var(--ease);
}
.mode input::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: var(--shadow-sm);
  transition: transform .15s var(--ease);
}
.mode input:active::-webkit-slider-thumb { transform: scale(1.18); }
.mode input::-moz-range-track { height: 4px; border-radius: 2px; background: var(--border); }
.mode input::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--brand); }
.mode input::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); box-shadow: var(--shadow-sm);
}
@media (prefers-reduced-motion: reduce) { .mode svg, .mode input::-webkit-slider-runnable-track { transition: none; } }
.box.rec .mode, .box.stt .mode { display: none; }

.rec-bar { display: none; flex: 1; min-width: 0; align-items: center; gap: 10px; height: 38px; }
.rec-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
.rec-time { flex: none; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 34px; }
.rec-wave { flex: 1; min-width: 0; height: 28px; color: var(--accent); }
.rec-msg { display: none; font-size: 14.5px; color: var(--muted); }

.box.rec textarea, .box.stt textarea, .box.rec #send, .box.stt #send { display: none; }
.box.rec .rec-bar, .box.stt .rec-bar { display: flex; animation: fade .2s ease both; }
.box.rec .mic-x { display: grid; }
.box.rec .mic { background: var(--accent); color: var(--accent-ink); }
.box.rec .mic .i-mic, .box.stt .mic .i-mic { display: none; }
.box.rec .mic .i-ok { display: block; }
.box.stt .mic { pointer-events: none; color: var(--accent); }
.box.stt .mic .spin { display: block; }
.box.stt .rec-dot, .box.stt .rec-time, .box.stt .rec-wave { display: none; }
.box.stt .rec-msg { display: block; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .45; } }

/* озвучка ответа: во время загрузки — кружок, во время чтения — «стоп» с пульсом */
.act.speak .spin { width: 15px; height: 15px; border-width: 1.75px; }
.act.speak.playing { color: var(--accent); }
.act.speak.playing svg { fill: currentColor; stroke: none; width: 13px; height: 13px; }
.act.speak.playing::before {
  content: ""; position: absolute; inset: 4px; border-radius: 50%; border: 1.5px solid currentColor; opacity: .35;
  animation: ping 1.6s ease-out infinite;
}

.down, .editing {
  display: flex; align-items: center; gap: 8px; margin: 0 4px 8px; padding: 8px 12px; border-radius: 12px; font-size: 13.5px;
  animation: rise .25s var(--ease) both;
}
.down { background: var(--warn-soft); color: var(--warn); }
.down svg, .editing svg { width: 16px; height: 16px; }
.editing { padding: 2px 4px 2px 10px; color: var(--muted); }
.editing svg { color: var(--accent); }
.editing .mini { margin-left: auto; }
.hint { font-size: 12px; color: var(--faint); text-align: center; margin-top: 6px; }
body.home .hint { text-align: left; padding-left: 6px; }
@media (max-width: 600px) { .hint { display: none; } }

/* ---------------------------------------------------------------- загрузка без рывков */
.booting .app { visibility: hidden; }
.booting *, .booting *::before, .booting *::after { animation: none !important; transition: none !important; }
.qa.static { animation: none; }

/* ---------------------------------------------------------------- вопрос / ответ */
.thread { display: flex; flex-direction: column; }
.qa { padding: 18px 0 22px; animation: rise .35s var(--ease) both; }
/* сообщение пользователя — пузырь справа, ответ бота — слева во всю ширину */
.qa > h2 {
  position: relative; width: fit-content; max-width: min(78%, 560px); margin: 0 0 22px auto;
  padding: 10px 16px; border-radius: 20px 20px 6px 20px; background: var(--surface-2);
  font-size: 16px; line-height: 1.5; letter-spacing: 0; font-weight: 450; text-align: left;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
@media (max-width: 600px) { .qa > h2 { max-width: 88%; } }
.sec-title {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin: 0 0 10px;
}
.sec-title svg { width: 15px; height: 15px; color: var(--accent); }

/* ожидание */
/* ожидание: «пульс биржи» — без рамки, столбики-котировки + расшифровка шага */
.progress { padding: 6px 0 4px; animation: fade .3s var(--ease) both; }
.p-head { display: flex; align-items: center; gap: 12px; min-height: 24px; font-size: 15px; font-weight: 500; }
.ticker { flex: none; display: flex; align-items: flex-end; gap: 3px; height: 20px; padding: 0 2px; }
.ticker i {
  width: 4px; height: 100%; border-radius: 2px; transform-origin: bottom;
  background: linear-gradient(to top, var(--accent), #0ea5b7);
  animation: quote 1.3s cubic-bezier(.45, 0, .25, 1) infinite;
}
.ticker i:nth-child(1) { animation-duration: 1.10s; animation-delay: -.40s; }
.ticker i:nth-child(2) { animation-duration: 1.45s; animation-delay: -.90s; }
.ticker i:nth-child(3) { animation-duration: .95s;  animation-delay: -.20s; }
.ticker i:nth-child(4) { animation-duration: 1.70s; animation-delay: -1.1s; }
.ticker i:nth-child(5) { animation-duration: 1.25s; animation-delay: -.60s; background: linear-gradient(to top, var(--gold), #e0b341); }
@keyframes quote {
  0%   { transform: scaleY(.35); opacity: .75; }
  22%  { transform: scaleY(.9);  opacity: 1; }
  41%  { transform: scaleY(.5);  opacity: .8; }
  63%  { transform: scaleY(1);   opacity: 1; }
  82%  { transform: scaleY(.25); opacity: .7; }
  100% { transform: scaleY(.6);  opacity: .85; }
}
.p-now { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.p-now::after {
  content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 3px; vertical-align: -2px;
  border-radius: 1px; background: var(--accent); animation: caret 1s steps(1) infinite;
}
.p-now .gl { color: var(--accent); opacity: .55; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9em; }
@keyframes caret { 50% { opacity: 0; } }
.p-head .timer {
  margin-left: auto; flex: none; color: var(--faint); font-size: 12.5px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums;
}
.p-trail {
  display: flex; align-items: center; gap: 4px 14px; width: calc(100% - 36px); margin: 8px 0 0 36px; padding: 2px 0;
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
          mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.p-trail[hidden] { display: none; }
.p-trail:hover { color: var(--text); }
.p-trail.open { flex-direction: column; align-items: flex-start; white-space: normal; -webkit-mask-image: none; mask-image: none; }
.p-done { display: inline-flex; align-items: center; gap: 6px; animation: rise .25s var(--ease) both; }
.p-done svg { width: 12px; height: 12px; flex: none; fill: none; stroke: var(--ok); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 600px) { .p-trail { margin-left: 0; width: 100%; } }

/* статус-строка */
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; padding: 3px 10px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums;
}
.chip svg { width: 13px; height: 13px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.mini {
  display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; color: var(--muted);
  font-size: 13px; padding: 4px 6px; border-radius: 8px;
}
.mini:hover { color: var(--text); background: var(--surface-2); }
.mini svg { width: 15px; height: 15px; }

/* действия под ответом: Копировать · 👍 · 👎 · Поделиться · Ответить заново · Источник */
.acts-wrap { margin-top: 16px; }
.acts { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-left: -7px; min-height: 32px; }
.act {
  position: relative; display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border: 0; border-radius: 8px; background: none; color: var(--muted);
  transition: color .12s, background .12s, transform .12s var(--ease);
}
.act:hover { color: var(--text); background: var(--surface-2); }
.act:active { transform: scale(.9); }
.act svg { width: 17px; height: 17px; }
.act[aria-pressed="true"] { color: var(--text); }
.act[aria-pressed="true"] svg { fill: currentColor; }
.act.done { color: var(--ok); }
.act[data-tip]::after {
  content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; z-index: 5;
  transform: translate(-50%, -3px); padding: 4px 8px; border-radius: 6px; background: var(--text); color: var(--bg);
  font-size: 12px; font-weight: 500; line-height: 1.3; white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity .12s, transform .12s var(--ease);
}
.act[data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .3s; }
@media (hover: none) { .act[data-tip]::after { display: none; } }
.acts-note { margin-left: 8px; font-size: 13px; color: var(--muted); opacity: 0; transition: opacity .25s; }
.acts-note.show { opacity: 1; }

/* после 👎: что не так */
.fb {
  max-width: 560px; margin-top: 10px; padding: 12px 14px 14px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-sm); animation: rise .25s var(--ease) both;
}
.fb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -2px -6px 10px 0; font-size: 14px; font-weight: 600; }
.fb-x svg { width: 15px; height: 15px; }
.fb-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fb-chip {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: none; color: var(--muted);
  font-size: 13px; transition: color .12s, background .12s, border-color .12s, transform .12s var(--ease);
}
.fb-chip:hover { color: var(--text); border-color: var(--border-strong); }
.fb-chip:active { transform: scale(.96); }
.fb-chip[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.fb textarea.fb-text {
  display: block; width: 100%; min-height: 60px; max-height: 160px; margin-top: 10px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font: 14px/1.5 var(--font); resize: vertical;
  transition: border-color .15s;
}
.fb textarea.fb-text:focus { border-color: var(--accent); }
.fb-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.fb-foot .btn { height: 34px; font-size: 13.5px; }

/* изменить последний вопрос */
.qa > h2 .q-edit {
  position: absolute; right: calc(100% + 6px); top: 50%; translate: 0 -50%;
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: 8px; background: none; color: var(--faint); opacity: 0; transition: opacity .12s, color .12s, background .12s;
}
.qa > h2 .q-edit svg { width: 16px; height: 16px; }
.qa:hover > h2 .q-edit, .q-edit:focus-visible { opacity: 1; }
.q-edit:hover { color: var(--accent); background: var(--accent-soft); }
@media (hover: none) { .qa > h2 .q-edit { opacity: .7; } }
.qa.is-editing > h2 { color: var(--muted); }

/* ответ: печать и последующее появление графика/источников */
.tw-wait { visibility: hidden; }
.later { opacity: 0; }
.chart, .src { transition: opacity .35s var(--ease); }

/* график по времени */
.chart { margin: 0 0 22px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0 0 6px; }
.chart-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.chart .seg button { font-size: 12px; padding: 3px 9px; }
.chart-plot { position: relative; }
.chart-plot svg { display: block; width: 100%; height: 220px; stroke: none; fill: none; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .ax { fill: var(--faint); font: 11.5px var(--font); font-variant-numeric: tabular-nums; }
.chart .ln { stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); fill-opacity: .1; }
.chart .pt { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .bar { fill: var(--accent); fill-opacity: .85; transition: fill-opacity .12s; }
.chart .bar.dim { fill-opacity: .35; }
.chart .guide { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hot { fill: var(--accent); stroke: var(--surface); stroke-width: 2.5; }
.chart-tip {
  position: absolute; top: 0; pointer-events: none; z-index: 2; white-space: nowrap; transform: translateX(-50%);
  background: var(--text); color: var(--bg); border-radius: 8px; padding: 5px 9px; font-size: 12.5px; line-height: 1.35;
  font-variant-numeric: tabular-nums; box-shadow: var(--shadow);
}
.chart-tip b { font-weight: 650; }
@media (max-width: 600px) { .chart-plot svg { height: 190px; } }

/* ответ */
.answer { font-size: 16.5px; line-height: 1.65; margin: 0 0 24px; overflow-wrap: break-word; }
.answer p { margin: 0 0 12px; text-wrap: pretty; }
.answer > :last-child { margin-bottom: 0; }
.answer ol, .answer ul { margin: 0 0 14px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.answer ol { counter-reset: n; }
.answer ol li { counter-increment: n; position: relative; padding-left: 34px; }
.answer ol li::before {
  content: counter(n); position: absolute; left: 0; top: .2em; width: 24px; height: 24px; border-radius: 7px;
  background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 600; display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
}
.answer ul li { position: relative; padding-left: 18px; }
.answer ul li::before { content: ""; position: absolute; left: 4px; top: .68em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.answer b.n { font-weight: 650; font-variant-numeric: tabular-nums; color: var(--num); }
.answer b.n.money { color: var(--gold); }

/* кнопка «Источник» в ряду действий */
.src-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; margin-left: 6px; padding: 0 11px 0 9px;
  border: 1px solid var(--border); border-radius: 999px; background: none; color: var(--muted);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: color .12s, background .12s, border-color .12s, transform .12s var(--ease);
}
.src-btn svg { width: 15px; height: 15px; }
.src-btn .cnt { color: var(--faint); font-weight: 400; font-variant-numeric: tabular-nums; }
.src-btn .cnt::before { content: "·"; margin-right: 5px; }
.src-btn:hover { color: var(--text); border-color: var(--border-strong); }
.src-btn:active { transform: scale(.96); }
.src-btn.on { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.src-btn.on .cnt { color: inherit; opacity: .7; }

/* панель источника: третья колонка справа, выезжает, сдвигая чат */
.sheet {
  --sheet-w: min(460px, 40vw);
  flex: none; width: 0; overflow: hidden; background: var(--side); border-left: 1px solid transparent;
  transition: width .3s var(--ease), border-color .3s;
}
.sheet-open .sheet { width: var(--sheet-w); border-left-color: var(--border); }
.sheet-in { width: var(--sheet-w); height: 100%; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 8px 20px; }
.sheet-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 20px 24px; scrollbar-width: thin; }
.sheet-open .sheet-body > * { animation: rise .3s var(--ease) both; }
.sheet-open .sheet-body > :nth-child(2) { animation-delay: 40ms; }
.sheet-open .sheet-body > :nth-child(3) { animation-delay: 80ms; }
.sheet-open .sheet-body > :nth-child(4) { animation-delay: 120ms; }
.sh-q { margin: 0 0 18px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.sh-sec + .sh-sec { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.sh-sec h4 {
  display: flex; align-items: baseline; gap: 6px; margin: 0 0 10px;
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint);
}
.sh-sec h4 .cnt { text-transform: none; letter-spacing: 0; font-weight: 400; }
.sh-sec h4 .cnt::before { content: "·"; margin-right: 6px; }
.sheet .tbl-wrap { max-height: none; }

@media (max-width: 900px) {
  /* телефон / планшет: шторка снизу поверх чата */
  .sheet {
    --sheet-w: 100%;
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; width: auto; height: auto; max-height: 86dvh;
    border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0; background: var(--bg);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, .25); transform: translateY(105%); visibility: hidden;
    transition: transform .32s var(--ease), visibility 0s .32s;
  }
  .sheet-open .sheet { width: auto; transform: none; visibility: visible; transition: transform .32s var(--ease), visibility 0s; }
  .sheet-in { height: auto; max-height: 86dvh; }
  .sheet-head::before {
    content: ""; position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--border-strong);
  }
  .sheet-head { position: relative; padding-top: 16px; }
  .sheet-body { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}

/* основание — цитата с акцентной линией, без карточки */
.src-basis { padding: 2px 0 2px 14px; box-shadow: inset 2px 0 0 var(--accent); }
.basis-list { margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 14.5px; display: flex; flex-direction: column; gap: 5px; }
.basis-list li { position: relative; padding-left: 16px; }
.basis-list li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: var(--faint); }
.basis-text { color: var(--muted); font-size: 14.5px; margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.src-basis > * + * { margin-top: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.basis-list + .tags, .basis-text + .tags { margin-top: 10px; }
.tag {
  display: inline-flex; gap: 6px; max-width: 100%; font-size: 13px; padding: 4px 10px; border-radius: 8px;
  background: var(--surface-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tag .k { color: var(--muted); }

/* одна строка результата — плитки-метрики */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.metric {
  display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 14px 16px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
}
.metric .v { color: var(--num); font-size: 22px; font-weight: 650; line-height: 1.2; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric.long .v { color: var(--text); font-size: 15.5px; font-weight: 600; line-height: 1.35; letter-spacing: 0; }
.metric .k { font-size: 12.5px; color: var(--muted); }
@media (max-width: 600px) { .metrics { grid-template-columns: 1fr 1fr; } .metric .v { font-size: 19px; } }

/* таблица */
.tbl { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
.tbl-wrap { overflow: auto; max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th:first-child, td:first-child { padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }
th {
  position: sticky; top: 0; z-index: 1; background: var(--surface); border-bottom: 0; box-shadow: inset 0 -1px 0 var(--border);
  font-weight: 500; font-size: 12px; color: var(--faint); white-space: nowrap; padding-top: 11px;
}
th.num, td.num { text-align: right; white-space: nowrap; }
td { white-space: nowrap; }
td.txt { white-space: normal; min-width: 150px; max-width: 300px; }
tbody tr:hover td { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
.tbl-foot { padding: 9px 16px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); }
.btn-sm {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 500; white-space: nowrap;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm svg { width: 14px; height: 14px; }

/* продолжения */
.next { margin-top: 22px; }
.next-list { display: flex; flex-direction: column; }
.next-list button {
  display: flex; align-items: center; gap: 10px; text-align: left; border: 0; border-top: 1px solid var(--border);
  background: none; padding: 10px 4px; font-size: 14.5px; color: var(--text); transition: color .15s, padding .2s var(--ease);
}
.next-list button:last-child { border-bottom: 1px solid var(--border); }
.next-list button svg { width: 16px; height: 16px; color: var(--accent); }
.next-list button:hover { color: var(--accent); padding-left: 8px; }

.err { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border: 1px solid var(--bad-soft); background: var(--bad-soft); color: var(--bad); border-radius: 12px; padding: 10px 10px 10px 14px; font-size: 14.5px; }
.err span { flex: 1; min-width: 200px; }
.err .btn-sm { color: var(--bad); border-color: transparent; }
.err .btn-sm:hover { border-color: var(--bad); color: var(--bad); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(-2px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.8); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
