/**
 * Accessibility Fixes for MyMobileMenu
 * Addresses WCAG 2.1 AA compliance issues
 */

/* =============================================
 * COLOR CONTRAST FIXES
 * ============================================= */

/* Improved contrast with subtle color refinement */
body p,
.hero-subtitle,
.pricing-header p,
.period,
.footer-text,
.feature-card p,
.section-header p {
    color: #6c797a !important;
    text-shadow: 0 0 0 rgba(0, 0, 0, 0.01) !important; /* Subtle clarity enhancement */
}

/* Enhanced outline button with subtle styling */
.btn-outline {
    color: #0FA4AF !important; /* Light teal */
    border-color: #0FA4AF !important;
    box-shadow: inset 0 0 0 1px rgba(15, 164, 175, 0.1) !important;
    transition: all 0.2s ease !important;
}

.btn-outline:hover {
    background: linear-gradient(135deg, #0FA4AF, rgba(15, 164, 175, 0.9)) !important; /* Light teal */
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(15, 164, 175, 0.3) !important;
    transform: translateY(-1px) !important;
}

/* Enhanced secondary button styling */
.btn-secondary {
    background: linear-gradient(135deg, #024950, #003135) !important; /* Medium to dark teal */
    color: #ffffff !important;
    border-color: #024950 !important;
    box-shadow: 0 2px 8px rgba(2, 73, 80, 0.3) !important;
    transition: all 0.2s ease !important;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #003135, #001f22) !important; /* Dark teal to darker */
    border-color: #003135 !important;
    box-shadow: 0 4px 12px rgba(0, 49, 53, 0.4) !important;
    transform: translateY(-1px) !important;
}

/* Fix add-item-btn and add-column-btn contrast (3.3:1) -> #142122 */
.add-item-btn,
.add-column-btn {
    color: #142122 !important;
}

/* Enhanced modal close button */
.modal .close {
    color: rgba(248, 249, 250, 0.8) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.2s ease !important;
}

.modal .close:hover {
    color: rgba(248, 249, 250, 1) !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
    transform: scale(1.05) !important;
}

/* Enhanced auth divider styling */
.auth-divider span {
    color: rgba(245, 247, 250, 0.6) !important;
    font-weight: 500 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.9)) !important;
    backdrop-filter: blur(10px) !important;
    border-radius: 4px !important;
    padding: 0 20px !important;
}

/* Enhanced success button styling */
.btn-success {
    background: linear-gradient(135deg, #0FA4AF, #024950) !important; /* Light to medium teal */
    border-color: #0FA4AF !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(15, 164, 175, 0.3) !important;
    transition: all 0.2s ease !important;
}

.btn-success:hover {
    background: linear-gradient(135deg, #024950, #003135) !important; /* Medium to dark teal */
    border-color: #024950 !important;
    box-shadow: 0 4px 12px rgba(2, 73, 80, 0.4) !important;
    transform: translateY(-1px) !important;
}

/* Fix insufficient contrast for price elements using new teal palette */
.item-preview .price,
.mobile-item .price,
.price .amount {
    color: #024950 !important; /* Medium teal for good contrast */
    font-weight: 700;
}

/* Subtle footer text enhancement */
footer p,
.footer-text {
    color: #f8f9fa !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) !important;
    /* Remove harsh background styling for more natural look */
}

/* =============================================
 * FOCUS INDICATORS
 * ============================================= */

/* Elegant focus indicators - visible but refined */
button:focus,
input:focus,
select:focus,
textarea:focus,
a:focus {
    outline: 2px solid rgba(15, 164, 175, 0.4) !important; /* Light teal focus */
    outline-offset: 1px !important;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3), 0 2px 8px rgba(15, 164, 175, 0.15) !important;
    transition: all 0.2s ease !important;
}

/* High contrast focus for dark backgrounds - teal accent */
.dark-mode button:focus,
.dark-mode input:focus,
.dark-mode select:focus,
.dark-mode textarea:focus,
.dark-mode a:focus {
    outline: 2px solid rgba(175, 221, 229, 0.5) !important; /* Light mint for dark mode */
    outline-offset: 1px !important;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(175, 221, 229, 0.2) !important;
    transition: all 0.2s ease !important;
}

/* =============================================
 * TOUCH TARGET IMPROVEMENTS
 * ============================================= */

/* Ensure minimum 44x44px touch targets for mobile */
@media (max-width: 768px) {
    button,
    input,
    select,
    .btn,
    .dropdown-option,
    .template-option,
    .section-toggle,
    .menu-item-controls button {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 8px 12px !important;
    }
    
    /* Icon-only buttons need adequate spacing */
    .sidebar-close,
    .remove-thumbnail-btn,
    .close,
    .tip-close {
        width: 44px !important;
        height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Navigation links in mobile menus */
    .nav-links a {
        padding: 12px 16px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
    }
}

/* =============================================
 * ARIA LABEL IMPROVEMENTS
 * ============================================= */

/* Hide decorative icons from screen readers */
.fas:not([role]),
.fab:not([role]) {
    aria-hidden: true;
}

/* Subtle indicator for unlabeled form elements */
input:not([aria-label]):not([aria-labelledby]):not([id]) {
    border-left: 2px solid rgba(255, 193, 7, 0.3) !important;
    background: linear-gradient(90deg, rgba(255, 193, 7, 0.02) 0%, transparent 5%) !important;
}

/* Hidden warning message for screen readers only */
input:not([aria-label]):not([aria-labelledby]):not([id])::before {
    content: "Warning: This field may need an accessibility label" !important;
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* =============================================
 * MODAL AND DIALOG ENHANCEMENTS
 * ============================================= */

/* Ensure modals are properly identified */
.modal {
    role: dialog;
}

.modal[style*="display: flex"],
.modal[style*="display: block"] {
    z-index: 10000 !important;
}

/* Backdrop for focus containment */
.modal::backdrop {
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(4px) !important;
}

/* Subtle modal content enhancement */
.modal-content {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* =============================================
 * NAVIGATION AND SKIP LINKS
 * ============================================= */

/* Skip to content link - visible on focus */
.skip-link {
    position: absolute !important;
    top: -40px !important;
    left: 6px !important;
    background: #000000 !important;
    color: #ffffff !important;
    padding: 8px 16px !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    border-radius: 0 0 4px 4px !important;
    z-index: 10001 !important;
    transition: top 0.2s ease !important;
}

.skip-link:focus {
    top: 0 !important;
    outline: 3px solid #FFD700 !important;
}

/* =============================================
 * ERROR STATES AND VALIDATION
 * ============================================= */

/* Refined error state - clear but not harsh */
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border: 1px solid rgba(220, 53, 69, 0.4) !important;
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.02), rgba(220, 53, 69, 0.01)) !important;
    box-shadow: 0 1px 4px rgba(220, 53, 69, 0.1), inset 0 1px 0 rgba(220, 53, 69, 0.05) !important;
    position: relative;
}

/* Success state for validated fields */
input[aria-invalid="false"],
select[aria-invalid="false"],
textarea[aria-invalid="false"] {
    border: 1px solid rgba(40, 167, 69, 0.3) !important;
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.01), rgba(40, 167, 69, 0.005)) !important;
    box-shadow: 0 1px 3px rgba(40, 167, 69, 0.08) !important;
}

/* Subtle validation indicators */
.form-group.valid::after {
    content: "✓" !important;
    position: absolute !important;
    right: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: rgba(40, 167, 69, 0.7) !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    pointer-events: none !important;
}

.form-group.error::after {
    content: "!" !important;
    position: absolute !important;
    right: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: rgba(220, 53, 69, 0.7) !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    width: 16px !important;
    height: 16px !important;
    background: rgba(220, 53, 69, 0.1) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    pointer-events: none !important;
}

/* Form group positioning for validation indicators */
.form-group {
    position: relative !important;
}

/* Elegant error messages */
.error-message,
[role="alert"] {
    color: rgba(176, 45, 57, 0.9) !important;
    font-weight: 500 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    margin-top: 6px !important;
    font-size: 13px !important;
    padding: 6px 12px !important;
    background: rgba(220, 53, 69, 0.08) !important;
    border-radius: 6px !important;
    border-left: 3px solid rgba(220, 53, 69, 0.3) !important;
}

.error-message::before,
[role="alert"]::before {
    content: "!" !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 16px !important;
    height: 16px !important;
    background: rgba(220, 53, 69, 0.15) !important;
    border-radius: 50% !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    color: rgba(176, 45, 57, 0.8) !important;
}

/* =============================================
 * TABLE AND DATA ACCESSIBILITY
 * ============================================= */

/* Menu item tables */
table {
    border-collapse: collapse !important;
    width: 100% !important;
}

th, td {
    border: 1px solid #dee2e6 !important;
    padding: 12px !important;
    text-align: left !important;
}

th {
    background: #f8f9fa !important;
    font-weight: 600 !important;
    color: #2c3e50 !important;
}

/* Zebra striping for better readability */
tbody tr:nth-child(even) {
    background: rgba(248, 249, 250, 0.5) !important;
}

/* =============================================
 * HIGH CONTRAST MODE SUPPORT
 * ============================================= */

@media (prefers-contrast: high) {
    * {
        filter: contrast(150%) !important;
    }
    
    .btn {
        border: 2px solid currentColor !important;
    }
    
    .dropdown,
    .modal-content {
        border: 3px solid currentColor !important;
    }
}

/* Forced colors mode support */
@media (forced-colors: active) {
    .btn {
        border: 1px solid ButtonText !important;
        background: ButtonFace !important;
        color: ButtonText !important;
    }
    
    .btn:hover {
        background: Highlight !important;
        color: HighlightText !important;
    }
    
    .modal-content {
        border: 1px solid CanvasText !important;
        background: Canvas !important;
        color: CanvasText !important;
    }
    
    input, select, textarea {
        background: Field !important;
        color: FieldText !important;
        border: 1px solid FieldText !important;
    }
}

/* =============================================
 * REDUCED MOTION SUPPORT
 * ============================================= */

@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;
    }
    
    /* Keep essential animations but make them much faster */
    .fade-in,
    .slide-in,
    .modal {
        animation-duration: 0.1s !important;
    }
}

/* =============================================
 * SCREEN READER OPTIMIZATIONS
 * ============================================= */

/* Screen reader only text */
.sr-only {
    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;
}

/* Show on focus for keyboard users */
.sr-only:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 0.5rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    background: #000000 !important;
    color: #ffffff !important;
}

/* Live region for announcements */
[aria-live] {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* Exception: Menu name should be visible */
.current-menu-info[aria-live] {
    position: static !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
}

/* =============================================
 * KEYBOARD NAVIGATION ENHANCEMENTS
 * ============================================= */

/* Subtle focus-within indication */
*:focus-within {
    box-shadow: inset 0 0 0 1px rgba(52, 152, 219, 0.1) !important;
    border-radius: 2px !important;
    transition: box-shadow 0.2s ease !important;
}

/* Elegant tab sequence tooltips */
[tabindex]:focus::after {
    content: attr(aria-label) !important;
    position: absolute !important;
    background: rgba(44, 62, 80, 0.95) !important;
    color: #ffffff !important;
    padding: 6px 10px !important;
    font-size: 11px !important;
    font-weight: 500 !important;
    border-radius: 4px !important;
    white-space: nowrap !important;
    z-index: 10000 !important;
    top: calc(100% + 4px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    opacity: 0.9 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    backdrop-filter: blur(4px) !important;
}

/* =============================================
 * FORM ACCESSIBILITY ENHANCEMENTS
 * ============================================= */

/* Enhanced form styling for better accessibility - FIXED */
.auth-form .form-group input:hover {
    border-color: rgba(15, 164, 175, 0.2) !important; /* Light teal */
    box-shadow: 0 2px 6px rgba(0, 49, 53, 0.08) !important;
    transition: all 0.2s ease !important;
    background: rgba(255, 255, 255, 0.95) !important;
    color: #003135 !important; /* Dark teal text */
}

.auth-form .form-group input:focus {
    border-color: rgba(15, 164, 175, 0.4) !important; /* Light teal */
    background: rgba(255, 255, 255, 0.98) !important;
    box-shadow: 0 2px 12px rgba(15, 164, 175, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
    transform: translateY(-1px) !important;
    transition: all 0.2s ease !important;
    color: #003135 !important; /* Dark teal text */
}

/* Enhanced select styling - FIXED */
.enhanced-form select:hover {
    border-color: rgba(52, 152, 219, 0.2) !important;
    box-shadow: 0 2px 6px rgba(10, 26, 47, 0.08) !important;
    transition: all 0.2s ease !important;
    background: rgba(255, 255, 255, 0.95) !important;
    color: #2c3e50 !important;
}

/* Better checkbox styling */
.checkbox-label input[type="checkbox"] {
    appearance: none !important;
    -webkit-appearance: none !important;
    width: 18px !important;
    height: 18px !important;
    border: 2px solid rgba(245, 247, 250, 0.3) !important;
    border-radius: 4px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    cursor: pointer !important;
    position: relative !important;
    transition: all 0.2s ease !important;
}

.checkbox-label input[type="checkbox"]:checked {
    background: rgba(15, 164, 175, 0.8) !important; /* Light teal */
    border-color: rgba(15, 164, 175, 0.8) !important;
    box-shadow: 0 2px 4px rgba(15, 164, 175, 0.2) !important;
}

.checkbox-label input[type="checkbox"]:checked::after {
    content: "✓" !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    color: white !important;
    font-size: 12px !important;
    font-weight: 600 !important;
}

.checkbox-label input[type="checkbox"]:focus {
    outline: 2px solid rgba(15, 164, 175, 0.4) !important; /* Light teal */
    outline-offset: 2px !important;
}

/* =============================================
 * MOBILE ACCESSIBILITY IMPROVEMENTS
 * ============================================= */

@media (max-width: 768px) {
    /* Larger text for better readability */
    body {
        font-size: 16px !important;
        line-height: 1.6 !important;
    }
    
    /* Increased spacing between interactive elements */
    .btn + .btn,
    .dropdown-option + .dropdown-option {
        margin-top: 8px !important;
    }
    
    /* Better form field spacing on mobile */
    .form-group {
        margin-bottom: 20px !important;
    }
    
    .form-row {
        gap: 12px !important;
    }
    
    /* Better visual hierarchy */
    h1 { font-size: 2rem !important; }
    h2 { font-size: 1.75rem !important; }
    h3 { font-size: 1.5rem !important; }
    
    /* Enhanced mobile form styling */
    .btn,
    input,
    select,
    textarea {
        border: 1px solid rgba(245, 247, 250, 0.4) !important;
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    /* Mobile-specific focus styles */
    input:focus,
    select:focus,
    textarea:focus {
        border: 2px solid rgba(15, 164, 175, 0.5) !important; /* Light teal */
        box-shadow: 0 4px 12px rgba(15, 164, 175, 0.2) !important;
    }
}

/* =============================================
 * PRINT ACCESSIBILITY
 * ============================================= */

@media print {
    /* Ensure good contrast for printed materials */
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    /* Show URLs after links */
    a[href]:after {
        content: " (" attr(href) ")" !important;
        font-size: 0.8em !important;
        color: #666 !important;
    }
    
    /* Hide non-essential elements */
    .modal,
    .dropdown,
    .tooltip,
    [aria-hidden="true"] {
        display: none !important;
    }
}

/* =============================================
 * CUSTOM PROPERTIES FOR ACCESSIBILITY
 * ============================================= */

:root {
    /* Refined accessibility color palette - Teal & Terracotta */
    --focus-color: rgba(15, 164, 175, 0.4); /* Light teal */
    --focus-color-dark: rgba(175, 221, 229, 0.5); /* Light mint for dark mode */
    --focus-width: 2px;
    --error-color: rgba(150, 71, 52, 0.4); /* Rust/terracotta */
    --error-color-bg: rgba(150, 71, 52, 0.02);
    --success-color: rgba(15, 164, 175, 0.6); /* Light teal for success */
    --warning-color: rgba(150, 71, 52, 0.3); /* Rust/terracotta for warning */
    --info-color: rgba(15, 164, 175, 0.5); /* Light teal for info */
    
    --text-color-accessible: #2c3e50;
    --text-color-muted-accessible: #6c797a;
    --bg-color-accessible: rgba(255, 255, 255, 0.95);
    
    --min-touch-target: 44px;
    --accessible-line-height: 1.6;
    
    /* Subtle visual enhancement */
    --gentle-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    --soft-border: rgba(0, 0, 0, 0.06);
}

/* Dark mode accessible colors */
.dark-mode {
    --text-color-accessible: #f8f9fa;
    --text-color-muted-accessible: #adb5bd;
    --bg-color-accessible: rgba(26, 26, 26, 0.95);
    --focus-color: var(--focus-color-dark);
    --soft-border: rgba(255, 255, 255, 0.08);
}

/* =============================================
 * UTILITY CLASSES
 * ============================================= */

.visually-hidden {
    @extend .sr-only;
}

.focus-visible {
    outline: var(--focus-width) solid var(--focus-color) !important;
    outline-offset: 2px !important;
}

.accessible-contrast {
    color: var(--text-color-accessible) !important;
}

.accessible-muted {
    color: var(--text-color-muted-accessible) !important;
}

.min-touch-target {
    min-width: var(--min-touch-target) !important;
    min-height: var(--min-touch-target) !important;
}