/**
 * Fresh Bake Theme - Accessibility Enhancements
 * 
 * Improves accessibility for users with disabilities, screen readers, and keyboard navigation.
 * 
 * @package Fresh_Bake
 * @version 1.0.0
 */

/* ========================================
   SKIP LINKS
   ======================================== */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999999;
    padding: 8px 16px;
    background: #000;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 4px;
}

.skip-link:focus {
    left: 6px;
    top: 7px;
    outline: 2px solid #f97316;
    outline-offset: 2px;
}

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

/* Enhanced focus styles for better visibility */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
    outline: 2px solid #f97316;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.2);
}

/* Remove default focus outline when custom is applied */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* Keyboard navigation focus */
.keyboard-navigation a:focus,
.keyboard-navigation button:focus,
.keyboard-navigation input:focus,
.keyboard-navigation textarea:focus,
.keyboard-navigation select:focus {
    outline: 3px solid #f97316;
    outline-offset: 2px;
    background-color: rgba(249, 115, 22, 0.1);
}

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

@media (prefers-contrast: high) {
    .bg-orange-500 {
        background-color: #000 !important;
        color: #fff !important;
    }
    
    .text-gray-600,
    .text-gray-700 {
        color: #000 !important;
    }
    
    .bg-white {
        background-color: #fff !important;
        border: 2px solid #000 !important;
    }
    
    .shadow-lg {
        box-shadow: 0 0 0 2px #000 !important;
    }
}

/* ========================================
   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;
    }
    
    .animate-bounce {
        animation: none !important;
    }
    
    .hover\:scale-105:hover,
    .hover\:-translate-y-2:hover {
        transform: none !important;
    }
}

/* ========================================
   SCREEN READER UTILITIES
   ======================================== */

.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;
}

.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: inherit !important;
    margin: inherit !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ========================================
   ARIA LIVE REGIONS
   ======================================== */

.live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

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

/* Required field indicators */
.required::after {
    content: " *";
    color: #dc2626;
    font-weight: bold;
    aria-label: "required";
}

/* Error states */
.error,
.has-error {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2) !important;
}

.error-message {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
}

.error-message::before {
    content: "⚠";
    margin-right: 0.5rem;
    font-weight: bold;
}

/* Success states */
.success,
.has-success {
    border-color: #16a34a !important;
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2) !important;
}

.success-message {
    color: #16a34a;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
}

.success-message::before {
    content: "✓";
    margin-right: 0.5rem;
    font-weight: bold;
}

/* ========================================
   BUTTON ACCESSIBILITY
   ======================================== */

/* Ensure buttons have adequate touch targets */
button,
.button,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 16px;
}

/* Disabled state */
button:disabled,
.button:disabled,
input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Loading state */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ========================================
   NAVIGATION ACCESSIBILITY
   ======================================== */

/* Mobile menu accessibility */
.mobile-menu[aria-hidden="true"] {
    display: none;
}

.mobile-menu[aria-hidden="false"] {
    display: block;
}

/* Navigation landmarks */
nav[role="navigation"] {
    position: relative;
}

/* Breadcrumb accessibility */
.breadcrumbs ol {
    list-style: none;
    padding: 0;
    margin: 0;
}

.breadcrumbs li {
    display: inline;
}

.breadcrumbs li:not(:last-child)::after {
    content: "/";
    margin: 0 0.5rem;
    color: #6b7280;
    aria-hidden: true;
}

/* ========================================
   TABLE ACCESSIBILITY
   ======================================== */

table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: left;
    font-weight: 600;
}

th,
td {
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
}

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   IMAGE ACCESSIBILITY
   ======================================== */

/* Decorative images */
img[alt=""],
img[role="presentation"] {
    opacity: 0.8;
}

/* Image loading states */
img {
    max-width: 100%;
    height: auto;
}

img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* ========================================
   COLOR AND CONTRAST
   ======================================== */

/* Ensure sufficient color contrast */
.text-gray-500 {
    color: #6b7280; /* WCAG AA compliant */
}

.text-gray-400 {
    color: #9ca3af; /* Use sparingly, may not meet contrast requirements */
}

/* Link colors with sufficient contrast */
a {
    color: #ea580c; /* Darker orange for better contrast */
}

a:hover {
    color: #c2410c; /* Even darker on hover */
}

/* ========================================
   RESPONSIVE TEXT SIZING
   ======================================== */

/* Ensure text can be zoomed to 200% without horizontal scrolling */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* Minimum 16px for mobile */
    }
    
    .text-sm {
        font-size: 14px; /* Minimum 14px for small text */
    }
}

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

@media print {
    /* Ensure good contrast in print */
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a,
    a:visited {
        text-decoration: underline;
    }
    
    /* Show URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }
    
    /* Hide non-essential elements */
    .mobile-menu,
    .skip-link,
    .live-region {
        display: none !important;
    }
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */

@media (prefers-color-scheme: dark) {
    :root {
        --primary-text: #f9fafb;
        --secondary-text: #d1d5db;
        --main-background: #111827;
        --card-background: #1f2937;
    }
    
    body {
        background-color: var(--main-background);
        color: var(--primary-text);
    }
    
    .bg-white {
        background-color: var(--card-background) !important;
    }
    
    .text-gray-900 {
        color: var(--primary-text) !important;
    }
    
    .text-gray-600 {
        color: var(--secondary-text) !important;
    }
    
    /* Adjust shadows for dark mode */
    .shadow-lg {
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.1) !important;
    }
}