/* Accessibility Enhancements (A11y) */

/* Skip to Content Link */
.skip-to-content {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 9999;
    padding: 1rem 2rem;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 0 0 8px 8px;
}

.skip-to-content:focus {
    left: 50%;
    transform: translateX(-50%);
}

/* Focus Indicators */
*:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Better focus for interactive elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(214, 51, 132, 0.1);
}

/* Remove outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Ensure proper color contrast */
.high-contrast {
    background: white !important;
    color: black !important;
}

.high-contrast a {
    color: #0066cc !important;
    text-decoration: underline !important;
}

.high-contrast button,
.high-contrast .btn {
    background: #0066cc !important;
    color: white !important;
    border: 2px solid #0066cc !important;
}

/* Screen Reader Only Text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Make focus visible when navigating with keyboard */
.sr-only:focus {
    position: absolute;
    width: auto;
    height: auto;
    padding: 0.5rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: var(--primary);
    color: white;
    z-index: 9999;
}

/* Improved form labels */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    cursor: pointer;
}

/* Required field indicators */
.required::after {
    content: " *";
    color: var(--primary);
    font-weight: bold;
}

/* Error messages */
.error-message {
    color: #d32f2f;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-message::before {
    content: "⚠";
    font-size: 1.2rem;
}

/* Success messages */
.success-message {
    color: var(--success);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.success-message::before {
    content: "✓";
    font-size: 1.2rem;
}

/* Improved button states */
button:disabled,
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading states */
[aria-busy="true"] {
    position: relative;
    pointer-events: none;
}

[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Improved link underlines for better visibility */
main a:not(.btn) {
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
}

/* Better table accessibility */
table {
    border-collapse: collapse;
    width: 100%;
}

table caption {
    font-weight: bold;
    margin-bottom: 0.5rem;
    text-align: left;
}

th {
    background: var(--cream);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
}

td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--cream);
}

/* Improved image alt text display */
img:not([alt]) {
    border: 3px solid red;
}

img[alt=""] {
    border: 3px solid orange;
}

/* Better keyboard navigation indicators */
.keyboard-nav *:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion preferences */
@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;
    }
    
    .hero video {
        display: none;
    }
    
    .flour-particle {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary: #c41e3a;
        --secondary: #0095a8;
        --text-dark: #000;
        --text-medium: #000;
        --text-light: #333;
        --cream: #fff;
        --warm-white: #fff;
    }
    
    * {
        border-color: currentColor !important;
    }
    
    .btn {
        border: 2px solid currentColor !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --cream: #1a1a1a;
        --warm-white: #2a2a2a;
        --text-dark: #f0f0f0;
        --text-medium: #d0d0d0;
        --text-light: #b0b0b0;
        --brown: #e0e0e0;
    }
    
    body {
        background: #1a1a1a;
        color: #f0f0f0;
    }
    
    .product-card,
    .blog-card,
    .contact-form-section,
    .contact-info-section {
        background: #2a2a2a;
        color: #f0f0f0;
    }
    
    img {
        opacity: 0.9;
    }
}

/* Improved form validation */
input:invalid,
select:invalid,
textarea:invalid {
    border-color: #d32f2f;
}

input:valid,
select:valid,
textarea:valid {
    border-color: var(--success);
}

/* Better touch targets */
@media (pointer: coarse) {
    a,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Improved readability */
p,
li {
    line-height: 1.6;
    max-width: 70ch;
}

/* Better heading hierarchy */
h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
h3 { font-size: clamp(1.25rem, 3vw, 2rem); }
h4 { font-size: clamp(1.1rem, 2.5vw, 1.5rem); }

/* Accessible modals */
[role="dialog"] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
}

[role="dialog"][aria-hidden="true"] {
    display: none;
}

/* Accessible tooltips */
[role="tooltip"] {
    position: absolute;
    background: var(--text-dark);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.875rem;
    white-space: nowrap;
    z-index: 1000;
}

/* Print styles for better readability */
@media print {
    * {
        background: white !important;
        color: black !important;
    }
    
    a {
        text-decoration: underline !important;
    }
    
    a[href^="http"]:after {
        content: " (" attr(href) ")";
    }
    
    .no-print {
        display: none !important;
    }
}

/* Language direction support */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .container {
    direction: rtl;
}

/* Improved icon accessibility */
.icon-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Ensure interactive elements are distinguishable */
a:not(.btn) {
    color: var(--primary);
    font-weight: 500;
}

a:not(.btn):hover {
    text-decoration: underline;
}

a:not(.btn):visited {
    color: #8e1f5b;
}

/* Better error handling */
.field-error {
    border: 2px solid #d32f2f !important;
    background-color: #ffebee;
}

.field-success {
    border: 2px solid var(--success) !important;
    background-color: #e8f5e9;
}

/* Accessible loading states */
.loading {
    position: relative;
    color: transparent;
}

.loading::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-medium);
}

/* Better list markers */
ul li::marker {
    color: var(--primary);
}

/* Improved table responsiveness */
@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
    }
}
