/* Стиль «framed-sheet»: тонированная рамка (верхняя полоса и поля окна), работа — на белом листе.
   Сетка листа при 1440: 1440 − 2×8 (поля) − 2×1 (край) − 2×24 (отступ) = 1374 = 1030 (работа) + 24 + 320 (состав КП).
   Слоты: 3 × 327,3 + 2 × 24 = 1030. */
:root {
  --frame: #f3f6f5;
  --surface: #ffffff;
  --raised: #f4f6f5;
  --active: #e9edeb;
  --border: #e6e9e8;
  --rule: #eef1f0;
  --control: #cdd1cf;
  --text: #131416;
  --muted: #5d5f60;
  --accent: #2f5d50;
  --primary: #1d1f20;
  --primary-text: #ffffff;
  --negative: #c4242a;
  --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e; --pill-warning-edge: #fde68a;
  --radius-sheet: 16px; --radius-card: 8px; --radius-control: 6px;
  --inset: 8px; --gap: 24px; --pad: 24px;
  --control-height: 36px;
  --font: "IBM Plex Sans", Inter, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --frame: #000000; --surface: #111111; --raised: #1b1b1b; --active: #242424;
    --border: #262626; --rule: #1d1d1d; --control: #444444;
    --text: #ffffff; --muted: #b4b4b4;
    --accent: #6fb39f; --primary: #ffffff; --primary-text: #111111;
    --negative: #ff8a80;
    --pill-warning-bg: #2a2214; --pill-warning-ink: #f0c56a; --pill-warning-edge: #4a3a17;
  }
}

* { box-sizing: border-box; }
html { background: var(--frame); }
body { margin: 0; background: var(--frame); color: var(--text); font: 14px/20px var(--font); -webkit-font-smoothing: antialiased; }
.num { font-variant-numeric: tabular-nums; }

/* Рамка */
.topbar { height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 calc(var(--inset) + var(--pad)); font-size: 14px; }
.topbar .mark { width: 20px; height: 20px; flex: none; }
.topbar b { font-weight: 600; white-space: nowrap; }
.crumb { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb::before { content: "/"; margin-right: 10px; color: var(--control); }

.sheet { margin: 0 var(--inset) var(--inset); min-height: calc(100vh - 48px - var(--inset)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); padding: var(--pad); }

header { margin-bottom: 8px; }
h1 { margin: 0 0 4px; font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -0.01em; }
.hint { color: var(--muted); margin: 0 0 16px; font-size: 14px; max-width: 72ch; }
header .hint { margin: 0; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap); align-items: start; }

/* Шаги — разделы листа, разделённые линией, без карточек */
.step { padding: 32px 0; border-bottom: 1px solid var(--rule); scroll-margin-top: 16px; }
.step:last-child { border-bottom: 0; }
.step h2 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0 0 16px; }

.drop { display: flex; flex-direction: column; justify-content: center; min-height: 104px; border: 1px dashed var(--control); border-radius: var(--radius-card); padding: 20px 24px; cursor: pointer; transition: background-color .15s, border-color .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--raised); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop b { font-weight: 600; font-size: 16px; line-height: 24px; }
.drop small { display: block; color: var(--muted); margin-top: 2px; font-size: 14px; }
.drop.done { border-style: solid; border-color: var(--border); background: var(--raised); }
.drop.done small { color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px var(--gap); }
.grid .wide { grid-column: 1 / -1; }
.grid label:nth-child(-n+2) { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 8px; font-size: 14px; font-weight: 500; color: var(--text); }
input, select { font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); height: var(--control-height); padding: 0 10px; }
input::placeholder { color: var(--muted); }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* Слоты картинок */
.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.slot { display: flex; flex-direction: column; gap: 8px; }
.slot .pic { aspect-ratio: 16 / 11; border: 1px dashed var(--control); border-radius: var(--radius-card); background: var(--raised) center / contain no-repeat; display: grid; place-items: center; padding: 16px; text-align: center; color: var(--muted); font-size: 14px; cursor: pointer; position: relative; overflow: hidden; transition: border-color .15s; }
.slot .pic:hover { border-color: var(--accent); }
.slot .pic:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.slot .pic.filled { border-style: solid; border-color: var(--border); background-color: #fff; }
.slot .pic.busy::after { content: "Генерация…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); color: #fff; }
.slot .bar { display: flex; gap: 8px; align-items: center; min-height: 28px; }
.slot .bar b { flex: 1; font-size: 14px; font-weight: 500; }
.slot input[type=file] { display: none; }

button { font: inherit; font-weight: 500; cursor: pointer; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); color: var(--text); height: var(--control-height); padding: 0 14px; transition: background-color .15s, border-color .15s, transform .1s; }
button:hover:not(:disabled) { background: var(--raised); border-color: var(--muted); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { color: var(--muted); cursor: not-allowed; }
button.small { height: 28px; font-size: 13px; padding: 0 10px; }

.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); border: 1px solid var(--pill-warning-edge); border-radius: var(--radius-control); padding: 8px 12px; margin-top: 12px; font-size: 14px; }
.empty { color: var(--muted); margin: 0; padding: 16px; border: 1px dashed var(--control); border-radius: var(--radius-card); }

/* Позиции сметы */
.cat { margin: 24px 0 4px; font-weight: 600; display: flex; justify-content: space-between; gap: 16px; }
.cat .count { color: var(--muted); font-weight: 400; margin-left: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 0 8px; height: 44px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
td:first-child, th:first-child { padding-left: 0; }
td:last-child, th:last-child { padding-right: 0; }
th { color: var(--muted); font-weight: 400; font-size: 12px; height: 32px; border-bottom-color: var(--border); }
td.r, th.r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td .unit { color: var(--muted); }
td select { height: 30px; font-size: 13px; padding: 0 6px; width: 200px; }
.sum-box { display: flex; flex-wrap: wrap; gap: 8px 24px; padding: 12px 16px; background: var(--raised); border-radius: var(--radius-card); font-size: 14px; font-variant-numeric: tabular-nums; }
.sum-box .total { font-weight: 600; }
.sum-box .bad { color: var(--negative); }

/* Состав КП */
.outline { position: sticky; top: 16px; margin-top: 32px; background: var(--raised); border-radius: var(--radius-card); padding: 20px; }
.outline h2 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0 0 8px; }
.outline ol { list-style: none; margin: 0; padding: 0; }
.outline li a { display: grid; grid-template-columns: 12px 1fr; column-gap: 10px; padding: 8px 8px 8px 0; margin-left: -8px; padding-left: 8px; border-radius: var(--radius-control); color: inherit; text-decoration: none; transition: background-color .15s; }
.outline li a:hover { background: var(--active); }
.outline li a:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.outline .dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; border: 1.5px solid var(--muted); }
.outline .ok .dot { background: var(--accent); border-color: var(--accent); }
.outline .name { font-weight: 500; }
.outline .state { grid-column: 2; color: var(--muted); font-size: 13px; line-height: 18px; }
.outline .bad .state { color: var(--negative); }

.outline .total { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.outline .total span { color: var(--muted); }
.outline .total b { font-size: 28px; line-height: 36px; font-weight: 400; letter-spacing: -0.01em; white-space: nowrap; }
.outline .total small { font-size: 13px; color: var(--muted); }
.outline .total small.bad { color: var(--negative); }

.actions { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
#makePdf { background: var(--primary); color: var(--primary-text); border-color: var(--primary); height: 40px; font-size: 15px; width: 100%; }
#makePdf:hover:not(:disabled) { background: var(--primary); opacity: .88; }
#makePdf:disabled { background: var(--active); border-color: var(--active); color: var(--muted); opacity: 1; }
#status { color: var(--muted); font-size: 13px; line-height: 18px; }
#status:empty { display: none; }
#status.error { color: var(--negative); }

/* Планшет: рамка и состав КП складываются; итог и кнопка — в нижней полосе */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid label:nth-child(-n+2) { grid-column: auto; }
  .outline { position: sticky; top: auto; bottom: 0; margin: 0 calc(-1 * var(--pad)) calc(-1 * var(--pad)); border-radius: 0 0 var(--radius-sheet) var(--radius-sheet); background: var(--surface); border-top: 1px solid var(--border); padding: 12px var(--pad); display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 16px; }
  .outline h2, .outline ol { display: none; }
  .outline .total { margin: 0; padding: 0; border: 0; }
  .outline .total b { font-size: 22px; line-height: 28px; }
  .actions { margin: 0; }
  #makePdf { width: auto; padding: 0 20px; }
  #status { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  :root { --inset: 0px; --pad: 16px; }
  .sheet { border-radius: 0; border-left: 0; border-right: 0; }
  .outline { border-radius: 0; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .slots { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .slot .pic { padding: 8px; font-size: 13px; }
  .step { padding: 24px 0; }
  thead { display: none; }
  table, tbody, tr, td { display: block; }
  tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
  td { height: auto; padding: 0; border: 0; }
  td:nth-child(2) { grid-row: 2; color: var(--muted); text-align: left; }
  td:nth-child(3) { grid-row: 1; grid-column: 2; }
  td:nth-child(4) { grid-row: 2; grid-column: 2; }
  td select { width: 160px; }
  button, input, select { min-height: 44px; }
  button.small { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Материалы изделия */
#refillMaterials { margin-bottom: 8px; }
.mat-table td { padding: 4px; }
.mat-table input { width: 100%; min-width: 110px; height: 30px; font-size: 13px; padding: 0 6px; }
.mat-note { display: block; margin: 8px 0 20px; font-size: 13px; }
.mat-note input { width: 100%; margin-top: 4px; }
.variant { display: block; font-size: 13px; margin-bottom: 8px; }
.variant select { width: 100%; margin-top: 4px; }

/* Навигация, вход, архив, сотрудники */
.topbar nav { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 14px; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-control); white-space: nowrap; }
.topbar nav a:hover { background: var(--active); color: var(--text); }
.topbar nav a[aria-current="page"] { color: var(--text); font-weight: 500; }
.topbar nav .who { color: var(--muted); padding: 0 6px 0 12px; border-left: 1px solid var(--border); white-space: nowrap; }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary) !important; opacity: .88; }
.login { max-width: 360px; margin: 10vh auto 0; display: flex; flex-direction: column; gap: 14px; }
.login label, .form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.login .err, .form .err { color: var(--negative); min-height: 20px; margin: 0; }
.group { padding: 24px 0; border-bottom: 1px solid var(--rule); }
.group:last-child { border-bottom: 0; }
.group h2 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0 0 12px; display: flex; gap: 8px; align-items: baseline; }
.group h2 small { color: var(--muted); font-weight: 400; font-size: 14px; }
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) 140px 110px auto; gap: 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--rule); }
.row:first-child { border-top: 0; }
.row .main { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { text-align: right; }
.row .acts { display: flex; gap: 6px; justify-content: flex-end; }
.row .acts a { text-decoration: none; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 8px 0 8px; }
.toolbar input { width: 280px; max-width: 100%; }
.form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: end; padding: 16px 0 24px; border-bottom: 1px solid var(--rule); }
.form .err { grid-column: 1 / -1; }
.urow { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 140px auto; }
.tag { display: inline-block; font-size: 12px; line-height: 18px; padding: 0 8px; border-radius: 999px; background: var(--raised); border: 1px solid var(--border); color: var(--muted); }
.tag.off { color: var(--negative); }
@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .topbar nav { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .row, .urow { grid-template-columns: 1fr auto; }
  .row .hide-m { display: none; }
  .form { grid-template-columns: 1fr; }
}
