/* ─── Reset & tokens ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:   #2563eb;
    --primary-d: #1d4ed8;
    --surface:   #ffffff;
    --bg:        #f1f5f9;
    --border:    #e2e8f0;
    --text:      #1e293b;
    --muted:     #64748b;
    --green:     #059669;
    --sidebar-w: 320px;
    --radius:    8px;
    --shadow:    0 1px 4px rgba(0,0,0,.08);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ─── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px;
    gap: 4px;
}

.sidebar-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}
.sidebar-header .subtitle {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 8px;
}

/* ─── Param sections ───────────────────────────────────────────────────────── */
.param-section {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 6px;
}
.param-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.param-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
.param-value {
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: right;
}

/* ─── Slider ────────────────────────────────────────────────────────────────── */
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    margin-bottom: 4px;
    cursor: pointer;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--primary);
}
.slider::-moz-range-thumb {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    cursor: pointer;
}

/* ─── Method toggle ─────────────────────────────────────────────────────────── */
/* ─── Method toggle ─────────────────────────────────────────────────────────── */
.method-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.method-btn {
    flex: 1;
    padding: 7px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    transition: background .15s, color .15s;
}
.method-btn:hover { background: #f1f5f9; }
.method-btn.active {
    background: var(--primary);
    color: white;
}

/* ─── Toggle row (L2 normalization etc.) ────────────────────────────────────── */
.toggle-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.toggle-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}
.toggle-check {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ─── Full select ──────────────────────────────────────────────────────────── */
.full-select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    font-size: 0.82rem;
    cursor: pointer;
    margin-bottom: 4px;
}

/* ─── Concepts textarea ─────────────────────────────────────────────────────── */
.concepts-box {
    width: 100%;
    min-height: 140px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-family: 'Menlo', 'Consolas', monospace;
    resize: vertical;
    line-height: 1.55;
    background: white;
}
.concepts-box:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* Badge on concept count */
.badge {
    background: var(--primary);
    color: white;
    border-radius: 20px;
    padding: 1px 8px;
    font-size: 0.72rem;
    font-weight: 700;
}

/* ─── Run button ────────────────────────────────────────────────────────────── */
.run-btn {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s;
    margin-bottom: 8px;
}
.run-btn:hover { background: var(--primary-d); }
.run-btn:disabled { background: #94a3b8; cursor: not-allowed; }

/* ─── Progress bar ──────────────────────────────────────────────────────────── */
.progress-wrap { display: flex; flex-direction: column; gap: 4px; }
.progress-bar-bg {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width .25s;
    width: 0%;
}
.status-msg {
    font-size: 0.76rem;
    color: var(--muted);
    line-height: 1.4;
    word-break: break-word;
}

/* Misc spacers */
.mt8  { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mb4  { margin-bottom: 4px; }
.hint {
    font-size: 0.73rem;
    color: var(--muted);
    line-height: 1.4;
    margin-top: 3px;
}
code { background: #f1f5f9; padding: 1px 4px; border-radius: 3px; font-size: 0.82em; }

/* ─── Main area ─────────────────────────────────────────────────────────────── */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

/* ─── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.tab-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: none;
    cursor: pointer;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--muted);
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.tab-btn:hover { background: #f1f5f9; }
.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.tabs-right { margin-left: auto; }

/* Export button */
.export-btn {
    padding: 6px 14px;
    background: var(--green);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.83rem;
    font-weight: 600;
    transition: background .15s;
}
.export-btn:hover { background: #047857; }

/* ─── Tab content ───────────────────────────────────────────────────────────── */
.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
}
.tab-content.active {
    display: block;
    height: 100%;
    overflow: auto;
}

/* ─── Plot containers ───────────────────────────────────────────────────────── */
.plot-container {
    width: 100%;
    height: calc(100vh - 62px);
    min-height: 400px;
}

/* ─── Report tab ────────────────────────────────────────────────────────────── */
.report-scroll {
    padding: 16px 20px;
    overflow-y: auto;
    height: calc(100vh - 62px);
}
.report-section { margin-bottom: 24px; }
.report-section h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
    color: var(--text);
}
.report-section h3 small { font-size: 0.78rem; color: var(--muted); font-weight: 400; }

/* Param pill */
.param-pill {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.73rem;
    color: #1d4ed8;
    margin-bottom: 10px;
    font-family: 'Menlo', 'Consolas', monospace;
    word-break: break-all;
}

/* Summary badges */
.cluster-summary { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.sum-badge {
    background: #dbeafe;
    color: #1e40af;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 0.76rem;
    font-weight: 700;
}
.sum-badge.muted { background: #f1f5f9; color: var(--muted); }

/* Cluster items */
.cluster-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
}
.cluster-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.cluster-badge {
    background: var(--primary);
    color: white;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 800;
}
.concept-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.concept-tag {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 0.78rem;
}
.concept-tag.muted { background: #f1f5f9; color: var(--muted); }

/* Noise details */
.noise-details {
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    margin-bottom: 8px;
}
.noise-details summary {
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 600;
    user-select: none;
    margin-bottom: 4px;
}
.noise-details[open] summary { margin-bottom: 8px; }

/* Pairs list */
.pairs-list { max-height: 500px; overflow-y: auto; }
.pair-item { padding: 6px 0; border-bottom: 1px dashed #e2e8f0; }
.pair-names { font-size: 0.83rem; display: block; margin-bottom: 3px; }
.sim-bar-wrap { display: flex; align-items: center; gap: 6px; }
.sim-bar {
    height: 5px;
    background: var(--primary);
    border-radius: 3px;
    opacity: 0.6;
    min-width: 2px;
}
.similarity-score {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

/* Matrix warn */
.matrix-warn {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ─── ELSST Lookup ──────────────────────────────────────────────────────────── */
.elsst-query-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.93rem;
    font-family: inherit;
    line-height: 1.5;
    background: white;
    margin-top: 4px;
    text-transform: uppercase;
    resize: vertical;
    min-height: 72px;
    letter-spacing: 0.01em;
    transition: border-color 0.15s;
    display: block;
}
.elsst-query-input:focus { outline: 2px solid var(--primary); border-color: transparent; }
kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.78rem;
    font-family: inherit;
    background: #f4f4f4;
    line-height: 1.4;
}

.elsst-results-list { display: flex; flex-direction: column; gap: 10px; }

.elsst-result-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: border-color .15s;
}
.elsst-result-card:hover { border-color: var(--primary); }

.elsst-rank {
    background: var(--primary);
    color: white;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    min-width: 36px;
    text-align: center;
}

.elsst-result-body { flex: 1; min-width: 0; }

.elsst-leaf-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.elsst-path-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    margin-bottom: 8px;
    font-size: 0.78rem;
}

.elsst-bc-parent {
    background: #e0e7ff;
    color: #3730a3;
    border-radius: 4px;
    padding: 1px 6px;
    white-space: nowrap;
}

.elsst-bc-sep {
    color: var(--muted);
    font-weight: 700;
    font-size: 0.9em;
}

.elsst-bc-leaf {
    background: #dbeafe;
    color: #1e40af;
    border-radius: 4px;
    padding: 1px 6px;
    font-weight: 700;
    white-space: nowrap;
}

/* Cross-encoder re-ranking badge (shown in param-pill) */
.rerank-badge {
    display: inline-block;
    background: linear-gradient(90deg, #7c3aed, #4f46e5);
    color: white;
    border-radius: 4px;
    padding: 1px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* Dual-score detail line shown when cross-encoder is active */
.score-detail {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
}
.score-detail strong { color: #7c3aed; }
