/**
 * Global Accessibility Styles
 * FilamentsDeals Bot - WCAG 2.1 Level AA Compliant
 */

/* ==========================================================================
   Focus Indicators - Critical for keyboard navigation
   ========================================================================== */

/* Default focus style for all interactive elements */
*:focus {
    outline: 3px solid #667eea !important;
    outline-offset: 2px !important;
}

/* Enhanced focus for buttons */
button:focus,
input[type="button"]:focus,
input[type="submit"]:focus,
input[type="reset"]:focus {
    outline: 3px solid #667eea !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2) !important;
}

/* Focus for links */
a:focus {
    outline: 3px solid #667eea !important;
    outline-offset: 2px !important;
    text-decoration: underline !important;
}

/* Focus for form inputs */
input:focus,
textarea:focus,
select:focus {
    outline: 3px solid #667eea !important;
    outline-offset: 1px !important;
    border-color: #667eea !important;
}

/* Focus within - for containers */
.card:focus-within,
.stat-card:focus-within,
.notification-item:focus-within {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* ==========================================================================
   Skip Links - Allow users to skip to main content
   ========================================================================== */

.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 12px 20px;
    text-decoration: none;
    font-weight: bold;
    z-index: 100000;
    border-radius: 0 0 4px 0;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #fff !important;
    outline-offset: 2px !important;
}

/* ==========================================================================
   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;
}

/* Allow screen reader content to be focusable */
.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ==========================================================================
   ARIA Live Regions
   ========================================================================== */

[aria-live="polite"],
[aria-live="assertive"] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Make live regions visible when they have content (for debugging) */
/* Remove in production if needed */
/*
[aria-live][data-debug="true"] {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: #000;
    color: #fff;
    padding: 8px;
    z-index: 99999;
    width: auto;
    height: auto;
}
*/

/* ==========================================================================
   Improved Form Labels
   ========================================================================== */

label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #333;
}

/* Required field indicator */
label.required::after,
label[aria-required="true"]::after {
    content: " *";
    color: #d32f2f;
    font-weight: bold;
}

/* Error state for inputs */
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
    border-color: #d32f2f !important;
    background-color: #fff5f5 !important;
}

/* Error messages */
.error-message,
[role="alert"] {
    color: #d32f2f;
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.error-message::before {
    content: "⚠️";
}

/* Success messages */
.success-message {
    color: #2e7d32;
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.success-message::before {
    content: "✓";
}

/* ==========================================================================
   Keyboard Navigation Indicators
   ========================================================================== */

/* Show navigation hints for keyboard users */
body.keyboard-nav *:focus {
    outline: 3px solid #667eea !important;
    outline-offset: 2px !important;
}

/* Detect keyboard navigation */
body:not(.keyboard-nav) *:focus {
    /* Optional: reduce outline for mouse users */
    /* Remove this if you want consistent focus for all users */
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
    * {
        outline-width: 3px !important;
        border-width: 2px !important;
    }

    button,
    a {
        text-decoration: underline;
    }
}

/* ==========================================================================
   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;
    }
}

/* ==========================================================================
   Touch Target Size - Minimum 44x44px (WCAG 2.1 Level AAA)
   ========================================================================== */

button,
a,
input[type="button"],
input[type="submit"],
input[type="reset"],
input[type="checkbox"],
input[type="radio"],
select {
    min-height: 44px;
    min-width: 44px;
}

/* Exception for inline links in text */
p a,
li a,
span a {
    min-height: auto;
    min-width: auto;
}

/* Ensure checkboxes and radios are large enough */
input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 12px;
}

/* ==========================================================================
   Modal/Dialog Accessibility
   ========================================================================== */

[role="dialog"],
[role="alertdialog"],
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
}

/* Modal backdrop */
.modal-backdrop,
[role="dialog"]::before {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* ==========================================================================
   Link Styles for Accessibility
   ========================================================================== */

a {
    text-decoration: underline;
    color: #667eea;
    cursor: pointer;
}

a:hover {
    text-decoration: none;
    color: #764ba2;
}

/* External link indicator */
a[target="_blank"]::after {
    content: " ↗";
    font-size: 0.8em;
}

/* Skip external indicator for images */
a[target="_blank"] img::after {
    content: none;
}

/* ==========================================================================
   Table Accessibility
   ========================================================================== */

table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: right;
    font-weight: bold;
    background: #f0f4ff;
}

th[scope="col"] {
    /* Column header styles */
}

th[scope="row"] {
    /* Row header styles */
}

/* ==========================================================================
   Status and Alert Styling
   ========================================================================== */

[role="status"] {
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
}

[role="alert"] {
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    background: #fff5f5;
    border-right: 4px solid #d32f2f;
}

[role="status"][aria-live="polite"] {
    background: #f0f4ff;
    border-right: 4px solid #667eea;
}

/* ==========================================================================
   Loading States
   ========================================================================== */

[aria-busy="true"] {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

[aria-busy="true"]::after {
    content: "⏳ טוען...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Tooltip Accessibility
   ========================================================================== */

[role="tooltip"] {
    position: absolute;
    z-index: 10001;
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    pointer-events: none;
}

/* ==========================================================================
   Print Styles for Accessibility
   ========================================================================== */

@media print {
    /* Show URLs for links */
    a[href]::after {
        content: " (" attr(href) ")";
    }

    /* Hide non-essential elements */
    .no-print,
    #accessibility-widget,
    nav,
    .quick-actions {
        display: none !important;
    }

    /* Ensure good contrast */
    * {
        color: #000 !important;
        background: #fff !important;
    }
}

/* ==========================================================================
   Mobile Accessibility Improvements
   ========================================================================== */

@media (max-width: 768px) {
    /* Larger touch targets on mobile */
    button,
    a,
    input[type="button"],
    input[type="submit"] {
        min-height: 48px;
        min-width: 48px;
        padding: 12px 16px;
    }

    /* Larger form inputs */
    input,
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 48px;
    }

    /* More spacing between interactive elements */
    button + button,
    a + a {
        margin-top: 12px;
    }
}

/* ==========================================================================
   Language Direction Support (RTL/LTR)
   ========================================================================== */

[dir="rtl"] .skip-link {
    left: auto;
    right: 0;
    border-radius: 0 0 0 4px;
}

[dir="ltr"] .skip-link {
    left: 0;
    right: auto;
    border-radius: 0 0 4px 0;
}

/* ==========================================================================
   Contrast and Color Accessibility
   ========================================================================== */

/* Ensure sufficient contrast for disabled elements */
button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #f5f5f5 !important;
    color: #666 !important;
}

/* ==========================================================================
   Focus Trap for Modals
   ========================================================================== */

.modal-open [inert],
.modal-open [aria-hidden="true"]:not(.modal):not(.modal *) {
    pointer-events: none;
    user-select: none;
}
