/* Прикладные стили. Токены и общие компоненты — design-system.css. */
@font-face {
  font-family: "Open Sans"; font-style: normal; font-weight: 300 700; font-display: swap;
  src: url("fonts/opensans-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Open Sans"; font-style: normal; font-weight: 300 700; font-display: swap;
  src: url("fonts/opensans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Pico на токенах дизайн-системы. Селектор сильнее светлой темы Pico ([data-theme=light]). */
:root[data-theme="light"], :root {
  --pico-font-family: var(--font);
  --pico-font-family-sans-serif: var(--font);
  --pico-font-size: var(--root-fs);
  --pico-line-height: 1.5833;
  --pico-font-weight: 400;
  --pico-spacing: .75rem;
  --pico-border-radius: var(--radius);
  --pico-border-width: var(--border);
  --pico-form-element-spacing-vertical: .4rem;
  --pico-form-element-spacing-horizontal: .75rem;
  --pico-background-color: var(--c-page);
  --pico-color: var(--c-text);
  --pico-h1-color: var(--c-heading); --pico-h2-color: var(--c-heading); --pico-h3-color: var(--c-heading);
  --pico-h4-color: var(--c-heading); --pico-h5-color: var(--c-heading); --pico-h6-color: var(--c-heading);
  --pico-muted-color: var(--c-text-muted);
  --pico-muted-border-color: var(--c-line);
  --pico-primary: var(--c-primary);
  --pico-primary-background: var(--c-primary);
  --pico-primary-border: var(--c-primary);
  --pico-primary-underline: rgba(2, 96, 232, .4);
  --pico-primary-hover: var(--c-primary-hover);
  --pico-primary-hover-background: var(--c-primary-hover);
  --pico-primary-hover-border: var(--c-primary-hover);
  --pico-primary-hover-underline: var(--c-primary-hover);
  --pico-primary-focus: var(--c-primary-focus);
  --pico-primary-inverse: #fff;
  --pico-secondary: var(--c-text);
  --pico-secondary-background: rgba(65, 64, 66, .1);
  --pico-secondary-border: var(--c-line-field);
  --pico-secondary-hover: var(--c-text);
  --pico-secondary-hover-background: rgba(65, 64, 66, .16);
  --pico-secondary-hover-border: var(--c-line-strong);
  --pico-secondary-inverse: var(--c-text);
  --pico-card-background-color: var(--c-surface);
  --pico-card-sectioning-background-color: #f7f8f9;
  --pico-card-box-shadow: var(--shadow-card);
  --pico-form-element-background-color: var(--c-surface);
  --pico-form-element-selected-background-color: var(--c-primary-soft);
  --pico-form-element-border-color: var(--c-line-field);
  --pico-form-element-color: var(--c-text);
  --pico-form-element-placeholder-color: var(--c-text-faint);
  --pico-form-element-active-background-color: var(--c-surface);
  --pico-form-element-active-border-color: var(--c-primary);
  --pico-form-element-focus-color: var(--c-primary-focus);
  --pico-table-border-color: var(--c-line);
  --pico-table-row-stripped-background-color: rgba(65, 64, 66, .03);
}
@media (min-width: 576px) { :root { --pico-font-size: var(--root-fs); } }
@media (min-width: 768px) { :root { --pico-font-size: var(--root-fs); } }
@media (min-width: 1024px) { :root { --pico-font-size: var(--root-fs); } }
@media (min-width: 1280px) { :root { --pico-font-size: var(--root-fs); } }
@media (min-width: 1536px) { :root { --pico-font-size: var(--root-fs); } }

/* базовый размер (от него считаются все rem): страницы — --fs-page, рабочее окно — --fs как в макете.
   Шапка задана в px (--fs) и от базового размера не зависит. */
:root { --root-fs: var(--fs-page); }
:root:has(> body.page-fixed) { --root-fs: var(--fs); }
html { font-size: var(--root-fs); }
body { font-family: var(--font); color: var(--c-text); background: var(--c-page); }
h1, h2, h3, h4, h5, h6 { font-weight: var(--fw-semibold); }
h1 { font-size: 24px; } h2 { font-size: 20px; } h3 { font-size: 16px; } h4 { font-size: 14px; }
::placeholder { color: var(--c-text-faint); }

/* шапка: полоса на всю ширину закреплена сверху, внутри — белая панель */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--c-header-band);
  -webkit-backdrop-filter: blur(10px) saturate(1.2); backdrop-filter: blur(10px) saturate(1.2);
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  max-width: var(--page-width); height: 53px; margin: 14px auto 13px; padding: 0 20px;
  background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow-header);
}
@media (max-width: 1232px) { .topbar { margin-inline: var(--gutter); } }
.topbar form { margin: 0; }
.topbar-search {
  flex: 1; min-width: 160px; display: flex; align-items: center; gap: 14px;
  height: var(--h-chip); padding: 0 10px; margin: 0 6px 0 7px;
  background: var(--c-primary-soft); border: var(--border) solid var(--c-line); border-radius: var(--radius);
}
.topbar-search:focus-within { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-focus); }
/* иконка — фоном, а не <svg> в разметке: на страницах <svg> означает график */
.search-ico {
  width: 14px; height: 14px; flex: none;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23414042' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='9.5' cy='6.5' r='4.5'/%3E%3Cpath d='M6.3 9.7 2 14'/%3E%3C/svg%3E");
}
.topbar-search input[type="search"] {
  flex: 1; height: 22px; margin: 0; padding: 0; border: 0; background: none; box-shadow: none;
  font-size: var(--fs); color: var(--c-text); -webkit-appearance: none; appearance: none;
}
.topbar-search input[type="search"]::-webkit-search-cancel-button { display: none; }
.topbar-search input[type="search"]:focus { box-shadow: none; }

/* «чип» — кнопка-ссылка высотой 24 px: навигация в шапке, фильтры */
.chip, button.chip {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  height: var(--h-chip); padding: 0 16px; margin: 0;
  font: var(--fw-regular) var(--fs)/1 var(--font); color: var(--c-text); white-space: nowrap; text-decoration: none;
  background: transparent; border: var(--border) solid var(--c-line); border-radius: var(--radius);
  transition: background-color .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--c-line-strong); background: var(--c-primary-soft); color: var(--c-text); }
.chip[aria-current="page"] { border-color: var(--c-primary); color: var(--c-primary); }
.chip-primary, .chip-primary:hover { background: var(--c-primary); border-color: rgba(65, 64, 66, .2); color: #fff; padding: 0 20px; }
.chip-primary:hover { background: var(--c-primary-hover); }
.chip-success, .chip-success:hover { background: var(--c-success); border-color: rgba(65, 64, 66, .2); color: #fff; }
.chip-success:hover { background: var(--c-success-hover); }
.chip-primary[aria-current="page"], .chip-success[aria-current="page"] { color: #fff; box-shadow: 0 0 0 2px #fff, 0 0 0 3px currentColor; }
.chip-primary[aria-current="page"] { box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--c-primary); }
.chip-success[aria-current="page"] { box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--c-success); }
.chip-quiet { color: var(--c-text-muted); border-color: transparent; padding: 0 8px; }
.topbar .chip-success { margin-left: 0; }

/* кнопки 38 px (формы, панели) */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h-control); padding: 0 18px; margin: 0; min-width: 0;
  font: var(--fw-medium) var(--fs)/1 var(--font); white-space: nowrap; text-decoration: none; cursor: pointer;
  border: var(--border) solid var(--c-line-field); border-radius: var(--radius); color: var(--c-text); background: transparent;
  transition: background-color .15s, border-color .15s;
}
.btn.btn-outline:hover, .btn.btn-outline.is-active { border-color: var(--c-primary); background: var(--c-primary-soft); }
.btn.btn-outline.is-active { color: var(--c-primary); }
.btn.btn-success { background: var(--c-success); border-color: var(--c-line); color: #fff; }
.btn.btn-success:hover { background: var(--c-success-hover); }
.btn.btn-primary { background: var(--c-primary); border-color: var(--c-line); color: #fff; }
.btn.btn-primary:hover { background: var(--c-primary-hover); }
.btn.btn-icon { width: 90px; padding: 0; }
/* правило Pico-обвязки «кнопка формы не уже 9rem» к чипам и кнопкам дизайн-системы не относится */
form button:is(.btn, .chip)[type="submit"]:not(.small) { min-width: 0; }
.btn-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linejoin: round; }
.btn[aria-busy="true"] svg { display: none; }
.btn:disabled { opacity: .6; cursor: progress; }
select.field { height: var(--h-control); margin: 0; font-weight: var(--fw-medium); font-size: var(--fs); }

/* панели и подписи */
.panel {
  background: var(--c-surface); border: var(--border-card) solid var(--c-line); border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.caption { font-size: var(--fs); line-height: var(--lh); color: var(--c-text-muted); margin: 0; }
.text-success { color: var(--c-success); }
.text-amber { color: var(--c-amber); }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }

/* индикатор категории A / B / C */
.cat-dot {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; flex: none;
  border-radius: var(--radius-pill); background: var(--c-line); color: #fff; font-size: var(--fs); font-weight: var(--fw-regular);
}
.cat-dot.cat-A { background: var(--c-success); }
.cat-dot.cat-B { background: var(--c-lime); }
.cat-dot.cat-C { background: var(--c-amber); }
.cat-dot.cat-none { background: rgba(65, 64, 66, .2); }

/* страница без общей прокрутки: шапка и левая колонка стоят, прокручивается только список */
body.page-fixed { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.page-fixed > main { flex: 1; min-height: 0; width: 100%; padding-bottom: 0; }

/* ===== Рабочее окно ===== */
.work {
  display: grid; grid-template-columns: minmax(0, 578fr) minmax(0, 587fr); column-gap: 35px;
  height: 100%; padding-top: 28px;
}
.work-new, .work-list { display: flex; flex-direction: column; min-height: 0; }
.col-head { height: var(--lh); margin: 0 0 9px 1px; }
.work-form { display: flex; flex-direction: column; padding: 29px 21px 24px; margin: 0; min-height: 0; max-height: calc(100% - 52px); }
.work-form.drag { border-color: var(--c-primary); background: #f5f9ff; }
.work-form textarea {
  flex: 1 1 385px; height: 385px; min-height: 160px; margin: 0; resize: none;
  border: var(--border) solid var(--c-line-strong); border-radius: var(--radius); font-size: var(--fs); line-height: var(--lh);
}
.work-form .flash, .work-form #parse-hint { margin: 10px 0 0; }
.work-actions { display: flex; gap: 8px; margin-top: 18px; }
.work-actions select { flex: 1; min-width: 0; }

.req-grid {
  display: grid; grid-template-columns: 47px 102px minmax(0, 1fr) 35px 119px 32px; column-gap: 12px; align-items: start;
  padding: 0 23px 0 12px; border: var(--border-card) solid transparent;
}
.req-head { height: var(--lh); margin-bottom: 9px; color: var(--c-heading); font-weight: var(--fw-light); line-height: var(--lh); overflow: hidden; scrollbar-gutter: stable; }
.work-list .scroll-fade { flex: 1; min-height: 0; padding-bottom: 24px; scrollbar-gutter: stable; }
.req-row {
  min-height: 63px; padding-block: 10px; margin-bottom: 7px; line-height: var(--lh);
  color: var(--c-text); text-decoration: none; background: var(--c-surface); border-color: var(--c-line); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
.req-row:hover { color: var(--c-text); text-decoration: none; border-color: rgba(2, 96, 232, .45); box-shadow: 0 2px 10px rgba(65, 64, 66, .08); }
.req-row:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 1px; }
.req-row .cat-dot { align-self: center; }
.req-row.warn { background: var(--c-warn-bg); }
.req-row.danger { background: var(--c-danger-bg); color: #fff; }
.req-row.done { background: var(--c-surface-off); color: var(--c-text-off); font-weight: var(--fw-semibold); }
.req-row.done .cat-dot { background: rgba(65, 64, 66, .2); font-weight: var(--fw-regular); }
.work-list .empty { padding: 12px 14px; }

@media (max-width: 1000px) {
  body.page-fixed { height: auto; overflow: visible; display: block; }
  .work { grid-template-columns: 1fr; row-gap: 28px; height: auto; }
  .work-form { max-height: none; }
  .work-list .scroll-fade { max-height: 70vh; }
}
@media (max-width: 640px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px; margin-block: 10px; }
  .topbar-search { order: 3; flex-basis: 100%; margin: 0; }
  .req-grid { grid-template-columns: 40px minmax(0, 1fr) 30px; }
  .req-grid > :nth-child(2), .req-grid > :nth-child(4) { display: none; }
  .req-grid > :nth-child(5) { grid-column: 2; }
  .req-head > :nth-child(5) { display: none; }
}

body > main { padding-block: 0.5rem; }
main.container-fluid { max-width: calc(var(--page-width) + 2 * var(--gutter)); margin-inline: auto; padding-inline: var(--gutter); }

.test-banner {
  background: #c62828; color: #fff; text-align: center; font-weight: 700;
  padding: 0.35rem 1rem; letter-spacing: 0.03em;
}
.test-banner small { font-weight: 400; opacity: 0.9; }
.test-banner.dry-run { background: var(--c-primary); }
.app-header .test-banner { font-size: 11px; padding-block: 3px; }
.test-banner a { color: #fff; text-decoration: underline; }
.mail-body { white-space: pre-wrap; font-size: 0.85rem; padding: 0.75rem; }
.outbox-item summary { cursor: pointer; }


table { font-size: 0.95rem; }
table th, table td { padding: 0.35rem 0.5rem; vertical-align: top; }
table.compact th, table.compact td { padding: 0.25rem 0.45rem; }
td.num, th.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted { color: var(--pico-muted-color); }
.small { font-size: 0.9rem; }

/* !important — иначе перебивает полосатость table.striped из Pico */
tr.price-warn > td, td.price-warn { background-color: var(--warn-bg) !important; }
tr.price-old > td, td.price-old { color: var(--old-fg) !important; background-color: var(--old-bg) !important; }
tr.price-old a { color: var(--old-fg); }

.badge {
  display: inline-block; padding: 0.05rem 0.45rem; border-radius: 0.6rem; font-size: 0.78rem;
  background: var(--pico-secondary-background); color: var(--pico-secondary-inverse); white-space: nowrap;
}
.badge.ok { background: #2e7d32; color: #fff; }
.badge.warn { background: #f9a825; color: #222; }
.badge.bad { background: #c62828; color: #fff; }
.badge.demo { background: #6a1b9a; color: #fff; }

.toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.toolbar > * { margin-bottom: 0; }
.toolbar button { width: auto; }
.toolbar input[type="search"] { max-width: 420px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.flash { padding: 0.5rem 0.75rem; border-radius: var(--pico-border-radius); margin-bottom: 1rem; }
.flash.ok { background: #e8f5e9; color: #1b5e20; }
.flash.error { background: #ffebee; color: #b71c1c; }
.errors { color: #b71c1c; }

button.small, a.button.small, [role="button"].small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }
form.inline { display: inline; margin: 0; }
form.inline button { margin: 0; }
.excerpt { font-size: 0.88rem; color: var(--pico-muted-color); max-width: 420px; }
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* Рабочее окно */
.raw-line { font-style: italic; }
.item-edit { display: inline-flex; gap: 0.3rem; align-items: center; }
.item-edit input, .item-edit select { margin: 0; padding: 0.15rem 0.4rem; height: auto; font-size: 0.85rem; }
.item-edit .qty { width: 5.5rem; } .item-edit .unit { width: 4.5rem; } .item-edit .qual { width: 4.5rem; }
.item-edit .comment { width: 11rem; }
.picker { margin: 0.3rem 0 0.6rem; }
.picker button { margin: 0 0.25rem 0.25rem 0; }
.picker input[type="search"] { max-width: 420px; margin-bottom: 0.3rem; }
table.suppliers input[type="checkbox"] { margin: 0; }
tr.history-row > td:empty { padding: 0; border: none; }
.history { background: var(--pico-card-sectioning-background-color); padding: 0.4rem 0.6rem; border-radius: 6px; }
.legend .price-warn-chip { background: var(--warn-bg); padding: 0 0.4rem; border-radius: 4px; }
.legend .price-old-chip { background: var(--old-bg); color: var(--old-fg); padding: 0 0.4rem; border-radius: 4px; }
#unmatched-block > h3 { color: #b71c1c; }
.flash.warn { background: #fff8e1; color: #5d4037; border: 1px solid #ffe082; }
.parse-mode { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.parse-mode legend { margin-bottom: 0.2rem; }
.parse-mode label { margin: 0; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; }

/* Черновики */
.draft-card textarea { font-size: 0.9rem; }
.flash-inline { color: #1b5e20; }

/* Импорт */
tr.row-warn > td { background: #fff8e1; }

/* Кластеры названий */
progress { margin: 0.3rem 0; }

/* Вложения заявки */
.dropzone { display: block; border: 2px dashed var(--pico-muted-border-color); border-radius: 8px; padding: 0.6rem 0.9rem;
  margin-bottom: 0.8rem; cursor: pointer; }
.dropzone input[type="file"] { display: none; }
.dropzone.drag { border-color: var(--pico-primary); background: var(--pico-primary-background); color: #fff; }
.dropzone.has-files { border-style: solid; border-color: #2e7d32; }
.attachments a { margin-right: 0.3rem; }

/* панель анализа заявки */
.compact-select { padding: .15rem 1.8rem .15rem .5rem; margin: 0; height: auto; font-size: .9rem; width: auto; }
.inline-label { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.compact-grid { gap: .6rem; margin-top: .4rem; }
.extraction td, .checklist td { vertical-align: top; }
.quote { font-size: .85rem; color: var(--pico-muted-color); font-style: italic; }
.conf { font-size: .72rem; padding: 0 .3rem; border-radius: .3rem; background: #e8f5e9; color: #1b5e20; }
.conf.low { background: #fff8e1; color: #8d6e00; }
.flow-steps { margin: .3rem 0 0 1rem; padding: 0; }
.flow-steps li { margin: .1rem 0; }
.badge.status-error { background: #c62828; color: #fff; }
.badge.status-category_c_parked { background: #eceff1; }
.mono { font-family: ui-monospace, Consolas, monospace; }
#letter-dialog article { max-width: 46rem; width: 100%; }

/* запрос цен и реестр */
#rfq-dialog article.rfq-modal { max-width: 60rem; width: 100%; }
.rfq-supplier { border: 1px solid var(--pico-muted-border-color); border-radius: 6px; padding: .5rem .75rem; margin-bottom: .6rem; }
.rfq-supplier.disabled { opacity: .6; }
.rfq-items { list-style: none; margin: .3rem 0 0; padding: 0; }
.rfq-items li { margin: .15rem 0; font-size: .9rem; list-style: none; }
.registry-filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.registry-filters select, .registry-filters input[type=search] { width: auto; margin: 0; }
.inline-fieldset { display: flex; gap: .6rem; margin: 0; align-items: center; }
.inline-fieldset legend { float: left; margin-right: .4rem; }

/* предложения поставщиков */
.quote-item.excluded { opacity: .55; }
tr.needs-review > td { background: #fff8e1; }
article.needs-review { border-left: 3px solid #f9a825; }
.calc-bar { margin: .6rem 0 1.2rem; }

/* калькулятор */
.compact-input { padding: .15rem .4rem; margin: 0; height: auto; font-size: .9rem; width: 9rem; }
input.markup { width: 5rem; }
.calc-inputs td { vertical-align: middle; }
.calc-totals { margin: .8rem 0; }
.calc-params fieldset { margin: 0; }

/* КП и задачи */
.pdf-frame { width: 100%; height: 70vh; border: 1px solid var(--pico-muted-border-color); }
.task-overdue { border-left: 3px solid #c62828; }
tr.task-overdue > td { background: #fdecea; }
.task-close { display: flex; gap: .4rem; align-items: center; margin: .3rem 0 0; flex-wrap: wrap; }
#kp-dialog article { max-width: 46rem; width: 100%; }

/* график «закуп / продажа» в карточке позиции */
.price-chart svg { width: 100%; height: auto; display: block; margin: .5rem 0; }
.price-chart .grid-line { stroke: var(--pico-muted-border-color, #ddd); stroke-width: 1; }
.price-chart .tick { fill: var(--pico-muted-color, #666); font-size: 11px; }
.price-chart .legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; }
.price-chart .legend i { display: inline-block; width: 14px; height: 3px; margin-right: .35rem; vertical-align: middle; }

/* контакты поставщика: свежие / устаревшие */
.contact-card { border: 1px solid var(--pico-muted-border-color); border-radius: 6px; padding: .5rem .75rem; margin-bottom: .6rem; }
.contact-card.outdated { opacity: .6; border-style: dashed; }

/* сортировка таблиц по клику на заголовок */
table.sortable th[data-sortable] { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable th[data-sortable]:hover { text-decoration: underline dotted; }
table.sortable th[data-sortable]::after { content: " ↕"; opacity: .3; font-size: .8em; }
table.sortable th[aria-sort="ascending"]::after { content: " ▲"; opacity: 1; }
table.sortable th[aria-sort="descending"]::after { content: " ▼"; opacity: 1; }

/* категории поставщиков */
.badge.cat-AA { background: #1b5e20; color: #fff; }
.badge.cat-AB { background: #43a047; color: #fff; }
.badge.cat-B { background: #f9a825; color: #222; }
.badge.cat-C { background: #90a4ae; color: #fff; }
.badge.cat-D { background: #cfd8dc; color: #333; }

/* заголовки таблиц остаются на месте при прокрутке страницы */
table thead th,
table:not(:has(thead)) > tbody > tr:first-child > th {
  position: sticky; top: var(--header-h); z-index: 2;
  background-color: var(--pico-background-color);
  box-shadow: inset 0 -1px 0 var(--pico-muted-border-color);
}
/* обёртки широких таблиц: свой вертикальный скролл, чтобы заголовок закреплялся и внутри них */
div[style*="overflow-x:auto"], div[style*="overflow-x: auto"] { max-height: 80vh; overflow-y: auto; }
div[style*="overflow-x:auto"] thead th, div[style*="overflow-x: auto"] thead th,
div[style*="overflow-x:auto"] tbody > tr:first-child > th, div[style*="overflow-x: auto"] tbody > tr:first-child > th { top: 0; }

/* график: полосы наведения по месяцам, направляющая и карточка месяца */
.price-chart .chart-box { position: relative; }
.price-chart .hit { fill: transparent; cursor: crosshair; }
.price-chart .guide { stroke: var(--pico-muted-color); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.price-chart .pt { pointer-events: none; transition: r 120ms ease; }
.price-chart .pt.on { r: 6; stroke: #fff; stroke-width: 2; }
.price-chart .legend i.dash { background: none; border-top: 2px dashed var(--pico-muted-color); height: 0; }
.chart-tip {
  position: absolute; top: 8px; min-width: 240px; max-width: 300px; z-index: 5; pointer-events: none;
  background: var(--pico-card-background-color, #fff); border: 1px solid var(--pico-muted-border-color);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); padding: .55rem .7rem; font-size: .85rem;
}
.chart-tip .tip-title { font-weight: 700; margin-bottom: .35rem; padding-bottom: .3rem; border-bottom: 1px solid var(--pico-muted-border-color); }
.chart-tip .tip-row { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; margin-top: .3rem; }
.chart-tip .tip-row strong { font-size: .95rem; white-space: nowrap; }
.chart-tip .tip-name { display: inline-flex; align-items: center; gap: .4rem; }
.chart-tip .tip-name i { width: 10px; height: 10px; border-radius: 5px; display: inline-block; }
.chart-tip .tip-sub { color: var(--pico-muted-color); font-size: .78rem; margin-left: 1.05rem; }
.chart-tip .tip-none { color: var(--pico-muted-color); }
.chart-tip .tip-markup { margin-top: .45rem; padding-top: .35rem; border-top: 1px solid var(--pico-muted-border-color); }
.chart-tip .tip-markup strong { color: #2e7d32; }
.chart-tip .tip-markup strong.neg { color: #c62828; }

/* поля: одна высота, тонкая рамка, мягкий фокус */
input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="submit"], [type="button"]),
select { height: 2.5rem; padding-block: 0; }
textarea { min-height: 4.5rem; resize: vertical; }
input, select, textarea { border-width: 1px; }
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px var(--pico-primary-focus); }
label { margin-bottom: .75rem; }
label > input, label > select, label > textarea { margin-top: .3rem; margin-bottom: 0; }
/* ряд полей: поля на одной линии, даже если подпись в две строки */
.grid > label { display: flex; flex-direction: column; justify-content: flex-end; }
.grid { column-gap: .9rem; row-gap: 0; }

/* кнопки: по ширине текста, одинаковая высота, аккуратные отступы */
button, [role="button"], input[type="submit"], input[type="button"] {
  width: auto; padding: .5rem 1.1rem; line-height: 1.25; border-width: 1px;
}
button[type="submit"], input[type="submit"] { width: auto; }
form button[type="submit"]:not(.small), form [type="submit"]:not(.small) { min-width: 9rem; }
button.small, a.button.small, [role="button"].small { padding: .28rem .7rem; line-height: 1.25; }
.toolbar { gap: .6rem; }
.toolbar form { margin: 0; }

/* панели: формы редактирования и блоки рядом — на карточке с тонкой рамкой */
.grid-2 > form, #contacts, .grid-2 > div > article {
  background: var(--pico-card-background-color); border: 1px solid var(--pico-muted-border-color);
  border-radius: 8px; padding: 1rem 1.1rem; box-shadow: none;
}
.grid-2 > form > p.small:first-child { margin-top: 0; }
.grid-2 > form > button[type="submit"] { margin-top: .25rem; }
#contacts > h3 { margin-top: 0; }
article { border: 1px solid var(--pico-muted-border-color); border-radius: 8px; box-shadow: none; }
article > header, article > footer { border-color: var(--pico-muted-border-color); }

/* показатели: ровная сетка небольших карточек */
.grid.metrics { gap: .75rem; margin-bottom: 1rem; }
.grid.metrics article { margin: 0; padding: .65rem .85rem; }
.grid.metrics article small.muted { display: block; line-height: 1.3; min-height: 2.6em; }

/* заголовки и отступы между блоками */
main h2 { margin-bottom: .9rem; }
main h3 { margin-top: 1.75rem; margin-bottom: .6rem; }
.grid-2 + h3, .grid-2 + div > h3 { margin-top: 2rem; }

/* контакты */
.contact-card { border-radius: 8px !important; padding: .7rem .85rem !important; }
.contact-card .grid > input { margin-bottom: .45rem; }
.contact-card .toolbar { gap: .45rem; }
details > summary { padding-block: .25rem; }

/* уведомления */
.flash { border-radius: 6px; padding: .55rem .8rem; }
/* заголовок боковой колонки — на одной линии с заголовком основной; номера заявок не переносятся */
aside > h3:first-child, section > h3:first-child, section > h2:first-child { margin-top: 0; }
/* только короткие номера (заявка, КП); названия позиций и поставщиков переносятся, иначе таблица шире страницы */
table td:first-child > a:only-child:is([href^="/requests/"], [href^="/kps/"]) { white-space: nowrap; }

/* вкладки разделов «Ящик» и «Кабинет» */
.section-tabs {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: .25rem;
  border-bottom: 1px solid var(--pico-muted-border-color); margin: -.25rem 0 1rem; padding-bottom: 0;
}
.section-tabs .section-title { font-weight: 700; margin-right: .75rem; padding: .45rem 0; }
.section-tabs a {
  padding: .45rem .8rem; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none;
  color: var(--pico-muted-color); border-radius: 6px 6px 0 0;
}
.section-tabs a:hover { color: var(--pico-color); background: var(--pico-secondary-background, rgba(0,0,0,.03)); }
.section-tabs a[aria-current="page"] { color: var(--pico-primary); border-bottom-color: var(--pico-primary); font-weight: 600; }

/* заголовок страницы с действием справа (карточка позиции: «Редактировать») */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.page-head > h2 { margin: 0; }

/* окно «Редактировать позицию»: форма и «Объединить дубль» рядом, как раньше на странице */
dialog.edit-dialog > article { width: min(1100px, calc(100vw - 2 * var(--gutter))); max-width: none; max-height: calc(100vh - 2rem); overflow-y: auto; }
dialog.edit-dialog > article > header { display: flex; align-items: center; flex-direction: row-reverse; justify-content: space-between; }
dialog.edit-dialog > article > header > [rel="prev"] { margin: 0; }
.edit-grid { margin-bottom: 0; }

.page-actions { display: flex; gap: 8px; }

/* окно «Добавить цену» */
dialog.price-dialog > article { width: min(640px, calc(100vw - 2 * var(--gutter))); max-width: none; overflow: visible; }
dialog.price-dialog > article > header { display: flex; align-items: center; flex-direction: row-reverse; justify-content: space-between; }
dialog.price-dialog > article > header > [rel="prev"] { margin: 0; }
.price-row { display: grid; grid-template-columns: 1.3fr 1fr .8fr 1.2fr; gap: .75rem; }
.price-row label { margin-bottom: .25rem; }
.price-dialog .caption { margin: 0 0 1rem; }
.price-dialog .field { margin-bottom: .9rem; }
.price-dialog .field > label { margin-bottom: .3rem; }
.price-dialog .field input[type="search"] { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 1.2rem; }
@media (max-width: 640px) { .price-row { grid-template-columns: 1fr 1fr; } }

/* подсказки поиска под полем */
.pick { position: relative; }
.smart-search-field { flex: 1; }
.pick-box { position: static; width: 0; height: 0; flex: none; }
.topbar-search .pick-list { min-width: 0; }
.pick-box:empty { display: none; }
.pick-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; display: block;
  box-sizing: border-box; width: 100%; max-height: 280px; overflow-x: hidden; overflow-y: auto;
  background: var(--c-surface); border: var(--border) solid var(--c-line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(65, 64, 66, .14); padding: 4px;
}
.pick-option, button.pick-option {
  display: flex; box-sizing: border-box; width: 100%; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0;
  padding: 7px 10px; text-align: left; font: inherit; font-size: .95rem; color: var(--c-text);
  background: none; border: 0; border-radius: 4px; cursor: pointer; min-width: 0;
}
.pick-option:hover, .pick-option:focus-visible { background: var(--c-primary-soft); background: rgba(2, 96, 232, .07); outline: none; }
.pick-option small { color: var(--c-text-muted); white-space: nowrap; }
.pick-maybe { padding: 8px 10px 4px; font-size: .85rem; color: var(--c-amber); font-weight: var(--fw-semibold); border-top: 1px solid var(--c-line); margin-top: 4px; }
.pick-list > .pick-maybe:first-child { border-top: 0; margin-top: 0; }
.pick-empty { padding: 8px 10px; color: var(--c-text-muted); font-size: .9rem; }
.pick-loading { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: var(--c-text-muted); }
.pick-spinner {
  width: 16px; height: 16px; flex: none; box-sizing: border-box;
  border: 2px solid var(--c-line); border-top-color: var(--c-primary); border-radius: 50%;
  animation: pick-spin .7s linear infinite;
}
@keyframes pick-spin { to { transform: rotate(360deg); } }

/* контакты поставщиков в карточке позиции: по белой карточке на компанию */
.supplier-contacts { display: flex; flex-direction: column; gap: 10px; margin-bottom: 1.5rem; }
.sc-card {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start;
  background: var(--c-surface); border: var(--border-card) solid var(--c-line); border-radius: var(--radius);
  box-shadow: var(--shadow-card); padding: 14px 18px;
}
.sc-card.sc-incomplete { border-color: rgba(196, 165, 39, .55); }
.sc-company { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; font-weight: var(--fw-semibold); }
.sc-company > a:first-child { color: var(--c-heading); text-decoration: none; }
.sc-company > a:first-child:hover { color: var(--c-primary); text-decoration: underline; }
.fill-tag {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius); font-size: .85rem; font-weight: var(--fw-semibold);
  background: var(--c-warn-bg); color: #6b5a00; text-decoration: none;
}
.fill-tag:hover { background: #ffec40; color: #4d4100; text-decoration: none; }
.sc-people { display: flex; flex-wrap: wrap; gap: 10px 28px; }
.sc-person { min-width: 210px; max-width: 300px; line-height: 1.45; }
.sc-name { font-weight: var(--fw-semibold); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sc-pos { color: var(--c-text-muted); font-size: .9rem; margin-bottom: 2px; }
.sc-line { display: flex; flex-wrap: wrap; gap: 0 10px; overflow-wrap: anywhere; }
.sc-line a { text-decoration: none; }
.sc-line a:hover { text-decoration: underline; }
.fill-text { color: #8a7300; background: rgba(255, 243, 118, .45); padding: 0 6px; border-radius: 4px; font-size: .9rem; }
.sc-empty { align-self: center; }
@media (max-width: 760px) { .sc-card { grid-template-columns: 1fr; gap: 10px; } }

/* менеджеры по направлению позиции, свежесть контакта, «Все контакты поставщика» */
.sc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 1.75rem 0 .6rem; }
.sc-head h3 { margin: 0; }
.sc-dirs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .9rem; color: var(--c-text-muted); }
.dir-chip {
  display: inline-block; padding: 1px 8px; border-radius: var(--radius); font-size: .82rem; line-height: 1.5;
  background: rgba(65, 64, 66, .07); color: var(--c-text); white-space: nowrap;
}
.dir-chip.dir-match { background: rgba(2, 96, 232, .1); color: var(--c-primary); font-weight: var(--fw-semibold); }
.sc-why { font-size: .85rem; font-weight: var(--fw-regular); color: var(--c-text-muted); }
.sc-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 2px 0 3px; }
.fresh { display: inline-flex; align-items: center; gap: 5px; font-size: .85rem; color: var(--c-text-muted); white-space: nowrap; }
.fresh::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.fresh-fresh { color: #2f8a45; }
.fresh-aging { color: #a68a10; }
.fresh-old { color: #b04a4a; }
.fresh-unknown { color: var(--c-text-muted); }
.sc-outdated .sc-name { color: var(--old-fg); }
.sc-all { margin-top: 10px; border-top: 1px solid var(--c-line); padding-top: 8px; }
.sc-all > summary { font-size: .9rem; color: var(--c-primary); cursor: pointer; padding: 0; margin-bottom: 0; }
.sc-all[open] > summary { margin-bottom: 10px; }
.dir-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 14px; margin: .4rem 0 .6rem; }
.dir-check { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .92rem; }
.dir-check input { margin: 0; }
.contact-dirs { margin: 0 0 .4rem; }
.contact-dirs > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-block: .15rem; }

/* «Активен» у названия поставщика; поиск поставщика в Кабинете */
.supplier-active { margin: 0; }
.supplier-active label { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: .95rem; }
.supplier-active input[type="checkbox"] { margin: 0; }
.cabinet-found { list-style: none; padding: 0; margin: 0 0 1rem; columns: 2; }
.cabinet-found li { list-style: none; margin: .15rem 0; }
.page-head-inline { justify-content: flex-start; gap: 18px; }

/* Рабочий стол по эталону Tilda: сайдбар, объявления и заявки */
body.work-home {
  background: #f7f7f2; color: #414042; font-family: Arial, sans-serif; font-size: 14px;
}
.work-home .app-header { display: none; }
.desk-sidebar {
  position: fixed; inset: 0 auto 0 0; width: 220px; z-index: 30;
  background: #fff; border-right: 1px solid rgba(65,64,66,.24);
}
.desk-brand { height: 50px; display: flex; align-items: center; gap: 8px; padding: 0 22px; border-bottom: 1px solid rgba(65,64,66,.12); }
.desk-brand strong { font-size: 21px; letter-spacing: .04em; }
.brand-mark { color: #56a446; font-size: 28px; line-height: 1; }
.profile-card {
  position: relative; height: 100px; margin: 12px; padding: 12px; overflow: hidden;
  color: #fff; border-radius: 8px; background: linear-gradient(115deg, #657d9f 0%, #344456 65%, #202833 100%);
}
.profile-person { font-size: 15px; font-weight: 700; line-height: 1.3; }
.profile-card small { display: block; margin-top: 5px; font-size: 10px; }
.profile-cabinet {
  position: absolute; right: 8px; bottom: 8px; display: grid; place-items: center;
  width: 24px; height: 24px; color: #414042; background: #fff; border-radius: 4px; text-decoration: none;
}
.desk-nav { margin-top: 12px; }
.desk-nav a {
  display: flex; align-items: center; gap: 12px; height: 34px; padding: 0 28px;
  color: #414042; text-decoration: none;
}
.desk-nav a span { width: 20px; text-align: center; }
.desk-nav a:hover { background: #0351c1; color: #fff; }
.desk-nav a.active { background: #0260e8; color: #fff; }
.desk-shell { min-height: 100vh; margin-left: 220px; }
.desk-topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  height: 50px; padding: 0 16px; background: #fff; border-bottom: 1px solid rgba(65,64,66,.24);
}
.desk-topbar .topbar-search { flex: 1; margin: 0; }
.desk-volume, .desk-create {
  flex: none; height: 32px; border: 0; border-radius: 5px; background: #0260e8; color: #fff; cursor: pointer;
}
.desk-volume { width: 36px; font-size: 18px; }
.desk-volume.muted { background: #7b8188; }
.desk-create { padding: 0 18px; font-size: 14px; }
.desk-volume:hover, .desk-create:hover { background: #0351c1; }
.desk-main {
  display: grid; grid-template-columns: minmax(480px, 1fr) minmax(520px, 1fr); gap: 30px;
  max-width: 1600px; padding: 28px 30px;
}
.desk-announcements h2 { margin: 0 0 14px; font-size: 22px; font-weight: 400; }
.announcement-list { max-height: 340px; padding-bottom: 4px; }
.announcement-card {
  min-height: 116px; margin-bottom: 12px; padding: 18px;
  color: #fff; background: #0351c1; border-radius: 8px;
}
.announcement-card h3 { margin: 0 0 9px; color: #fff; font-size: 16px; font-weight: 700; }
.announcement-card p { margin: 0 0 14px; color: #fff; line-height: 1.45; }
.announcement-card footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #fff; background: transparent; }
.announcement-card time { font-size: 12px; color: rgba(255,255,255,.78); }
.announcement-card footer a {
  padding: 10px 16px; color: #fff; background: rgba(255,255,255,.23); border-radius: 4px; text-decoration: none; white-space: nowrap;
}
.announcement-card footer a:hover { background: rgba(255,255,255,.32); }
.desk-requests .req-grid { grid-template-columns: 55px 155px minmax(160px, 1fr) 45px minmax(110px, .7fr) 30px; column-gap: 12px; align-items: center; }
.desk-requests .req-head { padding: 0 14px 8px; font-size: 12px; font-weight: 300; }
.desk-requests .request-list { max-height: calc(100vh - 120px); padding-bottom: 20px; }
.desk-requests .req-row {
  min-height: 63px; margin-bottom: 8px; padding: 10px 14px; color: #414042;
  background: #fff; border: 1px solid rgba(65,64,66,.22); border-radius: 8px;
}
.desk-requests .req-row:hover { border-color: rgba(2,96,232,.45); }
.desk-requests .req-row.warn { background: #fff376; }
.desk-requests .req-row.danger { background: #ff6e6e; color: #fff; }
.desk-requests .req-row.done { background: rgba(65,64,66,.06); color: rgba(0,0,0,.24); }
.request-dialog {
  width: 720px; max-width: 90vw; max-height: 90vh; padding: 0; overflow: visible;
  border: 0; background: transparent;
}
.request-dialog::backdrop { background: rgba(32,40,51,.3); }
.request-dialog .work-form {
  position: relative; max-height: 85vh; padding: 24px;
  background: #fff; border: 1px solid rgba(65,64,66,.22); border-radius: 8px; box-shadow: 0 18px 60px rgba(32,40,51,.18);
}
.request-dialog .work-form textarea { min-height: 390px; }
.dialog-close {
  position: absolute; top: 8px; right: 10px; z-index: 1; width: 28px; height: 28px;
  border: 0; background: transparent; color: #66656a; font-size: 24px; cursor: pointer;
}
