/**
 * NEXUS Property OS - Accessibility Stylesheet
 * WCAG 2.1 AA Compliant Styles
 */

/* ===================================
   Skip Navigation Links
   =================================== */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: #D4AF37;
    color: #0A1628;
    padding: 0.75rem 1.5rem;
    z-index: 10000;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #00D4AA;
    outline-offset: 2px;
}

.skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
}

.skip-links a {
    position: absolute;
    top: -100%;
    left: 0;
    padding: 1rem 1.5rem;
    background: #D4AF37;
    color: #0A1628;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.3s;
}

.skip-links a:focus {
    top: 0;
}

/* ===================================
   Focus Styles
   =================================== */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 3px solid #D4AF37;
    outline-offset: 2px;
    border-radius: 2px;
}

/* Custom focus for dark backgrounds */
.dark-bg *:focus-visible,
[data-theme="dark"] *:focus-visible {
    outline-color: #00D4AA;
}

/* Focus within for complex components */
.form-group:focus-within {
    outline: 2px solid rgba(212, 175, 55, 0.5);
    outline-offset: 4px;
    border-radius: 8px;
}

/* Remove outline on mouse focus */
:focus:not(:focus-visible) {
    outline: none;
}

/* ===================================
   Keyboard Navigation Indicators
   =================================== */
.keyboard-user *:focus {
    outline: 3px solid #D4AF37 !important;
    outline-offset: 2px !important;
}

.keyboard-user button:focus,
.keyboard-user a:focus,
.keyboard-user [role="button"]:focus {
    box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.3);
}

/* Tab indicator for tab panels */
[role="tablist"] [role="tab"]:focus-visible {
    background: rgba(212, 175, 55, 0.2);
    outline: 2px solid #D4AF37;
}

[role="tab"][aria-selected="true"] {
    border-bottom: 3px solid #D4AF37;
}

/* ===================================
   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:focus,
.sr-only-focusable:active {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !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;
    }

    /* Keep essential loading indicators */
    .nexus-spinner,
    .loading-spinner {
        animation-duration: 1s !important;
    }
}

/* User preference for reduced motion */
.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
    animation: none !important;
    transition: none !important;
}

/* ===================================
   High Contrast Mode
   =================================== */
@media (prefers-contrast: high) {
    :root {
        --gold-primary: #FFD700;
        --teal-accent: #00FFCC;
        --text-primary: #FFFFFF;
        --text-secondary: #E0E0E0;
        --border-color: #FFFFFF;
    }

    body {
        background: #000 !important;
        color: #FFF !important;
    }

    .card,
    .nexus-card,
    .dashboard-card {
        border: 2px solid #FFF !important;
    }

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

    a {
        text-decoration: underline !important;
    }

    /* Ensure sufficient contrast for text */
    .text-muted {
        color: #CCC !important;
    }
}

/* Manual high contrast toggle */
.high-contrast {
    --gold-primary: #FFD700;
    --teal-accent: #00FFCC;
}

.high-contrast body {
    background: #000 !important;
    color: #FFF !important;
}

.high-contrast .card {
    border: 2px solid #FFF !important;
    background: #111 !important;
}

/* ===================================
   Color Blindness Support
   =================================== */
/* Deuteranopia (Red-Green) */
.colorblind-deuteranopia {
    --success-color: #0077B6;
    --error-color: #E63946;
    --warning-color: #FFB703;
}

/* Protanopia (Red-Green) */
.colorblind-protanopia {
    --success-color: #0077B6;
    --error-color: #9D4EDD;
    --warning-color: #FFB703;
}

/* Tritanopia (Blue-Yellow) */
.colorblind-tritanopia {
    --success-color: #06D6A0;
    --error-color: #E63946;
    --warning-color: #FF6B6B;
}

/* Add patterns to status indicators for color-blind users */
.colorblind-mode .status-success::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 4px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2310b981'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.colorblind-mode .status-error::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 4px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ef4444'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.colorblind-mode .status-warning::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 4px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f59e0b'%3E%3Cpath d='M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ===================================
   Text Accessibility
   =================================== */
/* Minimum font size */
html {
    font-size: 100%;
}

/* Scalable text */
body {
    font-size: 1rem;
    line-height: 1.5;
}

/* Large text mode */
.large-text body {
    font-size: 1.25rem;
}

.large-text h1 { font-size: 2.5rem; }
.large-text h2 { font-size: 2rem; }
.large-text h3 { font-size: 1.75rem; }
.large-text h4 { font-size: 1.5rem; }

/* Extra large text */
.extra-large-text body {
    font-size: 1.5rem;
}

/* Dyslexia-friendly font */
.dyslexia-friendly {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
    letter-spacing: 0.05em;
    word-spacing: 0.1em;
    line-height: 1.8;
}

/* Line spacing options */
.increased-line-height {
    line-height: 2 !important;
}

.increased-line-height p,
.increased-line-height li {
    margin-bottom: 1em;
}

/* Letter spacing options */
.increased-letter-spacing {
    letter-spacing: 0.1em;
}

/* Word spacing options */
.increased-word-spacing {
    word-spacing: 0.2em;
}

/* ===================================
   Link Accessibility
   =================================== */
a {
    color: #D4AF37;
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    text-decoration-thickness: 2px;
}

/* External link indicator */
a[target="_blank"]::after {
    content: " ↗";
    font-size: 0.75em;
    vertical-align: super;
}

/* Download link indicator */
a[download]::after {
    content: " ⬇";
    font-size: 0.85em;
}

/* Email link indicator */
a[href^="mailto:"]::before {
    content: "✉ ";
}

/* Phone link indicator */
a[href^="tel:"]::before {
    content: "📞 ";
}

/* ===================================
   Form Accessibility
   =================================== */
/* Labels */
label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

/* Required field indicator */
.required::after,
[aria-required="true"] + label::after {
    content: " *";
    color: #ef4444;
}

/* Error states */
.form-control[aria-invalid="true"],
.form-control.is-invalid {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Success states */
.form-control[aria-invalid="false"],
.form-control.is-valid {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Error messages */
.error-message,
[role="alert"] {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Form hints */
.form-hint,
[aria-describedby] + .hint {
    color: #94a3b8;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ===================================
   Button Accessibility
   =================================== */
button,
[role="button"],
.btn {
    min-height: 44px;
    min-width: 44px;
    cursor: pointer;
}

button:disabled,
[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Loading state */
button[aria-busy="true"] {
    position: relative;
    color: transparent;
}

button[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

th {
    text-align: left;
    font-weight: 600;
    background: rgba(26, 41, 66, 0.5);
}

th, td {
    padding: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Sortable columns */
th[aria-sort] {
    cursor: pointer;
}

th[aria-sort]::after {
    content: " ⇅";
    opacity: 0.5;
}

th[aria-sort="ascending"]::after {
    content: " ↑";
    opacity: 1;
}

th[aria-sort="descending"]::after {
    content: " ↓";
    opacity: 1;
}

/* Row selection */
tr[aria-selected="true"] {
    background: rgba(212, 175, 55, 0.1);
}

/* ===================================
   Modal/Dialog Accessibility
   =================================== */
[role="dialog"],
[role="alertdialog"] {
    position: fixed;
    z-index: 1000;
}

[role="dialog"][aria-modal="true"]::backdrop,
.modal-backdrop {
    background: rgba(0, 0, 0, 0.7);
}

/* Focus trap visual indicator */
[role="dialog"]:focus {
    outline: none;
}

/* ===================================
   Tab Panel Accessibility
   =================================== */
[role="tablist"] {
    display: flex;
    gap: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

[role="tab"] {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    transition: all 0.3s;
}

[role="tab"][aria-selected="true"] {
    color: #D4AF37;
    border-bottom: 2px solid #D4AF37;
}

[role="tab"]:hover {
    color: #fff;
}

[role="tabpanel"] {
    padding: 1.5rem 0;
}

[role="tabpanel"][hidden] {
    display: none;
}

/* ===================================
   Accordion Accessibility
   =================================== */
.accordion-header button {
    width: 100%;
    text-align: left;
    padding: 1rem;
    background: rgba(26, 41, 66, 0.5);
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.accordion-header button[aria-expanded="true"] {
    background: rgba(212, 175, 55, 0.1);
}

.accordion-header button::after {
    content: "+";
    font-size: 1.25rem;
}

.accordion-header button[aria-expanded="true"]::after {
    content: "−";
}

.accordion-panel[hidden] {
    display: none;
}

/* ===================================
   Progress Indicators
   =================================== */
[role="progressbar"] {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

[role="progressbar"]::before {
    content: "";
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #D4AF37, #00D4AA);
    width: var(--progress, 0%);
    transition: width 0.3s ease;
}

/* Indeterminate progress */
[role="progressbar"][aria-valuenow="undefined"]::before {
    width: 30%;
    animation: indeterminate 1.5s infinite ease-in-out;
}

@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ===================================
   Alert/Notification Accessibility
   =================================== */
[role="alert"] {
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0;
}

[role="alert"].success {
    background: rgba(16, 185, 129, 0.1);
    border-left: 4px solid #10b981;
}

[role="alert"].error {
    background: rgba(239, 68, 68, 0.1);
    border-left: 4px solid #ef4444;
}

[role="alert"].warning {
    background: rgba(245, 158, 11, 0.1);
    border-left: 4px solid #f59e0b;
}

[role="alert"].info {
    background: rgba(59, 130, 246, 0.1);
    border-left: 4px solid #3b82f6;
}

/* Live region for dynamic content */
[aria-live="polite"],
[aria-live="assertive"] {
    position: relative;
}

/* ===================================
   Image Accessibility
   =================================== */
img {
    max-width: 100%;
    height: auto;
}

/* Decorative images */
img[alt=""],
img[role="presentation"] {
    user-select: none;
}

/* Missing alt text warning (dev only) */
img:not([alt]) {
    outline: 3px dashed #ef4444;
}

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

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    background: #1a2942;
    color: #fff;
    font-size: 0.875rem;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    opacity: 1;
    visibility: visible;
}

/* Tooltips with role */
[role="tooltip"] {
    position: absolute;
    padding: 0.5rem 1rem;
    background: #1a2942;
    color: #fff;
    font-size: 0.875rem;
    border-radius: 4px;
    z-index: 100;
}

/* ===================================
   Landmark Regions
   =================================== */
[role="banner"],
[role="navigation"],
[role="main"],
[role="complementary"],
[role="contentinfo"] {
    display: block;
}

/* ===================================
   Accessibility Toggle Widget
   =================================== */
.a11y-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
}

.a11y-toggle-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #1a2942;
    border: 2px solid #D4AF37;
    color: #D4AF37;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s;
}

.a11y-toggle-btn:hover,
.a11y-toggle-btn:focus {
    background: #D4AF37;
    color: #0A1628;
}

.a11y-panel {
    position: absolute;
    bottom: 60px;
    left: 0;
    width: 280px;
    background: #1a2942;
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 12px;
    padding: 1rem;
    display: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.a11y-panel.active {
    display: block;
}

.a11y-panel h3 {
    margin-bottom: 1rem;
    color: #D4AF37;
    font-size: 1rem;
}

.a11y-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.a11y-option:last-child {
    border-bottom: none;
}

.a11y-option label {
    font-size: 0.9rem;
    color: #cbd5e1;
}

.a11y-option input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #D4AF37;
}

.a11y-slider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.a11y-slider input[type="range"] {
    width: 100px;
}
