/* SABIT AI Assistant — стриманий «документаційний» стиль: нейтральні тони, тонкі лінії,
   відповідь читається як сторінка довідки, а не як бульбашка чату. */
:root {
  --bg: #fbfbfa; --panel: #ffffff; --side: #f4f4f2; --text: #1a1c20; --text-2: #4a4f59; --muted: #7c818b;
  --line: #e6e6e3; --line-2: #d6d6d2; --accent: #c8102e; --accent-2: #a50d26;
  --code: #f3f3f1; --link: #1d4ed8; --link-line: rgba(29, 78, 216, .35); --hover: #ececea;
  --focus: rgba(200, 16, 46, .18);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
/* Темна тема: за системою (якщо користувач не вибрав світлу) або вибрана вручну в Налаштуваннях */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #111214; --panel: #17181b; --side: #141517; --text: #ececee; --text-2: #b9bcc3; --muted: #868a93;
    --line: #26282c; --line-2: #34363b; --code: #1d1f23; --link: #9cc3ff; --link-line: rgba(156, 195, 255, .35);
    --hover: #1f2125; --focus: rgba(255, 90, 110, .25); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #111214; --panel: #17181b; --side: #141517; --text: #ececee; --text-2: #b9bcc3; --muted: #868a93;
    --line: #26282c; --line-2: #34363b; --code: #1d1f23; --link: #9cc3ff; --link-line: rgba(156, 195, 255, .35);
    --hover: #1f2125; --focus: rgba(255, 90, 110, .25); color-scheme: dark; }
/* Розмір тексту відповіді: Налаштування → Розмір тексту */
:root { --scale: 1; }
:root[data-size="s"] { --scale: .92; }
:root[data-size="l"] { --scale: 1.12; }
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { margin: 0; font: 15px/1.6 var(--font); background: var(--bg); color: var(--text);
  font-feature-settings: "cv11", "ss01"; letter-spacing: -0.003em; }
.hidden { display: none !important; }

/* ---------- Кнопки й поля ---------- */
button { font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text); padding: 7px 14px;
  transition: background .15s, border-color .15s, color .15s; }
button:hover { background: var(--hover); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
input:focus, textarea:focus { outline: none; border-color: var(--muted); box-shadow: 0 0 0 3px var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.secondary { border-color: var(--line-2); color: var(--text); }
button.secondary:hover { border-color: var(--accent); color: var(--accent); background: var(--panel); }
button.ghost { border-color: var(--line-2); background: transparent; text-align: left; }
button.link { border: none; background: none; color: var(--muted); padding: 4px 0; font-weight: 400; }
button.link:hover { color: var(--text); background: none; }
button:disabled { opacity: .45; cursor: default; }
input, textarea { font: inherit; width: 100%; padding: 10px 12px; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text); }
::placeholder { color: var(--muted); }

.brand { font-weight: 650; font-size: 20px; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-weight: 450; }
.brand::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px;
  background: var(--accent); margin-right: 9px; vertical-align: 2px; }
.brand.small { font-size: 15px; }
.msg { min-height: 1.5em; color: var(--muted); font-size: 14px; } .msg.err { color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }
.langs { display: flex; gap: 2px; margin-top: 12px; }
.langs button { padding: 2px 8px; font-size: 12px; border-color: transparent; background: none; color: var(--muted); }
.langs button.on { color: var(--text); border-color: var(--line-2); }

/* ---------- Вхід ---------- */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 32px; width: 100%; max-width: 400px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .04); }
.card p { color: var(--text-2); }
#login-form { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Каркас ---------- */
#app { display: flex; height: 100vh; }
#sidebar { width: 252px; flex: none; background: var(--side);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 10px; }
#side-resizer { flex: none; width: 7px; margin: 0 -3px; position: relative; z-index: 2; cursor: col-resize; touch-action: none; }
#side-resizer::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 1px; background: var(--line); transition: background .15s, width .15s, left .15s; }
#side-resizer:hover::after, #side-resizer:focus-visible::after, body.resizing #side-resizer::after { left: 2px; width: 3px; background: var(--muted); }
#side-resizer:focus-visible { outline: none; }
body.resizing { cursor: col-resize; user-select: none; }
#conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#conv-list li.group { cursor: default; padding: 12px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); background: none; }
#conv-list li.conv { display: flex; align-items: center; gap: 4px; }
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pin { border: none; background: none; padding: 2px 4px; color: var(--muted); opacity: 0; display: inline-flex; }
#conv-list li.conv:hover .pin, .pin.on, .pin:focus-visible { opacity: 1; }
.pin.on { color: var(--text-2); }
.pin:hover { background: none; color: var(--text); }
#conv-list li { padding: 6px 10px; border-radius: 5px; cursor: pointer; white-space: nowrap; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; }
#conv-list li:hover { background: var(--hover); color: var(--text); }
#conv-list li.on { background: var(--hover); color: var(--text); font-weight: 500; }
.side-foot { border-top: 1px solid var(--line); padding-top: 8px; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header { display: flex; align-items: center; gap: 12px; padding: 0 20px; height: 52px; border-bottom: 1px solid var(--line); background: var(--bg); }
header #ticket-btn { margin-left: auto; }
.icon { display: none; border: none; background: none; font-size: 18px; padding: 4px 8px; }
.badge.tester { border-color: #3b82f6; color: #3b82f6; }
.badge { border: 1px solid #d99a1e; color: #d99a1e; border-radius: 4px; padding: 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .04em; }

/* ---------- Розмова ---------- */
#messages { flex: 1; overflow-y: auto; padding: 32px 20px 24px; display: flex; flex-direction: column; gap: 8px; }
.m { max-width: 720px; width: 100%; margin: 0 auto; }
.m.user { margin-top: 20px; }
.m.user:first-child { margin-top: 0; }
.m.user .bubble { white-space: pre-wrap; font-weight: 550; font-size: calc(16px * var(--scale)); line-height: 1.5; letter-spacing: -0.01em;
  padding: 0 0 12px; border-bottom: 1px solid var(--line); color: var(--text); }
.m.assistant .bubble { padding: 4px 0 0; color: var(--text); overflow-x: auto; font-size: calc(15px * var(--scale)); }
.m .bubble p { margin: 0 0 12px; } .m .bubble p:last-child { margin-bottom: 0; }
.m .bubble h3 { font-size: 15.5px; font-weight: 600; margin: 22px 0 8px; letter-spacing: -0.01em; }
.m .bubble h4 { font-size: 14.5px; font-weight: 600; margin: 18px 0 6px; color: var(--text-2); }
.m .bubble h3:first-child, .m .bubble h4:first-child { margin-top: 4px; }
.m .bubble ul, .m .bubble ol { margin: 0 0 12px; padding-left: 22px; }
.m .bubble li { margin: 3px 0; } .m .bubble li::marker { color: var(--muted); }
.m .bubble strong { font-weight: 600; }
.m .bubble pre { background: var(--code); padding: 12px 14px; margin: 0; overflow-x: auto; font-size: calc(13px * var(--scale)); line-height: 1.55; }
.codeblock { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: 0 0 12px; background: var(--code); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--line); font: 11.5px/1.6 var(--mono); color: var(--muted); }
.code-copy { display: inline-flex; align-items: center; gap: 6px; border: none; background: none; color: var(--muted);
  padding: 3px 8px; font-size: 12px; font-weight: 500; }
.code-copy:hover { background: var(--hover); color: var(--text); }
.code-copy.ok, .act.ok { color: #1f9d55; }
.m .bubble code { font-family: var(--mono); background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: .88em; }
.m .bubble pre code { padding: 0; background: none; font-size: inherit; }

/* Посилання: колір тексту з тонким підкресленням; акцент лише при наведенні */
a, a:visited { color: var(--link); text-decoration: underline; text-decoration-color: var(--link-line);
  text-decoration-thickness: 1px; text-underline-offset: 3px; transition: text-decoration-color .15s; }
a:hover { text-decoration-color: currentColor; }

/* Джерела: підпис + список як у довідці */
.sources { margin-top: 16px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 12.5px;
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.sources-label { color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: 11px; font-weight: 600; }
.sources a, .sources a:visited { color: var(--text-2); text-decoration-color: var(--line-2); }
.sources a:hover { color: var(--text); text-decoration-color: currentColor; }

/* Пошук у базі: тонка лінія, що «сканує», + етап */
.working { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; color: var(--muted); font-size: 13.5px; }
.scan { position: relative; display: block; width: 160px; height: 2px; background: var(--line); overflow: hidden; border-radius: 2px; }
.scan::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 40%; background: var(--accent);
  animation: scan 1.2s cubic-bezier(.4, 0, .2, 1) infinite; }
@keyframes scan { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .scan::after { animation: none; width: 100%; opacity: .5; } }

.empty { margin: auto; text-align: center; color: var(--muted); max-width: 520px; }
#composer { display: flex; gap: 8px; padding: 12px 20px 8px; max-width: 760px; width: 100%; margin: 0 auto; align-items: flex-end; }
#composer textarea { font-size: calc(15px * var(--scale)); resize: none; border-radius: 8px; padding: 12px 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
#composer button { height: 44px; }
.disclaimer { text-align: center; font-size: 11px; line-height: 1.4; color: var(--muted); opacity: .8; margin: 0 0 2px; padding: 0 16px; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text);
  width: min(640px, calc(100vw - 32px)); padding: 24px; box-shadow: 0 16px 48px rgba(0, 0, 0, .18); }
dialog::backdrop { background: rgba(10, 10, 12, .4); }
dialog form { display: flex; flex-direction: column; gap: 8px; }
dialog label { font-size: 13px; font-weight: 500; color: var(--text-2); margin-top: 4px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
dialog h3 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

@media (max-width: 760px) {
  #sidebar { position: fixed; z-index: 10; height: 100vh; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: none; }
  #sidebar { width: 280px !important; border-right: 1px solid var(--line); }
  #side-resizer { display: none; }
  .icon { display: block; }
  header { padding: 0 12px; }
  header #ticket-btn { padding: 6px 10px; font-size: 13px; }
  #messages { padding: 20px 16px; }
  #composer { padding: 10px 16px 6px; }
}

/* Дії під відповіддю: копіювати, 👍, 👎 */
.actions { display: flex; gap: 2px; margin-top: 10px; }
.act { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 28px; padding: 0;
  border: none; background: none; color: var(--muted); border-radius: 5px; }
.act:hover { background: var(--hover); color: var(--text); }
.act.up.on { color: #1f9d55; } .act.down.on { color: var(--accent); }
.fb { margin-top: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.fb-title { font-size: 13px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; font-size: 12.5px; border-radius: 999px; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.fb textarea { font-size: 13px; resize: vertical; }
.fb-row { display: flex; justify-content: flex-end; gap: 8px; }
.fb-thanks { font-size: 13px; color: var(--text-2); }

/* Налаштування */
/* Обліковий запис унизу сайдбару */
.account { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: none; background: none;
  text-align: left; border-radius: 6px; font-weight: 400; }
.account:hover { background: var(--hover); }
.avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--text); color: var(--bg); font-size: 11.5px; font-weight: 600; letter-spacing: .02em; }
.acc-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.acc-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-name:not(.hidden) + .acc-email { font-size: 12px; font-weight: 400; color: var(--text-2); }
.acc-email { font-size: 13px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-limits { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.acc-gear { flex: none; color: var(--muted); display: inline-flex; }
.account:hover .acc-gear { color: var(--text); }
.set-account { display: flex; align-items: center; gap: 12px; }
button.small { padding: 5px 12px; font-size: 13px; }
.settings section { padding: 14px 0; border-top: 1px solid var(--line); }
.settings section:first-of-type { margin-top: 10px; }
.settings h4 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.set-value { font-weight: 500; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 6px 0; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { border: none; background: none; padding: 4px 12px; font-size: 13px; color: var(--text-2); border-radius: 5px; }
.seg button:hover { background: var(--hover); }
.seg button.on { background: var(--hover); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.settings .row { justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 14px; }
button.link.danger:hover { color: var(--accent); }

/* Правова інформація і приватність */
.legal-foot { text-align: center; font-size: 10.5px; color: var(--muted); opacity: .6; padding: 0 16px 8px; line-height: 1.4; transition: opacity .15s; }
.legal-foot:hover { opacity: 1; }
.legal-foot a, .legal-links a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 2px; }
.legal-foot a:hover, .legal-links a:hover { color: var(--text-2); }
#login .legal-foot { position: fixed; left: 0; right: 0; bottom: 0; }
.legal-links { margin: 8px 0 0; }
.conv-del { border: none; background: none; padding: 2px 4px; color: var(--muted); opacity: 0; display: inline-flex; }
#conv-list li.conv:hover .conv-del, .conv-del:focus-visible { opacity: 1; }
.conv-del:hover { background: none; color: var(--accent); }
button.danger { color: var(--accent); }
button.primary.danger { background: var(--accent); color: #fff; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; color: var(--text); line-height: 1.45; }
label.check input { margin-top: 3px; width: auto; flex: none; padding: 0; border: none; box-shadow: none; }
#terms-text a, #terms-check-label a { color: var(--link); }
