/**
 * DataTable.css - Стилі для класу DataTable
 * Використовується разом з DataTable.js
 */

/* ============================================
   КОНТЕЙНЕР ТАБЛИЦІ
   ============================================ */

.table-details {
    padding: 20px;
}

/* Парящий заголовок таблиці */
.table-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: white;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.table-header:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.table-header h2 {
    margin: 0;
    color: #333;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
}

.table-header h2 i {
    margin-right: 10px;
    color: #007bff;
}

/* ============================================
   ОБГОРТКА ТАБЛИЦІ
   ============================================ */

.data-table-wrapper {
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table-wrapper:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

/* ============================================
   ОСНОВНА ТАБЛИЦЯ
   ============================================ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 14px;
    table-layout: auto;
    border: 1px solid #ddd;
}

/* ============================================
   ЗАГОЛОВОК ТАБЛИЦІ (THEAD)
   ============================================ */

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

.data-table th {
    background-color: #007bff;
    color: white;
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    border: 1px solid #0056b3;
    white-space: nowrap;
    position: relative;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
}

.data-table th .th-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ============================================
   РЕСАЙЗЕР КОЛОНОК
   ============================================ */

.data-table th .resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
}

.data-table th .resizer:hover,
.data-table th .resizer.resizing {
    background: rgba(255, 255, 255, 0.5);
}

.data-table.resizing {
    cursor: col-resize;
    user-select: none;
    -moz-user-select: none;
}

/* ============================================
   СОРТУВАННЯ
   ============================================ */

.data-table th.sortable {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.data-table th.sortable:hover {
    background-color: #0056b3;
}

.data-table th .sort-icon {
    margin-left: 8px;
    font-size: 12px;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.data-table th.sortable:hover .sort-icon {
    opacity: 1;
}

.data-table th.sort-asc .sort-icon,
.data-table th.sort-desc .sort-icon {
    opacity: 1;
    color: #fff;
}

.data-table th.sort-asc {
    background-color: #28a745;
    border-color: #1e7e34;
}

.data-table th.sort-asc:hover {
    background-color: #218838;
}

.data-table th.sort-desc {
    background-color: #dc3545;
    border-color: #c82333;
}

.data-table th.sort-desc:hover {
    background-color: #c82333;
}

/* Мультисортування - номер сортування */
.data-table th .sort-order {
    font-size: 10px;
    margin-left: 2px;
    vertical-align: super;
    opacity: 0.8;
}

/* ============================================
   ФІЛЬТРАЦІЯ
   ============================================ */

/* Поле введення фільтра */
.data-table th .filter-input {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 8px 10px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    font-size: 14px;
    font-weight: normal;
    box-sizing: border-box;
    outline: none;
    z-index: 10;
}

.data-table th .filter-input::placeholder {
    color: #999;
    font-style: italic;
}

.data-table th .filter-input:focus {
    background: #fff;
    box-shadow: inset 0 0 0 2px #007bff;
}

/* Заголовок з активним полем фільтра */
.data-table th.filter-active {
    padding: 0;
    overflow: visible;
}

/* Індикатор активного фільтра */
.data-table th.has-filter {
    background-color: #17a2b8;
    border-color: #138496;
}

.data-table th.has-filter:hover {
    background-color: #138496;
}

/* Бейдж з текстом фільтра */
.data-table th .filter-badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    font-size: 11px;
    font-weight: normal;
    padding: 2px 6px;
    margin-left: 8px;
    border-radius: 10px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    cursor: help;
}

.data-table th .filter-badge:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* Комбінування з сортуванням */
.data-table th.has-filter.sort-asc {
    background: linear-gradient(135deg, #17a2b8 50%, #28a745 50%);
}

.data-table th.has-filter.sort-desc {
    background: linear-gradient(135deg, #17a2b8 50%, #dc3545 50%);
}

/* ============================================
   ФІКСОВАНІ (STICKY) КОЛОНКИ
   ============================================ */

.data-table th.sticky-column,
.data-table td.sticky-column {
    position: sticky;
    left: 0;
    z-index: 2;
}

.data-table th.sticky-column {
    z-index: 6; /* вище за thead sticky */
}

.data-table td.sticky-column {
    background-color: #fff;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
}

.data-table tbody tr:nth-child(even) td.sticky-column {
    background-color: #f8f9fa;
}

.data-table tbody tr:hover td.sticky-column {
    background-color: #e3f2fd;
}

.data-table tbody tr.selected td.sticky-column {
    background-color: #bbdefb;
}

/* Перший стовпець (за замовчуванням sticky) */
.data-table th:first-child,
.data-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
}

.data-table th:first-child {
    z-index: 6;
}

.data-table td:first-child {
    background-color: #fff;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    border-right: 2px solid #007bff;
}

.data-table tbody tr:nth-child(even) td:first-child {
    background-color: #f8f9fa;
}

.data-table tbody tr:hover td:first-child {
    background-color: #e3f2fd;
}

.data-table tbody tr.selected td:first-child {
    background-color: #bbdefb;
}

/* ============================================
   ФІКСОВАНІ (STICKY) РЯДКИ
   ============================================ */

.data-table tbody tr.sticky-row {
    position: sticky;
    z-index: 3;
}

.data-table tbody tr.sticky-row td {
    background-color: #f0f7ff;
    font-weight: 500;
}

.data-table tbody tr.sticky-row:hover td {
    background-color: #e3f2fd;
}

/* ============================================
   ЯЧЕЙКИ ТАБЛИЦІ
   ============================================ */

.data-table td {
    padding: 10px 8px;
    border: 1px solid #ddd;
    vertical-align: top;
    box-sizing: border-box;
    background-color: #fff;
}

/* Чергування кольорів рядків */
.data-table tbody tr:nth-child(even) {
    background: #f8f9fa;
}

.data-table tbody tr:nth-child(even) td {
    background-color: #f8f9fa;
}

/* Ховер ефект */
.data-table tbody tr:hover {
    background: #e3f2fd;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
    position: relative;
    z-index: 1;
}

.data-table tbody tr:hover td {
    background-color: #e3f2fd;
}

/* ============================================
   ВИДІЛЕННЯ РЯДКІВ
   ============================================ */

.data-table tbody tr.selected {
    background: #bbdefb;
    outline: 2px solid #1976d2;
}

.data-table tbody tr.selected td {
    background-color: #bbdefb;
}

.data-table tbody tr.selected:hover {
    background: #90caf9;
}

.data-table tbody tr.selected:hover td {
    background-color: #90caf9;
}

/* ============================================
   СТАНИ: ЗАВАНТАЖЕННЯ, ПОМИЛКИ, ПОРОЖНЬО
   ============================================ */

.data-table-loading {
    text-align: center;
    padding: 50px;
    font-size: 18px;
    color: #666;
}

.data-table-loading i {
    margin-right: 10px;
    color: #007bff;
}

.data-table-error {
    text-align: center;
    padding: 50px;
    font-size: 18px;
    color: #dc3545;
    background: #fff;
    border-radius: 8px;
}

.data-table-error i {
    margin-right: 10px;
}

.data-table-empty {
    text-align: center;
    padding: 50px;
    font-size: 16px;
    color: #666;
}

/* ============================================
   ПАГІНАЦІЯ
   ============================================ */

.data-table-pagination-container {
    margin-top: 15px;
}

.data-table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
    padding: 12px 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.data-table-pagination:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

/* Інформація про рядки */
.pagination-info {
    font-size: 14px;
    color: #666;
}

/* Вибір кількості рядків */
.pagination-size {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-size label {
    font-size: 14px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-size-select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    background: white;
    transition: border-color 0.2s ease;
}

.page-size-select:hover {
    border-color: #007bff;
}

.page-size-select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Навігація */
.pagination-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    color: #333;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: #007bff;
    border-color: #007bff;
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: #007bff;
    border-color: #007bff;
    color: white;
    font-weight: 600;
}

.pagination-btn i {
    font-size: 12px;
}

/* Номери сторінок */
.pagination-pages {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 8px;
}

.pagination-ellipsis {
    padding: 0 8px;
    color: #999;
}

/* ============================================
   КОНТЕКСТНЕ МЕНЮ (МОБІЛЬНИЙ)
   ============================================ */

.data-table-context-menu {
    position: fixed;
    z-index: 1000;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    min-width: 180px;
    max-width: 280px;
    overflow: hidden;
    animation: contextMenuFadeIn 0.15s ease;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu-header {
    padding: 12px 16px;
    font-weight: 600;
    color: #333;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.context-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #333;
    transition: background-color 0.15s ease;
}

.context-menu-item:hover,
.context-menu-item:active,
.context-menu-item.touching {
    background-color: #f0f0f0;
}

.context-menu-item.active {
    background-color: #e3f2fd;
    color: #1976d2;
}

.context-menu-item i {
    width: 16px;
    text-align: center;
    color: #666;
}

.context-menu-item.active i {
    color: #1976d2;
}

.context-menu-item.filter-value {
    background-color: #e8f5e9;
    color: #2e7d32;
    font-style: italic;
}

.context-menu-item.filter-value i {
    color: #2e7d32;
}

.context-menu-divider {
    height: 1px;
    background: #eee;
    margin: 4px 0;
}

/* ---- Mcard Row Context Menu ---- */

.mcard-ctx-menu {
    position: fixed;
    display: none;
}

.mcard-ctx-menu.ctx-show {
    animation: contextMenuFadeIn 0.15s ease forwards;
}

.mcard-ctx-menu.ctx-hide {
    animation: contextMenuFadeOut 0.15s ease forwards;
}

@keyframes contextMenuFadeOut {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.95); }
}

.mcard-ctx-menu .context-menu-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mcard-ctx-menu .context-menu-header i {
    font-size: 15px;
    color: #555;
}

.mcard-ctx-menu .context-menu-item.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* ---- Oper Row Context Menu ---- */

.oper-ctx-menu {
    position: fixed;
    display: none;
}

.oper-ctx-menu.ctx-show {
    animation: contextMenuFadeIn 0.15s ease forwards;
}

.oper-ctx-menu.ctx-hide {
    animation: contextMenuFadeOut 0.15s ease forwards;
}

.oper-ctx-menu .context-menu-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.oper-ctx-menu .context-menu-header i {
    font-size: 15px;
    color: #555;
}

.oper-ctx-menu .context-menu-item.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* ---- Consult Row Context Menu ---- */

.consult-ctx-menu {
    position: fixed;
    display: none;
}

.consult-ctx-menu.ctx-show {
    animation: contextMenuFadeIn 0.15s ease forwards;
}

.consult-ctx-menu.ctx-hide {
    animation: contextMenuFadeOut 0.15s ease forwards;
}

.consult-ctx-menu .context-menu-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.consult-ctx-menu .context-menu-header i {
    font-size: 15px;
    color: #555;
}

.consult-ctx-menu .context-menu-item.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* Адаптивність */
@media (max-width: 768px) {
    .table-details {
        padding: 2px;
    }

    .table-header {
        padding: 8px;
        margin-bottom: 6px;
        border-radius: 4px;
    }

    .data-table-wrapper {
        padding: 2px;
        border-radius: 4px;
    }

    .data-table-pagination {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 8px 4px;
    }
    
    .pagination-info,
    .pagination-size,
    .pagination-nav {
        justify-content: center;
    }
    
    .pagination-nav {
        flex-wrap: wrap;
    }
    
    /* Більші елементи меню для тачу */
    .context-menu-item {
        padding: 14px 16px;
    }
}

/* Ландшафтний режим на мобільних */
@media screen and (max-height: 500px) {
    .data-table-wrapper {
    }
    
    .table-header {
        padding: 10px 15px;
        margin-bottom: 10px;
    }
    
    .table-header h2 {
        font-size: 14px;
        padding-bottom: 5px;
    }
    
    .data-table th {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .data-table td {
        padding: 6px;
        font-size: 12px;
    }
    
    .table-details {
        padding: 10px;
    }
}

/* Fullscreen режим */
body.fullscreen-mode .data-table-wrapper {
}

body.fullscreen-mode .table-header {
    display: none !important;
}

body.fullscreen-mode .table-details {
    padding: 0;
}

@media screen and (max-height: 500px) {
    body.fullscreen-mode .data-table-wrapper {
    }
}

/* ============================================
   АНІМАЦІЯ ОНОВЛЕНОЇ КЛІТИНКИ (diffUpdate)
   ============================================ */
@keyframes cellHighlight {
    0%   { background-color: rgba(40, 167, 69, 0.25); }
    100% { background-color: transparent; }
}

.data-table td.cell-updated {
    animation: cellHighlight 0.6s ease-out;
}
