:root {
  /* Единая ширина шапки и рабочего контейнера: 1416 px × 1,1 = 1557,6 px,
     округлённые до 1558 px. Через переменную обе области меняются синхронно
     на всех страницах сайта, поэтому в таблицах помещается больше колонок. */
  --ширина-рабочей-области: 1558px;
  --фон: #f4f7f6;
  --карточка: #ffffff;
  --текст: #17212b;
  --приглушённый: #667085;
  --линия: #dce4e1;
  --основной: #146c53;
  --светло-зелёный: #e8f5ef;
  --предупреждение: #fff4d6;
  --ошибка: #fff0ee;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--фон); color: var(--текст); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
header { display: flex; gap: 20px; align-items: baseline; padding: 22px max(20px, calc((100% - var(--ширина-рабочей-области)) / 2)); color: #fff; background: #123d35; }
header h1 { margin: 0; font-size: 22px; }
header p { margin: 0; opacity: .8; }
.wrap { max-width: var(--ширина-рабочей-области); margin: 24px auto; padding: 0 20px; }
.navigation { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.navigation a, button { display: inline-block; border: 1px solid var(--линия); border-radius: 7px; padding: 8px 12px; color: var(--текст); background: #fff; font: inherit; text-decoration: none; cursor: pointer; }
.navigation a[aria-current="page"], button.primary { color: #fff; border-color: var(--основной); background: var(--основной); }
.navigation-logout { margin-left: auto; }
.compact-actions { margin-top: 0; }
button:disabled { opacity: .55; cursor: not-allowed; }
button:hover:not(:disabled), .navigation a:hover { filter: brightness(.97); }
.card { padding: 18px; border: 1px solid var(--линия); border-radius: 10px; background: var(--карточка); box-shadow: 0 1px 2px #102a2510; }
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin: 0 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > * { flex: 1; min-width: 140px; }
.row .fixed { flex: 0 0 auto; }
label { display: block; margin: 10px 0 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 8px; border: 1px solid #bfcac6; border-radius: 6px; background: #fff; color: inherit; font: inherit; }
textarea { min-height: 170px; resize: vertical; }
.personal-note { min-height: 280px; }
.hint, .small { color: var(--приглушённый); }
.small { font-size: 12px; }
.drop, .image-paste { padding: 22px; border: 2px dashed #b8ccc4; border-radius: 9px; background: #fbfefd; text-align: center; }
.image-paste { display: flex; min-height: 154px; align-items: center; justify-content: center; flex-direction: column; gap: 8px; cursor: pointer; outline: none; }
.image-paste:focus { border-color: var(--основной); box-shadow: 0 0 0 3px #146c5326; }
.image-paste img { display: block; max-width: 100%; max-height: 220px; object-fit: contain; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
/* Верхняя часть расчёта разделена на ввод и настройки. Результат находится за
   пределами этого грида, поэтому всегда использует всю ширину карточки ниже. */
.quote-top-layout { display: grid; grid-template-columns: minmax(440px, .85fr) minmax(560px, 1.15fr); gap: 16px; align-items: start; }
.quote-request-panel, .quote-top-layout .column-visibility { min-width: 0; }
.quote-request-panel .hint { margin-top: 0; }
.quote-top-layout .column-visibility { margin-top: 0; }
.quote-calculation-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-top: 14px; }
.quote-calculation-controls button { margin-bottom: 0; }
.quote-markup-input { width: min(260px, 100%); margin: 0; }
.quote-copy-panel { margin-top: 14px; padding: 14px; border: 1px solid #b8ccc4; border-radius: 8px; background: #fbfefd; }
.quote-copy-panel h3 { margin: 0 0 4px; }
.quote-copy-panel .status { margin-bottom: 0; }
.quote-excel-export-action { padding-top: 12px; border-top: 1px solid var(--линия); }
.quote-copy-column-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quote-copy-column-option { display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 5px 8px; border: 1px solid var(--линия); border-radius: 6px; background: #fff; font-weight: 500; }
.quote-copy-column-option input { width: auto; margin: 0; }
.column-visibility { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--линия); border-radius: 7px; background: #fbfefd; }
.column-visibility summary { cursor: pointer; font-weight: 600; }
.column-option-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; margin-top: 12px; }
.column-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border: 1px solid #dce4e1; border-radius: 6px; background: #fff; }
.column-option label { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-weight: 500; }
.quote-output-format { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0 0; padding: 8px 10px; border: 1px solid #dce4e1; border-radius: 6px; background: #fff; }
.quote-output-format legend { padding: 0 4px; font-weight: 600; }
.quote-output-format label { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-weight: 500; }
.quote-catalog-editing-control { margin: 12px 0 0; padding: 8px 10px; border: 1px solid #dce4e1; border-radius: 6px; background: #fff; }
.quote-catalog-editing-control legend { padding: 0 4px; font-weight: 600; }
.quote-catalog-editing-control label { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-weight: 500; }
.quote-catalog-editing-control input { width: auto; margin: 0; }
.quote-catalog-editing-control .small { margin: 6px 0 0; }
/* Две связанные настройки расчёта занимают одну строку при достаточной ширине.
   Auto-fit одновременно сохраняет удобную одну колонку на узком экране и после
   скрытия «Редактирования артикулов» у сетевой роли user растягивает приоритет имён. */
.quote-preference-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.quote-preference-pair .quote-catalog-editing-control, .quote-preference-pair .quote-output-format { min-width: 0; margin: 0; }
.column-option input { width: auto; margin: 0; }
.column-move-actions { display: inline-flex; gap: 4px; }
.column-move-actions button { min-width: 30px; padding: 2px 6px; line-height: 1.2; }
.import-sort-control { padding: 0; border: 0; border-radius: 0; color: inherit; background: transparent; font: inherit; font-weight: 700; }
.import-sort-control:hover:not(:disabled) { text-decoration: underline; filter: none; }
.status { display: none; margin: 12px 0; padding: 10px; border-radius: 6px; background: var(--светло-зелёный); }
.status.show { display: block; }
.status.warning { color: #704d00; background: var(--предупреждение); }
.status.error { color: #9a2117; background: var(--ошибка); }
.status.info { color: #174a83; background: #eaf2ff; }
.toast { position: fixed; z-index: 10; top: 18px; right: 18px; display: none; max-width: 420px; padding: 13px 16px; border-radius: 8px; color: #fff; background: var(--основной); box-shadow: 0 6px 24px #102a2550; }
.toast.show { display: block; }
.toast.error { background: #ad2e24; }
.table-wrap { overflow: auto; max-height: 500px; }
.copy-table { max-height: none; }
table { width: 100%; margin-top: 12px; border-collapse: collapse; background: #fff; }
th, td { padding: 7px; border: 1px solid var(--линия); text-align: left; vertical-align: top; }
th { background: #eef5f2; font-size: 13px; }
/* Шапка результата остаётся вверху именно внутренней области прокрутки, поэтому
   пользователь видит названия колонок даже у длинного расчёта. */
#quoteResult thead th { position: sticky; z-index: 2; top: 0; box-shadow: 0 1px 0 var(--линия); }
.quote-result-legend { margin: 12px 0 0; padding: 8px 10px; border-left: 3px solid var(--основной); background: #fbfefd; }
/* При длинном результате браузер показывает нативный хват за нижний край. Ограничения
   не дают случайно сжать таблицу до нечитаемого размера или растянуть её за пределы страницы. */
#quoteResult.quote-result-resizable { height: min(500px, 60vh); min-height: 220px; max-height: min(85vh, 1200px); resize: vertical; }
.quote-resize-hint { margin: 6px 0 0; }
td input { min-width: 70px; padding: 2px; border: 0; }
.quote-name-cell { min-width: 250px; cursor: pointer; }
.quote-name-cell:not(.quote-name-editing):hover, .quote-name-cell:not(.quote-name-editing):focus { outline: 2px solid #146c5333; outline-offset: -2px; }
.quote-name-cell.quote-name-editing { padding: 3px; cursor: text; }
.quote-name-editor { display: flex; min-width: 240px; align-items: center; gap: 4px; }
.quote-name-inline-input { flex: 1 1 160px; min-width: 160px; padding: 5px 7px; border: 1px solid var(--основной); border-radius: 4px; }
.quote-name-editor-actions { display: inline-flex; flex: 0 0 auto; gap: 3px; }
.quote-name-action { width: 27px; min-width: 27px; height: 27px; padding: 0; font-size: 16px; font-weight: 700; line-height: 1; }
.quote-name-confirm { color: #0d5c46; border-color: #9dc8ba; background: #f2fbf7; }
.quote-name-cancel { color: #9a2117; border-color: #dfb3ae; background: #fff7f6; }
.quote-name-empty { color: var(--приглушённый); }
.quote-article-with-edit { display: flex; align-items: center; gap: 6px; }
/* Карандаш не должен занимать место заметнее самого артикула: он лишь открывает
   общий редактор карточки и не входит в скопированный или выгруженный текст. */
.quote-edit-catalog-item { flex: 0 0 auto; padding: 2px 7px; border-color: #a9c2b8; font-size: 17px; line-height: 1; }
tr.old td { background: var(--предупреждение); }
tr.missing td { background: var(--ошибка); }
/* Связанная цена остаётся видимой для расчёта, но красный текст не даёт принять
   её за прямую цену введённого артикула. Подробность всегда дублируется в примечании. */
tr.related-price td { color: #b42318; font-weight: 600; }
/* «Brak» отличается от отсутствующей истории: позиция известна, но поставщик
   прямо указал её недоступность, поэтому используем отдельное оранжевое выделение. */
tr.unavailable td { background: #ffe5c0; }
.hide { display: none !important; }
.right { text-align: right; }
.part-thumb, .catalog-thumb { display: block; border: 1px solid var(--линия); border-radius: 4px; background: #fff; object-fit: contain; }
.part-thumb { width: 88px; height: 64px; }
.catalog-thumb { width: 120px; height: 100px; }
.catalog-rotate-image { margin-top: 6px; padding: 4px 7px; font-size: 12px; line-height: 1.25; }
.catalog-conflict-filter { display: inline-flex; align-items: center; gap: 7px; margin: 12px 0 0; font-weight: 600; }
.catalog-conflict-filter input { width: auto; margin: 0; }
tr.catalog-conflict-unresolved td { background: var(--предупреждение); }
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.subtabs button.active { color: #fff; border-color: var(--основной); background: var(--основной); }
.word-section-panel { display: none; }
.word-section-panel.active { display: block; }
.panel { display: none; }
.panel.active { display: block; }
.confirmation { margin-top: 14px; padding: 12px; border: 1px solid #b8ccc4; border-radius: 7px; background: #fbfefd; }
.confirmation label { display: flex; gap: 8px; align-items: flex-start; margin: 0; font-weight: 500; }
.confirmation input { width: auto; margin-top: 3px; }
.catalog-compare { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--линия); }
.state-new, .state-image_update { color: var(--основной); font-weight: 600; }
.state-duplicate { color: #704d00; font-weight: 600; }
.state-conflict, .state-invalid { color: #9a2117; font-weight: 600; }
.word-copy-table { width: 100%; table-layout: fixed; }
.word-copy-table td { overflow-wrap: anywhere; }
.word-copy-header td { background: #eef5f2; font-weight: 700; }
.word-copy-number { width: 38px; text-align: center; }
.word-copy-article { width: 118px; }
.word-copy-photo-cell { width: 156px; text-align: center; vertical-align: middle; }
.word-copy-days { width: 125px; text-align: center; }
.catalog-word-image { display: block; max-width: 132px; max-height: 108px; margin: 0 auto; object-fit: contain; }
.quote-note-cell { white-space: pre-line; }
.word-column-visibility { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin: 12px 0 0; padding: 8px 12px; border: 1px solid var(--линия); border-radius: 7px; }
.word-column-visibility legend { padding: 0 4px; font-weight: 600; }
.word-column-visibility label { display: flex; gap: 6px; align-items: center; margin: 0; font-weight: 500; }
.word-column-visibility input { width: auto; margin: 0; }
.word-catalog-search { margin: 14px 0; padding: 12px; border: 1px solid var(--линия); border-radius: 7px; background: #fbfefd; }
.word-catalog-search label { margin-top: 0; }
.word-catalog-search input { max-width: 620px; }
.word-catalog-search .small { margin: 7px 0 0; }
.word-article-with-edit { display: flex; align-items: center; gap: 6px; }
.word-edit-card { flex: 0 0 auto; padding: 2px 7px; border-color: #a9c2b8; font-size: 17px; line-height: 1; }
.word-sort-control { margin-left: 4px; padding: 1px 5px; border-color: #a9c2b8; font-size: 14px; line-height: 1; }
.copy-selection-stage { position: fixed; top: 0; left: -20000px; width: 1100px; pointer-events: none; }
.modal-overlay { position: fixed; z-index: 20; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: #17212b80; }
.modal-dialog { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 20px; border-radius: 10px; background: var(--карточка); box-shadow: 0 18px 48px #102a2566; }
.modal-dialog h2 { margin: 0 0 8px; }
.catalog-reference-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; margin: 16px 0; padding: 0 12px 12px; border: 1px solid var(--линия); border-radius: 7px; }
.catalog-reference-fields legend { padding: 0 4px; font-weight: 600; }
.catalog-reference-fields label { min-width: 0; }
.modal-heading { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.modal-heading > button { flex: 0 0 auto; min-width: 36px; padding: 3px 9px; font-size: 22px; line-height: 1.1; }
.import-details-dialog { width: min(1120px, 100%); }
.import-delete-dialog { width: min(1120px, 100%); }
.import-offer-editor, .import-price-list, .import-price-editor { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--линия); }
.import-offer-editor h3, .import-price-list h3, .import-price-editor h3 { margin-bottom: 4px; }
.import-positions-wrap { max-height: 380px; }
.import-delete-positions { max-height: 380px; }
.delete-import-warning { margin: 16px 0; padding: 12px; color: #9a2117; border: 1px solid #d9aaa5; border-radius: 7px; background: #fff3f1; }
.import-source-button { width: 100%; border: 0; border-radius: 0; padding: 0; color: var(--основной); background: transparent; font-weight: 700; text-align: left; }
.import-source-button:hover { text-decoration: underline; filter: none; }
tr.last-opened-import td { background: var(--предупреждение); }
.import-list-actions { white-space: nowrap; }
.import-list-actions button { padding: 3px 8px; font-size: 13px; line-height: 1.2; }
.import-position-actions { white-space: nowrap; }
.import-position-actions button { padding: 3px 7px; font-size: 15px; line-height: 1.1; }
button.danger { color: #9a2117; border-color: #d9aaa5; background: #fff7f6; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
/* Узкая форма входа расширена на те же 10 %, что и весь рабочий интерфейс. */
.login-wrap { width: min(581px, 100%); }
.login-card h1 { margin-top: 0; }

@media (max-width: 600px) {
  header { display: block; padding: 18px 12px; }
  .wrap { padding: 0 12px; }
  .row > * { flex-basis: 100%; }
  .toast { top: 12px; right: 12px; left: 12px; }
  .catalog-reference-fields { grid-template-columns: 1fr; }
}

/* До сужения карточек ввода и настроек складываем их вертикально, сохраняя
   удобочитаемость переключателей и отсутствие горизонтальной прокрутки. */
@media (max-width: 1100px) {
  .quote-top-layout { grid-template-columns: 1fr; }
}
