/**
 * Responsive Table for Elementor - Styles
 * Version: 2.0.0
 */

/* ==================== БАЗОВЫЕ СТИЛИ ==================== */
.rte-table-container {
    position: relative;
    width: 100%;
    margin: 0 auto;
}

.rte-table-wrapper {
    width: 100%;
    overflow: hidden;
    /* Для корректного отображения border-radius при наличии overflow */
}

.rte-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    table-layout: auto;
}

.rte-table th,
.rte-table td {
    vertical-align: middle;
    word-wrap: break-word;
}

.rte-table tbody td {
    color: var(--rte-cell-text-color, inherit);
}

.rte-table thead th {
    font-weight: 600;
    white-space: nowrap;
    position: relative;
}

/* Скругление углов для крайних ячеек - наследует от wrapper */
.rte-table thead th:first-child {
    border-top-left-radius: inherit;
}

.rte-table thead th:last-child {
    border-top-right-radius: inherit;
}

.rte-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: inherit;
}

.rte-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: inherit;
}

/* ==================== ТУЛБАР ==================== */
.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    margin-bottom: 15px;
}

.rte-toolbar:empty {
    display: none;
}

/* ==================== ПОИСК ==================== */
.rte-search-wrapper {
    flex: 0 0 auto;
}

.rte-search-input {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.rte-search-input:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.rte-search-input::placeholder {
    color: #999;
}

/* ==================== СОРТИРОВКА ==================== */
.rte-table.rte-sortable thead th {
    cursor: pointer;
    user-select: none;
}

.rte-table.rte-sortable thead th:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.rte-sort-icon {
    display: inline-block;
    margin-left: 5px;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.rte-sort-icon::after {
    content: "⇅";
    font-size: 0.9em;
}

.rte-table thead th.rte-sort-asc .rte-sort-icon::after {
    content: "↑";
}

.rte-table thead th.rte-sort-desc .rte-sort-icon::after {
    content: "↓";
}

.rte-table thead th.rte-sort-asc .rte-sort-icon,
.rte-table thead th.rte-sort-desc .rte-sort-icon {
    opacity: 1;
}

/* ==================== КНОПКИ ==================== */
.rte-btn {
    display: inline-block;
    padding: 8px 16px;
    background-color: #3498db;
    color: #ffffff;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    transition: background-color 0.2s, transform 0.1s;
    white-space: nowrap;
}

.rte-btn:hover {
    background-color: #2980b9;
    color: #ffffff;
    transform: translateY(-1px);
}

.rte-btn:active {
    transform: translateY(0);
}

/* ==================== БЕЙДЖИ ==================== */
.rte-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    border-radius: 12px;
    white-space: nowrap;
    text-decoration: none;
}

.rte-badge-primary {
    background-color: #3498db;
    color: #ffffff;
}

.rte-badge-success {
    background-color: #27ae60;
    color: #ffffff;
}

.rte-badge-warning {
    background-color: #f39c12;
    color: #ffffff;
}

.rte-badge-danger {
    background-color: #e74c3c;
    color: #ffffff;
}

.rte-badge-info {
    background-color: #17a2b8;
    color: #ffffff;
}

/* ==================== ИКОНКИ В ЯЧЕЙКАХ ==================== */
.rte-cell-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.rte-cell-icon i,
.rte-cell-icon svg {
    font-size: 18px;
    width: 1em;
    height: 1em;
}

.rte-cell-icon .rte-cell-icon-el,
.rte-cell-icon .rte-cell-icon-el *,
.rte-cell-icon svg,
.rte-cell-icon svg * {
    color: var(--rte-cell-icon-color, inherit);
    fill: var(--rte-cell-icon-color, currentColor);
    stroke: var(--rte-cell-icon-color, currentColor);
}

.rte-cell-icon-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.rte-cell-image {
    max-width: 100px;
    height: auto;
    border-radius: 4px;
}

/* ==================== ИКОНКИ В ЗАГОЛОВКАХ ==================== */
.rte-header-icon-before {
    margin-right: 8px;
}

.rte-header-icon-after {
    margin-left: 8px;
}

/* ==================== ТЕКСТ В ЗАГОЛОВКАХ ==================== */
.rte-header-text {
    display: block;
    box-sizing: border-box;
    vertical-align: top;
}

/* ==================== ПОДТЕКСТ В ЗАГОЛОВКАХ ==================== */
.rte-header-subtext {
    display: block;
    box-sizing: border-box;
    vertical-align: top;
    font-weight: 400;
    font-size: 0.8em;
    opacity: 0.75;
    white-space: normal;
    line-height: 1.3;
    margin-top: 2px;
}

/* ==================== ПЕРВЫЙ СТОЛБЕЦ КАК ЗАГОЛОВОК ==================== */
.rte-table.rte-first-col-header tbody td:first-child {
    font-weight: 600;
}

/* ==================== ВЫДЕЛЕННЫЕ СТРОКИ ==================== */
.rte-table tbody tr.rte-row-highlight {
    position: relative;
}

/* ==================== "НИЧЕГО НЕ НАЙДЕНО" ==================== */
.rte-no-results {
    text-align: center;
    padding: 30px 20px;
    color: #666;
    font-size: 14px;
    background-color: #f9f9f9;
    border-radius: 4px;
}

/* ==================== РЕЖИМ: ГОРИЗОНТАЛЬНАЯ ПРОКРУТКА ==================== */
.rte-table-container[data-mode="scroll"] .rte-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.rte-table-container[data-mode="scroll"] .rte-table {
    min-width: 600px;
}

/* Стилизация скроллбара */
.rte-table-container[data-mode="scroll"] .rte-table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.rte-table-container[data-mode="scroll"] .rte-table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.rte-table-container[data-mode="scroll"] .rte-table-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.rte-table-container[data-mode="scroll"] .rte-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Индикатор прокрутки */
.rte-scroll-indicator {
    display: none;
    text-align: center;
    padding: 8px;
    background: linear-gradient(90deg, transparent, rgba(0,0,0,0.05), transparent);
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
}

/* ==================== РЕЖИМ: КАРТОЧКИ (STACKED/CARD VIEW) ==================== */
.rte-table.rte-mode-stack.rte-stacked-active,
.rte-table.rte-mode-stack.rte-stacked-active tbody,
.rte-table.rte-mode-stack.rte-stacked-active tr,
.rte-table.rte-mode-stack.rte-stacked-active td {
    display: block;
    width: 100%;
}

.rte-table.rte-mode-stack.rte-stacked-active colgroup {
    display: none;
}

.rte-table.rte-mode-stack.rte-stacked-active thead {
    display: none;
}

.rte-table.rte-mode-stack.rte-stacked-active tbody tr {
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.rte-table.rte-mode-stack.rte-stacked-active tbody tr:last-child {
    margin-bottom: 0;
}

.rte-table.rte-mode-stack.rte-stacked-active tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    text-align: right;
    border: none;
    border-bottom: 1px solid #f0f0f0;
}

.rte-table.rte-mode-stack.rte-stacked-active tbody td:last-child {
    border-bottom: none;
}

.rte-table.rte-mode-stack.rte-stacked-active tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    text-align: left;
    padding-right: 15px;
    flex-shrink: 0;
    width: 35%;
    color: #666;
}

.rte-table.rte-mode-stack.rte-stacked-active tbody td:empty::before,
.rte-table.rte-mode-stack.rte-stacked-active tbody td.rte-column-hidden-mobile::before {
    content: none;
}

.rte-table.rte-mode-stack.rte-stacked-active tbody td.rte-column-hidden-mobile {
    display: none !important;
}

/* ==================== РЕЖИМ: СКРЫТИЕ СТОЛБЦОВ (COLUMN TOGGLE) ==================== */
.rte-column-toggle-wrapper {
    position: relative;
    display: inline-block;
}

.rte-column-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: #3498db;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.rte-column-toggle-btn:hover {
    background-color: #2980b9;
}

.rte-toggle-icon {
    font-size: 16px;
}

.rte-column-toggle-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    min-width: 200px;
    margin-top: 5px;
    padding: 10px 0;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
}

.rte-column-toggle-menu.rte-menu-open {
    display: block;
    animation: rte-fadeIn 0.2s ease;
}

.rte-column-toggle-item {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.rte-column-toggle-item:hover {
    background-color: #f5f5f5;
}

.rte-column-toggle-item input[type="checkbox"] {
    margin-right: 10px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.rte-column-toggle-item span {
    font-size: 14px;
    color: #333;
}

/* Скрытые столбцы */
.rte-table th.rte-column-hidden,
.rte-table td.rte-column-hidden {
    display: none !important;
}

/* ==================== РЕЖИМ: ДИНАМИЧЕСКОЕ МАСШТАБИРОВАНИЕ (RE-FLOW) ==================== */
.rte-table-container[data-mode="reflow"] .rte-table {
    table-layout: fixed;
}

.rte-table-container[data-mode="reflow"] .rte-table-wrapper {
    overflow: visible;
}

.rte-table-container[data-mode="reflow"] .rte-table th,
.rte-table-container[data-mode="reflow"] .rte-table td {
    overflow: hidden;
    text-overflow: ellipsis;
}

.rte-table.rte-mode-reflow.rte-reflow-active {
    table-layout: fixed;
}

.rte-table.rte-mode-reflow.rte-reflow-sticky-head {
    border-collapse: separate;
    border-spacing: 0;
}

.rte-table.rte-mode-reflow.rte-reflow-sticky-head thead th {
    position: sticky;
    top: var(--rte-reflow-sticky-top, 0px);
    z-index: var(--rte-reflow-sticky-z-index, 5);
    transform: translateY(var(--rte-reflow-sticky-shift, 0px));
    background-clip: padding-box;
}

.rte-table.rte-mode-reflow.rte-reflow-scaled {
    font-size: var(--rte-reflow-scale, 1em);
}

.rte-table.rte-mode-reflow.rte-reflow-scaled th,
.rte-table.rte-mode-reflow.rte-reflow-scaled td {
    padding: var(--rte-reflow-padding, 12px 15px);
}

/* ==================== HOVER ЭФФЕКТЫ ==================== */
.rte-table.rte-hover-enabled tbody tr {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ==================== АНИМАЦИИ ==================== */
@keyframes rte-fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rte-table.rte-mode-stack.rte-stacked-active tbody tr {
    animation: rte-fadeIn 0.3s ease;
}

/* ==================== УТИЛИТЫ ==================== */
.rte-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.rte-hidden {
    display: none !important;
}

/* ==================== ПЕЧАТЬ ==================== */
@media print {
    .rte-toolbar {
        display: none !important;
    }
    
    .rte-column-toggle-wrapper {
        display: none !important;
    }
    
    .rte-scroll-indicator {
        display: none !important;
    }
    
    .rte-table-container[data-mode="scroll"] .rte-table-wrapper {
        overflow: visible;
    }
    
    .rte-table {
        font-size: 10pt;
    }
    
    .rte-table th,
    .rte-table td {
        padding: 5px 8px;
        border: 1px solid #333 !important;
    }
    
    .rte-table thead th {
        background-color: #eee !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .rte-btn {
        background-color: transparent !important;
        color: #333 !important;
        border: 1px solid #333 !important;
    }
    
    .rte-badge {
        background-color: transparent !important;
        color: #333 !important;
        border: 1px solid #333 !important;
    }
}

/* ==================== ФИКС ДЛЯ ELEMENTOR РЕДАКТОРА ==================== */
.elementor-editor-active .rte-table-container {
    min-height: 100px;
}

.elementor-editor-active .rte-table tbody tr:hover {
    cursor: pointer;
}

/* ==================== АДАПТИВНОСТЬ КОНТЕЙНЕРА ==================== */
@media screen and (max-width: 600px) {
    .rte-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .rte-search-input {
        width: 100%;
    }
    
    .rte-column-toggle-btn {
        width: 100%;
        justify-content: center;
        padding: 8px 15px;
        font-size: 13px;
    }
    
    .rte-column-toggle-menu {
        min-width: 100%;
        left: 0;
        right: 0;
    }
}
