/**
 * WCAG 2.2 Level AAA Accessibility Styles
 * Ensures all visual requirements for AAA compliance
 */

/* === SKIP LINK (2.4.1 Bypass Blocks - Level A) === */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--v3-primary, #0ea5e9);
    color: white;
    padding: 1rem 2rem;
    z-index: 10000;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    transition: top 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #fff;
    outline-offset: 4px;
}

/* === FOCUS VISIBLE (2.4.7 Focus Visible - Level AA, Enhanced for AAA) === */
:focus-visible {
    outline: 3px solid var(--v3-primary, #0ea5e9) !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 6px rgba(14, 165, 233, 0.2) !important;
}

/* Enhanced focus for keyboard users */
.user-is-tabbing *:focus {
    outline: 3px solid var(--v3-primary, #0ea5e9) !important;
    outline-offset: 4px !important;
}

/* Remove focus outline for mouse users */
body:not(.user-is-tabbing) *:focus {
    outline: none;
}

/* === TEXT SPACING (1.4.12 Text Spacing - Level AA, Enhanced for AAA) === */
*:not(video):not(img):not(svg):not(canvas):not(iframe) {
    line-height: 1.5 !important;
}

/* Ensure media elements have proper display */
video,
img,
svg,
canvas,
iframe {
    line-height: normal !important;
    display: block;
}

p {
    line-height: 1.5 !important;
    margin-bottom: 2.25em !important;
    /* 1.5x line-height (1.5 * 1.5 = 2.25) for AAA */
    text-align: left !important;
    text-justify: none !important;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: 1.3 !important;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
}

/* === VISUAL PRESENTATION (1.4.8 Visual Presentation - Level AAA) === */
/* Maximum line length: 80 characters */
p,
li,
dd {
    max-width: 80ch;
}

/* Text not justified (WCAG AAA) - Exception for centered footer */
p:not(.footer-bottom p),
li,
dd,
td {
    text-align: left !important;
}

.footer-bottom p {
    text-align: center !important;
    max-width: none !important;
    /* Allow footer to span full width for centering */
}

/* Paragraph spacing: at least 1.5x line spacing (1.5 * 1.5 = 2.25) */
p+p {
    margin-top: 2.25em !important;
}

/* 2.4.12 Focus Not Obscured (WCAG 2.2) */
/* Ensure focused elements are not hidden by sticky headers */
:focus {
    scroll-margin-top: 100px;
}

/* 2.4.13 Focus Appearance (Enhanced) */
.user-is-tabbing *:focus {
    outline: 4px solid var(--v3-primary, #0ea5e9) !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 8px rgba(14, 165, 233, 0.4), 0 0 0 12px #fff !important;
    border-radius: 4px !important;
}

[data-theme="dark"] .user-is-tabbing *:focus {
    box-shadow: 0 0 0 8px rgba(96, 213, 250, 0.4), 0 0 0 12px #000 !important;
}

/* === CONTRAST RATIOS (1.4.6 Contrast Enhanced - Level AAA: 7:1) === */
/* Already handled in design system, but enforce minimum */
body {
    color: var(--text-primary);
    background: var(--bg-body);
}

/* Ensure all text meets 7:1 contrast */
a {
    color: var(--text-accent);
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 2px;
}

a:hover,
a:focus {
    color: var(--v3-primary);
    text-decoration: underline;
    text-decoration-thickness: 3px;
}

/* === TARGET SIZE (2.5.5 Target Size - Level AAA: 44x44px) === */
button,
a,
input[type="button"],
input[type="submit"],
input[type="reset"],
[role="button"] {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0.5rem 1rem !important;
}

/* === BUTTON CONTRAST (WCAG 2.2 AAA: 7:1) === */
/* Ensure all buttons have AAA-compliant contrast */

/* Primary buttons - dark background with white text */
.btn-primary,
button.btn-primary,
[class*="btn-primary"] {
    background-color: #00486b !important;
    /* Dark blue for 7:1 contrast */
    color: #ffffff !important;
}

.btn-primary:hover,
button.btn-primary:hover {
    background-color: #00527a !important;
    color: #ffffff !important;
}

/* Secondary buttons - ensure text contrast */
.btn-secondary,
button.btn-secondary,
[class*="btn-secondary"] {
    background-color: #ffffff !important;
    color: #0f172a !important;
    /* Dark text on light background */
    border: 2px solid #0f172a !important;
}

.btn-secondary:hover,
button.btn-secondary:hover {
    background-color: #f8fafc !important;
    color: #00486b !important;
}

/* Light blue buttons - MUST have white text for AAA */
.btn-light,
.btn-info,
[style*="background: #38bdf8"],
[style*="background: #0ea5e9"],
[style*="background-color: #38bdf8"],
[style*="background-color: #0ea5e9"] {
    color: #ffffff !important;
    /* Force white text on light blue */
}

/* Ensure all buttons on colored backgrounds have white text */
button[style*="background"],
.btn[style*="background"] {
    color: #ffffff !important;
}

/* Dark mode button fixes */
[data-theme="dark"] .btn-primary {
    background: var(--brand-gradient) !important;
    color: #ffffff !important;
    border: none !important;
}

[data-theme="dark"] .btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 20px rgba(14, 165, 233, 0.4);
}

[data-theme="dark"] .btn-secondary {
    background-color: #0f172a !important;
    color: #ffffff !important;
    border-color: #60d5fa !important;
}

[data-theme="dark"] .btn-secondary:hover {
    background-color: #1e293b !important;
    color: #ffffff !important;
}

/* === REFLOW (1.4.10 Reflow - Level AA) === */
/* Content reflows at 320px width without horizontal scrolling */
@media (max-width: 320px) {
    * {
        max-width: 100% !important;
        overflow-wrap: break-word !important;
    }
}

/* === RESIZE TEXT (1.4.4 Resize Text - Level AA, Enhanced for AAA) === */
/* Text can be resized up to 200% without loss of content or functionality */
html {
    font-size: 100%;
}

@media (min-width: 1920px) {
    html {
        font-size: 112.5%;
        /* 18px base */
    }
}

/* === IMAGES OF TEXT (1.4.5 Images of Text - Level AA, 1.4.9 for AAA) === */
/* Avoid images of text - use actual text with CSS styling */
/* This is enforced through content guidelines */

/* === ABBREVIATIONS (3.1.4 Abbreviations - Level AAA) === */
abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
    border-bottom: 1px dotted currentColor;
}

/* === SECTION HEADINGS (2.4.10 Section Headings - Level AAA) === */
/* Ensure headings are visually distinct */
h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-top: 0;
}

h2 {
    font-size: 2rem;
    font-weight: 700;
}

h3 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Specific override for HERO and Dashboard to keep spacing tight */
.hero h1,
.hero-content h1,
.dashboard-grid h1,
#content-area h1 {
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
}

h4 {
    font-size: 1.25rem;
    font-weight: 600;
}

h5 {
    font-size: 1.125rem;
    font-weight: 600;
}

h6 {
    font-size: 1rem;
    font-weight: 600;
}

/* === ANIMATION (2.3.3 Animation from Interactions - Level AAA) === */
/* Respect prefers-reduced-motion and manual override */
@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;
    }
}

.reduce-motion-active *,
.reduce-motion-active *::before,
.reduce-motion-active *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

.reduce-motion-active .reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
}

/* === CONSISTENT NAVIGATION (3.2.3 Consistent Navigation - Level AA) === */
/* Navigation should appear in same relative order */
nav {
    position: relative;
}

/* === ERROR IDENTIFICATION (3.3.1 Error Identification - Level A) === */
.error,
[aria-invalid="true"] {
    border-color: #dc2626 !important;
    outline: 2px solid #dc2626 !important;
}

.error-message {
    color: #dc2626;
    font-weight: 600;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-message::before {
    content: '⚠️';
    font-size: 1.2em;
}

/* === SUCCESS MESSAGES === */
.success-message {
    color: #16a34a;
    font-weight: 600;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.success-message::before {
    content: '✓';
    font-size: 1.2em;
}

/* === ARIA LIVE REGIONS === */
[role="status"],
[role="alert"],
[aria-live] {
    position: relative;
}

/* === BREADCRUMBS (2.4.8) === */
.breadcrumbs {
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
    position: relative;
    z-index: 100;
}

@media (max-width: 1100px) {
    .breadcrumbs {
        margin-top: 0.5rem !important;
    }
}

.breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
    align-items: center;
    gap: 0.5rem;
}

.breadcrumbs li {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.breadcrumbs li a {
    color: var(--v3-primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.breadcrumbs li a:hover {
    color: var(--v3-deep);
    text-decoration: underline;
}

/* === ACTIVE NAV INDICATOR (2.4.8) === */
.nav-item a.active {
    background: rgba(14, 165, 233, 0.1) !important;
    color: var(--v3-primary) !important;
    box-shadow: inset 0 -2px 0 var(--v3-primary);
    font-weight: 700;
}

/* === PRINT STYLES (for accessibility) === */
@media print {

    .skip-link,
    nav,
    .no-print {
        display: none !important;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    abbr[title]::after {
        content: " (" attr(title) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* === HIGH CONTRAST MODE SUPPORT === */
@media (prefers-contrast: high) {
    * {
        border-color: currentColor !important;
    }

    a {
        text-decoration: underline !important;
        font-weight: 700 !important;
    }
}

/* === DARK MODE ACCESSIBILITY === */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #ffffff;
        --text-secondary: #d4dce6;
        --bg-body: #020617;
        --bg-surface: #0f172a;
    }

    /* Video visibility in system dark mode */
    video,
    .hero-video {
        opacity: 0.6 !important;
        /* Made darker */
        filter: brightness(0.7) contrast(1.1) !important;
        /* Reduced brightness */
        z-index: 1 !important;
    }

    .hero-overlay {
        background: radial-gradient(circle at center, transparent 0%, rgba(2, 6, 23, 0.6) 100%),
            linear-gradient(to bottom, rgba(2, 6, 23, 0.5) 0%, #020617 100%) !important;
        z-index: 2 !important;
        opacity: 0.8 !important;
        /* Darker overlay */
    }

    .hero-content {
        position: relative !important;
        z-index: 3 !important;
    }

    .hero {
        background: transparent !important;
    }
}

/* Dark mode theme attribute (manual toggle) */
[data-theme="dark"] {
    /* Ensure AAA contrast ratios (7:1 minimum) */
    color: #ffffff;
    background-color: #020617;
}

[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6 {
    color: #ffffff;
}

[data-theme="dark"] p,
[data-theme="dark"] li,
[data-theme="dark"] dd,
[data-theme="dark"] td {
    color: #d4dce6;
    /* 7.1:1 contrast on #0f172a */
}

[data-theme="dark"] a {
    color: #60d5fa;
    /* Lighter blue for better contrast */
}

[data-theme="dark"] a:hover,
[data-theme="dark"] a:focus {
    color: #7ee0fc;
    /* Even lighter on hover */
}

/* Dark mode borders */
[data-theme="dark"] .card,
[data-theme="dark"] .border {
    border-color: rgba(255, 255, 255, 0.15);
}

/* Dark mode focus indicators */
[data-theme="dark"] :focus-visible {
    outline-color: #60d5fa !important;
    box-shadow: 0 0 0 6px rgba(96, 213, 250, 0.3) !important;
}

/* Dark mode error/success messages */
[data-theme="dark"] .error-message {
    color: #fca5a5;
    /* Lighter red for dark backgrounds */
}

[data-theme="dark"] .success-message {
    color: #86efac;
    /* Lighter green for dark backgrounds */
}

/* Dark mode video visibility */
[data-theme="dark"] video,
[data-theme="dark"] .hero-video {
    opacity: 0.6 !important;
    /* Made darker for better text contrast */
    filter: brightness(0.7) contrast(1.1) !important;
    /* Reduced brightness */
    z-index: 1 !important;
}

[data-theme="dark"] .hero-overlay {
    background: radial-gradient(circle at center, transparent 0%, rgba(2, 6, 23, 0.6) 100%),
        linear-gradient(to bottom, rgba(2, 6, 23, 0.5) 0%, #020617 100%) !important;
    z-index: 2 !important;
    opacity: 0.8 !important;
    /* Darker overlay for professional look */
}

/* Watermark / Decorative Layer for Dark Mode */
[data-theme="dark"] .hero::after {
    content: "MediClean Pro® Secure Systems";
    position: absolute;
    bottom: 2rem;
    left: 2rem;
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.2rem;
    color: rgba(255, 255, 255, 0.15);
    z-index: 4;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    backdrop-filter: blur(2px);
}

/* Ensure parent background doesn't cover video */
[data-theme="dark"] .hero {
    background: transparent !important;
    position: relative !important;
}

[data-theme="dark"] .hero-content {
    position: relative !important;
    z-index: 3 !important;
    /* Top layer */
}

/* CRITICAL: Ensure video element is always displayed */
video,
.hero-video {
    display: block !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Video controls in dark mode */
[data-theme="dark"] .video-controls button {
    background-color: rgba(255, 255, 255, 0.2) !important;
    backdrop-filter: blur(10px) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

[data-theme="dark"] .video-controls button:hover {
    background-color: rgba(255, 255, 255, 0.3) !important;
}

/* === RESPONSIVE ACCESSIBILITY BANNER === */
.accessibility-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    /* Ensure icon and text wrap on small screens */
    font-size: 1.5rem;
    color: var(--text-main);
    margin-top: 0 !important;
    margin-bottom: 1rem !important;
}

.accessibility-header svg {
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .accessibility-header {
        gap: 0.8rem;
        font-size: 1.2rem;
        justify-content: center;
        text-align: center;
        flex-direction: column;
        /* Stack on very small screens for safety */
    }

    .accessibility-header svg {
        margin-bottom: 0.5rem;
    }

    .accessibility-banner {
        padding: 1.5rem !important;
    }
}

/* Ensure abbreviations inside headers don't break flex layout */
.accessibility-header abbr,
.accessibility-header span {
    display: inline-block;
    white-space: normal;
}

/* === LEICHTER SPRACHE / SIMPLIFIED VIEW (WCAG 3.1.5) === */
.simplified-view-active * {
    font-family: Arial, Helvetica, sans-serif !important;
    line-height: 1.8 !important;
    letter-spacing: 0.5px !important;
}

.simplified-view-active p {
    font-size: 1.1rem !important;
    max-width: 65ch !important;
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--v3-primary);
}

.simplified-view-active .hero-video,
.simplified-view-active .particles-canvas,
.simplified-view-active img:not([alt]),
.simplified-view-active .decorative-icon {
    display: none !important;
}

.simplified-view-active .reveal,
.simplified-view-active .reveal.active {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
}

.simplified-view-active h1,
.simplified-view-active h2,
.simplified-view-active h3 {
    text-transform: none !important;
    font-weight: 800 !important;
    border-bottom: 2px solid var(--v3-primary);
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem !important;
    display: inline-block;
}

.simplified-view-active .card,
.simplified-view-active .feature-card,
.simplified-view-active .service-card {
    border: 2px solid var(--text-main) !important;
    box-shadow: none !important;
    background: var(--bg-surface) !important;
    transform: none !important;
    transition: none !important;
}

.simplified-view-active footer {
    border-top: 4px solid var(--v3-primary) !important;
}