/* ==========================================================================
   Комплектация: таблица запчастей

   Одна разметка на все экраны — на узких вьюпортах строки таблицы
   превращаются в карточки средствами CSS, без дублирования DOM.

   Токены наследуются от темы (style.css), чтобы блок не выбивался
   из общего оформления сайта.
   ========================================================================== */

.sp {
    /* палитра темы с запасными значениями */
    --sp-accent: var(--ltn__secondary-color, #e53e29);
    --sp-accent-dark: var(--ltn__secondary-color-2, #cb3421);
    --sp-ink: var(--ltn__primary-color, #071c1f);
    --sp-muted: #71858a;
    --sp-line: var(--border-color-1, #e5eaee);
    --sp-line-soft: #eef2f4;
    --sp-bg-soft: #f6f8f9;

    /* типографика темы */
    --sp-font: var(--ltn__body-font, 'Open Sans', sans-serif);
    --sp-font-head: var(--ltn__heading-font, 'Rajdhani', sans-serif);

    --sp-radius: 12px;
    --sp-shadow: 0 2px 10px rgba(7, 28, 31, .06);

    /* отступ прилипающей шапки таблицы; переопредели, если шапка сайта fixed */
    --sp-sticky-top: 0px;

    font-family: var(--sp-font);
    color: var(--sp-ink);
}

/* ---------- Панель инструментов ---------- */

.sp-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.sp-search {
    position: relative;
    flex: 1 1 280px;
    min-width: 0;
}

.sp-search input {
    width: 100%;
    height: 46px;
    padding: 0 40px;
    border: 1px solid var(--sp-line);
    border-radius: var(--sp-radius);
    background: #fff;
    font-family: var(--sp-font);
    font-size: .95rem;
    line-height: 1.4;
    color: var(--sp-ink);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.sp-search input::placeholder {
    color: var(--sp-muted);
}

.sp-search input:focus {
    border-color: var(--sp-accent);
    box-shadow: 0 0 0 3px rgba(229, 62, 41, .12);
}

.sp-search .sp-search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--sp-muted);
    font-size: .9rem;
    pointer-events: none;
}

.sp-search .sp-search-clear {
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: var(--sp-bg-soft);
    color: var(--sp-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: none;
}

.sp-search .sp-search-clear:hover {
    background: var(--sp-line);
    color: var(--sp-ink);
}

.sp-search.is-filled .sp-search-clear {
    display: block;
}

.sp-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.sp-btn {
    appearance: none;
    border: 1px solid var(--sp-line);
    background: #fff;
    color: var(--sp-ink);
    border-radius: 10px;
    padding: 0 18px;
    height: 46px;
    font-family: var(--sp-font-head);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: .01em;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.sp-btn:hover {
    background: var(--sp-bg-soft);
    border-color: #d3dade;
}

.sp-btn-dark {
    background: var(--sp-ink);
    border-color: var(--sp-ink);
    color: #fff;
}

.sp-btn-dark:hover {
    background: #041113;
    border-color: #041113;
    color: #fff;
}

/* ---------- Таблица ---------- */

/* Прокрутка страничная: внутреннего скролла нет, шапка липнет к вьюпорту */
.sp-table-wrap {
    border: 1px solid var(--sp-line);
    border-radius: var(--sp-radius);
    background: #fff;
    box-shadow: var(--sp-shadow);
    overflow: visible;
}

.sp-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .95rem;
    line-height: 1.5;
    margin: 0;
}

.sp-table thead th {
    position: sticky;
    top: var(--sp-sticky-top);
    z-index: 2;
    background: var(--sp-bg-soft);
    color: var(--sp-ink);
    font-family: var(--sp-font-head);
    font-weight: 700;
    font-size: .9rem;
    letter-spacing: .02em;
    text-transform: uppercase;
    text-align: left;
    padding: 15px 14px;
    border-bottom: 1px solid var(--sp-line);
    white-space: nowrap;
    user-select: none;
}

.sp-table thead th:first-child {
    border-top-left-radius: var(--sp-radius);
}

.sp-table thead th:last-child {
    border-top-right-radius: var(--sp-radius);
}

.sp-table thead th.is-sortable {
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}

.sp-table thead th.is-sortable:hover {
    background: #eaeff1;
    color: var(--sp-accent-dark);
}

.sp-sort-arrow {
    display: inline-block;
    margin-left: 5px;
    opacity: .3;
    font-size: .75rem;
    vertical-align: middle;
}

.sp-table thead th[data-dir] .sp-sort-arrow {
    opacity: 1;
    color: var(--sp-accent);
}

.sp-table tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--sp-line-soft);
    vertical-align: middle;
}

.sp-table tbody tr:last-child td {
    border-bottom: 0;
}

.sp-table tbody tr {
    transition: background .12s ease;
}

.sp-table tbody tr:hover {
    background: #fbfcfc;
}

.sp-table tbody tr.is-chosen {
    background: rgba(229, 62, 41, .04);
}

.sp-table tbody tr.is-chosen:hover {
    background: rgba(229, 62, 41, .07);
}

.sp-col-num {
    width: 82px;
    color: var(--sp-muted);
    font-variant-numeric: tabular-nums;
}

.sp-col-desig {
    width: 200px;
    font-size: .9rem;
    font-variant-numeric: tabular-nums;
    color: #4a5c60;
    word-break: break-word;
}

.sp-col-unit {
    width: 82px;
    text-align: center;
    color: var(--sp-muted);
}

.sp-col-stock {
    width: 120px;
    text-align: center;
}

.sp-col-qty {
    width: 158px;
    text-align: center;
}

.sp-name {
    font-weight: 500;
    line-height: 1.45;
}

/* Заголовок раздела внутри таблицы */
.sp-section-row td {
    background: var(--sp-bg-soft);
    font-family: var(--sp-font-head);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--sp-ink);
    padding: 12px 14px;
    border-bottom: 1px solid var(--sp-line);
    border-top: 1px solid var(--sp-line);
}

/* «Положено содержать» — кликабельная пилюля */
.sp-stock-pill {
    appearance: none;
    border: 1px solid var(--sp-line);
    background: #fff;
    color: var(--sp-ink);
    border-radius: 999px;
    padding: 6px 14px;
    font-family: var(--sp-font);
    font-size: .9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.sp-stock-pill:hover {
    border-color: var(--sp-accent);
    background: rgba(229, 62, 41, .06);
    color: var(--sp-accent-dark);
}

/* ---------- Счётчик количества ---------- */

.sp-qty {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--sp-line);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    height: 42px;
}

.sp-qty-btn {
    appearance: none;
    border: 0;
    width: 38px;
    background: var(--sp-bg-soft);
    color: #4a5c60;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}

.sp-qty-btn:hover {
    background: var(--sp-line);
    color: var(--sp-ink);
}

.sp-qty-btn:active {
    background: #d9e0e3;
}

.sp-qty-input {
    width: 58px;
    border: 0;
    border-left: 1px solid var(--sp-line);
    border-right: 1px solid var(--sp-line);
    text-align: center;
    font-family: var(--sp-font);
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--sp-ink);
    background: transparent;
    outline: none;
    -moz-appearance: textfield;
}

.sp-qty-input::-webkit-outer-spin-button,
.sp-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sp-qty-input:focus {
    background: rgba(229, 62, 41, .05);
}

.sp-qty.is-active {
    border-color: var(--sp-accent);
}

.sp-qty.is-active .sp-qty-input {
    color: var(--sp-accent-dark);
}

/* ---------- Пустые состояния ---------- */

.sp-empty {
    padding: 52px 16px;
    text-align: center;
    color: var(--sp-muted);
    font-size: .95rem;
}

.sp-empty i {
    font-size: 2rem;
    display: block;
    margin-bottom: 12px;
    opacity: .45;
}

/* ---------- Итоговая панель ---------- */

.sp-summary {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-top: 20px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, .97);
    backdrop-filter: blur(6px);
    border: 1px solid var(--sp-line);
    border-radius: var(--sp-radius);
    box-shadow: 0 -4px 18px rgba(7, 28, 31, .07);
}

.sp-summary-stat {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.sp-summary-stat b {
    font-family: var(--sp-font-head);
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--sp-ink);
}

.sp-summary-stat span {
    font-size: .8rem;
    color: var(--sp-muted);
}

.sp-summary-divider {
    width: 1px;
    align-self: stretch;
    background: var(--sp-line);
}

.sp-submit {
    appearance: none;
    margin-left: auto;
    border: 0;
    border-radius: var(--sp-radius);
    background: var(--sp-accent);
    color: #fff;
    font-family: var(--sp-font-head);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: .02em;
    padding: 13px 36px;
    cursor: pointer;
    transition: background .18s ease, transform .1s ease, opacity .18s ease;
}

.sp-submit:hover:not(:disabled) {
    background: var(--sp-accent-dark);
}

.sp-submit:active:not(:disabled) {
    transform: translateY(1px);
}

.sp-submit:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* ---------- Скрытие при фильтрации ---------- */
/* !important нужен: на мобильных строки переведены в display:block */

.sp .is-hidden {
    display: none !important;
}

/* ==========================================================================
   Мобильная раскладка: строки таблицы становятся карточками
   ========================================================================== */

@media (max-width: 767.98px) {
    .sp-toolbar {
        gap: 10px;
    }

    .sp-toolbar-actions {
        width: 100%;
        margin-left: 0;
    }

    .sp-toolbar-actions .sp-btn {
        flex: 1;
    }

    .sp-table-wrap {
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    .sp-table,
    .sp-table tbody,
    .sp-table tr,
    .sp-table td {
        display: block;
        width: 100%;
    }

    .sp-table thead {
        display: none;
    }

    .sp-table tbody tr {
        border: 1px solid var(--sp-line);
        border-radius: var(--sp-radius);
        background: #fff;
        box-shadow: var(--sp-shadow);
        margin-bottom: 14px;
        padding: 16px;
    }

    .sp-table tbody tr.is-chosen {
        border-color: rgba(229, 62, 41, .5);
        box-shadow: 0 3px 14px rgba(229, 62, 41, .13);
    }

    .sp-table tbody td {
        border: 0;
        padding: 7px 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        text-align: right;
        min-height: 0;
    }

    /* пустое значение — строку не показываем совсем */
    .sp-table tbody td:empty {
        display: none;
    }

    /* подпись колонки слева от значения */
    .sp-table tbody td::before {
        content: attr(data-label);
        flex: 0 1 auto;
        font-family: var(--sp-font-head);
        font-size: .95rem;
        font-weight: 600;
        letter-spacing: .02em;
        color: var(--sp-muted);
        text-align: left;
        white-space: nowrap;
    }

    /* наименование — заголовок карточки, во всю ширину и без подписи */
    .sp-table tbody td.sp-col-name {
        display: block;
        text-align: left;
        padding: 0 0 12px;
        margin-bottom: 10px;
        border-bottom: 1px solid var(--sp-line-soft);
    }

    .sp-table tbody td.sp-col-name::before {
        display: none;
    }

    .sp-table tbody td.sp-col-name .sp-name {
        font-family: var(--sp-font-head);
        font-size: 1.2rem;
        font-weight: 700;
        line-height: 1.3;
    }

    .sp-col-num,
    .sp-col-desig,
    .sp-col-unit,
    .sp-col-stock,
    .sp-col-qty {
        width: auto;
        text-align: right;
    }

    .sp-col-desig {
        font-size: .95rem;
        word-break: break-word;
    }

    /* количество — отдельным блоком снизу, с крупными кнопками */
    .sp-table tbody td.sp-col-qty {
        padding-top: 12px;
        margin-top: 6px;
        border-top: 1px solid var(--sp-line-soft);
    }

    .sp-section-row td {
        border: 0;
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 12px 14px;
        text-align: left;
        display: block;
        font-size: 1.05rem;
    }

    .sp-section-row td::before {
        display: none;
    }

    .sp-qty {
        height: 48px;
    }

    .sp-qty-btn {
        width: 48px;
        font-size: 20px;
    }

    .sp-qty-input {
        width: 66px;
        font-size: 16px; /* меньше 16px вызывает зум при фокусе в iOS */
    }

    .sp-stock-pill {
        padding: 8px 16px;
        font-size: .95rem;
    }

    .sp-summary {
        gap: 12px;
        padding: 14px;
    }

    .sp-summary-stat b {
        font-size: 1.35rem;
    }

    .sp-submit {
        width: 100%;
        margin-left: 0;
        order: 10;
        padding: 15px 24px;
    }
}

/* ==========================================================================
   Вид «карточки с фото»
   ========================================================================== */

.sp-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--sp-line);
    border-radius: var(--sp-radius);
    overflow: hidden;
    background: #fff;
    box-shadow: var(--sp-shadow);
    transition: box-shadow .2s ease, border-color .2s ease;
}

.sp-card:hover {
    box-shadow: 0 6px 22px rgba(7, 28, 31, .12);
}

.sp-row.is-chosen .sp-card {
    border-color: rgba(229, 62, 41, .5);
    box-shadow: 0 4px 18px rgba(229, 62, 41, .14);
}

.sp-card-img,
.sp-card-no-img {
    width: 100%;
    height: 220px;
    object-fit: cover;
    background: var(--sp-bg-soft);
}

.sp-card-no-img {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b7c2c5;
    font-size: 2.5rem;
}

.sp-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 18px;
}

.sp-card-title {
    font-family: var(--sp-font-head);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--sp-ink);
    margin-bottom: 6px;
}

.sp-card-designation {
    font-size: .9rem;
    font-variant-numeric: tabular-nums;
    color: var(--sp-muted);
    margin-bottom: 10px;
}

.sp-card-desc {
    font-size: .92rem;
    line-height: 1.6;
    color: #4a5c60;
    margin-bottom: 14px;
}

.sp-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 14px;
}
