/* Adaptación compartida: los estilos de escritorio siguen en cada vista. */
.public-form-page {
    min-height: calc(100vh - 52px);
    min-height: calc(100dvh - 52px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.public-form-container { width: 100%; min-width: 0; }
.public-form-login { max-width: 480px; }
.public-form-register { max-width: 520px; }
.public-form-ticket { max-width: 620px; }
.guest-identity-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
.mobile-menu-toggle { display: none; }
.admin-mobile-navigation { display: none; }
.ticket-navigation-toggle, .ticket-sort-controls, .ticket-subject-full { display: none; }
.page-wrapper { width: 100%; max-width: none; }
.page-wrapper.tickets-index-page { width: 100%; }
#navbarAccountMenu { display: flex; }
.ticket-detail-page { width: 100%; margin: 0 auto; padding: 20px 24px 80px; }

/* El ancho disponible y el tipo de interacción definen el modo compacto. */
@media (max-width: 991.98px), (pointer: coarse) and (max-width: 1366px) {
    .top-navbar { padding: 0 16px; gap: 12px; }
    .mobile-menu-toggle {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        min-height: 44px;
        padding: 8px 12px;
        border: 1px solid rgba(255,255,255,.3);
        border-radius: 6px;
        background: transparent;
        color: #fff;
        font: inherit;
    }
    #navbarAccountMenu {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        max-height: calc(100vh - 52px);
        max-height: calc(100dvh - 52px);
        overflow-y: auto;
        background: #243447;
        padding: 16px;
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        box-shadow: 0 6px 12px rgba(0,0,0,.2);
    }
    #navbarAccountMenu:not(.show):not(.collapsing) { display: none; }
    #navbarAccountMenu > a,
    #navbarAccountMenu form button { min-height: 44px; }
    #navbarAccountMenu.collapsing { transition: none; }
    #notifPanel { width: min(320px, calc(100vw - 32px)) !important; left: 0; right: auto !important; }
    .ticket-page { flex-direction: column; }
    .ticket-main, .ticket-side { width: 100%; }
    body .admin-layout { flex-direction: column; }
    body .admin-sidebar { display: none; }
    .admin-mobile-navigation { display: block; background: #1a2332; color: #fff; }
    .admin-mobile-navigation summary { padding: 14px 16px; cursor: pointer; }
    .admin-mobile-navigation nav { max-height: 45vh; max-height: 45dvh; overflow-y: auto; }
    .admin-mobile-navigation .sidebar-nav-item { min-height: 44px; white-space: normal; }
    body .admin-content, body .admin-layout .admin-wrapper { padding: 20px 16px 96px; }
    body .admin-page-header { flex-wrap: wrap; gap: 12px; }
    body .admin-page-header > div { min-width: 0; flex-wrap: wrap; }
    body .admin-card:has(> table) { overflow-x: auto !important; }
    body .agent-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
    body .agent-name { overflow-wrap: anywhere; }
}

@media (max-width: 991.98px), (pointer: coarse) and (max-width: 1366px) {
    /* 16px evita el zoom automático al enfocar campos en teléfonos. */
    .form-control, .form-select, .form-control-custom,
    .reply-wrap textarea, .side-status-select {
        font-size: 1rem !important;
        min-height: 44px;
    }
    .public-form-page {
        padding: 28px 12px 96px;
        align-items: flex-start;
    }
    .public-form-container { max-width: none; }
    .public-form-container .form-label-custom { font-size: .95rem; }
    .public-form-container .btn-submit-ticket { min-height: 48px; font-size: 1rem !important; }
    .public-form-container a { min-height: 44px; align-content: center; }
    .public-form-container h1 { font-size: 1.6rem !important; }
    .public-form-container h2 { font-size: 1.1rem !important; }
    .login-options { flex-wrap: wrap; gap: 8px 16px; }
    .login-options label { min-height: 44px; }
    .guest-identity-fields { grid-template-columns: minmax(0, 1fr); }
    .content-card-header, .page-header { flex-wrap: wrap; gap: 12px; }
    .content-card-search { max-width: 100%; }
    .content-card-search input { width: 100%; min-height: 44px; font-size: 1rem; }
    .breadcrumb-bar { flex-wrap: wrap; }
    .page-wrapper { padding-bottom: 96px; }
    .admin-layout input:not([type="checkbox"]):not([type="radio"]),
    .admin-layout select, .admin-layout textarea { font-size: 1rem !important; min-height: 44px; }
    .ticket-detail-page { padding: 16px 12px 96px; }
    .tk-header { padding: 20px 16px; }
    .tk-title, .tk-desc, .c-body, .att-pill, .info-list .val { overflow-wrap: anywhere; }
    .tk-desc, .c-body { font-size: .95rem; }
    .comment-head { flex-wrap: wrap; }
    .c-time { white-space: normal; }
    .info-list li { gap: 12px; flex-wrap: wrap; }
    .toast-container { left: 12px; right: 12px; bottom: 84px; }
    .toast-msg { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
    #newTicketModal .modal-header,
    #newTicketModal .modal-body,
    #newTicketModal .modal-footer { padding: 16px !important; }
    #newTicketModal .modal-title { font-size: 1.1rem !important; }
    #newTicketModal .modal-footer { gap: 8px; flex-wrap: wrap; }
    #newTicketModal .modal-footer button { min-height: 44px; margin: 0; }
    #newTicketModal .btn-close { flex-shrink: 0; width: 44px; height: 44px; padding: 0; margin: 0; }
    #modalFileNames, #fileNames { overflow-wrap: anywhere; }

    /* Navegación disponible bajo un control plegable; los tickets van primero. */
    .page-wrapper, .page-wrapper.tickets-index-page {
        flex-direction: column;
        gap: 16px;
        padding: 16px 12px 96px;
    }
    .page-wrapper .sidebar, .page-wrapper .main-content { width: 100%; }
    .ticket-navigation-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 48px;
        padding: 12px 16px;
        border: 1px solid #dbe2ea;
        border-radius: 8px;
        background: #fff;
        color: #243447;
        font-weight: 600;
        cursor: pointer;
        list-style: none;
    }
    .ticket-navigation-toggle::-webkit-details-marker { display: none; }
    .ticket-navigation[open] .ticket-navigation-toggle .fa-chevron-down { transform: rotate(180deg); }
    .ticket-navigation-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 12px; padding-top: 12px; }
    .ticket-navigation-body .sidebar-section { margin: 0; }
    .sidebar-item { min-height: 44px; font-size: 1rem; }
    .sidebar-item .item-left { min-width: 0; }
    #cta-new-ticket { padding: 18px 16px !important; gap: 12px !important; }
    #cta-new-ticket > div { min-width: 0; }
    #cta-new-ticket > div:nth-last-child(3) { width: 44px !important; height: 44px !important; }
    #attention-banner { flex-wrap: wrap; padding: 16px !important; }
    #attention-banner > div { min-width: 0; }
    #attention-banner > div:last-child { flex-wrap: wrap; }
    #filterForm { display: grid !important; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); padding: 16px !important; }
    #filterForm > div { min-width: 0 !important; }
    #filterForm > div:first-of-type { grid-column: 1 / -1; }
    #filterForm input:not([type="hidden"]), #filterForm select { font-size: 1rem !important; min-height: 44px; }
    #filterForm label { font-size: .875rem !important; }
    #filterForm button, #filterForm a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; font-size: 1rem !important; }
    #filterForm > span { margin-left: 0 !important; }
    .ticket-sort-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; }
    .ticket-sort-controls > span { font-size: .875rem; color: #718096; }
    .ticket-sort-controls a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 12px; border: 1px solid #dbe2ea; border-radius: 6px; color: #2980b9; text-decoration: none; }
    .ticket-sort-controls a.active { background: #ebf5fb; border-color: #3498db; }

    /* Tarjetas legibles en una o dos columnas, con todos los campos del ticket. */
    .tickets-index-page .ticket-table, .tickets-index-page .ticket-table tbody { display: block; width: 100%; }
    .tickets-index-page .ticket-table thead { display: none; }
    .tickets-index-page .ticket-table tbody { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 12px; padding: 12px; }
    .tickets-index-page .ticket-table tbody tr { display: flex; flex-direction: column; margin: 0; padding: 16px; border: 1px solid #dbe2ea; border-radius: 8px; background: #fff; }
    .tickets-index-page .ticket-table tbody td,
    .tickets-index-page .ticket-table tbody td:nth-child(n) {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        width: 100%;
        padding: 7px 0;
        border: 0;
        font-size: 1rem;
        overflow-wrap: anywhere;
    }
    .tickets-index-page .ticket-table tbody td::before { content: attr(data-label); flex-shrink: 0; font-size: .825rem; font-weight: 700; color: #718096; }
    .tickets-index-page .ticket-table tbody td.celda-asunto { display: block; order: -1; padding-bottom: 12px; margin-bottom: 6px; border-bottom: 1px solid #e8ecf0; }
    .tickets-index-page .ticket-table tbody td.celda-asunto::before { content: none; }
    .tickets-index-page .ticket-subject-link, .tickets-index-page .ticket-subject-sub { font-size: 1rem; line-height: 1.5; }
    .ticket-subject-preview { display: none; }
    .ticket-subject-full { display: inline; }
    .tickets-index-page .status-badge, .tickets-index-page .priority-badge { font-size: .875rem; white-space: normal; }
    body .bur-panel {
        top: 0; right: 0; bottom: 0; left: 0;
        width: 100%; height: 100vh; height: 100dvh;
        max-height: none; border-radius: 0;
    }
    .bur-cerrar { min-width: 44px; min-height: 44px; }
}

@media (min-width: 600px) {
    .guest-identity-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 991.98px), (pointer: coarse) and (max-width: 1366px) {
    /* Ventana completa: el contenido desplaza, los botones permanecen accesibles. */
    #newTicketModal .modal-dialog {
        width: 100%;
        max-width: none;
        margin: 0;
        height: 100vh;
        height: 100dvh;
    }
    #newTicketModal .modal-content { height: 100%; max-height: 100%; border: 0; }
    #newTicketModal .modal-content,
    #newTicketModal .modal-header { border-radius: 0 !important; }
    #newTicketModal .modal-header, #newTicketModal .modal-footer { flex-shrink: 0; }
    #newTicketModal .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
    #newTicketModal .modal-header { padding-top: max(16px, env(safe-area-inset-top)) !important; }
    #newTicketModal .modal-footer { padding-bottom: max(16px, env(safe-area-inset-bottom)) !important; }
    #newTicketModal .modal-title { font-size: clamp(1.125rem, 2.2vw, 1.4rem) !important; }
    #newTicketModal .form-control, #newTicketModal .form-select { font-size: clamp(1rem, 1.8vw, 1.25rem) !important; min-height: 48px; }
    #newTicketModal .form-label, .ticket-classification-hint { font-size: 1rem !important; }
    .ticket-classification-hint { align-items: flex-start !important; }
    .ticket-upload-area > div { font-size: .95rem !important; }
    #newTicketModal .modal-footer button { font-size: 1rem !important; min-height: 48px; }
}

@media (max-width: 575.98px) {
    #newTicketModal .modal-footer button { flex: 1 1 auto; }
    body .rule-form { grid-template-columns: minmax(0, 1fr); }
}

@media (max-height: 550px) and (max-width: 991.98px) {
    .public-form-page { align-items: flex-start; }
    .bur-panel { max-height: calc(100dvh - 20px); }
}

/* Formularios secundarios y subventanas conservan el mismo espacio táctil. */
@media (max-width: 991.98px), (pointer: coarse) and (max-width: 1366px) {
    .admin-layout .admin-form-wrap { padding: 20px 12px 96px; }
    .admin-layout .admin-wrapper, .admin-layout .card { max-width: none !important; }
    .admin-layout .admin-wrapper { width: 100%; }
    .admin-layout .admin-card, .admin-layout .card { overflow-wrap: anywhere; }
    .admin-layout .admin-table, .admin-layout .admin-table tbody { display: block; width: 100%; }
    .admin-layout .admin-table thead { display: none; }
    .admin-layout .admin-table tbody { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 12px; padding: 12px; }
    .admin-layout .admin-table tbody tr { display: block; border: 1px solid #dbe2ea; border-radius: 8px; padding: 14px; }
    .admin-layout .admin-table tbody td { display: block; width: 100%; padding: 8px 0; border: 0; text-align: left !important; font-size: 1rem !important; white-space: normal; overflow-wrap: anywhere; }
    .admin-layout .admin-table td::before { content: attr(data-label); display: block; color: #718096; font-size: .875rem; font-weight: 600; margin-bottom: 4px; }
    .admin-layout .admin-table td strong, .admin-layout .admin-table td span { font-size: 1rem !important; }
    .admin-layout .admin-table td button { min-height: 44px; font-size: 1rem !important; }
    .admin-layout form button[type="submit"], .admin-layout .btn-back-admin,
    .btn-submit-ticket, .btn-send, .side-btn, .art-btn {
        min-height: 48px;
        font-size: 1rem !important;
    }
    .form-label-custom, .admin-layout form label { font-size: .95rem !important; }
    .public-form-container .card-body { padding: 20px !important; }
    .public-form-container .btn-submit-ticket { font-size: 1rem !important; }
    .admin-layout .rule-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
    .admin-layout .kb-fila { grid-template-columns: minmax(0, 1fr); }
    .admin-content .cat-layout, .admin-content .kb-grid { grid-template-columns: minmax(0, 1fr); }
    button[onclick*="togglePass"], button[onclick*="toggleField"] { min-width: 44px; min-height: 44px; }
    input:has(+ button[onclick*="togglePass"]), input:has(+ button[onclick*="toggleField"]) { padding-right: 60px !important; }
    .art-wrap { width: 100%; max-width: none; padding: 20px 12px 96px; }
    .art-pasos { font-size: 1rem; overflow-wrap: anywhere; }
    .art-head h1, .art-migas { overflow-wrap: anywhere; }
    .ticket-detail-page input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]):not([type="file"]),
    .ticket-detail-page select, .ticket-detail-page textarea { font-size: 1rem !important; min-height: 44px; }
    .main-content input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]):not([type="file"]),
    .main-content select, .main-content textarea { font-size: 1rem !important; min-height: 44px; }
    .ticket-detail-page .enc-caras { grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; }
    .ticket-detail-page .enc-cara { min-height: 88px; justify-content: center; }
    .ticket-detail-page .enc-texto { font-size: .875rem; }
    .ticket-detail-page .enc-titulo { font-size: .95rem; }

    .modal .modal-dialog { width: 100%; max-width: none; height: 100vh; height: 100dvh; margin: 0; }
    .modal .modal-dialog > form { height: 100%; display: flex; flex-direction: column; min-height: 0; }
    .modal .modal-content { height: 100%; max-height: 100%; border-radius: 0 !important; }
    .modal .modal-content > form { flex: 1; min-height: 0; display: flex; flex-direction: column; }
    .modal .modal-header, .modal .modal-footer { flex-shrink: 0; padding: 16px !important; border-radius: 0 !important; gap: 8px; }
    .modal .modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px !important; }
    .modal .modal-title { font-size: 1.125rem !important; overflow-wrap: anywhere; }
    .modal .btn-close { width: 44px; height: 44px; padding: 0; margin: 0; flex-shrink: 0; }
    .modal button[type="submit"], .modal .modal-footer button { min-height: 48px; font-size: 1rem !important; }
    .modal label { font-size: 1rem !important; }
    .modal input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]):not([type="file"]),
    .modal select, .modal textarea { min-height: 48px; font-size: 1rem !important; }

    body .admin-modal { z-index: 1060; align-items: stretch; }
    body .admin-modal > .card, body .admin-modal > .card.category-modal-card {
        width: 100% !important; max-width: none !important; height: 100vh; height: 100dvh;
        max-height: 100dvh; border-radius: 0; overflow-y: auto;
    }
    body .admin-modal > .card.category-modal-card { overflow: hidden; }
    .category-modal-card .card-body { flex: 1; min-height: 0; overflow-y: auto; }
    .category-modal-head { flex-shrink: 0; }
    .category-modal-close { min-width: 44px; min-height: 44px; }
    .admin-modal button, .admin-modal .btn { min-height: 44px; font-size: 1rem; }
    .admin-modal .sub-edit-form { grid-template-columns: minmax(0, 1fr); }
    .admin-modal .tipo-chip { font-size: .95rem; max-width: 100%; overflow-wrap: anywhere; }
    .admin-modal details > summary { min-height: 44px; font-size: 1rem; }
    .admin-modal .add-sub-form, .admin-modal .add-type-form { flex-wrap: wrap; }
    .admin-modal .add-sub-form .form-control, .admin-modal .add-type-form .form-control { min-width: 100%; }

    #notifPanel { width: calc(100vw - 24px) !important; max-width: none; position: fixed !important; left: 12px !important; right: 12px !important; top: 60px !important; }
    #notifPanel > div:first-child { flex-wrap: wrap; gap: 8px; }
    #notifPanel button { min-height: 44px; font-size: 1rem !important; }
    #notifPanel .notif-panel-close { min-width: 44px; font-size: 1.5rem !important; margin-left: auto; }
    #notifList { max-height: calc(100dvh - 220px) !important; }
    #notifList [data-notif-url] > div > div > div:first-child { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; font-size: 1rem !important; }
    #notifList [data-notif-url] > div > div > div:nth-child(2) { font-size: .95rem !important; overflow-wrap: anywhere; }
}
