/* Spectrum panel. Tokens and primitives follow the AniVerse design system
   (Onest, neutral backgrounds, blue accent, LineTabs/Segmented/btn-solid/btn-soft). */
:root, html[data-theme="dark"] {
  color-scheme: dark;
  --background: #000000;
  --foreground: oklch(0.985 0 0);
  --surface: #0e0e10;
  --surface-secondary: #161618;
  --overlay: #18181b;
  --well: #161618;
  --well-hover: #1f1f22;
  --well-strong: #2c2c31;
  --thumb: #2a2a2f;
  --default: oklch(27.4% .006 286.033);
  --muted: oklch(70.5% .015 286.067);
  --accent: oklch(0.6204 0.195 253.83);
  --accent-foreground: #ffffff;
  --danger: oklch(0.68 0.19 25);
  --success: oklch(0.74 0.16 152);
  --line: #1d1d20;
  --shadow-overlay: 0 12px 32px rgb(0 0 0 / .55), 0 0 0 1px rgb(255 255 255 / .06);
  --header-shadow: 0 1px 0 rgb(255 255 255 / .06);
}
html[data-theme="light"] {
  color-scheme: light;
  --background: oklch(0.9702 0 0);
  --foreground: oklch(0.21 0.006 285.885);
  --surface: #ffffff;
  --surface-secondary: oklch(0.955 0.002 286);
  --overlay: #ffffff;
  --well: oklch(92.6% .003 286);
  --well-hover: oklch(89.8% .004 286);
  --well-strong: oklch(85% .005 286);
  --thumb: #ffffff;
  --default: oklch(94% .001 286.375);
  --muted: oklch(.5517 .0138 285.94);
  --danger: oklch(0.58 0.21 25);
  --success: oklch(0.56 0.15 152);
  --line: oklch(90% .003 286);
  --shadow-overlay: 0 12px 32px rgb(0 0 0 / .14), 0 0 0 1px rgb(0 0 0 / .06);
  --header-shadow: 0 1px 0 rgb(0 0 0 / .07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.danger { color: var(--danger); }
.success { color: var(--success); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.shell { width: 100%; max-width: 1480px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .shell { padding: 0 24px; } }
@media (min-width: 1024px) { .shell { padding: 0 32px; } }

/* ---------- header */
.header {
  position: fixed; inset: 0 0 auto 0; height: 64px; z-index: 50;
  background: var(--background); transition: box-shadow .2s;
}
.header.scrolled { box-shadow: var(--header-shadow); }
.header .shell { height: 100%; display: flex; align-items: center; gap: 16px; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: -.01em; text-decoration: none; }
.brand small { font-size: 13.5px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.header .spacer { flex: 1; }
main { padding-top: 64px; padding-bottom: 80px; }

/* ---------- LineTabs */
.line-tabs {
  display: flex; gap: 24px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line); margin-bottom: 32px;
}
.line-tabs::-webkit-scrollbar { display: none; }
.line-tab {
  position: relative; height: 48px; padding: 0; border: 0; background: none; cursor: pointer;
  font-size: 17px; font-weight: 600; color: var(--muted); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px; transition: color .15s;
}
@media (min-width: 640px) { .line-tab { font-size: 18px; } }
.line-tab:hover { color: var(--foreground); }
.line-tab[aria-selected="true"] { color: var(--foreground); }
.line-tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: var(--accent); border-radius: 3px 3px 0 0;
}
.count {
  min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; background: var(--well); color: var(--muted);
}
.line-tab[aria-selected="true"] .count { background: var(--accent); color: var(--accent-foreground); }

/* ---------- Segmented (track) */
.segmented { display: inline-flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--well); }
.segmented button {
  height: 36px; padding: 0 16px; border: 0; border-radius: 999px; background: none; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--muted); white-space: nowrap; transition: background .15s, color .15s;
}
.segmented button:hover { color: var(--foreground); }
.segmented button[aria-pressed="true"] { background: var(--thumb); color: var(--foreground); box-shadow: 0 1px 2px rgb(0 0 0 / .18); }
.segmented.sm button { height: 32px; padding: 0 12px; font-size: 13.5px; }

/* ---------- buttons */
.btn-solid {
  height: 44px; padding: 0 20px; border: 0; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 15px; font-weight: 600; background: var(--foreground); color: var(--background);
  transition: opacity .15s, transform .1s; white-space: nowrap; text-decoration: none;
}
.btn-solid:hover { opacity: .85; }
.btn-solid:active { transform: scale(.98); }
.btn-solid.accent { background: var(--accent); color: var(--accent-foreground); }
.btn-soft {
  height: 40px; padding: 0 16px; border: 0; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 500; background: var(--default); color: var(--foreground);
  transition: background .15s, transform .1s; white-space: nowrap; text-decoration: none;
}
.btn-soft:hover { background: var(--well-strong); }
.btn-soft:active { transform: scale(.98); }
.btn-soft.sm { height: 34px; padding: 0 13px; font-size: 13.5px; }
.btn-soft.danger-text { color: var(--danger); }
.btn-soft[aria-pressed="true"] { background: var(--foreground); color: var(--background); }
button:disabled { opacity: .5; cursor: default; pointer-events: none; }

/* ---------- typography blocks */
.section { margin-bottom: 56px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.h2 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -.005em; }
@media (min-width: 640px) { .h2 { font-size: 24px; } }
.h3 { font-size: 17px; font-weight: 600; margin: 0; }
.meta { font-size: 13.5px; color: var(--muted); }
.small { font-size: 12px; }
.lead { font-size: 15px; color: var(--muted); margin: 4px 0 0; max-width: 760px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- bots overview */
.bots { display: grid; gap: 56px; }
@media (min-width: 1180px) { .bots { grid-template-columns: 1fr 1fr; gap: 48px; } }
.bot-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.bot-title .h2 { font-size: 24px; }
@media (min-width: 640px) { .bot-title .h2 { font-size: 30px; font-weight: 700; } }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 500; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.on { color: var(--success); }
.status.on::before { background: var(--success); }
.status.busy { color: var(--accent); }
.status.busy::before { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.bot-facts { margin: 6px 0 18px; }
.targets { border-top: 1px solid var(--line); }
.target {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--line);
}
.target-name { font-weight: 600; font-size: 16px; }
.target-info { grid-column: 1 / 2; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.target-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-last a { text-decoration: none; }
.target-last a:hover { text-decoration: underline; }
.target .btn-soft { grid-row: 1 / span 2; grid-column: 2; }

/* ---------- stats */
.stat-line { display: flex; flex-wrap: wrap; gap: 32px 48px; margin-bottom: 28px; }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.chart { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; align-items: end; height: 150px; }
.chart-col { display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; position: relative; }
.chart-bar { border-radius: 4px; min-height: 0; }
.chart-bar.news { background: var(--accent); }
.chart-bar.edu { background: var(--well-strong); }
.chart-bar.err { background: var(--danger); }
.chart-labels { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); text-align: center; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); margin-top: 12px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.topics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.tag { height: 36px; padding: 0 12px; border-radius: 10px; background: var(--well); font-size: 13.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }

/* ---------- history list */
.filters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.list { border-top: 1px solid var(--line); }
.item { display: grid; grid-template-columns: 92px 1fr auto; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: start; }
.item-time { font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.35; padding-top: 2px; }
.item-title { font-weight: 600; font-size: 15px; text-decoration: none; }
a.item-title:hover { text-decoration: underline; }
.item-meta { font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.item-error { font-size: 13.5px; color: var(--danger); margin-top: 4px; word-break: break-word; }
.item.deleted .item-title { text-decoration: line-through; color: var(--muted); }
.empty { padding: 32px 0; color: var(--muted); }
@media (max-width: 720px) {
  .item { grid-template-columns: 1fr; gap: 6px; }
  .item-time { padding: 0; }
}

/* ---------- logs */
.logbox {
  background: var(--surface); border-radius: 16px; padding: 8px 0; max-height: 68vh; overflow: auto;
  font-size: 13.5px; line-height: 1.45;
}
.logrow { display: grid; grid-template-columns: 84px 72px 1fr; gap: 12px; padding: 5px 16px; }
.logrow:hover { background: var(--well); }
.logrow .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.logrow .b { color: var(--muted); }
.logrow.error .m { color: var(--danger); }
.logrow.warn .m { color: oklch(0.8 0.14 80); }
html[data-theme="light"] .logrow.warn .m { color: oklch(0.55 0.13 70); }
@media (max-width: 640px) { .logrow { grid-template-columns: 64px 1fr; } .logrow .b { display: none; } }

/* ---------- forms */
.form-grid { display: grid; gap: 16px 24px; grid-template-columns: 1fr; max-width: 980px; }
@media (min-width: 760px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 14px; font-weight: 500; }
.field .desc { font-size: 12px; color: var(--muted); }
.input, .textarea {
  height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid transparent;
  background: var(--well); outline: none; width: 100%; transition: background .15s, border-color .15s;
}
.input:hover, .textarea:hover { background: var(--well-hover); }
.input:focus, .textarea:focus { border-color: var(--accent); background: var(--well); }
.textarea { height: auto; min-height: 320px; padding: 12px 14px; line-height: 1.55; resize: vertical; font-size: 14px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 20px; }
.result { font-size: 13.5px; margin-top: 12px; white-space: pre-wrap; }
.slots { font-size: 13.5px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.prompt { margin-bottom: 48px; max-width: 1100px; }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 90;
  background: var(--overlay); color: var(--foreground); border-radius: 12px; padding: 12px 18px;
  box-shadow: var(--shadow-overlay); font-size: 14px; font-weight: 500; max-width: min(92vw, 560px);
  transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: var(--danger); }

/* ---------- login */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { font-size: 30px; font-weight: 700; margin: 0 0 4px; }
@media (min-width: 640px) { .login h1 { font-size: 36px; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------------- цепочки моделей, предпросмотр, тесты */
.textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.textarea.short { min-height: 110px; }
.dlg {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 24px;
  border: 0; border-radius: 20px; background: var(--surface); color: var(--foreground);
  box-shadow: var(--shadow-overlay); overflow: auto;
}
.dlg::backdrop { background: var(--overlay); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
#pv-body { margin-top: 16px; }
.tg-bubble {
  background: var(--surface-secondary); border-radius: 16px; padding: 14px 16px;
  white-space: pre-wrap; line-height: 1.5; font-size: 15px; overflow-wrap: anywhere;
}
.tg-bubble a { color: var(--accent); }
.tg-bubble blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.tg-spoiler { background: var(--well-strong); border-radius: 4px; }
.tg-btn {
  display: block; margin-top: 12px; padding: 10px; border-radius: 10px; text-align: center;
  background: var(--well); font-weight: 500; text-decoration: none; white-space: normal;
}
.tg-btn:hover { background: var(--well-hover); }
.pv-quiz { margin-top: 12px; background: var(--surface-secondary); border-radius: 16px; padding: 14px 16px; }
.pv-quiz-q { font-weight: 600; margin-bottom: 8px; }
.pv-opt { padding: 6px 0; border-bottom: 1px solid var(--line); }
.pv-opt:last-of-type { border-bottom: 0; }
.pv-opt.ok { color: var(--success); font-weight: 500; }
.item.test .item-title { color: var(--muted); }
