/* Интерфейс в духе чат-ассистента: тёмная тема, боковая панель с историей, лента по центру, поле ввода-«пилюля» снизу. */

:root {
  --bg: #000000;
  --sidebar: #000000;
  --surface: #0d0d0d;
  --text: #f3f3f3;
  --muted: #9b9b9b;
  --faint: #6e6e6e;
  --border: #2e2e2e;
  --border-soft: #1c1c1c;
  --bubble: #262626;
  --hover: #1a1a1a;
  --active: #212121;
  --card: #0d0d0d;
  --composer: #1b1b1b;
  --accent: #ffffff;
  --accent-text: #000000;
  --blue: #2f7bf6;
  --link: #7cb0ff;
  --danger: #f28b82;
  --danger-bg: #2a1513;
  --ok: #81c995;
  --star: #f5b301;
  --focus: #5b9dff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  --radius: 20px;
  --input-bg: #141414;
  --input-focus: #4a4a4a;
  --chip-bg: #111111;
  --composer-border: #262626;
  --composer-focus: #343434;
  --scrollbar: #2a2a2a;
  --toast: #2a2a2a;
  --toast-error: #5c1f1b;
  --backdrop: rgba(40, 40, 40, .45);
  --send-hover: #4189ff;
  color-scheme: dark;
}

/* Светлая тема: по настройке системы или выбором в меню (кнопка темы сохраняет выбор в браузере) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff; --sidebar: #f9f9f9; --surface: #f7f7f8; --text: #0d0d0d; --muted: #5d5d5d; --faint: #8f8f8f;
    --border: #dedede; --border-soft: #ececec; --bubble: #f1f1f1; --hover: #ececec; --active: #e3e3e3;
    --card: #ffffff; --composer: #ffffff; --accent: #0d0d0d; --accent-text: #ffffff; --link: #1a5fd0;
    --danger: #c5221f; --danger-bg: #fdecea; --ok: #1e7e34; --star: #e0a100; --focus: #1a73e8;
    --shadow: 0 8px 30px rgba(0, 0, 0, .12); --input-bg: #ffffff; --input-focus: #9a9a9a; --chip-bg: #f7f7f8;
    --composer-border: #d9d9d9; --composer-focus: #b5b5b5; --scrollbar: #d0d0d0; --toast: #2f2f2f;
    --toast-error: #b3261e; --backdrop: rgba(0, 0, 0, .3);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #ffffff; --sidebar: #f9f9f9; --surface: #f7f7f8; --text: #0d0d0d; --muted: #5d5d5d; --faint: #8f8f8f;
  --border: #dedede; --border-soft: #ececec; --bubble: #f1f1f1; --hover: #ececec; --active: #e3e3e3;
  --card: #ffffff; --composer: #ffffff; --accent: #0d0d0d; --accent-text: #ffffff; --link: #1a5fd0;
  --danger: #c5221f; --danger-bg: #fdecea; --ok: #1e7e34; --star: #e0a100; --focus: #1a73e8;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12); --input-bg: #ffffff; --input-focus: #9a9a9a; --chip-bg: #f7f7f8;
  --composer-border: #d9d9d9; --composer-focus: #b5b5b5; --scrollbar: #d0d0d0; --toast: #2f2f2f;
  --toast-error: #b3261e; --backdrop: rgba(0, 0, 0, .3);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok { color: var(--ok); }

/* --- Каркас --------------------------------------------------------------- */

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; overflow: clip; }
.sidebar {
  width: 260px; flex: 0 0 260px; background: var(--sidebar);
  display: flex; flex-direction: column; padding: 8px 8px 10px;
  transition: margin-left .22s ease;
}
.app.sidebar-collapsed .sidebar { margin-left: -260px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; overflow: clip; }
.topbar {
  height: 56px; flex: 0 0 56px; display: flex; align-items: center; gap: 6px; padding: 0 14px 0 16px;
}
.topbar-title {
  flex: 1; min-width: 0; font-size: 18px; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px;
}
.chat-title { overflow: hidden; text-overflow: ellipsis; }
.topbar-offer {
  display: inline-flex; align-items: center; gap: 7px; color: var(--link); text-decoration: none;
  font-size: 15px; padding: 7px 10px; border-radius: 10px; white-space: nowrap;
}
.topbar-offer:hover { background: var(--hover); }
.topbar-offer svg { width: 19px; height: 19px; }
.only-mobile { display: none !important; }
.when-collapsed { display: none !important; }
.app.sidebar-collapsed .when-collapsed { display: inline-grid !important; }
.sidebar-backdrop { display: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  background: transparent; border: 0; cursor: pointer; color: var(--text); text-decoration: none;
}
.icon-btn:hover { background: var(--hover); }

/* --- Боковая панель -------------------------------------------------------- */

.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 10px 10px; }
.sb-brand { flex: 1; min-width: 0; font-size: 20px; font-weight: 600; text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-top .icon-btn { color: var(--muted); }
.sb-top .icon-btn:hover { color: var(--text); }
.sb-scroll { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -8px; padding: 0 8px; scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; padding-bottom: 14px; }
.sb-item, .sb-chat {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px;
  text-decoration: none; font-size: 15px; min-height: 40px;
}
.sb-item svg { flex: 0 0 auto; }
.sb-item:hover, .sb-chat:hover { background: var(--hover); }
.sb-item.active, .sb-chat.active { background: var(--active); }
.sb-history { padding: 0 0 8px; }
.sb-group-title { font-size: 15px; color: var(--muted); padding: 16px 10px 8px; }
.sb-chat-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-empty { color: var(--faint); font-size: 14px; padding: 4px 10px; }
.dot-busy { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); animation: pulse 1.2s infinite; flex: 0 0 8px; }
.sb-footer { border-top: 1px solid var(--border-soft); margin: 0 -8px; padding: 10px 8px 0; display: flex; flex-direction: column; gap: 10px; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 12px; }
.sb-user form { margin: 0; }
.sb-user .icon-btn { color: var(--muted); }
.sb-user .icon-btn:hover { color: var(--text); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #a855c7; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: 0 0 34px; letter-spacing: .02em; }
.sb-user-text { flex: 1; min-width: 0; line-height: 1.25; }
.sb-user-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-plan { font-size: 13px; color: var(--muted); white-space: nowrap; }
.sb-pill {
  display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border);
  border-radius: 999px; padding: 9px 14px; font-size: 14px; text-decoration: none; background: var(--chip-bg);
}
.sb-pill:hover { background: var(--hover); }

/* --- Главный экран --------------------------------------------------------- */

.home {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px 12vh;
}
.home-center { width: 100%; max-width: 768px; display: flex; flex-direction: column; }
.home-title { font-size: 30px; font-weight: 400; margin: 0 0 30px; text-align: center; letter-spacing: -0.01em; }
.home-tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 22px; }
.home-tiles form, .home-more form { margin: 0; }
.home-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; height: 100%;
  padding: 12px 12px 11px; border: 1px solid var(--border); border-radius: 14px; background: transparent;
  color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.home-tile:hover { background: var(--hover); }
.home-tile:disabled { opacity: .6; cursor: default; }
.home-tile-icon { font-size: 19px; line-height: 1; margin-bottom: 5px; filter: grayscale(.15); }
.home-tile-title { font-size: 15px; font-weight: 500; }
.home-tile-hint { font-size: 12.5px; line-height: 1.3; color: var(--faint); }
.home-more { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.home-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border);
  border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: 13.5px; cursor: pointer; }
.home-chip:hover { background: var(--hover); color: var(--text); }
.home-chip span { filter: grayscale(.15); }
.unfinished + .home-tiles { margin-top: 10px; }
.scenario-list { display: flex; flex-direction: column; gap: 2px; margin-top: 22px; }
.scenario-list form { margin: 0; }
.scenario-row {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; border: 0; background: transparent;
  border-radius: 16px; padding: 14px 18px; cursor: pointer; transition: background .15s; min-height: 58px;
}
.scenario-row:hover { background: var(--hover); }
.scenario-row:disabled { opacity: .6; cursor: default; }
.scenario-icon { font-size: 18px; width: 24px; text-align: center; flex: 0 0 24px; filter: grayscale(.15); }
.scenario-title { font-size: 16px; white-space: nowrap; }
.scenario-desc { flex: 1; min-width: 0; font-size: 14px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scenario-go { color: var(--muted); opacity: 0; transition: opacity .15s; display: grid; }
.scenario-row:hover .scenario-go { opacity: 1; }

/* --- Лента ------------------------------------------------------------------ */

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.thread { max-width: 800px; margin: 0 auto; padding: 8px 16px 32px; }
.msg { display: flex; gap: 12px; margin: 24px 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  background: var(--bubble); border-radius: 22px; padding: 10px 18px; max-width: min(78%, 620px);
  overflow-wrap: anywhere;
}
.bubble-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.file-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; background: var(--chip-bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px 8px; margin: 2px 4px 2px 0; }
.avatar-agent { display: none; }
.msg-body { flex: 1; min-width: 0; }
.msg-actions { display: flex; gap: 2px; margin: 6px 0 0 -8px; }
.msg-actions .icon-btn { width: 32px; height: 32px; color: var(--muted); border-radius: 8px; }
.msg-actions .icon-btn:hover { color: var(--text); }
.msg-actions .icon-btn.copied { color: var(--ok); }
.md { line-height: 1.65; }
.md p { margin: 0 0 12px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.suggest { margin-top: 10px; }
.msg.pending { opacity: .7; }

.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--card); }
.card.done { background: transparent; border-color: var(--border-soft); }
.card-head { font-weight: 600; margin-bottom: 6px; }
.card-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.hint { margin-top: 10px; font-size: 14px; color: var(--muted); }

/* Вопросы шага */
.q { padding: 6px 0 10px; }
.q + .q { border-top: 1px solid var(--border-soft); padding-top: 12px; }
.q-label { font-weight: 500; margin-bottom: 6px; }
.req { color: var(--danger); margin-left: 3px; }
.q-hint { font-size: 13px; color: var(--muted); margin: -2px 0 6px; }
.answered { margin: 0; display: grid; gap: 6px; }
.answered div { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 10px; font-size: 14px; }
.answered dt { color: var(--muted); }
.answered dd { margin: 0; overflow-wrap: anywhere; }

.input {
  width: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--input-bg);
  padding: 9px 12px; outline: 0; resize: vertical;
}
.input:focus { border-color: var(--input-focus); }
.input::placeholder { color: var(--faint); }
textarea.input { min-height: 44px; }
.custom-input { margin-top: 8px; }
.custom-row { display: flex; gap: 8px; margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative; display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; background: transparent; cursor: pointer; line-height: 1.3; text-align: left;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { background: var(--hover); }
.chip input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.chip:has(input:checked) { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.file-btn {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 6px;
  border: 1px dashed var(--border); border-radius: 12px; padding: 8px 14px; cursor: pointer; font-size: 14px;
}
.file-btn:hover { background: var(--hover); }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.file-btn:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Поле «Ваш вариант» показываем, только когда выбран «Свой вариант» */
.q:has(input[value="__custom__"]) .custom-input,
.sum-form:has(input[value="__custom__"]) .custom-input { display: none; }
.q:has(input[value="__custom__"]:checked) .custom-input,
.sum-form:has(input[value="__custom__"]:checked) .custom-input { display: block; }
.file-names { font-size: 13px; color: var(--muted); margin-left: 8px; }

/* Сводка */
.sum-group { margin-top: 10px; }
.sum-group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 10px 0 4px; }
.sum-row { border-bottom: 1px solid var(--border-soft); }
.sum-row summary {
  list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(110px, 34%) 1fr auto; gap: 10px;
  grid-template-areas: "label value edit" "note note note";
  padding: 8px 0; align-items: baseline; font-size: 14px;
}
.sum-label { grid-area: label; }
.sum-value { grid-area: value; }
.sum-edit { grid-area: edit; }
.sum-row summary::-webkit-details-marker { display: none; }
.sum-label { color: var(--muted); }
.sum-value { overflow-wrap: anywhere; }
.sum-edit { font-size: 12px; color: var(--link); opacity: 0; transition: opacity .15s; }
.sum-row summary:hover .sum-edit, .sum-row[open] .sum-edit { opacity: 1; }
.sum-note { grid-area: note; font-size: 13px; line-height: 1.45; color: var(--muted); }
.sum-note::before { content: "⚠ "; color: var(--star); }
.sum-form { padding: 4px 0 12px; }
.confirm-row { border-top: 0; margin-top: 16px; }
.sum-collapsed summary { cursor: pointer; }

/* Выполнение */
.progress-top { display: flex; align-items: center; gap: 10px; }
.progress-label { flex: 1; }
.progress-pct { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.bar { height: 6px; background: var(--active); border-radius: 99px; overflow: hidden; margin: 10px 0 8px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s ease; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--text);
  animation: spin .8s linear infinite; display: inline-block; flex: 0 0 16px;
}

/* Результат */
.result-card.old { opacity: .8; }
.preview { display: block; max-width: 100%; max-height: 420px; border-radius: 12px; border: 1px solid var(--border); margin: 8px 0; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 6px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 12px; text-decoration: none; font-size: 14px; background: var(--chip-bg); cursor: pointer;
}
.file-chip:hover { background: var(--hover); }
.file-chip span { color: var(--muted); font-size: 12px; }
.file-chip.disabled { color: var(--muted); }

.refusal-card { border-color: var(--border); }
.dispute { margin-top: 10px; }
.dispute summary { list-style: none; display: inline-flex; }
.dispute summary::-webkit-details-marker { display: none; }
.dispute form { margin-top: 8px; }
.error-card { border-color: var(--danger); background: var(--danger-bg); }

.stars { position: relative; display: inline-flex; flex-direction: row-reverse; gap: 2px; margin: 6px 0 8px; }
.stars input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars label { font-size: 28px; color: var(--border); cursor: pointer; line-height: 1; transition: color .1s; }
.stars label:hover, .stars label:hover ~ label, .stars input:checked ~ label { color: var(--star); }
.stars input:focus-visible + label { outline: 2px solid var(--focus); border-radius: 4px; }
.stars-static { color: var(--star); letter-spacing: 1px; }

.typing { display: inline-flex; gap: 4px; padding: 10px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }

/* --- Поле ввода ---------------------------------------------------------- */

.composer { width: 100%; max-width: 800px; margin: 0 auto; padding: 0 16px calc(8px + env(safe-area-inset-bottom)); }
.composer-box {
  border: 1px solid var(--composer-border); border-radius: 28px; position: relative; background: var(--composer);
  padding: 9px 10px; transition: border-color .15s;
}
.composer-box:focus-within { border-color: var(--composer-focus); }
.composer textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; resize: none; max-height: 220px;
  padding: 7px 4px; line-height: 1.45; display: block; font-size: 16px;
}
.composer textarea:disabled { opacity: .6; }
.composer textarea::placeholder { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer textarea { scrollbar-width: none; }
.composer textarea::-webkit-scrollbar { display: none; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer-row > .icon-btn { border-radius: 50%; color: var(--text); }
/* Выбор модели в поле ввода: кнопка-«пилюля», список раскрывается над полем */
.model-pick { flex: 0 0 auto; display: inline-flex; align-items: center; min-width: 0; }
.model-pick select { height: 36px; max-width: 160px; border: 0; background: transparent; color: var(--muted); font-size: 14px; }
.model-pick .ui-select-btn {
  height: 36px; max-width: 220px; padding: 0 8px 0 12px; border: 0; border-radius: 18px; background: transparent;
  color: var(--muted); font-size: 14px; transition: background .15s, color .15s;
}
.model-pick .ui-select-btn:hover, .model-pick .ui-select-btn[aria-expanded="true"] { background: var(--hover); color: var(--text); }

/* --- Выпадающий список (select[data-ui-select] + кнопка и список из app.js) ---------------- */

.js select[data-ui-select] { display: none; }
html:not(.js) .ui-select-btn { display: none; }
.ui-select-btn {
  display: inline-flex; align-items: center; gap: 4px; min-width: 0; cursor: pointer; text-align: left;
  font: inherit; color: inherit;
}
.ui-select-value { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-select-btn > svg { flex: 0 0 auto; width: 14px; height: 14px; transform: rotate(90deg); transition: transform .15s; }
.ui-select-btn[aria-expanded="true"] > svg { transform: rotate(-90deg); }
.ui-select-btn.busy { opacity: .6; cursor: progress; }
.ui-select-tiny { display: none; }
/* Поле формы: кнопка во всю ширину, как обычное поле ввода */
.ui-select-btn.input { display: flex; justify-content: space-between; gap: 10px; min-height: 42px; }
.ui-select-btn.input:hover, .ui-select-btn.input[aria-expanded="true"] { border-color: var(--input-focus); }
.ui-select-btn.input > svg { width: 16px; height: 16px; color: var(--muted); }

.ui-select-menu {
  position: fixed; z-index: 70; overflow-y: auto; overscroll-behavior: contain; padding: 6px;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; animation: ui-menu-down .12s ease-out;
}
.ui-select-menu.up { animation-name: ui-menu-up; }
.ui-select-menu-model { width: 344px; }
.ui-select-group + .ui-select-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border-soft); }
.ui-select-group-label { padding: 6px 10px 4px; font-size: 12px; font-weight: 500; color: var(--faint); letter-spacing: .02em; }
.ui-select-option {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 7px 10px; border-radius: 10px;
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.ui-select-option.active { background: var(--hover); }
.ui-select-option[aria-disabled="true"] { opacity: .45; cursor: default; }
.ui-select-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ui-select-title { font-size: 14px; line-height: 1.35; }
.ui-select-option[aria-selected="true"] .ui-select-title { font-weight: 500; }
.ui-select-desc { font-size: 12.5px; line-height: 1.35; color: var(--muted); }
.ui-select-check { flex: 0 0 16px; height: 16px; display: grid; place-items: center; color: var(--text); }
@keyframes ui-menu-down { from { opacity: 0; transform: translateY(-4px); } }
@keyframes ui-menu-up { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .ui-select-menu { animation: none; } }

/* Память в профиле и строка «Запомнил: …» в чате */
.memory-more > summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 2px 0; }
.memory-more > .profile-form { margin: 14px 0 0; }
.memory-link { display: inline-block; margin-top: 2px; color: var(--link); text-decoration: none; font-size: 13px; }
.memory-link:hover { text-decoration: underline; }
.attach-list:empty { display: none; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 8px; }
.send-btn {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; border: 0; background: var(--blue); color: #fff;
  display: grid; place-items: center; cursor: pointer; transition: opacity .15s, background .15s;
}
.send-btn:hover { background: var(--send-hover); }
.send-btn:disabled { opacity: .35; cursor: default; }
.composer-note { text-align: center; font-size: 12px; color: var(--muted); padding: 9px 0 2px; }
.home-composer { max-width: none; padding: 0; }

/* --- Кнопки ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: transparent; border-radius: 999px; padding: 8px 16px; cursor: pointer; text-decoration: none;
  font-size: 14px; font-weight: 500; transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: .88; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.big { padding: 11px 22px; font-size: 15px; }
.btn.block { width: 100%; padding: 11px 16px; font-size: 15px; }
.btn:disabled, .btn.htmx-request { opacity: .5; pointer-events: none; }
.link-btn { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font-size: 14px; }

/* --- Страницы ----------------------------------------------------------- */

.page { flex: 1; overflow-y: auto; width: 100%; max-width: 800px; margin: 0 auto; padding: 12px 16px 40px; }
.page.narrow { max-width: 620px; }
.page-title { font-size: 28px; font-weight: 500; margin: 12px 0 8px; letter-spacing: -0.01em; }
.res-card { border: 1px solid var(--border-soft); background: var(--surface); border-radius: var(--radius); padding: 14px 18px; margin: 12px 0; }
.res-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.res-title { font-weight: 600; text-decoration: none; flex: 1; min-width: 0; }
.res-title:hover { text-decoration: underline; }
.res-version { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.res-v { font-size: 13px; color: var(--muted); min-width: 24px; }
.empty { color: var(--muted); padding: 30px 0; }
.invite-box { display: flex; gap: 8px; margin: 16px 0 12px; }

.toasts { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; width: min(92%, 520px); }
.toast { background: var(--toast); color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: fadeout 6s forwards; }
.toast.error { background: var(--toast-error); color: #fff; }
.toast.success { background: var(--toast); }

/* --- Вход --------------------------------------------------------------- */

.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card h1 { font-size: 30px; font-weight: 500; margin: 18px 0 8px; letter-spacing: -0.01em; }
.auth-card form { text-align: left; margin: 22px 0 14px; display: grid; gap: 8px; }
.auth-logo { width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; margin: 0 auto; }
.auth-logo svg { width: 28px; height: 28px; }
.field-label { font-size: 14px; font-weight: 500; }
.field-error { color: var(--danger); font-size: 13px; }
.notice { background: var(--composer); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.code-input { font-size: 24px; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.auth-links { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.auth-links form { margin: 0; }
.auth .input { padding: 13px 18px; border-radius: 999px; }
.auth .code-input { border-radius: 16px; }
.auth .btn.block { padding: 13px 16px; }
.auth-links a { color: var(--link); text-decoration: none; }

/* --- Анимации ----------------------------------------------------------- */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes fadeout { 0%, 85% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

/* --- Телефон ------------------------------------------------------------ */

@media (max-width: 767px) {
  .only-mobile { display: inline-grid !important; }
  .only-desktop, .app .when-collapsed { display: none !important; }
  .app.sidebar-collapsed .sidebar { margin-left: 0; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: 84vw; max-width: 320px;
    transform: translateX(-102%); transition: transform .22s ease; border-right: 1px solid var(--border-soft);
    padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: var(--backdrop); z-index: 40; }
  .topbar { padding: env(safe-area-inset-top) 8px 0; height: calc(52px + env(safe-area-inset-top)); flex-basis: auto; }
  .topbar-title { justify-content: center; font-size: 17px; }
  .topbar-offer span { display: none; }
  .topbar-offer { padding: 8px; }
  .thread { padding: 4px 14px 20px; }
  .msg { margin: 18px 0; }
  .bubble { max-width: 88%; }
  .composer { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer-note { display: none; }
  .model-pick .ui-select-btn { padding: 0 6px 0 9px; }
  .ui-select-long { display: none; }
  .ui-select-tiny { display: inline; }
  .ui-select-option { min-height: 44px; }
  .home { justify-content: flex-start; padding: 0 12px; }
  .home-center { flex: 1; }
  .home-title { font-size: 26px; margin: auto 0 18px; }
  .scenario-list { margin: 0 0 auto; }
  .home-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 0; }
  .home-tile { padding: 10px; }
  .home-tile-title { font-size: 14px; }
  .home-tile-hint { display: none; }
  .home-more { justify-content: flex-start; margin-bottom: auto; }
  .scenario-row { padding: 12px 12px; min-height: 50px; }
  .scenario-desc { display: none; }
  .scenario-go { opacity: 1; margin-left: auto; }
  .home-composer { order: 3; position: sticky; bottom: 0; padding: 12px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--bg); }
  .answered div { grid-template-columns: 1fr; gap: 2px; }
  .sum-row summary { grid-template-columns: 1fr auto; grid-template-areas: "label edit" "value value" "note note"; gap: 2px 10px; }
  .sum-edit { opacity: 1; }
  .quick-edits .chip { font-size: 13px; }
  .card { padding: 12px 14px; }
  .confirm-row { margin: 16px -14px -12px; padding: 12px 14px; }
}

/* --- Шаги, сводка, результат ------------------------------------------------- */

.card-kicker { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.step-pos { color: var(--text); }
.step-bar { height: 3px; background: var(--active); border-radius: 99px; margin: -2px 0 10px; overflow: hidden; }
.step-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.step-done { border: 1px solid var(--border-soft); border-radius: 14px; padding: 0 14px; }
.step-done summary {
  list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; padding: 9px 0; font-size: 14px; min-width: 0;
}
.step-done summary::-webkit-details-marker { display: none; }
.step-check { color: var(--ok); flex: 0 0 auto; }
.step-done-title { font-weight: 600; flex: 0 0 auto; }
.step-done-brief { color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-done[open] .step-done-brief { visibility: hidden; }
.step-done .answered { padding: 0 0 12px; }
.msg:has(> .msg-body > .step-done) { margin: 10px 0; }

.sum-more { border-bottom: 1px solid var(--border-soft); }
.sum-more > summary {
  cursor: pointer; font-size: 13px; color: var(--muted); padding: 8px 0; list-style: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sum-more > summary::-webkit-details-marker { display: none; }
.sum-more > summary::before { content: "+ "; }
.sum-more[open] > summary::before { content: "− "; }
.sum-form .q-hint { margin: 6px 0 0; }
.profile-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--surface); }
.profile-offer span { flex: 1; min-width: 200px; }
.confirm-row {
  position: sticky; bottom: 0; z-index: 2; background: var(--card); margin: 16px -16px -14px; padding: 12px 16px 14px;
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -10px 16px -12px rgba(0, 0, 0, .45);
}

.changes { margin: 6px 0 4px; padding-left: 20px; font-size: 14px; }
.outline { margin: 10px 0 4px; border: 1px solid var(--border-soft); border-radius: 12px; }
.outline > summary { cursor: pointer; padding: 9px 12px; font-size: 14px; color: var(--link); list-style: none; }
.outline > summary::-webkit-details-marker { display: none; }
.outline-body { padding: 2px 14px 12px; font-size: 14px; line-height: 1.55; max-height: 420px; overflow-y: auto; }
.outline-body p { margin: 0 0 8px; }
.outline-body ul, .outline-body ol { margin: 0 0 8px; padding-left: 20px; }
.ol-title { font-size: 17px; font-weight: 600; margin: 4px 0 2px; }
.ol-subtitle { color: var(--muted); margin-bottom: 8px; }
.ol-heading { font-weight: 600; margin: 10px 0 4px; }
.ol-callout { border-left: 3px solid var(--accent); padding: 4px 10px; margin: 8px 0; background: var(--surface); }
.ol-table-wrap { overflow-x: auto; margin: 6px 0 8px; }
.ol-table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.ol-table th, .ol-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.ol-table th { background: var(--surface); font-weight: 600; }
.ol-slide { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.ol-slide:last-child { border-bottom: 0; }
.ol-slide .ol-heading { margin-top: 0; }
.ol-n { flex: 0 0 22px; height: 22px; border-radius: 6px; background: var(--active); font-size: 12px; display: grid; place-items: center; color: var(--muted); }
.share-chip { color: var(--text); font: inherit; font-size: 14px; }
.quick-edits { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.quick-edits form { margin: 0; }
.similar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 12px; }
.progress-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* --- Поле ввода: файлы, голос, перетаскивание -------------------------------- */

.file-tag .file-x { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 15px; line-height: 1; }
.file-tag .file-x:hover { color: var(--text); }
.mic-btn { border-radius: 50%; color: var(--muted); }
.mic-btn.listening { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }
.drop-hint { display: none; }
.composer-box.dragover { border-color: var(--blue); border-style: dashed; }
.composer-box.dragover .drop-hint {
  display: grid; place-items: center; position: absolute; inset: 0; border-radius: inherit; background: var(--composer);
  color: var(--blue); font-size: 14px;
}
.chat.dragover .composer-box { border-color: var(--blue); border-style: dashed; }

/* --- История ------------------------------------------------------------------ */

.sb-search { display: flex; align-items: center; gap: 8px; margin: 4px 2px 0; padding: 6px 10px; border-radius: 10px; background: var(--hover); color: var(--muted); }
.sb-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14px; color: var(--text); }
.sb-chat { padding: 0; gap: 0; position: relative; }
.sb-chat-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 8px 4px 8px 10px; text-decoration: none; min-height: 40px; }
.sb-chat-icon { flex: 0 0 auto; font-size: 14px; filter: grayscale(.2); }
.sb-chat-menu { width: 30px; height: 30px; color: var(--muted); opacity: 0; margin-right: 4px; }
.sb-chat:hover .sb-chat-menu, .sb-chat.active .sb-chat-menu, .sb-chat-menu:focus-visible, .sb-chat-menu[aria-expanded="true"] { opacity: 1; }
.sb-menu {
  position: fixed; z-index: 60; min-width: 190px; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column;
}
.sb-menu button { border: 0; background: transparent; text-align: left; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.sb-menu button:hover, .sb-menu button:focus-visible { background: var(--hover); }
.sb-menu button.danger { color: var(--danger); }
button.sb-item { border: 0; background: transparent; width: 100%; text-align: left; cursor: pointer; color: var(--text); }

/* --- Главная, профиль, результаты ------------------------------------------- */

.unfinished { margin-top: 22px; }
.unfinished-title { font-size: 13px; color: var(--muted); padding: 0 18px 4px; }
.unfinished .scenario-row { text-decoration: none; }
.unfinished + .scenario-list { margin-top: 10px; }
.profile-form { display: grid; gap: 16px; margin: 18px 0; }
.ol-table tr.ol-total td { font-weight: 600; }
.accepted-mark { font-size: 13px; color: var(--muted); padding: 6px 4px; }
.cal-card { display: grid; gap: 4px; margin: 6px 0 10px; }
.cal-when { font-size: 15px; }
.cal-day { font-weight: 500; margin-top: 8px; }
.cal-list { margin: 2px 0 0; padding-left: 0; list-style: none; display: grid; gap: 2px; }
.cal-time { display: inline-block; min-width: 92px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-status { font-size: 13px; color: var(--muted); margin-top: 4px; }
.cal-status.ok::before { content: "✓ "; }
.cal-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tariff { display: grid; gap: 6px; font-size: 14px; }
.tariff-bar { height: 6px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.tariff-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.tariff-rows, .tariff-prices ul { margin: 2px 0; padding-left: 18px; font-size: 13.5px; }
.tariff-prices > summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.section-title { font-size: 20px; font-weight: 500; margin: 32px 0 6px; }
.cal-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 0; border-bottom: 1px solid var(--border); }
.cal-actions { display: flex; gap: 6px; }
.cal-connect { margin: 12px 0; }
.cal-connect > summary { cursor: pointer; font-weight: 500; padding: 6px 0; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--hover);
  color: var(--muted); }
.field { display: grid; gap: 6px; }
.field .q-hint { margin: 0; }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-preview { max-height: 44px; max-width: 140px; border-radius: 6px; background: #fff; padding: 4px; border: 1px solid var(--border); }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check-row input { margin-top: 4px; }
.res-search { display: flex; gap: 8px; margin: 14px 0 4px; }
.install-hint { display: flex; gap: 10px; align-items: flex-start; }
.install-hint button { flex: 0 0 auto; }
.unfinished .scenario-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.unfinished .scenario-desc { flex: 0 0 auto; }
@media (max-width: 767px) {
  .unfinished .scenario-desc { display: block; font-size: 13px; }
  .unfinished .scenario-go { margin-left: 0; }
}
/* На сенсорных экранах нет наведения — меню «…» у задач в истории видно всегда */
@media (hover: none) { .sb-chat-menu { opacity: 1; } }
