/* ==========================================================================
   Юнит-экономика — оформление
   Один шрифт, три размера, нейтральная палитра, один акцентный цвет.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-sunken: #fafbfc;
  --text: #14161a;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e6e8ec;
  --line-strong: #d5d9e0;
  --field: #ffffff;
  --field-border: #d5d9e0;

  --accent: #2f6feb;
  --accent-hover: #245bc9;
  --accent-soft: rgba(47, 111, 235, 0.10);

  --danger: #c8352b;
  --danger-solid: #c8352b;
  --danger-soft: rgba(200, 53, 43, 0.09);
  --warn: #a35b06;
  --warn-soft: rgba(163, 91, 6, 0.10);

  --bar: #9aa3b2;
  --bar-track: #edeff3;

  --fs-1: 12px;    /* подписи, служебный текст */
  --fs-2: 13.5px;  /* основной текст, поля, значения */
  --fs-3: 25px;    /* крупные метрики */

  --radius: 8px;
  --radius-sm: 6px;
  --header-h: 52px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #16191f;
    --surface-sunken: #12151a;
    --text: #e7e9ee;
    --muted: #98a2b3;
    --faint: #79839a;
    --line: #242932;
    --line-strong: #313846;
    --field: #1b1f26;
    --field-border: #313846;

    --accent: #5b8cf5;
    --accent-hover: #7aa3f8;
    --accent-soft: rgba(91, 140, 245, 0.14);

    --danger: #f0776c;
    --danger-solid: #a8352b;
    --danger-soft: rgba(240, 119, 108, 0.13);
    --warn: #e0a458;
    --warn-soft: rgba(224, 164, 88, 0.13);

    --bar: #5d6779;
    --bar-track: #1f242c;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-2);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul { margin: 0; }
button { font: inherit; color: inherit; }

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Шапка и табы ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover:not(:disabled) { background: var(--bar-track); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tab:disabled { cursor: not-allowed; color: var(--faint); }

.tab-soon {
  font-size: var(--fs-1);
  color: var(--faint);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 4px;
  line-height: 16px;
}

/* ---------- Раскладка ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 24px;
  align-items: start;
  padding-top: 20px;
  padding-bottom: 48px;
}

/* ---------- Блоки ввода ---------- */

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  border-radius: var(--radius);
}
.block-head::-webkit-details-marker { display: none; }
.block-head:hover .block-title { color: var(--accent); }

.block-index {
  font-size: var(--fs-1);
  color: var(--faint);
  min-width: 14px;
}

.block-title { font-weight: 600; flex: 1; }

.block-summary {
  font-size: var(--fs-1);
  color: var(--muted);
  white-space: nowrap;
}

.chevron {
  width: 14px;
  height: 14px;
  flex: none;
  color: var(--faint);
  transition: transform 0.15s ease;
}
.block[open] .chevron { transform: rotate(90deg); }

.block-body {
  padding: 2px 14px 14px;
  border-top: 1px solid var(--line);
  margin-top: -1px;
  padding-top: 12px;
}

/* ---------- Поля ---------- */

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 168px;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}
.field.is-hidden { display: none; }

.field-label {
  font-size: var(--fs-2);
  color: var(--text);
  min-width: 0;
}

.field-hint {
  grid-column: 1 / -1;
  font-size: var(--fs-1);
  color: var(--muted);
  margin-top: -3px;
  padding-bottom: 3px;
  max-width: 62ch;
}

.field--text { grid-template-columns: 1fr; gap: 4px; }
.field--text .field-label { font-size: var(--fs-1); color: var(--muted); }

/* Поле со справочником: подпись сверху, ниже выбор категории и само число */
.field--catalog { grid-template-columns: 1fr; gap: 4px; }
.field--catalog .field-label { font-size: var(--fs-1); color: var(--muted); }

.catalog-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 8px;
  align-items: center;
}
.catalog-select { min-width: 0; }

.control { position: relative; display: block; }

input[type="text"],
select {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  font: inherit;
  font-size: var(--fs-2);
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  outline: none;
  /* Переход только по box-shadow: цвета из переменных не анимируем, иначе при
     смене системной темы Chrome оставляет на элементе старое значение. */
  transition: box-shadow 0.12s ease;
  font-variant-numeric: tabular-nums;
}

input[type="text"]::placeholder { color: var(--faint); }

input[type="text"]:hover,
select:hover { border-color: var(--line-strong); }

input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.control--num input { text-align: right; padding-right: 26px; }

.unit {
  position: absolute;
  right: 9px;
  top: 0;
  height: 32px;
  display: flex;
  align-items: center;
  font-size: var(--fs-2);
  color: var(--faint);
  pointer-events: none;
}

select {
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%2398a2b3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  height: 32px;
  background: var(--bar-track);
  border-radius: var(--radius-sm);
}

.segmented button {
  border: 0;
  background: transparent;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

/* ---------- Панель итогов ---------- */

.panel {
  position: sticky;
  top: calc(var(--header-h) + 20px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: calc(100vh - var(--header-h) - 40px);
  display: flex;
  flex-direction: column;
}

.panel-bar { display: none; }

.panel-body {
  overflow-y: auto;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: var(--fs-2); font-weight: 600; }
.panel-head span { font-size: var(--fs-1); }

/* Уведомление об убытке / нулевой марже */
.alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-1);
  margin-bottom: 12px;
  border-left: 3px solid transparent;
}
.alert[hidden] { display: none; }
.alert--loss { background: var(--danger-soft); border-left-color: var(--danger); color: var(--danger); }
.alert--warn { background: var(--warn-soft); border-left-color: var(--warn); color: var(--warn); }
.alert--info { background: var(--bar-track); border-left-color: var(--line-strong); color: var(--muted); }
.alert b { font-weight: 600; }

/* Четыре крупные метрики */
.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.metric {
  background: var(--surface);
  padding: 10px 12px 11px;
  min-width: 0;
}

.metric-label {
  font-size: var(--fs-1);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  font-size: var(--fs-3);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-note {
  font-size: var(--fs-1);
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric.is-negative .metric-value { color: var(--danger); }
.metric.is-zero .metric-value { color: var(--warn); }

/* Разбивка расходов */
.breakdown { margin-top: 16px; }

.breakdown-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--fs-1);
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.breakdown-head b { color: var(--text); font-weight: 600; font-size: var(--fs-2); }

.bar-row { padding: 4px 0; }
.bar-row.is-empty { opacity: 0.45; }

.bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--fs-1);
  margin-bottom: 3px;
}

.bar-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-figures { white-space: nowrap; color: var(--text); }
.bar-figures .share { color: var(--faint); margin-right: 6px; }

.bar-track {
  height: 5px;
  background: var(--bar-track);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--bar);
  border-radius: 3px;
  transition: width 0.18s ease;
  min-width: 0;
}

.bar-row--profit { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.bar-row--profit .bar-name { font-weight: 600; }
.bar-row--profit .bar-fill { background: var(--accent); }
.bar-row--profit.is-negative .bar-name,
.bar-row--profit.is-negative .bar-figures { color: var(--danger); }
.bar-row--profit.is-negative .bar-fill { background: var(--danger); }

/* Партия */
.batch {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.batch-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.batch-top label { font-size: var(--fs-1); color: var(--muted); }
.batch-top .control { width: 84px; }
.batch-top .unit { right: 8px; }

.batch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.batch-cell { min-width: 0; }
.batch-cell .k { font-size: var(--fs-1); color: var(--muted); }
.batch-cell .v {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.batch-cell.is-negative .v { color: var(--danger); }

/* Подвал панели: кнопка выгрузки всегда на виду, не уезжает в прокрутку */
.panel-foot {
  flex: none;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-sunken);
  border-radius: 0 0 var(--radius) var(--radius);
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.btn {
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: #fff; flex: 1; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--field-border);
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-sunken); }

.foot-note {
  margin-top: 9px;
  font-size: var(--fs-1);
  color: var(--faint);
}

/* ==========================================================================
   Библиотека товаров, настройки, служебные элементы
   ========================================================================== */

[hidden] { display: none !important; }

/* ---------- Загрузка ---------- */

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 90px 20px;
  color: var(--muted);
  font-size: var(--fs-1);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.boot-error { color: var(--danger); font-weight: 600; }
.boot-note { color: var(--muted); font-size: var(--fs-1); margin-top: 4px; }

/* ---------- Индикатор сохранения ---------- */

.save-state {
  font-size: var(--fs-1);
  color: var(--muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.save-state.is-visible { opacity: 1; }
.save-state.is-error { color: var(--danger); }

/* ---------- Общие элементы экранов ---------- */

.screen { padding-bottom: 48px; }

.screen-title {
  font-size: var(--fs-3);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen-note {
  font-size: var(--fs-1);
  color: var(--muted);
  max-width: 68ch;
  margin-top: 6px;
  margin-bottom: 18px;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px 4px 4px;
  margin-left: -4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-1);
  cursor: pointer;
}
.back:hover { color: var(--text); background: var(--bar-track); }
.back-icon { width: 13px; height: 13px; flex: none; }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: var(--fs-1);
  line-height: 17px;
  background: var(--bar-track);
  color: var(--muted);
  white-space: nowrap;
}
.tag--loss { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.tag--warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Библиотека ---------- */

.lib-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 20px;
  margin-bottom: 14px;
}
.lib-head .screen-title { flex: 1; }
.lib-count { color: var(--faint); font-weight: 400; }
.lib-actions { display: flex; gap: 8px; flex: none; }

.lib-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.control--search { flex: 1; min-width: 0; }
.lib-tools select { width: 190px; flex: none; }

.lib-cols,
.prow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px 128px 92px 132px 34px;
  gap: 14px;
  align-items: center;
}

.lib-cols {
  padding: 0 13px 8px;
  font-size: var(--fs-1);
  color: var(--faint);
}

.lib-rows {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.prow {
  padding: 9px 12px;
  border-top: 1px solid var(--line);
}
.prow:first-child { border-top: 0; }
.prow:hover { background: var(--surface-sunken); }
.prow.is-loss { box-shadow: inset 3px 0 0 var(--danger); }

.prow-open {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.prow-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prow-open:hover .prow-name { color: var(--accent); }

.prow-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: var(--fs-1);
  color: var(--muted);
}
.prow-sku {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prow-cell { min-width: 0; }
.prow-cell .k { display: none; font-size: var(--fs-1); color: var(--muted); }
.prow-cell .v {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prow-cell.is-negative .v { color: var(--danger); font-weight: 600; }
.prow-when .v { color: var(--muted); font-size: var(--fs-1); }

.prow-more {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}
.prow-more:hover { background: var(--bar-track); color: var(--text); }

.prow-rename { display: block; padding: 0; }
.rename-input {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  font: inherit;
  font-size: var(--fs-2);
  font-weight: 500;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Пустое состояние ---------- */

.empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 56px 24px;
  text-align: center;
}
.empty-title { font-size: var(--fs-2); font-weight: 600; }
.empty-text {
  font-size: var(--fs-1);
  color: var(--muted);
  max-width: 46ch;
  margin: 6px auto 18px;
}

/* ---------- Экран товара ---------- */

.prod-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding-top: 16px;
}
.prod-head .back { flex-basis: 100%; }

.prod-ident {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.prod-sku { font-size: var(--fs-1); color: var(--muted); white-space: nowrap; }
.prod-actions { display: flex; gap: 8px; flex: none; }

/* ---------- Настройки ---------- */

.set-grid { max-width: 620px; }
.set-grid + .set-grid { margin-top: 10px; }

.block--static .block-head { cursor: default; }
.block--static .block-body { border-top: 1px solid var(--line); }

.field-hint--lead { margin-bottom: 10px; }
.field-hint--warn { color: var(--warn); }

/* ---------- Редактор справочника ---------- */

.cat-rows { display: grid; gap: 6px; }

.cat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 30px;
  gap: 8px;
  align-items: center;
}

.cat-row--add {
  grid-template-columns: minmax(0, 1fr) 96px auto;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.cat-name {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  font: inherit;
  font-size: var(--fs-2);
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: box-shadow 0.12s ease;
}
.cat-name:hover { border-color: var(--line-strong); }
.cat-name:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.cat-del {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.cat-del:hover { background: var(--danger-soft); color: var(--danger); }

.cat-add { height: 32px; padding: 0 12px; }

/* ---------- Всплывающее меню ---------- */

.menu {
  position: absolute;
  z-index: 60;
  min-width: 178px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
}

.menu-item {
  display: block;
  width: 100%;
  padding: 6px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--bar-track); }
.menu-item.is-danger { color: var(--danger); }

/* ---------- Модальное окно ---------- */

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 420px;
  width: calc(100% - 32px);
}
.modal::backdrop { background: rgba(10, 12, 16, 0.45); }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 16px 48px rgba(16, 24, 40, 0.24);
}
.modal-title { font-size: var(--fs-2); font-weight: 600; }
.modal-text {
  font-size: var(--fs-1);
  color: var(--muted);
  margin-top: 6px;
  max-width: 52ch;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- Опасное действие ---------- */

.btn-danger { background: var(--danger-solid); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-ghost.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--field-border);
}
.btn-ghost.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { background: transparent; border-color: var(--field-border); }

/* ---------- Мобильная раскладка ---------- */

@media (max-width: 900px) {
  .wrap { padding: 0 14px; }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding-bottom: 88px;
  }

  .col-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
  }

  .panel {
    position: static;
    max-height: none;
    border-radius: 12px 12px 0 0;
    border-width: 1px 0 0;
    box-shadow: 0 -6px 24px rgba(16, 24, 40, 0.12);
  }

  .panel-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
    border-radius: 12px 12px 0 0;
  }

  .panel-bar .pb-item { min-width: 0; }
  .panel-bar .pb-key { font-size: var(--fs-1); color: var(--muted); display: block; }
  .panel-bar .pb-val {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }
  .panel-bar .pb-item.is-negative .pb-val { color: var(--danger); }
  .panel-bar .pb-spacer { flex: 1; }
  .panel-bar .chevron { transform: rotate(-90deg); }
  .panel-bar[aria-expanded="true"] .chevron { transform: rotate(90deg); }

  .panel-body {
    display: none;
    max-height: 62vh;
    border-top: 1px solid var(--line);
  }
  .panel-foot { display: none; }
  .panel.is-open .panel-body,
  .panel.is-open .panel-foot { display: block; }

  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-value { font-size: 21px; }
  /* исключения — поля, у которых подпись сверху и контрол на всю ширину */
  .field:not(.field--text):not(.field--catalog) { grid-template-columns: minmax(0, 1fr) 140px; }
}

@media (max-width: 380px) {
  .field:not(.field--text):not(.field--catalog) { grid-template-columns: minmax(0, 1fr) 126px; }
}

/* Библиотека складывается раньше калькулятора: колонок больше */
@media (max-width: 760px) {
  .lib-head { flex-wrap: wrap; }
  .lib-head .screen-title { flex-basis: 100%; }
  .lib-actions { flex: 1; }
  .lib-actions .btn { flex: 1; }

  .lib-tools { flex-direction: column; }
  .lib-tools select { width: 100%; }

  .lib-cols { display: none; }

  .prow {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px;
    grid-template-areas:
      "nm nm mr"
      "c1 c2 c2"
      "c3 c4 c4";
    row-gap: 10px;
    padding: 12px;
  }
  .prow-open,
  .prow-rename { grid-area: nm; }
  .prow-more { grid-area: mr; align-self: start; }
  .prow .c1 { grid-area: c1; }
  .prow .c2 { grid-area: c2; }
  .prow .c3 { grid-area: c3; }
  .prow .c4 { grid-area: c4; }
  .prow-cell .k { display: block; }

  .prod-ident { flex-basis: 100%; }
  .prod-actions { flex: 1; }
  .prod-actions .btn { flex: 1; }

  .empty { padding: 40px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .spinner { animation-duration: 2s; }
}
