/* ДаЛи · админ — тема согласована с продуктовым чат-UI (:8200).
   Токены — HSL-триплеты (как в rca-chat/public/custom.css), используются через hsl(var(--token)).
   Светлая по умолчанию (:root); тёмная — html[data-theme="dark"]. Тумблер в шапке (base.html). */
:root {
  color-scheme: light;            /* нативные контролы (input/select) — светлые, НЕ по теме ОС */
  --bg: 210 40% 98%;
  --panel: 0 0% 100%;
  --ink: 222 47% 11%;
  --muted: 215 16% 43%;
  --line: 214 32% 90%;
  --accent: 221 72% 40%;          /* строгий индиго-синий — как primary чата */
  --accent-ink: 210 40% 98%;
  --accent-soft: 213 96% 94%;     /* светло-голубой фон-акцент */
  --accent-soft-ink: 221 72% 30%;
  --ok: 142 68% 33%;
  --err: 0 72% 46%;
  --warn: 32 85% 36%;
  --code-bg: 210 40% 97%;
  --code-ink: 222 30% 26%;
  --th-bg: 210 40% 97%;
  --hover: 213 96% 96%;
  --zebra: 210 40% 99%;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .05);
  --radius: 0.55rem;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
html[data-theme="dark"] {
  color-scheme: dark;             /* тёмная тема → нативные контролы тоже тёмные */
  --bg: 222 47% 8%;
  --panel: 222 44% 11%;
  --ink: 210 40% 96%;
  --muted: 215 20% 65%;
  --line: 217 33% 20%;
  --accent: 213 94% 62%;          /* яркий синий на тёмном */
  --accent-ink: 222 47% 11%;
  --accent-soft: 217 40% 22%;
  --accent-soft-ink: 210 40% 96%;
  --ok: 142 60% 48%;
  --err: 0 72% 62%;
  --warn: 38 92% 58%;
  --code-bg: 222 47% 6%;
  --code-ink: 210 25% 80%;
  --th-bg: 222 40% 13%;
  --hover: 217 33% 16%;
  --zebra: 222 44% 12%;
  --shadow: 0 1px 2px rgb(0 0 0 / .3);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: hsl(var(--bg)); color: hsl(var(--ink));
  font: 15px/1.55 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Шапка ── */
header {
  display: flex; align-items: center; gap: 1.25rem; padding: .7rem 1.5rem;
  background: hsl(var(--panel)); border-bottom: 1px solid hsl(var(--line));
  position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
header .brand {
  font-weight: 700; color: hsl(var(--ink)); text-decoration: none;
  letter-spacing: .2px; white-space: nowrap;
}
header nav { display: flex; gap: .25rem; }
header nav a {
  color: hsl(var(--muted)); text-decoration: none; padding: .35rem .7rem;
  border-radius: calc(var(--radius) - 2px); font-size: .92rem; transition: background .12s, color .12s;
}
header nav a { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
header nav a svg { width: 16px; height: 16px; opacity: .8; flex: 0 0 auto; }
header nav a:hover { color: hsl(var(--ink)); background: hsl(var(--hover)); }
header nav a.active { color: hsl(var(--accent)); background: hsl(var(--accent-soft) / .6); font-weight: 600; }
header nav a.active svg { opacity: 1; }
header .spacer { margin-left: auto; }
header .user { color: hsl(var(--muted)); font-size: .88rem; white-space: nowrap; }
header .user a { color: hsl(var(--accent)); }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--line)); background: transparent; color: hsl(var(--muted));
  cursor: pointer; font-size: 1rem; line-height: 1; transition: background .12s, color .12s, border-color .12s;
}
.theme-toggle:hover { color: hsl(var(--ink)); border-color: hsl(var(--accent) / .5); background: hsl(var(--hover)); }

/* ── Каркас ── */
main { max-width: 1180px; margin: 1.75rem auto 3rem; padding: 0 1.5rem; }
h1 { font-size: 1.5rem; margin: .2rem 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; margin: 1.8rem 0 .6rem; padding-bottom: .3rem; border-bottom: 1px solid hsl(var(--line)); }
a { color: hsl(var(--accent)); }
p { margin: .5rem 0 1rem; }
.muted { color: hsl(var(--muted)); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.crumbs { color: hsl(var(--muted)); font-size: .85rem; margin: 0 0 .75rem; }
.crumbs a { color: hsl(var(--muted)); text-decoration: none; }
.crumbs a:hover { color: hsl(var(--accent)); }
code {
  font-family: var(--mono); font-size: .86em; padding: .08em .35em;
  background: hsl(var(--code-bg)); border: 1px solid hsl(var(--line)); border-radius: 4px;
  color: hsl(var(--code-ink));
}

/* ── Таблицы как карточки (без обёрток в шаблонах) ── */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: hsl(var(--panel)); border: 1px solid hsl(var(--line));
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
th, td { text-align: left; padding: .7rem .85rem; border-bottom: 1px solid hsl(var(--line)); vertical-align: top; }
thead th {
  color: hsl(var(--muted)); font-weight: 600; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; background: hsl(var(--th-bg));
}
tbody tr:nth-child(even) td { background: hsl(var(--zebra)); }
tbody tr:hover td { background: hsl(var(--hover)); }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }

/* ── Кнопки ── */
.btn {
  display: inline-block; padding: .38rem .8rem; border-radius: calc(var(--radius) - 1px);
  text-decoration: none; background: hsl(var(--accent)); color: hsl(var(--accent-ink));
  font-size: .85rem; font-weight: 500; border: 1px solid transparent; cursor: pointer;
  transition: filter .12s, background .12s, border-color .12s;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost {
  background: transparent; border: 1px solid hsl(var(--line)); color: hsl(var(--ink)); font-weight: 400;
}
.btn.ghost:hover { border-color: hsl(var(--accent) / .5); background: hsl(var(--hover)); filter: none; }
.btn.danger {
  background: transparent; border: 1px solid hsl(0 60% 55% / .45); color: hsl(0 62% 52%); font-weight: 400;
}
.btn.danger:hover { border-color: hsl(0 62% 52%); background: hsl(0 62% 52% / .1); filter: none; }
button.btn, button:not(.theme-toggle) {
  font: inherit; font-size: .9rem;
}
/* форма-обёртка кнопки «Удалить» не должна ломать ряд действий */
td.actions form { display: inline; margin: 0; }

/* ── Теги / статусы / пилюли ── */
.tag {
  display: inline-block; background: hsl(var(--accent-soft) / .5); border: 1px solid hsl(var(--line));
  border-radius: 999px; padding: .08rem .5rem; margin: .12rem .25rem .12rem 0; font-size: .76rem;
  color: hsl(var(--accent-soft-ink));
}
html[data-theme="dark"] .tag { color: hsl(var(--ink)); }
.status { font-size: .8rem; padding: .12rem .5rem; border-radius: 999px; font-weight: 500; display: inline-block; }
.status-done, .status-DONE { color: hsl(var(--ok)); background: hsl(var(--ok) / .12); }
.status-running, .status-RUNNING, .status-queued, .status-QUEUED, .status-retry, .status-awaiting { color: hsl(var(--warn)); background: hsl(var(--warn) / .13); }
.status-fail, .status-failed, .status-FAIL, .status-FAILED { color: hsl(var(--err)); background: hsl(var(--err) / .12); }
.status-dlq { color: #fff; background: hsl(var(--err) / .85); }
.status-unstart, .status-UNSTART, .status-skipped { color: hsl(var(--muted)); background: hsl(var(--muted) / .12); }

.sum { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1.1rem; }
.pill {
  padding: .25rem .7rem; border-radius: 999px; border: 1px solid hsl(var(--line));
  background: hsl(var(--panel)); font-size: .82rem; box-shadow: var(--shadow);
}
.pill.ok { border-color: hsl(var(--ok) / .5); color: hsl(var(--ok)); background: hsl(var(--ok) / .08); }
.pill.warn { border-color: hsl(var(--warn) / .5); color: hsl(var(--warn)); background: hsl(var(--warn) / .09); }

/* ── Флеши ── */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1.1rem; border: 1px solid transparent; }
.flash.ok { background: hsl(var(--ok) / .1); border-color: hsl(var(--ok) / .45); color: hsl(var(--ok)); }
.flash.error { background: hsl(var(--err) / .1); border-color: hsl(var(--err) / .45); color: hsl(var(--err)); }

/* ── Блоки кода ── */
pre.joblog, pre.code-view {
  background: hsl(var(--code-bg)); color: hsl(var(--code-ink));
  border: 1px solid hsl(var(--line)); border-radius: var(--radius); padding: 1rem;
  font-family: var(--mono); font-size: .82rem; box-shadow: var(--shadow) inset;
}
pre.joblog { white-space: pre-wrap; word-break: break-word; max-height: 60vh; overflow: auto; }
/* Просмотр конфига: сохраняем отступы YAML (без переноса), прокрутка по обеим осям */
pre.code-view { white-space: pre; max-height: 55vh; overflow: auto; }
pre code { background: none; border: 0; padding: 0; color: inherit; }

/* ── Формы ── */
form.meta-form fieldset {
  border: 1px solid hsl(var(--line)); border-radius: var(--radius); margin: 0 0 1.1rem; padding: 1rem 1.1rem;
  background: hsl(var(--panel)); box-shadow: var(--shadow);
}
form.meta-form legend { color: hsl(var(--muted)); padding: 0 .45rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.meta-form label { display: block; margin-bottom: .8rem; color: hsl(var(--muted)); font-size: .85rem; }
.meta-form input, .meta-form textarea, .meta-form select {
  display: block; width: 100%; margin-top: .3rem; padding: .5rem .65rem;
  background: hsl(var(--bg)); color: hsl(var(--ink)); border: 1px solid hsl(var(--line));
  border-radius: calc(var(--radius) - 1px); font: inherit; transition: border-color .12s, box-shadow .12s;
}
.meta-form input:focus, .meta-form textarea:focus, .meta-form select:focus {
  outline: none; border-color: hsl(var(--accent)); box-shadow: 0 0 0 3px hsl(var(--accent) / .18);
}
.meta-form textarea { font-family: var(--mono); font-size: .85rem; resize: vertical; }
.meta-form label.chk { display: flex; align-items: center; gap: .55rem; color: hsl(var(--ink)); }
.meta-form label.chk input { width: auto; margin: 0; }
.form-actions { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.form-actions form { margin: 0; }

/* ── Подсказка «?» у поля (CSS-тултип по hover/фокусу) ── */
.field-help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: .35rem; vertical-align: middle;
  border-radius: 999px; border: 1px solid hsl(var(--line)); background: hsl(var(--panel));
  color: hsl(var(--muted)); font-size: .72rem; font-weight: 700; line-height: 1;
  cursor: help; position: relative; user-select: none; text-transform: none;
}
.field-help:hover, .field-help:focus-visible {
  color: hsl(var(--accent)); border-color: hsl(var(--accent) / .55);
  outline: none; box-shadow: 0 0 0 3px hsl(var(--accent) / .15);
}
.field-help::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(100% + 9px); transform: translateX(-50%);
  width: max-content; max-width: 280px; padding: .5rem .65rem;
  background: hsl(var(--ink)); color: hsl(var(--bg));
  border-radius: calc(var(--radius) - 1px); font-size: .78rem; font-weight: 400;
  line-height: 1.42; text-align: left; white-space: normal; letter-spacing: normal;
  box-shadow: 0 6px 20px rgb(16 24 40 / .18); z-index: 60;
  opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none;
}
.field-help::before {  /* стрелочка тултипа */
  content: ""; position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: hsl(var(--ink));
  opacity: 0; visibility: hidden; transition: opacity .12s; z-index: 60; pointer-events: none;
}
.field-help:hover::after, .field-help:focus::after,
.field-help:hover::before, .field-help:focus::before { opacity: 1; visibility: visible; }

/* ── Чанки / детали / пагинация ── */
details { margin: .5rem 0; }
details summary { cursor: pointer; padding: .3rem 0; color: hsl(var(--accent)); }
.chunks { list-style: none; padding: 0; }
.chunks li { margin-bottom: .9rem; }
.chunks pre {
  white-space: pre-wrap; word-break: break-word; background: hsl(var(--panel));
  border: 1px solid hsl(var(--line)); border-radius: var(--radius); padding: .8rem .9rem; margin: .25rem 0;
  box-shadow: var(--shadow);
}
.pager { display: flex; gap: .7rem; margin-top: 1.2rem; }

/* ── Логин ── */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
form.login {
  background: hsl(var(--panel)); border: 1px solid hsl(var(--line)); border-radius: 14px;
  padding: 2.2rem; width: 340px; box-shadow: 0 10px 30px rgb(16 24 40 / .1), var(--shadow);
}
form.login h1 { text-align: center; font-size: 1.35rem; margin: 0 0 1.2rem; }
form.login label { display: block; margin: .85rem 0; color: hsl(var(--muted)); font-size: .85rem; }
form.login input {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem;
  background: hsl(var(--bg)); color: hsl(var(--ink)); border: 1px solid hsl(var(--line));
  border-radius: calc(var(--radius) - 1px); font: inherit; transition: border-color .12s, box-shadow .12s;
}
form.login input:focus { outline: none; border-color: hsl(var(--accent)); box-shadow: 0 0 0 3px hsl(var(--accent) / .18); }
form.login button {
  width: 100%; margin-top: 1.1rem; padding: .6rem; font-size: .95rem; font-weight: 600;
  background: hsl(var(--accent)); color: hsl(var(--accent-ink)); border: 0;
  border-radius: calc(var(--radius) - 1px); cursor: pointer; transition: filter .12s;
}
form.login button:hover { filter: brightness(1.06); }

/* ── Пустые состояния ── */
.empty {
  text-align: center; color: hsl(var(--muted));
  background: hsl(var(--panel)); border: 1px dashed hsl(var(--line));
  border-radius: var(--radius); padding: 2.5rem 1.5rem; box-shadow: var(--shadow);
}
.empty a { font-weight: 500; }

/* ── A11y / детали ── */
::selection { background: hsl(var(--accent) / .25); }
.btn:focus-visible, .theme-toggle:focus-visible, header nav a:focus-visible,
.meta-form input:focus-visible, .meta-form select:focus-visible {
  outline: 2px solid hsl(var(--accent)); outline-offset: 2px;
}
pre::-webkit-scrollbar { height: 10px; width: 10px; }
pre::-webkit-scrollbar-thumb { background: hsl(var(--line)); border-radius: 6px; }
pre::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted) / .5); }
pre::-webkit-scrollbar-track { background: transparent; }

/* ── Адаптив ── */
@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: .5rem .75rem; padding: .6rem .9rem; }
  header nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: .1rem; }
  main { margin: 1.1rem auto 2rem; padding: 0 .9rem; }
  h1 { font-size: 1.3rem; }
  h2 { font-size: 1.05rem; }
  th, td { padding: .55rem .6rem; }
  td.actions { text-align: left; }
  td.actions .btn { padding: .3rem .55rem; margin-top: .15rem; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn, .form-actions button { width: 100%; text-align: center; }
}

/* ─── раздел «Качество» (eval, ADR F7/F9) ─────────────────────────────────── */
.cards { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }
.card { flex: 1 1 140px; border: 1px solid var(--border, #ddd); border-radius: 10px; padding: 12px 14px; background: var(--panel, #fff); }
.card .num { font-size: 1.5rem; font-weight: 700; }
.card .lbl { font-size: .8rem; color: var(--muted, #777); margin-top: 2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.loop { border: 1px solid var(--border, #ddd); border-radius: 10px; padding: 12px 14px; margin: 10px 0; background: var(--panel, #fff); }
.loop-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.loop .answer { white-space: pre-wrap; margin-top: 6px; color: var(--muted, #555); max-height: 240px; overflow: auto; }
.loop-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.loop-form input[type=text] { flex: 1 1 200px; min-width: 160px; }
.resolved-only { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1 1 auto; }
.badge { font-size: .75rem; background: var(--accent-bg, #fdf0d5); color: var(--accent-fg, #8a5a00); border-radius: 6px; padding: 1px 7px; }
.warn { color: #b45309; }

/* Форма создания базы знаний (раздел «Базы знаний») */
.create-ds { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0 18px; }
.create-ds input[type=text] { flex: 1 1 320px; min-width: 220px; }

/* ─── раздел «Конфигурация» (config-as-code) ──────────────────────────────── */
/* памятка «как это работает» */
details.explain {
  border: 1px solid hsl(var(--line)); border-radius: var(--radius);
  background: hsl(var(--panel)); padding: .4rem .9rem; margin: .8rem 0 1.2rem; box-shadow: var(--shadow);
}
details.explain > summary { color: hsl(var(--ink)); font-weight: 600; }
.explain-body { padding: .3rem 0 .4rem; }
table.mini { margin: .6rem 0; font-size: .85rem; }
table.mini th, table.mini td { padding: .4rem .6rem; }
/* таблицы конфигурации */
table.cfg td { vertical-align: top; }
table.cfg .tag { margin: 0 .25rem .25rem 0; }
details.drift { margin: 0; }
details.drift > summary { padding: 0; list-style: none; }
details.drift > summary::-webkit-details-marker { display: none; }
table.diff { margin: .5rem 0 .2rem; font-size: .82rem; box-shadow: none; }
table.diff th, table.diff td { padding: .35rem .55rem; }
table.diff td:nth-child(2) { color: hsl(var(--ok)); }
table.diff td:nth-child(3) { color: hsl(var(--warn)); }
/* инлайн-правка документа */
tr.edit-row > td { background: hsl(var(--zebra)); }
.cfg-edit { margin: 0; }
.cfg-edit .grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .4rem .9rem; margin-bottom: .6rem;
}
.cfg-edit label { display: block; color: hsl(var(--muted)); font-size: .8rem; margin: 0; }
.cfg-edit input, .cfg-edit select, .cfg-edit textarea {
  display: block; width: 100%; margin-top: .2rem; padding: .4rem .55rem;
  background: hsl(var(--bg)); color: hsl(var(--ink)); border: 1px solid hsl(var(--line));
  border-radius: calc(var(--radius) - 2px); font: inherit; font-size: .85rem;
}
.cfg-edit textarea { font-family: var(--mono); resize: vertical; }
.cfg-edit .reparse-note { color: hsl(var(--warn)); font-size: .8rem; margin: .2rem 0 .5rem; }
.cfg-edit .parser-locked { display: block; margin-top: .2rem; color: hsl(var(--muted)); font-size: .8rem; font-style: italic; }

/* ─── раздел «Промпты» ────────────────────────────────────────────────────── */
details.prompt {
  border: 1px solid hsl(var(--line)); border-radius: var(--radius);
  background: hsl(var(--panel)); padding: .5rem .9rem; margin: .5rem 0; box-shadow: var(--shadow);
}
details.prompt > summary { color: hsl(var(--ink)); }
details.prompt > summary code { font-weight: 600; }
details.prompt .tag { margin-left: .35rem; }
details.prompt textarea { width: 100%; font-family: var(--mono); font-size: .84rem; line-height: 1.45; resize: vertical; }
