:root {
    --bg: #0b1220;
    --bg-soft: #111a2d;
    --panel: rgba(12, 20, 36, 0.94);
    --panel-2: rgba(15, 25, 44, 0.94);
    --border: #25324a;
    --text: #e8eefc;
    --muted: #9fb0cf;
    --accent: #14b8a6;
    --accent-2: #f59e0b;
    --danger: #f87171;
    --success: #34d399;
    --warning: #fbbf24;
    --shadow: 0 20px 42px rgba(0, 0, 0, 0.32);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family:
        "Segoe UI Variable Display", "Trebuchet MS", "Segoe UI", sans-serif;
    background:
        radial-gradient(
            circle at 10% -5%,
            rgba(20, 184, 166, 0.16),
            transparent 34%
        ),
        radial-gradient(
            circle at 95% 0,
            rgba(245, 158, 11, 0.14),
            transparent 24%
        ),
        linear-gradient(180deg, var(--bg) 0%, #091120 100%);
}

code {
    font-family: "Cascadia Code", "JetBrains Mono", monospace;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.3rem;
    border-bottom: 1px solid rgba(37, 50, 74, 0.8);
    background: rgba(9, 16, 30, 0.86);
    backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.brand-mark {
    width: 2.5rem;
    height: 2.5rem;
    display: grid;
    place-items: center;
    border-radius: 0.9rem;
    border: 1px solid rgba(20, 184, 166, 0.45);
    background: linear-gradient(
        135deg,
        rgba(20, 184, 166, 0.15),
        rgba(37, 50, 74, 0.5)
    );
    color: #9df8f0;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.brand h1 {
    margin: 0;
    font-size: 1.08rem;
}

.brand p,
.muted {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.87rem;
    line-height: 1.45;
}

.topbar-meta {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.pill,
.mini-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    border: 1px solid rgba(20, 184, 166, 0.5);
    background: rgba(20, 184, 166, 0.16);
    color: #a7f3d0;
    padding: 0.32rem 0.66rem;
    font-size: 0.75rem;
}

.pill.subtle,
.mini-pill {
    border-color: rgba(72, 92, 126, 0.8);
    background: rgba(17, 26, 45, 0.8);
    color: #c4d3ed;
}

.shell {
    min-height: calc(100vh - 74px);
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr) 440px;
    gap: 1rem;
    padding: 1rem;
}

.panel {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid rgba(37, 50, 74, 0.88);
    border-radius: 1.3rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.center {
    display: flex;
    flex-direction: column;
}

.sidebar {
    display: flex;
    flex-direction: column;
}

.sidebar .models-section {
    order: 1;
}

.sidebar .keys-intro {
    order: 2;
}

.sidebar .provider-grid {
    order: 3;
}

.panel-section {
    padding: 1rem;
    border-bottom: 1px solid rgba(37, 50, 74, 0.8);
}

.panel-section:last-child {
    border-bottom: 0;
}

.center-panel-header {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.back-to-start {
    align-self: flex-start;
}

.section-kicker {
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: #7fd5e1;
    font-size: 0.68rem;
    margin-bottom: 0.32rem;
}

h2,
h3 {
    margin: 0;
}

h2 {
    font-size: 1rem;
}

h3 {
    font-size: 0.9rem;
}

.provider-grid {
    display: grid;
    gap: 0.75rem;
}

.provider-card,
.summary-card,
.result-card,
.metric-card {
    border-radius: 1rem;
    border: 1px solid rgba(47, 64, 92, 0.82);
    background: rgba(11, 18, 32, 0.82);
    padding: 0.85rem;
}

.provider-card.active {
    border-color: rgba(20, 184, 166, 0.6);
    box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.22);
}

.provider-card-header,
.result-card-header,
.tier-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
}

.provider-card small {
    color: var(--muted);
}

.field {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
}

.field:last-child {
    margin-bottom: 0;
}

.field span {
    color: #d8e5fb;
    font-size: 0.83rem;
}

input,
textarea {
    width: 100%;
    border-radius: 0.88rem;
    border: 1px solid rgba(70, 89, 121, 0.92);
    background: rgba(10, 17, 30, 0.95);
    color: var(--text);
    padding: 0.78rem 0.88rem;
    font: inherit;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: rgba(20, 184, 166, 0.95);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}

textarea {
    resize: vertical;
    min-height: 260px;
    line-height: 1.45;
}

.tier-block + .tier-block {
    margin-top: 0.9rem;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.42rem;
    max-height: 330px;
    overflow-y: auto;
    align-content: start;
    padding-right: 0.14rem;
}

.model-card {
    width: 100%;
    text-align: left;
    border-radius: 0.78rem;
    border: 1px solid rgba(47, 64, 92, 0.9);
    padding: 0.5rem 0.56rem;
    font: inherit;
    font-size: 0.82rem;
    line-height: 1.24;
    transition:
        border-color 0.15s ease,
        transform 0.15s ease,
        background 0.15s ease;
}

.model-card.is-disabled {
    cursor: not-allowed;
    color: #94a3b8;
    background: rgba(47, 64, 92, 0.26);
}

.model-card.is-enabled {
    cursor: pointer;
    color: #0f172a;
    background: #f8fafc;
    border-color: rgba(203, 213, 225, 0.9);
}

.model-card.is-enabled:hover {
    transform: translateY(-1px);
    border-color: rgba(15, 23, 42, 0.25);
}

.model-card.is-selected {
    border-color: rgba(20, 184, 166, 0.85);
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.18);
}

.model-card-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.34rem;
    margin-bottom: 0.24rem;
}

.model-card-top strong {
    font-size: 0.77rem;
    line-height: 1.24;
}

.provider-tag {
    font-size: 0.62rem;
    color: #1e293b;
    background: rgba(148, 163, 184, 0.28);
    border-radius: 999px;
    padding: 0.08rem 0.42rem;
    white-space: nowrap;
}

.model-card-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.24rem;
    font-size: 0.64rem;
    color: #334155;
}

.model-card-badges {
    margin-top: 0.3rem;
    min-height: 1rem;
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
}

.badge {
    font-size: 0.6rem;
    border-radius: 999px;
    padding: 0.1rem 0.42rem;
    border: 1px solid transparent;
}

.badge.recommend {
    background: rgba(20, 184, 166, 0.14);
    border-color: rgba(20, 184, 166, 0.5);
    color: #0f766e;
}

.badge.preview {
    background: rgba(245, 158, 11, 0.18);
    border-color: rgba(245, 158, 11, 0.5);
    color: #9a3412;
}

.badge.think {
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.45);
    color: #1d4ed8;
}

.model-card-note {
    margin: 0.2rem 0 0;
    min-height: 0;
    font-size: 0.62rem;
    line-height: 1.25;
    color: #475569;
}

.selection-preview {
    margin-top: 0.85rem;
    display: grid;
    gap: 0.6rem;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
}

.selection-preview.compact div {
    padding: 0.7rem 0.75rem;
    border-radius: 0.9rem;
    border: 1px solid rgba(71, 94, 130, 0.8);
    background: rgba(12, 22, 39, 0.7);
}

.selection-preview small {
    display: block;
    color: var(--muted);
    margin-bottom: 0.3rem;
}

.selection-preview strong {
    font-size: 0.88rem;
    line-height: 1.35;
}

.tier-note {
    margin: 0 0 0.55rem;
}

.divider {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-size: 0.68rem;
}

.divider::before,
.divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(71, 94, 130, 0.84);
}

.cta-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.primary-button,
.ghost-button {
    border-radius: 0.92rem;
    border: 1px solid transparent;
    padding: 0.82rem 1.08rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition:
        transform 0.14s ease,
        border-color 0.14s ease,
        opacity 0.14s ease;
}

.primary-button {
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    color: #ecfeff;
}

.ghost-button {
    background: rgba(12, 22, 39, 0.9);
    border-color: rgba(71, 94, 130, 0.82);
    color: #d3e0f8;
}

.primary-button:hover,
.ghost-button:hover {
    transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
    opacity: 0.56;
    cursor: not-allowed;
    transform: none;
}

.run-status {
    min-height: 1.3rem;
    font-size: 0.85rem;
}

.statusbar {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.2rem;
    margin-bottom: 0.2rem;
    padding: 0.72rem 0.8rem;
    border-radius: 0.95rem;
    border: 1px solid rgba(71, 94, 130, 0.82);
    background: rgba(8, 14, 27, 0.82);
}

.statusbar.is-active {
    border-color: rgba(20, 184, 166, 0.52);
    background: rgba(10, 30, 35, 0.38);
}

.statusbar.is-success {
    border-color: rgba(52, 211, 153, 0.5);
    background: rgba(6, 78, 59, 0.2);
}

.statusbar.is-warning {
    border-color: rgba(251, 191, 36, 0.5);
    background: rgba(120, 53, 15, 0.22);
}

.statusbar.is-error {
    border-color: rgba(248, 113, 113, 0.5);
    background: rgba(127, 29, 29, 0.22);
}

.statusbar-track {
    position: relative;
    height: 0.48rem;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.96);
}

.statusbar-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent) 0%, #67e8f9 100%);
    transition: width 0.5s ease;
}

.statusbar.is-warning .statusbar-fill {
    background: linear-gradient(90deg, #f59e0b 0%, #fde68a 100%);
}

.statusbar.is-success .statusbar-fill {
    background: linear-gradient(90deg, #10b981 0%, #6ee7b7 100%);
}

.statusbar.is-error .statusbar-fill {
    background: linear-gradient(90deg, #ef4444 0%, #fca5a5 100%);
}

.statusbar-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.statusbar-meta strong {
    font-size: 0.83rem;
}

.statusbar-meta span {
    color: var(--muted);
    font-size: 0.78rem;
}

.run-status.success {
    color: var(--success);
}

.run-status.warning {
    color: var(--warning);
}

.run-status.error {
    color: var(--danger);
}

.center-results-view {
    flex: 1;
    padding-top: 1.2rem;
}

.center-results-shell {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

.search-main-card {
    min-height: 100%;
}

.metric-grid {
    display: grid;
    gap: 0.6rem;
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

.metric-card small {
    color: var(--muted);
    font-size: 0.74rem;
}

.metric-card strong {
    display: block;
    margin-top: 0.3rem;
    font-size: 1.12rem;
}

.metric-card .muted {
    margin-top: 0.3rem;
    display: block;
    font-size: 0.74rem;
    line-height: 1.35;
}

.result-stack {
    display: grid;
    gap: 0.78rem;
}

.summary-card.empty {
    color: var(--muted);
}

.summary-card.success {
    border-color: rgba(52, 211, 153, 0.5);
    background: rgba(6, 78, 59, 0.22);
}

.summary-card.warning {
    border-color: rgba(251, 191, 36, 0.5);
    background: rgba(120, 53, 15, 0.24);
}

.summary-card.error {
    border-color: rgba(248, 113, 113, 0.5);
    background: rgba(127, 29, 29, 0.24);
}

.summary-text {
    margin-top: 0.35rem;
}

.summary-card strong {
    display: block;
}

.json-block {
    margin: 0;
    padding: 0.88rem;
    border-radius: 0.9rem;
    border: 1px solid rgba(47, 64, 92, 0.82);
    background: rgba(6, 11, 21, 0.95);
    color: #dbeafe;
    font-family: "Cascadia Code", "JetBrains Mono", monospace;
    font-size: 0.75rem;
    line-height: 1.48;
    overflow: auto;
    max-height: 260px;
}

@media (max-width: 1280px) {
    .shell {
        grid-template-columns: 1fr;
    }
}

/* Search results */
.search-controls {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.search-intro {
    margin-bottom: 0.75rem;
}

.hypothesis-list {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.hypothesis-card,
.query-run-card,
.search-evaluation {
    border-radius: 0.95rem;
    border: 1px solid rgba(47, 64, 92, 0.82);
    background: rgba(8, 14, 27, 0.82);
    padding: 0.85rem;
}

.hypothesis-card.is-active {
    border-color: rgba(20, 184, 166, 0.7);
    box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.18);
}

.hypothesis-card.is-disabled {
    opacity: 0.72;
}

.hypothesis-card-head,
.query-run-header,
.search-evaluation-head,
.search-result-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.65rem;
}

.hypothesis-pill-stack {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    align-items: flex-end;
}

.hypothesis-pill-stack.inline {
    display: inline-flex;
    flex-direction: row;
    margin-top: 0.35rem;
    align-items: center;
}

.hypothesis-meta,
.signal-group-title {
    margin-top: 0.2rem;
    font-size: 0.72rem;
    color: var(--muted);
}

.hypothesis-copy,
.search-summary-copy {
    margin-top: 0.55rem;
}

.chip-row,
.search-stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.38rem;
    margin-top: 0.6rem;
}

.query-chip,
.platform-chip,
.signal-chip,
.stat-chip,
.search-result-score {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.7rem;
    border: 1px solid rgba(71, 94, 130, 0.82);
    background: rgba(12, 22, 39, 0.86);
    color: #d6e4fb;
}

.query-chip {
    background: rgba(15, 23, 42, 0.95);
}

.hypothesis-mode-chip.baseline {
    border-color: rgba(52, 211, 153, 0.52);
    background: rgba(6, 78, 59, 0.25);
    color: #a7f3d0;
}

.hypothesis-mode-chip.deviation {
    border-color: rgba(251, 191, 36, 0.5);
    background: rgba(120, 53, 15, 0.24);
    color: #fde68a;
}

.platform-chip {
    background: rgba(30, 41, 59, 0.88);
}

.signal-group + .signal-group {
    margin-top: 0.55rem;
}

.signal-chip.success {
    border-color: rgba(52, 211, 153, 0.52);
    background: rgba(6, 78, 59, 0.25);
    color: #a7f3d0;
}

.signal-chip.danger {
    border-color: rgba(248, 113, 113, 0.45);
    background: rgba(127, 29, 29, 0.22);
    color: #fecaca;
}

.hypothesis-actions {
    margin-top: 0.75rem;
}

.hypothesis-run-button {
    width: 100%;
}

.search-evaluation {
    margin-bottom: 0.85rem;
}

.search-evaluation.empty {
    color: var(--muted);
}

.search-evaluation.loading {
    border-color: rgba(251, 191, 36, 0.45);
    background: rgba(120, 53, 15, 0.18);
}

.search-evaluation.success {
    border-color: rgba(52, 211, 153, 0.5);
    background: rgba(6, 78, 59, 0.22);
}

.search-evaluation.warning {
    border-color: rgba(251, 191, 36, 0.5);
    background: rgba(120, 53, 15, 0.24);
}

.search-evaluation.error {
    border-color: rgba(248, 113, 113, 0.5);
    background: rgba(127, 29, 29, 0.24);
}

.query-run-card + .query-run-card {
    margin-top: 0.75rem;
}

.search-result-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.search-result-item a:hover {
    text-decoration: underline;
}

.search-result-head {
    align-items: center;
}

.search-result-details {
    margin: 0.2rem 0 0;
    font-size: 0.82rem;
    line-height: 1.4;
}

.search-result-link {
    margin-top: 0.75rem;
    font-size: 0.85rem;
}

.search-result-link a {
    color: var(--accent-2);
}

@media (max-width: 720px) {
    .model-grid {
        grid-template-columns: 1fr;
        max-height: 280px;
    }

    .selection-preview {
        grid-template-columns: 1fr;
    }

    .hypothesis-card-head,
    .query-run-header,
    .search-evaluation-head,
    .search-result-head {
        flex-direction: column;
    }

    .hypothesis-pill-stack {
        align-items: flex-start;
    }
}

/* ── Mode Tabs ────────────────────────────────── */
.mode-tabs {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    overflow: hidden;
    align-self: flex-start;
    margin-bottom: 0.5rem;
}

.mode-tab {
    padding: 0.55rem 1.1rem;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: transparent;
    color: var(--muted);
    transition: background 0.15s, color 0.15s;
}

.mode-tab.active {
    background: rgba(20, 184, 166, 0.18);
    color: var(--accent);
}

.mode-tab:hover:not(.active) {
    background: rgba(37, 50, 74, 0.5);
}

/* ── Reactive Search ──────────────────────────── */
.reactive-action-card {
    border-left: 3px solid var(--border);
    padding: 0.55rem 0.85rem;
    margin-bottom: 0.45rem;
    border-radius: 0 0.6rem 0.6rem 0;
    background: rgba(11, 18, 32, 0.6);
}

.reactive-action-card[data-type="search"] {
    border-left-color: var(--accent);
}

.reactive-action-card[data-type="pick"] {
    border-left-color: var(--success);
}

.reactive-action-card[data-type="stop"] {
    border-left-color: var(--warning);
}

.reactive-action-type {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: 0.35rem;
    margin-right: 0.4rem;
}

.reactive-action-type.search {
    background: rgba(20, 184, 166, 0.15);
    color: var(--accent);
}

.reactive-action-type.pick {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
}

.reactive-action-type.stop {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
}

.reactive-candidate {
    border-radius: 0.8rem;
    border: 1px solid var(--border);
    background: rgba(11, 18, 32, 0.82);
    padding: 0.85rem;
    margin-bottom: 0.55rem;
}

.reactive-candidate-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.reactive-candidate-head a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.reactive-candidate-head a:hover {
    text-decoration: underline;
}

.reactive-candidate-score {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

.score-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin-top: 0.45rem;
}

.score-bar-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--accent);
    transition: width 0.3s;
}

.reactive-conclusion {
    border-radius: 0.8rem;
    background: rgba(20, 184, 166, 0.08);
    border: 1px solid rgba(20, 184, 166, 0.2);
    padding: 0.85rem 1rem;
    margin-bottom: 0.75rem;
}

.reactive-conclusion .stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.45rem;
}

.reactive-model-select {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    max-height: 140px;
    overflow-y: auto;
}

.reactive-model-chip {
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.reactive-model-chip:hover {
    border-color: var(--accent);
    color: var(--text);
}

.reactive-model-chip.selected {
    background: rgba(20, 184, 166, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.reactive-model-chip:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
