/*
 * style.css — оформление инструмента «Раскладка плит по машинам».
 *
 * Автор: Тищенко Александр
 * Права: ООО «Стройпоставка»
 */

:root {
    --bg: #eef1f6;
    --panel: #ffffff;
    --ink: #1c2430;
    --muted: #7a8697;
    --line: #dde3ec;
    --accent: #2f6df6;
    --accent-dark: #1f57d6;          /* заливка активной кнопки под курсором */
    --accent-ink: #fff;
    --ok: #1f9d57;
    --warn: #b7791f;
    --bad: #d64545;
    --or-bg: #21ba45;                /* бейдж «или» между кнопками сортировки */
    --or-ink: #fff;
    --action: #2185d0;               /* залитая кнопка действия («Сбросить все») */
    --action-hover: #1678c2;         /* её же под курсором */
    --save: #a5673f;                 /* залитая кнопка «Сохранить» */
    --save-shadow: rgba(165, 103, 63, .35);   /* её тень в тон заливке */
    --radius: 14px;
    --radius-ctl: 10px;              /* радиус всех кнопок и полей ввода — один на интерфейс */
    --ring: 0 0 0 3px rgba(47, 109, 246, .16);   /* свечение поля в фокусе */
    --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 8px 24px rgba(20, 30, 50, .06);
    --topbar-shadow: 0 2px 6px rgba(20, 30, 50, .14);   /* тень под прилипшей шапкой */
    --topbar-h: 96px;                /* высота прилипшей шапки с запасом: текст шапки переносится, фактические 86..93px */
    --side-w: 340px;                 /* одинаковая ширина боковой панели у всех машин */
}

* { box-sizing: border-box; }

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

body {
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
}

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

/* ---------- topbar ---------- */
.topbar {
    /* Шапка «прилипает» к верху окна и остаётся на месте при прокрутке.
       sticky работает относительно окна, поэтому ни у body, ни у html
       не должно быть overflow — иначе прилипание отключается. */
    position: sticky;
    top: 0;
    /* Выше подписей плит (.stacklabels, z-index 9000+), иначе имена плит
       рисовались бы поверх шапки, но ниже пузыря подсказки (.tip, 10000). */
    z-index: 9500;
    background: linear-gradient(120deg, #17233b 0%, #24406e 55%, #2f6df6 140%);
    color: #fff;
    /* Постоянная тень отделяет шапку от уезжающего под неё содержимого. */
    box-shadow: var(--topbar-shadow);
}
.topbar__inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand__logo {
    display: block;
    width: 40px;
    height: 40px;
    flex: none;              /* знак не сжимается, когда заголовок переносится */
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 13px; opacity: .7; }
.source { font-size: 12px; opacity: .65; }

/* ---------- layout ---------- */
.wrap {
    max-width: 1440px;
    margin: 0 auto;
    padding: 22px 28px 60px;
}

/* ---------- footer ---------- */
.footer {
    border-top: 1px solid var(--line);
    background: var(--panel);
}
.footer__inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 28px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.h2 { font-size: 15px; margin: 0 0 10px; }

.panel, .summary, .legend, .trucks, .fleet { margin-bottom: 22px; }

/* ---------- alerts ---------- */
.alert {
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
    border: 1px solid;
}
.alert--error { background: #fdecec; border-color: #f3b6b6; color: #7a1f1f; }
.alert--warn { background: #fff7e8; border-color: #f0d49a; color: #6b4b0e; }
.alert__list { margin: 8px 0 0; padding-left: 20px; }
.alert__list li { margin: 2px 0; }

/* ---------- panel / form ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel__summary {
    cursor: pointer;
    padding: 14px 20px;
    font-weight: 600;
    user-select: none;
}
.panel__summary:hover { color: var(--accent); }

.form { margin: 0; }
.panel__body { padding: 4px 20px 20px; }
.form__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 12px; font-weight: 600; color: #445; }
.field__label em { font-weight: 400; color: var(--muted); font-style: normal; }
/* ---------- поля ввода: один вид у всех ---------- */
/* Текстовые поля, счётчик машин и поле перегруза рисуются одинаково: белый
   фон, рамка var(--line), радиус --radius-ctl и синее свечение в фокусе.
   Своё у каждого (шрифт, ширина, выравнивание) остаётся в его правиле. */
textarea,
.opt input[type=number],
.fleet__count,
.truck__overload .overload__input {
    border: 1px solid var(--line);
    border-radius: var(--radius-ctl);
    background: #fff;
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}
textarea:focus,
.opt input[type=number]:focus,
.fleet__count:focus,
.truck__overload .overload__input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

/* Флажки тоже одного размера и цвета по всему интерфейсу. */
.opt--check input,
.fleet__on,
.view3d__labels input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

textarea {
    width: 100%;
    resize: vertical;
    font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.5;
    padding: 12px;
}

.form__options {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
}
.opt { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: #445; }
.opt input[type=number] {
    width: 120px;
    padding: 8px 10px;
    font-size: 13px;
}
.opt--check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; padding-bottom: 8px; }

.btn {
    margin-left: auto;
    background: var(--accent);
    color: var(--accent-ink);
    border: 0;
    border-radius: var(--radius-ctl);
    padding: 11px 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(47, 109, 246, .35);
    transition: transform .06s ease, box-shadow .2s ease;
}
.btn:hover { box-shadow: 0 6px 18px rgba(47, 109, 246, .45); }
.btn:active { transform: translateY(1px); }

/* ---------- summary chips ---------- */
.summary {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.chip {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 150px;
}
.chip__k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.chip__v { font-size: 18px; font-weight: 700; }
.chip--ok .chip__v { color: var(--ok); }
.chip--bad .chip__v { color: var(--bad); }
.chip--accent .chip__v { color: var(--accent); }
/* Кликабельный чип (например, «С замечаниями») — кнопка в обличье чипа. */
.chip--link {
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, transform .05s;
}
.chip--link:hover { border-color: var(--bad); }
.chip--link:active { transform: translateY(1px); }
.chip--link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- legend (таблица «Типы плит») ---------- */
.legend {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
}
/* Список типов: колонки одной таблицы сжимаются вместе с панелью
   (в две половины — table-layout: fixed, в одну — короткие заголовки
   переносятся), поэтому прокрутка тут не нужна. */
.legend__cols { display: grid; grid-template-columns: 1fr; gap: 14px; }
/* шапка панели: заголовок слева, кнопки направления сортировки справа —
   как в «Видах машин» */
.legend__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.legend__head .h2 { margin: 0; }
.legend__actions { display: flex; gap: 8px; flex-wrap: wrap; }
/* Кнопки направления сортировки — тот же вид, что у кнопок «Видов машин». */
.legend__btn {
    font: inherit; font-size: 12px; font-weight: 600; padding: 6px 12px;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    border-radius: var(--radius-ctl); cursor: pointer;
    transition: background .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
}
.legend__btn:hover { border-color: var(--accent); color: var(--accent); }
.legend__sort { white-space: nowrap; }
/* Типов больше семи — список идёт в две половины. По умолчанию вторая
   половина встаёт ПОД первой (с разделителем): на узком экране двум
   таблицам рядом тесно, они не сжимаются и вылезают за панель. Рядом
   половины встают только там, где каждая получает не меньше ~490px
   (отсюда порог 1100px: панель занимает почти всю ширину окна). */
.legend__cols--two > .slabtable + .slabtable {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

/* Половины рядом: между ними воздух, чтобы не сливались в одну.
   table-layout: fixed — у таблиц пропадает минимальная ширина по
   содержимому, поэтому обе сжимаются вместе с панелью; ширины колонок
   заданы одинаково (см. ниже), из-за чего правая таблица продолжает
   левую по тем же линиям. */
@media (min-width: 1100px) {
    .legend__cols--two { grid-template-columns: 1fr 1fr; gap: 0 3px; }
    .legend__cols--two > .slabtable { table-layout: fixed; }
    .legend__cols--two > .slabtable:first-child { padding-right: 26px; }
    .legend__cols--two > .slabtable + .slabtable { padding-top: 0; border-top: 0; padding-left: 26px; }
    /* колонкам в две половины тесно: заголовкам убираем разрядку и чуть
       уменьшаем кегль — иначе самое длинное слово («ТОЛЩИНА,») лезет
       в соседний столбец. */
    .legend__cols--two > .slabtable thead th { letter-spacing: 0; font-size: 11px; }
    /* колонки: 1 — образец цвета, 2 — марка, 3..7 — длина, ширина,
       толщина, вес, количество (поровну). */
    .legend__cols--two > .slabtable th:nth-child(1) { width: 5%; }
    .legend__cols--two > .slabtable th:nth-child(2) { width: 24%; }
    .legend__cols--two > .slabtable th:nth-child(3),
    .legend__cols--two > .slabtable th:nth-child(4),
    .legend__cols--two > .slabtable th:nth-child(5),
    .legend__cols--two > .slabtable th:nth-child(6),
    .legend__cols--two > .slabtable th:nth-child(7) { width: 14.2%; }
}
.slabtable {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
.slabtable tbody { font-size: 12px; }
.slabtable .swatch { width: 13px; height: 13px; }
.slabtable th,
.slabtable td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
.slabtable tbody td { padding: 5px 10px; }
.slabtable tbody tr { background: var(--row, transparent); }
.slabtable thead th {
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    line-height: 1.25;
    border-bottom: 2px solid var(--line);
}
.slabtable tbody tr:last-child td { border-bottom: 0; }
.slabtable tbody tr:hover { background: var(--row-hover, #f5f8fd); }
/* Числа в ячейках не переносим — столбцы «держатся» по разрядам. Заголовки
   же переносить можно (правило на td, а не на .num): узким столбцам иначе
   не хватает места, и таблица вылезает за панель. */
.slabtable td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.slabtable th.num { text-align: right; font-variant-numeric: tabular-nums; }
.slabtable__sw { width: 1%; padding-right: 0; }
.slabtable__name { font-weight: 600; overflow-wrap: anywhere; }
.legend__total {
    margin: 12px 0 0;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 12.5px;
    color: var(--muted);
}
.legend__total b { color: var(--ink); font-weight: 700; }
.swatch {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 4px;
    border: 1.5px solid;
    flex: 0 0 auto;
}

/* ---------- пара кнопок сортировки: «или» на шве ---------- */
/* Две взаимоисключающие сортировки сшиты в одну группу: внутренние рамки
   схлопнуты в общий шов, скруглены только внешние края. Невыбранная кнопка
   контурная цветная (как Basic Colored), выбранная — залитая (как Colored).
   Поверх шва лежит зелёный бейдж «или» — приём conditionals из Semantic UI. */
.sortpair { display: inline-flex; align-items: stretch; white-space: nowrap; }
.sortpair > .legend__btn,
.sortpair > .fleet__btn { border-radius: 0; }
.sortpair > :first-child { border-radius: var(--radius-ctl) 0 0 var(--radius-ctl); padding-right: 22px; }
.sortpair > :last-child { margin-left: -1px; border-radius: 0 var(--radius-ctl) var(--radius-ctl) 0; position: relative; padding-left: 22px; }
/* Бейдж висит на шве — левой рамке второй кнопки — и центрируется по нему
   через translate, поэтому ширина надписи на положение не влияет. */
.sortpair > :last-child::before {
    content: 'или';
    position: absolute; top: 50%; left: 0;
    transform: translate(-50%, -50%);
    z-index: 3; pointer-events: none; user-select: none;
    padding: 0 7px;
    font-size: 11px; font-weight: 700; line-height: 17px;
    color: var(--or-ink); background: var(--or-bg); border-radius: 500rem;
}

/* ---------- fleet (виды машин) ---------- */
.fleet {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
}
.fleet__hint { margin: 0 0 12px; font-size: 12.5px; color: var(--muted); }
.fleet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.fleet__head .h2 { margin: 0; }
.fleet__actions { display: flex; gap: 8px; flex-wrap: wrap; }
/* Общий вид кнопок панели. Вне пары — по умолчанию нейтральная контурная. */
.fleet__btn {
    font: inherit; font-size: 12px; font-weight: 600; padding: 6px 12px;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    border-radius: var(--radius-ctl); cursor: pointer;
    transition: background .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
}
.fleet__btn:hover { border-color: var(--accent); color: var(--accent); }
.fleet__sort { white-space: nowrap; }

/* «Сбросить все» — залитая кнопка действия. Правило идёт после базового
   :hover, поэтому при равном весе селектора перекрывает его и цвет текста. */
.fleet__btn--reset {
    background: var(--action);
    border-color: var(--action);
    color: #fff;
}
.fleet__btn--reset:hover {
    background: var(--action-hover);
    border-color: var(--action-hover);
    color: #fff;
}

/* Цвет кнопок внутри пары: невыбранная — контурная цветная (Basic Colored),
   выбранная — залитая (Colored). Правила идут после базовых, поэтому при
   равном весе селектора перекрывают обычный :hover. */
.sortpair > .fleet__btn,
.sortpair > .legend__btn { border-color: var(--accent); color: var(--accent); }
.sortpair > .fleet__btn:not(.fleet__btn--on):hover,
.sortpair > .legend__btn:not(.legend__btn--on):hover { background: #eef4ff; }
.sortpair > .fleet__btn--on,
.sortpair > .legend__btn--on,
.fleet__btn--on,
.legend__btn--on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 2px 8px rgba(47, 109, 246, .32);
}
.sortpair > .fleet__btn--on:hover,
.sortpair > .legend__btn--on:hover,
.fleet__btn--on:hover,
.legend__btn--on:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: var(--accent-ink);
}
/* Столбцами, а не рядами: список заполняет первый столбец сверху вниз,
   затем следующий — как таблицы «Типы плит». Число столбцов подбирается
   по ширине панели (column-width — минимум, столбцы растягиваются). */
.fleet__list { column-width: 320px; column-gap: 22px; }
.fleet__item { display: flex; align-items: center; gap: 10px; font-size: 12.5px; break-inside: avoid; margin-bottom: 8px; }
.fleet__count {
    width: 64px; flex: 0 0 auto;
    padding: 5px 8px;
    font: inherit; text-align: center;
}
.fleet__count:disabled { background: var(--bg); color: var(--muted); opacity: .7; cursor: not-allowed; }
.fleet__on { flex: 0 0 auto; }
.fleet__item--off .fleet__spec { color: var(--muted); }
.fleet__spec { flex: 1 1 auto; }

/* ---------- truck cards ---------- */
.trucks { display: flex; flex-direction: column; gap: 18px; }

.truck {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    /* Прилипшая шапка закрывала бы верх карточки, к которой привёл
       scrollIntoView (чип «С замечаниями»), поэтому оставляем запас. */
    scroll-margin-top: calc(var(--topbar-h) + 10px);
}
.truck--warn { border-color: #f0d49a; }

/* Короткая подсветка карточки, к которой привёл чип «С замечаниями».
   Через outline, а не box-shadow — не спорит с тенью карточки. */
@keyframes truckFlash {
    0%   { outline: 3px solid rgba(214, 69, 69, .7); outline-offset: 2px; }
    100% { outline: 3px solid rgba(214, 69, 69, 0);  outline-offset: 2px; }
}
.truck--flash { animation: truckFlash 1.4s ease-out 1; }
@media (prefers-reduced-motion: reduce) {
    .truck--flash { animation: none; }
}

.truck__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 13px 20px;
    background: #f7f9fd;
    border-bottom: 1px solid var(--line);
}
.truck__id { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.truck__no { font-weight: 700; font-size: 15px; }
.truck__spec {
    font-size: 12.5px;
    color: #34435a;
    background: #e7eefc;
    border-radius: 20px;
    padding: 4px 12px;
}
.truck__stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat {
    font-size: 12px;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 4px 12px;
}
.stat b { color: var(--ink); }
.stat--ok { color: #175c33; border-color: #b6e0c4; background: #eaf7ef; }

/* ---------- разрешённый перегруз ---------- */
.truck__overload {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 4px 10px;
    cursor: help;
}
.truck__overload-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.truck__overload .overload__input {
    width: 68px;
    padding: 5px 8px;
    font-size: 13px;
    text-align: right;
}
.truck__overload-max { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---------- блок пересчёта с перегрузом ---------- */
.recalc {
    display: flex;
    align-items: center;
    gap: 14px 18px;
    flex-wrap: wrap;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 20px;
    margin-bottom: 22px;
}
.recalc .btn { margin-left: 0; flex: 0 0 auto; }
.recalc__hint { margin: 0; flex: 1 1 320px; font-size: 12.5px; color: var(--muted); }

.truck__warn {
    padding: 9px 20px;
    background: #fff7e8;
    color: #6b4b0e;
    font-size: 12.5px;
    border-bottom: 1px solid #f0d49a;
}

.truck__body {
    display: flex;
    gap: 22px;
    padding: 20px;
    align-items: center;              /* машина по центру по высоте */
    flex-wrap: wrap;
}

.bedwrap { overflow: auto; flex: 0 0 auto; }
.bed {
    box-sizing: content-box;      /* рамка снаружи: плиты точно вписываются в bw×bh */
    position: relative;
    border: 2px solid #33415c;
    border-radius: 6px;
    background:
        repeating-linear-gradient(90deg, #f2f5fa 0 20px, #eef2f8 20px 40px);
}

/* ---------- вид сверху: кабина и подписи «перед/зад» ---------- */
.view2d {
    display: inline-block;
    max-width: 100%;
    margin-left: auto;                /* центрируем машину по ширине карточки… */
    margin-right: auto;               /* …а боковую панель прижимаем вправо (margin-left: auto) */
}
.view2d[hidden], .view3d[hidden] { display: none; }
.topview {
    display: flex;
    align-items: center;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.cab {
    position: relative;
    flex: 0 0 auto;
    border: 2px solid #33415c;
    border-right: 0;
    border-radius: 12px 0 0 12px;
    background: linear-gradient(180deg, #dbe5f6, #b3c4e4);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}
.cab::before {                 /* лобовое стекло у переда */
    content: '';
    position: absolute;
    left: 15%;
    top: 15%;
    bottom: 15%;
    width: 26%;
    border-radius: 3px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(205, 222, 250, .45));
    transform: skewX(-14deg);
}
.cab::after {                  /* решётка/фары на самом переда */
    content: '';
    position: absolute;
    left: 3px;
    top: 22%;
    bottom: 22%;
    width: 3px;
    border-radius: 2px;
    background: #8fa3c6;
    opacity: .85;
}
.topview__axis {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    font-size: 10.5px;
    color: var(--muted);
    letter-spacing: .02em;
}
.topview__label--front::before { content: '◀ '; }
.topview__label--back::after { content: ' ▶'; }

.slot {
    position: absolute;
    border: 1.5px solid;
    border-radius: 4px;
    overflow: hidden;
}
/* Подписи стопки: верхняя плита — по центру своего прямоугольника (--pin),
   остальные — списком (одно имя под другим) по центру видимой части
   основания. Если список не влезает — app.js уменьшает кегль подписи. */
.stacklabels {
    position: absolute;
    pointer-events: none;
}
.stacklabels__name {
    position: absolute;
    white-space: nowrap;
    font-weight: 600;
    font-size: 10.5px;
    text-shadow: 0 0 3px #fff, 0 0 2px #fff, 0 0 2px #fff;
}
.stacklabels__name--pin {
    transform: translate(-50%, -50%);
}

.truck__side { flex: 0 0 var(--side-w); width: var(--side-w); margin-left: auto; }
.composition {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
    font-size: 11.5px;
}
.composition th {
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 4px 6px;
    border-bottom: 1px solid var(--line);
}
.composition td {
    padding: 3px 6px;
    border-bottom: 1px solid #eef1f6;
    vertical-align: middle;
}
.composition tr:last-child td { border-bottom: none; }
.comp__c-sw { width: 14px; padding-right: 0; }
.comp__c-qty { text-align: right; font-weight: 700; color: var(--accent); white-space: nowrap; }
.comp__name { font-weight: 600; color: #334; }
.comp__dim { color: var(--muted); font-size: 11px; white-space: nowrap; }

.stacks summary { cursor: pointer; font-size: 12.5px; color: var(--accent); font-weight: 600; }
.stacks__list { margin: 10px 0 0; padding-left: 20px; font-size: 12px; color: #334; }
.stacks__list li { margin: 3px 0; }

/* ---------- оси ---------- */
.axles {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: #fbfcfe;
}
/* Свёрнутая панель: заголовок со стрелкой раскрытия, как у «Схемы стопок». */
.axles__title {
    cursor: pointer;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    font-weight: 700;
}
.axles__title:hover { color: var(--accent); }
.axles__rows {
    /* Одна сетка на все строки: колонка «Ось N» и колонка значений общие,
       поэтому полоски во всех рядах одинаковой ширины и ровно выровнены.
       Колонка значений подстраивается под самую широкую надпись. */
    display: grid;
    grid-template-columns: 52px minmax(48px, 1fr) auto;
    column-gap: 10px;
    row-gap: 5px;
    align-items: center;
    margin-top: 10px;
}
.axle {
    display: contents;
    font-size: 12px;
}
.axle__no { color: #445; font-weight: 600; }
.axle__bar {
    height: 9px;
    background: #e7ecf4;
    border-radius: 6px;
    overflow: hidden;
}
.axle__bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #4f7ff0, #2f6df6);
    border-radius: 6px;
    transition: width .2s ease;
}
.axle__val { color: var(--muted); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.axle__val b { color: var(--ink); }
.axle--warn .axle__bar i { background: linear-gradient(90deg, #e0a83e, #c98a12); }
.axle--warn .axle__val b { color: var(--warn); }
.axle--bad .axle__bar i { background: linear-gradient(90deg, #e05a5a, #d64545); }
.axle--bad .axle__val b { color: var(--bad); }

.stat--warn { color: var(--warn); border-color: #f0d49a; background: #fff7e8; }
.stat--bad { color: var(--bad); border-color: #f3b6b6; background: #fdecec; }

/* ---------- всплывающие пояснения к чипам ---------- */
.stat--hint { cursor: help; }
.stat--hint::after {
    content: '?';
    display: inline-block;
    vertical-align: 1px;
    margin-left: 6px;
    width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    font-size: 9.5px;
    font-weight: 800;
    color: #fff;
    background: var(--accent);
    border-radius: 50%;
    opacity: .8;
}
.tip {
    position: fixed;
    /* выше подписей плит (.stacklabels, z-index 9000+), иначе имена плит
       рисовались бы поверх пузыря подсказки */
    z-index: 10000;
    max-width: min(340px, calc(100vw - 24px));
    background: #17233b;
    color: #eef2f8;
    font-size: 12.5px;
    line-height: 1.5;
    padding: 10px 13px;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(20, 30, 50, .3);
    opacity: 0;
    visibility: hidden;
    transition: opacity .12s ease;
    pointer-events: none;
}
.tip.is-open { opacity: 1; visibility: visible; }
.tip::after {
    content: '';
    position: absolute;
    left: var(--ax, 50%);
    top: -5px;
    width: 11px;
    height: 11px;
    margin-left: -5.5px;
    background: #17233b;
    border-radius: 2px;
    transform: rotate(45deg);
}
.tip--above::after { top: auto; bottom: -5px; }

/* ---------- кнопка «Вверх» ---------- */

/* Плавающая кнопка в правом нижнем углу: появляется, когда страница
   прокручена (класс .is-on ставит app.js), и возвращает в начало. Только
   стрелка, без подписи — компактный квадрат; имя для скринридера задаёт
   aria-label в index.php. Полупрозрачность — на фоне (rgba + backdrop-filter),
   а не на всей кнопке, иначе и стрелка выцветала бы. Спрятана через
   opacity/visibility — как .tip: так работает плавное появление, а
   visibility: hidden заодно убирает её из порядка обхода Tab. */
.totop {
    position: fixed;
    right: 24px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    /* выше прилипшей шапки (9500), ниже пузыря подсказки (.tip, 10000) */
    z-index: 9600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    color: #fff;
    background: rgba(47, 109, 246, .55);
    /* лёгкое размытие: фон под кнопкой угадывается, но текст не читается */
    backdrop-filter: blur(3px) saturate(1.2);
    -webkit-backdrop-filter: blur(3px) saturate(1.2);
    border: 0;
    border-radius: var(--radius-ctl);
    box-shadow: 0 4px 14px rgba(47, 109, 246, .32);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity .18s ease, transform .18s ease, visibility .18s, background .15s ease, box-shadow .15s ease;
}
.totop.is-on { opacity: 1; visibility: visible; transform: none; }
/* Под курсором кнопка «собирается» — непрозрачная, тень плотнее. */
.totop:hover { background: var(--accent); box-shadow: 0 8px 22px rgba(47, 109, 246, .5); }
.totop:active { transform: translateY(1px); }
.totop:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 2px; }
.totop svg { display: block; flex: none; width: 18px; height: 18px; }
@media (prefers-reduced-motion: reduce) { .totop { transition: none; } }

/* ---------- переключатель вида и 3D ---------- */
.truck__view {
    display: inline-flex;
    background: #e7eefc;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}
.vbtn {
    border: 0;
    background: transparent;
    color: #34435a;
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.vbtn:hover { color: var(--accent); }
.vbtn.is-active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(20, 30, 50, .12); }

.view3d {
    flex: 1 1 420px;
    min-width: 300px;
    position: relative;
}
.view3d canvas {
    display: block;
    width: 100%;
    height: 340px;
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: grab;
    touch-action: none;
}
.view3d canvas:active { cursor: grabbing; }
.view3d__hint {
    position: absolute;
    left: 10px;
    bottom: 8px;
    font-size: 11px;
    color: #5a6b86;
    background: rgba(255, 255, 255, .78);
    border-radius: 6px;
    padding: 3px 8px;
    pointer-events: none;
}
.view3d__labels {
    position: absolute;
    top: 8px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: #34435a;
    background: rgba(255, 255, 255, .82);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 9px;
    cursor: pointer;
    user-select: none;
}

/* ---------- footer ---------- */
.foot {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    line-height: 1.7;
}

.mobile-hint { display: none; }

/* ---------- сохранение раскладки ---------- */
.share {
    display: flex;
    align-items: center;
    gap: 16px 18px;
    flex-wrap: wrap;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 22px;
    transition: border-color .2s ease;
}
.share.is-bad { border-color: #f3b6b6; }
.share.is-done { border-color: #b6e0c4; }
.share__lead { flex: 1 1 320px; min-width: 220px; }
.share__title {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 14px;
    font-weight: 600;
}
.share__title svg { width: 17px; height: 17px; color: var(--accent); flex: 0 0 auto; }
.share__hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.share.is-bad .share__hint { color: var(--bad); }

.share__result { flex: 1 1 100%; }
.share__row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.share__field {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1 1 340px;
    min-width: 0;
    background: #f4f7fd;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 13px;
    transition: border-color .15s ease, background .15s ease;
}
.share__field:focus-within { border-color: var(--accent); background: #fff; }
.share__field svg { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; }
.share__url {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    outline: none;
    padding: 12px 0;
    font: 13px/1.4 "Cascadia Mono", Consolas, "Courier New", monospace;
    color: #26303f;
}
.copybtn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border-radius: var(--radius-ctl);
    padding: 0 20px;
    box-shadow: 0 4px 12px rgba(47, 109, 246, .35);
    transition: box-shadow .18s ease, background .18s ease, transform .06s ease;
}
.copybtn:hover { box-shadow: 0 6px 18px rgba(47, 109, 246, .45); }
.copybtn:active { transform: translateY(1px); }
.copybtn svg { width: 15px; height: 15px; }
.copybtn.is-done { background: var(--ok); box-shadow: 0 4px 12px rgba(31, 157, 87, .3); }
.share__meta {
    display: flex;
    align-items: center;
    gap: 8px 18px;
    flex-wrap: wrap;
    margin-top: 10px;
    font-size: 12.5px;
    color: var(--muted);
}
.share__meta code {
    font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
    color: var(--ink);
    background: #eef2f8;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 8px;
    letter-spacing: .04em;
}
.share__open { color: var(--accent); font-weight: 600; }
.share__open:hover { text-decoration: underline; }

/* кнопка «Сохранить» — коричневая заливка, тень в тон (идёт после .btn:hover, иначе синяя тень перебивает) */
.share > .btn {
    background: var(--save);
    box-shadow: 0 4px 12px var(--save-shadow);
}
.share > .btn:hover { box-shadow: 0 6px 18px rgba(165, 103, 63, .45); }

.alert--ok { background: #eaf7ef; border-color: #b6e0c4; color: #175c33; }

@media (max-width: 900px) {
    :root { --topbar-h: 88px; }
    .form__grid { grid-template-columns: 1fr; }
    .wrap { padding: 16px; }
    .topbar__inner { padding: 14px 16px; }
    .btn { margin-left: 0; }
    .share { padding: 14px 16px; }
    .footer__inner { padding: 14px 16px; }
    .share__lead { flex-basis: 100%; }
    .share > .btn { flex: 1 1 100%; }
    .share__field { flex-basis: 100%; }
    .copybtn { flex: 1 1 100%; padding: 12px 20px; }
    .truck__side { flex: 1 1 100%; width: auto; margin-left: 0; }
}

/* ---------- телефоны ---------- */
@media (max-width: 640px) {
    :root { --topbar-h: 104px; }

    body { font-size: 13.5px; }

    .topbar__inner { padding: 12px 14px; gap: 10px; }
    .brand { gap: 10px; }
    .brand__logo { width: 32px; height: 32px; }
    .brand h1 { font-size: 16px; }
    .brand p { font-size: 11.5px; }
    .source { flex-basis: 100%; font-size: 11.5px; opacity: .6; }

    .wrap { padding: 12px 12px 48px; }
    .footer__inner { padding: 12px 12px; }
    .panel, .summary, .legend, .trucks, .fleet, .share { margin-bottom: 14px; }

    .panel__summary { padding: 12px 14px; }
    .panel__body { padding: 0 14px 14px; }
    .form__grid { gap: 12px; }
    .form__options { gap: 10px 14px; }
    .opt { flex: 1 1 calc(50% - 7px); }
    .opt input[type=number] { width: 100%; }
    .opt--check { flex-basis: 100%; padding-bottom: 0; }
    .btn { width: 100%; padding: 13px 20px; }

    .summary { gap: 8px; }
    .chip { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 9px 12px; }
    .chip__v { font-size: 15.5px; }

    .legend { padding: 12px 14px; }
    .legend__cols { gap: 12px; }
    .legend__cols--two > .slabtable + .slabtable { padding-top: 10px; }
    .slabtable th, .slabtable td { padding: 5px 6px; }
    .slabtable thead th { font-size: 10.5px; letter-spacing: 0; }

    .fleet { padding: 12px 14px; }
    .fleet__list { columns: 1; }

    .mobile-hint {
        display: block;
        margin: -4px 2px 12px;
        font-size: 12px;
        color: var(--muted);
    }

    .trucks { gap: 12px; }
    .truck__head {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px 14px;
    }
    .truck__id { gap: 8px; }
    .truck__spec { font-size: 12px; }
    .truck__overload { width: 100%; justify-content: space-between; }
    .truck__overload .overload__input { flex: 1 1 auto; width: auto; }
    .recalc { padding: 14px; }
    .recalc .btn { flex: 1 1 100%; }
    .truck__view { display: flex; }
    .vbtn { flex: 1 1 0; text-align: center; padding: 9px 10px; }
    .truck__stats { gap: 6px; }
    .stat { font-size: 11.5px; padding: 3px 10px; }

    .truck__body {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 14px;
        padding: 14px;
    }
    .view2d { max-width: 100%; margin-left: 0; margin-right: 0; }
    .view3d { flex: 1 1 auto; min-width: 0; }
    .view3d canvas { height: 260px; }

    .axles__rows { grid-template-columns: 44px minmax(40px, 1fr) auto; column-gap: 8px; }
    .axle__val { font-size: 11px; }

    .share { padding: 14px; }

    /* кнопка «Вверх» вплотную к краю экрана */
    .totop { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ---------- очень узкие экраны: таблица «Типы плит» в карточки ---------- */
/* Шесть числовых столбцов на телефоне не помещаются: таблица сжимается до
   нечитаемого (марка в три строки, подписи столбцов в столбик) или её
   приходится крутить вбок. От 560px и ниже тип плиты показывается
   карточкой: в первой строке марка с образцом цвета, ниже — значения с
   подписями (подписи берутся из data-label ячейки). */
@media (max-width: 560px) {
    .slabtable thead { display: none; }
    .slabtable,
    .slabtable tbody { display: block; width: 100%; }
    .slabtable tbody tr {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 3px 10px;
        padding: 9px 11px;
        background: var(--row, transparent);
        border: 1px solid var(--line);
        border-radius: var(--radius-ctl);
    }
    .slabtable tbody tr + tr { margin-top: 8px; }
    /* границы между таблицами нет — на карточках разделитель лишний */
    .legend__cols--two > .slabtable + .slabtable { padding-top: 0; border-top: 0; }
    .legend__cols--two > .slabtable + .slabtable tbody tr:first-child { margin-top: 8px; }
    .slabtable tbody td { display: block; padding: 0; border: 0; }
    .slabtable td.slabtable__sw { grid-area: 1 / 1; align-self: center; width: auto; padding: 0; }
    .slabtable td.slabtable__name { grid-area: 1 / 2 / 2 / 4; align-self: center; font-size: 13px; margin-bottom: 2px; }
    /* значения — не сжатая строка, а пары «подпись сверху, число снизу» */
    .slabtable td.num { text-align: left; white-space: normal; font-size: 12.5px; }
    .slabtable td.num::before {
        content: attr(data-label);
        display: block;
        font-size: 9.5px;
        line-height: 1.2;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--muted);
    }
}

/* ---------- узкие телефоны ---------- */
@media (max-width: 400px) {
    .brand p { display: none; }
    .chip { flex-basis: 100%; }
    .view3d canvas { height: 230px; }
}
