/* Автоматизатор КП (/kp). Только переменные темы из style.css — светлая/тёмная подхватываются сами. */
[hidden] { display: none !important; }

.kp-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.kp-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
}
@media (max-width: 900px) {
    .kp-two-col { grid-template-columns: 1fr; }
}
.kp-pad { padding: 0 18px; }

/* --- загрузка файла --- */
.kp-drop {
    display: block;
    border: 2px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.kp-drop:hover, .kp-drop.drag { border-color: var(--accent); background: var(--panel-2); }
.kp-drop-title { font-weight: 700; color: var(--ink); }
.kp-drop-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.kp-file-status { margin-top: 10px; font-size: 13px; color: var(--ink); }
.kp-file-status .kp-err, .kp-err { color: #e0574a; font-weight: 600; }
.kp-ok { color: #3fae5a; font-weight: 600; }

/* --- раскладка столбцов --- */
.kp-map-controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin: 10px 0; }
.kp-legend { display: flex; flex-wrap: wrap; gap: 6px; }
.kp-chip { font-size: 11px; padding: 3px 8px; border-radius: 10px; font-weight: 600; color: #fff; }
.kp-role-name  { --kp-role: #4a7bd0; }
.kp-role-qty   { --kp-role: #2e9a5b; }
.kp-role-unit  { --kp-role: #8a5cc7; }
.kp-role-price { --kp-role: #d0822b; }
.kp-role-sum   { --kp-role: #b0475c; }
.kp-chip[class*="kp-role-"] { background: var(--kp-role); }

.kp-grid-wrap {
    overflow: auto;
    max-height: 460px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.kp-grid { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.kp-grid th, .kp-grid td {
    border: 1px solid var(--border);
    padding: 3px 6px;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
}
.kp-grid thead th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); }
.kp-grid thead tr.kp-letters th { top: 0; font-weight: 600; color: var(--text-muted); text-align: center; }
.kp-grid thead tr.kp-selects th { top: 23px; padding: 3px; }
.kp-grid select {
    width: 100%;
    min-width: 110px;
    font-size: 12px;
    padding: 3px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--ink);
}
.kp-grid select.kp-has-role { border-color: var(--kp-role); background: var(--kp-role); color: #fff; font-weight: 600; }
.kp-grid td.kp-rownum {
    position: sticky; left: 0; z-index: 1;
    background: var(--panel-2); color: var(--text-muted);
    text-align: right; cursor: pointer; user-select: none;
}
.kp-grid td.kp-rownum:hover { color: var(--accent); }
.kp-grid td.kp-col-role { box-shadow: inset 3px 0 0 var(--kp-role); }
.kp-grid tr.kp-before td:not(.kp-rownum) { opacity: .45; }
.kp-grid tr.kp-start td { border-top: 2px solid var(--accent); }
.kp-grid tr.kp-start td.kp-rownum { color: var(--accent); font-weight: 700; }
.kp-grid tr.kp-skip td:not(.kp-rownum) { text-decoration: line-through; color: var(--text-muted); }
.kp-grid td.kp-num { text-align: right; }

.kp-extract-summary { margin-top: 12px; font-size: 14px; color: var(--ink); }
.kp-skipped { margin-top: 8px; font-size: 13px; }
.kp-skipped summary { cursor: pointer; color: var(--text-muted); }
.kp-skipped-table { margin-top: 8px; }

/* --- формы --- */
.kp-form { display: flex; flex-direction: column; gap: 14px; }
.kp-form .input-group { display: flex; flex-direction: column; gap: 6px; }
.kp-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kp-btn-sm { margin-left: 0; padding: 7px 10px; }
.kp-btn-danger { border-color: #e0574a; color: #e0574a; }
.kp-manager-contacts { font-size: 12px; color: var(--text-muted); white-space: pre-line; }
.kp-manager-form { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }
.kp-confirm { font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--ink); }
.kp-check { display: flex; gap: 8px; align-items: center; cursor: pointer; color: var(--ink); font-size: 14px; }
.kp-check input { width: 18px; height: 18px; accent-color: var(--accent); }

.kp-btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 22px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.kp-btn-primary:hover { background: var(--accent-dark); }
.kp-btn-primary:disabled { opacity: .6; cursor: wait; }

/* --- таблицы предпросмотра --- */
.kp-preview-wrap { overflow: auto; max-height: 560px; }
.kp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kp-table th, .kp-table td { border-bottom: 1px solid var(--border); padding: 6px 10px; text-align: left; color: var(--ink); vertical-align: middle; }
.kp-table thead th { position: sticky; top: 0; background: var(--panel-2); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; z-index: 1; }
.kp-preview-table td:nth-child(1), .kp-preview-table td:nth-child(3),
.kp-preview-table td:nth-child(5), .kp-preview-table td:nth-child(6) { text-align: right; white-space: nowrap; }
.kp-preview-table input {
    width: 100px;
    text-align: right;
    font-size: 13px;
    padding: 4px 6px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--ink);
}
.kp-preview-table input:focus { outline: none; border-color: var(--accent); }
.kp-preview-table tr.kp-no-price td { background: rgba(224, 87, 74, .12); }
.kp-merged-note { font-size: 11px; color: var(--text-muted); }

.kp-warnings { padding: 0 18px; }
.kp-warnings div { margin-top: 10px; padding: 8px 12px; border-left: 3px solid #e0a03a; background: var(--panel-2); font-size: 13px; color: var(--ink); }
.kp-totals { padding: 14px 18px; border-top: 1px solid var(--border); font-size: 14px; color: var(--ink); line-height: 1.6; }
.kp-totals b { font-size: 16px; }
.kp-totals .kp-words { color: var(--text-muted); font-style: italic; }
.kp-actions { padding: 0 18px 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.kp-gen-status { font-size: 13px; color: var(--text-muted); }
.kp-result { margin: 0 18px 18px; padding: 14px; border: 1.5px solid #3fae5a; border-radius: var(--radius); color: var(--ink); }
.kp-result .kp-dl { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.kp-dl a {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    color: var(--ink);
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
}
.kp-dl a:hover { border-color: var(--accent); color: var(--accent); }
.kp-dl a.kp-dl-main { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kp-hist-dl a { margin-right: 8px; font-size: 12px; color: var(--ink); }
.kp-manager-form-title { font-weight: 700; color: var(--ink); font-size: 13px; }
.kp-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.kp-field-hint { font-size: 12px; color: var(--text-muted); }

/* --- закупка, доп. расходы, наценка по строкам --- */
.kp-preview-table td:nth-child(7), .kp-preview-table td:nth-child(8), .kp-preview-table td:nth-child(9) { text-align: right; white-space: nowrap; }
.kp-preview-table td:nth-child(5), .kp-preview-table td:nth-child(6) { font-size: 12px; }
.kp-preview-table input.kp-in-pct { width: 64px; }
.kp-preview-table input.kp-own { border-color: #d0822b; background: rgba(208, 130, 43, .10); }
.kp-preview-table input:disabled { opacity: .55; }
.kp-muted { color: var(--text-muted) !important; }
.kp-nowrap { white-space: nowrap; }
.kp-num { text-align: right; white-space: nowrap; }
.kp-mini {
    font-size: 11px;
    padding: 3px 7px;
    margin-left: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}
.kp-mini:hover { border-color: var(--accent); color: var(--accent); }
.kp-extras { margin: 14px 18px 0; border: 1.5px dashed #d0822b; border-radius: var(--radius-sm); overflow: auto; }
.kp-extras-title { padding: 8px 12px; font-weight: 700; font-size: 13px; color: var(--ink); background: rgba(208, 130, 43, .10); }
.kp-extras-table td { vertical-align: top; }
.kp-target summary { cursor: pointer; color: var(--accent); font-weight: 600; white-space: nowrap; }
.kp-pick-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 220px; overflow: auto; min-width: 260px; }
.kp-pick-hint { font-size: 11px; color: var(--text-muted); }
.kp-pick { font-size: 12px; display: flex; gap: 6px; align-items: flex-start; cursor: pointer; color: var(--ink); }
.kp-pick input { accent-color: var(--accent); margin-top: 2px; }
.kp-calc {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 26px;
    padding: 12px 18px 0;
    font-size: 13px;
    color: var(--ink);
}
.kp-calc:empty { display: none; }
.kp-calc > div { display: flex; flex-direction: column; }
.kp-calc span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.kp-calc b { font-size: 15px; }
.kp-calc .kp-profit b { color: #3fae5a; }
.kp-calc .kp-loss b { color: #e0574a; }
.kp-calc .kp-err { flex-basis: 100%; }
.kp-incl { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; white-space: nowrap; }
.kp-incl input { accent-color: var(--accent); margin: 0; width: auto; }
.kp-preview-table tr.kp-excluding td { opacity: .4; }
.kp-excluded { margin: 14px 18px 0; border: 1.5px dashed var(--text-muted); border-radius: var(--radius-sm); overflow: auto; }
.kp-excluded > summary { padding: 8px 12px; font-weight: 700; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.kp-excluded-table td { color: var(--text-muted); text-decoration: line-through; }
.kp-excluded-table td:first-child { text-decoration: none; }
.kp-excluded-table td:nth-child(3), .kp-excluded-table td:nth-child(5), .kp-excluded-table td:nth-child(6) { text-align: right; white-space: nowrap; }
