/* Схема стана и линия участков (plan.js). Только токены из tokens.css; цвет несут атрибуты data-state и data-heat. */
:root, [data-theme="light"] {
  --heat-0: #f3f5f7; --heat-1: #fbd9d4; --heat-2: #f2a99f; --heat-3: #e2786b; --heat-4: #c5463a; --heat-5: #9e1b16;
  --metal: #ffb020; --nodata-line: #9aa5b0;
}
[data-theme="dark"] {
  --heat-0: var(--surface-3); --heat-1: #4a2220; --heat-2: #7a2c27; --heat-3: #a63a31; --heat-4: #d24a3d; --heat-5: #f26d6a;
  --metal: #ffc53d; --nodata-line: #6b7783;
}

.plan { display: grid; gap: var(--space-3); min-width: 0; }
/* Коробка плана: светлая подложка, внутри схема во всю ширину. Уже ширины схемы — прокрутка по горизонтали */
.plan__scroll { min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); background: var(--surface-2);
  padding: var(--space-2) var(--space-3); }
.plan-svg { display: block; width: 100%; height: auto; min-width: 1040px; }

/* ---------- Лента рольганга ---------- */
.plan-line__base { fill: none; stroke: var(--line-strong); stroke-opacity: .5; stroke-width: 16; stroke-linejoin: round; }
.plan-line__rolls { fill: none; stroke: var(--surface-2); stroke-width: 13; stroke-dasharray: 1.3 4.1; stroke-linejoin: round; }

/* ---------- Участок на схеме ---------- */
.plan-sec { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.plan-sec:focus-visible .plan-hit { stroke: var(--focus); stroke-width: 3; fill: none; pointer-events: all; }
.plan-hit { fill: transparent; pointer-events: all; }
/* Фигуры плана по 3D-модели: тон — цвет материала модели (colors.* из model.js), приглушённый смесью с фоном карточки.
   h — обшивка печи, b — станины и корпуса клетей, t — линия охлаждения, p — упаковка, s — сталь (валки, ролики), d — чугун и привод,
   o — жёлтые ограждения, e — красные кожухи, c — бетон и площадки. Заливка состояния — подсветка plan-wash под фигурами. */
.plan-svg--art .plan-sec path, .plan-svg--art .plan-back path { stroke-linejoin: round; stroke-linecap: round; fill-rule: evenodd; vector-effect: non-scaling-stroke; stroke-width: .7px; }
.plan-svg--art .plan-sec path[data-tone="c"] { fill: color-mix(in srgb, #cbd2d7 50%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 22%, transparent); }
.plan-svg--art .plan-sec path[data-tone="h"] { fill: color-mix(in srgb, #777d81 62%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 55%, transparent); }
.plan-svg--art .plan-sec path[data-tone="b"] { fill: color-mix(in srgb, #326786 62%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 60%, transparent); }
.plan-svg--art .plan-sec path[data-tone="t"] { fill: color-mix(in srgb, #39738b 62%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 60%, transparent); }
.plan-svg--art .plan-sec path[data-tone="p"] { fill: color-mix(in srgb, #506f86 62%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 60%, transparent); }
.plan-svg--art .plan-sec path[data-tone="s"] { fill: color-mix(in srgb, #a9b5bf 70%, var(--surface)); stroke: color-mix(in srgb, var(--ink) 45%, transparent); }
.plan-svg--art .plan-sec path[data-tone="d"] { fill: color-mix(in srgb, #303b43 70%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 60%, transparent); }
.plan-svg--art .plan-sec path[data-tone="o"] { fill: color-mix(in srgb, #e4b431 72%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 50%, transparent); }
.plan-svg--art .plan-sec path[data-tone="e"] { fill: color-mix(in srgb, #984638 62%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 55%, transparent); }
/* Условная схема (запасной сборщик build-plan.mjs): корпус (b), тёмная деталь (k) и контурная линия (l) */
.plan-svg:not(.plan-svg--art) .plan-sec path { stroke-linejoin: round; stroke-linecap: round; fill: none; }
.plan-svg:not(.plan-svg--art) .plan-sec path[data-tone="b"] { fill: var(--surface); fill-opacity: .82; stroke: var(--line-strong); stroke-width: 1.2; }
.plan-svg:not(.plan-svg--art) .plan-sec path[data-tone="k"] { fill: var(--ink); fill-opacity: .4; stroke: none; }
.plan-svg:not(.plan-svg--art) .plan-sec path[data-tone="l"] { stroke: var(--ink-3); stroke-width: .9; stroke-opacity: .85; }
.plan-svg--art .plan-back path { fill: color-mix(in srgb, var(--ink) 5%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 15%, transparent); }
.plan-svg--art .plan-back path[data-tone="y"] { fill: color-mix(in srgb, var(--ink) 13%, var(--surface-2)); stroke: color-mix(in srgb, var(--ink) 24%, transparent); }
.plan-back { pointer-events: none; }
.plan-wash { fill: var(--run); stroke: none; pointer-events: none; }
.plan-sec[data-state="stop"] .plan-wash { fill: var(--stop-place); fill-opacity: .65; }
.plan-sec[data-state="nodata"] .plan-wash { fill: var(--nodata-line); fill-opacity: .26; }
.plan-sec[data-state="nodata"] path { opacity: .55; filter: grayscale(1); }
.pl-stop-ring { fill: none; stroke: var(--stop-place-line); stroke-width: 2.2; pointer-events: none; }
/* Карта потерь: оборудование красится уровнем простоя (чем темнее, тем больше), бетон и тёмный привод остаются как есть */
.plan[data-mode="loss"] .plan-sec { --heat: var(--heat-0); }
.plan[data-mode="loss"] .plan-sec[data-heat="1"] { --heat: var(--heat-1); }
.plan[data-mode="loss"] .plan-sec[data-heat="2"] { --heat: var(--heat-2); }
.plan[data-mode="loss"] .plan-sec[data-heat="3"] { --heat: var(--heat-3); }
.plan[data-mode="loss"] .plan-sec[data-heat="4"] { --heat: var(--heat-4); }
.plan[data-mode="loss"] .plan-sec[data-heat="5"] { --heat: var(--heat-5); }
.plan[data-mode="loss"] .plan-svg--art .plan-sec path[data-tone]:not([data-tone="c"]):not([data-tone="d"]) { fill: var(--heat); fill-opacity: 1; stroke: color-mix(in srgb, var(--ink) 60%, transparent); }
.plan[data-mode="loss"] .plan-svg--art .plan-sec[data-heat="0"] path[data-tone]:not([data-tone="c"]):not([data-tone="d"]) { fill-opacity: .55; }
/* Участки без простоя приглушены (выбранный обведён рамкой plan-frame--sel); подпись наведённого и сфокусированного участка темнее */
.plan[data-mode="loss"] .plan-svg:not(.plan-svg--art) .plan-sec path[data-tone="b"] { fill: var(--heat); fill-opacity: 1; stroke: var(--line-strong); }
.plan[data-mode="loss"] .plan-svg:not(.plan-svg--art) .plan-sec[data-heat="0"] path[data-tone="b"] { fill-opacity: .55; }
.plan[data-mode="loss"] .plan-sec[data-heat="0"] .plan-label { opacity: .6; }
.plan[data-mode="loss"] .plan-sec:hover .plan-label, .plan[data-mode="loss"] .plan-sec:focus-visible .plan-label { fill: var(--ink); font-weight: 800; }

.plan-label { fill: var(--ink-2); font-weight: 600; paint-order: stroke; stroke: var(--surface-2); stroke-width: 3.5px; stroke-linejoin: round; pointer-events: all; }
.plan-label--min { fill: var(--ink); font-weight: 800; }
/* Число простоев участка: кружок цвета чернил с цифрой на самом участке */
.plan-badge { fill: var(--ink); stroke: var(--surface-2); stroke-width: 2; pointer-events: none; }
.plan-badge__n { fill: var(--surface); font-weight: 800; pointer-events: none; }
/* Строка подсказки под схемой карты потерь: высота постоянная, чтобы схема не прыгала при наведении */
.plan-tip { margin: 0; min-height: 22px; font-size: 14px; line-height: 22px; color: var(--ink-3); }
.plan-tip[data-on="1"] { color: var(--ink); font-weight: 700; }
.plan-sec[data-state="stop"] .plan-label { fill: var(--stop-place-ink); font-weight: 800; }
.plan-sec[aria-pressed="true"] .plan-label { fill: var(--ink); font-weight: 800; }
.plan-leader { stroke: var(--line-strong); stroke-width: .8; stroke-dasharray: 2 2; fill: none; }
.plan-frame { fill: none; pointer-events: none; }
/* Кандидаты — пунктиром, выбранный участок — сплошной рамкой цвета фокуса */
.plan-frame--lit { stroke: var(--focus); stroke-width: 2; stroke-dasharray: 4 3; }
.plan-frame--sel { stroke: var(--focus); stroke-width: 3.5; }

/* ---------- Заготовки (слой plan-flow.js) ---------- */
.plan-flow { pointer-events: none; }
.plan-billet { --billet-color: var(--metal-hot); }
.plan-billet[data-temperature="still"] { --billet-color: var(--metal-still); }
.plan-billet[data-temperature="cooling"] { --billet-color: var(--metal-cooling); }
.plan-billet[data-temperature="cold"] { --billet-color: var(--metal-cold); }
.plan-billet[data-card], .plan-billet[data-product-tip] { pointer-events: all; cursor: help; }
.plan-billet__halo { pointer-events: none; }
/* Толщина металла — единицы плана (5 на метр), все стадии в одной пропорции ×1,7 к прежним: тело 3,5 → 6, ореол 10 → 16, плеть-полоса 5,2 → 8.
   Зоны плети (.plan-metal-zone) всегда той же толщины, что тело плети. */
.plan-billet__halo { fill: none; stroke: var(--billet-color); stroke-opacity: .32; stroke-width: 16; stroke-linejoin: round; stroke-linecap: round; }
.plan-billet__body { fill: none; stroke: var(--billet-color); stroke-width: 6; stroke-linejoin: round; stroke-linecap: round; }
.plan-billet[data-stage="pack"] .plan-billet__body { stroke-width: 2; }
.plan-billet[data-stage="pack"] .plan-billet__halo { stroke-width: 4; stroke-opacity: .18; }
.plan-billet[data-temperature="cold"] .plan-billet__halo { stroke: var(--metal-edge); stroke-width: 8.5; stroke-opacity: 1; }
.plan-billet[data-temperature="cold"][data-stage="pack"] .plan-billet__halo { stroke-width: 4; }
.plan-billet[data-stage="ply"][data-product="strip"] .plan-billet__body { stroke-width: 8; }
.plan-billet[data-stage="ply"][data-product="strip"] .plan-billet__halo { stroke-width: 11; }
.plan-billet[data-stage="pack"][data-product="strip"] .plan-billet__body { stroke-width: 3; }
.plan-billet[data-stage="pack"][data-product="strip"] .plan-billet__halo { stroke-width: 4.6; }
.plan-billet[data-stage="ply"]:not([data-product="strip"]) .plan-billet__body { stroke-width: 3.4; }
.plan-billet[data-stage="pack"]:not([data-product="strip"]) .plan-billet__body { stroke-width: 1.6; }
.plan-metal-detail { fill: none; stroke: var(--metal-edge); stroke-width: 1.2; stroke-linecap: round; pointer-events: none; }
.plan-metal-presence { fill: none; stroke: var(--metal-hot); stroke-width: 6; stroke-linejoin: round; pointer-events: none; }
.plan-metal-presence--glow { stroke-width: 16; stroke-opacity: .25; }
.plan-billet[data-motion="still"] .plan-metal-presence { stroke: var(--metal-still); }
.plan-metal-zone { fill: none; stroke-width: 3.4; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.plan-billet[data-product="strip"] .plan-metal-zone { stroke-width: 8; }
.plan-metal-zone--hot { stroke: var(--metal-hot); }
.plan-metal-zone--cooling { stroke: var(--metal-cooling); }
.plan-billet[data-motion="still"] .plan-metal-zone { stroke: var(--metal-still); }
.pl-program > span { flex-basis: 100%; }

/* ---------- Скобки контроллеров ---------- */
.plan-ctl__br { fill: none; stroke: var(--line-strong); stroke-width: 1.4; stroke-linejoin: round; }
.plan-ctl__t { fill: var(--ink-2); font-size: 13px; font-weight: 700; }
.plan-ctl__s { fill: var(--ink-3); font-size: 13px; font-weight: 600; }
.plan-ctl[data-kind="ok"] .plan-ctl__s { fill: var(--run-ink); }
.plan-ctl[data-kind="off"] .plan-ctl__s, .plan-ctl[data-kind="lost"] .plan-ctl__s { fill: var(--ink-3); }

/* ---------- Лента участков ---------- */
.plan-ribbon-wrap { display: grid; gap: var(--space-3); min-width: 0; }
.plan-ribbon { display: flex; gap: 6px; padding: 2px 2px 8px; overflow-x: auto; scroll-snap-type: x proximity; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.plan-chip { position: relative; flex: none; display: grid; align-content: start; gap: 2px; width: 118px; min-height: 76px; margin: 0; padding: 8px 10px; scroll-snap-align: start;
  border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink-2); text-align: left; cursor: pointer;
  font: inherit; touch-action: manipulation; box-shadow: none; }
.plan-chip__no { font-size: 12px; line-height: 14px; font-weight: 700; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.plan-chip__name { font-size: 15px; line-height: 18px; font-weight: 800; color: var(--ink); overflow-wrap: anywhere; }
.plan-chip__state { font-size: 12px; line-height: 15px; font-weight: 600; }
.plan-chip[data-state="run"] { background: var(--run-soft); border-color: var(--run); color: var(--run-ink); }
.plan-chip[data-state="run"] .plan-chip__name { color: var(--run-ink); }
.plan-chip[data-state="stop"] { background: color-mix(in srgb, var(--stop-place) 30%, var(--surface)); border-color: var(--stop-place-line); color: var(--stop-place-ink); }
.plan-chip[data-state="stop"] .plan-chip__name { color: var(--stop-place-ink); }
.plan-chip[data-state="idle"] { background: var(--surface-2); }
.plan-chip[data-state="nodata"] { background: repeating-linear-gradient(-45deg, var(--surface-3) 0 5px, var(--surface-2) 5px 10px); border-color: var(--nodata-line); }
.plan-chip[data-lit] { border-color: var(--zone-unplanned); box-shadow: inset 0 0 0 2px var(--zone-unplanned); }
.plan-chip[aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: 1px; }
.plan-chip[data-metal]::after { content: ""; position: absolute; top: 8px; right: 8px; width: 12px; height: 12px; border-radius: var(--radius-pill);
  background: var(--metal); border: 2px solid var(--ink); }
.plan-chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.plan[data-mode="loss"] .plan-chip { background: var(--heat-0); border-color: var(--line-strong); color: var(--ink); animation: none; }
.plan[data-mode="loss"] .plan-chip[data-heat="1"] { background: var(--heat-1); }
.plan[data-mode="loss"] .plan-chip[data-heat="2"] { background: var(--heat-2); }
.plan[data-mode="loss"] .plan-chip[data-heat="3"] { background: var(--heat-3); }
.plan[data-mode="loss"] .plan-chip[data-heat="4"] { background: var(--heat-4); color: #fff; }
.plan[data-mode="loss"] .plan-chip[data-heat="5"] { background: var(--heat-5); color: #fff; }
.plan[data-mode="loss"] .plan-chip[data-heat="4"] .plan-chip__name, .plan[data-mode="loss"] .plan-chip[data-heat="5"] .plan-chip__name,
.plan[data-mode="loss"] .plan-chip[data-heat="4"] .plan-chip__no, .plan[data-mode="loss"] .plan-chip[data-heat="5"] .plan-chip__no { color: #fff; }
.plan[data-mode="loss"] .plan-chip[data-heat="1"] .plan-chip__name, .plan[data-mode="loss"] .plan-chip[data-heat="2"] .plan-chip__name,
.plan[data-mode="loss"] .plan-chip[data-heat="3"] .plan-chip__name { color: #111; }

.plan-ribbon-wrap { display: grid; }
@media (max-width: 599px) { .plan__scroll { padding: var(--space-2); } }

/* ---------- Обозначения ---------- */
.pl-legend, .pl-program { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); font-size: 13px; line-height: 18px; color: var(--ink-2); }
.pl-legend span { display: inline-flex; align-items: center; gap: var(--space-2); }
.pl-key { display: inline-block; width: 18px; height: 12px; border-radius: 3px; border: 1px solid var(--line-strong); background: var(--surface-3); }
.pl-key[data-state="run"] { background: var(--run); border-color: var(--run-strong); }
.pl-key[data-state="stop"] { background: var(--stop-place); border-color: var(--stop-place-line); }
.pl-key[data-state="nodata"] { background: var(--nodata-line); border-color: var(--nodata-line); opacity: .7; }
.pl-key--billet { width: 24px; height: 5px; border-radius: 3px; background: var(--metal-hot); border: 1.5px solid var(--ink); }

/* Тепловая шкала карты потерь */
.heat { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 13px; line-height: 18px; color: var(--ink-3); }
.heat i { display: inline-block; width: 32px; height: 12px; border-radius: 3px; border: 1px solid var(--line); background: var(--heat-0); }
.heat i[data-heat="1"] { background: var(--heat-1); } .heat i[data-heat="2"] { background: var(--heat-2); } .heat i[data-heat="3"] { background: var(--heat-3); }
.heat i[data-heat="4"] { background: var(--heat-4); } .heat i[data-heat="5"] { background: var(--heat-5); }


.pl-key--still { background: var(--metal-still); }
.pl-key--cooling { background: var(--metal-cooling); }
.pl-key--cold { background: var(--metal-cold); border-color: var(--metal-edge); }

/* Раскладка карточки «План цеха» на пульте от 1280×720 (легенда в строке заголовка, высота ячейки — доля сетки пульта, а не clamp 160–200 px) — в wide.css. */

/* C2: схема сохраняет читаемый масштаб внутри рамки. Локальные подложки
   закрывают тени у достигнутого края; без переполнения обе тени закрыты.
   Это работает при ручной и программной прокрутке, без обработчика JS. */
@media (max-width: 1279px) and (orientation: landscape), (max-width: 1024px) and (orientation: portrait) {
  .with-scale .plan__scroll {
    background:
      linear-gradient(to right, var(--surface-2) 65%, transparent) left center / 32px 100% no-repeat local,
      linear-gradient(to left, var(--surface-2) 65%, transparent) right center / 32px 100% no-repeat local,
      linear-gradient(to right, color-mix(in srgb, var(--ink) 28%, transparent), transparent) left center / 14px 100% no-repeat scroll,
      linear-gradient(to left, color-mix(in srgb, var(--ink) 28%, transparent), transparent) right center / 14px 100% no-repeat scroll;
    background-color: var(--surface-2);
  }
  .with-scale .plan-svg { min-width: 1040px; }
}
@media (orientation: landscape) and (max-height: 499px) and (max-width: 1279px) {
  /* Рамка низкая, а масштаб схемы тот же: можно листать и по вертикали. */
  .with-scale .plan__scroll { height: 142px; overflow-y: auto; display: flex; flex-direction: column-reverse; align-items: flex-start; }
  .with-scale .plan-svg { flex: none; }
}

/* Кнопка «Уточнить позицию» рядом с подписью «Катаем» (v147): небольшая в строке программы, на касании — 44 px; план и плитки не сдвигает */
.pl-program > .pl-pick-btn { flex: none; min-height: 36px; border-width: 2px; font-weight: 600; padding-block: 0; padding-inline: var(--space-3); font-size: 14px; line-height: 20px; }
@media (pointer: coarse) { .pl-program > .pl-pick-btn { min-height: 44px; } }
