:root {
  --blue: #1f4e8c;
  --blue-2: #2f66b3;
  --bg: #f4f6fa;
  --panel: #fff;
  --line: #d7deea;
  --muted: #6a7386;
  --ok: #2e9e5b;
  --warn: #d98b17;
  --err: #cc3b3b;
  --ink: #1b2333;
  --chip: #eef2f8;
  --chip-on: #2f66b3;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h2, h3 { margin: 0; }

/* Шапка */
.topbar { display: flex; align-items: center; gap: 28px; background: var(--blue); color: #fff; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 5; }
.brand { font-size: 18px; font-weight: 600; white-space: nowrap; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tab { border: none; background: none; color: #c9d7ee; padding: 0 16px; cursor: pointer; font-size: 15px; border-bottom: 3px solid transparent; }
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: #fff; }
.pane { display: none; }
.pane.active { display: block; }

/* Кнопки и поля */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 14px; text-decoration: none; white-space: nowrap; font-family: inherit; }
.btn:hover { background: #eef2f8; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--blue-2); color: #fff; border-color: var(--blue-2); }
.btn-primary:hover { background: var(--blue); }
.btn-link { border: none; background: none; color: var(--blue-2); padding: 4px 0; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.icon-btn { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--chip); color: var(--ink); }
.input { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; font: inherit; background: #fff; color: var(--ink); }
.input:focus { outline: 2px solid #b9cdef; border-color: var(--blue-2); }
textarea.input { resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label .input, label .with-btn { margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); margin: 4px 0; cursor: pointer; }

/* Раскладка списка */
.layout { display: flex; min-height: calc(100vh - 52px); }
.filters { width: 290px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 16px; position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto; }
.f-block { margin: 16px 0; }
.f-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 10px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1px solid var(--line); background: var(--chip); color: var(--ink); border-radius: 14px; padding: 3px 10px; font-size: 13px; cursor: pointer; user-select: none; font-family: inherit; }
.chip:hover { border-color: var(--blue-2); }
.chip.on { background: var(--chip-on); border-color: var(--chip-on); color: #fff; }
.chip .n { opacity: .6; font-size: 11px; margin-left: 3px; }
.content { flex: 1; min-width: 0; padding: 16px 20px; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.found { font-size: 15px; font-weight: 600; }
.list-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Таблица */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #f8fafd; white-space: nowrap; }
.grid td { padding: 9px 10px; border-bottom: 1px solid #edf1f7; vertical-align: top; }
#supplierRows tr { cursor: pointer; }
#supplierRows tr:hover td { background: #f5f8fd; }
#supplierRows tr.inactive td { color: #98a0b0; }
.s-name { font-weight: 600; }
.s-site { font-size: 12px; color: var(--muted); }
.warn-dot { color: var(--warn); margin-left: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 3px; max-width: 360px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 9px; background: var(--chip); white-space: nowrap; }
.tag.m { background: #e3ecf9; color: #1f4e8c; }
.tag.t { background: #e8f4ec; color: #22693f; }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; color: #fff; white-space: nowrap; }
.badge.maker { background: var(--ok); }
.badge.dealer { background: #8391a8; }
.badge.raw { background: #a77b3d; }
.badge.unknown { background: #b9c1cf; }
.badge.pause { background: var(--warn); }
.badge.inactive { background: #98a0b0; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Карточка */
.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(20, 30, 50, .35); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--bg); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 20px; }
.drawer-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 20px; background: var(--panel); border-top: 1px solid var(--line); }
.msg { margin-right: auto; font-size: 13px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 6px; margin-bottom: 12px; }
.section h3 { font-size: 15px; margin-bottom: 8px; }
.section .chips { margin-bottom: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.with-btn { display: flex; gap: 6px; }
.contact-row { display: grid; grid-template-columns: 1.2fr 1fr 1.2fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.review { background: #fff7e8; border: 1px solid #f0d49c; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.review b { display: block; margin-bottom: 4px; }
.review li { margin: 2px 0; }
.review .done { margin-left: 6px; }
.source summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.source table { font-size: 12px; margin-bottom: 10px; }
.source td { padding: 3px 6px; border-bottom: 1px solid #edf1f7; }
.source td:first-child { color: var(--muted); white-space: nowrap; }

/* Окно обхода сайта */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(20, 30, 50, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; padding: 18px 20px; width: min(820px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.scan-grid td { font-size: 13px; }
.scan-grid td:nth-child(3) { color: var(--muted); }

/* Справочник */
.settings, .placeholder { max-width: 900px; margin: 24px auto; padding: 0 16px; }
.placeholder { text-align: center; color: var(--muted); }
.hint { color: var(--muted); }
.settings-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tag-editor { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.tag-editor h3 { margin-bottom: 10px; }
.tag-row { display: flex; gap: 4px; margin-bottom: 5px; }
.tag-row .n { color: var(--muted); font-size: 12px; align-self: center; min-width: 34px; text-align: right; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 40; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .filters { width: auto; position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .row2, .settings-cols { grid-template-columns: 1fr; }
  .contact-row { grid-template-columns: 1fr 1fr; }
  .topbar { gap: 10px; overflow-x: auto; }
}

/* Запросы КП */
.req-wrap { max-width: 1400px; margin: 0 auto; padding: 16px 20px; }
.req-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.req-side { position: sticky; top: 64px; max-height: calc(100vh - 76px); overflow-y: auto; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.item-head h3 { margin-bottom: 0; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 10px; }
.file { background: var(--chip); border-radius: 7px; padding: 2px 4px 2px 10px; font-size: 13px; }
.file .icon-btn { font-size: 13px; padding: 2px 6px; }
#addItem { margin-bottom: 12px; }
.cands { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.cand { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink); margin: 0; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.cand:hover { background: #f5f8fd; }
.cand input { margin-top: 3px; }
#candSearch { margin-bottom: 6px; }
details summary.f-title { cursor: pointer; }
textarea.letter, .letter-view { font-family: Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.45; }
.letter-view { white-space: pre-wrap; background: #f8fafd; border: 1px solid var(--line); border-radius: 7px; padding: 10px; margin: 0 0 10px; }
.err-text { color: var(--err); font-size: 12px; }
.badge.st-draft { background: #8391a8; }
.badge.st-sending { background: var(--warn); }
.badge.st-sent { background: var(--blue-2); }
.badge.st-chosen { background: var(--ok); }
.badge.st-closed { background: #98a0b0; }
.rec { font-size: 12px; padding: 1px 7px; border-radius: 9px; background: var(--chip); }
.rec-sent { background: #e8f4ec; color: #22693f; }
.rec-queued { background: #fff3dc; color: #8a5a0c; }
.rec-error { background: #fbe5e5; color: var(--err); }
.rec-cancelled { color: var(--muted); }
#reqRows tr { cursor: pointer; }
#reqRows tr:hover td { background: #f5f8fd; }
@media (max-width: 1100px) {
  .req-grid { grid-template-columns: 1fr; }
  .req-side { position: static; max-height: none; }
  .row5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .row3, .row5 { grid-template-columns: 1fr 1fr; }
}
.req-main, .req-side { min-width: 0; }
@media (max-width: 700px) {
  .req-wrap { padding: 12px; }
  .with-btn { flex-wrap: wrap; }
  .grid td, .grid th { padding: 7px 6px; }
}

/* Клиенты */
.subnav { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 14px; }
.subtab { border: none; background: none; padding: 9px 14px; cursor: pointer; font-size: 14px; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; font-family: inherit; }
.subtab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.tab-badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #fff; color: var(--blue); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.tab-badge.dark { background: var(--err); color: #fff; }
.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 34px; margin-bottom: 8px; }
.badge.st-err { background: var(--err); }
.letter-item { border-top: 1px solid #edf1f7; padding: 8px 0; }
.letter-item summary { cursor: pointer; font-size: 13px; }
.letter-item .letter-view { margin-top: 8px; }
.section.reply .item-head { flex-wrap: wrap; }
.section.reply .list-actions .input { flex: 1; min-width: 200px; }
#clientRows tr { cursor: pointer; }
#clientRows tr:hover td { background: #f5f8fd; }
#clientRows tr.inactive td { color: #98a0b0; }

/* Разбор запроса и сравнение предложений */
#newReqText { width: 100%; resize: vertical; font-family: inherit; }
.source-text { white-space: pre-wrap; background: #f8fafd; border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; margin: 6px 0 10px; font-size: 13px; }
.verdict { font-size: 15px; font-weight: 600; margin: 4px 0 6px; }
.cmp-title { font-weight: 600; margin: 14px 0 4px; }
.cmp td.num, .cmp th.num { text-align: right; white-space: nowrap; }
.cmp tr.best td { background: #eaf6ee; }
.cmp tr.alt td { color: var(--muted); }
.cmp .flags { font-size: 12px; color: #8a5a0c; }
.offer { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; font-size: 13px; }
.offer .grid td, .offer .grid th { padding: 5px 8px; }
.warn { color: #8a5a0c; }
.ok { color: var(--ok); }
.offer-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.offer input.input, .offer select.input { padding: 3px 6px; font-size: 13px; width: auto; }

/* Рейтинг поставщиков */
#ratingBox summary { cursor: pointer; list-style: none; display: flex; gap: 12px; align-items: baseline; padding-bottom: 8px; }
#ratingBox summary::-webkit-details-marker { display: none; }
#ratingBox summary h3::before { content: '▸ '; color: var(--muted); }
#ratingBox[open] summary h3::before { content: '▾ '; }
.star { color: #c88a00; font-weight: 600; white-space: nowrap; }

/* Почтовые ящики */
#boxesBox { margin-bottom: 12px; }
#boxesBox summary { cursor: pointer; list-style: none; display: flex; gap: 12px; align-items: baseline; padding-bottom: 8px; }
#boxesBox summary::-webkit-details-marker { display: none; }
#boxesBox summary h3::before { content: '▸ '; color: var(--muted); }
#boxesBox[open] summary h3::before { content: '▾ '; }
.box-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin: 10px 0; }
.box-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.box-form .input { width: 220px; }
.st-active { color: var(--ok); }
.st-paused { color: #8a5a0c; }
.st-error { color: var(--err); }

/* Просчёт по истории в карточке позиции */
.item-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.est-box { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line, #dfe3ea); border-radius: 8px; background: #f8fafc; }
.est-head { font-weight: 600; margin-bottom: 6px; }
.est-box table { margin-top: 8px; }
.est-box .check { font-weight: 400; }
label.wide { grid-column: 1 / -1; }
label .hint { display: block; margin-top: 2px; }

/* вход и смена пароля (11.11.2026) */
.auth-actions { margin-left: auto; display: flex; gap: 6px; }
.pw-dialog { border: 1px solid var(--line); border-radius: 10px; padding: 22px; width: 340px; }
.pw-dialog::backdrop { background: rgba(20, 30, 50, .35); }
.pw-dialog h3 { margin: 0 0 14px; }
.pw-dialog label { display: block; margin: 0 0 10px; }
.pw-dialog .input { margin-top: 4px; }
/* ответ поставщику */
.reply-form { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; background: #fafcff; }
.reply-form textarea { min-height: 120px; }
.reply-form .row { display: flex; gap: 8px; margin-bottom: 8px; }
.reply-sent { margin-top: 6px; font-size: 13px; }
.reply-preview { white-space: pre-wrap; font-size: 12px; background: #f4f6fa; padding: 8px; border-radius: 6px; max-height: 260px; overflow: auto; }
