/**
 * Accessibility Enhancements CSS
 * 
 * WCAG 2.1 AA compliant accessibility styles for the Wetail e-commerce platform.
 * Ensures the site is usable by everyone, including users with disabilities.
 * 
 * Features:
 * - High contrast focus indicators
 * - Skip navigation links
 * - Screen reader utilities
 * - Keyboard navigation support
 * - Color contrast compliance
 * - Reduced motion support
 */

/* ===== Skip Navigation Links ===== */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    font-weight: bold;
    border-radius: 0 0 4px 0;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid #ffd700;
    outline-offset: 2px;
}

/* ===== Focus Indicators ===== */
/* Enhanced focus styles for keyboard navigation */
*:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* Special focus for form inputs */
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #0066cc;
    outline-offset: 0;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}

/* Focus for buttons */
button:focus,
a.btn:focus,
.button:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.2);
}

/* Remove focus outline for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

:focus-visible {
    outline: 3px solid #ffd700;
    outline-offset: 2px;
}

/* ===== Screen Reader Only Content ===== */
.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;
}

.sr-only-focusable:active,
.sr-only-focusable:focus,
.visually-hidden-focusable:active,
.visually-hidden-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ===== High Contrast Mode ===== */
@media (prefers-contrast: high) {
    /* Increase border visibility */
    * {
        border-width: max(1px, 0.1em) !important;
    }
    
    /* Make links more visible */
    a {
        text-decoration: underline !important;
        text-decoration-thickness: 2px !important;
    }
    
    /* Enhance button visibility */
    button,
    .btn,
    input[type="submit"],
    input[type="button"] {
        border: 2px solid currentColor !important;
    }
    
    /* Increase form field borders */
    input,
    select,
    textarea {
        border: 2px solid currentColor !important;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    /* Disable animations */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* Remove parallax effects */
    .parallax {
        background-attachment: scroll !important;
    }
}

/* ===== Color Contrast Enhancements ===== */
/* Ensure text has sufficient contrast */
.text-muted {
    color: #666 !important; /* 4.5:1 contrast on white */
}

.text-light-gray {
    color: #767676 !important; /* Minimum WCAG AA contrast */
}

/* Link contrast */
a {
    color: #0066cc; /* High contrast blue */
}

a:hover,
a:focus {
    color: #004499; /* Darker on hover/focus */
    text-decoration: underline;
}

/* Button contrast */
.btn-primary {
    background-color: #0066cc;
    color: #fff;
    border: none;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: #0055aa;
}

.btn-secondary {
    background-color: #6c757d;
    color: #fff;
    border: none;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: #5a6268;
}

/* ===== Form Accessibility ===== */
/* Required field indicators */
.required::after,
label.required::after,
[required] + label::after {
    content: " *";
    color: #d00;
    font-weight: bold;
    font-size: 1.2em;
    line-height: 1;
}

/* Screen reader text for required fields */
.required-sr::after {
    content: " (required)";
    clip: rect(0, 0, 0, 0);
    position: absolute;
}

/* Error message styling */
.error,
.form-error,
.invalid-feedback,
[role="alert"] {
    color: #d00;
    font-weight: bold;
    padding: 8px;
    margin-top: 4px;
    display: block;
    font-size: 0.9em;
}

.error::before,
.form-error::before,
.invalid-feedback::before {
    content: "⚠️ ";
    margin-right: 4px;
}

/* Invalid input styling */
input:invalid,
select:invalid,
textarea:invalid {
    border-color: #d00;
    border-width: 2px;
}

input:invalid:focus,
select:invalid:focus,
textarea:invalid:focus {
    outline-color: #d00;
    box-shadow: 0 0 0 3px rgba(220, 0, 0, 0.2);
}

/* Valid input styling */
input:valid:not(:placeholder-shown),
select:valid,
textarea:valid:not(:placeholder-shown) {
    border-color: #28a745;
}

/* ===== Button Accessibility ===== */
/* Minimum touch target size (44x44px per WCAG) */
button,
.btn,
a.btn,
input[type="button"],
input[type="submit"],
input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 24px;
    cursor: pointer;
}

/* Disabled state with sufficient contrast */
button:disabled,
.btn:disabled,
button[disabled],
.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #ccc;
    color: #666;
}

/* Loading state accessibility */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #fff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: btn-spinner 0.6s linear infinite;
}

@keyframes btn-spinner {
    to { transform: rotate(360deg); }
}

/* ===== Table Accessibility ===== */
/* Table headers */
th {
    font-weight: bold;
    text-align: left;
}

/* Table caption */
caption {
    padding: 8px;
    caption-side: top;
    font-weight: bold;
    text-align: left;
}

/* Zebra striping for readability */
table.striped tbody tr:nth-child(odd) {
    background-color: #f8f9fa;
}

/* ===== Navigation Accessibility ===== */
/* Navigation landmarks */
nav[aria-label],
[role="navigation"] {
    position: relative;
}

/* Current page indicator */
.nav-link[aria-current="page"],
.nav-item.active {
    font-weight: bold;
    text-decoration: underline;
    position: relative;
}

.nav-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: currentColor;
}

/* ===== Modal Accessibility ===== */
/* Focus trap for modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    display: none;
}

.modal.show {
    display: block;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

.modal-dialog {
    position: relative;
    margin: 1.75rem auto;
    max-width: 500px;
    background: #fff;
    border-radius: 4px;
    padding: 20px;
}

/* Modal focus management */
.modal:focus {
    outline: none;
}

.modal .close-button {
    position: absolute;
    top: 16px;
    right: 16px;
    min-width: 44px;
    min-height: 44px;
}

/* ===== Image Accessibility ===== */
/* Decorative images */
img[alt=""],
img[role="presentation"] {
    /* Properly hidden from screen readers */
}

/* Ensure all images have dimensions */
img:not([width]):not([height]) {
    max-width: 100%;
    height: auto;
}

/* ===== Link Accessibility ===== */
/* External links indicator */
a[target="_blank"]:not(:has(img))::after {
    content: " ↗";
    display: inline-block;
    font-size: 0.8em;
    vertical-align: super;
}

/* Links with only images don't show the indicator */
/* Note: :has() is used for modern browsers, gracefully degrades in older browsers */

/* Download links indicator */
a[download]::after {
    content: " ⬇";
    display: inline-block;
    font-size: 0.8em;
}

/* ===== Tooltip Accessibility ===== */
.tooltip {
    position: absolute;
    z-index: 1070;
    display: none;
    background-color: #000;
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    max-width: 200px;
}

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

/* Tooltip arrow */
.tooltip::before {
    content: "";
    position: absolute;
    border: 5px solid transparent;
}

.tooltip-top::before {
    bottom: -10px;
    border-top-color: #000;
}

.tooltip-bottom::before {
    top: -10px;
    border-bottom-color: #000;
}

/* ===== Live Region for Dynamic Content ===== */
[aria-live="polite"],
[aria-live="assertive"] {
    position: relative;
}

.loading-message,
.success-message,
.error-message {
    padding: 12px 16px;
    margin: 16px 0;
    border-radius: 4px;
    font-weight: bold;
}

.loading-message {
    background-color: #d1ecf1;
    color: #0c5460;
    border-left: 4px solid #0c5460;
}

.success-message {
    background-color: #d4edda;
    color: #155724;
    border-left: 4px solid #28a745;
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    border-left: 4px solid #d00;
}

/* ===== Breadcrumb Accessibility ===== */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 12px 16px;
    margin-bottom: 16px;
    background-color: #f8f9fa;
    border-radius: 4px;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    padding: 0 8px;
    color: #6c757d;
}

.breadcrumb-item[aria-current="page"] {
    font-weight: bold;
}

/* ===== Card Accessibility ===== */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

.card-header {
    padding: 12px 16px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    font-weight: bold;
}

.card-body {
    padding: 16px;
    flex: 1 1 auto;
}

/* ===== Alert Accessibility ===== */
.alert {
    position: relative;
    padding: 12px 16px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    border-radius: 4px;
}

.alert-info {
    color: #0c5460;
    background-color: #d1ecf1;
    border-color: #bee5eb;
}

.alert-success {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
}

.alert-warning {
    color: #856404;
    background-color: #fff3cd;
    border-color: #ffeaa7;
}

.alert-danger {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
}

/* Alert close button */
.alert .close {
    position: absolute;
    top: 12px;
    right: 12px;
    min-width: 44px;
    min-height: 44px;
    padding: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
}

/* ===== Progress Bar Accessibility ===== */
.progress {
    display: flex;
    height: 24px;
    overflow: hidden;
    background-color: #e9ecef;
    border-radius: 4px;
}

.progress-bar {
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    text-align: center;
    background-color: #0066cc;
    transition: width 0.6s ease;
}

@media (prefers-reduced-motion: reduce) {
    .progress-bar {
        transition: none;
    }
}

/* ===== Print Accessibility ===== */
@media print {
    /* Show links */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }
    
    /* Hide non-essential elements */
    nav,
    .no-print,
    .skip-to-content {
        display: none !important;
    }
    
    /* Ensure good contrast */
    * {
        color: #000 !important;
        background: #fff !important;
    }
}
