/* Оболочка сервиса. Токены и облик — 1:1 с эталоном вида
   prototypes/ct2-ui-v2/styles.css (§0 SPEC_prototype_screen_inventory).
   Сборка новая: здесь только то, что нужно каркасу, плюс адаптив —
   в эталоне его не было, а сервис обязан читаться с телефона. */

:root {
  --navy-950: #061a2f;
  --navy-900: #09233e;
  --navy-800: #103654;
  --blue-600: #1467e8;
  --blue-700: #0f56c6;
  --blue-50: #edf5ff;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #172033;
  --muted: #667085;
  --muted-2: #98a2b3;
  --border: #dfe4eb;
  --border-strong: #c9d1dc;
  --green: #16865c;
  --green-bg: #eaf8f1;
  --red: #cc3a3a;
  --red-bg: #fff0f0;
  --orange: #b95f12;
  --orange-bg: #fff4e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --sidebar-w: 224px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font: 13px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- каркас: боковая навигация + рабочая область ---------- */

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

.sidebar {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  color: #d8e3ef;
  background: var(--navy-950);
  border-right: 1px solid #142f49;
}
.brand {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--blue-600);
  border-radius: 8px;
  font-size: 18px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.brand strong { display: block; color: #fff; letter-spacing: .08em; font-size: 15px; }
.brand span { color: #7f97ae; font-size: 10px; }

.workspace { padding: 14px 12px 10px; }
.workspace > span, .nav-separator span {
  display: block;
  margin: 0 7px 6px;
  color: #6f879e;
  letter-spacing: .08em;
  font-size: 9px;
  font-weight: 700;
}
.workspace .tenant-card {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: #d9e5f0;
  text-align: left;
  background: var(--navy-900);
  border: 1px solid #1e3b56;
  border-radius: 7px;
}
.workspace .tenant-card b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.market-dot { width: 8px; height: 8px; background: #28a978; border-radius: 50%; }
.market-dot.off { background: #7c8ea1; }

#nav { min-height: 0; overflow-y: auto; padding: 2px 9px 10px; }
.nav-item {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  margin: 2px 0;
  padding: 0 10px 0 6px;
  color: #aebfd0;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .055); }
.nav-item.active { color: #fff; background: var(--blue-600); }
.nav-item i { font-style: normal; text-align: center; font-weight: 700; }
.nav-item b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.nav-item em {
  min-width: 19px;
  padding: 1px 5px;
  color: #a9bfd3;
  text-align: center;
  background: #153653;
  border-radius: 10px;
  font-size: 10px;
  font-style: normal;
}
.nav-item.active em { color: #fff; background: rgba(4, 37, 83, .35); }
.nav-separator { padding-top: 15px; }

.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid rgba(255, 255, 255, .08); }
.sync-state { display: flex; align-items: center; gap: 8px; padding: 5px 8px 10px; color: #7890a6; font-size: 10px; }
.sync-state i { width: 7px; height: 7px; background: #36b37e; border-radius: 50%; flex: none; }
.sync-state i.stale { background: #e99a3a; }
.sync-state i.off { background: #7c8ea1; }
.sync-state b { color: #a9bbcc; font-weight: 500; }

.workspace-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.topbar {
  min-height: 68px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.crumbs { margin-bottom: 2px; color: var(--muted-2); font-size: 10px; }
.crumbs span { padding: 0 4px; }
.crumbs b { color: var(--muted); font-weight: 500; }
.topbar h1 { margin: 0; font-size: 19px; line-height: 1.2; letter-spacing: -.02em; }
.top-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.data-age { color: var(--muted); font-size: 11px; }
.data-age b { color: var(--text); font-weight: 600; }

.icon-button, .primary-button, .secondary-button { height: 34px; border-radius: 6px; }
.icon-button {
  width: 34px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
}
.primary-button {
  padding: 0 13px;
  color: #fff;
  background: var(--blue-600);
  border: 1px solid var(--blue-600);
  font-weight: 650;
}
.primary-button:hover { background: var(--blue-700); }
.secondary-button {
  padding: 0 11px;
  color: #344054;
  background: var(--surface);
  border: 1px solid var(--border-strong);
}
.secondary-button:hover { background: #f4f6f8; }
.danger-button { color: var(--red); border-color: #eab6b6; }
.danger-button:hover { background: var(--red-bg); }

/* Кнопка открытия навигации — видна только на узком экране. */
.nav-toggle { display: none; }
.scrim { display: none; }

#content { min-height: 0; overflow: auto; padding: 18px 22px 28px; outline: none; }
.page { max-width: 1560px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; }
.page-head h2 { margin: 0 0 3px; font-size: 16px; }
.page-head p { margin: 0; color: var(--muted); font-size: 11px; }

/* ---------- панели, таблицы, значки ---------- */

.panel, .data-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.data-panel { overflow: hidden; }
.panel-head {
  min-height: 46px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { margin: 0; font-size: 12px; }
.panel-head span { color: var(--muted); font-size: 10px; }
.panel-body { padding: 13px 14px; }
.panel + .panel, .data-panel + .data-panel, .panel + .data-panel, .data-panel + .panel { margin-top: 12px; }

/* Широкая таблица прокручивается внутри своей рамки: страница по
   горизонтали не едет ни на каком экране. */
.table-scroll { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 11px; }
th {
  height: 34px;
  padding: 7px 10px;
  color: #536174;
  text-align: left;
  white-space: nowrap;
  background: #f3f6f9;
  border-bottom: 1px solid var(--border-strong);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .025em;
  text-transform: uppercase;
}
td { height: 35px; padding: 7px 10px; white-space: nowrap; background: #fff; border-bottom: 1px solid #e6eaf0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f7faff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.primary { color: #194a83; font-weight: 650; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 10px; font-size: 9px; font-weight: 650; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--green); background: var(--green-bg); }
.badge.red { color: var(--red); background: var(--red-bg); }
.badge.orange { color: var(--orange); background: var(--orange-bg); }
.badge.gray { color: #667085; background: #eef1f4; }

.empty-callout { padding: 35px 20px; color: var(--muted); text-align: center; }
.state-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 11px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 8px;
  font-size: 13px;
}
.state-note.error { border-left-color: var(--red); background: var(--red-bg); }
.state-note.ok { border-left-color: var(--green); background: var(--green-bg); }
.state-note.empty { color: var(--muted); border-left-color: var(--border-strong); background: var(--surface-2); }

/* ---------- формы (экран «Кабинеты») ---------- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field span { color: var(--muted); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select {
  min-width: 0;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: 0;
  font-size: 12px;
}
.field input:focus, .field select:focus { border-color: var(--blue-600); }
.field small { color: var(--muted-2); font-size: 10px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.cabinet-card + .cabinet-card { margin-top: 12px; }
.cabinet-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cabinet-head b { font-size: 13px; }
.cabinet-head .grow { flex: 1 1 auto; min-width: 0; }

/* ---------- экран «Цены»: сбор и фильтры ---------- */

/* Поля тянутся и переносятся: на 375px они встают в столбец, страница
   по горизонтали не едет — едет только сама таблица внутри рамки. */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.filters .field { flex: 1 1 150px; }
.counter { padding-bottom: 9px; color: var(--muted); white-space: nowrap; font-size: 11px; }
.inline-field { flex: 1 1 150px; }
.panel-head .inline-field span { margin-bottom: 1px; }

/* ---------- экран «Себестоимость»: загрузка файлом, правка, история ---------- */

/* Поле выбора файла живёт по правилам остальных полей формы, только выше:
   имя файла в одну строку высотой 36px не помещается. */
.field input[type="file"] { height: auto; padding: 7px 8px; font-size: 11px; }

/* Кнопки строки таблицы не растягивают колонку и не рвутся по буквам. */
.row-actions { display: flex; gap: 6px; }
.row-actions .secondary-button { height: 28px; padding: 0 9px; font-size: 10px; }

/* Список причин отказа: заголовок сверху, причины столбиком — так он читается
   и на 375px, где строка «строка 4, колонка …» в одну линию не влезает. */
.problems-note { flex-direction: column; align-items: flex-start; gap: 4px; }
.problems { margin: 0; padding-left: 18px; font-size: 12px; }
.problems li { margin-top: 3px; }

/* ---------- экран «Юнитка»: лист владельца как есть ---------- */

/* Переключатель WB / Ozon (эталон §14). Выбор запоминается браузером. */
.switcher { display: inline-flex; padding: 2px; background: #eef1f5; border: 1px solid var(--border); border-radius: 8px; }
.switch-button { height: 28px; padding: 0 14px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; font-size: 11px; font-weight: 650; }
.switch-button.active { color: var(--text); background: #fff; box-shadow: var(--shadow); }

/* Полоса причин неполноты: почему в витрине есть пустые места. */
/* Причин бывает много (у каждой колонки своя). Полоса не растёт на весь
   экран: выше трёх строк она прокручивается, и таблица остаётся видна. */
.unit-notes { display: flex; flex-wrap: wrap; gap: 6px; max-height: 86px; overflow-y: auto; margin-bottom: 10px; }
.unit-notes:empty { display: none; }
.unit-notes .badge { max-width: 100%; white-space: normal; text-align: left; }

/* Ширины колонок задаются на <col>, поэтому раскладка фиксированная: ручной
   размер обязан держаться, а не пересчитываться по содержимому. Ширина
   таблицы — по сумме колонок: лист едет по горизонтали внутри своей рамки. */
.unit-table { table-layout: fixed; width: max-content; min-width: 100%; }
.unit-table th, .unit-table td { position: relative; overflow: hidden; text-overflow: ellipsis; }
.unit-table th.unit-group { height: auto; padding-bottom: 3px; color: var(--muted-2); white-space: normal; border-bottom: 0; }
.unit-table thead tr:last-child th { height: auto; padding-top: 3px; white-space: normal; vertical-align: bottom; }

/* Первая колонка закреплена: на 375px строка не теряется при перемотке. */
.unit-table th:first-child, .unit-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  box-shadow: 1px 0 0 var(--border);
}
/* Фон у закреплённой ячейки задан обеим — и шапке, и строке. Опираться на
   общий стиль таблицы здесь нельзя: сквозь прозрачную закреплённую ячейку
   при горизонтальной перемотке едет остальная таблица. */
.unit-table thead th:first-child { z-index: 3; background: #f3f6f9; }
.unit-table td:first-child { background: #fff; }
.unit-table tbody tr:hover td:first-child { background: #f7faff; }

/* Число и пропуск нажимаются: по клику приходит след. Кнопка выглядит как
   обычная ячейка — лист от этого не меняется. */
.cell-trace { max-width: 100%; padding: 0; color: inherit; background: none; border: 0; font: inherit; text-align: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-trace:hover, .cell-trace:focus-visible { color: var(--blue-700); text-decoration: underline; }
.cell-trace.missing { color: var(--muted-2); font-style: italic; }

/* Ручки размера: правый край заголовка — ширина, нижний край первой ячейки —
   высота. Как в Sheets; двойной клик возвращает размер по умолчанию. */
.col-grip { position: absolute; top: 0; right: 0; width: 7px; height: 100%; cursor: col-resize; touch-action: none; }
.col-grip:hover { background: var(--blue-600); }
.row-grip { position: absolute; left: 0; bottom: 0; width: 100%; height: 5px; cursor: row-resize; touch-action: none; }
.row-grip:hover { background: var(--blue-600); }

/* Карточка следа: формула словами, подстановка, период, источник. */
.trace-card { margin-bottom: 12px; }
.trace-body { display: flex; flex-direction: column; gap: 4px; }
.trace-value { font-size: 18px; font-weight: 700; }
.trace-value.missing { color: var(--muted); font-size: 14px; font-style: italic; }
.trace-line { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* ---------- экран входа ---------- */

.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(380px, 100%); padding: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.gate-card h1 { margin: 0 0 4px; font-size: 18px; }
.gate-card p { margin: 0 0 16px; color: var(--muted); font-size: 12px; }

/* ---------- адаптив ---------- */

/* Планшет: колонка навигации уже, отступы меньше. */
@media (max-width: 1100px) {
  :root { --sidebar-w: 198px; }
  #content { padding: 16px 16px 24px; }
  .topbar { padding: 10px 16px; }
}

/* Телефон (проверяется на 375px): навигация уезжает в выдвижную панель,
   рабочая область занимает всю ширину, ничего не выходит за экран. */
@media (max-width: 720px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 30;
    width: min(280px, 86vw);
    height: 100%;
    transform: translateX(-100%);
    transition: transform .18s ease-out;
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .app-shell.nav-open .scrim {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(6, 26, 47, .45);
    border: 0;
  }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { min-height: 58px; padding: 10px 14px; }
  .topbar h1 { font-size: 17px; }
  #content { padding: 14px 14px 22px; }
  .page-head { align-items: flex-start; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters .field, .inline-field { flex: 1 1 100%; }
  .filters .primary-button, .panel-head .primary-button { flex: 1 1 auto; }
  .top-actions { width: 100%; }
  .top-actions .primary-button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
