/**
 * WCAG 2.1 Level AA - global focus, skip link, motion, contrast helpers (3.8.4).
 */

.skip-link {
    position: absolute;
    left: 0.75rem;
    top: -4rem;
    z-index: 10000;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    background: #fff;
    color: var(--plan-deep-blue);
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(11, 67, 104, 0.2);
    border: 2px solid var(--plan-deep-blue);
}

.skip-link:focus,
.skip-link:focus-visible {
    top: 0.75rem;
    outline: none;
}

/* Visible focus for keyboard users (2.4.7) */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--plan-deep-blue);
    outline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--plan-deep-blue);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--field-focus-ring);
}

.top-nav a:focus-visible,
.app-rail-item:focus-visible {
    outline-color: #fff;
    box-shadow: 0 0 0 3px var(--plan-yellow), 0 0 0 5px var(--plan-deep-blue);
}

.hero .header-ticket-search input:focus-visible {
    outline-color: var(--plan-deep-blue);
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--plan-deep-blue);
}

/* Slightly stronger muted text for 4.5:1 on white (1.4.3) */
.muted,
.plan-app-dialog__message {
    color: #3d556c;
}

/* Error identification (3.3.1) */
[aria-invalid="true"],
input:user-invalid,
select:user-invalid,
textarea:user-invalid {
    border-color: var(--warn) !important;
    box-shadow: 0 0 0 2px rgba(217, 72, 15, 0.25);
}

.field-error,
.alert-error {
    color: #9c2f0a;
    font-weight: 600;
}

.alert-error {
    border: 1px solid #f0a78a;
    background: #fff4f0;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
}

.alert-error[role="alert"] {
    margin-bottom: 0.75rem;
}

/* Reduced motion (2.3.3) */
@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;
    }
}

/* High contrast / forced colors */
@media (forced-colors: active) {
    :focus-visible {
        outline: 3px solid CanvasText;
    }

    .skip-link {
        border-color: CanvasText;
    }
}

/* Screen-reader only (not display:none - remains focusable when skip link pattern) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

caption.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ticket data tables - programmatic headers when stacked */
@media (max-width: 720px) {
    .table-wrap--stacked-md tbody td::before {
        color: #2a4a62;
    }
}

/* 3.8.5 - language switcher (match header logout control size) */
label.lang-switcher {
    display: inline-flex;
    align-items: center;
    margin-inline-start: 0;
    gap: 0;
}

label.lang-switcher select {
    min-width: 0;
    width: auto;
    min-height: 0;
    height: auto;
    padding: 0.4rem 1.7rem 0.4rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--plan-deep-blue);
    background-color: #e9f6ff;
    background-image: linear-gradient(45deg, transparent 50%, var(--plan-deep-blue) 50%),
        linear-gradient(135deg, var(--plan-deep-blue) 50%, transparent 50%);
    background-position: calc(100% - 12px) calc(50% - 2px), calc(100% - 7px) calc(50% - 2px);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    box-shadow: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

label.lang-switcher select:hover {
    background-color: #d8efff;
    border-color: var(--line);
    box-shadow: none;
}

label.lang-switcher select:focus {
    outline: none;
    border-color: var(--field-border-focus);
    box-shadow: 0 0 0 2px var(--field-focus-ring);
}

/* Text size preference (header + profile) */
.ui-font-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.ui-font-switcher__label {
    font-size: 0.78rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
    white-space: nowrap;
}

.hero .ui-font-switcher__label {
    color: rgba(255, 255, 255, 0.92);
}

.auth-card .ui-font-switcher__label,
.profile-card .ui-font-switcher__label,
.dash-top-bar__actions .ui-font-switcher__label,
.dashboard-config-font-size .ui-font-switcher__label {
    color: var(--muted);
}

.ui-font-switcher__control {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.14);
}

.auth-card .ui-font-switcher__control,
.profile-card .ui-font-switcher__control,
.dash-top-bar__actions .ui-font-switcher__control,
.dashboard-config-font-size .ui-font-switcher__control {
    border-color: var(--line);
    background: #eef7fc;
}

.ui-font-switcher__btn {
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 1;
    min-height: 0;
    padding: 0.42rem 0.55rem;
    cursor: pointer;
    box-shadow: none;
}

.ui-font-switcher__btn + .ui-font-switcher__btn {
    border-inline-start: 1px solid rgba(255, 255, 255, 0.28);
}

.auth-card .ui-font-switcher__btn,
.profile-card .ui-font-switcher__btn,
.dash-top-bar__actions .ui-font-switcher__btn,
.dashboard-config-font-size .ui-font-switcher__btn {
    color: var(--plan-deep-blue);
}

.auth-card .ui-font-switcher__btn + .ui-font-switcher__btn,
.profile-card .ui-font-switcher__btn + .ui-font-switcher__btn,
.dash-top-bar__actions .ui-font-switcher__btn + .ui-font-switcher__btn,
.dashboard-config-font-size .ui-font-switcher__btn + .ui-font-switcher__btn {
    border-inline-start-color: var(--line);
}

.ui-font-switcher__btn:hover {
    background: rgba(255, 255, 255, 0.18);
    box-shadow: none;
}

.auth-card .ui-font-switcher__btn:hover,
.profile-card .ui-font-switcher__btn:hover,
.dash-top-bar__actions .ui-font-switcher__btn:hover,
.dashboard-config-font-size .ui-font-switcher__btn:hover {
    background: #d8efff;
}

.ui-font-switcher__btn.is-active {
    background: #fff;
    color: var(--plan-deep-blue);
}

.auth-card .ui-font-switcher__btn.is-active,
.profile-card .ui-font-switcher__btn.is-active,
.dash-top-bar__actions .ui-font-switcher__btn.is-active,
.dashboard-config-font-size .ui-font-switcher__btn.is-active {
    background: var(--plan-deep-blue);
    color: #fff;
}

.ui-font-switcher__btn:focus-visible {
    outline: 2px solid var(--plan-yellow);
    outline-offset: -2px;
    z-index: 1;
}

.profile-font-size {
    margin: 0.35rem 0 0.85rem;
}

.profile-font-size .ui-font-switcher,
.dashboard-config-font-size .ui-font-switcher {
    flex-wrap: wrap;
    gap: 0.55rem;
}

.dashboard-config-font-size {
    margin: 0 0 1rem;
}

.auth-card__lang {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-bottom: 0.75rem;
}

/* RTL (Arabic) */
html[dir="rtl"] .dashboard-shell,
html[dir="rtl"] .dash-sidebar,
html.plan-rtl .dashboard-shell,
html.plan-rtl .dash-sidebar {
    direction: rtl;
}

html[dir="rtl"] .dash-nav-item,
html.plan-rtl .dash-nav-item {
    flex-direction: row-reverse;
}

html[dir="rtl"] .toolbar,
html.plan-rtl .toolbar {
    flex-direction: row-reverse;
    flex-wrap: wrap;
}

html[dir="rtl"] .modal-card__header,
html.plan-rtl .modal-card__header {
    flex-direction: row-reverse;
}
