/**
 * Progressive Enhancement Styles
 *
 * Ensures core functionality is accessible without JavaScript
 * and provides graceful degradation for older browsers.
 *
 * CSS Audit (Feb 2026): KEEP — legitimate infrastructure CSS.
 * Actively used sections:
 *   - .no-js / .js class toggling (base.html sets class="no-js", JS swaps to .js)
 *   - @media (prefers-reduced-motion: reduce) — accessibility
 *   - @media (prefers-contrast: high) — accessibility
 *   - @media print — print styles
 *   - :focus-visible styles — keyboard navigation accessibility
 *   - .sr-only, .visually-hidden — used in 16 templates
 * Dead sections (targets non-existent elements):
 *   - .no-js .mobile-nav-toggle, .no-js .sidebar (elements not in templates)
 *   - .no-js .invalid-feedback-modern (class not used)
 *   - .no-js .keyboard-hint, .no-js [data-keyboard-shortcut]
 *   - .skip-to-content (not in any template)
 *   - .sr-only-focusable, .visually-hidden-focusable (not used)
 */

/* ===========================================
   No-JS Fallback Styles
   =========================================== */

/* Hide JS-only elements when JS is disabled */
.no-js .js-only {
    display: none !important;
}

/* Show no-JS fallback elements only when JS is disabled */
.js .no-js-only {
    display: none !important;
}

/* Default: hide no-js elements (JS will add .js class to html) */
.no-js-only {
    display: block;
}

/* ===========================================
   No-JS Navigation Fallback
   =========================================== */

/* Show navigation links in a basic layout without JS */
.no-js .mobile-nav-toggle {
    display: none !important;
}

.no-js .sidebar {
    position: static !important;
    transform: none !important;
    width: auto !important;
}

.no-js .sidebar-backdrop {
    display: none !important;
}

/* ===========================================
   No-JS Form Fallbacks
   =========================================== */

/* Basic form styling without JS validation */
.no-js .invalid-feedback-modern {
    display: none;
}

.no-js input:invalid,
.no-js select:invalid,
.no-js textarea:invalid {
    border-color: var(--ds-color-error);
}

.no-js input:valid,
.no-js select:valid,
.no-js textarea:valid {
    border-color: var(--ds-color-success);
}

/* ===========================================
   No-JS Loading States
   =========================================== */

/* Hide JS-based loading spinners */
.no-js .loading-overlay,
.no-js .element-loading-overlay,
.no-js .skeleton-loader {
    display: none !important;
}

/* Show content immediately without loading states */
.no-js [data-loading] {
    display: block !important;
}

/* ===========================================
   No-JS Interactive Elements
   =========================================== */

/* Command palette won't work without JS - hide trigger hints */
.no-js .keyboard-hint,
.no-js [data-keyboard-shortcut] {
    display: none !important;
}

/* Tooltips fallback to title attribute */
.no-js [data-bs-toggle="tooltip"] {
    cursor: help;
}

/* ===========================================
   No-JS Toast/Notification Fallbacks
   =========================================== */

.no-js .toast-container {
    display: none !important;
}

/* Flash messages should be visible */
.no-js .alert {
    display: block !important;
}

/* ===========================================
   Reduced Motion Preferences
   =========================================== */

@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;
    }

    .skeleton-line {
        animation: none !important;
    }

    .progress-bar-animated {
        animation: none !important;
    }

    .spinner,
    .spinner-border {
        animation: none !important;
    }
}

/* ===========================================
   High Contrast Mode
   =========================================== */

@media (prefers-contrast: high) {
    .btn,
    .badge,
    .alert {
        border-width: 2px !important;
    }

    a {
        text-decoration: underline !important;
    }

    .text-muted {
        color: inherit !important;
        opacity: 0.8;
    }
}

/* ===========================================
   Print Styles
   =========================================== */

@media print {
    /* Hide interactive elements */
    .sidebar,
    .mobile-nav-toggle,
    .toast-container,
    .loading-overlay,
    .command-palette-overlay,
    .btn-group,
    button:not(.print-visible),
    .no-print {
        display: none !important;
    }

    /* Ensure content is visible */
    body {
        background: white !important;
        color: black !important;
    }

    a {
        text-decoration: underline;
        color: black !important;
    }

    /* Show URLs after links */
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: var(--ds-color-text-tertiary);
    }

    /* Avoid page breaks inside important elements */
    .card,
    .table,
    .list-group {
        break-inside: avoid;
    }
}

/* ===========================================
   Focus Visible Styles
   =========================================== */

/* Enhanced focus styles for keyboard navigation */
:focus-visible {
    outline: 3px solid var(--ds-color-accent);
    outline-offset: 2px;
}

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

/* ===========================================
   Skip to Content Link
   =========================================== */

.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--ds-color-accent);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.3s;
}

.skip-to-content:focus {
    top: 0;
}

/* ===========================================
   Screen Reader Only
   =========================================== */

.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,
.visually-hidden-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: inherit !important;
    margin: inherit !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}
