/* ============================================================================
   Таблицы
   ============================================================================ */

.applications-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.applications-table td,
.applications-table th {
    padding: 0.35rem 0.5rem; /* Уменьшен padding для компактности */
    border-bottom: 1px solid rgba(16, 100, 209, 0.15);
    text-align: center;
    vertical-align: middle;
}

/* Изолируем выпадающие списки статусов от border таблицы */
.applications-table td .status-select,
.applications-table td .choices,
.applications-table td .choices__list--dropdown,
.applications-table td .choices__list--dropdown .choices__item {
    border-bottom: none !important;
}

/* Убираем влияние border ячейки таблицы на выпадающий список */
.applications-table td:has(.status-select),
.applications-table td:has(.choices) {
    overflow: visible !important;
}

/* Альтернативный способ для браузеров без поддержки :has() */
.applications-table td .choices {
    position: relative !important;
    z-index: 11000 !important; /* Базовый z-index для закрытых списков */
    isolation: isolate !important;
}

/* Открытый список должен перекрывать закрытые */
.applications-table td .choices.is-open {
    z-index: 12000 !important; /* Высокий z-index для открытого контейнера */
}

.applications-table td .choices__list--dropdown {
    position: absolute !important;
    z-index: 11000 !important; /* Базовый z-index для закрытых списков */
    isolation: isolate !important;
    border-bottom: none !important;
}

/* Открытый выпадающий список должен быть выше закрытых */
.applications-table td .choices.is-open .choices__list--dropdown {
    z-index: 12000 !important; /* Высокий z-index для открытого списка - перекрывает закрытые */
}

.applications-table thead th {
    background: linear-gradient(180deg, rgba(239, 246, 255, 0.9), rgba(224, 231, 255, 0.7), rgba(237, 233, 254, 0.6));
    color: #1064d1;
    font-weight: 700;
    border-bottom: 2px solid;
    border-image: linear-gradient(90deg, rgba(16, 100, 209, 0.4), rgba(139, 92, 246, 0.4)) 1;
}

.applications-table tbody tr {
    height: auto; /* Автоматическая высота строки */
    min-height: auto; /* Минимальная высота без ограничений */
}

.applications-table tbody tr:hover {
    background: rgba(239, 246, 255, 0.5);
}

.applications-table th {
    font-size: 0.75rem; /* Уменьшен размер шрифта для компактности */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    padding: 0.4rem 0.5rem; /* Уменьшен padding для заголовков */
}

/* Колонка статуса - делаем уже */
.applications-table th:nth-child(2),
.applications-table td:nth-child(2) {
    width: 120px;
    max-width: 120px;
    min-width: 120px;
}

/* Селектор статуса в таблице - ограничиваем ширину для соответствия колонке */
.applications-table td:nth-child(2) .status-select {
    min-width: 110px !important;
    max-width: 120px !important;
    width: 100% !important;
}

.applications-table td:nth-child(2) .status-select + .choices,
.applications-table td:nth-child(2) .status-select + .choices .choices__inner {
    min-width: 110px !important;
    max-width: 120px !important;
    width: 100% !important;
}

.applications-table td:nth-child(2) .status-select + .choices .choices__list--dropdown {
    min-width: 110px !important;
    max-width: 120px !important;
    width: 100% !important;
}

/* Колонка оператора - фиксированная ширина для предотвращения заползания на статус */
/* Применяется только к таблицам, где есть селектор оператора */
.applications-table th:nth-child(3),
.applications-table td:nth-child(3):has(.operator-select),
.applications-table td:nth-child(3):has(.filter-select.operator-select) {
    width: 180px;
    max-width: 180px;
    min-width: 180px;
    overflow: hidden;
    word-wrap: break-word;
}

/* Альтернативный селектор для браузеров без поддержки :has() */
.applications-table td:nth-child(3) .operator-select,
.applications-table td:nth-child(3) .filter-select.operator-select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

/* Нативный select оператора в строке: скругление и SVG-стрелка (как в панели фильтров, не квадрат ОС) */
.applications-table select.filter-select.operator-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border-radius: 12px;
    border: 2px solid var(--form-border-color);
    background-color: var(--form-bg);
    color: var(--form-text);
    cursor: pointer;
    color-scheme: light;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%231064d1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 0.75rem;
    padding: 0.3rem 1.75rem 0.3rem 0.45rem;
    min-height: 30px;
    line-height: 1.25;
    text-align: center;
}

.applications-table select.filter-select.operator-select:focus {
    outline: none;
    border-color: var(--form-border-focus);
    box-shadow: 0 0 0 2px var(--form-focus-shadow);
}

/* Опции в селекторе оператора - обрезаем длинные имена */
.applications-table td .operator-select option,
.applications-table td .filter-select.operator-select option {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Столбцы с суммами — по центру, моноширинные цифры */
.applications-table th.amount-column,
.applications-table td.amount-column {
    white-space: nowrap !important;
    text-align: center !important;
    font-variant-numeric: tabular-nums;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
}

/* Колонка: скрепка и при необходимости экстренная оплата */
th.dashboard-docs-col,
td.dashboard-docs-cell {
    width: 6.5rem;
    min-width: 6rem;
    max-width: 7rem;
    text-align: center;
    vertical-align: middle;
    padding-left: 0.1rem !important;
    padding-right: 0.25rem !important;
}

.dashboard-docs-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.3rem;
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    padding-bottom: 0.1rem;
}

.dashboard-docs-actions::-webkit-scrollbar {
    height: 5px;
}

.dashboard-docs-actions::-webkit-scrollbar-thumb {
    background: rgba(16, 100, 209, 0.35);
    border-radius: 4px;
}

.dashboard-postpaid-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2rem;
    width: 2rem;
    min-width: 2rem;
    padding: 0;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.16);
    color: #1e40af;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    flex: 0 0 auto;
}

.dashboard-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: rgba(16, 100, 209, 0.12);
    color: #0f4f9a;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s ease, transform 0.1s ease;
    flex: 0 0 auto;
}

.dashboard-attach-btn svg {
    width: 1.05rem;
    height: 1.05rem;
    flex-shrink: 0;
}

.dashboard-attach-btn:hover {
    background: rgba(16, 100, 209, 0.22);
}

.dashboard-attach-btn:focus-visible {
    outline: 2px solid rgba(16, 100, 209, 0.5);
    outline-offset: 2px;
}

/* Кнопка «монетки» — экстренная оплата */
.dashboard-emergency-pay-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: rgba(180, 120, 20, 0.14);
    color: #8a5a00;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s ease, transform 0.1s ease;
    flex: 0 0 auto;
}

.dashboard-emergency-pay-btn svg {
    width: 1.05rem;
    height: 1.05rem;
    flex-shrink: 0;
}

.dashboard-emergency-pay-btn:hover {
    background: rgba(180, 120, 20, 0.26);
}

.dashboard-emergency-pay-btn:focus-visible {
    outline: 2px solid rgba(180, 120, 20, 0.55);
    outline-offset: 2px;
}

.emergency-payment-modal-text {
    margin: 0.75rem 0 0.35rem;
    font-size: 1.05rem;
    font-weight: 600;
}

.emergency-payment-modal-hint {
    margin: 0 0 1rem;
    font-size: 0.9rem;
    line-height: 1.45;
    color: rgba(15, 23, 42, 0.72);
}

.emergency-payment-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

/* Строки настройки типа документа в модалках загрузки */
.dashboard-doc-per-file-rows {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-top: 0.5rem;
    max-height: 14rem;
    overflow-y: auto;
}

.dashboard-doc-per-file-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid rgba(148, 163, 184, 0.35);
}

.dashboard-doc-per-file-row .doc-row-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    word-break: break-all;
}

.dashboard-doc-per-file-row select.modal-input,
.dashboard-doc-per-file-row input.modal-input {
    width: 100%;
}

.applications-table.wide td form.inline-form {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Текст в компактных селекторах статуса в строке заявки */
.applications-table .choices .choices__inner {
    text-align: center;
    justify-content: center;
}

.table-wide {
    width: 100%;
    border-collapse: collapse;
}

.table-wide td,
.table-wide th {
    padding: 0.35rem 0.5rem; /* Уменьшен padding для компактности */
    text-align: left;
    border-bottom: 1px solid rgba(16, 100, 209, 0.15);
}

.table-wide th {
    font-size: 0.75rem; /* Уменьшен размер шрифта для компактности */
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #1064d1;
    font-weight: 700;
    background: linear-gradient(180deg, rgba(239, 246, 255, 0.9), rgba(224, 231, 255, 0.7), rgba(237, 233, 254, 0.6));
    border-bottom: 2px solid;
    border-image: linear-gradient(90deg, rgba(16, 100, 209, 0.4), rgba(139, 92, 246, 0.4)) 1;
    padding: 0.4rem 0.5rem; /* Уменьшен padding для заголовков */
}

.table-wide tbody tr:hover {
    background: rgba(239, 246, 255, 0.4);
}

/* ============================================================================
   АДАПТИВНОСТЬ ТАБЛИЦ
   ============================================================================ */

/* Обертка для горизонтальной прокрутки на мобильных */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible !important; /* Убираем вертикальную прокрутку - важно для выпадающих списков */
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
    position: relative;
    /* Фон наследуется от родителя (карточки) */
    background: transparent;
    /* Убираем горизонтальные отступы для синхронизации с фоном карточки */
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
    max-height: none; /* Убираем ограничение высоты */
}

/* На больших экранах таблица внутри обертки должна быть 100% */
.table-wrapper .applications-table,
.table-wrapper .table-wide {
    width: 100%;
    min-width: 100%;
}

.table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.5);
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(168, 85, 247, 0.7);
}

/* Адаптивность для таблиц */
@media (max-width: 1024px) {
    .applications-table,
    .table-wide {
        font-size: 0.85rem;
    }
    
    .applications-table td,
    .applications-table th,
    .table-wide td,
    .table-wide th {
        padding: 0.3rem 0.4rem; /* Уменьшен padding для компактности */
    }
    
    .applications-table th,
    .table-wide th {
        font-size: 0.7rem; /* Уменьшен размер шрифта */
        padding: 0.35rem 0.4rem; /* Уменьшен padding для заголовков */
    }
    
    /* На планшетах таблица должна быть 100% ширины, но может прокручиваться */
    .table-wrapper .applications-table,
    .table-wrapper .table-wide {
        width: 100%;
        min-width: 100%;
    }
    
    /* Корректируем отступы для планшетов */
    .table-wrapper {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* На очень маленьких экранах - уменьшаем размеры и делаем более компактными */
@media (max-width: 768px) {
    /* Таблицы внутри обертки получают min-width для прокрутки, но не width: 100% */
    .table-wrapper .applications-table,
    .table-wrapper .table-wide {
        font-size: 0.8rem;
        width: auto;
        min-width: 600px; /* Минимальная ширина для горизонтальной прокрутки */
    }
    
    /* Корректируем отступы для мобильных */
    .table-wrapper {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
        border-radius: 0;
    }
    
    .applications-table td,
    .applications-table th,
    .table-wide td,
    .table-wide th {
        padding: 0.375rem 0.5rem;
        white-space: nowrap;
    }
    
    .applications-table th,
    .table-wide th {
        font-size: 0.65rem;
        letter-spacing: 0.02em;
        padding: 0.4rem 0.5rem;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    /* Удаляем автоматическое скрытие колонок - пусть таблица прокручивается */
    /* Это лучше для пользователя, так как он может видеть всю информацию */
}

/* На очень маленьких экранах (до 480px) - еще более компактный вид */
@media (max-width: 480px) {
    .table-wrapper .applications-table,
    .table-wrapper .table-wide {
        font-size: 0.75rem;
        width: auto;
        min-width: 500px;
    }
    
    .applications-table td,
    .applications-table th,
    .table-wide td,
    .table-wide th {
        padding: 0.3rem 0.4rem;
    }
    
    .applications-table th,
    .table-wide th {
        padding: 0.35rem 0.4rem;
        font-size: 0.6rem;
    }
    
    /* Корректируем отступы для маленьких мобильных */
    .table-wrapper {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* На самых маленьких экранах */
@media (max-width: 375px) {
    .table-wrapper .applications-table,
    .table-wrapper .table-wide {
        font-size: 0.7rem;
        min-width: 450px;
    }
    
    .applications-table td,
    .applications-table th,
    .table-wide td,
    .table-wide th {
        padding: 0.25rem 0.3rem;
    }
    
    .applications-table th,
    .table-wide th {
        padding: 0.3rem 0.3rem;
        font-size: 0.55rem;
    }
    
    .table-wrapper {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* ============================================================================
   Дашборд заявок: загрузка по AJAX без смещения шапки, появление строк
   ============================================================================ */

#dashboardTableContainer {
    position: relative;
}

#dashboardTableContainer > .ajax-loader {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 3.25rem;
    box-sizing: border-box;
    background: color-mix(in srgb, var(--card-bg, #ffffff) 78%, transparent);
    backdrop-filter: blur(3px);
    pointer-events: none;
    color: rgba(15, 23, 42, 0.72);
    font-weight: 600;
    font-size: 0.95rem;
}

@supports not (background: color-mix(in srgb, white 50%, transparent)) {
    #dashboardTableContainer > .ajax-loader {
        background: rgba(255, 255, 255, 0.82);
    }
}

@keyframes dashboard-row-reveal {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.applications-table.wide tbody tr.dashboard-table-row {
    animation: dashboard-row-reveal 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: calc(var(--dash-row-i, 0) * 0.038s);
    animation-fill-mode: backwards;
}

@media (prefers-reduced-motion: reduce) {
    .applications-table.wide tbody tr.dashboard-table-row {
        animation: none;
    }
}

