/* Астра — стили перенесены из ASTRA (ui/index.html, наработка владельца, решение 8): те же размеры,
   цвета и тени. Своё: состояния портрета, запись микрофона, вид в окне браузера, робот Астры (скрыт).
   Цвета — только через переменные темы (решение 43): одна тема на всё окно, html[data-theme].
   Тени: rgb(var(--shade) / a) — тёмная сторона, rgb(var(--light) / a) — светлая. */
:root {
  color-scheme: light; --level: 0; --speak: 0;
  --ink: #34465c; --ink-strong: #25374d; --ink-soft: #34475f; --muted: #64778f; --faint: #7c8da2;
  --icon: #6a7f98; --icon-off: #9aa8ba; --icon-hover: #3b5577; --placeholder: #7488a2; --wave: #98a9c0;
  --page: #dce7f3; --native: #dfe9f5; --card-1: #e3edf8; --card-2: #dce7f3; --card-3: #dce5f2;
  --raised-1: #eaf0f9; --raised-2: #dce6f3; --bubble-1: #e6eef8; --bubble-2: #dce7f4;
  --pane-1: #eef4fc; --pane-2: #e2ebf7; --pane-head: #e7eef9; --sheet: #e8eff9; --well: #d3dfef;
  --menu-1: #eef3fa; --menu-2: #e3ebf6; --hover: rgb(255 255 255 / .56);
  --shade: 168 185 209; --light: 255 255 255;
  --accent: #6c87d3; --accent-strong: #5373c2; --accent-text: #4d67c6; --accent-soft: #edf3fd; --chosen: #dbe4f5;
  --dot: #899fe8; --dot-off: #b3bfcf; --ring-tick: #a4b3c5; --line: #c9d5e6; --dash: #b7c5d8; --line-glow: #9baff0;
  --focus: #7286d1; --toast: #405777; --error: #a24a5b; --draft: #8a6d2f; --quit: #b8455c;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #dde6f2; --ink-strong: #f2f6fc; --ink-soft: #dde6f2; --muted: #9aabc2; --faint: #8796ab;
  --icon: #a3b2c6; --icon-off: #6f7f95; --icon-hover: #e6eefa; --placeholder: #7f8fa5; --wave: #7d8ea6;
  --page: #1f2633; --native: #1f2633; --card-1: #252d3b; --card-2: #222a37; --card-3: #202835;
  --raised-1: #2a3343; --raised-2: #232b39; --bubble-1: #29313f; --bubble-2: #232b38;
  --pane-1: #262f3e; --pane-2: #212938; --pane-head: #252e3d; --sheet: #2b3444; --well: #1b212c;
  --menu-1: #2b3444; --menu-2: #252e3c; --hover: rgb(255 255 255 / .08);
  --shade: 8 11 17; --light: 60 72 92;
  --accent: #6f8be0; --accent-strong: #5f7ad0; --accent-text: #a9bcf5; --accent-soft: #2f3a4f; --chosen: #34405a;
  --dot: #8aa2f0; --dot-off: #5b6880; --ring-tick: #5d6b80; --line: #3a4558; --dash: #465266; --line-glow: #6f8be0;
  --focus: #8aa2f0; --toast: #0f141c; --error: #f08a9b; --draft: #e0b866; --quit: #f08a9b;
}
:root[data-theme="green"] {
  --ink: #2f4a3f; --ink-strong: #22392f; --ink-soft: #2f4a3f; --muted: #5f7d70; --faint: #7a9488;
  --icon: #628476; --icon-off: #98b2a6; --icon-hover: #2f5a49; --placeholder: #6f8f81; --wave: #93b3a5;
  --page: #dcebe3; --native: #dcebe3; --card-1: #e1efe7; --card-2: #dbeae2; --card-3: #d9e8e0;
  --raised-1: #e6f2eb; --raised-2: #d9e9e0; --bubble-1: #e3f0e8; --bubble-2: #d9e9df;
  --pane-1: #ecf6f0; --pane-2: #e0eee6; --pane-head: #e6f2eb; --sheet: #e5f1ea; --well: #cfe2d7;
  --menu-1: #ebf5ef; --menu-2: #e0eee6;
  --shade: 160 190 175;
  --accent: #4f9a7b; --accent-strong: #3f8768; --accent-text: #357a5d; --accent-soft: #e8f5ee; --chosen: #d3eadf;
  --dot: #6dbb98; --dot-off: #adc7bb; --ring-tick: #9fbcb0; --line: #c3dbcf; --dash: #b0cbbd; --line-glow: #8fd0b2;
  --focus: #5aa587; --toast: #35574a;
}
:root[data-theme="warm"] {
  --ink: #4e3d30; --ink-strong: #3d2e23; --ink-soft: #4e3d30; --muted: #84705f; --faint: #9c8977;
  --icon: #8f7865; --icon-off: #bba996; --icon-hover: #5a4331; --placeholder: #9a8573; --wave: #bba591;
  --page: #f1e6da; --native: #f1e6da; --card-1: #f4eadf; --card-2: #efe4d8; --card-3: #ede2d6;
  --raised-1: #f6ede3; --raised-2: #ede1d4; --bubble-1: #f5ebe0; --bubble-2: #eee2d5;
  --pane-1: #f8f0e8; --pane-2: #efe4d8; --pane-head: #f3e9df; --sheet: #f4e9de; --well: #e6d7c7;
  --menu-1: #f7eee5; --menu-2: #efe4d8;
  --shade: 205 180 155;
  --accent: #d08a55; --accent-strong: #bd7744; --accent-text: #a8642f; --accent-soft: #fbefe4; --chosen: #f1dcc8;
  --dot: #e0a372; --dot-off: #d3c0ad; --ring-tick: #c8b3a0; --line: #e2cfbd; --dash: #d6c0ab; --line-glow: #f0b88a;
  --focus: #d4935f; --toast: #6a5240;
}
:root[data-theme="lilac"] {
  --ink: #3f3758; --ink-strong: #2f2846; --ink-soft: #3f3758; --muted: #6f6790; --faint: #8a82a6;
  --icon: #7a6f9b; --icon-off: #ada4c6; --icon-hover: #4a3f72; --placeholder: #8378a2; --wave: #a99fc4;
  --page: #e6e0f2; --native: #e6e0f2; --card-1: #ebe5f6; --card-2: #e5dff2; --card-3: #e3ddf0;
  --raised-1: #eee9f8; --raised-2: #e3dcf1; --bubble-1: #ece6f7; --bubble-2: #e3dcf2;
  --pane-1: #f2eefb; --pane-2: #e8e2f5; --pane-head: #ede8f8; --sheet: #ece7f7; --well: #d9d0ec;
  --menu-1: #f1ecfa; --menu-2: #e8e2f5;
  --shade: 178 165 210;
  --accent: #8a6fd3; --accent-strong: #775cc2; --accent-text: #6a4fc0; --accent-soft: #f1edfd; --chosen: #e2daf6;
  --dot: #a08be8; --dot-off: #c3bbd8; --ring-tick: #b3a8cc; --line: #d6cdea; --dash: #c6bbdd; --line-glow: #b6a3f0;
  --focus: #9179d8; --toast: #4e4570;
}
:root[data-theme="pink"] {
  --ink: #4d3440; --ink-strong: #3b2530; --ink-soft: #4d3440; --muted: #87657a; --faint: #a08292;
  --icon: #93707f; --icon-off: #c4a6b4; --icon-hover: #6a3a52; --placeholder: #9c7a8a; --wave: #c6a2b2;
  --page: #f3e1e8; --native: #f3e1e8; --card-1: #f6e7ed; --card-2: #f1dee6; --card-3: #efdbe3;
  --raised-1: #f8ebf0; --raised-2: #efdae3; --bubble-1: #f7e9ef; --bubble-2: #f0dce5;
  --pane-1: #faf0f4; --pane-2: #f2e1e8; --pane-head: #f6e8ee; --sheet: #f6e9ee; --well: #e9d1db;
  --menu-1: #f9eef3; --menu-2: #f2e1e8;
  --shade: 210 170 188;
  --accent: #d0688f; --accent-strong: #bc567d; --accent-text: #a8466d; --accent-soft: #fcecf2; --chosen: #f3d3e0;
  --dot: #e08aab; --dot-off: #d6bcc8; --ring-tick: #cfaab9; --line: #e8cad6; --dash: #dcb9c7; --line-glow: #f2a2c0;
  --focus: #d4759a; --toast: #6a4256;
}
:root[data-theme="yellow"] {
  --ink: #4a4024; --ink-strong: #383019; --ink-soft: #4a4024; --muted: #7f7350; --faint: #998d68;
  --icon: #8c7f55; --icon-off: #bfb38c; --icon-hover: #5c4d1c; --placeholder: #958863; --wave: #c2b588;
  --page: #f3ecd2; --native: #f3ecd2; --card-1: #f6f0da; --card-2: #f1e9cf; --card-3: #efe6cb;
  --raised-1: #f8f3e0; --raised-2: #efe6c9; --bubble-1: #f7f1dd; --bubble-2: #f0e7cc;
  --pane-1: #faf6e6; --pane-2: #f2ebd2; --pane-head: #f6f0dc; --sheet: #f6f0dc; --well: #e8ddb8;
  --menu-1: #f9f4e3; --menu-2: #f2ebd2;
  --shade: 205 190 140;
  --accent: #c49a1c; --accent-strong: #ad8612; --accent-text: #8a6a0a; --accent-soft: #fbf4dc; --chosen: #f0e2b0;
  --dot: #d8b444; --dot-off: #d4c9a0; --ring-tick: #cbbd8e; --line: #e6dbb4; --dash: #d9cc9f; --line-glow: #ecc95e;
  --focus: #c9a32e; --toast: #5f5326;
}
:root[data-theme="teal"] {
  --ink: #2b4549; --ink-strong: #1f3538; --ink-soft: #2b4549; --muted: #5b7d82; --faint: #77959a;
  --icon: #5f8388; --icon-off: #97b4b8; --icon-hover: #255a61; --placeholder: #6b8d92; --wave: #8fb6bb;
  --page: #d9edef; --native: #d9edef; --card-1: #dff1f2; --card-2: #d8eced; --card-3: #d5e9eb;
  --raised-1: #e4f4f5; --raised-2: #d5e9eb; --bubble-1: #e1f2f3; --bubble-2: #d6eaec;
  --pane-1: #eaf7f8; --pane-2: #ddeff0; --pane-head: #e4f3f4; --sheet: #e3f2f3; --well: #c9e1e4;
  --menu-1: #e9f6f7; --menu-2: #ddeff0;
  --shade: 150 190 195;
  --accent: #2c9aa8; --accent-strong: #208795; --accent-text: #177581; --accent-soft: #e3f5f7; --chosen: #c9e8ec;
  --dot: #4fb8c5; --dot-off: #a6c8cc; --ring-tick: #93bcc1; --line: #bfdde1; --dash: #a9cfd4; --line-glow: #6fd0dc;
  --focus: #35a5b3; --toast: #2c5257;
}* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); font: 18px/1.5 'Segoe UI', sans-serif; background: var(--page);
  transition: background .4s; }
button, input, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
button:disabled { cursor: default; opacity: .5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.page { min-height: 100vh; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; }
.companion { position: relative; isolation: isolate; width: 100%; min-height: 100vh; border: 0; border-radius: 22px;
  background: linear-gradient(135deg, var(--card-1), var(--card-2) 54%, var(--card-3)); box-shadow: inset 0 0 0 1px rgb(var(--light) / .36); overflow: hidden; }
/* Своё окно (pywebview): углы скругляет само окно, страница — прямоугольник без светлого контура,
   иначе в углах видны «уголки» второго контура */
html.native, html.native body { background: var(--native); }
.native .companion { border-radius: 0; box-shadow: none; }
/* В окне браузера окно само не сужается: без панели «Разговоры» карточка как в ASTRA, 420px по центру */
.companion:not(.expanded) { max-width: 420px; }

/* ---------- шапка ---------- */
.chrome { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 4px; gap: 12px; user-select: none; }
.chrome > .drag-handle { align-self: stretch; flex: 1; min-height: 36px; }
.brand { font: 600 10px/1 'Segoe UI', sans-serif; letter-spacing: 2.2px; text-transform: uppercase; color: var(--faint); opacity: .7;
  align-self: center; margin-right: 4px; padding-left: 2px; pointer-events: none; user-select: none; white-space: nowrap; order: -1; }
.build { letter-spacing: .5px; margin-left: 4px; }   /* временный счётчик сборки (build.py) */
.chrome-controls { display: flex; gap: 8px; flex-shrink: 0; }
.icon { border: 0; border-radius: 50%; width: 34px; height: 34px; background: transparent; display: inline-grid; place-items: center; color: var(--icon); padding: 7px; }
.icon:hover { background: var(--hover); color: var(--icon-hover); }
.icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.icon[hidden] { display: none; }
.icon:disabled { opacity: .45; cursor: default; }
#quit:hover { background: color-mix(in srgb, var(--quit) 15%, transparent); color: var(--quit); }
/* кнопка «Ошибка» (решение 46): только в шапке, как остальные значки */
#report.busy { opacity: .45; cursor: progress; }

.layout { display: block; }
.expanded .layout { display: grid; grid-template-columns: 395px 1fr; }
.expanded .chrome { padding-bottom: 6px; }

/* ---------- портрет ---------- */
.presence { padding: 18px 24px 0; text-align: center; }
.portrait { width: 178px; height: 178px; margin: 0 auto; position: relative; display: grid; place-items: center; }
.portrait:before { content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, var(--ring-tick) 0deg 1deg, transparent 1deg 5deg);
  mask: radial-gradient(transparent 68%, #000 69%, #000 73%, transparent 74%);
  -webkit-mask: radial-gradient(transparent 68%, #000 69%, #000 73%, transparent 74%); opacity: .78;
  transition: transform .12s linear; }
.portrait:after { content: ''; position: absolute; inset: 11px; border-radius: 50%;
  box-shadow: inset 3px 3px 8px rgb(var(--shade) / .55), inset -4px -4px 8px rgb(var(--light) / 1), 0 8px 17px rgb(var(--shade) / .28); pointer-events: none; }
.face { position: relative; width: 146px; height: 146px; transform-origin: 50% 58%; }
.face img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; pointer-events: none; -webkit-user-drag: none; }
.face canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; pointer-events: none; }

/* состояния (вид «пунктир», как в ASTRA): думает — пунктир вращается, говорит — светится */
.portrait[data-state="thinking"]:before { animation: spin 6s linear infinite; opacity: 1; }
.portrait[data-state="speaking"]:before { animation: glow 1.1s ease-in-out infinite; }
.portrait[data-state="listening"]:before { opacity: calc(.78 + var(--level) * .22); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glow { 50% { opacity: .35; } }

/* ---------- виды ободка (решение 44): data-ring на #portrait ----------
   --speak — громкость звучащего ответа (0…1, app.js по самому звуку): ободок движется в такт голосу.
   .halo — второй слой для лучей, волн и искр */
.halo { position: absolute; inset: -10px; border-radius: 50%; pointer-events: none; display: none; }
.halo:before, .halo:after { content: ''; position: absolute; border-radius: 50%; }

/* Живые ободки (решение 49): у каждого вида своё устройство.
   лучи и искры — canvas (ring.js): эквалайзер по полосам частот и частицы; пунктир, дыхание, волны — здесь */
.ring-fx { position: absolute; inset: -22px; width: calc(100% + 44px); height: calc(100% + 44px); pointer-events: none; display: none; }
.portrait:is([data-ring="rays"], [data-ring="sparks"]) .ring-fx { display: block; }
.portrait:is([data-ring="rays"], [data-ring="sparks"]):before { display: none; }
.portrait.mini .ring-fx { inset: -7px; width: calc(100% + 14px); height: calc(100% + 14px); }

/* дыхание: не кольцо, а мягкое сияние вокруг лица — медленно дышит, в речи разгорается по громкости */
.portrait[data-ring="breath"]:before { inset: -14px; background: radial-gradient(circle, transparent 52%, var(--accent) 60%, transparent 72%);
  mask: none; -webkit-mask: none; filter: blur(5px); opacity: .35; animation: breathe-ring 4.5s ease-in-out infinite; }
.portrait[data-ring="breath"][data-state="thinking"]:before { animation: breathe-ring 1.6s ease-in-out infinite; }
.portrait[data-ring="breath"][data-state="speaking"]:before { animation: none; opacity: calc(.3 + var(--speak) * .6);
  transform: scale(calc(1 + var(--speak) * .08)); }
.portrait[data-ring="breath"][data-state="listening"]:before { animation: none; opacity: calc(.3 + var(--level) * .5);
  transform: scale(calc(1 + var(--level) * .05)); }
@keyframes breathe-ring { 50% { opacity: .15; transform: scale(.97); } }

/* волны: тонкое кольцо, от него расходятся круги — в речи чаще и дальше */
.portrait[data-ring="waves"]:before { background: var(--accent);
  mask: radial-gradient(transparent 70%, #000 71%, #000 72.5%, transparent 73.5%);
  -webkit-mask: radial-gradient(transparent 70%, #000 71%, #000 72.5%, transparent 73.5%); opacity: .6; }
.portrait[data-ring="waves"] .halo { display: block; }
.portrait[data-ring="waves"] .halo:before, .portrait[data-ring="waves"] .halo:after { inset: 18%; border: 2px solid var(--accent); opacity: 0; }
.portrait[data-ring="waves"]:is([data-state="speaking"], [data-state="listening"], [data-state="thinking"]) .halo:before { animation: ripple 2.4s ease-out infinite; }
.portrait[data-ring="waves"]:is([data-state="speaking"], [data-state="listening"], [data-state="thinking"]) .halo:after { animation: ripple 2.4s ease-out 1.2s infinite; }
.portrait[data-ring="waves"][data-state="speaking"] .halo:before, .portrait[data-ring="waves"][data-state="speaking"] .halo:after { animation-duration: 1.3s; }
.portrait[data-ring="waves"][data-state="speaking"] .halo { transform: scale(calc(1 + var(--speak) * .12)); }
@keyframes ripple { 0% { transform: scale(.92); opacity: .55; } 100% { transform: scale(1.25); opacity: 0; } }
/* облегчённый вид (решение 44): телефон и экономное питание — только кольцо и мягкий пульс, без второго слоя */
.ring-lite .halo { display: none !important; }
.ring-lite .portrait:before { animation: none !important; transform: none !important; }
.ring-lite .portrait[data-state="speaking"]:before { animation: glow 1.6s ease-in-out infinite !important; }

/* имя и выбор собеседника (решение 31): главное — позвать по имени голосом, список — запасной,
   поэтому маленький и в цветах окна, без системной серой подсветки */
.identity { margin-top: 9px; line-height: 1.2; position: relative; }
.persona-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 12px; background: transparent;
  font: 600 19px 'Segoe UI', sans-serif; color: var(--ink-soft); padding: 4px 10px; max-width: 100%; transition: background .2s, color .2s; }
.persona-btn:hover { background: rgb(var(--light) / .4); color: var(--ink-strong); }
.persona-btn .chev { width: 10px; height: 6px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.persona-btn.single { cursor: default; }
.persona-btn.single:hover { background: transparent; }
.persona-btn.single .chev { display: none; }
.persona-list { position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%); z-index: 20; margin: 0;
  padding: 6px; list-style: none; min-width: 150px; text-align: left; border-radius: 16px;
  background: linear-gradient(135deg, var(--menu-1), var(--menu-2)); box-shadow: 6px 6px 16px rgb(var(--shade) / .4), -4px -4px 12px rgb(var(--light) / .7), inset 0 0 0 1px rgb(var(--light) / .5); }
.persona-list[hidden] { display: none; }
.persona-list button { display: block; width: 100%; border: 0; border-radius: 10px; background: transparent; text-align: left;
  font: 400 15px/1.3 'Segoe UI', sans-serif; color: var(--ink); padding: 7px 12px; }
.persona-list button:hover, .persona-list button:focus-visible { background: var(--hover); outline: none; }
.persona-list [aria-selected="true"] button { color: var(--accent-text); font-weight: 600; background: var(--chosen); }

/* полоска состояния */
.state { margin: 22px auto 0; border-radius: 30px; background: linear-gradient(135deg, var(--raised-1), var(--raised-2));
  box-shadow: 5px 5px 11px rgb(var(--shade) / .31), -5px -5px 12px rgb(var(--light) / .66); min-height: 46px; padding: 4px 8px;
  display: flex; align-items: center; justify-content: center; gap: 7px; font-size: 16px; position: relative; }
.state:after { content: ''; height: 2px; position: absolute; bottom: 0; width: 85px; background: linear-gradient(90deg, transparent, var(--line-glow), transparent); }
.state-dot { height: 6px; width: 6px; background: var(--dot); border-radius: 50%; flex-shrink: 0; transition: background .3s; }
.state-dot.off { background: var(--dot-off); }
.wave { display: flex; align-items: center; gap: 2px; height: 13px; color: var(--wave); }
.wave i { width: 3px; height: 4px; border-radius: 2px; background: currentColor; transform: scaleY(calc(.4 + var(--level) * 2)); transition: transform .16s; }
.wave i:nth-child(2) { height: 8px; } .wave i:nth-child(3) { height: 12px; } .wave i:nth-child(4) { height: 7px; }
#readyText { font-size: 14px; flex: 1; text-align: left; }
.audio-controls { display: flex; gap: 3px; margin-left: auto; }
.audio-controls .icon { width: 30px; height: 30px; border-radius: 10px; }
/* Одно правило для обеих кнопок: синий — включено, серый — выключено (решение владельца: без красного) */
.audio-controls .icon { color: var(--icon-off); }
.audio-controls .icon:hover:not(.recording):not(.active) { color: var(--icon-hover); }
/* Озвучка: вкл — синий динамик на светлом, выкл — серый перечёркнутый (владелец: так понятно).
   Микрофон: слушает — синяя заливка и «дышащее» кольцо */
.audio-controls .icon.active { background: var(--accent-soft); color: var(--accent-strong); box-shadow: 2px 2px 6px rgb(var(--shade) / .3); }
.audio-controls .icon.recording { background: var(--accent-strong); color: white; }
.audio-controls .icon.recording { animation: listening 1.4s ease-out infinite; }
@keyframes listening { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-strong) 40%, transparent); } 100% { box-shadow: 0 0 0 9px transparent; } }
@media (prefers-reduced-motion: reduce) { .audio-controls .icon.recording { animation: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-strong) 20%, transparent); } }

/* Подсветка по просьбе «где микрофон?» (решение 33): мягкое кольцо на 6 с, без мигания.
   outline остаётся и без анимации (prefers-reduced-motion выключает анимации целиком) */
.hint { outline: 2px solid var(--accent-strong); outline-offset: 3px;   /* контур повторяет скругление кнопки */
        animation: hint 1.6s ease-in-out 3; }
@keyframes hint { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent-strong) 20%, transparent); } }

/* ---------- текущий ответ и ввод ---------- */
/* Левая колонка — на всю высоту окна: карточка ответа растягивается, поле ввода прижато к низу,
   без пустого места под ним (замечание владельца) */
.companion-body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.folded .companion-body { height: auto; }
.conversation { padding: 17px 19px 24px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.bubble { border-radius: 23px; background: linear-gradient(140deg, var(--bubble-1), var(--bubble-2)); padding: 19px 20px 14px;
  box-shadow: 7px 7px 15px rgb(var(--shade) / .33), -6px -6px 15px rgb(var(--light) / .61); flex: 1 1 0; min-height: 160px; overflow: auto;
  scrollbar-width: thin; scrollbar-color: var(--dash) transparent; }
.bubble p { font-size: 19px; line-height: 1.55; margin: 0 0 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble p:last-child { margin-bottom: 0; }
.message-user { color: var(--muted); font-size: 15px !important; }
.sources { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px !important; line-height: 1.4 !important; }
.sources a { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }
.open-result { display: block; margin: 13px 0 0 auto; border: 0; background: none; color: var(--muted); font-size: 14px; }
.open-result.back { margin: 0 0 14px; padding: 0; }
.entry { margin-top: 17px; display: flex; align-items: center; gap: 8px; border-radius: 17px; padding: 7px 8px 7px 15px;
  background: var(--well); box-shadow: inset 3px 3px 7px rgb(var(--shade) / .37), inset -3px -3px 8px rgb(var(--light) / .76); }
.entry input { min-width: 0; width: 100%; border: 0; background: none; color: var(--ink-soft); outline: none; font-size: 16px; padding: 7px 0; }
.entry input::placeholder { color: var(--placeholder); }
.entry .send { background: var(--accent); color: white; flex-shrink: 0; box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 31%, transparent); }
.entry .send:hover { background: var(--accent-strong); }

/* ---------- панель «Разговоры» ---------- */
.detail-pane { display: none; background: linear-gradient(135deg, var(--pane-1), var(--pane-2)); border-left: 1px solid rgb(var(--light) / .47);
  padding: 25px 25px 30px; min-width: 0; height: 100vh; overflow-y: auto; }
.expanded .detail-pane { display: block; }
/* заголовок «Разговоры» остаётся наверху, пока список прокручен к последним сообщениям */
.detail-head { display: flex; align-items: center; justify-content: space-between; margin: -25px -25px 6px; padding: 25px 25px 16px;
  position: sticky; top: -25px; z-index: 2; background: linear-gradient(135deg, var(--pane-1), var(--pane-head)); }
.native .detail-head { user-select: none; }
.detail-head h1 { font-size: 23px; line-height: 1.25; margin: 0; font-weight: 600; }
.detail-head p { font-size: 13px; margin: 6px 0 0; color: var(--muted); }
.detail-head p:empty { display: none; }
.sheet { background: var(--sheet); border-radius: 19px; padding: 20px; box-shadow: 5px 5px 15px rgb(var(--shade) / .18), -4px -4px 12px rgb(var(--light) / .53); margin-bottom: 15px; }
.sheet p { font-size: 16px; line-height: 1.6; margin: 0 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet p:last-child { margin: 0; }
.sheet small { color: var(--muted); font-size: 13px; }
.sheet label { display: flex; gap: 8px; align-items: center; font-size: 16px; }
.subtle { color: var(--muted); font-size: 16px; }
.view[hidden] { display: none; }

/* ---------- рабочая область «Вид окна» (решение 47): образцы цветов и ободков ----------
   Кружок цвета показывает чужую тему, поэтому её цвета — здесь, рядом с темами (фон и акцент темы) */
.look-group h3 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }
.look-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.look-pick { border: 0; border-radius: 16px; background: transparent; padding: 8px 4px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-size: 14px; color: var(--ink); }
.look-pick:hover { background: var(--hover); }
.look-pick[aria-pressed="true"] { background: var(--chosen); color: var(--accent-text); font-weight: 600; }
.swatch { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--sw-bg) 50%, var(--sw-accent) 50%);
  box-shadow: 0 3px 8px rgb(var(--shade) / .35); }
.look-pick[aria-pressed="true"] .swatch { box-shadow: 0 0 0 3px var(--accent); }
.swatch[data-swatch="light"] { --sw-bg: #dce7f3; --sw-accent: #6c87d3; }
.swatch[data-swatch="dark"] { --sw-bg: #1f2633; --sw-accent: #6f8be0; }
.swatch[data-swatch="green"] { --sw-bg: #dcebe3; --sw-accent: #4f9a7b; }
.swatch[data-swatch="warm"] { --sw-bg: #f1e6da; --sw-accent: #d08a55; }
.swatch[data-swatch="lilac"] { --sw-bg: #e6e0f2; --sw-accent: #8a6fd3; }
.swatch[data-swatch="pink"] { --sw-bg: #f3e1e8; --sw-accent: #d0688f; }
.swatch[data-swatch="yellow"] { --sw-bg: #f3ecd2; --sw-accent: #c49a1c; }
.swatch[data-swatch="teal"] { --sw-bg: #d9edef; --sw-accent: #2c9aa8; }
.portrait.mini { width: 60px; height: 60px; margin: 4px; }
.portrait.mini:after { display: none; }
.portrait.mini .halo { inset: -5px; }
.look-own { margin-top: 10px; border: 0; border-radius: 14px; padding: 8px 16px; font-size: 15px; background: var(--accent-soft);
  color: var(--icon-hover); }
.look-own[aria-pressed="true"] { background: var(--chosen); color: var(--accent-text); font-weight: 600; }
.look-hint { font-size: 14px; color: var(--muted); margin: 0 4px; }

/* ---------- рабочая область «Собеседники» (шаг В1) ---------- */
.persona-list .setup { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.persona-list .setup button { color: var(--muted); font-size: 14px; white-space: nowrap; }
.ws-lead { margin: 0 0 14px; }
.slot-card { display: grid; grid-template-columns: 64px 1fr; gap: 6px 14px; align-items: center; }
.slot-face { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; box-shadow: 0 4px 10px rgb(var(--shade) / .28); grid-row: span 2; }
.slot-face.empty { background: var(--well); box-shadow: inset 3px 3px 7px rgb(var(--shade) / .37), inset -3px -3px 8px rgb(var(--light) / .76); }
.slot-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.slot-text strong { font-size: 18px; overflow-wrap: anywhere; }
.slot-text .subtle { font-size: 14px; }
.draft-note { font-size: 13px; color: var(--draft); }
.slot-actions, .ws-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ws-actions { justify-content: space-between; margin: 4px 0 10px; }
.pill { border: 0; border-radius: 14px; padding: 8px 16px; font-size: 15px; background: var(--accent-soft); color: var(--icon-hover);
  box-shadow: 2px 2px 6px rgb(var(--shade) / .3), -2px -2px 6px rgb(var(--light) / .7); }
.pill:hover:not(:disabled) { background: var(--pane-1); }
.pill.primary { background: var(--accent); color: white; box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 31%, transparent); }
.pill.primary:hover:not(:disabled) { background: var(--accent-strong); }
.limit-line { font-size: 14px; margin: 6px 0 0; }
.ws-error { color: var(--error); font-size: 15px; margin: 0 0 8px; }
.steps { display: flex; gap: 4px; flex-wrap: wrap; margin: 6px 0 12px; }
.step { border: 0; border-radius: 10px; padding: 4px 10px; font-size: 13px; background: transparent; color: var(--muted); }
.step.done { color: var(--accent-text); }
.step.current { background: var(--chosen); color: var(--accent-text); font-weight: 600; }
.step-body h2 { font-size: 18px; font-weight: 600; margin: 0 0 14px; }
.face-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.face-pick { border: 0; border-radius: 16px; background: transparent; padding: 6px 4px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; font-size: 13px; color: var(--ink); }
.face-pick img { width: 66px; height: 66px; border-radius: 50%; object-fit: cover; box-shadow: 0 4px 10px rgb(var(--shade) / .28); }
.face-pick:hover:not(:disabled) { background: var(--hover); }
.face-pick.chosen { background: var(--chosen); color: var(--accent-text); font-weight: 600; }
.face-pick.chosen img { box-shadow: 0 0 0 3px var(--accent); }
.face-pick:disabled img { filter: grayscale(1); opacity: .45; }
.name-input { width: 100%; border: 0; border-radius: 14px; padding: 10px 14px; font-size: 18px; color: var(--ink-soft); background: var(--well);
  box-shadow: inset 3px 3px 7px rgb(var(--shade) / .37), inset -3px -3px 8px rgb(var(--light) / .76); outline: none; }
.step-body .subtle { font-size: 14px; margin-top: 10px; }
.choices { display: flex; flex-direction: column; gap: 6px; }
.choice { display: flex; align-items: center; gap: 8px; border-radius: 14px; }
.choice-main { flex: 1; border: 0; border-radius: 14px; background: transparent; text-align: left; padding: 8px 12px; font-size: 16px;
  color: var(--ink); display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.choice-main .subtle { margin: 0; font-size: 13px; }
.choice-main:hover, .choice:hover .choice-main { background: var(--hover); }
.chosen.choice, .choice-main.chosen { background: var(--chosen); }
.chosen.choice .choice-main, .choice-main.chosen strong { color: var(--accent-text); font-weight: 600; }
.pairs { display: flex; flex-direction: column; gap: 10px; }
.pair { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pair-title { font-size: 15px; color: var(--muted); }
.seg { display: inline-flex; border-radius: 13px; padding: 3px; background: var(--well);
  box-shadow: inset 2px 2px 5px rgb(var(--shade) / .37), inset -2px -2px 6px rgb(var(--light) / .76); }
.seg button { border: 0; border-radius: 10px; background: transparent; padding: 5px 12px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--pane-1); color: var(--accent-text); font-weight: 600; box-shadow: 1px 1px 4px rgb(var(--shade) / .3); }
.dev-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 22px; padding-top: 12px;
  border-top: 1px dashed var(--dash); font-size: 13px; color: var(--muted); }

/* свёрнуто: только шапка */
.folded { max-width: 320px; min-height: 0; }
.folded .presence, .folded .conversation, .folded .detail-pane { display: none !important; }
.folded .chrome { padding-bottom: 14px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--toast); color: white; border-radius: 13px;
  padding: 14px 22px; font-size: 15px; box-shadow: 0 9px 25px rgb(var(--shade) / .26); max-width: calc(100% - 30px); z-index: 30; }
#toast[hidden] { display: none; }

/* экран согласия бета-тестера */
.consent { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgb(var(--shade) / .55); backdrop-filter: blur(3px); }
.consent[hidden] { display: none; }
.consent-card { max-width: 420px; width: 100%; box-sizing: border-box; background: var(--sheet); color: var(--ink); border-radius: 18px;
  padding: 22px 22px 18px; box-shadow: 0 14px 40px rgb(var(--shade) / .45); }
.consent-card h2 { margin: 0 0 10px; font-size: 19px; color: var(--ink-strong); }
.consent-card p { margin: 0 0 18px; font-size: 15px; line-height: 1.45; }
.consent-card button { display: block; margin-left: auto; padding: 10px 22px; border: 0; border-radius: 12px;
  background: var(--accent-strong); color: white; font-size: 15px; cursor: pointer; }
.consent-card button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* код доступа (телефон) */
.access-code { display: block; width: 100%; box-sizing: border-box; margin: 0 0 16px; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--well); color: var(--ink-strong);
  font-size: 16px; letter-spacing: .04em; }
.access-code:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.access-wrong { color: var(--error); }
/* телефон: окно приложения не сворачивается и не закрывается кнопками в шапке */
.phone #fold, .phone #quit { display: none; }
.access-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.consent-card .access-actions button { margin-left: 0; }
.consent-card .access-paste { background: transparent; color: var(--ink-strong); box-shadow: inset 0 0 0 1px var(--ink); }

/* ---------- лицо Астры: робот (скрыт до решения владельца) ---------- */
.robot { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; }
.portrait[data-kind="photo"] .robot { display: none; }
.portrait[data-kind="robot"] img, .portrait[data-kind="robot"] canvas { display: none; }
.robot .eye rect, .robot .bar, .robot .gem, .robot .ear-light { fill: #7fe3ff; }
.robot .accent-line { stroke: #6f80e3; opacity: .55; }
.robot .ear-light { opacity: .35; transition: opacity .3s; }
.robot .gem { opacity: .55; }
.robot .eye { transform-box: fill-box; transform-origin: center; transition: transform .12s ease; }
.robot .eyes { transition: transform .4s ease; }
.robot .bar { transform-box: fill-box; transform-origin: center; transition: transform .15s; }
.robot.blink .eye { transform: scaleY(.12); }
.robot[data-state="idle"] .eyes { animation: breathe 4.5s ease-in-out infinite; }
.robot[data-state="listening"] .eye { transform: scale(1.12, 1.18); }
.robot[data-state="listening"] .ear-light { opacity: 1; }
.robot[data-state="thinking"] .eyes { transform: translate(3px, -3px); }
.robot[data-state="thinking"] .gem { animation: pulse 1s ease-in-out infinite; }
.robot[data-state="speaking"] .bar { animation: talk .42s ease-in-out infinite alternate; }
.robot[data-state="speaking"] .b1 { animation-delay: -.30s; }
.robot[data-state="speaking"] .b2 { animation-delay: -.12s; }
.robot[data-state="speaking"] .b3 { animation-delay: -.36s; }
.robot[data-state="speaking"] .b4 { animation-delay: -.05s; }
.robot[data-state="speaking"] .b5 { animation-delay: -.22s; }
@keyframes breathe { 50% { opacity: .82; } }
@keyframes pulse { 50% { opacity: 1; r: 5; } }
@keyframes talk { from { transform: scaleY(1); } to { transform: scaleY(3.4); } }

/* ---------- телефон и узкое окно (как в ASTRA) ---------- */
@media (max-width: 760px) {
  .companion, .companion:not(.expanded) { border-radius: 0; max-width: none; }
  .expanded .layout { display: block; }
  .expanded .detail-pane { position: absolute; inset: 62px 0 0; border: 0; border-radius: 0 0 22px 22px; z-index: 4; height: auto; }
  .detail-pane { padding: 20px; }
  .portrait { width: 162px; height: 162px; }
  .face { width: 133px; height: 133px; }
  .presence { padding-top: 15px; }
  .state { margin-top: 18px; }
  .bubble p { font-size: 18px; }
  .chrome { padding-top: max(14px, env(safe-area-inset-top)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
