:root {
  --bg: #0e1014;
  --bg2: #14171d;
  --card: #181c23;
  --card2: #1e232c;
  --line: #2a303b;
  --text: #e8eaef;
  --muted: #8f98a8;
  --accent: #e0a243;      /* рыжий мех воротника */
  --accent-2: #f3c072;
  --ok: #4cc38a;
  --warn: #e8b04b;
  --bad: #e5604f;
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: #232833; padding: 1px 5px; border-radius: 5px; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 18px; margin-bottom: 4px; }

/* layout */
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--bg2); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand-mark, .login-logo { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; font-size: 20px;
  background: linear-gradient(140deg, var(--accent) 0%, #8a5a1e 100%); color: #1a1206; box-shadow: 0 4px 18px rgba(224,162,67,.25); }
.brand-text { display: flex; flex-direction: column; font-weight: 700; font-size: 17px; line-height: 1.1; }
.brand-text small { color: var(--muted); font-weight: 500; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--card); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--card2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav .ico { width: 18px; text-align: center; opacity: .8; }
.logout { margin-top: auto; padding: 0 8px; }
.main { padding: 26px 32px 60px; max-width: 1240px; width: 100%; min-width: 0; }
.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 26px; }
.page-sub { color: var(--muted); margin-top: 2px; }

/* cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin-bottom: 10px; }
.card-head .card-title { margin-bottom: 0; }
.grid { display: grid; gap: 16px; }
.grid.tight { gap: 10px; }
.grid > .card { margin-bottom: 0; }
.grid + .grid, .grid + .card, .card + .grid { margin-top: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
.big { font-size: 21px; font-weight: 650; margin-bottom: 4px; word-break: break-word; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.row > input, .row > select { width: auto; }
.row > input.grow { flex: 1 1 220px; }
.wide { width: 100%; }
.center { text-align: center; align-items: center; }
.self-end { align-self: end; }
.bad-text { color: var(--bad); }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; align-content: start; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid > .form-actions, .form-grid > .test-out { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 550; display: flex; gap: 8px; align-items: baseline; }
.field output { color: var(--text); font-family: var(--mono); }
input, select, textarea { font: inherit; color: var(--text); background: #11141a; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); background: transparent; border: 0; }
input[type=file] { padding: 7px; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,162,67,.15); }
.field .row > input, .field .row > select { flex: 1 1 auto; width: auto; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
fieldset.sub { border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px 14px; display: grid; gap: 12px; margin: 0; min-width: 0; }
fieldset.sub legend { color: var(--accent-2); font-size: 13px; padding: 0 6px; font-weight: 600; }

.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 15px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card2); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: #3a4250; background: #232935; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1307; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: #ffb1a6; border-color: #4a2a27; background: #261716; }
.btn.danger:hover { background: #331c1a; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; }

/* tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.mono { word-break: break-all; }
.table td.actions .btn + .btn { margin-left: 4px; }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; color: var(--muted); font-weight: 550; padding: 6px 12px 6px 0; width: 110px; vertical-align: top; }
.kv td { padding: 6px 0; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #252b36; color: var(--muted); }
.tag.ok { background: rgba(76,195,138,.15); color: var(--ok); }
.tag.warn { background: rgba(232,176,75,.15); color: var(--warn); }
.tag.bad { background: rgba(229,96,79,.15); color: var(--bad); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot.ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.bad { background: var(--bad); box-shadow: 0 0 10px var(--bad); }
.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid; }
.alert.warn { background: rgba(232,176,75,.08); border-color: rgba(232,176,75,.35); color: #f2cf8c; }
.alert.bad { background: rgba(229,96,79,.08); border-color: rgba(229,96,79,.4); color: #ffb1a6; }
.help { color: var(--muted); margin-top: 4px; }
.help summary { cursor: pointer; color: var(--accent-2); font-weight: 600; }
.help li { margin: 6px 0; }
.errlist { margin: 0; padding-left: 18px; }
.errlist li { margin-bottom: 6px; word-break: break-word; }
.test-out:not(:empty) { margin-top: 10px; padding: 10px 12px; background: #11141a; border-radius: 9px; border: 1px solid var(--line); white-space: pre-wrap; color: var(--text); }

/* dialog */
.dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(560px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(5,6,8,.7); backdrop-filter: blur(2px); }
.qr { width: 260px; height: 260px; background: #fff; border-radius: 12px; padding: 8px; margin: 6px auto; display: block; }

/* avatar */
.preview { width: 100%; max-height: 420px; object-fit: contain; background: #000; border-radius: 10px; aspect-ratio: 9/16; }
.preview.empty { display: grid; place-items: center; color: var(--muted); max-height: 220px; aspect-ratio: auto; height: 220px; }

/* dialogs */
.turns { display: grid; gap: 10px; }
.turn { margin: 0; padding: 14px 16px; }
.turn.has-error { border-color: rgba(229,96,79,.45); }
.turn-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.msg { margin: 4px 0; word-break: break-word; }
.msg.user b { color: #9fb7ff; }
.msg.dog b { color: var(--accent-2); }
.msg.err { color: #ffb1a6; font-size: 13px; }
.timings { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.timings b { color: var(--text); font-family: var(--mono); }

/* sandbox */
.sandbox { display: flex; flex-direction: column; gap: 12px; }
.chat { min-height: 320px; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px; background: #11141a; border: 1px solid var(--line); border-radius: 10px; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 14px; word-break: break-word; }
.bubble.user { align-self: flex-end; background: #233257; border-bottom-right-radius: 4px; }
.bubble.dog { align-self: flex-start; background: #2b2216; border: 1px solid #4a3a20; border-bottom-left-radius: 4px; }
.bubble.dog.interrupted::after { content: " ✂"; color: var(--warn); }
.bubble.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 2px; }
.bubble.err { align-self: center; color: #ffb1a6; font-size: 13px; }
.bubble .stats { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; font-family: var(--mono); }
#sb-mic.rec { background: var(--bad); border-color: var(--bad); color: #fff; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card h1 { font-size: 26px; }
.login-logo { width: 52px; height: 52px; font-size: 28px; }

/* toast */
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--card2); border: 1px solid var(--line); padding: 11px 16px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; max-width: min(460px, calc(100vw - 36px)); z-index: 50; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { border-color: rgba(229,96,79,.6); color: #ffcdc6; }
.toast.ok { border-color: rgba(76,195,138,.5); }

.bubble .stats { white-space: pre-wrap; }
/* search page + tool calls in the turn log */
.search-hits { margin: 10px 0 0; padding-left: 22px; display: grid; gap: 10px; }
.search-hits li > a { font-weight: 600; color: var(--accent-2); text-decoration: none; }
.search-hits li > a:hover { text-decoration: underline; }
.search-hits .mono { word-break: break-all; }
.search-hits pre.test-out { max-height: 260px; overflow: auto; }
#st-model { max-height: 420px; overflow: auto; }
.tools { margin: 6px 0 2px; display: grid; gap: 3px; font-size: 13px; }
.tools .tool { color: var(--muted); word-break: break-word; }
.tools .tool b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.tools .tool.bad { color: #ffb1a6; }
/* mobile */
@media (max-width: 900px) {
  .cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand-text { display: none; }
  .brand-mark { width: 32px; height: 32px; font-size: 17px; }
  .nav { flex-direction: row; gap: 2px; }
  .nav a { white-space: nowrap; padding: 7px 9px; font-size: 14px; }
  .nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .nav .ico { display: none; }
  .logout { margin: 0 0 0 auto; padding: 0; }
  .main { padding: 18px 16px 50px; }
  .cols-2, .cols-3, .form-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 22px; }
  .bubble { max-width: 92%; }
  .table td.actions { white-space: normal; }
}
