/* Панель оператора нейроофиса. Без внешних шрифтов и библиотек. Все цвета — переменные ниже. */

:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e1e4e9;
  --border-strong: #c7ccd4;
  --text: #1b1f24;
  --text-2: #3d4450;
  --muted: #59616e;

  --accent: #2a5aa6;
  --accent-hover: #224b8c;
  --accent-soft: #e8eff9;
  --on-accent: #ffffff;

  --red: #b42318;
  --red-soft: #fdeeec;
  --red-line: #efbcb6;
  --red-mark: #d92d20;
  --on-red: #ffffff;
  --amber: #85510a;
  --amber-soft: #fff5df;
  --amber-line: #ead29c;
  --amber-mark: #dd9f1c;
  --green: #1d7337;
  --green-soft: #e8f4eb;
  --green-line: #b6dbc1;
  --green-mark: #2f9e57;
  --gray-soft: #eef0f3;
  --gray-line: #d5d9df;
  --gray-mark: #98a0ab;
  --info: #2a5aa6;
  --info-soft: #e8eff9;
  --info-line: #bccfee;

  --focus: #2a5aa6;
  --backdrop: rgb(15 18 24 / 0.5);
  --radius: 8px;
  --topbar-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111317;
    --surface: #1a1d22;
    --surface-2: #20242a;
    --border: #2d323a;
    --border-strong: #434a55;
    --text: #e7e9ec;
    --text-2: #c3c8cf;
    --muted: #9da5af;

    --accent: #7ca6ee;
    --accent-hover: #9abbf3;
    --accent-soft: #1c2a42;
    --on-accent: #0b1424;

    --red: #ff9d93;
    --red-soft: #381d1b;
    --red-line: #6b2d27;
    --red-mark: #f47066;
    --on-red: #2a0d0a;
    --amber: #f1c46c;
    --amber-soft: #322811;
    --amber-line: #625020;
    --amber-mark: #e9b54a;
    --green: #88d7a2;
    --green-soft: #152e1e;
    --green-line: #2a5739;
    --green-mark: #4fb877;
    --gray-soft: #262a31;
    --gray-line: #3b414a;
    --gray-mark: #6f7883;
    --info: #7ca6ee;
    --info-soft: #1c2a42;
    --info-line: #34507e;

    --focus: #9abbf3;
    --backdrop: rgb(0 0 0 / 0.65);
  }
}

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  overflow-wrap: break-word;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
p { margin: 0 0 8px; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button { font: inherit; }
.mono { font-family: var(--mono); font-size: 13px; }
.t .mono { white-space: nowrap !important; }
.muted { color: var(--muted); }
.neg { color: var(--red); }
.pos { color: var(--green); }
.na { color: var(--muted); font-size: 13px; white-space: nowrap; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  padding: 8px 12px; background: var(--surface); color: var(--accent);
  border: 1px solid var(--border-strong); border-radius: 6px;
}
.skip-link:focus { top: 8px; }
.noscript { padding: 24px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text);
  font-weight: 500; line-height: 1.2; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn-danger { color: var(--red); border-color: var(--red-line); }
.btn-danger:hover { background: var(--red-soft); color: var(--red); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-quiet:hover { background: var(--surface-2); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-link {
  border: 0; background: none; padding: 0; margin: 0;
  color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
  cursor: pointer; font-size: inherit;
}
.btn-link:hover { color: var(--accent-hover); }

/* ---------- Каркас ---------- */
.app {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) auto;
  min-height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1 1 auto; }
.menu-btn { display: none; flex: none; }
.mock-tag {
  flex: none; font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  color: var(--amber); background: var(--amber-soft); border: 1px solid var(--amber-line);
  padding: 1px 6px; border-radius: 4px;
}

.sidenav {
  position: sticky; top: var(--topbar-h); align-self: start;
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 12px 8px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-foot { margin: 16px 4px 0; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.nav-foot:empty { display: none; }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1;
}
.badge-red { background: var(--red-mark); color: var(--on-red); }
.badge-red-soft { background: var(--red-soft); color: var(--red); border: 1px solid var(--red-line); }
.badge-accent { background: var(--accent); color: var(--on-accent); }

.main { padding: 24px 28px 56px; min-width: 0; width: 100%; max-width: 1320px; }
.main:focus { outline: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 0 12px; gap: 8px; }
  .menu-btn { display: inline-flex; }
  .sidenav {
    display: none;
    position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 25;
    height: auto; max-height: calc(100vh - var(--topbar-h));
    border-right: 0; border-bottom: 1px solid var(--border-strong);
  }
  .sidenav.open { display: block; }
  .main { padding: 16px 16px 48px; }
}
@media (max-width: 420px) {
  .brand-name { font-size: 15px; }
  .topbar .btn-sm { padding: 4px 8px; }
}

/* ---------- Заголовок экрана и источники ---------- */
.screen-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 4px 24px; margin-bottom: 10px;
}
.screen-head h1 { font-size: 24px; font-weight: 700; }
.screen-head h1:focus { outline: none; }
.screen-head h1:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.subtitle { margin: 4px 0 0; color: var(--text-2); }
.owner { margin: 0; color: var(--muted); font-size: 14px; }
.owner strong { color: var(--text); font-weight: 600; }

.sources {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px;
  margin: 0 0 20px; font-size: 13px; color: var(--muted);
}
.sources-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.src-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.src {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; min-width: 0;
  padding: 3px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
}
.src-name { color: var(--text); font-weight: 500; }
.src-time { white-space: nowrap; }
.src-note::before { content: "· "; }
.src.stale { border-color: var(--amber-line); background: var(--amber-soft); }
.src.stale .src-time { color: var(--amber); }

/* ---------- Блоки ---------- */
.block { margin: 0 0 28px; }
.block-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 4px 16px; margin-bottom: 10px;
}
.block h2 { font-size: 17px; font-weight: 650; }
.block > h2 { margin-bottom: 10px; }
.block-note { margin: 0; color: var(--muted); font-size: 13px; }
.count {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 10px;
  background: var(--gray-soft); color: var(--text-2);
  font-size: 13px; font-weight: 600; vertical-align: 2px; font-variant-numeric: tabular-nums;
}
.empty {
  margin: 0; padding: 14px 16px;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-2);
}
.loading { color: var(--muted); padding: 24px 0; }
.error-box {
  padding: 20px; background: var(--surface); border: 1px solid var(--red-line);
  border-left: 4px solid var(--red-mark); border-radius: var(--radius);
}
.error-box h1 { font-size: 20px; margin-bottom: 8px; }
.error-box h1:focus { outline: none; }
.notice {
  margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}
.notice.tone-amber { border-color: var(--amber-line); background: var(--amber-soft); }
.notice.tone-red { border-color: var(--red-line); background: var(--red-soft); }
.notice.tone-green { border-color: var(--green-line); background: var(--green-soft); }
[id^="a-"] { scroll-margin-top: calc(var(--topbar-h) + 12px); }
[id^="a-"]:focus { outline: none; }
.is-target { outline: 2px solid var(--accent) !important; outline-offset: 4px; border-radius: var(--radius); }

/* ---------- Плитки ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 12px; }
@media (min-width: 1100px) { .kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.kpi {
  min-width: 0; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.kpi-label { font-size: 13px; color: var(--muted); line-height: 1.3; }
.kpi-value {
  margin-top: 4px; font-size: 24px; font-weight: 700; line-height: 1.2;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.kpi-value .na { font-size: 15px; font-weight: 500; }
.kpi-sub { margin-top: 4px; font-size: 13px; color: var(--text-2); line-height: 1.35; }
.kpi-delta { margin-top: 4px; font-size: 13px; }
.kpi.tone-red { border-color: var(--red-line); }
.kpi.tone-red .kpi-value { color: var(--red); }
.kpi.tone-amber { border-color: var(--amber-line); }
.kpi.tone-amber .kpi-value { color: var(--amber); }
.kpi.tone-green .kpi-value { color: var(--green); }

/* ---------- Строка состояния на «Сегодня» ---------- */
.status-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 12px; margin-bottom: 16px; }
.status-card {
  display: flex; align-items: flex-start; gap: 10px; min-width: 0;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); text-decoration: none;
}
.status-card:hover { border-color: var(--border-strong); color: var(--text); }
.status-card.tone-red { border-color: var(--red-line); background: var(--red-soft); }
.status-card.tone-amber { border-color: var(--amber-line); background: var(--amber-soft); }
.status-label { display: block; font-weight: 600; }
.status-text { display: block; font-size: 14px; color: var(--text-2); }
.status-more { display: block; font-size: 13px; color: var(--accent); margin-top: 2px; }
.dot { flex: none; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--gray-mark); }
.dot-green { background: var(--green-mark); }
.dot-amber { background: var(--amber-mark); }
.dot-red { background: var(--red-mark); }
.dot-gray { background: var(--gray-mark); }
.dot-info { background: var(--accent); }

/* ---------- Подсказки ---------- */
.hints { display: grid; gap: 12px; }
.hint {
  min-width: 0; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--gray-mark);
  border-radius: var(--radius);
}
.hint-red { border-left-color: var(--red-mark); }
.hint-amber { border-left-color: var(--amber-mark); }
.hint-info { border-left-color: var(--accent); }
.hint-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 4px; }
.hint-area { font-size: 13px; color: var(--muted); }
.hint-title { font-size: 16px; font-weight: 650; margin: 2px 0 4px; }
.hint-detail { color: var(--text-2); }
.hint-dl {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 8px 20px; margin: 8px 0 10px;
}
.hint-dl dt, .ap-meta dt, .detail-dl dt, .calc-dl dt { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint-dl dd, .ap-meta dd, .detail-dl dd, .calc-dl dd { margin: 0; font-size: 14px; }
.hint-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Метки ---------- */
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 10px; border: 1px solid transparent;
  font-size: 12px; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.tag-red { background: var(--red-soft); color: var(--red); border-color: var(--red-line); }
.tag-amber { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }
.tag-green { background: var(--green-soft); color: var(--green); border-color: var(--green-line); }
.tag-gray { background: var(--gray-soft); color: var(--text-2); border-color: var(--gray-line); }
.tag-info { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }

/* ---------- Таблицы ---------- */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  container-type: inline-size;
}
.table-wrap:focus-visible { outline-offset: 0; }
.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.t th, .t td {
  padding: 8px 10px; text-align: left; vertical-align: top; white-space: nowrap;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.t thead th {
  background: var(--surface-2); color: var(--text-2);
  font-size: 12.5px; font-weight: 600; line-height: 1.3; vertical-align: bottom;
  white-space: normal; min-width: 64px;
}
.t tbody th { font-weight: 500; }
.t tbody tr:last-child > * { border-bottom: 0; }
.t .num { text-align: right; }
.t .wrap { white-space: normal; min-width: 180px; }
.t .wrap-sm { white-space: normal; min-width: 120px; }
.t .sticky-col { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--border); }
.t thead .sticky-col { z-index: 2; }
.t tr.row-red > * { background: var(--red-soft); }
.t tr.row-amber > * { background: var(--amber-soft); }
.t tr.group-row > * {
  background: var(--surface-2); font-size: 12.5px; font-weight: 650; color: var(--text-2);
  text-transform: none; padding-top: 6px; padding-bottom: 6px;
}
.t tfoot th, .t tfoot td { border-top: 1px solid var(--border-strong); border-bottom: 0; font-weight: 650; }
.t .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.t .sticky-col .sub, .t .wrap .sub { white-space: normal; }
@media (max-width: 600px) { .t tbody th.sticky-col { max-width: 140px; white-space: normal; } }
.t .sub.pos { color: var(--green); }
.t .sub.neg { color: var(--red); }
.t .sub .tag { margin-top: 2px; }
.t-compact th, .t-compact td { padding: 6px 10px; }
.t-foot { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }

.th-sort {
  display: inline-flex; align-items: flex-end; gap: 4px;
  padding: 0; margin: 0; border: 0; background: none;
  color: inherit; font: inherit; text-align: inherit; cursor: pointer;
}
.num .th-sort { flex-direction: row-reverse; text-align: right; }
.th-sort:hover { color: var(--text); }
.th-sort:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.sort-ind { display: inline-block; min-width: 8px; font-size: 10px; color: var(--accent); line-height: 1.6; }

.row-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0; margin: 0; border: 0; background: none; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.row-toggle:hover { color: var(--accent); }
.row-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.chev { display: inline-block; width: 10px; color: var(--muted); font-weight: 700; }
[aria-expanded="true"] > .chev { transform: rotate(90deg); }
.model-code { font-weight: 600; }
.t .tag + .tag { margin-left: 4px; }
.cell-tags { display: block; margin-top: 3px; }

.detail-row > td { background: var(--surface-2); white-space: normal; }
.detail-inner { position: sticky; left: 12px; max-width: calc(100cqw - 24px); }
.detail-dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 8px 20px; margin: 2px 0; }

/* ---------- Графики ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 12px; }
.chart {
  margin: 0; min-width: 0; padding: 12px 14px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.chart-title { font-size: 14px; font-weight: 600; margin: 0 0 10px; }
.chart-plot { position: relative; height: 140px; border-bottom: 1px solid var(--border-strong); }
.chart-plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-max {
  position: absolute; left: 0; top: calc(18% - 19px);
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none;
}
.chart-x { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart figcaption { margin-top: 6px; font-size: 13px; color: var(--text-2); }
.bar { fill: var(--accent); }
.bar-green { fill: var(--green-mark); }
.bar-na { fill: var(--gray-line); }
.bar-hit { fill: transparent; }
g:hover > .bar { fill: var(--accent-hover); }
g:hover > .bar-green { fill: var(--green); }
.grid-line { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }

/* ---------- Формы ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-help { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input:not([type]), select {
  width: 100%; min-width: 0; min-height: 38px; padding: 7px 10px;
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[aria-invalid="true"] { border-color: var(--red-mark); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); gap: 12px; margin: 12px 0; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.form-error { margin: 8px 0 0; color: var(--red); font-size: 14px; }
.form-msg { margin: 0; font-size: 14px; }
.form-msg.form-error { margin: 0; }
.checkbox { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.warn-box {
  margin: 12px 0 0; padding: 10px 12px;
  background: var(--amber-soft); border: 1px solid var(--amber-line); border-radius: var(--radius);
}
.warn-box p { color: var(--text); }
.ap-text { margin: 12px 0 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.ap-text summary { cursor: pointer; padding: 8px 12px; font-size: 14px; font-weight: 600; }
.ap-text-body { padding: 0 12px 12px; white-space: pre-wrap; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.pv-mode { margin: 12px 0 0; padding: 10px 12px; background: var(--accent-soft); border-radius: var(--radius); font-size: 14px; }

/* ---------- Сверка воронки ---------- */
.funnel { padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.funnel h3 { font-size: 15px; font-weight: 650; margin: 12px 0 8px; }
.funnel .table-wrap { margin: 8px 0; }

/* ---------- Окно ---------- */
.dlg-box {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto;
  padding: 0; border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.dlg-box::backdrop { background: var(--backdrop); }
.dlg { padding: 20px; }
.dlg-title { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
.dlg-body { color: var(--text-2); }
.dlg-body strong { color: var(--text); }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.pv-row { display: flex; gap: 8px; }
.pv-row input { flex: 1 1 auto; }
.pv-table { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.pv-table tbody th { white-space: normal; }
.pv-out { margin-top: 4px; }
.pv-out > p { margin-top: 10px; }

/* ---------- Согласования ---------- */
.ap-list { display: grid; gap: 12px; }
.ap {
  min-width: 0; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ap-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.ap-title { font-size: 17px; font-weight: 650; margin: 8px 0 6px; }
.ap-reason { color: var(--text-2); }
.ap-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 8px 20px; margin: 10px 0; }
.ap-preview { margin: 4px 0 0; padding-left: 18px; }
.ap-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ap-result { margin-top: 14px; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }
.ap-result.tone-green { background: var(--green-soft); border-color: var(--green-line); }
.ap-result.tone-red { background: var(--red-soft); border-color: var(--red-line); }
.ap-result.tone-gray { background: var(--gray-soft); border-color: var(--gray-line); }
.calc { margin-top: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }
.calc-title { font-size: 13px; font-weight: 650; margin: 0 0 6px; color: var(--text-2); }
.calc-dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 6px 16px; margin: 0; font-variant-numeric: tabular-nums; }
.calc-strong dd { font-weight: 700; }

/* ---------- Офис ---------- */
.health { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 10px; }
.hc {
  display: flex; gap: 10px; min-width: 0; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.hc.tone-red { background: var(--red-soft); border-color: var(--red-line); }
.hc.tone-amber { background: var(--amber-soft); border-color: var(--amber-line); }
.hc-label { font-weight: 600; }
.hc-status { font-size: 14px; color: var(--text-2); }
.hc-time { font-size: 12px; color: var(--muted); }
.meter { height: 8px; margin-top: 8px; border-radius: 4px; background: var(--gray-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--green-mark); }
.meter.tone-amber > span { background: var(--amber-mark); }
.meter.tone-red > span { background: var(--red-mark); }

/* ---------- Журнал ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 8px; }
.filters .field { flex: 1 1 200px; }
.filters .field-grow { flex: 3 1 260px; }
.j-day { font-size: 14px; font-weight: 650; color: var(--text-2); margin: 18px 0 6px; }
.j-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.j-item { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 2px 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.j-item:last-child { border-bottom: 0; }
.j-time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.j-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13px; color: var(--muted); }
.j-text { margin: 2px 0 0; overflow-wrap: anywhere; }

/* ---------- Что считается ---------- */
.about { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px; margin-top: 36px; }
.about-col { min-width: 0; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.about h2 { font-size: 14px; font-weight: 650; margin: 0 0 6px; }
.about ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--text-2); }
.about li + li { margin-top: 4px; }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .field { margin: 16px 0 4px; }
.login-card .btn-block { margin-top: 16px; }

/* ---------- Сообщение внизу ---------- */
.toast {
  position: fixed; left: 50%; bottom: 16px; z-index: 60;
  transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 8px;
  background: var(--text); color: var(--surface); font-size: 14px;
  opacity: 0; pointer-events: none;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast.toast-error { background: var(--red-soft); color: var(--red); border: 1px solid var(--red-line); }

/* ---------- Чат ---------- */
.main:has(#chat-root) { padding-bottom: 16px; }
.chat-note { margin-bottom: 12px; font-size: 14px; color: var(--text-2); }
.chat {
  display: grid; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  height: max(440px, calc(100vh - var(--topbar-h) - 200px));
  height: max(440px, calc(100dvh - var(--topbar-h) - 200px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.chat-side { min-width: 0; overflow-y: auto; padding: 12px; background: var(--surface-2); border-right: 1px solid var(--border); }
.chat-side-title { font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 2px 8px; }
.chat-side-title:not(:first-child) { margin-top: 16px; }
.agents { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.agent { min-width: 0; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.agent.is-paused { background: var(--gray-soft); }
.agent.is-paused .agent-name, .agent.is-paused .agent-role { color: var(--muted); }
.agent-head { display: flex; align-items: center; gap: 8px; }
.agent-head .dot { margin-top: 0; }
.agent-name { font-weight: 650; min-width: 0; }
.agent-head .tag { margin-left: auto; }
.agent-role { margin: 2px 0 8px; font-size: 13px; color: var(--text-2); }
.agent-note { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.agent-new[aria-current="page"] { border-color: var(--accent); color: var(--accent); }
.threads { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.threads > li { min-width: 0; }
.thread-link {
  display: block; min-width: 0; padding: 6px 8px; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
.thread-link:hover { background: var(--surface-2); color: var(--text); }
.thread-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.thread-title { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--muted); }
.thread-last {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 13px; color: var(--text-2);
}
.thread-none { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-main-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.chat-main-title { flex: 1 1 auto; min-width: 0; }
.chat-main-title h2 { font-size: 16px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-main-title h2:focus { outline: none; }
.chat-main-title h2:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.chat-main-title p { margin: 0; font-size: 13px; color: var(--muted); }
.chat-back { display: none; flex: none; }
.chat-msgs { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; }
.chat-msgs:focus-visible { outline-offset: -2px; }
.chat-empty { margin: auto; max-width: 480px; padding: 24px 8px; text-align: center; color: var(--text-2); }
.chat-empty-main { display: flex; flex-direction: column; justify-content: center; height: 100%; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.chip {
  padding: 6px 12px; border: 1px solid var(--info-line); border-radius: 16px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; text-align: left; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }

.msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: min(720px, 88%); }
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-agent { align-self: flex-start; align-items: flex-start; }
.bubble {
  min-width: 0; max-width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2); overflow-wrap: anywhere;
}
.msg-user .bubble { background: var(--accent-soft); border-color: var(--info-line); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg-agent .bubble { border-bottom-left-radius: 4px; }
.msg-agent.is-wait .bubble { color: var(--text-2); background: var(--surface); border-style: dashed; }
.msg-agent.is-failed .bubble { background: var(--red-soft); border-color: var(--red-line); color: var(--text); }
.msg-hint { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.timer { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.msg-author { margin: 0 4px 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.msg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 4px 4px 0; font-size: 12px; color: var(--muted); }
.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md ul { list-style: disc; }
.md ol { list-style: decimal; }
.md li + li { margin-top: 3px; }
.md > :last-child { margin-bottom: 0; }
.msg-approvals { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; width: 100%; }
.msg-ap {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px;
}
.msg-ap-title { flex: 1 1 160px; min-width: 0; }

.composer { flex: none; margin: 0; padding: 10px 14px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea {
  display: block; width: 100%; min-height: 72px; max-height: 40vh; resize: vertical; padding: 8px 10px;
  font: inherit; font-size: 15px; line-height: 1.45; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
}
.composer textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.composer textarea[aria-invalid="true"] { border-color: var(--red-mark); }
.composer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 8px; }
.composer-help { flex: 1 1 auto; margin: 0; font-size: 13px; color: var(--muted); }
.char-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.char-count.over { color: var(--red); font-weight: 600; }
.composer-note { margin: 6px 0 0; font-size: 13px; color: var(--amber); }
.composer-note:empty { display: none; }
.composer-note.is-error { color: var(--red); }
.composer-off { color: var(--muted); font-size: 14px; }

@media (max-width: 860px) {
  .chat {
    grid-template-columns: minmax(0, 1fr);
    height: max(420px, calc(100vh - var(--topbar-h) - 180px));
    height: max(420px, calc(100dvh - var(--topbar-h) - 180px));
  }
  .chat[data-view="list"] .chat-main { display: none; }
  .chat[data-view="thread"] .chat-side { display: none; }
  .chat-side { border-right: 0; }
  .chat-back { display: inline-flex; }
  .chat-msgs { padding: 12px; }
  .msg { max-width: 92%; }
  .composer { padding: 8px 10px 10px; }
  .composer textarea { min-height: 60px; }
}

@media print {
  .topbar, .sidenav, .hint-actions, .ap-actions, .toast { display: none !important; }
  .app { display: block; }
}
