/**
 * Shared state selector + read-only state context badge.
 *
 * Used in the public top bar, the dashboard, and the test chooser.
 * Kept theme-neutral so it works on the light marketing header and the
 * dashboard surface without page-specific overrides.
 */

.state-select {
    --state-ink: #15224a;
    --state-accent: #fb5b3b;
    --state-line: rgba(21, 34, 74, 0.16);

    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    line-height: 1;
}

.state-select-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.42rem 0.55rem;
    border: 1px solid rgba(21, 34, 74, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    color: var(--state-ink);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    box-shadow: 0 6px 18px -12px rgba(21, 34, 74, 0.2);
}

.state-select-label svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: var(--state-accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.state-select-control {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 0;
}

.state-select select {
    -webkit-appearance: none;
    appearance: none;

    min-width: 172px;
    height: 42px;
    padding: 0 36px 0 14px;

    border: 1px solid rgba(21, 34, 74, 0.12);
    border-radius: 12px;

    background: rgba(255, 255, 255, 0.92);
    color: var(--state-ink);

    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;

    cursor: pointer;
    box-shadow: 0 12px 26px -18px rgba(21, 34, 74, 0.4);

    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        background-color 0.18s ease,
        transform 0.18s ease;
}

.state-select select:hover {
    border-color: rgba(251, 91, 59, 0.55);
    transform: translateY(-1px);
}

.state-select select:focus-visible {
    outline: 2px solid rgba(251, 91, 59, 0.45);
    outline-offset: 2px;
    border-color: var(--state-accent);
}

.state-select-caret {
    position: absolute;
    right: 11px;
    width: 13px;
    height: 13px;
    pointer-events: none;
    fill: none;
    stroke: var(--state-ink);
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.65;
}

.state-select--header {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.state-select--header .state-select-label {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
    color: #15224a;
    opacity: 1;
    letter-spacing: 0.01em;
}

.state-select--header .state-select select {
    min-width: 154px;
    height: 38px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(21, 34, 74, 0.12);
    border-radius: 10px;
    box-shadow: none;
}

/* Compact context on the test chooser */
.state-select--compact .state-select-label span {
    display: none;
}

/* Read-only badge for active tests and results */
.state-context {
    --state-ink: #15224a;

    display: inline-flex;
    align-items: center;
    gap: 0.5rem;

    padding: 0.42rem 0.75rem;

    border: 1px solid rgba(21, 34, 74, 0.14);
    border-radius: 999px;

    background: #ffffff;
    color: var(--state-ink);

    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;

    box-shadow: 0 2px 8px rgba(21, 34, 74, 0.05);
}

.state-context-code {
    display: inline-grid;
    place-items: center;

    min-width: 30px;
    height: 22px;
    padding: 0 0.4rem;

    border-radius: 6px;

    background: var(--state-ink);
    color: #ffffff;

    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}

@media (max-width: 768px) {
    .state-select--header {
        padding: 0.12rem 0.14rem;
    }

    .state-select-label span {
        display: none;
    }

    .state-select select {
        min-width: 128px;
    }
}

@media (max-width: 640px) {
    .state-select select {
        min-width: 116px;
    }
}

/* Enhanced picker; the native select remains the no-JavaScript fallback. */
.state-select-control--enhanced > select,
.state-select-control--enhanced > .state-select-caret {
    display: none;
}

.state-picker-trigger {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: 218px;
    min-width: 0;
    height: 46px;
    padding: 6px 13px 6px 7px;
    border: 1px solid #e2e5ed;
    border-radius: 13px;
    background: #fff;
    color: #15224a;
    font: 600 13px/1.3 'Inter', system-ui, sans-serif;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 3px 9px rgba(21, 34, 74, 0.04);
    transition: border-color .18s, box-shadow .18s;
}

.state-picker-trigger:hover,
.state-picker-trigger[aria-expanded="true"] {
    border-color: #fb5b3b;
    box-shadow: 0 0 0 3px rgba(251, 91, 59, .09);
}

.state-picker-trigger:focus-visible {
    outline: 2px solid #fb5b3b;
    outline-offset: 3px;
}

.state-picker-badge {
    display: inline-grid;
    place-items: center;
    flex: 0 0 31px;
    height: 31px;
    border-radius: 9px;
    background: #fff0eb;
    color: #cd4126;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .04em;
}

.state-picker-value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.state-picker-chevron {
    flex: 0 0 6px;
    width: 6px;
    height: 6px;
    margin: -4px 2px 0 4px;
    border: solid #72809b;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
    transition: transform .18s;
}

.state-picker-trigger[aria-expanded="true"] .state-picker-chevron {
    transform: translateY(3px) rotate(225deg);
}

.state-picker-panel {
    position: fixed;
    z-index: 9500;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    padding: 17px 8px 0;
    border: 1px solid #e5e7ee;
    border-radius: 18px;
    background: #fff;
    color: #15224a;
    box-shadow: 0 20px 60px -12px rgba(21, 34, 74, .24), 0 4px 12px rgba(21, 34, 74, .05);
    font: 400 13px/1.4 'Inter', system-ui, sans-serif;
    text-align: left;
    animation: state-picker-appear .15s ease-out;
}

.state-picker-panel *,
.state-picker-panel *::before,
.state-picker-panel *::after {
    box-sizing: border-box;
}

.state-picker-panel[hidden],
.state-picker-option[hidden],
.state-picker-empty[hidden] {
    display: none;
}

.state-picker-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 12px;
    padding: 0 9px 13px;
}

.state-picker-heading strong {
    font-size: 14px;
    font-weight: 750;
}

.state-picker-heading > span {
    padding: 3px 7px;
    border-radius: 6px;
    background: #f3f5f9;
    color: #65718b;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.state-picker-search {
    position: relative;
    flex-shrink: 0;
    margin: 0 8px 10px;
}

.state-picker-search input {
    width: 100%;
    height: 42px;
    margin: 0;
    padding: 0 12px 0 36px;
    border: 1px solid #e5e7ee;
    border-radius: 10px;
    background: #f7f8fb;
    color: #15224a;
    font: inherit;
    font-size: 12px;
    outline: none;
}

.state-picker-search input:focus {
    border-color: #f6a28f;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(251, 91, 59, .07);
}

.state-picker-search input::placeholder { color: #7b8499; }

.state-picker-search-icon {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 11px;
    height: 11px;
    border: 1.6px solid #8690a6;
    border-radius: 50%;
    pointer-events: none;
}

.state-picker-search-icon::after {
    content: '';
    position: absolute;
    width: 5px;
    height: 1.6px;
    right: -4px;
    bottom: -2px;
    border-radius: 2px;
    background: #8690a6;
    transform: rotate(45deg);
}

.state-picker-list {
    flex: 0 1 auto;
    min-height: 0;
    max-height: 288px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #d6dbe5 transparent;
    padding: 2px 3px 6px;
}

.state-picker-option {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 43px;
    margin: 2px 0;
    padding: 7px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
}

.state-picker-option:hover,
.state-picker-option.is-active { background: #fff0eb; }

.state-picker-option[aria-selected="true"] {
    background: #fb5b3b;
    color: #fff;
    font-weight: 700;
}

.state-picker-option[aria-selected="true"].is-active { box-shadow: inset 0 0 0 2px #dc4427; }

.state-picker-option-code {
    display: inline-grid;
    place-items: center;
    flex: 0 0 29px;
    height: 27px;
    border: 1px solid #e6e9f0;
    border-radius: 7px;
    background: #fff;
    color: #7c879d;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
}

.state-picker-option[aria-selected="true"] .state-picker-option-code {
    border-color: rgba(255, 255, 255, .35);
    background: rgba(255, 255, 255, .16);
    color: #fff;
}

.state-picker-check {
    visibility: hidden;
    margin-left: auto;
    color: #df4a2d;
    font-size: 16px;
    font-weight: 700;
}

.state-picker-option[aria-selected="true"] .state-picker-check { visibility: visible; color: #fff; }

.state-picker-empty {
    margin: 0;
    padding: 24px 20px;
    color: #6a7590;
    font-size: 12px;
    line-height: 1.7;
    text-align: center;
}

.state-picker-footer {
    flex-shrink: 0;
    margin: 4px -8px 0;
    padding: 12px 16px;
    border-top: 1px solid #edf0f5;
    background: #fafbfc;
    color: #7b8499;
    font-size: 10px;
    text-align: center;
}

@keyframes state-picker-appear {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
    .state-picker-trigger { width: 190px; height: 43px; font-size: 12px; }
    .state-picker-search input { font-size: 16px; }
}

@media (max-width: 400px) {
    .state-picker-trigger { width: 170px; }
}

@media (prefers-reduced-motion: reduce) {
    .state-picker-panel { animation: none; }
    .state-picker-trigger, .state-picker-chevron { transition: none; }
}
