/* BambuLaba — стили. Палитра: стол PEI, графит, сосновый акцент. */
:root {
  --bg: #EDF0F2;
  --surface: #FFFFFF;
  --surface-2: #F6F8F9;
  --ink: #18202B;
  --muted: #5E6B78;
  --line: #D5DBE0;
  --accent: #0E7C66;
  --accent-ink: #FFFFFF;
  --accent-soft: #DDF0EB;
  --warn: #B86E00;
  --warn-soft: #FBEFD9;
  --danger: #B3261E;
  --danger-soft: #F9E1DF;
  --side: #1F2A36;
  --side-ink: #C9D3DC;
  --radius: 10px;
  --radius-s: 6px;
  --font: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Катушка-образец цвета (фирменный элемент) ---------- */
.spool {
  --c: #999;
  display: inline-block; flex: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle, var(--surface) 0 3px, transparent 3.5px),
              repeating-radial-gradient(circle, var(--c) 0 2px, color-mix(in srgb, var(--c) 82%, #000) 2px 2.6px);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18);
  vertical-align: -4px;
}
.spool--lg { width: 34px; height: 34px; }
.mat { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); padding: 32px;
  border-radius: var(--radius); border: 1px solid var(--line);
  display: grid; gap: 14px;
}
.login-card p { margin: -6px 0 6px; }

/* ---------- Каркас ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh;
  background: linear-gradient(to right, var(--side) 228px, var(--bg) 228px); }
.side {
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
  /* слои печати */
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 4px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: #fff; padding: 0 8px 18px; }
.brand--big { color: var(--ink); font-size: 24px; padding: 0; }
.brand--big .spool, .side .brand .spool { width: 26px; height: 26px; }
.nav { display: grid; gap: 2px; }
.nav a {
  color: var(--side-ink); text-decoration: none; padding: 9px 12px; border-radius: var(--radius-s);
  border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.09); color: #fff; border-left-color: #3FC7A6; font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.1); display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.side-foot .link { color: #9FE3D1; }

.main { min-width: 0; padding: 24px 28px 48px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }

/* ---------- Кнопки ---------- */
.btn {
  font: 500 14px var(--font); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: var(--radius-s); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #AEB8C1; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: #0B6956; border-color: #0B6956; }
.btn--danger { color: var(--danger); }
.btn--danger:hover { border-color: var(--danger); }
.btn--sm { padding: 4px 9px; font-size: 13px; }
.btn--wide { width: 100%; padding: 10px; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.icon-btn { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row--nowrap { flex-wrap: nowrap; }
.name-link { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.name-link:hover b { color: var(--accent); text-decoration: underline; }

/* ---------- Формы ---------- */
label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: 15px var(--font); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 36px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 400; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-error { color: var(--danger); font-size: 14px; min-height: 0; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.req::after { content: " *"; color: var(--danger); }

/* ---------- Фильтры ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters label { min-width: 140px; }
.filters .grow { flex: 1 1 220px; }

/* ---------- Панели ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }

/* Лента показателей */
.figures { display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.figure { flex: 1 1 170px; padding: 16px 18px; border-right: 1px solid var(--line); }
.figure:last-child { border-right: 0; }
.figure b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.figure span { font-size: 13px; color: var(--muted); }
.figure--neg b { color: var(--danger); }
.figure--accent b { color: var(--accent); }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel .table-wrap { border: 0; border-radius: 0; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
td.n, th.n { text-align: right; white-space: nowrap; }
tbody tr:hover { background: #F7FAFA; }
tbody tr.clickable { cursor: pointer; }
tfoot td { font-weight: 600; background: var(--surface-2); border-bottom: 0; }
tr.inactive td { color: #9AA5AF; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.neg { color: var(--danger); }
.pos { color: var(--accent); }
.warn { color: var(--warn); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* Статусы */
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; background: var(--surface-2); border: 1px solid var(--line); }
.tag--Принят { background: #E8EEF6; border-color: #C9D6E8; color: #234A7A; }
.tag--В-работе { background: var(--warn-soft); border-color: #EDD3A4; color: #7A4A00; }
.tag--Готов { background: var(--accent-soft); border-color: #B5DDD2; color: #0A5A4A; }
.tag--Выдан { background: #EEF0F2; color: #4A5560; }
.tag--Отменён { background: var(--danger-soft); border-color: #EFC2BE; color: var(--danger); text-decoration: line-through; }
.tag--low { background: var(--warn-soft); border-color: #EDD3A4; color: #7A4A00; }
.tag--ok { background: var(--accent-soft); border-color: #B5DDD2; color: #0A5A4A; }
.tag--unpaid { background: var(--danger-soft); border-color: #EFC2BE; color: var(--danger); }
select.status-select { width: auto; padding: 3px 6px; font-size: 13px; }

/* Вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: 500 14px var(--font); color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

/* Списки на сводке */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list li > :last-child { flex: none; }

/* График */
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.chart .legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Палитра цветов */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.swatch { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); cursor: pointer; text-align: left; font: inherit; color: inherit; }
.swatch:hover { border-color: var(--accent); }

/* ---------- Модальное окно ---------- */
.modal { position: fixed; inset: 0; background: rgba(24,32,43,.45); display: grid; place-items: start center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: min(620px, 100%); box-shadow: 0 20px 50px rgba(24,32,43,.25); animation: pop .16s ease-out; }
.modal-box.wide { width: min(1080px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px 20px; display: grid; gap: 16px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Позиции заказа */
.items-table input, .items-table select { padding: 5px 6px; font-size: 14px; }
.items-table td { padding: 6px 6px; vertical-align: top; }
.items-table td.calc { color: var(--muted); font-size: 13px; padding-top: 11px; }
.items-table .rec { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.items-table .rec.low { color: var(--warn); font-weight: 600; }
.order-totals { display: flex; flex-wrap: wrap; gap: 6px 24px; justify-content: flex-end; font-size: 14px; }
.order-totals b { font-size: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* Уведомление */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--radius-s); opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- Каталог, КП, импорт .3mf ---------- */
.spool--xl { width: 64px; height: 64px; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.row-model { display: flex; gap: 8px; align-items: flex-start; }
.row-model > div { flex: 1; min-width: 0; }
.row-thumb { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; flex: none; }
.form-note { font-size: 13px; color: var(--muted); display: grid; gap: 2px; }
.form-note:empty { display: none; }
.picker { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--surface-2); display: grid; gap: 10px; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; max-height: 300px; overflow-y: auto; }
.pick-item { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; text-align: left; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 10px 6px 6px; cursor: pointer; }
.pick-item:hover { border-color: var(--accent); }
.pick-item img, .pick-noimg { width: 48px; height: 48px; object-fit: contain; border-radius: 4px; background: #fff; display: grid; place-items: center; }
.pick-item b { display: block; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.mcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.mcard.inactive { opacity: .6; }
.mcard-img { aspect-ratio: 4 / 3; background: #fff; border: 0; border-bottom: 1px solid var(--line); display: grid; place-items: center; cursor: pointer; padding: 0; }
.mcard-img img { width: 100%; height: 100%; object-fit: contain; }
.mcard-body { padding: 12px 14px 14px; display: grid; gap: 4px; flex: 1; align-content: start; }
.mcard-body .btn-row { margin-top: 8px; }
.mcard-price b { font-size: 18px; }
.model-form { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.mp-img { aspect-ratio: 1; border: 1px dashed var(--line); border-radius: var(--radius); display: grid; place-items: center; background: #fff; overflow: hidden; margin-bottom: 8px; }
.mp-img img { width: 100%; height: 100%; object-fit: contain; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
@media (max-width: 700px) { .model-form { grid-template-columns: minmax(0, 1fr); } .model-preview { max-width: 220px; } }

/* ---------- Справка ---------- */
.title-row { display: flex; align-items: center; gap: 10px; }
.help-link {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-weight: 700; font-size: 14px; text-decoration: none;
}
.help-link:hover { color: var(--accent); border-color: var(--accent); }
.nav a.nav-help { margin-top: 10px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.help-search { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.help-search label { flex: 1 1 320px; max-width: 560px; }
.help { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.help-toc { position: sticky; top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px; max-height: calc(100vh - 32px); overflow-y: auto; }
.help-toc ul { list-style: none; margin: 0; padding: 0; }
.help-toc a { display: block; padding: 5px 10px; border-radius: var(--radius-s); color: var(--ink); text-decoration: none; font-size: 14px; }
.help-toc li.sub a { padding-left: 22px; font-size: 13px; color: var(--muted); }
.help-toc a:hover { background: var(--surface-2); color: var(--accent); }
.help-text { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 28px 28px; max-width: 820px; line-height: 1.6; }
.help-text > p:first-child { font-size: 16px; color: var(--muted); margin-top: 18px; }
.help-text h2 { font-size: 21px; margin: 28px 0 10px; padding-top: 18px; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
.help-sec:first-of-type h2 { border-top: 0; }
.help-text h3 { font-size: 16px; margin: 20px 0 6px; scroll-margin-top: 16px; }
.help-text p, .help-text ul, .help-text ol { margin: 0 0 12px; max-width: 72ch; }
.help-text li { margin-bottom: 4px; }
.help-text .table-wrap { margin: 6px 0 16px; }
.help-text table td { vertical-align: top; }
.help-text mark { background: #FBE7A1; color: inherit; border-radius: 2px; padding: 0 1px; }
.help-text .flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
@media (max-width: 860px) {
  .help { grid-template-columns: minmax(0, 1fr); }
  .help-toc { position: static; max-height: none; }
  .help-text { padding: 4px 16px 20px; }
  .nav a.nav-help { margin-top: 0; border-top: 0; padding-top: 7px; }
}

/* ---------- Адаптив ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: var(--bg); }
  .side { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; z-index: 20; gap: 8px; }
  .side .brand { padding: 0 6px 0 0; font-size: 0; }
  .nav { display: flex; flex: 1; min-width: 0; overflow-x: auto; gap: 2px; scrollbar-width: none; }
  .nav a { white-space: nowrap; border-left: 0; border-bottom: 2px solid transparent; padding: 7px 10px; }
  .nav a.active { border-bottom-color: #3FC7A6; }
  .side-foot { display: none; }
  .main { padding: 16px 16px 40px; }
  h1 { font-size: 22px; }
  .figure { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Печать квитанции ---------- */
@media print {
  .side, .top, .modal, .toast { display: none !important; }
}
