/* ── Positions Table (Frontend) ─────────────────────────── */
/* Container */
.positions-table {
    margin: 40px 0; font-family: var(--font-main, 'Muller', sans-serif);
}
.positions-table__title {
    font-size: 28px; font-weight: 800; margin: 0 0 12px; line-height: 1.2;
}
.positions-table__meta {
    display: flex; gap: 20px; align-items: center; margin-bottom: 20px;
    font-size: 14px; color: #6b7280;
}
.positions-table__meta-item {
    display: flex; align-items: center; gap: 6px;
}
.positions-table__meta-icon {
    display: inline-flex; width: 20px; height: 20px;
    border-radius: 4px; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.positions-table__meta-icon--ya { background: #fc0; color: #000; }
.positions-table__meta-icon--google { background: #4285F4; }

/* Scroll wrapper — independent scroll area */
.positions-table__wrap {
    max-height: 70vh; overflow: auto;
    border: 1px solid #e5e7eb; border-radius: 8px;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Table */
.positions-table__table {
    width: max-content; min-width: 100%; border-collapse: separate;
    border-spacing: 0; font-size: 14px; line-height: 1.3;
}
.positions-table__table th,
.positions-table__table td {
    border-bottom: 1px solid #e5e7eb; border-right: 1px solid #e5e7eb;
    padding: 8px 10px; text-align: center; white-space: nowrap;
    box-sizing: border-box;
}
/* Remove double right border on last column */
.positions-table__table th:last-child,
.positions-table__table td:last-child { border-right: none; }

/* Header — sticky on top */
.positions-table__table thead th {
    background: #f9fafb; font-weight: 700; font-size: 13px;
    position: sticky; top: 0; z-index: 3; color: #374151;
}

/* Sticky columns: №  and Запрос (frozen on horizontal scroll) */
.positions-table__th-num,
.positions-table__num {
    position: sticky; left: 0; z-index: 2;
    background: #f9fafb; width: 44px; color: #9ca3af; font-weight: 600;
}
.positions-table__num { background: #fff; }
.positions-table__th-kw,
.positions-table__kw {
    position: sticky; left: 44px; z-index: 2;
    background: #f9fafb;
}
.positions-table__kw { background: #fff; }
/* Corner cells: both sticky top + left */
.positions-table__table thead .positions-table__th-num,
.positions-table__table thead .positions-table__th-kw {
    z-index: 4;
}
/* Shadow on frozen columns */
.positions-table__th-kw::after,
.positions-table__kw::after {
    content: ''; position: absolute; top: 0; right: -6px;
    width: 6px; height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0.06), transparent);
    pointer-events: none;
}
.positions-table__col-keyword,
.positions-table__th-kw {
    text-align: left !important; min-width: 250px; font-weight: 700;
}
.positions-table__col-date {
    min-width: 100px;
}

/* Keyword cell */
.positions-table__keyword {
    text-align: left !important; font-weight: 600; color: #111827;
}
.positions-table__kw {
    text-align: left !important; font-weight: 600; color: #111827;
}

/* Position cell */
.positions-table__pos {
    font-weight: 700; font-size: 15px; position: relative;
    transition: background 0.15s;
}

/* Position color classes */
.positions-table__pos--top3 {
    background: #b4d9f1; color: #1a5276;
}
.positions-table__pos--top10 {
    background: #c8f0da; color: #145a32;
}
.positions-table__pos--top30 {
    background: #fef9e7; color: #7d6608;
}
.positions-table__pos--top50 {
    background: #fdf2f2; color: #922b21;
}
.positions-table__pos--low {
    background: #f9fafb; color: #6b7280;
}

/* Dynamic change overlay */
.positions-table__pos--up {
    background: #edf9f3 !important;
}
.positions-table__pos--top3.positions-table__pos--up {
    background: #a3d1ee !important;
}
.positions-table__pos--top10.positions-table__pos--up {
    background: #b4f0d1 !important;
}
.positions-table__pos--down {
    background: #fff4f3 !important;
}
.positions-table__pos--top3.positions-table__pos--down {
    background: #c4dff0 !important;
}
.positions-table__pos--empty {
    background: #f7f7f7; color: #d1d5db;
}

/* Change indicator */
.positions-table__change {
    display: block; font-size: 10px; font-weight: 500;
    margin-top: 2px; line-height: 1;
}
.positions-table__change--up {
    color: #059669;
}
.positions-table__change--down {
    color: #DC2626;
}

/* Cell position value */
.positions-table__val {
    display: block; line-height: 1.2;
}

/* Footer stats row — sticky at bottom */
.positions-table__foot td {
    font-weight: 600; font-size: 13px;
    border-top: 1px solid #e5e7eb;
    position: sticky; bottom: 0; z-index: 2;
}
.positions-table__foot--top1 td  { background: #dbeafe; }
.positions-table__foot--top5 td  { background: #dcfce7; }
.positions-table__foot--top10 td { background: #f0fdf4; }
/* Stack sticky: TOP-10 at very bottom, then TOP-5, then TOP-1 */
.positions-table__foot--top1 td  { bottom: calc(2 * 2.2em); }
.positions-table__foot--top5 td  { bottom: calc(1 * 2.2em); }
.positions-table__foot--top10 td { bottom: 0; }
.positions-table__foot-label {
    text-align: left !important; color: #374151;
    position: sticky; left: 0; z-index: 3;
}
.positions-table__top10-count {
    display: block; font-size: 14px; font-weight: 700; color: #059669;
}
.positions-table__top10-pct {
    display: block; font-size: 11px; font-weight: 600; color: #6b7280;
    margin-top: 2px;
}

/* Row highlight on hover */
.positions-table__table tbody tr:hover td {
    background: #f3f4f6;
}
.positions-table__table tbody tr:hover .positions-table__num,
.positions-table__table tbody tr:hover .positions-table__kw {
    background: #f3f4f6;
}
/* Preserve position colors on hover */
.positions-table__table tbody tr:hover .positions-table__pos--top3 { background: #a3d1ee !important; }
.positions-table__table tbody tr:hover .positions-table__pos--top10 { background: #b4f0d1 !important; }
.positions-table__table tbody tr:hover .positions-table__pos--top30 { background: #fef3c7 !important; }
.positions-table__table tbody tr:hover .positions-table__pos--up { background: #d1fae5 !important; }
.positions-table__table tbody tr:hover .positions-table__pos--down { background: #fee2e2 !important; }

/* Striped rows */
.positions-table__table tbody tr:nth-child(even) td {
    background: #fafafa;
}
.positions-table__table tbody tr:nth-child(even) .positions-table__num,
.positions-table__table tbody tr:nth-child(even) .positions-table__kw {
    background: #fafafa;
}

/* Number column */
.positions-table__num {
    color: #9ca3af; font-size: 12px; font-weight: 500;
}

/* Legend */
.positions-table__legend {
    display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px;
    font-size: 12px; color: #6b7280;
}
.positions-table__legend-item {
    display: flex; align-items: center; gap: 4px;
}
.positions-table__legend-color {
    width: 14px; height: 14px; border-radius: 3px; border: 1px solid #ddd;
    flex-shrink: 0;
}

/* Responsive */
@media (max-width: 992px) {
    .positions-table__title { font-size: 22px; }
    .positions-table__meta { flex-wrap: wrap; gap: 10px; }
    .positions-table__table { font-size: 13px; }
    .positions-table__table th,
    .positions-table__table td { padding: 6px 8px; }
    .positions-table__col-keyword { min-width: 180px; }
    .positions-table__pos { font-size: 13px; }
}
@media (max-width: 576px) {
    .positions-table { margin: 24px 0; }
    .positions-table__title { font-size: 18px; }
    .positions-table__table { font-size: 12px; }
    .positions-table__table th,
    .positions-table__table td { padding: 4px 6px; }
    .positions-table__col-keyword { min-width: 140px; }
}

/* Подсказка горизонтального скролла + примечание о срезе */
.positions-table__hint {
    display: none;
    font-size: 12.5px;
    color: #6b7280;
    margin: 0 0 8px;
    text-align: center;
}
.positions-table__note {
    margin: 12px 0 0;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
}
/* =============================================================
   МОБИЛЬНЫЙ ВИД 1:1 С БЛОКОМ AI-ПОЗИЦИЙ (@since 1.66.0)
   Зеркало ai-positions-mobile.css: скрытый №, узкая липкая колонка
   запроса с тап-раскрытием, крупные тач-ячейки, max-height 60vh со
   скролл-тенью справа, компактный футер, зелёная подсказка-свайп.
   ============================================================= */

/* ── Подсказка-свайп как в AI (зелёная плашка с пульсацией) ── */
@media (max-width: 768px) {
    .positions-table__hint {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 8px 16px;
        margin: 0 0 8px;
        text-align: center;
        background: linear-gradient(135deg, rgba(5,150,105,0.06), rgba(5,150,105,0.02));
        border: 1px solid rgba(5,150,105,0.12);
        border-radius: 8px;
        font-size: 12px;
        color: #6b7280;
        animation: ptHintPulse 2s ease-in-out infinite;
    }
    @keyframes ptHintPulse { 0%,100%{opacity:.7} 50%{opacity:1} }
}

@media (max-width: 576px) {
    .positions-table { margin: 24px 0; }
    .positions-table__title { font-size: 18px; }
    .positions-table__table { font-size: 12px; }

    /* Скрываем колонку № (и в шапке, и в теле, и пустую ячейку футера) */
    .positions-table__th-num,
    .positions-table__num,
    .positions-table__foot > td:first-child {
        display: none !important;
    }

    /* Запрос: узкая липкая колонка left:0, ellipsis, тап-раскрытие */
    .positions-table__th-kw,
    .positions-table__kw,
    .positions-table__foot-label {
        left: 0 !important;
        min-width: 92px !important;
        max-width: 92px !important;
        width: 92px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px !important;
        padding: 6px 8px 6px 10px !important;
    }
    .positions-table__th-kw::after,
    .positions-table__kw::after {
        right: -8px; width: 8px;
        background: linear-gradient(to right, rgba(0,0,0,0.1), transparent);
    }

    /* Даты: компактнее */
    .positions-table__th-date {
        min-width: 72px !important;
        font-size: 12px !important;
        padding: 6px 4px !important;
    }
    .positions-table__date { font-size: 12px; }
    .positions-table__top-pct { font-size: 12px; }

    /* Ячейки позиций: крупнее для тача */
    .positions-table__pos {
        font-size: 14px !important;
        padding: 8px 6px !important;
        min-width: 72px;
    }
    .positions-table__change { font-size: 12px; }

    /* Скролл-контейнер: 60vh + скруг + правая скролл-тень */
    .positions-table__wrap {
        max-height: 60vh;
        border-radius: 10px;
        position: relative;
    }
    .positions-table__wrap::after {
        content: '';
        position: absolute; top: 0; right: 0;
        width: 32px; height: 100%;
        pointer-events: none; z-index: 5;
        background: linear-gradient(to right, transparent, rgba(5,150,105,0.08));
        transition: opacity 0.3s ease;
    }
    .positions-table__wrap--scrolled-end::after { opacity: 0; }

    /* Футер: компактнее */
    .positions-table__foot td { font-size: 12px; padding: 4px 4px !important; }
    .positions-table__foot-label { font-size: 12px !important; padding-left: 8px !important; }
    .positions-table__foot-stat { font-size: 12px; }
    .positions-table__foot-pct { font-size: 12px; }
    /* Пересчёт sticky-стека футера под компактную высоту строки */
    .positions-table__foot--top1 td  { bottom: calc(2 * 2em); }
    .positions-table__foot--top5 td  { bottom: calc(1 * 2em); }
    .positions-table__foot--top10 td { bottom: 0; }

    /* Раскрытие запроса по тапу (JS вешает класс) */
    .positions-table__kw--expanded {
        max-width: none !important;
        width: auto !important;
        min-width: 92px !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: unset !important;
        z-index: 10;
        box-shadow: 4px 0 12px rgba(0,0,0,0.15);
        position: sticky; left: 0;
        background: #fff !important;
    }
}

@media (max-width: 380px) {
    .positions-table__th-kw,
    .positions-table__kw,
    .positions-table__foot-label {
        min-width: 76px !important;
        max-width: 76px !important;
        width: 76px !important;
        font-size: 12px !important;
        padding: 5px 6px 5px 8px !important;
    }
    .positions-table__pos { min-width: 62px; font-size: 13px !important; padding: 7px 4px !important; }
    .positions-table__th-date { min-width: 62px !important; font-size: 12px !important; }
}

/* Кнопка «Показать все» под таблицей позиций */
.positions-table__more{display:inline-block;margin-top:14px;padding:12px 22px;border:1.5px solid #059669;border-radius:10px;background:transparent;color:#047857;font:inherit;font-weight:600;font-size:15px;line-height:1.2;cursor:pointer;transition:background .15s,color .15s}
.positions-table__more:hover{background:#059669;color:#fff}
.positions-table__more:focus-visible{outline:2px solid #059669;outline-offset:3px}
.positions-table__row--hidden[hidden]{display:none}

/* Раскрытая таблица: без ограничения высоты, горизонтальная прокрутка по датам остаётся */
.positions-table__wrap.positions-table__wrap--expanded{max-height:none}
