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

/* Skip Navigation Link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 16px 32px;
    border-radius: 8px;
    font-weight: 600;
    z-index: 10000;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 20px;
    outline: 3px solid var(--secondary);
    outline-offset: 3px;
}

/* Focus Indicators - Enhanced Visibility */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Remove outline only for mouse users */
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;
}

/* Enhanced keyboard navigation */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 53, 39, 0.1);
}

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

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

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --primary: #002d1f;
        --text: #000000;
        --bg: #ffffff;
    }

    a,
    button {
        text-decoration: underline;
    }

    .btn {
        border: 2px solid currentColor;
    }
}

/* 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;
    }
}

/* ARIA Live Regions */
[aria-live="polite"],
[aria-live="assertive"] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Better Link Underlines for Readability */
.content a:not(.btn) {
    text-decoration: underline;
    text-decoration-color: var(--primary);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.content a:not(.btn):hover {
    text-decoration-thickness: 2px;
}

/* Form Labels - Always Visible */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

/* Required Field Indicator */
.required::after {
    content: " *";
    color: var(--error);
    font-weight: bold;
}

/* Error Messages - Accessible */
.error-message {
    color: var(--error);
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.error-message::before {
    content: "⚠";
    font-size: 16px;
}

/* Success Messages */
.success-message {
    color: #2ecc71;
    font-size: 14px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.success-message::before {
    content: "✓";
    font-size: 16px;
    font-weight: bold;
}

/* Improve Form Input States */
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown) {
    border-color: var(--error);
}

input:valid:not(:placeholder-shown),
textarea:valid:not(:placeholder-shown) {
    border-color: #2ecc71;
}

/* Disabled State - Clear Visual Indicator */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--surface-dim);
}

/* Better Table Accessibility */
table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: right;
    font-weight: 700;
    background: var(--surface-container);
    padding: 12px;
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--outline-variant);
}

/* Caption for Tables */
caption {
    font-weight: 700;
    text-align: right;
    padding: 12px;
    caption-side: top;
}

/* Landmark Roles Visual Indicators (Dev Mode) */
body.show-landmarks [role="banner"]::before,
body.show-landmarks [role="main"]::before,
body.show-landmarks [role="contentinfo"]::before,
body.show-landmarks [role="navigation"]::before {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--primary);
    color: white;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    z-index: 9999;
}

body.show-landmarks [role="banner"]::before {
    content: "BANNER";
}

body.show-landmarks [role="main"]::before {
    content: "MAIN";
}

body.show-landmarks [role="contentinfo"]::before {
    content: "FOOTER";
}

body.show-landmarks [role="navigation"]::before {
    content: "NAV";
}

/* Font Size Control */
html[data-font-size="large"] {
    font-size: 18px;
}

html[data-font-size="x-large"] {
    font-size: 20px;
}

/* Image Alt Text Warning (Dev Mode) */
body.show-alt-warnings img:not([alt]) {
    outline: 3px solid var(--error);
    outline-offset: 2px;
}

/* Heading Hierarchy Warning (Dev Mode) */
body.show-heading-warnings h3:first-child,
body.show-heading-warnings h4:first-child,
body.show-heading-warnings h5:first-child {
    outline: 2px dashed orange;
}

/* Language Attributes */
[lang="en"] {
    direction: ltr;
    text-align: left;
}

[lang="ar"] {
    direction: rtl;
    text-align: right;
}

/* Button Hover States - Clear Indication */
.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

/* Loading State Accessibility */
[aria-busy="true"] {
    pointer-events: none;
    opacity: 0.7;
    cursor: wait;
}

/* Modal Accessibility */
.modal[aria-hidden="true"] {
    display: none;
}

.modal[aria-hidden="false"] {
    display: flex;
}

/* Focus Trap for Modals */
.modal-open {
    overflow: hidden;
}

/* Better Color Contrast for Links */
a {
    color: var(--primary);
}

a:hover {
    color: var(--primary-dark);
}

/* Tooltip Accessibility */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    right: 0;
    background: var(--text);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 8px;
}

/* Print Styles - Accessibility */
@media print {
    .skip-link,
    .site-header,
    .site-footer,
    .whatsapp-float,
    .call-float,
    #scrollTop {
        display: none !important;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 12px;
        color: #666;
    }

    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}
