/**
 * Accessibility Styles
 *
 * Enhanced accessibility styles including visible focus states,
 * screen reader utilities, and minimum touch targets.
 * Compliant with WCAG 2.1 Level AA standards.
 *
 * @package ROI_Theme
 * @since 1.0.0
 */

/* ==========================================================================
   Focus Styles - Highly Visible
   ========================================================================== */

/**
 * Enhanced focus styles for better keyboard navigation
 * Using double outline for better visibility across different backgrounds
 */
*:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* Remove default browser focus outline (we're replacing it with better one) */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Modern browsers that support :focus-visible */
*:focus-visible {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}

/* Links */
a:focus,
a:focus-visible {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
    text-decoration: underline;
}

/* Buttons */
button:focus,
button:focus-visible,
.button:focus,
.button:focus-visible,
input[type="submit"]:focus,
input[type="submit"]:focus-visible,
input[type="button"]:focus,
input[type="button"]:focus-visible,
input[type="reset"]:focus,
input[type="reset"]:focus-visible {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.2);
}

/* Form inputs */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
input[type="range"]:focus,
input[type="date"]:focus,
input[type="month"]:focus,
input[type="week"]:focus,
input[type="time"]:focus,
input[type="datetime"]:focus,
input[type="datetime-local"]:focus,
input[type="color"]:focus,
textarea:focus,
select:focus {
    outline: 3px solid #0066cc;
    outline-offset: 0;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}

/* Checkboxes and radio buttons */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}

/* Navigation menu items */
.main-navigation a:focus,
.primary-menu a:focus,
nav a:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    background-color: rgba(0, 102, 204, 0.1);
}

/* Menu toggle button */
.menu-toggle:focus,
.mobile-menu-toggle:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.2);
}

/* ==========================================================================
   Screen Reader Text Utilities
   ========================================================================== */

/**
 * Hide elements visually but keep them accessible to screen readers
 */
.screen-reader-text,
.sr-only,
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    clip-path: inset(50%) !important;
}

/**
 * Make screen reader text visible on focus
 * Important for skip links and keyboard navigation
 */
.screen-reader-text:focus,
.sr-only:focus,
.visually-hidden:focus {
    position: fixed !important;
    top: 5px !important;
    left: 5px !important;
    width: auto !important;
    height: auto !important;
    padding: 15px 23px 14px !important;
    margin: 0 !important;
    background-color: #000 !important;
    color: #fff !important;
    font-size: 14px !important;
    font-weight: bold !important;
    line-height: normal !important;
    text-decoration: none !important;
    z-index: 100000 !important;
    clip: auto !important;
    clip-path: none !important;
    outline: 3px solid #0066cc !important;
    outline-offset: 2px !important;
    border-radius: 3px !important;
}

/**
 * Skip to content link
 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background-color: #000;
    color: #fff;
    padding: 10px 20px;
    text-decoration: none;
    z-index: 100000;
    font-weight: bold;
    border-radius: 0 0 3px 0;
    transition: top 0.2s ease-in-out;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* ==========================================================================
   Touch Targets - Minimum 44x44px
   ========================================================================== */

/**
 * Ensure all interactive elements meet WCAG 2.1 Level AAA
 * minimum touch target size of 44x44 pixels
 */

/* Buttons */
button,
.button,
input[type="submit"],
input[type="button"],
input[type="reset"],
.wp-block-button__link {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Links in navigation */
.main-navigation a,
.primary-menu a,
.footer-navigation a,
nav a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 10px 15px;
}

/* Menu toggle buttons */
.menu-toggle,
.mobile-menu-toggle {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
}

/* Pagination links */
.page-numbers,
.pagination a,
.posts-navigation a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 15px;
}

/* Form inputs */
input[type="text"],
input[type="email"],
input[type="url"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="tel"],
textarea,
select {
    min-height: 44px;
    padding: 10px 15px;
}

/* Checkboxes and radio buttons */
input[type="checkbox"],
input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
    margin: 10px; /* Add margin to reach 44px effective touch target */
}

/* Links with small text need larger padding */
.tags-list a,
.category-badge {
    min-height: 44px;
    padding: 12px 16px;
    display: inline-flex;
    align-items: center;
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

/**
 * Ensure elements remain visible in Windows High Contrast Mode
 */
@media (prefers-contrast: high) {
    button,
    a,
    .button {
        border: 2px solid currentColor;
    }

    *:focus,
    *:focus-visible {
        outline: 3px solid;
        outline-offset: 3px;
    }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

/**
 * Respect user's preference for reduced motion
 * Remove animations for users who prefer reduced motion
 */
@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;
    }
}

/* ==========================================================================
   Color Contrast Enhancements
   ========================================================================== */

/**
 * Ensure text has sufficient color contrast
 * WCAG AA requires 4.5:1 for normal text, 3:1 for large text
 */

/* Enhanced link contrast */
a {
    color: #0056b3;
    text-decoration: underline;
}

a:hover {
    color: #003d82;
    text-decoration: underline;
}

/* Error messages - high contrast red */
.error,
.error-message,
.form-error {
    color: #c81e1e;
    background-color: #fef0f0;
    border: 2px solid #c81e1e;
    padding: 10px 15px;
    border-radius: 4px;
}

/* Success messages - high contrast green */
.success,
.success-message,
.form-success {
    color: #1e7e34;
    background-color: #e8f5e9;
    border: 2px solid #1e7e34;
    padding: 10px 15px;
    border-radius: 4px;
}

/* Warning messages - high contrast yellow/orange */
.warning,
.warning-message,
.form-warning {
    color: #856404;
    background-color: #fff3cd;
    border: 2px solid #856404;
    padding: 10px 15px;
    border-radius: 4px;
}

/* ==========================================================================
   ARIA Live Regions
   ========================================================================== */

/**
 * Ensure live regions are properly announced
 */
[aria-live] {
    position: relative;
}

[aria-live="assertive"] {
    font-weight: bold;
}

/* ==========================================================================
   Focus Management for Modals and Dialogs
   ========================================================================== */

/**
 * Trap focus within modals
 */
.modal[aria-modal="true"],
.dialog[aria-modal="true"] {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
}

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 999998;
}

/* ==========================================================================
   Text Spacing and Readability
   ========================================================================== */

/**
 * Support for user text spacing preferences
 * WCAG 2.1 Level AA Success Criterion 1.4.12
 */
p,
li,
dd,
dt {
    line-height: 1.6;
    letter-spacing: 0.02em;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    letter-spacing: 0.01em;
}

/* Allow text to be resized up to 200% without loss of content or functionality */
html {
    font-size: 100%;
}

/* ==========================================================================
   Table Accessibility
   ========================================================================== */

/**
 * Ensure tables are accessible
 */
table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: left;
    font-weight: bold;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 12px;
}

td {
    border: 1px solid #dee2e6;
    padding: 12px;
}

/* Add scope visually for screen readers */
caption {
    font-weight: bold;
    text-align: left;
    padding: 10px 0;
    caption-side: top;
}

/* ==========================================================================
   Print Accessibility
   ========================================================================== */

@media print {
    /* Ensure focus styles don't print */
    *:focus {
        outline: none !important;
        box-shadow: none !important;
    }

    /* Show link URLs in print */
    a[href]:after {
        content: " (" attr(href) ")";
    }

    /* Don't show URLs for fragment links or javascript */
    a[href^="#"]:after,
    a[href^="javascript:"]:after {
        content: "";
    }
}

/* ==========================================================================
   Navegación por Teclado - Menús Desplegables
   ========================================================================== */

/**
 * Estilos para menús desplegables (dropdowns) con navegación por teclado
 * Asegura que los submenús sean accesibles y visibles durante la navegación
 */

/* Submenú general */
.navbar-nav .dropdown-menu,
.primary-menu .sub-menu {
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

/* Mostrar submenú cuando el padre tiene hover o focus */
.navbar-nav .dropdown:hover > .dropdown-menu,
.navbar-nav .dropdown:focus-within > .dropdown-menu,
.primary-menu .menu-item:hover > .sub-menu,
.primary-menu .menu-item:focus-within > .sub-menu {
    display: block;
    opacity: 1;
}

/* Estilo del item de menú con submenú cuando recibe focus */
.navbar-nav .dropdown > a:focus,
.primary-menu .menu-item-has-children > a:focus {
    background-color: rgba(0, 102, 204, 0.1);
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* Items de submenú con focus */
.navbar-nav .dropdown-menu a:focus,
.primary-menu .sub-menu a:focus {
    background-color: rgba(0, 102, 204, 0.15);
    outline: 3px solid #0066cc;
    outline-offset: -2px;
    color: #003d82;
}

/* ==========================================================================
   ARIA Estados Visuales
   ========================================================================== */

/**
 * Estilos visuales para estados ARIA
 * Proporciona feedback visual para estados interactivos
 */

/* Elementos expandidos/colapsados */
[aria-expanded="true"] {
    /* Indicador visual de estado expandido */
}

[aria-expanded="false"] {
    /* Indicador visual de estado colapsado */
}

/* Elementos ocultos pero presentes en el DOM */
[aria-hidden="true"] {
    display: none !important;
}

/* Elementos deshabilitados */
[aria-disabled="true"],
[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Elementos seleccionados en menús */
[aria-current="page"],
.current-menu-item > a,
.current_page_item > a {
    font-weight: bold;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

/* ==========================================================================
   Indicadores de Estado de Carga (Loading)
   ========================================================================== */

/**
 * Estilos para indicadores de carga accesibles
 */
.loading,
[aria-busy="true"] {
    position: relative;
    pointer-events: none;
}

.loading::after,
[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0066cc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Respetar preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    .loading::after,
    [aria-busy="true"]::after {
        animation: none;
        border-top-color: transparent;
    }
}

/* ==========================================================================
   Mejoras para Formularios Accesibles
   ========================================================================== */

/**
 * Mejoras adicionales para formularios accesibles
 */

/* Labels obligatorios con indicador visual */
label.required::after,
label[required]::after {
    content: " *";
    color: #c81e1e;
    font-weight: bold;
}

/* Focus en inputs con error */
input:invalid:focus,
textarea:invalid:focus,
select:invalid:focus {
    border-color: #c81e1e;
    outline-color: #c81e1e;
    box-shadow: 0 0 0 3px rgba(200, 30, 30, 0.2);
}

/* Estados de validación descriptivos */
input:valid:not(:placeholder-shown),
textarea:valid:not(:placeholder-shown),
select:valid {
    border-color: #1e7e34;
}

/* Mensajes de ayuda descriptivos */
.form-help,
.field-description,
[role="tooltip"] {
    font-size: 14px;
    color: #666;
    margin-top: 4px;
    display: block;
}

/* ==========================================================================
   TOC (Table of Contents) Accesibilidad
   ========================================================================== */

/**
 * Mejoras de accesibilidad para Tabla de Contenidos
 */

/* Links del TOC con focus visible */
.roi-toc a:focus,
.toc-link:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    background-color: rgba(0, 102, 204, 0.1);
    text-decoration: underline;
}

/* Item activo del TOC */
.roi-toc a.active,
.toc-link.active {
    font-weight: bold;
    border-left: 4px solid #0066cc;
    padding-left: 12px;
}

/* Botón toggle del TOC con ARIA */
.roi-toc-toggle[aria-expanded="true"]::before {
    content: "▼ ";
}

.roi-toc-toggle[aria-expanded="false"]::before {
    content: "▶ ";
}

/* ==========================================================================
   Enlaces con Iconos - Accesibilidad
   ========================================================================== */

/**
 * Asegurar que los enlaces con solo iconos tengan texto descriptivo
 */

/* Enlaces con iconos deben tener aria-label */
a[aria-label] {
    position: relative;
}

/* Iconos decorativos en enlaces */
a .icon[aria-hidden="true"],
a .dashicons[aria-hidden="true"],
a .fa[aria-hidden="true"] {
    pointer-events: none;
}

/* Enlaces sociales con solo iconos */
.social-links a:focus,
.social-menu a:focus {
    outline: 3px solid #0066cc;
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(0, 102, 204, 0.2);
}

/* ==========================================================================
   Paginación Accesible
   ========================================================================== */

/**
 * Mejoras para navegación de paginación
 */

.pagination,
.nav-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 20px 0;
}

.pagination a,
.nav-links a,
.page-numbers {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 15px;
    border: 2px solid #dee2e6;
    border-radius: 4px;
    text-decoration: none;
    color: #0056b3;
    transition: all 0.2s ease;
}

.pagination a:hover,
.nav-links a:hover,
.page-numbers:hover {
    background-color: #f8f9fa;
    border-color: #0066cc;
}

.pagination a:focus,
.nav-links a:focus,
.page-numbers:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.2);
    border-color: #0066cc;
    background-color: rgba(0, 102, 204, 0.1);
}

/* Página actual */
.pagination .current,
.page-numbers.current,
.nav-links .current {
    background-color: #0066cc;
    color: #fff;
    border-color: #0066cc;
    font-weight: bold;
}

/* ==========================================================================
   Breadcrumbs Accesibles
   ========================================================================== */

/**
 * Estilos para breadcrumbs (migas de pan) accesibles
 */

.breadcrumbs,
[aria-label="Breadcrumb"] {
    padding: 10px 0;
    margin-bottom: 20px;
}

.breadcrumbs a:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    text-decoration: underline;
}

.breadcrumbs [aria-current="page"] {
    color: #666;
    font-weight: normal;
}

/* ==========================================================================
   Contraste de Color Mejorado (WCAG AA)
   ========================================================================== */

/**
 * Asegurar que todos los colores cumplan con ratio 4.5:1 para texto normal
 * y 3:1 para texto grande (18pt o 14pt bold)
 */

/* Texto en fondos claros */
body {
    color: #212529;
    background-color: #ffffff;
}

/* Enlaces con contraste suficiente */
a {
    color: #0056b3; /* Ratio 4.89:1 en fondo blanco */
}

a:hover {
    color: #003d82; /* Ratio 7.33:1 en fondo blanco */
}

/* Texto en gris debe tener suficiente contraste */
.text-muted,
.meta-info,
.entry-meta {
    color: #495057; /* Ratio 7.0:1 en fondo blanco */
}

/* Placeholders en inputs */
::placeholder {
    color: #6c757d; /* Ratio 4.54:1 en fondo blanco */
    opacity: 1;
}

/* Botones secundarios con borde */
.btn-outline-primary,
.button-outline {
    color: #0056b3;
    border-color: #0056b3;
}

.btn-outline-primary:hover,
.button-outline:hover {
    background-color: #0056b3;
    color: #ffffff;
}

/* ==========================================================================
   Modo de Alto Contraste Mejorado
   ========================================================================== */

/**
 * Mejoras adicionales para modo de alto contraste
 */
@media (prefers-contrast: high) {
    /* Aumentar contraste de bordes */
    button,
    input,
    textarea,
    select {
        border-width: 2px;
        border-style: solid;
    }

    /* Eliminar efectos de sombra que reducen contraste */
    *,
    *::before,
    *::after {
        text-shadow: none !important;
        box-shadow: none !important;
    }

    /* Focus aún más visible */
    *:focus,
    *:focus-visible {
        outline-width: 4px;
        outline-offset: 4px;
    }

    /* Fondo de navegación más contrastante */
    .navbar,
    .site-header {
        border-bottom: 3px solid currentColor;
    }
}

/* ==========================================================================
   Zoom de Texto y Escalado
   ========================================================================== */

/**
 * Asegurar que el texto se pueda escalar hasta 200% sin pérdida de contenido
 * WCAG 2.1 Success Criterion 1.4.4
 */

/* Usar unidades relativas */
html {
    font-size: 100%; /* Base 16px */
}

body {
    font-size: 1rem; /* 16px */
    line-height: 1.6;
}

/* Evitar anchos fijos en contenedores de texto */
.entry-content,
.content-area {
    max-width: 100%;
}

/* Permitir que las imágenes se redimensionen */
img {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   Animaciones Respetuosas
   ========================================================================== */

/**
 * Deshabilitar animaciones automáticas que puedan causar mareos
 * WCAG 2.1 Success Criterion 2.3.3
 */

/* No usar animaciones infinitas que parpadeen */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Limitar duración de animaciones */
.animate {
    animation-duration: 0.3s;
    animation-timing-function: ease-in-out;
}

/* ==========================================================================
   Fin del archivo
   ========================================================================== */
