/*
 * responsive.css — адаптивность (REQ-066, NFR-UX-001): 1280 / 768 / 360 px, касание ≥ 44 px,
 * шрифт ≥ 14 px, уважение к prefers-reduced-motion. Подключается последним.
 */

/* ---------- ≤ 1279 px: узкий десктоп ---------- */
@media (max-width: 1279.98px) {
    :root {
        --sidebar-width: 220px;
    }

    .layout-main {
        padding: var(--space-5) var(--space-5) var(--space-7);
    }

    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- ≤ 1023 px: планшет — боковая панель выезжает по кнопке меню ---------- */
@media (max-width: 1023.98px) {
    .navbar-toggle {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        bottom: 0;
        height: auto;
        width: min(300px, 85vw);
        box-shadow: var(--shadow-lg);
        transform: translateX(-105%);
        transition: transform var(--transition);
        z-index: calc(var(--z-navbar) - 1);
    }

    .nav-toggle:checked ~ .layout .sidebar {
        transform: translateX(0);
    }

    .nav-toggle:checked ~ .layout .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: var(--navbar-height) 0 0 0;
        z-index: calc(var(--z-navbar) - 2);
        background: var(--color-overlay);
    }

    .nav-toggle:focus-visible ~ .navbar .navbar-toggle {
        outline: 3px solid var(--color-focus);
        outline-offset: 2px;
    }

    .layout-main {
        padding: var(--space-4) var(--space-4) var(--space-7);
    }

    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- ≤ 767 px: смартфон ---------- */
@media (max-width: 767.98px) {
    :root {
        --font-size-xxl: 22px;
        --font-size-xl: 20px;
    }

    .navbar {
        padding: 0 var(--space-2);
        gap: var(--space-2);
    }

    .navbar-brand-text,
    .navbar-user-role {
        display: none;
    }

    .navbar-user-name {
        max-width: 120px;
    }

    .page-header {
        align-items: stretch;
        flex-direction: column;
        margin-bottom: var(--space-4);
    }

    .page-actions .btn {
        flex: 1 1 auto;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: minmax(0, 1fr);
    }

    .card-body {
        padding: var(--space-4);
    }

    .auth-card,
    .error-card {
        padding: var(--space-5) var(--space-4);
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-card {
        max-width: none;
        max-height: 92vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .modal-actions .btn {
        flex: 1 1 auto;
    }

    .toast-region {
        left: var(--space-2);
        right: var(--space-2);
        bottom: var(--space-2);
        width: auto;
        max-width: none;
    }

    .dropdown-panel {
        position: fixed;
        top: var(--navbar-height);
        left: var(--space-2);
        right: var(--space-2);
        width: auto;
        max-width: none;
    }

    .pagination {
        justify-content: center;
    }

    /* Таблица → карточки: ячейки с data-label показывают подпись столбца */
    .table-cards thead {
        display: none;
    }

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

    .table-cards tr {
        padding: var(--space-3) var(--space-4);
        border-bottom: 1px solid var(--color-border);
    }

    /* Подпись — плавающая слева, содержимое ячейки — одним потоком справа. Не flex: в flex каждый узел ячейки
       (текст, ссылка, строка-пояснение) становился отдельной колонкой и сжимался в узкие столбики (W5). */
    .table-cards td {
        display: block;
        padding: var(--space-1) 0;
        border: 0;
        text-align: right;
    }

    .table-cards td::before {
        content: attr(data-label);
        float: left;
        max-width: 50%;
        margin-right: var(--space-3);
        font-weight: var(--font-weight-medium);
        color: var(--color-text-muted);
        text-align: left;
    }

    .table-cards td::after {
        content: "";
        display: block;
        clear: both;
    }

    .table-cards td > .inline-group {
        justify-content: flex-end;
    }

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

/* ---------- Цели касания ≥ 44 px: сенсорный ввод на любой ширине и любые экраны ≤ 1023 px (T-14.13) ---------- */
@media (pointer: coarse), (max-width: 1023.98px) {
    .btn,
    .btn-sm,
    .btn-icon,
    .form-control,
    .form-control-sm,
    .nav-link,
    .tab,
    .dropdown-footer,
    .navbar-user {
        min-height: var(--touch-target);
    }

    .btn-icon,
    .toast-close {
        width: var(--touch-target);
        height: var(--touch-target);
    }

    .radio,
    .checkbox {
        min-height: var(--touch-target);
    }

    .navbar-user {
        justify-content: center;
    }

    /* Ссылки-кнопки и ссылки строк списка — блочная зона касания, а не только высота строки текста */
    .btn-link,
    .row-link,
    .breadcrumbs a {
        display: inline-flex;
        align-items: center;
        min-height: var(--touch-target);
    }

    /* 16 px в полях ввода: iOS не масштабирует страницу при фокусе */
    .form-control,
    .form-control-sm {
        font-size: var(--font-size-md);
    }
}

/* ---------- Пониженная анимация ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- Печать ---------- */
@media print {
    .navbar,
    .sidebar,
    .sidebar-backdrop,
    .page-actions,
    .toast-region,
    .skip-link,
    .pagination {
        display: none !important;
    }

    body {
        background: #ffffff;
    }

    .layout-main {
        padding: 0;
        max-width: none;
    }
}

/* ---------- Страницы W2: фильтры, списки, двухколоночные карточки ---------- */
@media (max-width: 1023.98px) {
    .two-columns {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 767.98px) {
    .filters {
        padding: var(--space-3);
    }

    .filters-grid,
    .checkbox-group {
        grid-template-columns: minmax(0, 1fr);
    }

    .filters-actions .btn,
    .list-toolbar .btn {
        flex: 1 1 auto;
    }

    .date-range {
        flex-direction: column;
    }

    .upload-item select {
        max-width: none;
        width: 100%;
    }

    .dropzone {
        padding: var(--space-5) var(--space-3);
    }

    .dropzone-actions .btn {
        flex: 1 1 100%;
    }
}

@media (pointer: coarse), (max-width: 1023.98px) {
    .sort-btn,
    .evidence-link,
    .filters-more > summary {
        min-height: var(--touch-target);
    }

    .evidence-link {
        display: inline-flex;
        align-items: center;
    }
}

/* ---------- 360 px: без горизонтальной прокрутки страницы (длинные подписи переносятся) ---------- */
@media (max-width: 767.98px) {
    .btn,
    .badge {
        white-space: normal;
        text-align: center;
    }

    .table-cards td {
        overflow-wrap: anywhere;
    }

    .table-cards td > * {
        min-width: 0;
    }

    .meta-list {
        grid-template-columns: minmax(0, 1fr);
        gap: 0 var(--space-2);
    }

    .meta-list dd {
        margin-bottom: var(--space-2);
    }

    .card-header.inline-group > .form-control-sm {
        max-width: 100%;
    }
}
