/* Сора — палитра Соранеи: тёмно-синий + голубой акцент */
:root {
  --bg: #0b1424; --bg2: #0f1b30; --panel: #13223b; --panel2: #182a47; --line: #22385a;
  --text: #e6eefb; --muted: #8fa3c2; --accent: #4cc3ff; --accent2: #1e88d6; --accent-ink: #04203a;
  --ok: #3ccf91; --warn: #ffb547; --err: #ff6b6b; --user: #1d3b66; --code: #0a1222;
  --radius: 14px; --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f6fb; --bg2: #e9eef7; --panel: #ffffff; --panel2: #f0f4fa; --line: #d6dfec;
  --text: #0e1c33; --muted: #5a6b86; --accent: #0f7fd1; --accent2: #0b62a8; --accent-ink: #ffffff;
  --user: #dceafa; --code: #eef3fa; --shadow: 0 10px 30px rgba(15, 35, 70, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #f3f6fb; --bg2: #e9eef7; --panel: #ffffff; --panel2: #f0f4fa; --line: #d6dfec;
    --text: #0e1c33; --muted: #5a6b86; --accent: #0f7fd1; --accent2: #0b62a8; --accent-ink: #ffffff;
    --user: #dceafa; --code: #eef3fa; --shadow: 0 10px 30px rgba(15, 35, 70, .12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
svg { width: 18px; height: 18px; flex: none; }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 9px 14px; cursor: pointer; transition: .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); border: 0; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted); transition: .15s; }
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.icon-btn.accent { color: var(--accent); }
.voice-btn { padding: 6px 12px; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.voice-btn:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
input, select, textarea { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* «шар» — фирменный знак */
.orb { position: relative; border-radius: 50%; background: radial-gradient(circle at 50% 45%, #e9fbff 0 8%, var(--accent) 22%, var(--accent2) 52%, #0a2b52 72%); box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 60%, transparent); }
.orb i { position: absolute; inset: 18%; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .55); border-left-color: transparent; border-right-color: transparent; animation: spin 6s linear infinite; }
.orb-sm { width: 26px; height: 26px; }
.orb-lg { width: 72px; height: 72px; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, var(--bg2), var(--bg)); }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: .5px; }
.login-card p { margin: -8px 0 4px; }
.login-card label { text-align: left; }
.err { color: var(--err); min-height: 1.2em; margin: 0; font-size: 14px; }

/* каркас */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; height: 100dvh; }
.side { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--bg2); border-right: 1px solid var(--line); min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: .3px; }
.search { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; margin: 0 -6px; padding: 0 6px; }
.conv-list .day { font-size: 12px; color: var(--muted); padding: 10px 8px 4px; text-transform: uppercase; letter-spacing: .5px; }
.conv { display: flex; align-items: center; gap: 6px; border-radius: 9px; padding: 7px 8px; cursor: pointer; color: var(--text); text-decoration: none; }
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel2); box-shadow: inset 2px 0 var(--accent); }
.conv span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.conv .kb-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.conv .icon-btn { width: 26px; height: 26px; opacity: 0; }
.conv:hover .icon-btn, .conv.active .icon-btn { opacity: 1; }
.side-nav { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 10px; }
.side-nav button { display: flex; align-items: center; gap: 10px; background: none; border: 0; border-radius: 9px; padding: 8px; cursor: pointer; text-align: left; color: var(--text); }
.side-nav button:hover, .side-nav button.active { background: var(--panel); }
.side-nav button svg { color: var(--muted); }
.me { display: flex; justify-content: space-between; align-items: center; padding: 8px; font-size: 14px; color: var(--muted); }
.scrim { display: none; }
.only-mobile { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); min-height: 58px; }
.top h2 { flex: 1; margin: 0; font-size: 16px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.top-tools { display: flex; align-items: center; gap: 6px; }
.top-tools select { padding: 6px 10px; font-size: 13px; max-width: 170px; }
.view { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

/* чат */
.chat { max-width: 860px; margin: 0 auto; padding: 22px 20px 12px; display: grid; gap: 20px; }
.msg { display: grid; gap: 8px; min-width: 0; }
.msg.user { justify-items: end; }
.msg.user .bubble { background: var(--user); border-radius: 16px 16px 4px 16px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot { grid-template-columns: 30px 1fr; column-gap: 12px; }
.msg.bot > .orb { margin-top: 2px; }
.msg.bot .body { min-width: 0; display: grid; gap: 8px; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .6em; } .md ul, .md ol { margin: 0 0 .6em; padding-left: 1.4em; } .md li { margin: .15em 0; }
.md h3, .md h4 { margin: .8em 0 .4em; font-size: 15.5px; }
.md code { background: var(--code); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; }
.md pre { position: relative; background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 .7em; }
.md pre code { background: none; border: 0; padding: 0; white-space: pre; }
.md pre .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 .7em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md th { background: var(--panel2); }
.md blockquote { margin: 0 0 .6em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; font-size: 11px; border-radius: 5px; border: 0; background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); cursor: pointer; vertical-align: 2px; }
.caret { display: inline-block; width: 8px; height: 16px; background: var(--accent); vertical-align: -3px; animation: blink 1s steps(2) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: inline-flex; gap: 4px; padding: 6px 0; } .thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: dot 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .2s; } .thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: none; } }

.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tool { border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: 12.5px; color: var(--muted); }
.tool summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 4px 10px; }
.tool summary::-webkit-details-marker { display: none; }
.tool .st { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: dot 1s infinite; }
.tool.ok .st { background: var(--ok); animation: none; } .tool.fail .st { background: var(--err); animation: none; }
.tool[open] { border-radius: 12px; flex-basis: 100%; }
.tool pre { margin: 0; padding: 8px 12px 10px; white-space: pre-wrap; font: 12px/1.5 ui-monospace, Consolas, monospace; color: var(--text); max-height: 260px; overflow: auto; border-top: 1px solid var(--line); }
.sources { display: grid; gap: 4px; font-size: 13px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 10px; }
.sources div.hl { color: var(--text); }
.actions { display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; }
.actions .icon-btn { width: 30px; height: 30px; }
.actions .icon-btn.on { color: var(--accent); }
.actions .model { margin-left: 6px; }
.err-box { color: var(--err); }

.empty { max-width: 680px; margin: 0 auto; padding: 12vh 20px 20px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty h1 { margin: 10px 0 0; font-size: 26px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 14px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

.composer { padding: 10px 18px 14px; }
.composer-box { max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow); }
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; padding: 8px 0; max-height: 220px; line-height: 1.5; }
.composer .send { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); }
.composer .send:disabled { opacity: .4; }
.composer .send.stop { background: var(--panel2); color: var(--err); }
#micBtn.rec { color: var(--err); background: color-mix(in srgb, var(--err) 15%, transparent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--err) 18%, transparent); } }
.composer-hint { max-width: 860px; margin: 6px auto 0; font-size: 12px; color: var(--muted); min-height: 16px; padding: 0 6px; }

/* страницы */
.page { max-width: 860px; margin: 0 auto; padding: 24px 20px 40px; display: grid; gap: 18px; align-content: start; }
.page h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page h3 { margin: 0 0 10px; font-size: 15px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.list { display: grid; gap: 0; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); vertical-align: 1px; margin-left: 6px; }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.off { background: var(--panel2); color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--panel2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-weight: 600; }
.stat span { font-size: 12px; color: var(--muted); }
.kb-card { cursor: pointer; }
.kb-card:hover { border-color: var(--accent); }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over, .drop:hover { border-color: var(--accent); color: var(--accent); }

/* голосовой режим */
.voice { position: fixed; inset: 0; z-index: 50; background: radial-gradient(ellipse at center, #10233f 0%, #050b16 75%); color: #e6eefb; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; }
.voice-close { position: absolute; top: 16px; right: 16px; color: #8fa3c2; }
.voice-orb { position: relative; width: min(220px, 52vw); aspect-ratio: 1; border-radius: 50%; cursor: pointer; margin-bottom: 18px;
  background: radial-gradient(circle at 50% 45%, #f2fdff 0 6%, #4cc3ff 20%, #1e88d6 48%, #0a2b52 70%, transparent 71%);
  box-shadow: 0 0 calc(40px + var(--lvl, 0) * 90px) rgba(76, 195, 255, calc(.35 + var(--lvl, 0) * .5)); transition: box-shadow .08s, transform .08s; transform: scale(calc(1 + var(--lvl, 0) * .08)); }
.voice-orb i, .voice-orb b { position: absolute; border-radius: 50%; border: 2px solid rgba(220, 245, 255, .55); }
.voice-orb i { inset: 14%; border-left-color: transparent; border-right-color: transparent; animation: spin 5s linear infinite; }
.voice-orb b { inset: 26%; border-top-color: transparent; border-bottom-color: transparent; animation: spin 3s linear infinite reverse; }
.voice[data-state="thinking"] .voice-orb i { animation-duration: 1s; } .voice[data-state="thinking"] .voice-orb b { animation-duration: .7s; }
.voice[data-state="speaking"] .voice-orb { animation: breathe 1.4s ease-in-out infinite; }
.voice[data-state="idle"] .voice-orb { filter: saturate(.4) brightness(.8); }
@keyframes breathe { 50% { box-shadow: 0 0 120px rgba(76, 195, 255, .8); } }
.voice-state { font-size: 20px; margin: 0; letter-spacing: .3px; }
.voice-heard { margin: 0; color: #8fa3c2; min-height: 1.4em; max-width: 640px; }
.voice-answer { margin: 0; max-width: 680px; font-size: 17px; line-height: 1.5; max-height: 30vh; overflow: auto; }

/* модальное окно и уведомление */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(3, 8, 18, .6); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.modal-card h3 { margin: 0; font-size: 17px; }
.modal-card textarea { min-height: 90px; resize: vertical; }
.modal-card .row { justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; z-index: 70; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; box-shadow: var(--shadow); pointer-events: none; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--err); }

/* телефон */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-102%); transition: transform .2s; }
  .app.side-open .side { transform: none; box-shadow: var(--shadow); }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .45); }
  .only-mobile { display: inline-grid; }
  .top { padding: 8px 10px; gap: 4px; }
  .top-tools select { max-width: 92px; padding: 6px; }
  .chat { padding: 16px 14px 8px; }
  .composer { padding: 8px 10px 10px; }
  .page { padding: 18px 16px 32px; }
  .grid2 { grid-template-columns: 1fr; }
  .msg.bot { grid-template-columns: 1fr; } .msg.bot > .orb { display: none; }
}
@media (max-width: 420px) { #kbSel { display: none; } .voice-btn .lbl { display: none; } .voice-btn { padding: 6px 9px; } }
