/* ============================================
   MagicMenu Accessibility Styles
   ============================================
   WCAG 2.1 AA Compliance
   ============================================ */

/* Focus Indicators */
:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* Better focus for form controls */
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: #0066cc;
    box-shadow: 0 0 0 0.25rem rgba(0, 102, 204, 0.25);
    outline: none;
}

/* Button focus states */
.btn:focus,
.btn:focus-visible {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 0.25rem rgba(0, 102, 204, 0.25);
}

/* Skip links */
.visually-hidden-focusable:focus,
.visually-hidden-focusable:focus-within {
    position: absolute !important;
    width: auto !important;
    height: auto !important;
    padding: 0.75rem 1.25rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    background-color: #0066cc;
    color: #fff;
    text-decoration: none;
    border-radius: 0.25rem;
    z-index: 999999;
    top: 0.5rem;
    left: 0.5rem;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
    
    .card {
        border-width: 2px;
    }
    
    .form-control,
    .form-select {
        border-width: 2px;
    }
}

/* Reduced motion support */
@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;
    }
    
    .collapse {
        transition: none;
    }
    
    .fade {
        transition: none;
    }
}

/* Color contrast improvements */
.text-muted {
    color: #595959 !important; /* WCAG AA compliant on white background */
}

.bg-light {
    background-color: #f8f9fa !important;
    color: #212529 !important;
}

/* Ensure links meet contrast requirements */
a {
    color: #0056b3;
    text-decoration: underline;
}

a:hover,
a:focus {
    color: #004085;
    text-decoration: underline;
}

/* Form validation states with better contrast */
.is-invalid {
    border-color: #dc3545;
}

.invalid-feedback {
    color: #721c24;
    background-color: #f8d7da;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    margin-top: 0.25rem;
}

.is-valid {
    border-color: #28a745;
}

.valid-feedback {
    color: #155724;
    background-color: #d4edda;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    margin-top: 0.25rem;
}

/* Improved touch targets */
.btn,
.form-control,
.form-select,
.nav-link {
    min-height: 44px;
    min-width: 44px;
}

/* Checkboxes/radios: size the input normally, rely on label for touch target */
.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
}

/* Form switch toggles need their natural pill shape (wider than tall) */
.form-switch .form-check-input {
    width: 2em;
    height: 1em;
    min-height: auto;
    min-width: auto;
}

/* Ensure form-check labels meet touch target size instead */
.form-check-label {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

/* Better spacing for clickable elements */
.shopping-item,
.meal-card {
    min-height: 48px;
    padding: 0.75rem;
}

/* Screen reader only text */
.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;
}

/* Ensure interactive elements are distinguishable */
.btn-link {
    text-decoration: underline;
}

.btn-link:hover,
.btn-link:focus {
    text-decoration: none;
    background-color: rgba(0, 0, 0, 0.05);
}

/* Keyboard navigation indicators */
.nav-link:focus,
.dropdown-item:focus {
    background-color: #e9ecef;
    outline: 2px solid #0066cc;
    outline-offset: -2px;
}

/* Dropdown menu focus improvements */
.dropdown-menu .dropdown-item:focus,
.dropdown-menu .dropdown-item:focus-visible {
    background-color: #e9ecef;
    outline: 2px solid #0066cc;
    outline-offset: -2px;
}

/* Collapsible section button focus */
.section-header:focus,
.section-header:focus-visible {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
    background-color: #e9ecef;
}

/* Error and warning colors with sufficient contrast */
.alert-danger {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background-color: #fff3cd;
    border-color: #ffeeba;
    color: #856404;
}

.alert-success {
    background-color: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.alert-info {
    background-color: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}

/* Ensure proper heading hierarchy is visually apparent */
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.75rem; font-weight: 600; }
h3 { font-size: 1.5rem; font-weight: 600; }
h4 { font-size: 1.25rem; font-weight: 500; }
h5 { font-size: 1.125rem; font-weight: 500; }
h6 { font-size: 1rem; font-weight: 500; }

/* Loading states with aria-live regions */
.htmx-request .htmx-indicator {
    opacity: 1;
}

.htmx-indicator::after {
    content: " Loading...";
    font-weight: normal;
    font-style: italic;
}

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

th {
    background-color: #f8f9fa;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
}

td {
    padding: 0.75rem;
    border-top: 1px solid #dee2e6;
}

/* Ensure images have proper alt text styling when missing */
img:not([alt]) {
    outline: 3px solid #dc3545;
}

/* Custom checkbox styling with accessibility */
.item-checkbox {
    position: relative;
    cursor: pointer;
}

.item-checkbox:checked::after {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1rem;
    font-weight: bold;
    color: #28a745;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bs-body-bg: #212529;
        --bs-body-color: #f8f9fa;
        --bs-border-color: #495057;
    }
    
    .card {
        background-color: #343a40;
        color: #f8f9fa;
    }
    
    .form-control,
    .form-select {
        background-color: #495057;
        color: #f8f9fa;
        border-color: #6c757d;
    }

    /* Focus state backgrounds */
    .nav-link:focus,
    .dropdown-item:focus,
    .dropdown-menu .dropdown-item:focus,
    .dropdown-menu .dropdown-item:focus-visible {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .section-header:focus,
    .section-header:focus-visible {
        background-color: rgba(255, 255, 255, 0.1);
    }

    /* Table headers */
    th {
        background-color: var(--card-bg, #2d2a28);
        color: var(--text-color, #faf6f1);
    }

    td {
        border-top-color: var(--border-color, #3d3a37);
    }

    /* Alert overrides for dark mode */
    .alert-danger {
        background-color: rgba(220, 53, 69, 0.15);
        border-color: rgba(220, 53, 69, 0.3);
        color: #f8a4ad;
    }

    .alert-warning {
        background-color: rgba(255, 193, 7, 0.15);
        border-color: rgba(255, 193, 7, 0.3);
        color: #ffe082;
    }

    .alert-success {
        background-color: rgba(40, 167, 69, 0.15);
        border-color: rgba(40, 167, 69, 0.3);
        color: #8ecc95;
    }

    .alert-info {
        background-color: rgba(23, 162, 184, 0.15);
        border-color: rgba(23, 162, 184, 0.3);
        color: #7ecadb;
    }
}