/* Единый слой адаптации для публичных страниц, импорта и администрирования.
   Не скрываем данные и не маскируем горизонтальное переполнение body. */
.row > *,
.d-flex > *,
.card,
.card-body,
.accordion-body,
.modal-content {
    min-width: 0;
}

.table-responsive,
.judge-scroll {
    max-width: 100%;
    overscroll-behavior-x: contain;
}

.table-scroll-hint {
    margin: .5rem 0;
    padding-inline: .5rem;
    color: #495057;
    font-size: .875rem;
}

.table-responsive:focus-visible,
.judge-scroll:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: -3px;
}

img,
canvas {
    max-width: 100%;
}

/* Матрица использует светлый sticky header, а не синий заголовок .table. */
.judge-matrix thead th {
    color: var(--bs-body-color);
    text-shadow: none;
}

@media (max-width: 1199.98px) {
    .navbar .dropdown-menu {
        min-width: 0 !important;
        width: 100%;
    }

    .navbar .nav-link,
    .navbar .dropdown-item {
        white-space: normal;
        gap: .5rem;
    }

    .navbar .dropdown-item i {
        flex-shrink: 0;
    }
}

@media (max-width: 767.98px) {
    main.container {
        padding-inline: 1rem;
    }

    /* Вложенные container у старых страниц не отнимают место у контента. */
    main > .container,
    main > .container-fluid {
        padding-inline: 0;
    }

    main .d-flex:not(.input-group) {
        flex-wrap: wrap;
        gap: .5rem;
    }

    main > .d-flex.justify-content-between,
    .card-header.d-flex,
    .card-header > .d-flex.justify-content-between {
        flex-direction: column;
        align-items: stretch !important;
    }

    main .position-relative[style*="width:"],
    main .form-control[style*="width:"],
    main .form-select[style*="width:"] {
        max-width: 100%;
        width: 100% !important;
        min-width: 0 !important;
    }

    .form-control,
    .form-select {
        min-width: 0;
        max-width: 100%;
        font-size: 1rem; /* iOS не увеличивает страницу при фокусе. */
        min-height: 44px;
    }

    .btn {
        min-height: 44px;
        max-width: 100%;
        white-space: normal;
    }

    .btn-group {
        max-width: 100%;
        gap: .25rem;
    }

    .card-header,
    .card-body,
    .performance-history-card .card-body {
        padding: 1rem;
    }

    .card-header h4,
    .card-header h5 {
        font-size: 1.125rem;
    }

    .badge {
        max-width: 100%;
        white-space: normal;
        line-height: 1.4;
    }

    .athlete-info .info-item {
        display: block;
        overflow-wrap: break-word;
    }

    .athlete-info .info-item strong {
        margin-bottom: .5rem;
    }

    /* У четырёх и более столбцов сохраняем читаемую ширину, а не
       сжимаем имена/даты до одного символа. Скролл только у обёртки. */
    .table-responsive > table:has(> thead > tr > :nth-child(4)),
    .judge-scroll > table {
        min-width: 40rem;
    }

    .table-responsive th,
    .table-responsive td,
    .judge-scroll th,
    .judge-scroll td {
        overflow-wrap: normal;
        word-break: normal;
        padding: .65rem .5rem;
    }

    .table-responsive .form-control,
    .table-responsive .form-select {
        min-width: 8rem;
    }

    .table-responsive .btn {
        width: auto;
    }

    .table-responsive th[data-sort="name"],
    .table-responsive th[data-sort="club"],
    .table-responsive th.name-column,
    .table-responsive .rank-table th:nth-child(2),
    .table-responsive .category-table th:nth-child(2),
    .table-responsive .category-table th:nth-child(3),
    .table-responsive .category-table th:nth-child(4) {
        min-width: 14rem;
    }

    /* Работает и для строк, добавленных через API: идентифицирующие
       ссылки не должны сжиматься между числовыми столбцами. */
    .table-responsive td:has(a:is([href^="/athlete/"], [href^="/event/"], [href^="/club/"], [href^="/coach/"], [href^="/admin/judging-corridors/"]):not(.btn)) {
        min-width: 14rem;
    }

    .method-switch {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .method-switch .btn {
        flex: 1 1 9rem;
        width: auto;
    }

    .info-table,
    .info-table tbody,
    .info-table tr,
    .info-table td {
        display: block;
        width: 100%;
    }

    .info-table td {
        padding: .5rem;
        overflow-wrap: break-word;
    }

    .info-table td:first-child {
        padding-bottom: 0;
        border-bottom: 0;
    }

    .base-source-name {
        display: block;
        min-width: min(14rem, 100%);
        overflow-wrap: break-word;
    }

    .judge-matrix th:first-child,
    .judge-matrix td:first-child {
        min-width: 9rem;
        max-width: 9rem;
        width: 9rem;
        white-space: normal;
    }

    .accordion-button {
        padding: 1rem;
    }

    .accordion-button > .d-flex,
    .accordion-button > span {
        min-width: 0;
        flex-wrap: wrap;
        gap: .5rem;
    }

    .accordion-button::after {
        flex-shrink: 0;
        margin-left: .75rem;
    }

    .accordion-body {
        padding: .75rem;
    }

    .upload-area {
        padding: 1.5rem 1rem;
    }

    .chart-container {
        height: 260px;
        padding: .5rem;
    }

    .modal-header,
    .modal-body,
    .printout-modal-header,
    .printout-modal-body {
        padding: 1rem;
    }

    .modal-header .modal-title {
        min-width: 0;
        font-size: 1.125rem;
    }

    .modal-body,
    .printout-section,
    .printout-summary {
        overflow-x: auto;
        overscroll-behavior-x: contain;
    }

    .printout-table {
        min-width: 40rem;
    }

    main .batch-page .actions {
        position: static; /* Длинная панель не перекрывает форму на телефоне. */
    }

    .pagination {
        gap: .25rem;
    }

    .pagination .page-link {
        padding-inline: .65rem;
    }
}

@media (max-width: 575.98px) {
    /* Три/четыре узких счётчика и поля фильтров становятся отдельными строками. */
    main .row > .col-4,
    main .row > .col-3,
    main .row > .col-6:has(.form-select, .form-control) {
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
    }

    .stat-item {
        padding: .75rem;
    }

    .stat-item .text-nowrap {
        white-space: normal !important;
    }

    .judge-page .season-select {
        min-width: 0;
        width: 100%;
    }
}

@media (hover: none) {
    .card:hover,
    .table-hover tbody tr:hover,
    .table tbody tr:hover {
        transform: none;
    }
}
