/**
 * Werkflow Accessibility CSS
 * WCAG 2.1 Level AA Compliance
 *
 * Diese Datei MUSS nach allen anderen CSS-Dateien geladen werden,
 * um problematische outline:none Styles zu überschreiben.
 *
 * Erstellt: 2025-12-01
 */

/* ==========================================================================
   1. FOCUS INDICATORS - Sichtbare Fokus-Indikatoren für alle interaktiven Elemente
   ========================================================================== */

/* Basis-Focus-Style für alle fokussierbaren Elemente */
*:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* Spezifische Focus-Styles für verschiedene Elemente */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.25) !important;
}

/* Focus für Buttons - noch deutlicher */
.btn:focus,
button:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.35) !important;
}

/* Focus für Form-Elemente */
.form-control:focus,
.form-select:focus {
    border-color: #0d6efd !important;
    outline: 0 !important;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25) !important;
}

/* Focus für Checkboxen und Radio-Buttons */
.form-check-input:focus {
    border-color: #0d6efd !important;
    outline: 0 !important;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25) !important;
}

/* Focus für Links in Navigation */
.nav-link:focus,
.navbar-nav .nav-link:focus {
    outline: 2px solid #fff !important;
    outline-offset: 2px !important;
    border-radius: 4px;
}

/* Focus für Dropdown-Items */
.dropdown-item:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: -2px !important;
    background-color: #e9ecef !important;
}

/* Focus für Cards (wenn klickbar) */
.card:focus,
.card[tabindex]:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* Focus für Modal-Elemente */
.modal-content:focus {
    outline: none !important; /* Modal selbst braucht keinen Fokus-Ring */
}

.modal .btn-close:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
}

/* ==========================================================================
   2. FOCUS-VISIBLE - Moderne Browser-Unterstützung
   ========================================================================== */

/* Focus-visible für Keyboard-Only Focus (moderne Browser) */
*:focus-visible {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* Verstecke Focus-Ring bei Maus-Klick (nur wenn focus-visible unterstützt wird) */
@supports selector(:focus-visible) {
    *:focus:not(:focus-visible) {
        outline: none !important;
        box-shadow: none !important;
    }

    /* Aber behalte Focus für Form-Elemente auch bei Maus */
    input:focus:not(:focus-visible),
    select:focus:not(:focus-visible),
    textarea:focus:not(:focus-visible) {
        border-color: #0d6efd !important;
        box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15) !important;
    }
}

/* ==========================================================================
   3. HIGH CONTRAST MODE - Unterstützung für Windows High Contrast
   ========================================================================== */

@media (forced-colors: active) {
    *:focus {
        outline: 3px solid CanvasText !important;
        outline-offset: 2px !important;
    }

    .btn:focus,
    button:focus {
        outline: 3px solid ButtonText !important;
    }
}

/* ==========================================================================
   4. LIBRARY OVERRIDES - Überschreibungen für Third-Party Libraries
   ========================================================================== */

/* DataTables */
.dataTables_wrapper *:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 1px !important;
}

table.dataTable tbody tr:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: -2px !important;
}

.dataTables_paginate .paginate_button:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* Select2 */
.select2-container--default .select2-selection:focus,
.select2-container--default .select2-selection--single:focus,
.select2-container--default .select2-selection--multiple:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 1px !important;
    border-color: #0d6efd !important;
}

.select2-container--default.select2-container--focus .select2-selection {
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25) !important;
}

.select2-results__option--highlighted,
.select2-results__option:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: -2px !important;
}

/* SweetAlert2 */
.swal2-popup:focus {
    outline: none !important; /* Popup selbst braucht keinen Ring */
}

.swal2-confirm:focus,
.swal2-cancel:focus,
.swal2-deny:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.35) !important;
}

.swal2-close:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* Bootstrap Icons (wenn als Buttons verwendet) */
.bi[tabindex]:focus,
i.bi:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* ==========================================================================
   5. SKIP-LINK STYLES (zentral, falls nicht in Layout)
   ========================================================================== */

.skip-link {
    position: absolute;
    top: -50px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 12px 24px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 0;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* ==========================================================================
   6. PLACEHOLDER CONTRAST - WCAG-konforme Placeholder-Farben
   ========================================================================== */

::placeholder {
    color: #767676 !important; /* WCAG: Minimum 4.5:1 auf weiß */
    opacity: 1 !important;
}

::-webkit-input-placeholder {
    color: #767676 !important;
    opacity: 1 !important;
}

::-moz-placeholder {
    color: #767676 !important;
    opacity: 1 !important;
}

:-ms-input-placeholder {
    color: #767676 !important;
}

::-ms-input-placeholder {
    color: #767676 !important;
}

/* ==========================================================================
   7. ERROR STATES - Zugängliche Fehlerzustände
   ========================================================================== */

/* Fehler nicht nur durch Farbe anzeigen */
.is-invalid,
.has-error input,
.has-error select,
.has-error textarea,
[aria-invalid="true"] {
    border-color: #dc3545 !important;
    border-width: 2px !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.75rem center !important;
    background-size: 1rem 1rem !important;
    padding-right: 2.5rem !important;
}

.is-invalid:focus,
[aria-invalid="true"]:focus {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.25) !important;
}

/* Error Messages */
.invalid-feedback,
.error-message,
[role="alert"] {
    color: #dc3545;
    font-weight: 500;
}

/* ==========================================================================
   7. REDUCED MOTION - Respektiere Benutzereinstellungen
   ========================================================================== */

@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;
    }

    .skip-link {
        transition: none !important;
    }
}

/* ==========================================================================
   8. TEXT SPACING - Unterstützung für Text-Spacing-Anpassungen (WCAG 1.4.12)
   ========================================================================== */

/* Container müssen flexibel sein für Text-Spacing-Anpassungen */
.card,
.modal-body,
.alert,
.form-group,
p,
li {
    overflow: visible;
    min-height: auto;
}

/* Keine fixed heights die Text abschneiden könnten */
.btn,
.nav-link,
.dropdown-item {
    height: auto;
    min-height: 44px; /* WCAG Touch Target Size */
    line-height: 1.5;
}

/* ==========================================================================
   9. WCAG CONTRAST FIXES - Bootstrap Badge/Alert Farben mit WCAG 2.1 AA Kontrast
   ========================================================================== */

/*
 * Bootstrap Standard-Farben mit schlechtem Kontrast:
 * - bg-info (#0dcaf0 auf #fff): 2.8:1 ❌ (Minimum: 4.5:1)
 * - bg-warning (#ffc107 auf #fff): 1.5:1 ❌ (Minimum: 4.5:1)
 *
 * Lösung: Dunklere Hintergrundfarben ODER dunkler Text
 */

/* --- bg-info: Dunklere Variante für besseren Kontrast --- */
/* Original: #0dcaf0 auf #fff = 2.8:1 ❌ */
/* #0891b2 (Cyan-600) = 3.68:1 ❌ (WAVE-Test fehlgeschlagen) */
/* Fix: #0e7490 (Cyan-700) auf #fff = 4.54:1 ✅ */
.bg-info {
    background-color: #0e7490 !important; /* Cyan-700: 4.54:1 Kontrast */
}

/* Badge-spezifisch */
.badge.bg-info {
    background-color: #0e7490 !important;
    color: #fff !important;
}

/* --- bg-warning: Dunkler Text für besseren Kontrast --- */
/* Original: #ffc107 auf #fff mit weißem Text = 1.5:1 */
/* Fix: #ffc107 mit schwarzem Text = 19.6:1 ✅ */
.bg-warning {
    background-color: #ffc107 !important;
    color: #212529 !important; /* Dunkler Text statt weiß */
}

.bg-warning.text-white {
    color: #212529 !important; /* Override .text-white */
}

.badge.bg-warning {
    background-color: #ffc107 !important;
    color: #212529 !important;
}

/* Karten mit bg-warning */
.card.bg-warning,
.card.bg-warning .card-body,
.card.bg-warning .card-title,
.card.bg-warning h1,
.card.bg-warning h2,
.card.bg-warning h3,
.card.bg-warning h4,
.card.bg-warning h5,
.card.bg-warning h6,
.card.bg-warning small {
    color: #212529 !important;
}

/* --- Alerts mit besseren Kontrast-Farben --- */
/* Alert-info */
.alert-info {
    background-color: #cff4fc !important;
    border-color: #0e7490 !important; /* Cyan-700 */
    color: #055160 !important; /* Dunkelcyan für Text: 7.5:1 ✅ */
}

/* Alert-warning */
.alert-warning {
    background-color: #fff3cd !important;
    border-color: #ffca2c !important;
    color: #664d03 !important; /* Dunkelbraun für Text: 7.0:1 ✅ */
}

/* --- Status-Badges für Housing-Modul --- */
/* Verschiedene Status mit optimierten Kontrast-Farben */

/* Status: Zugewiesen (Blau) */
.badge-status-assigned,
.badge[data-status="assigned"] {
    background-color: #0d6efd !important;
    color: #fff !important;
}

/* Status: Anerkannt (Grün) */
.badge-status-recognized,
.badge[data-status="recognized"] {
    background-color: #198754 !important;
    color: #fff !important;
}

/* Status: Eigenes Mietverhältnis (Teal) */
.badge-status-private-rental,
.badge[data-status="private_rental"] {
    background-color: #0e7490 !important; /* Cyan-700: 4.54:1 */
    color: #fff !important;
}

/* Status: Freiwillige Ausreise (Gelb mit dunklem Text) */
.badge-status-voluntary-departure,
.badge[data-status="voluntary_departure"] {
    background-color: #ffc107 !important;
    color: #212529 !important;
}

/* Status: Untergetaucht (Orange) */
.badge-status-absconded,
.badge[data-status="absconded"] {
    background-color: #fd7e14 !important;
    color: #212529 !important;
}

/* Status: Abgeschoben (Rot) */
.badge-status-deported,
.badge[data-status="deported"] {
    background-color: #dc3545 !important;
    color: #fff !important;
}

/* Status: Umverteilt (Lila) */
.badge-status-redistributed,
.badge[data-status="redistributed"] {
    background-color: #6f42c1 !important;
    color: #fff !important;
}

/* ==========================================================================
   10. TOUCH TARGETS - Mindestgröße für Touch (WCAG 2.5.5)
   ========================================================================== */

/* Mindestens 44x44px für Touch-Targets */
a,
button,
input[type="checkbox"],
input[type="radio"],
.btn,
.nav-link,
.dropdown-item,
.page-link {
    min-height: 44px;
    min-width: 44px;
}

/* Kleine Buttons trotzdem nutzbar */
.btn-sm {
    min-height: 38px;
    padding: 0.375rem 0.75rem;
}

/* Icon-Only Buttons */
.btn-icon,
button[aria-label]:not([aria-label=""]) {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   12. MOBILE / TABLET RESPONSIVE - Globale Verbesserungen
   ========================================================================== */

/* iOS Zoom Prevention - Inputs unter 16px loesen auf iOS Auto-Zoom aus */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    textarea,
    select,
    .form-control,
    .form-select {
        font-size: 16px !important;
    }
}

/* Modal-Body Scroll auf Mobile */
@media (max-width: 576px) {
    .modal-body {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Kompaktere Modals auf sehr kleinen Bildschirmen */
    .modal-header {
        padding: 0.75rem 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
    }
}

/* Touch-Optimierung fuer alle Module */
@media (hover: none) and (pointer: coarse) {
    /* Groessere Touch-Targets in Tabellen-Aktionen */
    .btn-group-sm .btn,
    .btn-group .btn-sm {
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 0.75rem;
    }

    /* Dropdown-Items groesser fuer Touch */
    .dropdown-item {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }

    /* Groessere Pagination-Links */
    .page-link {
        padding: 0.625rem 0.875rem;
    }

    /* Nav-Links in collapsed Navbar */
    .navbar-collapse .nav-link {
        padding: 0.75rem 1rem;
    }

    /* Form-Select groesser */
    .form-select,
    .form-control {
        min-height: 44px;
    }

    /* Callbacks-Dropdown auf Mobile volle Breite */
    .callbacks-dropdown {
        min-width: auto !important;
        width: calc(100vw - 20px) !important;
        max-width: 400px;
    }

    /* Liste-Gruppen Items Touch-freundlich */
    .list-group-item {
        padding: 0.75rem 1rem;
    }

    /* Quick-Link Items */
    .quick-link-item {
        min-height: 48px;
    }
}

/* ==========================================================================
   13. PRINT STYLES - Globale Druckoptimierung
   ========================================================================== */

@media print {
    /* Navigation und UI-Elemente ausblenden */
    .navbar,
    .breadcrumb,
    .pagination,
    .btn:not(.btn-link),
    footer,
    .skip-link,
    .offcanvas,
    .modal-backdrop,
    .toast-container {
        display: none !important;
    }

    /* Weisser Hintergrund */
    body {
        background: white !important;
        color: #000 !important;
        font-size: 12pt !important;
    }

    /* Kein Padding */
    .content-container {
        padding: 0 !important;
    }

    /* Cards ohne Schatten */
    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        break-inside: avoid;
    }

    /* Links mit URL anzeigen */
    a[href]:not(.btn)::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    /* Interne Links ohne URL */
    a[href^="#"]::after,
    a[href^="javascript"]::after,
    .nav-link::after,
    .navbar-brand::after,
    .dropdown-item::after,
    .breadcrumb-item a::after {
        content: none !important;
    }

    /* Stat-Cards lesbar drucken */
    .stat-card {
        background: white !important;
        color: #212529 !important;
        border: 1px solid #ccc !important;
    }
}

/* ==========================================================================
   11. CUSTOM CHECKBOXEN - Minimalistisch (Blauer Rahmen + Haken)
   ========================================================================== */

/* Standard Bootstrap Checkboxen überschreiben - GLOBAL! */
.form-check-input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1.1em;
    height: 1.1em;
    border: 1.5px solid #adb5bd;
    border-radius: 3px;
    background-color: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
    flex-shrink: 0;
    margin-top: 0;
}

/* Vertikale Zentrierung */
.form-check {
    display: flex;
    align-items: center;
}

/* Hover-Effekt */
.form-check-input[type="checkbox"]:hover:not(:disabled) {
    border-color: #0d6efd;
}

/* Focus-Effekt (WCAG!) */
.form-check-input[type="checkbox"]:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 1px !important;
    border-color: #0d6efd;
}

/* Checked-State - Nur blauer Rahmen, kein Hintergrund */
.form-check-input[type="checkbox"]:checked {
    background-color: transparent;
    border-color: #0d6efd;
    border-width: 2px;
}

/* Blauer Haken */
.form-check-input[type="checkbox"]:checked::after {
    content: '\2713';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -52%);
    color: #0d6efd;
    font-size: 0.85em;
    font-weight: bold;
    line-height: 1;
}

/* Disabled-State */
.form-check-input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f8f9fa;
}

.form-check-input[type="checkbox"]:disabled ~ .form-check-label {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Label */
.form-check-label {
    cursor: pointer;
    user-select: none;
    padding-left: 0.35rem;
}

/* Icon neben Label */
.form-check-label i {
    color: #6c757d;
    margin-right: 0.25rem;
}
