/* marketplace-agent — hand-written, no framework, no external font or image.
   Everything the browser needs is local, so the UI works with no internet.

   The look: a light grey-blue page, one white card per screen, and the chat as a
   column of bubbles where every question carries a card of the steps the agent
   took. Colours come from the tokens below and nothing else, so a palette change
   is one block. */

:root {
  /* surfaces */
  --bg: #f4f6fb;          /* page: very light grey-blue */
  --card: #ffffff;        /* the panel a screen lives on */
  --soft: #fcfcfd;        /* the steps card, one shade off white */
  --sunken: #f9fafb;      /* inputs, code, the search field */
  --line: #e5e7eb;        /* hairlines */
  --line-soft: #f3f4f6;   /* separators inside a card */

  /* text */
  --fg: #1f2937;          /* body */
  --strong: #111827;      /* headings and the action line */
  --muted: #6b7280;       /* captions, labels, the preview line */
  --faint: #9ca3af;       /* metrics, the «ИСТОРИЯ» heading */

  /* accents */
  --accent: #10b981;      /* teal: primary buttons, links, focus */
  --accent-dark: #059669; /* its hover */
  --accent-ink: #ffffff;
  --accent-soft: #ecfdf5; /* hovers, soft highlights */
  --glow: #d1fae5;        /* the halo around a focused composer */
  --bubble: #e8f4f8;      /* the user's own words: light blue */
  --hover: #f3f4f6;       /* a sidebar row under the cursor */
  --ok: #10b981;
  --warn: #d97706;
  --err: #dc2626;

  /* the mono tool tag */
  --tag-bg: #f3f4f6;
  --tag-fg: #4b5563;

  --radius-lg: 22px;      /* the screen card */
  --radius-md: 12px;      /* bubbles, steps card */
  --radius-sm: 8px;       /* inputs, buttons, chips */
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 4%), 0 1px 3px rgb(16 24 40 / 6%);
  --shadow-up: 0 -12px 16px -14px rgb(16 24 40 / 14%);  /* under the band with the field */
  --sidebar: 280px;       /* the history panel is exactly this wide */
  --feed: 860px;          /* and the conversation is exactly this wide */
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

code, pre, kbd, samp, textarea, input, select, button { font-family: inherit; }

code {
  padding: 1px 6px;
  background: var(--tag-bg);
  border-radius: 6px;
  color: var(--tag-fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875em;
}

pre { margin: 0; }

h1 { font-size: 24px; line-height: 1.25; margin: 0 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }

/* --- chrome ------------------------------------------------------------------ */

.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--strong);
}

/* Марка сервиса — та же ``logo-mark.svg``, что стоит иконкой вкладки: в шапке она
   слева от названия, поэтому логотип видно на всех страницах с шапкой. У чата,
   автоматизаций и промтов шапки нет — там марку несёт панель (``.side-brand``). */
.brand-mark { flex: 0 0 auto; display: block; width: 28px; height: 28px; border-radius: 8px; }

.top nav { display: flex; gap: 16px; font-size: 14px; }
.top nav a { text-decoration: none; color: var(--muted); }
.top nav a:hover { color: var(--accent); }
.inline-form { margin-left: auto; }

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
}

.foot {
  padding: 16px 24px 40px;
  color: var(--faint);
  font-size: 12px;
  text-align: center;
}

/* --- the start page: a public landing, no login, no app chrome --------------- */

/* Two columns: the copy on the left (badge, headline, the three-step strip, one
   button) and the network illustration on the right. Everything is HTML plus
   these rules — no font, no image file, no inline style (the domain CSP is
   'self' without unsafe-inline). The colours come from the tokens above. */

body.landing-page {
  justify-content: flex-start;
  background: linear-gradient(180deg, var(--bg) 0%, #eef4f2 100%);
}

.landing-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px 32px;
}

.landing-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.landing-brand-mark { display: block; width: 46px; height: 46px; }

.landing-brand-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--strong);
}

/* «Вход» for someone who already has an account: the hero button is the door for
   a newcomer, so the returning person gets a quiet text link. */
.landing-signin { font-size: 15px; font-weight: 600; color: var(--strong); text-decoration: none; }
.landing-signin:hover { color: var(--accent-dark); }

.landing-main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 32px 48px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  align-items: center;
  gap: 48px;
  width: 100%;
}

.hero-copy { max-width: 560px; }

.hero-badge {
  display: inline-block;
  margin: 0 0 22px;
  padding: 8px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--glow);
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-title {
  margin: 0;
  font-size: clamp(2.1rem, 4.4vw, 3.4rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.03em;
  color: var(--strong);
}

.hero-num { color: var(--accent); }

.hero-markets { margin: 20px 0 0; color: var(--muted); font-size: 17px; }

/* The three steps as a chain: every chip but the last carries a green arrow into
   the one after it — decoration, so it lives here and not in the markup.
   The chain never wraps: on a phone the chips and the arrows shrink together
   (``--flow-gap`` is the one width the row and the arrow both measure from, and
   the sizes are ``clamp``ed against the viewport), so «Анализирует → Предлагает →
   Управляет» stays one line instead of breaking and leaving an arrow hanging.
   The clamp ceilings are the old fixed sizes, so a wide screen looks untouched;
   the floors hold the whole row inside ~270 pixels, which is narrower than any
   phone — measured against real glyph widths, at 360 pixels the row wants 295 of
   the 320 it has. */
.hero-flow {
  --flow-gap: clamp(10px, 4vw, 26px);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--flow-gap);
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
}

.hero-flow li {
  position: relative;
  padding: clamp(6px, 1.5vw, 7px) clamp(6px, 2.2vw, 13px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  color: var(--strong);
  font-size: clamp(9.5px, 3.4vw, 13.5px);
  font-weight: 600;
  white-space: nowrap;
}

.hero-flow li.is-last {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* The arrow sits in the middle of that one gap, so it stays between the chips at
   any width: half the gap out from the chip's edge, less half of its own glyph
   (the glyph is exactly 1em wide, so half of it is 0.5em). */
.hero-flow li:not(.is-last)::after {
  content: "→";
  position: absolute;
  top: 50%;
  right: calc(-0.5 * var(--flow-gap) - 0.5em);
  transform: translateY(-50%);
  color: var(--accent);
  font-weight: 700;
}

.hero-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hero-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.hero-cta { margin-top: 28px; padding: 13px 26px; font-size: 15px; }

/* --- the illustration: a glowing mesh with the mark in the middle ------------- */

.hero-art {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.orbit {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
}

.orbit-glow {
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%,
              #a7f3c6 0%, #6ee7b7 16%, #5bc9c9 32%,
              #60a5fa 56%, #818cf8 80%, rgb(129 140 248 / 0%) 100%);
  filter: blur(7px);
  box-shadow: 0 40px 110px -40px rgb(96 165 250 / 65%);
}

.orbit-net { position: absolute; inset: 0; width: 100%; height: 100%; }

.orbit-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22%;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 14px 26px rgb(15 23 42 / 45%));
}

.orbit-pill {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: 0 12px 26px -12px rgb(16 24 40 / 45%);
  color: var(--strong);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.orbit-pdot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; }

.orbit-wb    { top: 3%;    left: 1%; }
.orbit-ozon  { top: 8%;    right: 0; }
.orbit-ym    { bottom: 20%; right: -3%; }
.orbit-avito { bottom: 5%; left: -2%; }

.orbit-wb    .orbit-pdot { background: #cb11ab; }
.orbit-ozon  .orbit-pdot { background: #005bff; }
.orbit-ym    .orbit-pdot { background: #ffcc00; }
.orbit-avito .orbit-pdot { background: #2481cc; }

/* On a phone the copy comes first and the picture drops under it, as in the
   reference: one column, the mesh a little smaller and centred. */
@media (max-width: 900px) {
  .landing-top { padding: 16px 20px; }
  .landing-brand-mark { width: 40px; height: 40px; }
  .landing-brand-name { font-size: 23px; }
  .landing-main { align-items: flex-start; padding: 8px 20px 32px; }
  .hero { grid-template-columns: 1fr; gap: 30px; }
  .hero-copy { max-width: none; }
  .hero-art { order: 2; }
  .orbit { max-width: 420px; margin: 0 auto; }
  .hero-title { font-size: clamp(1.9rem, 8.5vw, 2.7rem); }
}

/* --- panels ------------------------------------------------------------------ */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 28px 32px;
  margin-bottom: 24px;
}

.card.narrow { max-width: 520px; margin: 6vh auto 24px; }

/* The conversation is the only card with bubbles in it: ~900px, generous air. */
.card.chat { max-width: 900px; margin: 0 auto 24px; padding: 32px; }

/* --- forms ------------------------------------------------------------------- */

label { display: block; margin: 12px 0; color: var(--muted); font-size: 13px; }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=datetime-local], select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 15px;
}

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea { resize: vertical; }

label.tick { display: inline-flex; align-items: center; gap: 6px; margin: 2px 12px 2px 0; }
label.tick input { width: auto; margin: 0; }

button {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  cursor: pointer;
}

button:hover { background: var(--sunken); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-size: 14px; }
button.link:hover { background: none; text-decoration: underline; }

/* A link that must look like a button (the «Вход» on the start page). */
.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.row { display: flex; align-items: flex-end; gap: 14px; }
.row.wrap { flex-wrap: wrap; }
.row label { flex: 1 1 160px; }

/* --- notes ------------------------------------------------------------------- */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: var(--card);
}

.flash.ok { border-color: var(--ok); color: #047857; }
.flash.err, .err { color: var(--err); }
.hint { color: var(--muted); font-size: 13px; }
.meta { color: var(--muted); font-size: 13px; margin: 8px 0; }

/* --- lists and tables -------------------------------------------------------- */

table.list { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 14px; }
table.list th, table.list td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

table.list th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.list tr:last-child td { border-bottom: 0; }
table.list form { display: flex; gap: 6px; align-items: center; margin: 0 0 6px; }
table.list input[type=text] { margin: 0; }
/* A login or a scope key longer than its column breaks instead of widening the
   whole table: ``break-word`` (not ``anywhere``) keeps the column's own minimum
   width, so a narrow window still scrolls rather than crushing every cell. */
table.list td, table.list th { overflow-wrap: break-word; }

/* The admin table: nine columns, most of them holding a control of their own.
   It only just fits the card, so it is set compactly, and a window too narrow
   for it scrolls the table inside the wrapper instead of spilling buttons over
   the card border. */
.table-wrap { overflow-x: auto; margin-top: 14px; }
.table-wrap > table.list { margin-top: 0; }
.nowrap { white-space: nowrap; }

table.admin-list { font-size: 13px; }
table.admin-list th, table.admin-list td { padding: 7px; }
table.admin-list th { vertical-align: bottom; }
table.admin-list .hint { font-size: 12px; }

/* Fields and buttons in the table are one size — 30px tall, 13px text — so a row
   reads as a row and not as a pile of differently sized boxes. */
table.admin-list input[type=text], table.admin-list input[type=number],
table.admin-list select, table.admin-list button {
  height: 30px;
  padding: 0 8px;
  font-size: 13px;
}
/* Fields are pills, not panels: ``width: 100%`` would make the column as wide as
   the card, and an input's default 20-character minimum would keep it that wide
   on a phone. */
table.admin-list input[type=text], table.admin-list input[type=number],
table.admin-list select {
  width: auto;
  min-width: 0;
  margin: 0;
}
table.admin-list input.pw { width: 7rem; }
/* Сколько запросов дано человеку: три-четыре цифры — ширина по числу, а не по
   умолчанию браузера, иначе колонка «Запросы» распирает всю таблицу. */
table.admin-list input.num { width: 4.5rem; }
table.admin-list button { padding: 0 10px; }
table.admin-list form { flex-wrap: nowrap; margin: 0 0 8px; }
table.admin-list form.stack { display: grid; gap: 6px; }
table.admin-list label.tick { margin: 0; font-size: 13px; }

/* Which cabinets a person sees: one key per line, so a second key never pushes
   the column wider than the buttons beside it. */
.admin-scopes { display: grid; gap: 2px; }

/* A state and the switch that flips it share a cell: «да · отключить». */
.admin-cell { display: flex; align-items: center; gap: 6px; }
.admin-cell > span { color: var(--muted); }
.admin-cell form { margin: 0; }

/* На телефоне таблица пользователей поворачивается на бок: десять колонок в 360
   пикселей не влезают, а прокрутка вбок в клетку с полем — это правка вслепую.
   Поэтому каждая строка становится карточкой, а подпись колонки встаёт над своим
   полем (``data-label`` из ``admin.html``): правка одного человека — одно движение
   вниз. Заголовки колонок при этом не нужны, их роль берут подписи; на широком
   экране ничего из этого нет — таблица стоит как стояла. */
@media (max-width: 640px) {
  table.stack-phone thead { display: none; }
  table.stack-phone,
  table.stack-phone tbody,
  table.stack-phone tr,
  table.stack-phone td {
    display: block;
    width: auto;
  }
  table.stack-phone tr {
    padding: 12px 14px;
    margin: 0 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
  }
  table.stack-phone td {
    padding: 7px 0;
    border-bottom: 1px solid var(--line-soft);
    /* ``.nowrap`` в таблице ставился, чтобы колонка не расползалась по ширине;
       в карточке ширина уже своя, и «не переносить» здесь только вредило бы:
       последний вход и подпись состояния читаются в две строки. */
    white-space: normal;
  }
  table.stack-phone tr td:last-child { border-bottom: 0; }
  table.stack-phone td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  table.admin-list.stack-phone form { margin: 0; }
  table.admin-list.stack-phone form.stack { gap: 8px; }
  /* Поле пароля в карточке — во всю ширину: тянуться к полосе 7rem справа на
     телефоне неудобно, а место здесь есть. */
  table.admin-list.stack-phone input.pw { width: 100%; }
  /* Ячейки-состояния больше не «строка с кнопкой справа»: подпись встала над ними,
     и прижатый вправо переключатель читался бы как чужая кнопка. */
  table.stack-phone .admin-cell { flex-wrap: wrap; }
}

.qr { background: #fff; display: inline-block; padding: 12px; border-radius: var(--radius-md); }
.qr svg { width: 220px; height: 220px; display: block; }
.steps { color: var(--muted); }

/* --- the conversation -------------------------------------------------------- */

/* One article per question: the question in a bubble on the right, the steps the
   agent took under it, then the answer as ordinary typography — ChatGPT-style,
   with no frame around it, because the answer is the page and not a quotation. */
.turn { margin: 0 0 32px; }
.turn:last-of-type { margin-bottom: 16px; }

/* The question itself: right-aligned, light blue, never wider than 70%, so a long
   question cannot read as something the agent said. */
.bubble {
  padding: 14px 18px;
  border-radius: var(--radius-xl);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.user {
  margin-left: auto;
  max-width: 70%;
  background: var(--bubble);
  color: var(--fg);
}

.bubble.user.muted { color: var(--muted); font-style: italic; }
/* Подставной пузырь (app.js) называет и файлы: иначе отправка с вложением
   выглядела бы как отправка без него — и человек искал бы, куда делся файл. */
.bubble .files-note { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

/* Файлы, приложенные к вопросу: строка на файл под пузырём — имя от человека,
   размер и то, увидела ли содержимое модель. Ссылка ведёт в приложение
   (``/c/<id>/files/<aid>``): скачивание проверяет право на беседу, и оно же
   закрывает файл от чужой вкладки. Имя длинное — переносится, а не растягивает
   ленту: ``overflow-wrap: anywhere`` на нём и ``min-width: 0`` на строке. */
.files {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
}
.file {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  max-width: 100%;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  font-size: 13px;
}
.file-open {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  color: var(--fg);
  text-decoration: none;
}
.file-open:hover .file-name { color: var(--accent-dark); text-decoration: underline; }
.file-icon { color: var(--muted); }
.file-name { overflow-wrap: anywhere; }
.file-meta { color: var(--faint); font-size: 12px; }

/* The answer: headings bold, lists with bullets, tables with hairlines — the
   markup comes from ``agent/web/text.py``, which escapes first. */
.answer {
  margin: 16px 0 0;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--fg);
}

.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 12px; }
.answer h3 { margin: 20px 0 8px; font-size: 17px; color: var(--strong); }
.answer h4 { margin: 18px 0 6px; font-size: 15px; color: var(--strong); }
.answer strong { color: var(--strong); font-weight: 600; }
.answer em { color: var(--muted); font-style: italic; }
.answer ul, .answer ol { margin: 0 0 12px; padding-left: 22px; }
.answer li { margin: 4px 0; }
.answer li::marker { color: var(--accent); }
.answer blockquote {
  margin: 12px 0;
  padding: 4px 0 4px 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}
.answer hr.md-rule { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.answer pre.md-code {
  margin: 12px 0;
  padding: 12px 14px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* Tables a cabinet answer is made of: numbers in columns, hairlines, no noise.
   Обёртка (``.md-scroll``, ``agent/web/text.py``) даёт таблице свою прокрутку: на
   телефоне шесть колонок в 360 пикселей не уложить, и лучше пусть прокрутится одна
   таблица, чем вся лента вбок (``.chat-scroll`` вбок не прокручивается вовсе). */
.md-scroll { overflow-x: auto; margin: 12px 0 16px; }
.md-scroll > table.md-table { margin: 0; }

.answer table, table.md-table {
  width: 100%;
  margin: 12px 0 16px;
  border-collapse: collapse;
  font-size: 14px;
}
.answer table th, .answer table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.answer table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--sunken);
}
.answer table tr:last-child td { border-bottom: 0; }

/* The visual block of an answer: a ```cards fence carries a JSON spec and the page
   draws it (``agent/web/text.py``), so the model names the numbers instead of
   printing a table of them. A card on the page, a row of tiles inside — the same
   surface the steps card uses, one shade off the answer. Colours come from the
   palette only: a spec can name a tone («good»/«bad»), never a colour of its own.
   No inline ``style`` anywhere — ``style-src 'self'`` would drop it, and the bars
   carry their width in SVG geometry (an ``<rect width>``) rather than in styling. */
.viz {
  margin: 14px 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--soft);
}
.viz-title {
  display: block;
  margin: 0 0 10px;
  color: var(--strong);
  font-size: 14px;
  font-weight: 600;
}
.viz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.viz-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--card);
}
.viz-label {
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.viz-value {
  color: var(--strong);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.viz-delta { font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.viz-delta--good { color: var(--ok); }
.viz-delta--bad { color: var(--err); }
.viz-delta--neutral { color: var(--muted); }
.viz-hint { color: var(--faint); font-size: 11.5px; overflow-wrap: anywhere; }

.viz-bars { display: flex; flex-direction: column; gap: 8px; }
.viz-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(60px, 110px) auto;
  align-items: center;
  gap: 10px;
}
.viz-bar-label { color: var(--fg); font-size: 13px; overflow-wrap: anywhere; }
.viz-bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--line-soft);
  overflow: hidden;
}
.viz-bar-fill { display: block; width: 100%; height: 8px; }
.viz-bar-fill rect { fill: var(--accent); }
.viz-bar-value {
  color: var(--strong);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* The steps of a turn — the key element of the page: which tool, with what, and
   how it ended. Collapsed for older turns, open for the newest one. */
.trace {
  margin: 14px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--soft);
}

.trace-head { display: flex; align-items: baseline; gap: 8px; cursor: pointer; }
.trace-head::-webkit-details-marker { display: none; }
.trace-icon { color: var(--faint); font-size: 12px; }

.trace-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.trace-count { color: var(--faint); font-size: 12px; margin-left: auto; }

.trace-steps { list-style: none; margin: 12px 0 2px; padding: 0; }

/* One step: mark · tool tag · what happened · metrics on the right. */
.step {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 14px;
}

.step:first-child { border-top: 0; padding-top: 2px; }

.mark {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  background: var(--tag-bg);
  color: var(--muted);
}

.step.ok .mark { background: #ecfdf5; color: var(--ok); }
/* Шаг, который автоматизация выполнила по стоячему согласию: не «выполнено» (это
   значит «человек нажал») и не «ожидает» — отдельное состояние со своим значком. */
.step.auto .mark { background: #eef2ff; color: var(--accent-dark); }
.step.error .mark, .step.denied .mark { background: #fef2f2; color: var(--err); }
.step.awaiting .mark { background: #fffbeb; color: var(--warn); }

.step-main { min-width: 0; }
.what { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }

/* The tool as a monospace chip: service in grey, the rest after a dot. */
.tag {
  display: inline-flex;
  align-items: baseline;
  padding: 2px 7px;
  border-radius: 7px;
  background: var(--tag-bg);
  color: var(--tag-fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.action { color: var(--strong); }
.step .chip {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 11px;
}

.step .metrics {
  color: var(--faint);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

.plain-args {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.step details { margin-top: 6px; }
.step details > summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.step .hint { margin: 4px 0 0; }

/* Steps appear one after another, as if the agent were still working. Pure CSS:
   one delay per position — no inline style, so the strict CSP stays strict. */
@keyframes step-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.trace-steps .step { animation: step-in 260ms ease-out both; }
.trace-steps .step:nth-child(1) { animation-delay: 30ms; }
.trace-steps .step:nth-child(2) { animation-delay: 110ms; }
.trace-steps .step:nth-child(3) { animation-delay: 190ms; }
.trace-steps .step:nth-child(4) { animation-delay: 270ms; }
.trace-steps .step:nth-child(5) { animation-delay: 350ms; }
.trace-steps .step:nth-child(6) { animation-delay: 430ms; }
.trace-steps .step:nth-child(7) { animation-delay: 510ms; }
.trace-steps .step:nth-child(8) { animation-delay: 590ms; }
.trace-steps .step:nth-child(n+9) { animation-delay: 670ms; }

@media (prefers-reduced-motion: reduce) {
  .trace-steps .step { animation: none; }
}

/* The human gate: nothing is sent anywhere until this is clicked. */
.pending {
  border: 1px solid #fcd34d;
  background: #fffbeb;
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin: 24px 0;
}

.pending h3 { color: #92400e; margin-bottom: 6px; }

.args {
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 10px 0;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* The band with the field you ask into: the last item of the flex column, a
   *sibling* of the thread rather than a child of the scroller.

   Neither ``fixed`` (that needs height arithmetic and leaves the last message
   hidden behind it) nor ``sticky`` inside the scroll container: the thread takes
   the free space and scrolls, this band keeps the bottom edge of the window — which
   is what a chat does. The soft shadow above it marks where the messages go under.
   A light teal halo appears around the field while the caret is inside. */
.composer-wrap {
  flex: 0 0 auto;
  padding: 10px 20px 12px;
  background: var(--card);
  box-shadow: var(--shadow-up);
}

.composer {
  max-width: var(--feed);
  margin: 0 auto;
  padding: 12px 10px 8px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-sm);
}

.composer:focus-within {
  border-color: #a7f3d0;
  box-shadow: 0 0 0 4px var(--glow), var(--shadow-sm);
}

.composer textarea {
  width: 100%;
  margin: 0;
  padding: 2px 0;
  min-height: 26px;
  max-height: 220px;
  border: 0;
  background: transparent;
  font-size: 15.5px;
  line-height: 1.55;
  resize: none;
  overflow-y: auto;
}

.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--faint); }
.composer.is-locked textarea { color: var(--muted); }

.composer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

/* Подсказка может быть длинной («осталось запросов: 3 из 3» плюс Enter), поэтому она
   тянется и умеет сжиматься: на узком экране текст переносится, а не выдавливает
   кнопку отправки из полосы. */
.composer-hint {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--faint);
  font-size: 12px;
}

/* Подсказка про Enter и счётчик запросов — две разные вещи в одной строке: на узком
   экране пропадает только первая (``.keys``), а «осталось запросов» остаётся
   видимым — это не удобство, а то, за что человек платит. Разделитель нарисован
   CSS: он уезжает вместе с подсказкой, а не остаётся висеть точкой. */
.composer-hint .keys::after { content: " · "; }
.composer-hint .quota { color: var(--muted); }

/* Скрепка: <label> вокруг настоящего ``<input type="file">``. Поле спрятано от
   глаз, но остаётся настоящим полем — нажатие по подписи открывает системный
   диалог, Tab доходит до него, и без JavaScript форма отправляется так же. Цвет
   контура — ``currentColor``, как у корзинки в истории. */
.attach {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  margin-left: -4px;
  border-radius: var(--radius-sm);
  color: var(--faint);
  cursor: pointer;
}
.attach:hover { background: var(--hover); color: var(--strong); }
.attach-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
}
.attach .clip {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Файл выбран: скрепка это показывает. Класс ставит app.js — он же рисует чипсы
   ниже; без JavaScript подсветки нет, но файл всё равно уезжает с формой: он
   лежит в самом поле выбора, а не в чипсах. */
.attach.is-set { color: var(--accent-dark); background: var(--accent-soft); }

/* Промты у поля вопроса: кнопка рядом со скрепкой и меню готовых промтов под ней.
   Кнопка — ``<summary>`` у ``<details>``: меню раскрывается и закрывается само, без
   JavaScript, а каждый промт внутри — настоящая ссылка в *эту же* беседу с ``?p=``
   (``app._prompt_link``), поэтому текст встаёт в поле вопроса и без app.js. С app.js
   клик кладёт текст на месте (``.prompt-pick`` в app.js).

   Меню растёт вверх (``bottom: calc(100% + 8px)``), а не вниз: полоса с полем стоит у
   самого низа окна, и меню вниз уехало бы за край. Цвет кнопки — тот же акцентный, что
   у нажатой скрепки: это её сосед по работе над вопросом. */
.prompts { position: relative; flex: 0 0 auto; }
.prompts-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px 0 8px;
  border-radius: var(--radius-sm);
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 12px;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}
.prompts-btn::-webkit-details-marker { display: none; }
.prompts-btn .spark { display: block; fill: currentColor; }
.prompts-btn:hover,
.prompts[open] .prompts-btn { color: var(--accent-ink); background: var(--accent-dark); }

.prompts-menu {
  position: absolute;
  z-index: 6;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(340px, 78vw);
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.prompts-head { margin: 4px 6px 6px; color: var(--faint); font-size: 12px; }
.prompt-pick {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg);
  text-decoration: none;
}
.prompt-pick:hover { background: var(--hover); }
.prompt-pick-title { display: block; font-size: 13.5px; color: var(--strong); }
.prompt-pick-note { display: block; margin-top: 2px; color: var(--faint); font-size: 11.5px; }
/* Последняя строка меню — дверь в каталог: промт выбирают и глазами, а не только из
   короткого списка, и страница «ИИ Промты» для этого и стоит. */
.prompts-all {
  display: block;
  margin-top: 4px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  color: var(--accent);
  font-size: 12.5px;
  text-decoration: none;
}
.prompts-all:hover { color: var(--accent-dark); text-decoration: underline; }

/* Имена выбранных файлов над полем. Их пишет app.js (id="attach-list"), поэтому
   без JavaScript блок пуст — и обязан быть пустым, а не пустым по размеру:
   ``hidden`` не работает без этой строки, потому что выше задан ``display: flex``. */
.composer-files { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.composer-files[hidden] { display: none; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--sunken);
  font-size: 12px;
}
.file-chip .file-name { overflow-wrap: anywhere; }
.file-chip .file-size { color: var(--faint); white-space: nowrap; }
.file-chip .file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.file-chip .file-drop:hover { background: #fee2e2; color: var(--err); }
/* Файл, который сервер не примет: он больше лимита. Сказать об этом до отправки
   дешевле, чем показать отказ после неё (app.js знает лимит из разметки). */
.file-chip.is-big { border-color: #fcd34d; background: #fffbeb; }
.file-chip.is-big .file-size { color: #92400e; }
/* Файл тащат в поле вопроса: тем же светом, что и фокус в поле. */
.composer.is-drop { border-color: var(--accent); box-shadow: 0 0 0 4px var(--glow), var(--shadow-sm); }

/* The send button: a grey circle with an arrow, and teal as soon as there is
   something to send. Pure CSS — ``:has`` reads the textarea next to it. */
.send {
  margin-left: auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #d1d5db;
  color: #ffffff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  /* Не только заливка: у кнопки остановки гаснет ещё и прозрачность, когда нажатие
     принято (``.composer.is-stopping``), — и гаснет так же мягко. */
  transition: background 120ms ease-out, opacity 120ms ease-out;
}

.send:hover { background: #9ca3af; }
.send:disabled { background: #e5e7eb; cursor: default; }
/* Текст в поле красит **стрелку**, а не любую кнопку в этой полосе: рядом с ней
   стоит кнопка остановки, у которой своя заливка (см. ниже). */
.composer:has(textarea:not(:placeholder-shown)) .send.go { background: var(--accent); }
.composer:has(textarea:not(:placeholder-shown)) .send.go:hover { background: var(--accent-dark); }

/* Остановка хода: пока ответ считается, кнопка отправки уступает это место ей —
   те же 34 пикселя, тот же правый край, поэтому ничего не переезжает. Это тот же
   кружок, что у отправки, но с белым квадратом внутри: знак «стоп» узнаётся без
   подписи и без перевода, а заливка — тот же зелёный, что у главных кнопок сайта
   (``--accent``). Отправка и остановка различаются знаком, а не местом. */
.send.stop {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--accent);
}
.send.stop:hover { background: var(--accent-dark); }
.send.stop .stop-mark {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: #ffffff;
}

/* Что показывать — стрелку или знак «стоп» — решает не разметка, а состояние
   запроса: класс ``htmx-request`` живёт на самой форме вопроса, пока ход считается,
   а обе кнопки лежат **внутри** этой формы — поэтому здесь достаточно одного класса,
   без ``:has()`` и без второго класса на обёртке. Достаётся форме этот класс только
   потому, что ``hx-indicator`` в разметке называет её саму (``#composer-form``):
   HTMX вешает свой класс лишь на элементы из ``hx-indicator``, а тому, кто запрос
   отправил, — не вешает (``or()`` в htmx.min.js). Пока атрибут указывал на
   ``#waiting``, правило ниже не срабатывало ни разу: класс доставался одной надписи,
   и стрелка оставалась на месте весь ход. */
.composer.htmx-request .send.go { display: none; }
.composer.htmx-request .send.stop { display: inline-flex; }
/* Кнопка остановки на месте стрелки бывает не только от ``htmx-request``: страницу могли
   открыть (или перечитать) посреди хода — форму запроса тогда никто не посылал, класса нет,
   а останавливать есть что: ход идёт. ``is-running`` ставит сервер из той же записи, которую
   читает кнопка остановки (``deps.running``), поэтому знак «стоп» стоит там, где ход идёт, и
   возвращается стрелкой вместе с концом хода. */
.composer.is-running .send.go { display: none; }
.composer.is-running .send.stop { display: inline-flex; }
/* Нажатие принято, ход доворачивается: знак «стоп» остаётся на месте, но гаснет и
   больше не нажимается — останавливать второй раз нечего, а пропажа кнопки читалась
   бы как «не сработало». Стрелка возвращается сама: ответ хода приносит полосу
   вопроса заново, вместе с ней уходит и ``htmx-request``. Классы ставит app.js на
   первый же запрос остановки: ``is-stopping`` на саму форму и на подставной ход в
   ленте. */
.composer.is-stopping .send.go { display: none; }
.composer.is-stopping .send.stop { display: inline-flex; opacity: .45; pointer-events: none; }
.turn.is-sending.is-stopping .spinner {
  animation: none;
  border-top-color: var(--line);
}

/* Форма остановки — пустая (в ней один CSRF-токен) и своей роли на экране не играет:
   кнопка лежит в форме вопроса и ссылается сюда атрибутом ``form``. Нолём отступов
   здесь сказано ровно это: между полосой вопроса и подписью под ней она ничего не
   добавляет. */
.stop-form { margin: 0; }

.composer-note {
  max-width: var(--feed);
  margin: 8px auto 0;
  text-align: center;
  color: var(--faint);
  font-size: 12px;
}
/* Причина, по которой вопрос не ушёл: файл слишком большой, кабинет недоступен,
   ошибка хода. Стоит прямо над полем — это ответ на только что нажатое, и искать его
   глазами по странице человек не должен (с HTMX фрагмент приезжает без вспышки
   страницы, см. _composer.html). */
.composer-error {
  max-width: var(--feed);
  margin: 0 auto 8px;
  padding: 8px 12px;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  color: #b91c1c;
  font-size: 13px;
}
/* Что читается из файла и сколько можно приложить, стоит не здесь, а у самой
   скрепки (её подсказка) и в отказе сервера: под полосой вопроса остаётся одна
   короткая строка про то, что цифры надо проверять. */

.audit { margin-top: 28px; }
.audit summary { cursor: pointer; color: var(--muted); }

/* --- the chat shell: the history panel and the conversation ------------------ */

/* The chat owns the whole window: the page itself does not scroll, the column of
   messages does. That is what keeps the composer at the bottom edge. */
body.app-body { height: 100vh; height: 100dvh; overflow: hidden; }

/* The chat pages keep base.html's footer tag but not its content: inside an app
   shell the bottom of the window belongs to the composer. */
body.app-body .foot { display: none; }

main.app-main {
  flex: 1 1 auto;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
}

/* A flash message floats over the shell instead of pushing the composer down. */
.app-main > .flash {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  margin: 0;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.shell { display: flex; width: 100%; min-height: 0; }

/* --- the left panel ---------------------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 var(--sidebar);
  width: var(--sidebar);
  min-height: 0;
  padding: 14px 12px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.side-top { position: relative; }
.side-logo { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; color: var(--strong); }
/* Марка в углу панели: у чата, автоматизаций и промтов шапки нет, и раздел узнают
   по ней. Стоит перед стрелкой меню разделов — той же, что открывает остальные. */
.side-brand { flex: 0 0 auto; display: block; width: 24px; height: 24px; border-radius: 7px; }
.side-caret { margin-left: auto; color: var(--faint); font-size: 11px; }

/* Выбора кабинета в панели нет (``_sidebar.html``): беседа заводится в кабинете по
   умолчанию, а выбор кабинета один — в «Настройках». */
.side-new { margin-bottom: 12px; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--strong);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.new-chat:hover { background: var(--hover); }
.new-chat .plus { color: var(--muted); font-size: 16px; line-height: 1; }
.new-chat .new-label { flex: 1 1 auto; text-align: left; }
.new-chat kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--sunken);
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

/* Закрытая дверь: «Новый чат» и «Новая автоматизация» при исчерпанном лимите — не
   кнопка, а состояние. Причина сказана рядом словами (``.side-warn``), поэтому здесь
   достаточно того, чтобы она читалась неживой и не ловила наведение как живая. */
.new-chat.is-off {
  background: var(--sunken);
  color: var(--faint);
  cursor: not-allowed;
}
.new-chat.is-off:hover { background: var(--sunken); }

.side-search { position: relative; margin-bottom: 12px; }
.side-search .lens {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: 14px;
}
.side-search input {
  width: 100%;
  margin: 0;
  padding: 9px 12px 9px 30px;
  background: var(--sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  font-size: 14px;
}
.side-search input:focus { background: var(--card); border-color: var(--line); }

.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  color: var(--fg);
  font-size: 14px;
  text-decoration: none;
}
.side-item:hover, .side-item.is-active { background: var(--hover); }
.side-item.is-active { font-weight: 500; }
.side-icon { font-size: 14px; }
.side-label { flex: 1 1 auto; }
.side-badge {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--line-soft);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* «Сегодня», «Вчера», «7 дней»… — a quiet line above each block of history. */
.side-head {
  margin: 12px 0 4px;
  padding: 0 10px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 500;
}

/* Only the history scrolls: the way in, the search and the profile stay put. */
.side-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-bottom: 8px; }
.side-group + .side-group { margin-top: 6px; }
.side-list { margin: 0; }
.side-link {
  display: block;
  padding: 9px 10px;
  color: var(--fg);
  text-decoration: none;
}
/* Строка истории — это ссылка и корзинка: наведя курсор, человек видит красный
   значок справа и может удалить беседу. Подсветка живёт на самой строке, а не на
   ссылке, иначе она гасла бы, стоило курсору сойти на корзинку. Корзинка скрыта и
   прозрачна для кликов — правый край строки обязан остаться ссылкой, иначе промах
   по нему удалял бы беседу; кликабельной она становится вместе с видимой. На
   тачскрине наведения нет, там она видна всегда. */
.side-row { position: relative; margin-bottom: 2px; }
.side-row:hover, .side-row.is-active { background: var(--hover); border-radius: var(--radius-md); }
.side-row:hover .side-title, .side-row:focus-within .side-title { padding-right: 30px; }
.side-del {
  position: absolute;
  top: 5px;
  right: 5px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out;
}
.side-row:hover .side-del, .side-del:focus-within {
  opacity: 1;
  pointer-events: auto;
}
.side-del-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--err);
  cursor: pointer;
}
/* Контур корзинки берёт цвет у кнопки (`currentColor`), поэтому в CSS она красная
   ровно так же, как и всё остальное красное в приложении. */
.side-del-btn .trash {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.side-del-btn:hover { background: #fee2e2; }
.side-del-btn:focus-visible { background: #fee2e2; outline: 2px solid var(--accent); }
@media (hover: none) {
  .side-del { opacity: 1; pointer-events: auto; }
  .side-title { padding-right: 30px; }
}
.side-title {
  display: block;
  color: var(--strong);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-meta { display: flex; align-items: baseline; gap: 8px; margin-top: 3px; }
.side-preview {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--faint);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-time { color: var(--faint); font-size: 11px; white-space: nowrap; }
.side-empty { margin: 4px 10px; color: var(--faint); font-size: 12px; }
.side-warn { display: block; margin: 4px 10px; color: var(--warn); font-size: 12px; }

.side-user { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line-soft); }
.side-user > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  list-style: none;
}
.side-user > summary::-webkit-details-marker { display: none; }
.side-user > summary:hover, .side-user[open] > summary { background: var(--hover); }

.avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 600;
}

.side-who { flex: 1 1 auto; min-width: 0; }
.side-name {
  display: block;
  color: var(--strong);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-role { display: block; color: var(--faint); font-size: 11px; }

.side-menu { padding: 4px 6px 2px; }
.side-menu form { margin: 0; }
.side-menu a, .side-menu button {
  display: block;
  width: 100%;
  padding: 7px 8px;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  text-decoration: none;
}
.side-menu a:hover, .side-menu button:hover { background: var(--hover); color: var(--strong); }

/* --- the conversation column -------------------------------------------------- */

.chat-col {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--card);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}
.chat-title {
  flex: 0 1 auto;
  margin: 0;
  color: var(--strong);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head .chip {
  padding: 2px 8px;
  border: 0;
  background: var(--sunken);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.share {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  text-decoration: none;
}
.share:hover { background: var(--hover); color: var(--strong); }
.share.is-copied { background: var(--accent-soft); color: var(--accent-dark); }

/* The one scrolling element of the chat: the header and the band under it never
   move, so nothing scrolls the field out of the window. The gutter is reserved on
   both sides, otherwise the feed and the band below it would sit on slightly
   different axes as soon as a scrollbar appears.

   ``overflow-x: hidden`` — не страховка, а правило: лента не прокручивается вбок
   ни на телефоне, ни на широком экране. Всё, что шире колонки, прокручивается
   внутри себя — таблица ответа (``.md-scroll``), аргументы вызова (``.args``),
   код (``pre.md-code``): широкое место должно остаться в своём прямоугольнике, а
   не утянуть за собой весь разговор. Раньше (до 02.10.2026) ``overflow-y: auto``
   при ``overflow-x: visible`` превращал видимую ось в ``auto`` — и таблица на
   шесть колонок уезжала вбок вместе с полем вопроса. */
.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px 8px;
  scrollbar-gutter: stable both-edges;
}

/* The strip every message lives on: 860px, centred, whatever the window is. */
.feed { max-width: var(--feed); margin: 0 auto; }

/* Search results (``_list.html``) and the card rows of the расписание list. */
.panel { padding: 4px 0 24px; }
.panel-title { margin: 0 0 6px; font-size: 18px; color: var(--strong); }
.cards { list-style: none; margin: 14px 0 0; padding: 0; }
.card-row { margin-bottom: 8px; }
.card-link {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--fg);
  text-decoration: none;
}
.card-link:hover { background: var(--hover); }
.card-name { display: block; color: var(--strong); font-weight: 500; }
.card-line { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.card-time { display: block; margin-top: 4px; color: var(--faint); font-size: 11px; }

/* --- htmx -------------------------------------------------------------------- */

/* The spinner only appears while a request is in flight. */
.htmx-indicator { visibility: hidden; color: var(--muted); font-size: 13px; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { visibility: visible; }

/* …и пока вопрос уже в ленте, а ответа ещё нет. Отправленный вопрос кладёт в ленту
   ``app.js`` — и это подставной ход, а не состояние страницы: ответ приезжает
   заменой всей ленты и забирает кружок с собой. Кружок стоит слева от пузыря, как
   и просили, и нарисован чистым CSS (рамка с одним цветным краем): ни картинки, ни
   inline-стиля — CSP домена пускает только 'self'. */
.turn.is-sending .ask-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
.turn.is-sending .bubble.user { margin-left: 0; min-width: 0; }
.spinner {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
/* Строка «ход идёт» в ленте: кружок тот же, что у подставного вопроса (app.js), — ожидание
   и там, и здесь выглядит одинаково. Стоит она в ленте, а не только в полосе вопроса: полоса
   молчит, когда страницу открыли посреди хода (класса запроса нет), а лента говорит, что ход
   идёт, — и одна и та же строка приезжает в каждом её перечитывании. */
.live-turn { display: flex; align-items: center; gap: 8px; }
.live-turn .spinner { width: 12px; height: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Вращение — такое же движение, как всё остальное: тому, кто попросил его меньше,
   кружок крутится медленнее, а не исчезает — ожидание и есть то, что он сообщает. */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2400ms; }
}

/* --- auth: one page, two doors ------------------------------------------------ */

/* The seg control from the reference: the active door is a white tab on a sunken
   track. It is two real links, so the choice survives a reload and works with
   JavaScript off. */
.auth-card { padding-top: 22px; }
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 18px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.tab {
  flex: 1 1 0;
  padding: 9px 12px;
  text-align: center;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.tab:hover { color: var(--strong); }
.tab.is-active { background: var(--card); color: var(--strong); box-shadow: var(--shadow-sm); }
button.wide { width: 100%; margin-top: 8px; }
.auth-alt { margin: 16px 0 0; text-align: center; color: var(--muted); font-size: 13px; }

/* A checkbox with a wrapping label — the consent pair on the registration form. */
label.check { display: flex; align-items: flex-start; gap: 9px; margin: 12px 0; color: var(--fg); font-size: 13px; }
label.check input { width: auto; flex: 0 0 auto; margin: 2px 0 0; }

/* --- settings ---------------------------------------------------------------- */

/* Two columns like the reference: a small section rail on the left, the panel on
   the right. On a phone the rail becomes a row of pills. */
.settings-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 28px; }
.settings-nav { position: sticky; top: 16px; align-self: start; }
.settings-nav a {
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}
.settings-nav a:hover { background: var(--hover); color: var(--strong); }
.settings-nav a.is-active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 500; }
.settings-title { margin: 0 0 6px; font-size: 20px; color: var(--strong); }
.key-block { padding: 22px 0; border-top: 1px solid var(--line-soft); }
.key-block:first-of-type { padding-top: 0; border-top: 0; }
.key-block h3 { margin: 0 0 4px; font-size: 16px; color: var(--strong); }
.key-block .hint { margin: 0 0 10px; }
.key-status { display: inline-flex; align-items: center; gap: 7px; margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.key-status .dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.key-status.is-on .dot { background: var(--ok); }
.key-status.is-on { color: var(--accent-dark); }
.key-note {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  color: var(--accent-dark);
  font-size: 13px;
}
.key-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.key-actions form { margin: 0; }
.reveal { flex: 0 0 auto; }
.reveal svg { display: block; }

@media (max-width: 760px) {
  .settings-grid { grid-template-columns: 1fr; gap: 16px; }
  .settings-nav { position: static; display: flex; flex-wrap: wrap; gap: 4px; }
}

/* --- narrow screens: панель истории — выдвижной ящик ------------------------- */

/* На телефоне панель слева отняла бы у беседы больше половины ширины, поэтому она
   уезжает за край и открывается кнопкой в шапке. Механика — на флажке:
   ``.nav-toggle`` это настоящий checkbox, ``.nav-btn`` и ``.scrim`` — его подписи, а
   открытое состояние читают соседние селекторы (``~``), а не класс из app.js.
   Поэтому ящик работает и без JavaScript: app.js добавляет только Escape и
   ``aria-expanded`` на кнопку. На широком экране всего этого нет — флажок, кнопка и
   затемнение скрыты, панель стоит на месте.
*/
.nav-toggle, .nav-btn, .scrim, .side-close { display: none; }
.side-close { cursor: pointer; }
.side-close:hover { background: var(--hover); color: var(--strong); }
.nav-btn:active { background: var(--hover); }

@media (max-width: 900px) {
  .shell { position: relative; }
  /* Флажок невидим, но настоящий: 1×1 пиксель в углу — Tab доходит до него первым,
     Space открывает ящик, а рамку фокуса мы показываем на кнопке (см. ниже). */
  .nav-toggle {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
  }
  .nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    margin-left: -8px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
  }
  .nav-btn:hover { background: var(--hover); color: var(--strong); }
  .nav-btn .burger {
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
  }
  .shell:has(.nav-toggle:focus-visible) .nav-btn { outline: 2px solid var(--accent); outline-offset: 2px; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(86vw, 320px);
    /* Нижний отступ панели — её собственные 14px плюс запас под системную полосу
       жеста: `padding-bottom` здесь не сокращение, а одна сторона, поэтому 14px надо
       повторить, иначе на экране без выреза панель прилипнет к краю. */
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    background: var(--card);
    box-shadow: 0 0 40px rgb(16 24 40 / 22%);
    /* Закрытый ящик не только за краем, но и невидим: иначе Tab доходил бы до
       ссылок истории, которых человек не видит. */
    visibility: hidden;
    transform: translateX(-101%);
    transition: transform 180ms ease-out, visibility 180ms ease-out;
  }
  .nav-toggle:checked ~ .sidebar { visibility: visible; transform: none; }
  /* ✕ стоит в самой панели, а не в строке меню: внутри ``<summary>`` нажатие на него
     ещё и раскрывало бы «ИИ Чат / ИИ Автоматизация». Панель на телефоне —
     ``position: fixed``, поэтому отсчёт идёт от неё. */
  .side-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 10px;
    width: 26px;
    height: 26px;
    margin-left: 4px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
  }
  /* На телефоне ✕ и строка разделов («▾ ИИ-агент») делят один и тот же угол панели: ✕
     нарисован позже, поэтому забирал нажатие себе — меню разделов не открывалось вовсе.
     Строка уступает крестику место справа, а стрелка разделов стоит слева (``.side-caret``
     в ``.side-top > summary``), поэтому подпись и кнопка не наезжают друг на друга; список
     разделов начинается под строкой, а не поверх неё: так он не может накрыть крестик ни
     при какой высоте строки. */
  .side-top > summary { padding-right: 44px; }
  .side-pick { top: 100%; }
  /* Затемнение — вторая подпись того же флажка: нажатие по нему закрывает ящик. */
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgb(17 24 39 / 35%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease-out;
  }
  .nav-toggle:checked ~ .scrim { opacity: 1; pointer-events: auto; }

  .chat-head { padding: 10px 14px; }
  .chat-scroll { padding: 16px 14px 8px; }
  /* Ниже — и с запасом под системную полосу жеста: поле вопроса не должно липнуть
     к самому низу экрана. */
  .composer-wrap { padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); }
  .bubble.user { max-width: 88%; }
  /* Пропадает только подсказка про клавиши: цифра «осталось запросов» нужна. */
  .composer-hint .keys { display: none; }
  /* 16px — не красота: iOS приближает страницу к полю, у которого шрифт мельче. */
  .composer textarea { font-size: 16px; }
}

/* Телефон у чата: 360–420 пикселей ширины. Здесь важно не «уменьшить», а не дать
   разговору уехать вбок — лента не прокручивается по горизонтали ни при какой
   ширине (``.chat-scroll``), и всё, что шире колонки, прокручивается внутри себя
   (``.md-scroll`` у таблицы ответа). Шапка беседы — единственное место, где три
   подписи стоят в одну строку: название беседы длинное, кабинет назван словом, и
   без сжатия они выдавливали бы друг друга из строки. Сжимаются оба (``overflow``
   на элементе флекс-строки снимает его минимальную ширину), и обрезаются
   многоточием — так видно и название, и кабинет, и значок ссылки. */
@media (max-width: 640px) {
  .chat-head { gap: 8px; padding: 10px 12px; }
  .chat-head .chip {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-head .nav-btn, .chat-head .share { flex: 0 0 auto; }
  /* Ответ читается тем же кеглем, но таблицы в нём — уже не «мелкий шрифт ради
     экономии места»: у них своя прокрутка, поэтому поля можно ужать. */
  .answer table th, .answer table td { padding: 6px 9px; font-size: 13.5px; }
  .md-scroll { margin: 10px 0 14px; }
}

/* Тому, кто попросил меньше движения, ящик достаётся без анимации — но не
   мгновенно открытым: сдвиг всё равно переключается, просто сразу. */
@media (prefers-reduced-motion: reduce) {
  .sidebar, .scrim { transition: none; }
}

@media (max-width: 640px) {
  main { padding: 16px; }
  .card { padding: 20px; border-radius: var(--radius-md); }
  .card.narrow { margin-top: 16px; }

  .top { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .top nav { flex-wrap: wrap; gap: 12px; }
  .step { grid-template-columns: 20px minmax(0, 1fr); }
  .step .metrics { grid-column: 2; text-align: left; white-space: normal; }
  .row { flex-wrap: wrap; }
}

/* --- разделы: меню «ИИ Чат / ИИ Автоматизация / ИИ Промты» в панели ------------- */

.side-top { position: relative; }
/* Сводка меню разделов — строка, как раньше надпись, но нажимаемая. */
.side-top > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 14px;
  cursor: pointer;
  list-style: none;
  transition: background .15s ease;
}
.side-top > summary::-webkit-details-marker { display: none; }
.side-top > summary:hover .side-logo { color: var(--accent-dark); }
/* Стрелка у подписи раздела — не бледная точка. Это единственная дверь в остальные
   разделы, и в прежнем виде её не находили: «ИИ-агент» читался как надпись, а не как
   меню. Теперь это кнопка в цвете акцента — видно без наведения, наведение заливает
   её тёмным и подсвечивает всю строку, а раскрытое меню переворачивает стрелку.

   Стоит она слева, перед подписью: это первое, за что цепляется глаз в углу панели, а
   подпись справа от неё называет раздел. ``margin-left: 0`` здесь не для красоты: общее
   правило ``.side-caret`` прижимает стрелку вправо (``margin-left: auto``) — так она
   стоит в строке профиля внизу, — и без этой строки стрелка раздела уезжала бы к
   правому краю, оставляя подпись висеть слева. */
.side-top > summary:hover { background: var(--hover); border-radius: var(--radius-sm); }
.side-top > summary .side-caret {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 0;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, background .15s ease;
}
.side-top > summary:hover .side-caret { background: var(--accent-dark); }
.side-top[open] > summary .side-caret { transform: rotate(180deg); }
/* Меню — поверх содержимого панели: раскрытие не должно сдвигать «Новый чат» и
   историю бесед, иначе список прыгал бы при каждом выборе раздела. */
.side-pick {
  position: absolute;
  z-index: 6;
  left: 8px;
  right: 8px;
  top: 38px;
  padding: 4px 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.side-pick a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 14px;
  text-decoration: none;
}
.side-pick a:hover { background: var(--hover); color: var(--strong); }
.side-pick a.is-active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 500; }

/* --- расписание: работы, вилка и история прогонов ---------------------------- */

.auto-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 16px 0 4px; }
.auto-actions form { margin: 0; }
.auto-back { color: var(--accent); font-size: 13px; text-decoration: none; }
.auto-back:hover { text-decoration: underline; }
.auto-form .row label { flex: 1 1 200px; }
.auto-form .row { margin-bottom: 6px; }
.auto-form .hint { display: block; margin: 5px 0 0; font-weight: 400; }
.auto-form .key-actions { margin-top: 18px; }
.auto-problems { margin: 8px 0 0 18px; }
.auto-runs td { vertical-align: top; }
.auto-result { display: block; margin-top: 4px; color: var(--muted); }
.auto-runs td .auto-back { display: inline-block; margin-top: 4px; }

/* Строка автоматизации в панели — такая же, как строка беседы, только без корзинки:
   сдвигать заголовок под несуществующую кнопку на наведении нечего. */
.side-scroll--automations .side-row:hover .side-title,
.side-scroll--automations .side-row:focus-within .side-title { padding-right: 0; }

/* --- каталоги: «ИИ Автоматизации» и «ИИ Промты» ------------------------------- */

/* Поиск, полоски категорий с числами и сетка карточек — для обоих каталогов: работа
   и промт выглядят как одно приложение, потому что читает их один и тот же человек.
   На «ИИ Автоматизации» карточка ведёт заводить расписание, на «ИИ Промты» — спрашивать
   в беседе (``_library.html`` и ``_prompts.html``); разное у них только слово на кнопке.
   Ни одной картинки — значок сервиса нарисован глифом в цветном квадрате, а цвета
   берутся из токенов выше. */
.lib-search { position: relative; margin: 14px 0 0; }
.lib-search .lens {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: 15px;
}
.lib-search input {
  width: 100%;
  margin: 0;
  padding: 10px 14px 10px 34px;
  background: var(--sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  font-size: 14px;
}
.lib-search input:focus { background: var(--card); border-color: var(--line); }

.lib-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.lib-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.lib-chip b { color: var(--strong); font-weight: 600; }
.lib-chip:hover { border-color: #d1d5db; color: var(--strong); }
.lib-chip.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.lib-chip.is-active b { color: var(--accent-dark); }

.lib-legend { display: flex; align-items: baseline; gap: 7px; margin: 12px 0 0; color: var(--faint); font-size: 12px; }
.lib-legend .lib-mark { color: #6d28d9; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
}
.lib-card {
  display: flex;
  flex-direction: column;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}
.lib-card:hover { border-color: #d1d5db; box-shadow: var(--shadow-sm); }
.lib-card.is-chosen { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.lib-card--empty { justify-content: center; }

/* «Сводка за период wb» — единственная карточка каталога с выбором срока. Фон и
   полоска светло-зелёные — те же, что у поля вопроса и его подсказок
   (``--accent-soft``, ``#a7f3d0``): срок — часть вопроса, а не отдельное расписание,
   и карточка говорит об этом цветом раньше, чем человек прочтёт слово «промт».
   Наведение — только полоска (``--accent``): зелёное кольцо ``.lib-card.is-chosen``
   означает «выбрано», и карточка не должна выглядеть выбранной сама по себе. */
.lib-card--period { background: var(--accent-soft); border-color: #a7f3d0; }
.lib-card--period:hover { border-color: var(--accent); }

.lib-top { display: flex; align-items: center; gap: 10px; }
.lib-icon {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 15px;
}
.lib-icon--wb { background: #eef2ff; color: #4f46e5; }
.lib-icon--ozon { background: #e0f2fe; color: #0369a1; }
.lib-icon--ym { background: #fee2e2; color: #b91c1c; }
.lib-icon--avito { background: #dcfce7; color: #15803d; }
.lib-icon--own { background: var(--line-soft); color: var(--muted); }
.lib-head { flex: 1 1 auto; min-width: 0; }
/* ``pre-line`` — ради промта-формы (``wb_unit_economics``): у него заголовок это семь
   строк, которые человек и заполняет, а обычному промту переносить нечего. Пробелы
   схлопываются, переносы остаются — то же, что видно в поле вопроса. */
.lib-title { display: block; color: var(--strong); font-size: 14px; font-weight: 600; white-space: pre-line; }
.lib-cat { display: block; color: var(--faint); font-size: 12px; }
/* «Навык» — то же слово, что в легенде: работа ставится на расписание, а не
   спрашивается один раз. Фиолетовый — чтобы отличать от зелёного действия. */
.lib-badge {
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ede9fe;
  color: #6d28d9;
  font-size: 11px;
}

.lib-desc { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.lib-meta { margin: 8px 0 0; color: var(--faint); font-size: 11px; }

/* Строка сроков «Сводки за период wb» — над подвалом, во всю ширину карточки.
   Кнопки переносятся, если не поместились: срок называют словом («Последние 7
   дней»), и обрезать слово ради одной строки нельзя. Кольцо вместо заливки — чтобы
   три подписи подряд читались как выбор одного из трёх, а не как три разных
   действия; «Спросить» у соседних карточек залито, и здесь заливка спорила бы с
   ней за одно и то же внимание. */
.lib-periods { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.lib-period {
  padding: 5px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--card);
  color: var(--accent-dark);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.lib-period:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: var(--accent-ink);
}

.lib-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
}
.lib-more { flex: 1 1 auto; min-width: 0; }
.lib-more > summary {
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
}
.lib-more > summary::-webkit-details-marker { display: none; }
.lib-more > summary:hover { color: var(--accent-dark); text-decoration: underline; }
.lib-full { margin-top: 8px; color: var(--muted); font-size: 12px; }
.lib-full p { margin: 0 0 6px; }
.lib-full p:last-child { margin-bottom: 0; }

.lib-use {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--hover);
  color: var(--strong);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.lib-use:hover { background: #e5e7eb; }
/* Кнопка каталога при исчерпанном лимите: и расписание не заведёшь, и вопрос не
   задашь — «Лимит исчерпан» не то, что стоит нажимать. Цвет приглушён, но текст
   читается: это ответ, а не запрет без объяснений (подробности — в подписи ``title``). */
.lib-use.is-off { opacity: .55; cursor: not-allowed; }
.lib-use.is-off:hover { background: var(--hover); }
.lib-picked {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* --- «ИИ Промты»: облако коротких промтов под карточками ---------------------- */

/* Второй заголовок страницы после карточек: «Подробные промты» и «Короткие промты».
   У ``panel-title`` размер заголовка страницы, и повторять его дважды внутри страницы
   значило бы спорить с ним за внимание; здесь — подпись над списком. */
.prompt-sub {
  margin: 24px 0 8px;
  color: var(--strong);
  font-size: 15px;
  font-weight: 600;
}
/* Облако — не сетка карточек, а строка-полоса пилюль: короткие промты коротки, и
   каждая пилюля читается как кнопка-вопрос. Строка переносится, поэтому на телефоне
   она сама становится столбцом — отдельного правила для этого не нужно. */
.prompt-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cloud-item {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--fg);
  background: var(--card);
  font-size: 13px;
  text-decoration: none;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.cloud-item:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}
/* Строка облака при исчерпанном лимите: это уже не ссылка, а ``<span>`` — нажимать
   нечего, и ``cursor`` об этом честно говорит. */
.cloud-item.is-off { opacity: .55; cursor: not-allowed; }
.cloud-item.is-off:hover {
  color: var(--fg);
  background: var(--card);
  border-color: var(--line);
}
/* Текст промта на карточке: в промте есть абзацы и нумерованные шаги, и без
   ``pre-wrap`` они слиплись бы в один абзац — тогда «прочитать, что уедет» не выйдет. */
.prompt-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .lib-grid { grid-template-columns: 1fr; }
  .prompt-sub { margin-top: 18px; }
}

/* Правила автоматизации: строка = поле + «×». Flex, а не grid: правил бывает и одно,
   и двадцать, и тянуться они должны так же, как остальные пары «поле + кнопка». */
.rule-rows { display: flex; flex-direction: column; gap: 8px; }
.rule-row { display: flex; gap: 8px; align-items: center; }
.rule-row input { flex: 1 1 auto; }
/* --- админка ----------------------------------------------------------------- */
/* Меню трёх страниц: одна из них текущая, поэтому «таб» — это span, а не ссылка,
   которую нельзя нажать (ссылка на себя читается как «раздел не работает»). */
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

.admin-tab {
  padding: 8px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  font-size: 14px;
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
}

.admin-tab.is-current {
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 600;
}

/* Форма создания: поля одной высоты, кнопка в конце ряда — как в остальных формах. */
.admin-new label { min-width: 0; }
.admin-new input[type=text], .admin-new select, .admin-new input.num { height: 38px; }
.admin-new input[name=password] { min-width: 180px; }

.admin-name { font-weight: 600; }

/* Поля внутри строки узкие: имя поля не должно раздвигать таблицу, из-за которой
   появлялась горизонтальная прокрутка. «0» в поле лимита читается и в 64 пикселях,
   а пароль человек всё равно видит в поле ввода. */
table.admin-list input.num { width: 64px; }
table.admin-list input.pw { width: 128px; }
table.admin-list button { padding: 0 10px; }
table.admin-list form { gap: 4px; }
table.admin-list .admin-cell { display: flex; flex-direction: column; gap: 4px; }
table.admin-list .admin-scopes { display: flex; flex-direction: column; gap: 2px; }

/* Периоды и даты на странице «Расход»: два ряда, а не один длинный. */
.admin-dates { margin-top: 4px; }
.admin-dates input[type=date] { height: 34px; }
