/* Atlas — базовые стили и компоненты пульта. Значения только из tokens.css. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: var(--leading);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-shadow);
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  stroke-width: 1.75;
}

.icon-sm {
  width: 14px;
  height: 14px;
}

.muted {
  color: var(--text-muted);
}

strong,
b {
  font-weight: var(--weight-medium);
}

.num {
  text-align: right;
  white-space: nowrap;
}

/* ---------- Каркас: сайдбар + рабочая область островом ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3);
  overflow-y: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--nav-item-height);
  padding: 0 var(--space-2);
  margin-bottom: var(--space-3);
  font-weight: var(--weight-medium);
}

.sidebar__group {
  margin: var(--space-4) var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--nav-item-height);
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: background var(--motion-fast) var(--ease-standard);
}

.nav-item:hover {
  background: var(--nav-hover);
  color: var(--text);
}

.nav-item[aria-current="page"] {
  background: var(--nav-active);
  color: var(--text);
}

.sidebar__user {
  position: relative;
  margin-top: auto;
}

.sidebar__user summary {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  list-style: none;
}

.sidebar__user summary::-webkit-details-marker {
  display: none;
}

.sidebar__user summary:hover {
  background: var(--nav-hover);
}

.avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-xs);
  background: var(--accent-tint);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: var(--shell-inset) var(--shell-inset) var(--shell-inset) 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.workspace__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--header-height);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.workspace__head h1 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
}

.workspace__spacer {
  flex: 1;
}

.workspace__body {
  flex: 1;
  overflow: auto;
  padding: var(--space-2);
}

/* Панель справа появляется, только когда в #aside есть содержимое. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
}

.split:has(> .split__aside:not(:empty)) {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

.split__list {
  min-width: 0;
  padding: var(--space-2);
  overflow: auto;
}

.split__aside {
  border-left: 1px solid var(--border);
  overflow: auto;
}

.split__aside:empty {
  display: none;
}

.workspace__body--flush {
  padding: 0;
  overflow: hidden;
}

/* ---------- Кнопки и поля ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-standard);
}

.btn:hover {
  background: var(--surface-2);
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.btn--primary:hover {
  background: var(--accent-strong);
}

.btn--ghost {
  border-color: transparent;
}

.btn--danger {
  color: var(--err);
}

.btn[disabled],
.btn.htmx-request {
  opacity: 0.56;
  cursor: progress;
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  transition: color var(--motion-field) var(--ease-emphasized);
}

.field:focus-within .field__label {
  color: var(--text);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.field__error {
  font-size: var(--text-xs);
  color: var(--err);
}

.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  font-size: var(--text-md);
  /* Мягкий фокус: кольцо вырастает из нуля, рамка и подпись темнеют вместе с ним. */
  box-shadow: 0 0 0 0 transparent;
  transition:
    border-color var(--motion-field) var(--ease-emphasized),
    box-shadow var(--motion-field) var(--ease-emphasized);
}

.textarea {
  height: auto;
  min-height: 88px;
  padding: var(--space-2) var(--space-3);
  resize: vertical;
}

@media (hover: hover) and (pointer: fine) {
  :is(.input, .select, .textarea):hover {
    border-color: var(--border-strong);
  }
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.input[aria-invalid="true"] {
  border-color: var(--err);
}

.form {
  display: grid;
  gap: var(--space-4);
  max-width: 480px;
  padding: var(--space-3);
}

.form__actions {
  display: flex;
  gap: var(--space-2);
}

/* ---------- Таблица как часть рабочей области (как в Linear) ---------- */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}

.table th {
  height: var(--band-height);
  padding: 0 var(--space-3);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  white-space: nowrap;
}

.table td {
  height: var(--row-height);
  padding: 0 var(--space-3);
  white-space: nowrap;
}

/* Длинный текст (значение, норма, тема письма, ошибка) переносится, а не раздвигает таблицу шире острова. */
.table td.cell-wrap {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Значение одной строкой с многоточием; полное — в title. */
.cell-clip {
  display: block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table tbody tr:not(.table__band):hover td {
  background: var(--row-hover);
}

.table tbody tr[aria-selected="true"] td {
  background: var(--row-selected);
}

.table td:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.table td:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.table__band td {
  height: var(--band-height);
  background: var(--band);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  white-space: normal;
  padding-block: var(--space-1);
}

.table__band td.num {
  white-space: nowrap;
}

.table__link {
  cursor: pointer;
}

/* ---------- Статусы, источники, бейджи ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.chip .icon {
  width: 13px;
  height: 13px;
}

/* Обычное состояние тихим текстом: подложка только у того, что требует внимания. */
.chip--ok,
.chip--off {
  padding: 0;
}

.chip--ok {
  color: var(--text-secondary);
}

.chip--ok .icon {
  color: var(--ok);
}

.chip--off {
  color: var(--text-muted);
}

.chip--run {
  background: var(--run-bg);
  color: var(--run);
}

.chip--need {
  background: var(--need-bg);
  color: var(--need);
}

.chip--err {
  background: var(--err-bg);
  color: var(--err);
}

/* В колонке значки и слова стоят на одной линии: подложка выступает влево. */
.table td > :is(.chip--run, .chip--need, .chip--err) {
  margin-left: calc(-1 * var(--space-2));
}

.source {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-medium);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--src, var(--icon-muted));
}

.method {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.method .icon {
  width: 15px;
  height: 15px;
}

/* ---------- Подпись главного числа ---------- */

.kpi__label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---------- Правая панель подробностей ---------- */

.panel__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--header-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  font-weight: var(--weight-medium);
}

.panel__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-4);
}

.props {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0;
  font-size: var(--text-sm);
}

.props dt {
  color: var(--text-muted);
}

.props dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.log {
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.log__line--warn {
  color: var(--need);
}

.log__line--error {
  color: var(--err);
}

/* ---------- Пустое состояние, тосты, вход ---------- */

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: 48px var(--space-4);
  color: var(--text-muted);
  text-align: center;
}

.toasts {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  display: grid;
  gap: var(--space-2);
  width: min(360px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  font-size: var(--text-sm);
  animation: toast-in var(--motion-control) var(--ease-emphasized);
}

.toast--err .icon {
  color: var(--err);
}

.toast--ok .icon {
  color: var(--ok);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.auth__card {
  width: min(360px, calc(100vw - 32px));
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.auth__card h1 {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.auth__card .form {
  padding: 0;
}

/* ---------- Узкий экран: сайдбар становится рельсом ---------- */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
  }

  .sidebar__label,
  .sidebar__group {
    display: none;
  }

  .split,
  .split:has(> .split__aside:not(:empty)) {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: max-content;
    overflow: auto;
  }

  .split__aside {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}

/* ---------- Дополнения пульта (те же токены) ---------- */

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.src-ppr {
  --src: var(--src-ppr);
}

.src-platon {
  --src: var(--src-platon);
}

.src-onec {
  --src: var(--src-onec);
}

.src-avtodor {
  --src: var(--src-avtodor);
}

.src-transmanager {
  --src: var(--src-transmanager);
}

.src-axenta {
  --src: var(--src-axenta);
}

.src-statement {
  --src: var(--src-statement);
}

.link:hover {
  text-decoration: underline;
}

.htmx-indicator {
  opacity: 0;
  transition: opacity var(--motion-control) var(--ease-standard);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Сайдбар: кнопка «свернуть», точка источника на месте значка, меню пользователя */

.sidebar__logo {
  display: grid;
  place-items: center;
}

.sidebar__toggle {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--icon-muted);
  cursor: pointer;
}

.sidebar__toggle:hover {
  background: var(--nav-hover);
  color: var(--text);
}

.sidebar__toggle .icon-rail,
[data-rail="on"] .sidebar__toggle .icon-wide {
  display: none;
}

[data-rail="on"] .sidebar__toggle .icon-rail {
  display: block;
}

a.sidebar__group:hover {
  color: var(--text);
}

.nav-item {
  position: relative;
}

.nav-item .icon {
  color: var(--icon-muted);
}

.nav-item:hover .icon,
.nav-item[aria-current="page"] .icon {
  color: var(--text);
}

.nav-item__dot {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: none;
}

.sidebar__user summary small {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.menu {
  position: absolute;
  bottom: calc(100% + var(--space-1));
  left: 0;
  z-index: var(--z-popover);
  display: grid;
  gap: 2px;
  min-width: 216px;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
}

.menu__head {
  padding: var(--space-2) var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: var(--nav-item-height);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.menu__item:hover {
  background: var(--nav-hover);
}

.menu__item--danger {
  color: var(--err);
}

.menu__check {
  margin-left: auto;
  visibility: hidden;
}

.menu__item[aria-checked="true"] .menu__check {
  visibility: visible;
}

.menu__sep {
  height: 1px;
  margin: var(--space-1) 0;
  background: var(--border);
}

/* Рельс: кнопкой на широком экране (cookie atlas_rail) */

[data-rail="on"] .shell {
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
}

[data-rail="on"] :is(.sidebar__label, .sidebar__group, .sidebar__logo) {
  display: none;
}

[data-rail="on"] :is(.nav-item, .sidebar__brand, .sidebar__user summary) {
  justify-content: center;
  padding: 0;
}

[data-rail="on"] .sidebar__toggle {
  margin: 0;
}

/* Шапка экрана: фильтры и действия */

.workspace__head form {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.workspace__head .select,
.workspace__head .input {
  width: auto;
  height: 28px;
  font-size: var(--text-sm);
}

.workspace__head .icon {
  color: var(--icon-muted);
}

.workspace__note {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.btn--sm {
  height: 28px;
  padding: 0 10px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--icon-muted);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inline-form .select,
.inline-form .input {
  width: auto;
  height: 28px;
  font-size: var(--text-sm);
}

/* Блоки внутри острова: заголовок тихим текстом, без своих карточек */

.block + .block {
  margin-top: var(--space-4);
}

.block__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.block__title .btn {
  margin-left: auto;
}

.note {
  max-width: 640px;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  /* Длинный путь или адрес без пробелов переносится по символам. */
  overflow-wrap: anywhere;
}

.form-error {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs);
  background: var(--err-bg);
  color: var(--err);
  font-size: var(--text-sm);
}

/* Своя деталь пульта: пунктир у всего, что открывает расчёт или исходный файл. */
.cell-link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted var(--border-strong);
  text-underline-offset: 3px;
}

.cell-link:hover {
  text-decoration: underline solid currentcolor;
}

.kpi__delta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.text-ok {
  color: var(--ok);
}

.text-err {
  color: var(--err);
}

.text-need {
  color: var(--need);
}

/* Обзор: главное число слева, показатели тихими строками по группам */

.overview-top {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.overview-side {
  display: grid;
  gap: var(--space-2);
}

.stats {
  padding: 0 var(--space-3);
  columns: 240px;
  column-gap: var(--space-6);
}

.stats__group {
  display: grid;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  break-inside: avoid;
}

.stats__group .panel__list li > span:first-child {
  color: var(--text-secondary);
}

.stats__delta {
  flex: none;
  width: 44px;
  text-align: right;
}

.summary {
  display: grid;
  align-content: start;
  gap: 2px;
}

.summary__row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--row-height);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.summary__row:hover {
  background: var(--row-hover);
}

.summary__value {
  margin-left: auto;
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

/* Правая панель */

.panel__head h2 {
  margin: 0;
  overflow: hidden;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Заголовок панели получает фокус программно после подмены (доступность), кольцо у некликабельного текста — шум. */
.panel__head h2:focus-visible {
  box-shadow: none;
}

.panel__section {
  display: grid;
  gap: var(--space-2);
}

/* Расшифровка показателя: итог крупно, строки группами (клиент, АЗС, участок, контрагент) или слагаемые с долей. */
.drill-hero {
  display: grid;
  gap: var(--space-1);
}

.drill-hero b {
  font-size: var(--text-xl);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}

.drill-hero span {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.drill-list {
  display: grid;
  gap: 2px;
  margin: 0 calc(-1 * var(--space-2));
  font-size: var(--text-sm);
}

.drill-group {
  display: grid;
  gap: 2px;
}

.drill-group + .drill-group {
  margin-top: var(--space-3);
}

.drill-group__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin: 0;
  padding: 6px var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.drill-group__head > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.drill-group__meta {
  flex: none;
  color: var(--text-secondary);
  font-weight: var(--weight-regular);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.drill-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 2px var(--space-3);
  padding: 6px var(--space-2);
  border-radius: var(--radius-xs);
  color: inherit;
  text-decoration: none;
}

a.drill-row:hover {
  background: var(--row-hover);
}

.drill-row__main {
  display: grid;
  min-width: 0;
}

.drill-row__main small {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.drill-row__num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.drill-bar {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  height: 4px;
  margin-top: 2px;
  border-radius: 2px;
  background: var(--viz-track);
}

.drill-bar__plus {
  fill: var(--viz-1);
}

.drill-bar__minus {
  fill: var(--viz-muted);
}

.panel__section-title {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
}

.panel__list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.panel__list li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 28px;
}

.panel__list .num {
  margin-left: auto;
}

/* Вкладки-таблетки без дорожки */

.tabs {
  display: flex;
  gap: var(--space-1);
}

.tab {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.tab:hover {
  background: var(--surface-2);
}

.tab[aria-current="page"] {
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  color: var(--text);
}

/* Тосты: ошибка закрывается крестиком */

.toast__close {
  margin-left: auto;
}

.toast a {
  text-decoration: underline;
}

/* ---------- Панель «Загрузить файл»: три шага и кнопка у нижнего края ---------- */

.icon--flip {
  transform: scaleX(-1);
}

.split__aside:has(> .panel__body--fill) {
  display: flex;
  flex-direction: column;
}

.split__aside:has(> .panel__body--fill) > .panel__head {
  flex: none;
}

.panel__body--fill {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.upload {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-4);
}

.upload .input {
  height: 36px;
}

.steps {
  display: grid;
  gap: var(--space-6);
  margin: 0 0 var(--space-6);
  padding: 0;
  list-style: none;
}

.step {
  display: grid;
  gap: var(--space-3);
}

.step__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.step__num {
  display: grid;
  flex: none;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--accent-tint);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

/* Тело шага начинается на линии текста заголовка: 20 (номер) + 8 (зазор). */
.step__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2);
  min-width: 0;
  padding-left: 28px;
}

@media (max-width: 540px) {
  .upload .input {
    /* iOS: не увеличивать экран при фокусе. */
    font-size: 16px;
  }
}

.up-account {
  margin-top: var(--space-2);
}

.up-account__one {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.up-account__one span {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

.upload__footer {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  margin: auto calc(-1 * var(--space-4)) calc(-1 * var(--space-4));
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.upload__submit {
  width: 100%;
  height: 36px;
  font-size: var(--text-md);
  touch-action: manipulation;
  transition:
    background var(--motion-fast) var(--ease-standard),
    transform var(--motion-control) var(--ease-standard);
}

.upload__submit:active {
  transform: scale(0.98);
}

/* ---------- Выбор из списка по образцу Bits UI Select ---------- */

.lselect {
  position: relative;
}

.lselect__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  height: 36px;
  padding: 0 var(--space-2) 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
  font-size: var(--text-md);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 0 0 0 transparent;
  transition:
    border-color var(--motion-field) var(--ease-emphasized),
    box-shadow var(--motion-field) var(--ease-emphasized);
}

@media (hover: hover) and (pointer: fine) {
  .lselect__trigger:hover {
    border-color: var(--border-strong);
  }
}

.lselect__trigger:focus-visible,
.lselect[data-open] .lselect__trigger {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.lselect__trigger[aria-invalid="true"] {
  border-color: var(--err);
}

.lselect__value {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.lselect__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lselect__text.is-placeholder {
  color: var(--text-muted);
}

.lselect__chevron {
  width: 16px;
  height: 16px;
  color: var(--icon-muted);
  transform: rotate(90deg);
  transition: transform var(--motion-control) var(--ease-standard);
}

.lselect[data-open] .lselect__chevron {
  transform: rotate(-90deg);
}

/* Список выезжает от кнопки: 4 px и 0,98 → на место; закрывается быстрее, чем открывается. */
.lselect__content {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  left: 0;
  z-index: var(--z-popover);
  max-height: min(320px, 50vh);
  padding: var(--space-1);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top center;
  transition:
    opacity var(--motion-fast) var(--ease-standard),
    transform var(--motion-fast) var(--ease-standard),
    visibility 0s linear var(--motion-fast);
}

.lselect__content[data-side="top"] {
  top: auto;
  bottom: calc(100% + var(--space-1));
  transform: translateY(4px) scale(0.98);
  transform-origin: bottom center;
}

.lselect__content[data-state="open"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition:
    opacity var(--motion-control) var(--ease-emphasized),
    transform var(--motion-control) var(--ease-emphasized),
    visibility 0s;
}

.lselect__group + .lselect__group {
  margin-top: var(--space-1);
  padding-top: var(--space-1);
  border-top: 1px solid var(--border);
}

.lselect__group-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 28px;
  padding: 0 var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.lselect__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--nav-item-height);
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  font-size: var(--text-sm);
  cursor: pointer;
}

/* Пункты группы — на линии текста заголовка группы: 8 + точка 8 + зазор 8. */
.lselect__group .lselect__item {
  padding-left: var(--space-6);
}

.lselect__item[data-highlighted] {
  background: var(--nav-hover);
}

.lselect__label {
  flex: 1;
  min-width: 0;
}

.lselect__check {
  width: 16px;
  height: 16px;
  visibility: hidden;
}

.lselect__item[aria-selected="true"] .lselect__check {
  visibility: visible;
}

/* ---------- Месяц стрелками ---------- */

.mperiod {
  display: grid;
  gap: var(--space-2);
}

.mperiod__bar {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
}

.mperiod__title {
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  text-align: center;
}

.mperiod__step {
  display: grid;
  place-items: center;
  justify-self: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--icon-muted);
  cursor: pointer;
  transition:
    background var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard),
    transform var(--motion-control) var(--ease-standard);
}

.mperiod__step .icon {
  width: 16px;
  height: 16px;
}

@media (hover: hover) and (pointer: fine) {
  .mperiod__step:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }
}

.mperiod__step:active:not(:disabled) {
  transform: scale(0.94);
}

.mperiod__step:focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.mperiod__step:disabled {
  opacity: 0.4;
  cursor: default;
}

.mperiod__custom > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: fit-content;
  min-height: 24px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  list-style: none;
  cursor: pointer;
}

.mperiod__custom > summary::-webkit-details-marker {
  display: none;
}

.mperiod__custom > summary:focus-visible {
  outline: 1px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.mperiod__more {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--text-secondary);
  transition: color var(--motion-fast) var(--ease-standard);
}

.mperiod__more::before {
  margin-right: var(--space-2);
  color: var(--text-muted);
  content: "·";
}

.mperiod__custom > summary:hover .mperiod__more {
  color: var(--text);
}

.mperiod__more-icon {
  width: 14px;
  height: 14px;
  transform: rotate(90deg);
  transition: transform var(--motion-control) var(--ease-standard);
}

.mperiod__custom[open] .mperiod__more-icon {
  transform: rotate(-90deg);
}

.mperiod__fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.mperiod__fields .field {
  min-width: 0;
}

@media (max-width: 540px) {
  .mperiod__fields {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Зона файла ---------- */

.drop {
  position: relative;
  display: grid;
  gap: var(--space-2);
}

/* Настоящий выбор файла: невидим, но в фокусе с клавиатуры и в форме (required). */
.drop__input {
  position: absolute;
  top: 24px;
  left: 50%;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop__zone {
  display: grid;
  justify-items: center;
  gap: var(--space-1);
  padding: var(--space-5) var(--space-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  text-align: center;
  cursor: pointer;
  transition:
    border-color var(--motion-field) var(--ease-emphasized),
    background var(--motion-field) var(--ease-emphasized),
    box-shadow var(--motion-field) var(--ease-emphasized);
}

@media (hover: hover) and (pointer: fine) {
  .drop__zone:hover {
    border-color: var(--text-muted);
    background: var(--surface-2);
  }
}

.drop__input:focus-visible + .drop__zone {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.drop__input[aria-invalid="true"] + .drop__zone {
  border-color: var(--err);
}

.drop[data-dragging] .drop__zone {
  border-style: solid;
  border-color: var(--text-secondary);
  background: var(--accent-tint);
}

.drop__icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: var(--space-1);
  border-radius: var(--radius-sm);
  background: var(--accent-tint);
  color: var(--text-secondary);
  transition: transform var(--motion-control) var(--ease-emphasized);
}

.drop__icon .icon {
  width: 16px;
  height: 16px;
}

.drop[data-dragging] .drop__icon {
  transform: translateY(-2px);
}

.drop__title {
  font-size: var(--text-sm);
}

.drop__link {
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}

.drop__hint {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.drop__file {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  transition:
    opacity var(--motion-control) var(--ease-emphasized),
    transform var(--motion-control) var(--ease-emphasized),
    box-shadow var(--motion-field) var(--ease-emphasized);
}

@starting-style {
  .drop__file {
    opacity: 0;
    transform: translateY(4px);
  }
}

.drop__input:focus-visible ~ .drop__file {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.drop__file-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent-tint);
  color: var(--text-secondary);
}

.drop__file-icon .icon {
  width: 16px;
  height: 16px;
}

.drop__meta {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.drop__name {
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop__size {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.drop__size.is-error {
  color: var(--err);
}

.drop__replace {
  flex: none;
}

.drop__clear {
  flex: none;
  margin-left: 0;
}

.upload.htmx-request :is(.drop__replace, .drop__clear) {
  visibility: hidden;
}

/* Прогресс отправки — тонкая линия по нижнему краю карточки файла. */
.drop__progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  border: 0;
  background: transparent;
  appearance: none;
}

.drop__progress::-webkit-progress-bar {
  background: transparent;
}

.drop__progress::-webkit-progress-value {
  background: var(--accent);
}

.drop__progress::-moz-progress-bar {
  background: var(--accent);
}

.up-template {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.up-template .icon {
  width: 16px;
  height: 16px;
  color: var(--icon-muted);
}

.up-template__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
  color: var(--text);
  font-weight: var(--weight-medium);
}

.up-template__link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.empty__title {
  color: var(--text);
  font-weight: var(--weight-medium);
}

/* Финальный отчёт: итог, мост, столбики по месяцам, вкладки */

.rb {
  container-type: inline-size;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-2);
}

.rb-wide {
  overflow-x: auto;
}

.rb-top {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(360px, 1fr) minmax(300px, 380px);
  gap: var(--space-4);
  align-items: start;
}

.rb-multi {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

/* Столбики по месяцам — фон для моста: подпись и цвет тише, акцент только у итога в мосте. */
.rb-multi .block__title {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
}

.hero {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: 10px;
  background: var(--surface-2);
}

.hero__value {
  font-size: var(--text-2xl);
  line-height: 1.1;
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.hero__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.hero__row b {
  font-weight: var(--weight-medium);
  color: var(--text);
  white-space: nowrap;
}

.bridge {
  display: grid;
  gap: 2px;
}

.bridge__row {
  display: grid;
  grid-template-columns: 148px minmax(40px, 1fr) 96px;
  align-items: center;
  gap: var(--space-2);
  height: 28px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  font-size: var(--text-sm);
}

a.bridge__row:hover {
  background: var(--row-hover);
}

.bridge__row--total {
  font-weight: var(--weight-medium);
}

.bridge__row--hidden {
  grid-template-columns: minmax(0, 1fr);
  color: var(--text-muted);
}

.bridge__track {
  display: block;
  width: 100%;
  height: 16px;
}

.bridge__bar {
  fill: var(--viz-muted);
}

.bridge__bar--total {
  fill: var(--text-secondary);
}

.bridge__bar--final {
  fill: var(--viz-1);
}

.bridge__bar--neg {
  fill: var(--viz-neg);
}

.bridge__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.spark {
  display: flex;
  gap: var(--space-3);
  padding: 0 var(--space-3);
}

.spark__col {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.spark__text {
  font-size: var(--text-xs);
  fill: var(--text-secondary);
}

.spark__col.is-now .spark__text {
  fill: var(--text);
  font-weight: var(--weight-medium);
}

.spark__plot {
  display: block;
  width: 100%;
  height: 58px;
  overflow: visible;
}

.spark__bar {
  fill: var(--viz-muted);
}

.spark__col.is-now .spark__bar {
  fill: var(--text-secondary);
}

.spark__bar--neg,
.spark__col.is-now .spark__bar--neg {
  fill: var(--viz-neg);
}

.spark__zero {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.spark__label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: 0 var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend svg {
  width: 10px;
  height: 10px;
}

.stack {
  display: block;
  width: 100%;
  min-width: 220px;
  height: 16px;
}

.stack rect {
  stroke: var(--surface);
  stroke-width: 2;
}

.viz-fuel {
  fill: var(--viz-1);
}

.viz-pay {
  fill: var(--viz-2);
}

.viz-other {
  fill: var(--viz-3);
}

.viz-rest {
  fill: var(--viz-track);
}

.dbar {
  display: block;
  width: 160px;
  height: 16px;
}

.dbar__zero {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.dbar__up {
  fill: var(--viz-1);
}

.dbar__down {
  fill: var(--viz-neg);
}

.tabs--body {
  padding: var(--space-2) var(--space-1);
}

.table th.num,
.table td.num {
  text-align: right;
}

.table td small {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
}

.table tr.row-strong td {
  font-weight: var(--weight-medium);
}

.table td.cell-now {
  background: var(--row-selected);
}

.summary__row--static {
  height: auto;
  min-height: var(--row-height);
  padding-top: var(--space-1);
  padding-bottom: var(--space-1);
  cursor: default;
}

.summary__row--static:hover {
  background: none;
}

.summary__text {
  min-width: 0;
}

.summary__text small {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.empty-inline {
  padding: var(--space-4) var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.panel__value {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
}

.panel__note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.panel__list li.is-total {
  font-weight: var(--weight-medium);
}

.panel__list--text li {
  align-items: flex-start;
}

.panel__list small {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.month-reopen {
  display: grid;
  gap: var(--space-2);
}

.month-changes {
  margin-top: var(--space-2);
}

.month-changes summary {
  padding: var(--space-1) 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.panel__list li.month-change {
  display: grid;
  gap: 2px;
  padding: var(--space-1) 0;
}

.month-change__nums {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.month-change__nums strong {
  margin-left: auto;
  font-weight: var(--weight-medium);
}

.rb-note {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--need-bg);
  color: var(--need);
  font-size: var(--text-sm);
  text-decoration: none;
}

.rb-note:hover {
  text-decoration: underline;
}

.viz-tip {
  position: fixed;
  z-index: var(--z-popover);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  font-size: var(--text-xs);
  pointer-events: none;
  /* Подсказка графика — несколько строк через \n: месяц, выручка, результат. */
  white-space: pre;
  font-variant-numeric: tabular-nums;
}

/* Обзор: доска «мост и машины». Цвет только у результата (--viz-1) и у отклонений. */

.board {
  display: grid;
  gap: var(--space-6);
}

.board section {
  min-width: 0;
}

.board-tiles {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.board-tile {
  display: grid;
  align-content: start;
  gap: var(--space-1);
  min-width: 0;
  padding: var(--space-4) var(--space-5);
  border-left: 1px solid var(--border);
}

.board-tile:first-child {
  border-left: 0;
}

.board-tile .kpi__label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.board-tile__value {
  justify-self: start;
  font-size: 26px;
  line-height: 1.15;
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.board-tile__meta {
  display: grid;
  gap: 2px;
}

.board-key {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--viz-1);
}

.board__pair {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: var(--space-6);
}

/* Мост: столбцы в растянутом SVG позади колонок; суммы — строкой сверху, названия — снизу. */
.wfv {
  position: relative;
  display: flex;
  height: 236px;
  margin-top: var(--space-2);
}

.wfv__svg {
  position: absolute;
  top: 28px;
  left: 0;
  width: 100%;
  height: 176px;
  overflow: visible;
  pointer-events: none;
}

.wfv__col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: var(--radius-xs);
  color: inherit;
  text-decoration: none;
}

a.wfv__col:hover {
  background: var(--row-hover);
}

.wfv__zero {
  stroke: var(--border-strong);
}

.wfv__link {
  stroke: var(--border-strong);
  stroke-dasharray: 3 3;
}

.wfv__bar {
  fill: var(--viz-muted);
}

.wfv__bar--total {
  fill: var(--text-secondary);
}

.wfv__bar--result {
  fill: var(--viz-1);
}

.wfv__bar--neg {
  fill: var(--viz-neg);
}

.wfv__value,
.wfv__label {
  padding: var(--space-1) 2px;
  font-size: var(--text-xs);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wfv__value {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.wfv__value--empty {
  color: var(--text-muted);
}

.wfv__label {
  color: var(--text-secondary);
}

.wfv__col--total .wfv__value,
.wfv__col--result .wfv__value,
.wfv__col--result .wfv__label {
  color: var(--text);
  font-weight: var(--weight-medium);
}

.wfh {
  display: none;
  gap: 2px;
}

.wfh__row {
  display: grid;
  grid-template-columns: 96px minmax(24px, 1fr) 72px;
  align-items: center;
  gap: var(--space-2);
  height: 28px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  color: inherit;
  font-size: var(--text-sm);
  text-decoration: none;
}

a.wfh__row:hover {
  background: var(--row-hover);
}

.wfh__row--total,
.wfh__row--result {
  font-weight: var(--weight-medium);
}

.wfh__track {
  display: block;
  width: 100%;
  height: 14px;
}

.wfh__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Тренд: подписи шкалы | растянутый SVG | подписи концов линий; месяцы — под SVG. */
.trend {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 96px;
  grid-template-rows: 200px auto;
  margin-top: var(--space-5);
}

.trend__ticks {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: -8px 0;
  padding-right: var(--space-2);
  font-size: 11px;
  line-height: 16px;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.trend__svg,
.trend__ends {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}

.trend__grid {
  stroke: var(--viz-track);
}

.trend__grid--zero {
  stroke: var(--border-strong);
}

.trend__hit {
  fill: transparent;
}

.trend__hit:hover {
  fill: var(--row-hover);
}

.trend__area,
.trend__line,
.trend__dot {
  pointer-events: none;
}

.trend__area {
  fill: var(--viz-1);
  fill-opacity: 0.08;
}

.trend__line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.trend__line--rev,
.trend__dot--rev {
  stroke: var(--viz-muted);
}

.trend__line--res,
.trend__dot--res {
  stroke: var(--viz-1);
}

.trend__line--partial {
  stroke-dasharray: 4 4;
}

.trend__dot {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
}

.trend__dot.is-now {
  stroke-width: 9;
}

.trend__ends text {
  font-size: 12px;
  fill: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.trend__end-value {
  fill: var(--text);
  font-weight: var(--weight-medium);
}

/* Месяцы по точкам: крайние подписи центрированы на краях графика. */
.trend__months {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  margin: 0 -20px;
  padding-top: var(--space-2);
}

.trend__months span {
  width: 40px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.trend__months span.is-now {
  color: var(--text);
  font-weight: var(--weight-medium);
}

.legend__line {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  background: var(--viz-muted);
}

.legend__line--res {
  background: var(--viz-1);
}

.legend__line--partial {
  background: repeating-linear-gradient(90deg, var(--text-muted) 0 4px, transparent 4px 7px);
}

/* Машины: полоса результата от общего нуля, расход к среднему по парку, результат по месяцам. */
.trk-bar-cell {
  width: 32%;
  min-width: 140px;
}

.trk-bar,
.trk-bar svg {
  display: block;
  width: 100%;
  height: 12px;
  overflow: visible;
}

.trk-bar__zero,
.fdev__mid {
  stroke: var(--border-strong);
}

.trk-bar__fill {
  fill: var(--viz-1);
}

.trk-bar__fill--neg {
  fill: var(--viz-neg);
}

.fdev {
  display: inline-grid;
  grid-template-columns: 72px auto;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.fdev__track {
  display: block;
  width: 72px;
  height: 10px;
  overflow: visible;
}

.fdev__fill {
  fill: var(--viz-muted);
}

.fdev__fill--over {
  fill: var(--need);
}

.tspark {
  display: block;
  width: 112px;
  height: 24px;
}

.tspark svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.tspark__line {
  fill: none;
  stroke: var(--viz-muted);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.tspark__zero {
  stroke: var(--border-strong);
  stroke-dasharray: 2 2;
}

.tspark__dot {
  fill: none;
  stroke: var(--viz-1);
  stroke-width: 6;
  stroke-linecap: round;
}

.tspark__dot--neg {
  stroke: var(--viz-neg);
}

/* Строка статуса: плашки ведут в сверки и «Состояние». Подложка — только у того, что требует внимания. */
.board-status {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  text-decoration: none;
  white-space: nowrap;
}

a.pill:hover {
  background: var(--row-hover);
}

.pill b {
  color: var(--text);
  font-weight: var(--weight-medium);
}

.pill .icon {
  width: 16px;
  height: 16px;
  color: var(--icon-muted);
}

.pill--need {
  border-color: transparent;
  background: var(--need-bg);
  color: var(--need);
}

.pill--err {
  border-color: transparent;
  background: var(--err-bg);
  color: var(--err);
}

.pill--need b,
.pill--need .icon,
.pill--err b,
.pill--err .icon {
  color: inherit;
}

.board-more {
  border-top: 1px solid var(--border);
  padding-top: var(--space-2);
}

.board-more > summary {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
}

.board-more[open] > summary {
  margin-bottom: var(--space-2);
}

/* Ширина блока, а не окна: открытая панель забирает место у отчёта */
@container (max-width: 1040px) {
  .rb-top {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  }

  .rb-top > :last-child {
    grid-column: 1 / -1;
  }

  .board__pair {
    grid-template-columns: minmax(0, 1fr);
  }

  .board-tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board-tile:nth-child(4) {
    border-left: 0;
  }

  .board-tile:nth-child(n + 4) {
    border-top: 1px solid var(--border);
  }
}

@container (max-width: 640px) {
  .rb-top,
  .rb-multi,
  .overview-top {
    grid-template-columns: minmax(0, 1fr);
  }

  .bridge__row {
    grid-template-columns: 120px minmax(24px, 1fr) 84px;
  }

  .board-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-tile:nth-child(n) {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .board-tile:nth-child(even) {
    border-left: 1px solid var(--border);
  }

  .board-tile:nth-child(-n + 2) {
    border-top: 0;
  }

  .board-tile__value {
    font-size: var(--text-xl);
  }

  .wfv {
    display: none;
  }

  .wfh {
    display: grid;
  }

  /* Машины на узком: номер, полоса и сумма; маржа, расход и месяцы — в «Все показатели» и расшифровке. */
  .trucks :is(th, td):nth-child(n + 4) {
    display: none;
  }

  .trucks .trk-bar-cell {
    width: auto;
    min-width: 48px;
  }

  .trucks__model {
    display: none;
  }

  .board-tile:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .trend {
    grid-template-columns: 32px minmax(0, 1fr) 80px;
  }
}

/* Файлы: дерево папок слева от списка */

/* Строка сетки — по высоте экрана: длинный список и панель прокручиваются внутри, а не вылезают за край. */
.tree-split {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.tree {
  padding: var(--space-2);
  border-right: 1px solid var(--border);
  overflow: auto;
}

.tree__title {
  margin: var(--space-3) var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.tree__title:first-child {
  margin-top: var(--space-1);
}

.tree__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--nav-item-height);
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.tree__item:hover {
  background: var(--nav-hover);
  color: var(--text);
}

.tree__item[aria-current="true"] {
  background: var(--nav-active);
  color: var(--text);
}

.tree__item .icon {
  color: var(--icon-muted);
}

/* Подпапка источника: значок под точкой источника, имя не переносится. */
.tree__item--sub {
  padding-left: calc(var(--space-2) + 20px);
}

.tree__item--add,
.tree__item--add .icon {
  color: var(--text-muted);
}

.tree__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree__count {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.crumbs b {
  color: var(--text);
  font-weight: var(--weight-medium);
}

.crumbs .icon {
  width: 13px;
  height: 13px;
}

.file-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.file-name .icon {
  width: 15px;
  height: 15px;
  color: var(--icon-muted);
}

.icon-link {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  color: var(--icon-muted);
}

.icon-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-link .icon {
  width: 15px;
  height: 15px;
}

@media (max-width: 900px) {
  .tree-split {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .tree {
    max-height: 200px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

.empty p {
  max-width: 420px;
  margin: 0;
}

@media (max-width: 900px) {
  :is(.nav-item, .sidebar__brand, .sidebar__user summary) {
    justify-content: center;
    padding: 0;
  }

  /* Ниже 900 px рельс всегда, поэтому вместо кнопки «свернуть» — логотип. */
  :root .sidebar__brand .sidebar__logo {
    display: grid;
  }

  .sidebar__toggle {
    display: none;
  }
}
