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

/* ── 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: var(--page-contained);
    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;
}

/* Базовая таблица — одна типографика для реестров и составов документов
   (ui-guide §13, ADR-0066): шапка 12/600 заглавными, значения 14px,
   итоги 14/600, вторичная строка 12px --muted; мельче 12px ничего нет.
   Отступы как у сетки макета: у края ряда 14px, между колонками 12px —
   по 6px с каждой стороны ячейки. */
.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: 10px 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.3;
    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 6px;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
    color: var(--text);
    vertical-align: top;
}

/* Строка итогов. Специфичность — одного класса: рамку и вес своих итогов
   страница задаёт классом строки (.payroll-total-row и т. п.). */
.tms-table :where(tfoot td) {
    padding: 12px 6px;
    border-top: 1px solid var(--border);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
}

/* Край ряда. :where() не поднимает специфичность выше правил ячеек:
   CSS страницы, переопределивший отступы своей плотностью, по-прежнему
   побеждает порядком подключения. */
.tms-table thead th:where(:first-child),
.tms-table tbody td:where(:first-child),
.tms-table :where(tfoot td:first-child) {
    padding-left: 14px;
}

.tms-table thead th:where(:last-child),
.tms-table tbody td:where(:last-child),
.tms-table :where(tfoot td:last-child) {
    padding-right: 14px;
}

/* Вторичная строка под значением ячейки: дата, основание, пояснение. */
.tms-table .cell-sub {
    display: block;
    margin-top: 2px;
    font-size: var(--text-xs);
    color: var(--muted);
}

.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;
}

/* Пагинация (ADR-0072): «‹ Назад · 1 … 4 5 6 … 12 · Вперёд ›», номера —
   кнопки вида secondary, текущая — primary. */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
}

.pagination-link,
.pagination-ellipsis {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    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);
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

/* «‹ Назад» / «Вперёд ›» — подписаны словами, шеврон скрыт от диктора */
.pagination-step {
    padding: 0 10px;
}

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

.pagination-ellipsis {
    min-width: 24px;
    padding: 0;
    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);
}

/* Действие строки с подписью — для доменного действия без общепринятой
   иконки («Проверить», «+ Расчёт»): тот же тон, что у иконки, — без рамки
   и фона, при наведении подложка (ADR-0068). Стоит в своей ячейке и видно
   всегда, не прячется в .row-actions до наведения (ui-guide §13). */
.row-action--label {
    width: auto;
    padding: 0 8px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
}

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

/* Поиск по таблице */
.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:hover {
    border-color: var(--border-input-hover);
}

.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-фильтр (направление, статус и т.д.): геометрия и токены — как у
   .tms-input (36px, радиус 8, наведение), стрелка — общая (globals.css);
   шрифт — мелкий, как у чипов панели. */
.filter-select {
    min-height: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-xs);
    font-size: var(--text-xs);
    background-color: var(--surface);
    color: var(--text);
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.filter-select:hover {
    border-color: var(--border-input-hover);
}

.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;
}

/* Низ реестра (ADR-0072) — одна строка: счётчик | страницы | «Показывать» */
.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(--text-secondary);
    font-size: var(--text-sm);
    white-space: nowrap;
}

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

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

.page-size-select {
    min-width: 64px;
    width: auto;
    height: 32px;
    min-height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    font-size: var(--text-sm);
    background: var(--surface);
    color: var(--text);
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.page-size-select:hover {
    border-color: var(--border-input-hover);
}

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

/* ── Чипы-фильтры (ui-guide §4, решение 0011, решение владельца 28.09.2026) ──
   Ссылки в .chip-group с подписью (role="group" + aria-labelledby).
   Невыбранный — рамка --border-interactive, наведение меняет фон и рамку;
   выбранный — фон --info-bg, текст --primary, «✓» и рамка --primary
   (граница формы к фону страницы 4,83:1 — WCAG 1.4.11), aria-current,
   на наведение не реагирует. 28px / 12px — меньше кнопки: чип выбирает
   режим, кнопка выполняет действие. */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--border-interactive);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-xs);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

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

.chip.is-selected,
.chip.is-selected:hover {
    border-color: var(--primary);
    background: var(--info-bg);
    color: var(--primary);
}

.chip.is-selected::before {
    content: "✓";
}

.chip-count {
    font-weight: 400;
    color: var(--muted);
}

/* ── Мобильная адаптация списков (≤ 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;
    }
}
