/* «Материалы» — тёмная индустриальная тема «Горячий цех» (вариант v2, утверждён владельцем 05.12).
   Токены: фон #14171b · поверхность #1c2127 · приподнятая #242a32 · линии #323a45 · текст #e8ebef ·
   вторичный #9aa4b2 · акцент #ff8a3d (текст на нём #1a1208) · второй акцент #6aa6ff · вспышка — оранжевый 35 %. */
* { box-sizing: border-box; }
:root {
  --fs-caption: 13px;
  --fs-small: 14px;
  --fs-body: 16px;
  --fs-lead: 20px;
  --fs-title: 28px;
  --fs-result: 56px;
}
html { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #e8ebef;
  background: #14171b;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- приложение: сайдбар + контент ---------- */
.app { display: flex; min-height: 100vh; }
.layout { display: flex; align-items: flex-start; min-width: 0; flex: 1 1 auto; }

.side {
  width: 216px; flex: 0 0 auto; background: #1c2127;
  border-right: 1px solid #323a45;
  display: flex; flex-direction: column; padding: 14px 10px; gap: 2px;
}
.side-brand { font-weight: 700; letter-spacing: .1em; font-size: var(--fs-small); padding: 0 10px 12px; color: #ff8a3d; }
.side-brand .sub { display: block; font-weight: 400; letter-spacing: 0; text-transform: none; color: #9aa4b2; font-size: var(--fs-caption); padding-top: 2px; }
.nav {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px;
  color: #9aa4b2; text-decoration: none; font-size: var(--fs-small); min-height: 40px;
}
.nav svg { width: 17px; height: 17px; flex: 0 0 auto; }
.nav:hover { background: #242a32; color: #e8ebef; }
.nav.active { background: #242a32; color: #ff8a3d; font-weight: 600; }
.nav:focus-visible, .btn:focus-visible, .chip:focus-visible, .in:focus-visible,
span.v:focus-visible, .link:focus-visible, a:focus-visible, summary:focus-visible, .rail:focus-visible {
  outline: 2px solid #6aa6ff; outline-offset: 1px;
}
.side-foot { margin-top: auto; padding: 10px; font-size: var(--fs-caption); color: #9aa4b2; letter-spacing: .06em; text-transform: uppercase; }
.nav.more, .more-menu { display: none; }
.nav.hide-m { display: flex; }

/* ---------- основная колонка ---------- */
.main {
  flex: 1 1 auto; min-width: 0; padding: 16px 20px 40px;
  display: flex; flex-direction: column; gap: 12px;
}

.plate {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
  border-radius: 12px; padding: 8px 12px; margin: 0; font-size: var(--fs-small);
}
.plate.demo { background: rgba(106, 166, 255, .12); border: 1px solid rgba(106, 166, 255, .4); color: #a9c8ff; }
.plate.warn { background: rgba(255, 138, 61, .12); border: 1px solid rgba(255, 138, 61, .45); color: #ffb27d; }

/* ---------- карточки ---------- */
.card, .result {
  background: #1c2127; border: 1px solid #323a45; border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35); padding: 14px 16px; min-width: 0;
}
.card h2 { margin: 0 0 10px; font-size: var(--fs-body); }
.card h3 { margin: 14px 0 8px; font-size: var(--fs-small); color: #9aa4b2; font-weight: 600; }
.empty { color: #9aa4b2; font-style: italic; }
.muted { color: #9aa4b2; }

/* ---------- формы ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin-bottom: 6px; }
.field-label { font-size: var(--fs-caption); color: #9aa4b2; }
.in, .input, input.input, select.input {
  min-height: 44px; border: 1px solid #323a45; border-radius: 12px;
  padding: 8px 10px; background: #242a32; color: #e8ebef;
}
.input.sm { min-height: 36px; font-size: var(--fs-small); }
.row2 { display: flex; gap: 8px; }
.row2 .input[type="number"] { flex: 1 1 auto; min-width: 0; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid #323a45; background: none; color: #9aa4b2; border-radius: 999px;
  padding: 2px 10px; font-size: var(--fs-caption); cursor: pointer; min-height: 30px;
}
.chip:hover { border-color: #ff8a3d; color: #ff8a3d; }
.hint { font-size: var(--fs-caption); color: #9aa4b2; margin-top: 4px; min-width: 0; }
.hint.model { color: #ffb27d; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; border-radius: 12px;
  border: 1px solid #323a45; background: none; color: #e8ebef; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: #6aa6ff; color: #6aa6ff; }
.btn.primary { background: #ff8a3d; border-color: #ff8a3d; color: #1a1208; }
.btn.primary:hover { background: #ff9d5c; color: #1a1208; }
.btn.ghost { color: #9aa4b2; }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: var(--fs-caption); }
.btn.big { width: 100%; justify-content: center; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.link { border: none; background: none; color: #6aa6ff; cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: #9cc2ff; }

/* ---------- сравнение ---------- */
.compare-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 1000px) {
  .compare-grid { grid-template-columns: 1fr 1fr; }
}
.qty .qty-num { font-size: var(--fs-title); font-weight: 700; }
.qty-out .hint { margin-top: 0; }

/* результат: правая липкая колонка на десктопе; компактная липкая плашка на телефоне */
.plashka {
  position: sticky; bottom: 0;
  background: #1c2127; border: 1px solid #323a45; border-radius: 12px;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .45);
  padding: 12px 16px; margin-top: 4px; z-index: 10;
}
@media (min-width: 1000px) {
  #main > .cmp-flex { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px 16px; align-items: start; }
  #main > .cmp-flex > .cmp-left { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
  .plashka { grid-column: 2; grid-row: 1 / span 6; align-self: start; position: sticky; top: 16px; bottom: auto; }
}
.plashka-in.blocked { border-left: 4px solid #ef5350; padding-left: 10px; }
.block-title { font-weight: 700; color: #ef5350; }
.block-why { margin-top: 4px; }
.fmt-row { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.fmt-opt {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid #323a45;
  border-radius: 999px; padding: 4px 12px; font-size: var(--fs-caption); cursor: pointer; color: #9aa4b2; min-height: 34px;
}
.fmt-opt.on { border-color: #ff8a3d; color: #ff8a3d; font-weight: 600; }
.fmt-opt input { accent-color: #ff8a3d; }
.eps-big { font-size: var(--fs-result); font-weight: 700; line-height: 1.1; color: #ff8a3d; }
.eps-n { font-size: var(--fs-body); margin-top: 4px; }
.eps-parts { margin-top: 10px; border-top: 1px solid #323a45; padding-top: 8px; }
.eps-part { margin-bottom: 4px; }
.eps-part-label { color: #9aa4b2; font-size: var(--fs-caption); }
.warn-line { background: rgba(255, 138, 61, .12); border-radius: 8px; padding: 6px 10px; margin-top: 8px; font-size: var(--fs-caption); color: #ffb27d; }
.warn-line.strong { color: #ef5350; background: rgba(239, 83, 80, .12); }
.abs-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.abs-card { border: 1px solid #323a45; border-radius: 12px; padding: 10px 12px; background: #242a32; }
.abs-card h3 { margin: 0 0 8px; }
.abs-row { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; flex-wrap: wrap; }
.abs-label { color: #9aa4b2; font-size: var(--fs-caption); min-width: 130px; }
.prop-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 16px; }
.prop { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 2px 0; }
.prop .abs-label { min-width: 150px; }

/* значения со источником */
.num { font-variant-numeric: tabular-nums; }
.num.big { font-size: var(--fs-title); font-weight: 700; }
span.v { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: #6aa6ff; }
span.v:hover { color: #6aa6ff; }
.v-dot { display: inline-block; width: 5px; height: 5px; margin-left: 3px; border-radius: 50%; background: #ff8a3d; vertical-align: super; }

/* бейджи: A зелёный, B синий, C янтарный, U серый */
.badge { display: inline-block; min-width: 18px; padding: 1px 7px; border-radius: 6px; font-size: var(--fs-caption); font-weight: 700; text-align: center; vertical-align: middle; }
.badge-A { color: #4ade80; background: rgba(34, 197, 94, .15); }
.badge-B { color: #6aa6ff; background: rgba(106, 166, 255, .15); }
.badge-C { color: #ff8a3d; background: rgba(255, 138, 61, .15); }
.badge-U { color: #9aa4b2; background: rgba(154, 164, 178, .15); }

/* вспышка изменённых ячеек: мягкий ярко-оранжевый 35 %, гашение ~0,8 с */
.chg { animation: chg-flash .8s ease-out 1; border-radius: 6px; }
@keyframes chg-flash { 0% { background: rgba(255, 138, 61, .35); box-shadow: 0 0 0 6px rgba(255, 138, 61, .2); } 100% { background: transparent; box-shadow: none; } }
@media (prefers-reduced-motion: reduce) {
  .chg { animation: none; background: rgba(255, 138, 61, .3); transition: background .2s; }
}

/* ---------- таблицы ---------- */
.tbl { border-collapse: collapse; width: 100%; font-size: var(--fs-small); }
.tbl th, .tbl td { border-bottom: 1px solid #323a45; padding: 7px 10px; text-align: left; white-space: nowrap; }
.tbl th { color: #9aa4b2; font-size: var(--fs-caption); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: #ff8a3d; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover { background: #242a32; }
.tbl tr.on { background: #242a32; }
.tbl-scroll { overflow-x: auto; min-width: 0; }
.tbl.sm th, .tbl.sm td { padding: 5px 8px; }

/* ---------- материалы: дерево ---------- */
.split { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 1000px) { .split { grid-template-columns: 340px 1fr; } }
.tree-branch { display: flex; flex-direction: column; gap: 2px; }
.tree-node summary { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 8px; border-radius: 10px; min-height: 36px; }
.tree-node summary:hover { background: #242a32; }
.tree-label { flex: 1 1 auto; min-width: 0; }
.tree-count { background: #242a32; color: #9aa4b2; border-radius: 999px; font-size: var(--fs-caption); padding: 1px 8px; }
.tree-body { padding: 2px 0 6px 14px; border-left: 1px solid #323a45; margin-left: 8px; }
.tree-mat { display: block; width: 100%; text-align: left; border: none; background: none; padding: 6px 8px; border-radius: 10px; cursor: pointer; min-height: 34px; color: #e8ebef; }
.tree-mat:hover { background: #242a32; color: #ff8a3d; }
.tree-mat.on { background: #242a32; color: #ff8a3d; font-weight: 600; }
.ops-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ops-yes, .ops-no { border-radius: 999px; padding: 2px 10px; font-size: var(--fs-caption); }
.ops-yes { background: rgba(34, 197, 94, .15); color: #4ade80; }
.ops-no { background: rgba(154, 164, 178, .15); color: #9aa4b2; }
.to-block { border-top: 1px solid #323a45; margin-top: 10px; padding-top: 8px; }
.slider { width: 100%; accent-color: #ff8a3d; min-height: 44px; }
.to-out { margin-top: 6px; min-height: 40px; }
.to-line { font-size: var(--fs-body); }

/* ---------- панель источника ---------- */
.scrim { display: none; }
.panel { display: none; }
.rail { display: flex; }
.layout.panel-open .panel { display: flex; }
.layout.panel-open .rail { display: none; }

.rail {
  position: sticky; top: 90px; align-self: flex-end; margin-left: auto;
  height: 150px; width: 30px; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid #323a45; border-right: none; border-radius: 12px 0 0 12px;
  background: #1c2127; color: #ff8a3d; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  writing-mode: vertical-rl; font-size: var(--fs-caption); z-index: 20;
}
.rail:hover { color: #ff9d5c; }

.panel {
  flex: 0 0 46%; min-width: 380px; max-width: 720px; flex-direction: column;
  border-left: 1px solid #323a45; background: #1c2127;
  position: sticky; top: 0; height: 100vh; z-index: 50;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid #323a45; }
.panel-title { font-weight: 700; color: #9aa4b2; font-size: var(--fs-caption); letter-spacing: .06em; text-transform: uppercase; }
.panel-body { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px; min-height: 0; }
.panel-foot { border-top: 1px solid #323a45; padding: 8px 14px; font-size: var(--fs-caption); color: #9aa4b2; }
.biblio { border-bottom: 1px solid #323a45; padding-bottom: 10px; margin-bottom: 10px; }
.biblio-num { color: #ff8a3d; font-weight: 700; font-size: var(--fs-caption); }
.biblio-title { margin: 2px 0; font-size: var(--fs-body); }
.biblio-meta, .biblio-loc { color: #9aa4b2; font-size: var(--fs-caption); }
.biblio-link { display: inline-block; margin-top: 6px; color: #6aa6ff; }
.quote { margin: 0 0 12px; padding: 10px 12px; border-left: 3px solid #ff8a3d; background: #242a32; border-radius: 0 10px 10px 0; }
.quote.hl { background: rgba(255, 138, 61, .15); box-shadow: inset 3px 0 0 #ff8a3d; }
.page-box { display: flex; flex-direction: column; gap: 8px; }
.page-img { max-width: 100%; border: 1px solid #323a45; border-radius: 10px; }
.page-nav { display: flex; align-items: center; gap: 10px; }
.page-label { color: #9aa4b2; font-size: var(--fs-caption); }
.page-empty { border: 1px dashed #323a45; border-radius: 10px; color: #9aa4b2; padding: 18px; text-align: center; font-size: var(--fs-small); }

/* телефон: панель поверх контента, сайдбар — нижний таббар */
@media (max-width: 999px) {
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; z-index: 30;
    flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    border-top: 1px solid #323a45; border-right: none;
  }
  .side-brand, .side-foot { display: none; }
  .nav { flex: 1 1 auto; flex-direction: column; gap: 3px; font-size: var(--fs-caption); padding: 5px 2px; min-height: 52px; text-align: center; }
  .nav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav svg { width: 20px; height: 20px; }
  .nav.hide-m { display: none; }
  .nav.more { display: flex; }
  .more-menu {
    display: none; position: absolute; bottom: 62px; right: 8px; z-index: 40;
    background: #242a32; border: 1px solid #323a45; border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5); padding: 6px; min-width: 170px;
  }
  .more-menu.open { display: block; }
  .more-menu a { display: block; padding: 9px 12px; color: #e8ebef; text-decoration: none; font-size: var(--fs-small); border-radius: 8px; }
  .more-menu a:hover { background: #323a45; }
  .panel {
    position: fixed; right: 0; top: 0; bottom: 0; max-width: 92vw; width: 92vw; min-width: 0;
    box-shadow: -8px 0 24px rgba(0, 0, 0, .5); z-index: 40;
  }
  .layout.panel-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 35; }
  .rail { top: 70px; }
  .main { padding: 12px 12px 170px; }
}
@media (prefers-reduced-motion: no-preference) {
  .panel { animation: panel-in .36s cubic-bezier(.2, 0, 0, 1) 1; }
}
@keyframes panel-in { from { opacity: 0; transform: translateX(24px); } }

/* ---------- тултип-карточка ---------- */
.tip {
  position: fixed; left: 0; top: 0; z-index: 60; display: none;
  max-width: min(360px, calc(100vw - 16px));
  padding: 10px 12px; border-radius: 12px;
  background: #242a32; color: #e8ebef; font-size: var(--fs-caption); line-height: 1.4;
  border: 1px solid #323a45; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.tip.on { display: block; }
@media (prefers-reduced-motion: no-preference) { .tip.on { animation: tip-in .16s ease-out 1; } }
@keyframes tip-in { from { opacity: 0; transform: translateY(4px); } }
.tip-src { font-weight: 700; margin-bottom: 2px; }
.tip-loc { color: #9aa4b2; font-size: var(--fs-caption); }
.tip-quote { margin: 6px 0; }
.tip .tip-open { margin-top: 6px; background: none; border-color: #ff8a3d; color: #ff8a3d; font-weight: 600; }
.tip .tip-open:hover { background: rgba(255, 138, 61, .15); }

/* ---------- помощник, цикл, источники ---------- */
.bot-row .input[type="text"] { flex: 1 1 auto; min-width: 0; }
.bot-answer { margin-top: 12px; border-top: 1px solid #323a45; padding-top: 10px; }
.bot-text { margin: 0 0 10px; }
.cycle-out { margin-top: 6px; }
.formula {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: var(--fs-caption);
  background: #242a32; border-radius: 8px; padding: 6px 10px; margin-top: 6px; overflow-x: auto;
}
.src-item { border-top: 1px solid #323a45; padding: 10px 0; }
.src-item:first-of-type { border-top: none; }
.src-num { color: #ff8a3d; font-weight: 700; font-size: var(--fs-caption); }
.src-title { font-weight: 600; }

/* компактная плашка (телефон): одна строка + «Подробнее», ландшафт — ещё ниже */
.plashka-toggle { display: none; }
.plashka-recalc { display: none; }
@media (max-width: 999px) {
  .plashka { position: fixed; left: 10px; right: 10px; bottom: 60px; top: auto; max-height: 88px; overflow: hidden; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 10px; padding: 8px 10px; }
  .plashka .plashka-in { display: contents; }
  .plashka .plashka-btnrow { display: contents; }
  .plashka .plashka-legend { grid-column: 1 / -1; }
  .plashka .btn { min-height: 34px; padding: 3px 10px; font-size: var(--fs-caption); }
  .plashka .btn.ghost { border: none; background: none; color: #6aa6ff; text-decoration: underline; text-underline-offset: 3px; padding: 2px 4px; font-weight: 400; }
  .plashka .eps-big { font-size: var(--fs-lead); white-space: nowrap; }
  .plashka .eps-n { font-size: var(--fs-caption); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .fmt-row, .eps-parts, .eps-note { display: none; }
  .plashka.open .fmt-row, .plashka.open .eps-parts { display: block; grid-column: 1 / -1; }
  .eps-big { font-size: var(--fs-title); }
  .eps-n { grid-column: 2; margin-top: 0; }
  .plashka-toggle, .plashka-recalc { display: inline-flex; }
  .btn.big { display: none; }
  .plashka-extra { display: none; }
  .plashka.open .plashka-extra { display: block; grid-column: 1 / -1; }
  .plashka-line { display: none; }
}
@media (max-width: 999px) and (orientation: landscape), (max-height: 500px) {
  .eps-big { font-size: var(--fs-title); }
  .plashka { grid-template-columns: auto 1fr auto auto; padding: 6px 10px; }
}

/* сворачиваемые условия и широкие поля пресетов (перенос из приёмочных правок) */
.cond { margin: 0; }
.cond-summary { display: flex; align-items: baseline; gap: 10px; cursor: pointer; min-height: 40px; flex-wrap: wrap; }
.cond-title { font-weight: 700; font-size: var(--fs-body); }
.cond-line { color: #9aa4b2; font-size: var(--fs-caption); }
.cond-body { padding-top: 10px; }
.form-grid .field.wide { grid-column: 1 / -1; }
.tabs-wrap { position: relative; }


/* ---------- W10: панель «Источник» — постоянная правая колонка ---------- */
@media (min-width: 1000px) {
  .rail { display: none; }
  .panel { display: flex; flex: 0 0 216px; min-width: 216px; max-width: 216px; position: sticky; top: 0; height: 100vh; transition: flex-basis .2s, min-width .2s, max-width .2s; }
  .layout.panel-open .panel { flex: 0 0 460px; min-width: 460px; max-width: 460px; }
  .panel-body { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
  .panel-hint { font-size: var(--fs-small); color: #c8ccd2; background: #242a32; border-radius: 10px; padding: 8px 10px; }
  .panel-hint-const { color: #9aa4b2; }
  .panel .btn { justify-content: center; }
}
.panel-hint { font-size: var(--fs-small); color: #c8ccd2; background: #242a32; border-radius: 10px; padding: 8px 10px; margin-top: 8px; }
.panel-hint-const { color: #9aa4b2; }

/* ---------- W10: калькулятор твёрдости и свёрнутые таблицы ---------- */
.calc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.calc-row .calc-num { width: 170px; font-size: var(--fs-title); font-weight: 700; }
.calc-row .calc-scale { width: 120px; }
.calc-sep { color: #9aa4b2; font-size: var(--fs-body); }
.calc-line { font-size: var(--fs-lead); }
.calc-result { color: #ff8a3d; font-weight: 700; font-size: var(--fs-title); }
.std-table summary { cursor: pointer; padding: 8px 10px; border-radius: 10px; color: #9aa4b2; min-height: 44px; }
.std-table summary:hover { background: #242a32; color: #e8ebef; }
.std-table[open] summary { color: #ff8a3d; }
