/* ═══════════════════════════════════════════════════════════════════════════
   IHK LERNAPP PRO - ACCESSIBILITY SYSTEM v2.27.0
   App-uebergreifende Barrierefreiheit mit modernem UI

   Entry Point: FAB (Floating Action Button)
   UI Pattern: Bottom Sheet Drawer
   WCAG 2.1 AA konform
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────────
   FAB (Floating Action Button)
   Material Design 3 inspiriert, 56x56px Touch Target
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-fab {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, #06B6D4, #3B82F6);
    border: none;
    color: white;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a11y-fab:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(6, 182, 212, 0.5);
}

.a11y-fab:active {
    transform: translateY(-1px) scale(1.02);
}

.a11y-fab:focus-visible {
    outline: 3px solid var(--accent-cyan, #06B6D4);
    outline-offset: 3px;
}

.a11y-fab svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* FAB Tooltip */
.a11y-fab::before {
    content: "Darstellung anpassen";
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 12px;
    padding: 6px 12px;
    background: var(--bg-card, #334155);
    color: var(--text-primary, #f8fafc);
    font-size: 0.85rem;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.a11y-fab:hover::before {
    opacity: 1;
    visibility: visible;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Backdrop (Overlay hinter Bottom Sheet)
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
}

.a11y-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Bottom Sheet Drawer
   Slide-up von unten, mobil-freundlich
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card, #334155);
    border-radius: 24px 24px 0 0;
    padding: var(--space-md, 1rem) var(--space-lg, 1.5rem) var(--space-xl, 2rem);
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
    pointer-events: none;  /* v3.6.3: Verhindert Klicks wenn versteckt */
}

.a11y-drawer.open {
    transform: translateY(0);
    pointer-events: auto;  /* v3.6.3: Erlaubt Klicks wenn offen */
}

/* Drag Handle */
.a11y-handle {
    width: 40px;
    height: 4px;
    background: var(--border-color, #475569);
    border-radius: 2px;
    margin: 0 auto var(--space-lg, 1.5rem);
}

/* Drawer Title */
.a11y-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary, #f8fafc);
    margin-bottom: var(--space-lg, 1.5rem);
    text-align: center;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Settings Sections
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-section {
    margin-bottom: var(--space-lg, 1.5rem);
    padding-bottom: var(--space-lg, 1.5rem);
    border-bottom: 1px solid var(--border-color, #475569);
}

.a11y-section:last-of-type {
    border-bottom: none;
    margin-bottom: var(--space-md, 1rem);
}

.a11y-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm, 0.5rem);
    margin-bottom: var(--space-md, 1rem);
    color: var(--text-secondary, #94a3b8);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.a11y-section-header svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Font Size Buttons (A A A)
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-font-options {
    display: flex;
    gap: var(--space-sm, 0.5rem);
    margin-bottom: var(--space-sm, 0.5rem);
}

.a11y-font-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-md, 1rem) var(--space-sm, 0.5rem);
    background: var(--bg-secondary, #1e293b);
    border: 2px solid var(--border-color, #475569);
    border-radius: var(--radius-md, 12px);
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-font-btn:hover {
    border-color: var(--accent-cyan, #06b6d4);
    color: var(--text-primary, #f8fafc);
}

.a11y-font-btn.active {
    border-color: var(--accent-cyan, #06b6d4);
    background: rgba(6, 182, 212, 0.15);
    color: var(--accent-cyan, #06b6d4);
}

.a11y-font-btn .font-preview {
    font-weight: 700;
    margin-bottom: 4px;
}

.a11y-font-btn .font-preview.small { font-size: 1rem; }
.a11y-font-btn .font-preview.medium { font-size: 1.25rem; }
.a11y-font-btn .font-preview.large { font-size: 1.5rem; }

.a11y-font-btn .font-label {
    font-size: 0.75rem;
}

/* Live Preview Text */
.a11y-preview {
    padding: var(--space-sm, 0.5rem) var(--space-md, 1rem);
    background: var(--bg-secondary, #1e293b);
    border-radius: var(--radius-sm, 6px);
    color: var(--text-secondary, #94a3b8);
    font-size: 0.9rem;
    text-align: center;
    transition: font-size 0.2s ease;
}

.a11y-preview.preview-large {
    font-size: 1.1rem;
}

.a11y-preview.preview-xlarge {
    font-size: 1.3rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Toggle Rows (Kontrast, Fokus)
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm, 0.5rem) 0;
}

.a11y-toggle-info {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md, 1rem);
}

.a11y-toggle-info svg {
    width: 24px;
    height: 24px;
    fill: var(--accent-cyan, #06b6d4);
    flex-shrink: 0;
    margin-top: 2px;
}

.a11y-toggle-label {
    display: block;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary, #f8fafc);
    margin-bottom: 2px;
}

.a11y-toggle-desc {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted, #64748b);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Toggle Switch
   iOS-inspired Toggle
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-switch {
    position: relative;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

.a11y-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.a11y-switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-secondary, #1e293b);
    border: 2px solid var(--border-color, #475569);
    border-radius: 14px;
    transition: all 0.25s ease;
}

.a11y-switch-slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.a11y-switch input:checked + .a11y-switch-slider {
    background: var(--accent-cyan, #06b6d4);
    border-color: var(--accent-cyan, #06b6d4);
}

.a11y-switch input:checked + .a11y-switch-slider::before {
    transform: translateX(24px);
}

.a11y-switch input:focus-visible + .a11y-switch-slider {
    outline: 3px solid rgba(6, 182, 212, 0.5);
    outline-offset: 2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Action Buttons
   ───────────────────────────────────────────────────────────────────────────── */

.a11y-actions {
    display: flex;
    gap: var(--space-sm, 0.5rem);
    margin-top: var(--space-lg, 1.5rem);
}

.a11y-actions .btn {
    flex: 1;
    padding: var(--space-md, 1rem);
    font-size: 1rem;
}

.a11y-btn-reset {
    background: var(--bg-secondary, #1e293b);
    border: 1px solid var(--border-color, #475569);
    color: var(--text-secondary, #94a3b8);
    border-radius: var(--radius-md, 12px);
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-btn-reset:hover {
    background: var(--bg-hover, #475569);
    color: var(--text-primary, #f8fafc);
}

.a11y-btn-done {
    background: linear-gradient(135deg, #06B6D4, #3B82F6);
    border: none;
    color: white;
    border-radius: var(--radius-md, 12px);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.a11y-btn-done:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
}

/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY MODES
   Werden auf :root (html) angewendet
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────────
   Font Size Classes
   ───────────────────────────────────────────────────────────────────────────── */

:root {
    --base-font-size: 16px;
}

html.font-normal { --base-font-size: 16px; }
html.font-large { --base-font-size: 20px; }
html.font-xlarge { --base-font-size: 24px; }

html.font-large body,
html.font-xlarge body {
    font-size: var(--base-font-size);
}

/* Skaliere relative Elemente */
html.font-large .card-question,
html.font-large .flashcard p,
html.font-large .message-content {
    font-size: 1.15rem;
}

html.font-xlarge .card-question,
html.font-xlarge .flashcard p,
html.font-xlarge .message-content {
    font-size: 1.35rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   High Contrast Mode
   WCAG AAA Kontrast (7:1)
   ───────────────────────────────────────────────────────────────────────────── */

html.high-contrast {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-card: #1a1a1a;
    --bg-input: #0a0a0a;
    --bg-hover: #2a2a2a;

    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-muted: #b0b0b0;

    --border-color: #606060;
    --border-light: #404040;
}

html.high-contrast .card,
html.high-contrast .flashcard,
html.high-contrast .modal-content,
html.high-contrast .a11y-drawer {
    border: 2px solid var(--border-color);
}

html.high-contrast .btn-primary,
html.high-contrast .btn-success {
    border: 2px solid white;
}

html.high-contrast a {
    text-decoration: underline;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Enhanced Focus Mode
   Deutlichere Fokus-Anzeige fuer Keyboard-Navigation
   ───────────────────────────────────────────────────────────────────────────── */

html.focus-enhanced *:focus {
    outline: none !important;
}

html.focus-enhanced *:focus-visible {
    outline: 4px solid var(--accent-cyan, #06b6d4) !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 8px rgba(6, 182, 212, 0.2) !important;
}

html.focus-enhanced button:focus-visible,
html.focus-enhanced a:focus-visible,
html.focus-enhanced input:focus-visible,
html.focus-enhanced select:focus-visible,
html.focus-enhanced textarea:focus-visible {
    outline: 4px solid var(--accent-cyan, #06b6d4) !important;
    outline-offset: 4px !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   Respektiert System-Einstellung fuer reduzierte Bewegung
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    .a11y-fab,
    .a11y-drawer,
    .a11y-backdrop,
    .a11y-switch-slider,
    .a11y-switch-slider::before,
    .a11y-font-btn {
        transition: none !important;
    }

    .a11y-fab:hover {
        transform: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   Mobile-optimierte Anpassungen
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .a11y-fab {
        bottom: 70px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .a11y-fab svg {
        width: 24px;
        height: 24px;
    }

    .a11y-fab::before {
        display: none; /* Kein Tooltip auf Mobile */
    }

    .a11y-drawer {
        padding: var(--space-md, 1rem);
        max-height: 90vh;
    }

    .a11y-font-options {
        flex-direction: column;
    }

    .a11y-font-btn {
        flex-direction: row;
        justify-content: flex-start;
        gap: var(--space-md, 1rem);
        padding: var(--space-md, 1rem);
    }

    .a11y-font-btn .font-preview {
        margin-bottom: 0;
    }

    .a11y-actions {
        flex-direction: column;
    }
}

/* Desktop: Bottom Sheet als zentriertes Modal */
@media (min-width: 768px) {
    .a11y-drawer {
        left: 50%;
        right: auto;
        bottom: 50%;
        transform: translate(-50%, 50%) scale(0.95);
        opacity: 0;
        max-width: 440px;
        width: 90%;
        border-radius: 24px;
        max-height: 80vh;
    }

    .a11y-drawer.open {
        transform: translate(-50%, 50%) scale(1);
        opacity: 1;
    }
}
