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

/* ── 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: 10px;
    width: 100%;
    min-width: 0;
    margin: 0;
    height: 100%;
    min-height: 0;
}

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

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

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

/* 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);
}
