/* ============================================
   MagicMenu Accessibility Styles
   ============================================
   WCAG 2.1 AA Compliance
   ============================================
   Colours come from the Larder tokens in style.css (--mm-*), so the focus ring
   and the semantic states read the same in light and dark. This file loads
   last; anything hard-coded here would win over the design system, which is
   how #595959 muted text once failed contrast across the whole dark site. */

/* Focus Indicators: 3px ink ring, offset so it sits on the ground. */
:focus {
    outline: 3px solid var(--mm-focus, #1e1b16);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--mm-focus, #1e1b16);
    outline-offset: 2px;
}

/* Form controls keep the same ring; no glow. */
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--mm-ink, #1e1b16);
    box-shadow: none;
    outline: 3px solid var(--mm-focus, #1e1b16);
    outline-offset: 2px;
}

/* Button focus states */
.btn:focus-visible {
    outline: 3px solid var(--mm-focus, #1e1b16);
    outline-offset: 2px;
    box-shadow: none;
}

/* 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: var(--mm-ink, #1e1b16);
    color: var(--mm-paper, #f6f1e7);
    text-decoration: none;
    border-radius: 2px;
    font-weight: 600;
    z-index: 999999;
    top: 0.5rem;
    left: 0.5rem;
    outline-color: var(--mm-oxblood, #7a2e2a);
}

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

    .card {
        border-width: 2px;
    }

    .form-control,
    .form-select {
        border-width: 2px;
    }

    :focus-visible {
        outline-width: 4px;
    }
}

/* 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;
    }
}

/* Colour contrast: muted text is ink-muted (5.2:1 on paper, 7.3:1 on the dark
   ground), in both modes. */
.text-muted {
    color: var(--mm-ink-muted, #6b6350) !important;
}

.bg-light {
    background-color: var(--mm-paper-2, #ede6d7) !important;
    color: var(--mm-ink, #1e1b16) !important;
}

/* Links: oxblood, underlined. */
a {
    color: var(--mm-accent-text, #7a2e2a);
    text-decoration: underline;
}

a:hover,
a:focus {
    color: var(--mm-oxblood-hover, #591f1c);
    text-decoration: underline;
}

/* Form validation states: the reserved error colour, ink for valid. */
.is-invalid {
    border-color: var(--mm-error, #c4381b);
}

.invalid-feedback {
    color: var(--mm-error-text, #c4381b);
    background-color: transparent;
    padding: 0.25rem 0;
    border-radius: 0;
    margin-top: 0.25rem;
    font-weight: 600;
}

.is-valid {
    border-color: var(--mm-ink, #1e1b16);
}

.valid-feedback {
    color: var(--mm-ink, #1e1b16);
    background-color: transparent;
    padding: 0.25rem 0;
    border-radius: 0;
    margin-top: 0.25rem;
    font-weight: 600;
}

/* 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;
}

/* Close buttons (modal/offcanvas headers, dismissible alerts) need a 44px tap
   target too (MM-286). The X icon keeps its natural size via background-size; only
   the clickable box grows, centred on the glyph. */
.btn-close {
    min-width: 44px;
    min-height: 44px;
    background-position: center;
}

/* The navbar hamburger is not a .btn, so the rule above never covered it and it
   rendered 56x40 — the one control every mobile visitor has to hit to reach the
   nav, 4px under the WCAG 2.5.5 target this project holds itself to. */
.navbar-toggler {
    min-height: 44px;
    min-width: 44px;
}

/* Better spacing for clickable elements */
.shopping-item {
    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: var(--mm-paper-2, #ede6d7);
}

/* Keyboard navigation indicators */
.nav-link:focus-visible,
.dropdown-item:focus-visible,
.dropdown-menu .dropdown-item:focus-visible {
    background-color: var(--mm-paper-2, #ede6d7);
    outline: 3px solid var(--mm-focus, #1e1b16);
    outline-offset: -3px;
}

/* Collapsible section button focus */
.section-header:focus-visible {
    outline: 3px solid var(--mm-focus, #1e1b16);
    outline-offset: 2px;
    background-color: var(--mm-paper-2, #ede6d7);
}

/* Semantic alerts: paper-2 ground, a 2px rule on top; only danger uses the
   reserved error colour. Text stays ink so every alert clears 4.5:1. */
.alert-danger {
    background-color: var(--mm-paper-2, #ede6d7);
    border-color: var(--mm-error, #c4381b);
    color: var(--mm-ink, #1e1b16);
}

.alert-warning,
.alert-success,
.alert-info {
    background-color: var(--mm-paper-2, #ede6d7);
    border-color: var(--mm-ink, #1e1b16);
    color: var(--mm-ink, #1e1b16);
}

/* Heading hierarchy stays visually apparent. Cormorant Garamond carries h1 and
   h2 (both at or above the 28px serif floor); h3 down are Source Sans 3. */
h1 { font-size: 2rem; font-weight: 500; }
h2 { font-size: 1.75rem; font-weight: 500; }
h3 { font-size: 1.5rem; font-weight: 600; }
h4 { font-size: 1.25rem; font-weight: 600; }
h5 { font-size: 1.125rem; font-weight: 600; }
h6 { font-size: 1rem; font-weight: 600; }

/* 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: transparent;
    font-weight: 700;
    text-align: left;
    padding: 0.75rem;
}

td {
    padding: 0.75rem;
    border-top: 1px solid var(--mm-hairline, #c9bda6);
}

/* Ensure images have proper alt text styling when missing */
img:not([alt]) {
    outline: 3px solid var(--mm-error, #c4381b);
}

/* 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: var(--mm-paper, #f6f1e7);
}

/* Dark mode: everything above already reads the inverted tokens, so the only
   remaining job is Bootstrap's fixed greys. */
@media (prefers-color-scheme: dark) {
    :root {
        --bs-body-bg: var(--mm-paper);
        --bs-body-color: var(--mm-ink);
        --bs-border-color: var(--mm-hairline);
    }

    .card {
        background-color: var(--mm-paper);
        color: var(--mm-ink);
    }

    .text-secondary {
        color: var(--mm-ink-soft) !important;
    }

    .form-control,
    .form-select {
        background-color: var(--mm-paper);
        color: var(--mm-ink);
        border-color: var(--mm-ink);
    }

    th {
        background-color: transparent;
        color: var(--mm-ink);
    }

    td {
        border-top-color: var(--mm-hairline);
    }
}
