/* =====================================================
   components.css — переиспользуемые UI-компоненты (модуль)
   Подключается отдельным <link> после base.css.
   Новые компоненты по ТЗ кладём сюда, не раздувая base.css.
   ===================================================== */

/* -----------------------------------------------------
   Панель массовых действий (единая для всех списков)
   ----------------------------------------------------- */
.bulk-bar {
    position: sticky;
    top: calc(var(--appbar-h) + 44px);   /* под appbar + субтабами */
    z-index: 15;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    padding: 8px 12px;
    margin-bottom: 14px;
    background: var(--card);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}
.bulk-bar .bulk-count {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding-right: 6px;
}
.bulk-bar .bulk-count .num {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.bulk-bar select {
    padding: 6px 11px;
    font-size: 13px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    min-height: 32px;
}
.bulk-bar .bulk-spacer { flex: 1; }

/* -----------------------------------------------------
   Хлебные крошки
   ----------------------------------------------------- */
.crumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); text-decoration: none; }
.crumbs .sep { color: var(--muted-2); }
.crumbs .current { color: var(--text-soft); font-weight: 600; }

/* -----------------------------------------------------
   Сортируемые заголовки таблиц
   ----------------------------------------------------- */
.table thead th.sortable a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    font: inherit;
}
.table thead th.sortable a:hover { color: var(--primary); text-decoration: none; }
.table thead th .sort-arrow { font-size: 9px; opacity: 0.9; }
.table thead th.sorted a { color: var(--primary); }

/* -----------------------------------------------------
   Грид строк документа (№, Код/Артикул/Наименование, итоги, выбор колонок)
   ----------------------------------------------------- */
.li-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.li-cols { position: relative; }
.li-cols-btn {
    border: 1px solid var(--border-strong); background: var(--card); color: var(--text-soft);
    border-radius: 8px; padding: 6px 11px; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.li-cols-btn:hover { border-color: var(--muted-2); }
.li-cols-menu {
    display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 25;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg); padding: 8px; min-width: 170px;
}
.li-cols-menu.open { display: block; }
.li-cols-menu label {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px;
    font-size: 13px; color: var(--text-soft); cursor: pointer;
}
.li-cols-menu label:hover { background: var(--bg-soft); }
.li-cols-menu input { accent-color: var(--primary); }

/* Номер позиции и авто-ячейки (Код/Артикул) — read-only вид */
.lines-table .col-num { width: 38px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.lines-table .li-code, .lines-table .li-sku {
    color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.lines-table .col-code { width: 90px; }
.lines-table .col-sku { width: 110px; }
.lines-table .li-sum { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.lines-table .li-cell { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Итоговая строка */
.lines-table tfoot td {
    border-top: 2px solid var(--border-strong); background: var(--bg-soft);
    padding: 10px 12px; font-size: 13px;
}
.lines-table tfoot .col-name { font-weight: 600; color: var(--text-soft); }
.lines-table tfoot .li-total-qty,
.lines-table tfoot .li-total-sum,
.lines-table tfoot .li-total-weight { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* Скрытие колонок по выбору пользователя */
.lines-table.hide-col-code .col-code,
.lines-table.hide-col-sku .col-sku,
.lines-table.hide-col-sum .col-sum,
.lines-table.hide-col-barcode .col-barcode,
.lines-table.hide-col-unit .col-unit,
.lines-table.hide-col-category .col-category,
.lines-table.hide-col-country .col-country,
.lines-table.hide-col-tnved .col-tnved,
.lines-table.hide-col-weight .col-weight,
.lines-table.hide-col-volume .col-volume,
.lines-table.hide-col-vat .col-vat,
.lines-table.hide-col-purchase .col-purchase,
.lines-table.hide-col-cost .col-cost,
.lines-table.hide-col-sale .col-sale,
.lines-table.hide-col-retail .col-retail,
.lines-table.hide-col-wholesale .col-wholesale,
.lines-table.hide-col-minprice .col-minprice { display: none; }

/* -----------------------------------------------------
   Формат таблицы позиций «как в МойСкладе» — вид электронной таблицы:
   сетка из тонких линий, безрамочные поля ввода во всю ячейку.
   ----------------------------------------------------- */
.lines-table { border-radius: 10px; }
/* вертикальные линии-сетка между колонками */
.lines-table th, .lines-table td { border-right: 1px solid var(--border); }
.lines-table th:last-child, .lines-table td:last-child { border-right: none; }
/* горизонтальные линии */
.lines-table tbody td { border-bottom: 1px solid var(--border); padding: 0; vertical-align: middle; }
.lines-table thead th { padding: 7px 10px; vertical-align: middle; }

/* статические ячейки (№, Код, Артикул, Сумма, доп. поля) — со своим паддингом */
.lines-table td.col-num,
.lines-table td.li-code,
.lines-table td.li-sku,
.lines-table td.li-sum,
.lines-table td.li-cell { padding: 6px 10px; }

/* поля ввода — без рамок, во всю ячейку (как ячейка таблицы) */
.lines-table tbody td input,
.lines-table tbody td select {
    border: none; border-radius: 0; background: transparent;
    width: 100%; padding: 8px 10px; min-height: 36px; box-shadow: none;
    font-size: 13px;
}
.lines-table tbody td input:focus,
.lines-table tbody td select:focus {
    outline: 2px solid var(--primary); outline-offset: -2px;
    background: var(--card); box-shadow: none;
}
.lines-table td.num input { text-align: right; }
.lines-table tbody tr.line-row:hover td { background: #fafbfc; }
.lines-table tbody tr.line-row:focus-within td { background: #fafbfc; }

/* кнопка удаления строки в ячейке-сетке */
.lines-table td.del { padding: 0; }

/* итоговая строка тоже в сетке */
.lines-table tfoot td { border-right: 1px solid var(--border); }
.lines-table tfoot td:last-child { border-right: none; }

/* Убрать стрелки-спиннеры у числовых полей (Кол-во, Цена и т.п.) */
.lines-table input[type="number"]::-webkit-outer-spin-button,
.lines-table input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.lines-table input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* -----------------------------------------------------
   Кастомный автоподбор товара (строго под полем)
   ----------------------------------------------------- */
.li-suggest {
    position: fixed; z-index: 9999; display: none;
    background: var(--card); border: 1px solid var(--border-strong);
    border-radius: 10px; box-shadow: var(--shadow-lg);
    max-height: 300px; overflow-y: auto; padding: 4px; min-width: 240px;
}
.li-suggest-item {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.li-suggest-item:hover { background: var(--primary-soft); }
.li-suggest-item .ls-name { color: var(--text); }
.li-suggest-item .ls-sku { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* -----------------------------------------------------
   Полировка списочных таблиц: поиск, плотность, липкая шапка
   ----------------------------------------------------- */
.table-enhanced thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    box-shadow: 0 1px 0 var(--border-strong);
}

.table-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin: 8px 0 8px;
    flex-wrap: wrap;
}
.table-tools-left,
.table-tools-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.table-filter {
    width: min(280px, 70vw);
    padding: 7px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}
.table-filter:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.table-count {
    color: var(--muted);
    font-size: 12.5px;
    white-space: nowrap;
}
.table-tool-btn {
    border: 1px solid var(--border-strong);
    background: var(--card);
    color: var(--text-soft);
    border-radius: 8px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 12.5px;
    cursor: pointer;
    white-space: nowrap;
}
.table-tool-btn:hover,
.table-tool-btn[aria-pressed="true"] {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}
.table.table-compact thead th {
    padding: 6px 10px;
    font-size: 10px;
    line-height: 1.15;
}
.table.table-compact tbody td {
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.2;
}
.table.table-compact thead th:first-child,
.table.table-compact tbody td:first-child {
    padding-left: 12px;
}
.table.table-compact thead th:last-child,
.table.table-compact tbody td:last-child {
    padding-right: 12px;
}
.table.table-compact .badge {
    padding: 2px 6px;
    font-size: 10.5px;
    line-height: 1.15;
}
.table.table-compact .cell-sub {
    margin-top: 1px;
    font-size: 11px;
}
.table.table-compact .cell-stack {
    gap: 2px;
}
.table.table-compact .actions a {
    min-height: 26px;
    padding: 4px 8px;
    margin-left: 3px;
    font-size: 12px;
}
.table.table-compact input[type="checkbox"] {
    width: 14px;
    height: 14px;
}
.table.table-compact img {
    max-width: 34px;
    max-height: 34px;
    object-fit: cover;
}
.table.table-compact .thumb {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

/* -----------------------------------------------------
   Массовые действия в один клик (кнопки + меню, как в МойСкладе)
   ----------------------------------------------------- */
.bulk-act {
    border: 1px solid var(--border-strong); background: var(--card); color: var(--text-soft);
    border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 500; cursor: pointer;
    font-family: inherit; white-space: nowrap; transition: all var(--t-fast) var(--ease);
}
.bulk-act:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.bulk-act.bulk-danger:hover { border-color: var(--error); color: var(--error); background: var(--error-soft); }
.bulk-pop { position: relative; }
.bulk-menu {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 30;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg); padding: 5px; min-width: 190px; max-height: 320px; overflow-y: auto;
    display: flex; flex-direction: column;
}
.bulk-menu button {
    text-align: left; border: none; background: transparent; color: var(--text-soft);
    padding: 8px 11px; border-radius: 7px; font-size: 13px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.bulk-menu button:hover { background: var(--primary-soft); color: var(--primary); }
.bulk-menu .bulk-menu-clear { border-top: 1px solid var(--border); margin-top: 4px; color: var(--muted); }
.bulk-menu-empty { padding: 8px 11px; font-size: 12.5px; color: var(--muted); }
.bulk-clear { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-family: inherit; padding: 6px 10px; }
.bulk-clear:hover { color: var(--text); }

/* -----------------------------------------------------
   Свотчи выбора цвета статуса (форма статуса + цвета встроенных)
   ----------------------------------------------------- */
.color-swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch { position: relative; cursor: pointer; line-height: 0; }
.swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch-dot {
    display: block; width: 30px; height: 30px; border-radius: 50%;
    border: 2px solid transparent; box-shadow: inset 0 0 0 2px #fff;
    transition: transform 120ms var(--ease);
}
.swatch:hover .swatch-dot { transform: scale(1.1); }
.swatch input:checked + .swatch-dot { border-color: var(--text); }
.swatch input:focus-visible + .swatch-dot { outline: 2px solid var(--primary); outline-offset: 2px; }
.swatch-blue   { background: #2563eb; }
.swatch-green  { background: #16a34a; }
.swatch-orange { background: #ea580c; }
.swatch-red    { background: #dc2626; }
.swatch-purple { background: #7c3aed; }
.swatch-gray   { background: #64748b; }

/* Строка «статус → цвет» на странице цветов встроенных статусов */
.sys-row { display: flex; align-items: center; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sys-row:last-child { border-bottom: none; }
.sys-row .sys-label { width: 150px; flex-shrink: 0; font-size: 14px; font-weight: 600; color: var(--text-soft); }

/* Цветовой спектр-пикер (выбор цвета статуса) */
input[type="color"].color-spectrum {
    width: 64px; height: 40px; padding: 3px; cursor: pointer;
    border: 1px solid var(--border-strong); border-radius: 9px; background: var(--card);
}

/* ===== Проверка комплектации (сканер) ===== */
.pk-scanbar {
    display: flex; gap: 16px; align-items: stretch; margin: 8px 0 18px;
    flex-wrap: wrap;
}
.pk-scan-field { flex: 1; min-width: 280px; }
.pk-scan-field label {
    display: block; font-size: 12px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px;
}
#pk-scan {
    width: 100%; font-size: 22px; padding: 14px 18px; font-weight: 600;
    border: 2px solid var(--accent); border-radius: 12px; background: var(--card);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
    outline: none;
}
.pk-feedback {
    flex: 1; min-width: 280px; display: flex; align-items: center;
    padding: 12px 18px; border-radius: 12px; font-size: 16px; font-weight: 600;
    background: var(--surface, #f3f5f9); border: 1px solid var(--border);
}
.pk-fb-ok  { background: #16a34a18; border-color: #16a34a55; color: #15803d; }
.pk-fb-bad { background: #dc262618; border-color: #dc262655; color: #b91c1c; }

.pk-progress { margin-bottom: 16px; }
.pk-progress-bar {
    height: 10px; border-radius: 6px; background: var(--border); overflow: hidden;
}
.pk-progress-bar span {
    display: block; height: 100%; width: 0; background: #16a34a;
    transition: width .25s ease;
}
.pk-progress-text { margin-top: 6px; font-size: 14px; color: var(--muted); }

#pk-table tr.pk-ok    { background: #16a34a0d; }
#pk-table tr.pk-under { background: #f59e0b0d; }
#pk-table tr.pk-over  { background: #dc26260d; }
#pk-table .pk-got { font-weight: 700; }
