/**
 * Capa compartida (admin + sitio público): móvil, accesibilidad y estados de botones.
 * Se carga al FINAL del <head> para poder ajustar sin reescribir cada vista.
 */

/* ═══ 1. ACCESIBILIDAD ══════════════════════════════════════════════ */

/* Enlace «Saltar al contenido» */
.skip-link {
    position: fixed; top: 8px; left: 8px; z-index: 100000;
    padding: 10px 16px; border-radius: 6px;
    background: #111827; color: #fff !important; font-weight: 600; text-decoration: none;
    transform: translateY(-200%);
    transition: transform .15s ease;
}
.skip-link:focus { transform: translateY(0); outline: 3px solid #fff; outline-offset: 2px; }
#main-content:focus { outline: none; }

/* Anillo de foco visible y consistente (solo con teclado). */
html body :is(a, button, input, select, textarea, summary, [tabindex], [role="button"]):focus-visible {
    outline: 3px solid #1d4ed8 !important;
    outline-offset: 2px !important;
}
html[data-theme="dark"] body :is(a, button, input, select, textarea, summary, [tabindex], [role="button"]):focus-visible {
    outline-color: #93b4ff !important;
}
/* Sobre fondos oscuros fijos (barra superior, sidebar, navbar pública) */
html body :is(.erp-shellbar, .sidenav, .site-navbar, .site-footer) :is(a, button, input, [tabindex]):focus-visible {
    outline-color: #ffffff !important;
}
/* Los inputs ya cambian de borde al enfocar: no los dejamos sin indicador */
html body :is(.form-control, .form-select):focus { outline: 2px solid transparent; }

/* Lectores de pantalla: región para anuncios dinámicos */
.sr-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ═══ 2. ESTADOS DE INTERACCIÓN DE BOTONES ══════════════════════════
   default → hover → focus-visible → active (presionado) → disabled → loading */

.btn, button.erp-icon-btn, .erp-shellbar__btn {
    transition: background-color .15s ease, border-color .15s ease, color .15s ease,
                opacity .15s ease, filter .15s ease, transform .08s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
/* Hover: oscurece un poco cualquier variante que no defina el suyo */
.btn:not(:disabled):not(.disabled):not(.is-loading):hover { filter: brightness(.94); }
html[data-theme="dark"] .btn:not(:disabled):not(.disabled):not(.is-loading):hover { filter: brightness(1.12); }
/* Active: se «hunde» */
.btn:not(:disabled):not(.disabled):not(.is-loading):active,
button.erp-icon-btn:not(:disabled):active,
.erp-shellbar__btn:active { transform: translateY(1px) scale(.98); filter: brightness(.88); }
/* Disabled */
.btn:disabled, .btn.disabled, fieldset:disabled .btn, [aria-disabled="true"].btn {
    cursor: not-allowed !important; opacity: .55; filter: none !important; transform: none !important;
}
/* Loading: lo pone a11y-ui.js al enviar un formulario (o a mano con la clase .is-loading) */
.btn.is-loading {
    position: relative; pointer-events: none; cursor: progress;
    color: transparent !important; overflow: hidden;
}
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,.45) 50%, transparent 80%);
    transform: translateX(-100%);
    animation: sk-shimmer 1.1s ease-in-out infinite;
}

/* Enlaces: subrayado al pasar/enfocar solo en texto corrido */
p a:not(.btn), li > a:not(.btn):not(.nav-link):not(.dropdown-item):not(.page-link) { text-underline-offset: 2px; }

/* ═══ 3. MÓVIL ══════════════════════════════════════════════════════ */

img, video, iframe, canvas, svg { max-width: 100%; }
img, video { height: auto; }
.table-responsive { -webkit-overflow-scrolling: touch; }
.table-responsive > .table { margin-bottom: 0; }
/* Tablas dentro de contenedores que ya envolvió a11y-ui.js */
.table-scroll-auto { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dt-container { max-width: 100%; }

/* Táctil: objetivos de al menos 44px (WCAG 2.5.5) */
@media (pointer: coarse) {
    :root { --control-h: 40px; --icon-btn: 40px; }
    html body .btn:not(.btn-close),
    html body .form-control, html body .form-select,
    html body .dropdown-item, html body .page-link,
    html body .nav-tabs .nav-link, html body .erp-tab,
    html body .erp-icon-btn, html body .erp-shellbar__btn {
        min-height: 44px;
    }
    html body .erp-icon-btn, html body .erp-shellbar__btn { min-width: 44px; }
    html body .btn-sm, html body .btn-group-sm > .btn { min-height: 38px; height: auto; }
    html body table .btn, html body table .erp-icon-btn { min-height: 38px; min-width: 38px; }
    html body input[type="checkbox"], html body input[type="radio"] { width: 1.25rem; height: 1.25rem; }
}

@media (max-width: 767.98px) {
    /* iOS hace zoom al enfocar campos < 16px */
    html body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    html body select, html body textarea { font-size: 16px !important; }

    html body .container, html body .container-fluid { padding-left: 12px; padding-right: 12px; }

    /* Modales a casi todo el ancho y desplazables */
    .modal-dialog:not(.modal-fullscreen) { margin: .5rem; max-width: calc(100vw - 1rem); }
    .modal-body { max-height: calc(100dvh - 9rem); overflow-y: auto; }
    .modal-footer { flex-wrap: wrap; gap: 8px; }
    .modal-footer > * { flex: 1 1 auto; margin: 0; }

    .dropdown-menu { max-width: calc(100vw - 1rem); }

    /* Cabeceras y barras de acciones se apilan */
    html body .erp-page-header, html body .erp-pagehead,
    html body .erp-table-panel__head, html body .erp-section__head,
    html body .erp-bulkbar { flex-wrap: wrap; gap: 8px; }
    html body .erp-pagehead__actions, html body .erp-table-panel__actions,
    html body .erp-actions { flex-wrap: wrap; width: 100%; }
    html body .erp-pagehead__actions > .btn, html body .erp-table-panel__actions > .btn { flex: 1 1 auto; }
    html body .erp-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    html body .erp-filter__body { grid-template-columns: minmax(0, 1fr) !important; }

    /* DataTables */
    .dt-container .dt-layout-row { flex-direction: column; align-items: stretch !important; gap: 8px; }
    .dt-container .dt-search, .dt-container .dt-length { text-align: left; }
    .dt-container .dt-search input { width: 100% !important; margin-left: 0 !important; }
    .dt-container .dt-paging { flex-wrap: wrap; justify-content: center; }
    .dt-container .dt-layout-cell { width: 100%; }

    /* Texto largo no desborda */
    h1, h2, h3, h4, h5, h6, p, td, th, .card-title { overflow-wrap: anywhere; }
    .erp-shellbar__system { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Mantiene la página sin scroll horizontal accidental */
html, body { max-width: 100%; overflow-x: clip; }

/* Cuadrículas con gutters grandes (g-4/g-5) se salen del ancho en móvil: se reducen */
@media (max-width: 767.98px) {
    .row.g-5, .row.gx-5 { --bs-gutter-x: 1.5rem; }
    .row.g-5, .row.gy-5 { --bs-gutter-y: 1.5rem; }
    .wa-float__label { display: none; }
}
