/* Общая оболочка и компоненты кабинета. Источник дизайна: docs/analytics-cabinet/mockup/*.html.
   Inter не подключается: макет его тоже не грузит, владелец видел системный шрифт. */
:root {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #222;
  background: #f5f5f5;
  --orange: #ff6900;
  --orange-text: #9c3d00;
  --peach: #fff6ed;
  --line: #e8e8e8;
  --muted: #626262;
  --green: #116649;
  --soft: #edf2f5;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-size: 14px; background: #f5f5f5; color: #222; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 8px; }
h1 { font-size: 32px; letter-spacing: -1px; }
h2 { font-size: 18px; letter-spacing: -.25px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; line-height: 1.4; }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 6px 0; padding-left: 20px; line-height: 1.4; }
small, .muted { color: var(--muted); font-size: 12px; }
small { display: block; }
strong, b, th { font-weight: 650; }
a { color: var(--orange-text); }
button, input, select, textarea { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
summary:focus-visible { outline: 2px solid #222; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Шапка ---- */
.wrap { max-width: 1480px; margin: auto; padding: 0 32px; }
.header { background: #fff; border-bottom: 1px solid var(--line); }
.top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 19px; min-height: 62px; }
.logo { display: flex; align-items: center; gap: 11px; font-weight: 700; white-space: nowrap; color: #222; text-decoration: none; }
.logo svg { display: block; }
.logo span { border-left: 1px solid var(--line); padding-left: 10px; }
.top .meta { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.meta form { margin: 0; }
.tag { display: inline-block; padding: 5px 9px; border-radius: 999px; background: var(--soft); font-size: 11px; font-weight: 650; }
.nav { display: flex; gap: 7px; overflow: auto; padding-bottom: 11px; }
.nav a { white-space: nowrap; border-radius: 999px; background: #f5f5f5; padding: 8px 14px; color: #333; text-decoration: none; }
.nav a:hover { background: #ebebeb; }
.nav a.on { background: var(--orange); color: #222; font-weight: 700; }
main.wrap { padding-top: 22px; padding-bottom: 30px; }

/* ---- Раскладка ---- */
.heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.heading h1 { margin: 0; }
.heading p { margin: 4px 0 0; color: var(--muted); }
.cols { display: grid; gap: 14px; }
.cols.a { grid-template-columns: minmax(0, 1fr) 310px; align-items: start; }
.stack { display: grid; gap: 13px; align-content: start; min-width: 0; }
.stack > .panel, .rail > .panel { margin: 0; }
.rail { display: grid; gap: 12px; min-width: 0; }

/* ---- Панели и показатели ---- */
.panel, .metric { background: #fff; border: 1px solid var(--line); border-radius: 16px; min-width: 0; }
.panel { padding: 15px 16px; margin: 0 0 14px; }
.panelhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.panelhead h2, .panelhead h3 { margin: 0; }
.panelhead h3 { font-size: 18px; letter-spacing: -.25px; }
.group .panel { margin-bottom: 0; }
.group h2 { font-size: 20px; margin: 0; }
.group .sub { margin: 3px 0 9px; }
.group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.group + .group { margin-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.metric { padding: 11px 12px; }
.metric .label { margin: 0; color: #505050; font-size: 12px; font-weight: 400; letter-spacing: 0; }
.metric strong { display: block; font-size: 23px; letter-spacing: -.7px; white-space: nowrap; margin: 4px 0 2px; }
.metric small { font-size: 11px; }
.metric .report-basis { margin-top: 4px; }
.metric.online .label::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #12815a; margin-right: 6px; }
.period-panel { margin-top: 9px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.number { font-size: 26px; font-weight: 650; letter-spacing: -.7px; }

/* ---- Чипы, теги, примечания ---- */
.chip { display: inline-block; border: 0; border-radius: 7px; padding: 5px 8px; font-size: 12px; font-weight: 600; background: #f0f0f0; color: #333; }
.chip.warning, .warning { background: var(--peach); color: #812f00; }
.chip.softred, .softred, .error { background: #fceae7; color: #922f25; }
.chip.good, .good { background: #e6f9f1; color: var(--green); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
/* Блочные сообщения (p.warning, details.warning, p.error) */
p.warning, details.warning, p.error { padding: 9px 12px; border: 1px solid #ffdfc7; border-radius: 10px; }
p.error { border-color: #f3c9c3; }
.report-basis { display: inline-block; padding: 2px 8px; border: 1px solid #ddd; border-radius: 7px; color: var(--muted); font-size: 11px; }
.action { color: var(--orange-text); font-size: 12px; font-weight: 650; text-decoration: none; }

/* ---- Сводка ИИ ---- */
.digest { background: var(--peach); border-color: #ffe2cd; }
.digest h2 span { color: var(--orange-text); }
.digest .line { border-top: 1px solid #f4dfcf; padding: 9px 0; }
.digest .panelhead + .line { border-top: 0; padding-top: 0; }
.digest .line small { margin-top: 3px; }
.digest .line ul { margin: 0; }
.digest form { margin-top: 8px; display: flex; align-items: center; gap: 8px; }

/* ---- Требует внимания ---- */
.attention .row { display: grid; grid-template-columns: 124px minmax(0, 1fr) auto; gap: 3px 10px; align-items: center; border-bottom: 1px solid #eee; padding: 7px 0; font-size: 13px; }
.attention .row:last-child { border-bottom: 0; padding-bottom: 0; }
.attention .row strong { display: block; }
.attention .row small { margin-top: 2px; }
.attention .row .chip { justify-self: start; white-space: nowrap; }
.attention .row > .more { grid-column: 1 / -1; }
.attention .row form.more { display: flex; align-items: flex-end; gap: 8px; margin: 0; }
.attention .row form.more textarea { margin: 0; flex: 1; }
.attention .row details summary { cursor: pointer; color: var(--orange-text); font-size: 12px; font-weight: 650; }
.attention .row details > * { margin-top: 6px; }
.attention .row textarea { display: block; width: min(100%, 28rem); margin-bottom: 8px; }
.attention .row ul { margin: 4px 0 0; }
.attention .state { margin: 0; padding: 3px 0; }

/* ---- Период и вкладки показателей ---- */
.dates { display: flex; justify-content: flex-start; gap: 6px; align-items: center; flex-wrap: wrap; }
.dates button, .dates input, .dates select { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.dates button { cursor: pointer; }
.dates button:hover { background: #fafafa; }
.dates button.go { background: var(--orange); border-color: var(--orange); font-weight: 700; }
.dates label { font-size: 11px; color: #505050; display: flex; flex-direction: row; align-items: center; gap: 4px; }
.group-head .dates { justify-content: flex-end; }
.group-head #cabinet-freshness { margin: 5px 0 0; text-align: right; font-size: 11px; }
.group-head .warning { margin-top: 6px; }
.group-head details.warning { font-size: 12px; text-align: left; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; padding: 0; border: 0; min-width: 0; }
.tabs button { background: #f5f5f5; border: 0; padding: 6px 9px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.tabs button:hover { background: #ebebeb; }
.tabs [aria-pressed="true"] { background: var(--orange); font-weight: 700; }
.chart .panelhead { margin-bottom: 3px; }
.chart .report-chart { height: 164px !important; } /* перебивает inline-высоту общего отчёта: в макете график низкий */
.chart-note { display: block; min-height: 18px; }

/* ---- Таблицы ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px; border-bottom: 1px solid #efefef; font-variant-numeric: tabular-nums; vertical-align: top; }
th { font-size: 11px; color: #555; }
tr:last-child td { border-bottom: 0; }
.scroll, .table-wrap { overflow: auto; }

/* ---- Формы и кнопки ---- */
button, .button { display: inline-block; cursor: pointer; padding: 6px 12px; border: 1px solid #ddd; border-radius: 8px; background: #fff; color: #222; text-decoration: none; font-weight: 600; }
button:hover, .button:hover { background: #fafafa; }
button:disabled { cursor: default; opacity: .6; }
.go, button.go { border: 0; background: var(--orange); font-weight: 700; color: #222; }
.go:hover, button.go:hover { background: #f26200; }
input, select, textarea { padding: 7px 9px; border: 1px solid #ddd; border-radius: 9px; background: #fff; color: #222; max-width: 100%; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 3px; }
form.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
form.filters.dates { gap: 6px; align-items: center; }
form p { margin: 0 0 10px; }
meter { width: 100%; }
details summary { cursor: pointer; }
.htmx-indicator { display: none; font-size: 12px; color: var(--muted); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* ---- ИИ-помощник (общий для вкладок) ---- */
.chat { min-width: 0; }
.chat article { border-top: 1px solid var(--line); padding-top: 9px; margin-top: 9px; overflow-wrap: anywhere; }
.chat article p { font-size: 13px; line-height: 1.4; }
.chat article:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.chat .askline { background: #f5f5f5; border-radius: 10px; padding: 9px; margin: 9px 0; }
.chat [data-ai-answer] { white-space: pre-wrap; }
.chat form { display: flex; align-items: flex-end; gap: 6px; margin: 9px 0 0; }
.chat form label { flex: 1; min-width: 0; }
.chat textarea { width: 100%; min-width: 0; padding: 8px; border-radius: 9px; }
.chat form button { align-self: flex-end; }
.chat #ai-history { max-height: 360px; overflow: auto; }
.chat [data-ai-error] { margin-top: 8px; }

/* ---- Узкие экраны ---- */
@media (min-width: 1360px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .wrap { padding-inline: 20px; } }
@media (max-width: 970px) {
  .cols.a { grid-template-columns: 1fr; }
  .rail { grid-template-columns: 1fr 1fr; align-items: start; }
}
@media (max-width: 820px) { .top .meta small { display: none; } }
@media (max-width: 780px) {
  .group-head { display: block; }
  .group-head .dates { justify-content: flex-start; }
  .group-head #cabinet-freshness { text-align: left; margin-bottom: 8px; }
}
@media (max-width: 590px) {
  .wrap { padding-inline: 12px; }
  .heading { align-items: flex-start; flex-direction: column; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .metric strong { font-size: 20px; }
  .rail { grid-template-columns: 1fr; }
  .attention .row { grid-template-columns: 1fr; }
  .group-head { flex-wrap: wrap; }
  .logo { gap: 6px; }
  .logo svg { width: 65px; }
  .logo span { padding-left: 6px; }
  .top { gap: 6px 8px; }
  .top .meta { gap: 8px; }
}
