/* =============================================================
   Accessibility layer, loaded last by every layout (after page
   styles) so these rules win:
   - reduced motion: no animations or transitions anywhere;
   - one visible focus ring on every interactive element, even
     where a component removed its outline;
   - footer landmark, language switcher and voice input styles.
   ============================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[role="menuitem"]:focus-visible,
[contenteditable="true"]:focus-visible {
    outline: 3px solid var(--accent-hover, #1d4ed8) !important;
    outline-offset: 2px !important;
}

/* Visually hidden inputs (custom radios and checkboxes) show focus on their visible label instead. */
input.visually-hidden:focus-visible + label {
    outline: 3px solid var(--accent-hover, #1d4ed8);
    outline-offset: 2px;
}

/* The main region takes focus from the skip link; it is not a control, so no ring. */
main[tabindex="-1"]:focus,
main[tabindex="-1"]:focus-visible {
    outline: none !important;
}

/* ---- Footer landmark ---------------------------------------- */

.app-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: auto;
    padding: 16px 24px;
    border-top: 1px solid var(--line, #e5e7eb);
    color: var(--muted, #4b5563);
    font-size: .875rem;
}

.app-footer p {
    margin: 0;
}

.app-footer-voice {
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid var(--line, #d1d5db);
    border-radius: 8px;
    background: var(--surface, #fff);
    color: var(--ink, #111827);
}

/* ---- Language switcher ----------------------------------- */

.language-switcher {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.language-switcher-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: var(--ink, #111827);
    font-weight: 500;
}

.language-switcher-icon {
    width: 18px;
    height: 18px;
}

.language-switcher-select,
.language-switcher-button {
    min-height: 44px;
    padding: 6px 10px;
    border: 1px solid var(--line, #d1d5db);
    border-radius: 8px;
    background: var(--surface, #fff);
    color: var(--ink, #111827);
}

.language-switcher-notice {
    flex-basis: 100%;
    margin: 0;
    font-size: .875rem;
}

.auth-language-bar {
    position: absolute;
    z-index: 5;
    top: 12px;
    right: 16px;
    padding: 6px 8px;
    border-radius: 10px;
    background: var(--surface, #fff);
}

@media (max-width: 767.98px) {
    .auth-language-bar {
        position: static;
        display: flex;
        flex-basis: 100%;
        justify-content: flex-end;
    }

    .top-actions .language-switcher-label span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
}

/* ---- Voice input ----------------------------------------- */

.voice-input {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
}

.voice-input[hidden] {
    display: none;
}

.voice-input-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line, #d1d5db);
    border-radius: 50%;
    background: var(--surface, #fff);
    color: var(--ink, #111827);
}

.voice-input-icon,
.voice-input-icon svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* Listening: a stop square (shape change, not just colour) and a thicker red border. */
.voice-input-button.is-listening {
    border: 3px solid #b91c1c;
    color: #b91c1c;
}

.voice-input-notice {
    position: absolute;
    z-index: 30;
    right: 0;
    bottom: calc(100% + 8px);
    width: min(300px, 80vw);
    padding: 12px;
    border: 1px solid var(--line, #d1d5db);
    border-radius: 10px;
    background: var(--surface, #fff);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .16);
    color: var(--ink, #111827);
    font-size: .875rem;
    text-align: left;
}

.voice-input-notice p {
    margin: 0 0 10px;
}

.voice-input-notice-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.voice-input-notice-actions button {
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--line, #d1d5db);
    border-radius: 8px;
    background: var(--surface, #fff);
    color: var(--ink, #111827);
}

.voice-input-notice-actions .voice-input-notice-continue {
    border-color: var(--accent, #2563eb);
    background: var(--accent, #2563eb);
    color: #fff;
}

.chatbot-language-note {
    margin: 0;
    padding: 8px 12px;
    font-size: .8125rem;
}

/* Admin > Translations filter links. */
.translations-page .aio-filter-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.translations-page .aio-filter-list a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    text-decoration: underline;
}

.translations-page .aio-filter-list a[aria-current="page"] {
    font-weight: 700;
    text-decoration-thickness: 3px;
}

/* Attestation shown in English inside a translated page. */
.attestation-language-note {
    display: block;
    margin-top: 6px;
    font-style: italic;
}

/* ---- Interaction targets (44px where practical) -------------
   Buttons, links styled as buttons, form fields, navigation links
   and icon buttons are at least 44px tall (icon buttons also wide).
   min-height only: dense tables keep their layout and simply give
   row buttons the room they need. Plain text links in sentences,
   checkboxes, radios and visually hidden controls are left alone
   (16px remove buttons already grow their hit area in base.css).
   The generic button rule is wrapped in :where() so it has no
   specificity: a component rule that deliberately sets its own
   min-height still wins. Left out: the member chat window's tabs
   and header icons (they sit in a fixed-height bar), and sortable
   table header buttons (the header cell is the target). Square
   icon buttons are kept square below. */
:where(button:not(.visually-hidden):not(.sr-only):not(.btn-close):not(.chip-multi-remove):not(.activity-subtype-tag button):not(.chatbot-tab):not(.chatbot-header-actions button):not(.data-table-sort)),
:where([role="button"]:not(.visually-hidden):not(.sr-only)),
.btn,
.button,
input[type="button"],
input[type="submit"],
input[type="reset"],
select:not(.visually-hidden):not(.sr-only):not([multiple]):not([size]),
.form-select,
.form-control,
input[type="text"]:not(.visually-hidden),
input[type="search"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input:not([type]),
.nav-link,
.side-nav a,
.nav-submenu a,
.profile-menu a,
.dropdown-item {
    min-height: 44px;
}

/* Square icon buttons grow in both directions so they stay square
   (row icon actions, pagination, calendar month arrows). */
.table-action,
.data-table-pagination button,
.activity-month-year button,
.icon-button,
.menu-toggle,
.sidebar-mobile-close,
.btn-close {
    min-width: 44px;
    min-height: 44px;
}

/* Links styled as buttons are often inline: make them boxes so the height applies. */
a.btn,
a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ---- Status badge (Views/Shared/_StatusBadge.cshtml, WorkTrackUiStates.status) ----
   The word is always shown; the icon's shape differs by tone (check, !, x, dot), so no
   status depends on colour alone. Colours meet 4.5:1 contrast on their backgrounds. */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 2px 10px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #f3f4f6;
    color: #374151;
    font-size: .8125rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: normal;
}

.status-badge__icon {
    flex: 0 0 auto;
    font-weight: 700;
    line-height: 1;
}

.status-badge--positive {
    border-color: #86efac;
    background: #f0fdf4;
    color: #166534;
}

.status-badge--attention {
    border-color: #fcd34d;
    background: #fffbeb;
    color: #92400e;
}

.status-badge--problem {
    border-color: #fca5a5;
    background: #fef2f2;
    color: #991b1b;
}

/* ---- Loading, empty and error states (js/ui-states.js) ------ */
.ui-state {
    margin: 12px 0;
}

.ui-state p {
    margin: 0 0 6px;
}

.ui-state--loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted, #4b5563);
}

.ui-state__spinner {
    width: 18px;
    height: 18px;
    border: 3px solid #d1d5db;
    border-top-color: var(--accent, #2563eb);
    border-radius: 50%;
    animation: ui-state-spin 1s linear infinite;
}

@keyframes ui-state-spin {
    to {
        transform: rotate(360deg);
    }
}

.ui-state--empty,
.ui-state--error {
    padding: 12px 16px;
    border: 1px dashed #d1d5db;
    border-radius: 10px;
}

.ui-state--error {
    border: 1px solid #fca5a5;
    border-left-width: 4px;
    background: #fef2f2;
    color: #7f1d1d;
}

.ui-state__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.ui-state__next {
    color: inherit;
}

.ui-state__retry {
    margin-top: 6px;
}

/* ---- Small phones: slim pinned header (E2E-014) ---------------------------
   The language select plus its "Change language" button did not fit beside the menu button, bell and profile at
   320-375px. Below 576px the header stays one slim pinned row: a globe button (44px) opens the language form as a
   small panel under the bar. Without JavaScript the toggle stays hidden and the form shows as before. */
.language-switcher-toggle {
    display: none;
}

.language-switcher-fields {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

@media (max-width: 575.98px) {
    .topbar .top-actions {
        min-width: 0;
        gap: 4px;
    }

    .topbar .language-switcher {
        position: relative;
    }

    .topbar .language-switcher.has-toggle .language-switcher-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 1px solid var(--line, #d1d5db);
        border-radius: 8px;
        background: var(--surface, #fff);
        color: var(--ink, #111827);
    }

    .topbar .language-switcher.has-toggle .language-switcher-toggle svg {
        width: 20px;
        height: 20px;
    }

    .topbar .language-switcher.has-toggle:not(.is-open) .language-switcher-fields {
        display: none;
    }

    .topbar .language-switcher.has-toggle.is-open .language-switcher-fields {
        position: absolute;
        z-index: 40;
        top: calc(100% + 6px);
        right: 0;
        flex-wrap: nowrap;
        width: max-content;
        max-width: calc(100vw - 24px);
        padding: 10px;
        border: 1px solid var(--line, #d1d5db);
        border-radius: 10px;
        background: var(--surface, #fff);
        box-shadow: 0 8px 24px rgba(16, 24, 40, .18);
    }

    .topbar .language-switcher.has-toggle .language-switcher-label span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .topbar .language-switcher-select {
        min-width: 0;
        max-width: 140px;
        text-overflow: ellipsis;
    }

    .topbar .language-switcher-button {
        white-space: nowrap;
    }
}

/* ---- Links keep a non-colour cue (E2E-015, WCAG 1.4.1) ----------------------
   base.css sets a { color: inherit; text-decoration: none }, so a link inside a sentence looked like body text.
   Links in running text are underlined; navigation, buttons and cards keep their own styling. */
:is(main, .main-content, .auth-card, .app-footer) :is(p, li, dd, td, small, label, figcaption) a:not([class]),
:is(main, .main-content) :is(p, li, dd, td, small) a:is(.text-link, .inline-link, .link, .link-inline) {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

:is(main, .main-content) :is(p, li, dd, td, small) a:not([class]):hover {
    text-decoration-thickness: 2px;
}

