/* ========================================================================
   offset.css — плитки продукции (модуль offset)
   Подключается index.php автоматически, с ?v=filemtime().

   КАК УСТРОЕНА ИКОНКА
   Иконки продукции (sborka.run/images/kabinet/*.png) — вертикальные
   спрайты с пропорцией около 1:2: верхняя половина — обычный вид, нижняя —
   вид при наведении (тёмный фон, светлая надпись). Плитка квадратная и
   обрезает картинку (overflow: hidden), а при наведении картинка
   прижимается к низу. Так же сделано на office.vtorge.com, размеры и цвета
   взяты оттуда: плитка 185×185, промежуток 20px, фон при наведении #d6d4d3.

   Раньше картинка выводилась с object-fit: contain, и на плитке были видны
   обе половины спрайта сразу.
   ======================================================================== */

.offset-products-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 20px;
    margin-top: 20px;
}

.offset-product-card {
    position: relative;
    box-sizing: border-box;
    width: 185px;
    height: 185px;
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 0 0 1px #e9e6e4;
    cursor: pointer;
    user-select: none;
    text-align: center;
}

/* Без transition: у vtorge смена мгновенная, а top ↔ bottom: auto
   всё равно не анимируется. */
.offset-product-card:hover {
    background: #d6d4d3;
}

.offset-product-card__image {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: block;
    width: 100%;
    height: auto;
    /* Как .anti-drag у vtorge: картинку нельзя утащить мышью, клик уходит
       карточке. */
    pointer-events: none;
}

.offset-product-card:hover .offset-product-card__image {
    top: auto;
    bottom: 0;
}

/* Загруженная админом картинка, которая не спрайт: вписываем целиком
   и при наведении не сдвигаем. */
.offset-product-card__image--plain,
.offset-product-card:hover .offset-product-card__image--plain {
    top: 0;
    bottom: 0;
    height: 100%;
    object-fit: contain;
}

/* ---------- Название и кнопки админа ---------- */

.offset-product-card__title {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
}

/* Название нарисовано на иконке — прячем текст только визуально. */
.offset-product-card--image .product-name-display {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Продукт без картинки — текстовая плитка того же размера. */
.offset-product-card--noimage .offset-product-card__title {
    top: 0;
    bottom: 0;
    justify-content: center;
}

.offset-product-card--noimage .product-name-display {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.2;
    color: #333;
}

.offset-product-card__descr {
    color: #888;
    line-height: 1.2;
}

/* Показываются при наведении правилом из админского <style> в offset.php. */
.product-controls {
    display: none;
    gap: 3px;
    align-items: center;
    padding: 4px 6px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.product-drag-handle {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1.5px solid #ccc;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    color: #555;
    font-size: 10px;
    font-weight: bold;
    line-height: 1;
    cursor: grab;
    transition: background 0.2s, transform 0.1s;
}

/* Видимость продукта для админа: «Регион: …» / «Город: …».
   Слева сверху, до кружка с ID (right 6px + 28px + зазор). Каждая строка
   обрезается на двух строках — регионов бывает десяток, а плитка 185px;
   полный список в подсказке (data-tooltip, js/tooltips.js). */
.offset-product-card__visibility {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 5;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 1px;
    max-width: calc(100% - 46px);
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    color: #555;
    font-size: 10px;
    line-height: 1.25;
    text-align: left;
}

.offset-product-card__visibility-line {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.offset-product-card__visibility-line b {
    color: #333;
    font-weight: 600;
}

/* ---------- Узкие экраны (те же пороги, что у vtorge) ---------- */

@media (max-width: 440px) {
    .offset-product-card {
        width: 142px;
        height: 142px;
    }
}

@media (max-width: 389.98px) {
    .offset-products-grid {
        justify-content: center;
        gap: 8px;
    }
    .offset-product-card {
        width: calc(50% - 4px);
        height: auto;
        aspect-ratio: 1 / 1;
    }
}
