/* Модели. Канон админки Тёрки (как gpu-panel и marketer): тёплый крем + синий primary, карточки с рамкой,
   Inter из самохоста, lucide-иконки. Сначала телефон: один экран за раз; от 860 px — список и разговор рядом. */
@font-face { font-family: 'Inter Variable'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(fonts/inter-cyrillic-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Inter Variable'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(fonts/inter-latin-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
:root {
  --primary: #3366FF; --primary-dark: #1A4FE6; --accent-text: #D93D3D; --amber-text: #B85A10; --success-text: #1E8A3A;
  --surface: #FAF6F0; --surface-2: #F3EDE4; --card: #FFFDF9; --text: #1A1A2E; --text-2: #63636B; --border: #E5E5EA;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--surface); color: var(--text); font: 15px/1.45 'Inter Variable', system-ui, sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-dark); }
.ic { display: inline-flex; flex: none; width: 18px; height: 18px; }
.ic svg { width: 100%; height: 100%; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin svg { animation-duration: 3s; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; color: inherit; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--accent-text); border-color: rgba(255, 107, 107, .45); }
.btn.danger-solid { background: var(--accent-text); border-color: var(--accent-text); color: #fff; }
.btn.icon { padding: 0; width: 40px; }
.btn.bare { border-color: transparent; background: none; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.chip.ok { background: rgba(52, 199, 89, .12); color: var(--success-text); }
.chip.off { background: var(--border); color: var(--text-2); }
.chip.mid { background: rgba(255, 140, 66, .14); color: var(--amber-text); }
.hint { font-size: 13px; color: var(--text-2); margin: 4px 0 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; font-size: 13px; border: 1px solid rgba(255, 140, 66, .4); background: rgba(255, 140, 66, .07); }
.banner.bad { border-color: rgba(255, 107, 107, .4); background: rgba(255, 107, 107, .07); }
.banner .grow { flex: 1; min-width: 0; }

/* каркас */
.app { display: grid; grid-template-columns: 1fr; height: 100dvh; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); padding-top: env(safe-area-inset-top); }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding-top: env(safe-area-inset-top); }
.app[data-screen="list"] .pane, .app:not([data-screen="list"]) .side { display: none; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.side-head b { flex: 1; font-size: 17px; }
.side-nav { display: grid; gap: 2px; padding: 0 8px 8px; }
.nav-btn { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; width: 100%; }
.nav-btn:hover { background: rgba(26, 26, 46, .05); }
.nav-btn.on { background: var(--card); outline: 1px solid var(--border); }
.nav-btn .ic { color: var(--text-2); }
.nav-btn small { margin-left: auto; color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.chats { flex: 1; overflow-y: auto; padding: 0 8px 8px; display: grid; gap: 2px; align-content: start; border-top: 1px solid var(--border); padding-top: 8px; }
.chat-item { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; width: 100%; font-size: 14px; }
.chat-item span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item:hover { background: rgba(26, 26, 46, .05); }
.chat-item.on { background: var(--card); outline: 1px solid var(--border); }
.side-foot { padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }

/* разговор */
.chat-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.chat-head select { flex: 1; min-width: 0; height: 40px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); padding: 0 8px; font-size: 16px; }
.conv { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.msg { max-width: min(860px, 100%); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-radius: 14px 14px 4px 14px; padding: 9px 13px; white-space: pre-wrap; max-width: min(680px, 92%); }
.msg.bot { background: var(--card); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 12px 14px; align-self: flex-start; width: 100%; }
.msg.bot.err { border-color: rgba(255, 107, 107, .5); }
.att-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.att { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 4px 8px; border-radius: 8px; font-size: 12px; background: rgba(255, 255, 255, .2); }
.att span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .ic { width: 14px; height: 14px; }
.msg-meta { display: flex; gap: 6px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.msg-meta .grow { flex: 1; min-width: 120px; }
.status { display: flex; gap: 8px; align-items: center; color: var(--text-2); font-size: 14px; }
.note { font-size: 12px; color: var(--amber-text); margin-bottom: 6px; }
.empty { margin: auto; text-align: center; color: var(--text-2); padding: 24px; max-width: 460px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

.composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.composer.over { background: rgba(51, 102, 255, .06); }
.pending { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.pending .att { background: var(--surface-2); padding-right: 2px; }
.pending img { width: 28px; height: 28px; object-fit: cover; border-radius: 5px; }
.pending button { border: 0; background: none; cursor: pointer; display: flex; padding: 6px; color: var(--text-2); }
.pending .att.bad { color: var(--accent-text); }
.c-row { display: flex; gap: 6px; align-items: flex-end; }
.c-row textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 40dvh; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); resize: none; font-size: 16px; line-height: 1.35; }
.c-row textarea:focus { outline: none; border-color: var(--primary); }
.c-opts { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--text-2); }
.c-opts input { width: 16px; height: 16px; margin: 0; }

/* экраны модели и устройства */
.page { flex: 1; overflow-y: auto; padding: 14px 12px calc(20px + env(safe-area-inset-bottom)); }
.page-in { max-width: 760px; margin: 0 auto; display: grid; gap: 12px; }
.page h2 { margin: 0; font-size: 20px; }
.model-top { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.model-top h3 { margin: 0; font-size: 16px; flex: 1; min-width: 160px; }
.qr { display: block; width: 200px; height: 200px; image-rendering: pixelated; margin-top: 10px; }
.mono { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.pair { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.pair .card { width: min(460px, 100%); }
.pair input { width: 100%; height: 44px; margin-top: 12px; padding: 0 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); font-size: 16px; }
.pair ol { padding-left: 20px; margin: 10px 0 0; font-size: 14px; display: grid; gap: 6px; }

/* Markdown */
.md { line-height: 1.55; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; }
.md li + li { margin-top: 3px; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; font-size: 16px; font-weight: 700; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 0 0 10px; }
.md pre code { background: none; padding: 0; }
.md .table-wrap { overflow-x: auto; margin: 0 0 10px; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-2); }

.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); display: grid; gap: 8px; z-index: 30; justify-items: end; pointer-events: none; }
.toast { pointer-events: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; box-shadow: 0 6px 20px rgba(40, 30, 10, .12); display: flex; gap: 8px; max-width: 460px; }
.toast.ok .ic { color: var(--success-text); } .toast.bad .ic { color: var(--accent-text); }
.modal-root:empty { display: none; }
.modal-root { position: fixed; inset: 0; background: rgba(26, 26, 46, .35); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; padding: 20px; width: min(460px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; }
.modal h3 { margin: 0 0 6px; } .modal p { margin: 0; font-size: 14px; } .modal .actions { justify-content: flex-end; }

@media (min-width: 860px) {
  .app { grid-template-columns: 290px 1fr; }
  .app[data-screen="list"] .pane, .app:not([data-screen="list"]) .side { display: flex; }
  .side { border-right: 1px solid var(--border); }
  .only-phone { display: none !important; }
  .conv, .composer, .page { padding-left: max(20px, calc((100% - 860px) / 2)); padding-right: max(20px, calc((100% - 860px) / 2)); }
}

/* источники ответа */
.sources { margin-top: 10px; font-size: 13px; }
.sources summary { cursor: pointer; color: var(--text-2); min-height: 28px; }
.sources ol { margin: 6px 0 0; padding-left: 22px; display: grid; gap: 8px; }
.sources li span { color: var(--text-2); }
.sources p { margin: 3px 0 0; color: var(--text-2); font-size: 12px; white-space: pre-wrap; }
