﻿/* Общие стили таблиц — используются на всех списковых страницах */

/* ── Layout списочной страницы ──
   Класс .list-page на корневом <section> обеспечивает:
   - страница занимает всю высоту <main>
   - таблица скроллится внутри себя
   - пагинация прибита к нижнему краю viewport
   Структура: .list-page > .list-toolbar (flex-shrink:0)
                           > .table-card  (flex:1, скролл внутри)
                           > .pagination-footer (flex-shrink:0)
   Или через partial: .list-page > [data-list-content] > .table-card + .pagination-footer */

.list-page {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    min-width: 0;
    margin: 0;
    height: 100%;
    min-height: 0;
}

/* Режим «справочник»: компактные списки (до ~8 колонок) центрируются
   с ограничением ширины — строка читается целиком, действия не улетают
   к правому краю широкого монитора. Рабочие таблицы с настраиваемыми
   колонками (рейсы) остаются без модификатора — на всю ширину viewport. */
.list-page--contained {
    max-width: 1320px;
    margin: 0 auto;
}

.list-page .list-toolbar {
    flex-shrink: 0;
}

.list-page [data-list-content] {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 12px;
}

/* ── Тулбар списковой страницы (единый паттерн) ──
   .list-toolbar > .list-toolbar-left  (h1 + .list-subtitle)
                 > .list-toolbar-right (поиск, фильтры, primary-кнопка)
   Страницы со сложными фильтрами (рейсы, счета) вместо right-блока
   используют зоны .toolbar-zone-* (globals.css) — база та же. */
.list-toolbar {
    display: flex;
    align-items: flex-start;
    gap: 10px 12px;
    flex-wrap: wrap;
}

.list-toolbar h1 {
    margin: 0;
    font-size: clamp(1.25rem, 1.8vw, 1.5rem);
    line-height: 36px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.list-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

.list-subtitle {
    margin: 2px 0 0;
    font-size: var(--text-sm);
    color: var(--muted);
}

.list-page .table-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.list-page .table-wrap {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: auto;
}

.list-page .pagination-footer {
    flex-shrink: 0;
}

.list-page .pagination {
    flex-shrink: 0;
}

/* Карточка-обёртка таблицы */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Прокрутка таблицы по горизонтали */
.table-wrap {
    width: 100%;
    overflow-x: auto;
}

/* Базовая таблица */
.tms-table {
    width: 100%;
    border-collapse: collapse;
}

.tms-table thead th {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky-header);
    text-align: left;
    padding: 12px 14px;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    background: var(--hover);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.tms-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
    color: var(--text);
    vertical-align: top;
}

.tms-table tbody tr:last-child td {
    border-bottom: none;
}

.tms-table tbody tr {
    transition: background 0.15s ease;
}

.tms-table tbody tr:hover td {
    background: var(--hover);
}

/* Пустое состояние */
.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 24px 14px;
}

.empty-state .tms-btn {
    margin-top: 12px;
}

/* Пагинация */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.pagination-link,
.pagination-ellipsis {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    text-decoration: none;
    color: var(--text);
    box-sizing: border-box;
}

.pagination-link {
    border: 1px solid var(--border-interactive);
    background: var(--surface);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.pagination-link:hover {
    background: var(--hover);
    border-color: var(--border-input);
}

.pagination-link.is-current {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--surface);
    font-weight: 600;
}

.pagination-link.is-disabled {
    color: var(--muted);
    background: var(--hover);
    pointer-events: none;
}

.pagination-ellipsis {
    color: var(--muted);
}

/* Sortable headers */
.sortable-header {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s ease;
    text-transform: uppercase;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
}

.sortable-header:hover {
    color: var(--text);
}

.sortable-header.is-active {
    color: var(--text);
}

.sort-indicator {
    font-size: var(--text-xs);
}

/* Клик по строке — переход в карточку */
.tms-table tbody tr[data-detail-url] {
    cursor: pointer;
}

/* Ячейка действий строки (th.row-actions-header / td.row-actions-cell) */
.row-actions-header,
.row-actions-cell {
    width: 100px;
}

.row-actions-cell {
    padding: 0 8px;
    vertical-align: middle;
}

/* Row actions — hover-иконки */
.row-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.tms-table tbody tr:hover .row-actions {
    opacity: 1;
}

.row-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    text-decoration: none;
}

.row-action--view:hover {
    background: var(--hover-active);
    color: var(--primary);
}

.row-action--edit:hover {
    background: var(--hover-active);
    color: var(--primary);
}

.row-action--delete:hover {
    background: var(--error-bg);
    color: var(--danger);
}

/* Поиск по таблице */
.search-field-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.search-field-wrap .search-icon {
    position: absolute;
    left: 10px;
    color: var(--muted);
    pointer-events: none;
}

.search-field-wrap .search-input {
    min-height: 36px;
    height: 36px;
    padding: 0 30px 0 30px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    font-size: var(--text-sm);
    background: var(--surface);
    color: var(--text);
    width: 240px;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.search-field-wrap .search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.search-field-wrap.is-filtered .search-input {
    border-color: var(--primary);
    background: var(--hover-active);
}

.search-field-wrap .search-clear {
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--neutral-bg);
    cursor: pointer;
    color: var(--muted);
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.search-field-wrap.is-filtered .search-clear {
    opacity: 1;
    pointer-events: auto;
}

.search-field-wrap .search-clear:hover {
    color: var(--text);
    background: var(--neutral-border);
}

/* Кнопка-тоггл (календарь, другие visibility-переключатели) */
.visibility-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border-interactive);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.visibility-toggle:hover {
    background: var(--hover);
    color: var(--text);
    border-color: var(--border-input-hover);
}

.visibility-toggle[aria-expanded="true"] {
    background: var(--hover-active);
    color: var(--primary);
    border-color: var(--primary);
}

/* Поля фильтров (дата, inline-input) */
.filter-input {
    min-height: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    font-size: var(--text-xs);
    background: var(--surface);
    color: var(--text);
    box-sizing: border-box;
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Select-фильтр (направление, статус и т.д.) */
.filter-select {
    min-height: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    font-size: var(--text-xs);
    background: var(--surface);
    color: var(--text);
    box-sizing: border-box;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Диапазон дат — скрыт через visibility, место зарезервировано */
.date-range-expand {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    visibility: hidden;
    pointer-events: none;
}

.date-range-expand.is-visible {
    visibility: visible;
    pointer-events: auto;
}

.date-range-expand .filter-input {
    width: 150px;
}

.date-range-expand .filter-input.is-filled {
    border-color: var(--primary);
    background: var(--hover-active);
}

.date-range-sep {
    font-size: var(--text-xs);
    color: var(--muted);
}

/* Состояние загрузки контента */
[data-list-content].is-loading {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

/* Pagination footer — сетка: page-size | пагинация | счётчик */
.pagination-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 0 4px;
}

.pagination-footer-left {
    justify-self: start;
}

.pagination-footer-center {
    justify-self: center;
}

.pagination-footer-right {
    justify-self: end;
}

.pagination-meta {
    color: var(--muted);
    font-size: var(--text-xs);
    white-space: nowrap;
}

/* Page size selector */
.page-size-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
}

.page-size-label {
    color: var(--muted);
    white-space: nowrap;
}

.page-size-select {
    min-width: 64px;
    width: auto;
    height: 34px;
    min-height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    font-size: var(--text-xs);
    background: var(--surface);
    color: var(--text);
    box-sizing: border-box;
    cursor: pointer;
}

.page-size-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ── Мобильная адаптация списков (≤ 760px) ──
   Карточная раскладка таблицы — опт-ин: <table class="tms-table tms-table--cards">
   плюс data-label на каждой td. Заголовки скрываются, строка становится
   карточкой «метка — значение». Таблицы без модификатора (рейсы, платные
   дороги) остаются скроллируемыми. */
@media (max-width: 760px) {
    .list-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .list-toolbar-right {
        margin-left: 0;
    }

    .list-toolbar .search-field-wrap,
    .list-toolbar .search-field-wrap .search-input {
        width: 100%;
    }

    .table-wrap:has(> .tms-table--cards) {
        overflow: visible;
    }

    .tms-table--cards {
        min-width: 100%;
        border-collapse: separate;
        border-spacing: 0;
    }

    .tms-table--cards thead {
        display: none;
    }

    .tms-table--cards tbody tr {
        display: block;
        margin: 10px;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--surface);
        overflow: hidden;
    }

    .tms-table--cards tbody td {
        display: grid;
        grid-template-columns: 120px 1fr;
        gap: 10px;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
        white-space: normal;
        height: auto;
        max-height: none;
    }

    .tms-table--cards tbody td:last-child {
        border-bottom: none;
    }

    .tms-table--cards tbody td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: var(--text-xs);
        font-weight: 600;
    }

    .tms-table--cards .row-actions-cell {
        width: auto;
        padding: 10px 12px;
        position: static;
    }

    .tms-table--cards .row-actions-cell::before {
        content: none;
    }

    .tms-table--cards .row-actions {
        opacity: 1;
    }

    .tms-table--cards .cell-money {
        text-align: left;
    }

    .tms-table--cards .entity-name {
        max-width: none;
        white-space: normal;
    }

    /* Ячейка без data-label (empty-state, colspan) — обычный блок без сетки «метка—значение» */
    .tms-table--cards tbody td:not([data-label]) {
        display: block;
    }

    .tms-table--cards tbody td.empty-state {
        text-align: center;
    }

    .pagination-footer {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 8px;
    }

    .pagination-footer-left,
    .pagination-footer-right {
        justify-self: center;
    }
}
