@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
    --bg-0: #f4efe5;
    --bg-1: #e7edf8;
    --panel: #ffffff;
    --ink: #101628;
    --muted: #5f6780;
    --line: #d8deea;
    --accent: #236aff;
    --accent-soft: rgba(35, 106, 255, 0.12);
    --positive: #f26b38;
    --negative: #2b6de9;
    --positive-soft: #f6c85f;
    --negative-soft: #7fb2ff;
    --missing: #c7ced9;
    --radius: 14px;
    --shadow: 0 12px 32px rgba(24, 36, 72, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Space Grotesk', 'Avenir Next', 'Helvetica Neue', sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0%, rgba(255, 196, 126, 0.32), transparent 38%),
        radial-gradient(circle at 90% 18%, rgba(106, 151, 255, 0.28), transparent 42%),
        linear-gradient(145deg, var(--bg-0), var(--bg-1));
    min-height: 100vh;
    overflow: hidden;
}

.dashboard-header {
    padding: 20px 28px 12px;
    text-align: left;
}

.dashboard-header h1 {
    margin: 0;
    font-family: 'Fraunces', 'Georgia', serif;
    font-size: 34px;
    line-height: 1.05;
    letter-spacing: 0.2px;
}

.dashboard-header p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(440px, 46%) 1fr;
    gap: 14px;
    height: calc(100vh - 108px);
    padding: 0 18px 18px;
}

.tree-panel,
.details-panel {
    background: rgba(255, 255, 255, 0.84);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.tree-panel {
    display: grid;
    grid-template-rows: auto 1fr;
    position: relative;
}

.details-panel {
    display: grid;
    grid-template-rows: auto 1fr;
}

.header {
    padding: 14px 18px;
    font-weight: 600;
    color: #1e2a4d;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(241, 247, 255, 0.95), rgba(255, 255, 255, 0.7));
}

.controls {
    border-bottom: 1px solid var(--line);
    padding: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 251, 255, 0.88));
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    gap: 10px;
}

.control-group {
    margin-bottom: 10px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.variable-selector,
.search-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 10px;
    font-size: 13px;
    font-family: 'Space Grotesk', sans-serif;
    color: #1a223c;
    background: #fff;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.variable-selector:focus,
.search-input:focus {
    outline: none;
    border-color: rgba(35, 106, 255, 0.55);
    box-shadow: 0 0 0 4px rgba(35, 106, 255, 0.14);
    transform: translateY(-1px);
}

.search-container {
    position: relative;
}

.clear-search-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    color: #7a86a7;
}

.search-results {
    margin-top: 6px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 8px 20px rgba(14, 30, 66, 0.12);
    max-height: 220px;
    overflow-y: auto;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    border-bottom: 1px solid #edf1f7;
    cursor: pointer;
    font-size: 12px;
}

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

.search-result-item.highlighted,
.search-result-item:hover {
    background: var(--accent-soft);
}

.search-result-name {
    font-weight: 600;
}

.search-result-code {
    color: #63709a;
    font-family: 'IBM Plex Mono', monospace;
}

.tree-controls {
    display: flex;
    gap: 8px;
}

.tree-control-btn {
    flex: 1;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 7px 8px;
    font-size: 12px;
    font-family: 'Space Grotesk', sans-serif;
    cursor: pointer;
    transition: all 0.14s ease;
}

.tree-control-btn:hover {
    border-color: rgba(35, 106, 255, 0.58);
    background: #f6f9ff;
}

.depth-slider-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

#depth-slider {
    width: 100%;
}

#depth-value {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: var(--muted);
}

#tree-container {
    position: relative;
    overflow: auto;
    background:
        linear-gradient(180deg, rgba(249, 252, 255, 0.96), rgba(245, 248, 255, 0.88));
}

.legend {
    position: absolute;
    right: 14px;
    bottom: 14px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    font-size: 11px;
    box-shadow: 0 10px 18px rgba(26, 45, 90, 0.12);
}

.legend-title {
    font-weight: 700;
    margin-bottom: 6px;
    color: #1f2f5f;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    border: 1px solid rgba(16, 22, 40, 0.14);
}

.details-content {
    overflow-y: auto;
    padding: 14px;
}

.breadcrumb {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.crumb {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 999px;
    padding: 4px 9px;
    cursor: pointer;
    font-size: 11px;
    color: #23345e;
}

.crumb:hover {
    border-color: rgba(35, 106, 255, 0.6);
    color: #1f55cb;
}

.crumb-separator {
    color: #8b94ac;
    font-size: 11px;
}

.node-info {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}

.node-info h3 {
    margin: 0 0 10px;
    font-family: 'Fraunces', serif;
    font-size: 19px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.kpi-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: #fbfdff;
}

.kpi-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7581a2;
    margin-bottom: 2px;
}

.kpi-value {
    font-weight: 700;
    font-size: 13px;
}

.kpi-value.small {
    font-size: 12px;
    line-height: 1.35;
}

.metric-list {
    border-top: 1px dashed var(--line);
    padding-top: 8px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    padding: 4px 0;
}

.metric-label {
    color: var(--muted);
}

.metric-value {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
}

.metric-value.positive {
    color: #bf3c0f;
}

.metric-value.negative {
    color: #1f55cb;
}

.metric-value.neutral {
    color: #7e879f;
}

.status-pill {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    border: 1px solid transparent;
    font-family: 'Space Grotesk', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sig-yes {
    color: #9a3900;
    background: rgba(242, 107, 56, 0.2);
    border-color: rgba(242, 107, 56, 0.35);
}

.sig-no {
    color: #1f4fab;
    background: rgba(43, 109, 233, 0.15);
    border-color: rgba(43, 109, 233, 0.28);
}

.sig-na {
    color: #5f6780;
    background: rgba(161, 171, 196, 0.2);
    border-color: rgba(161, 171, 196, 0.3);
}

.visualizations-container {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
}

.viz-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(244, 248, 255, 0.9), rgba(255, 255, 255, 0.9));
}

.tab-button {
    border: none;
    background: transparent;
    padding: 10px 11px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.58px;
    color: #5a6688;
    cursor: pointer;
    border-right: 1px solid rgba(216, 222, 234, 0.65);
    transition: all 0.15s ease;
}

.tab-button:last-child {
    border-right: none;
}

.tab-button:hover {
    background: #f5f8ff;
    color: #1f4fb9;
}

.tab-button.active {
    color: #0f1d42;
    background: #fff;
    box-shadow: inset 0 -2px 0 0 var(--accent);
    font-weight: 700;
}

.tab-panel {
    display: none;
    min-height: 340px;
    max-height: 560px;
    overflow-y: auto;
    padding: 12px;
}

.tab-panel.active {
    display: block;
}

.placeholder,
.empty-state {
    color: #7080a5;
    font-size: 13px;
    line-height: 1.45;
}

.empty-card {
    border: 1px dashed var(--line);
    border-radius: 10px;
    padding: 12px;
    color: #63729a;
    background: #fbfdff;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.meta-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: #fafcff;
}

.meta-label {
    font-size: 10px;
    color: #7a86a7;
    text-transform: uppercase;
    letter-spacing: 0.45px;
}

.meta-value {
    font-size: 13px;
    font-weight: 700;
}

.meta-note {
    font-size: 12px;
    color: #4f5f89;
    background: #f5f8ff;
    border: 1px solid #d7e1fb;
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
}

.content-block {
    margin-bottom: 12px;
}

.content-block h4 {
    margin: 0 0 6px;
    font-family: 'Fraunces', serif;
    font-size: 16px;
}

.content-block h5 {
    margin: 0 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #65729a;
}

.narrative-body {
    margin: 0;
    font-size: 13px;
    line-height: 1.55;
    color: #1f2944;
}

.bullet-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    line-height: 1.5;
    color: #1f2944;
}

.bullet-list li {
    margin: 5px 0;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
    background: rgba(35, 106, 255, 0.15);
    color: #1646a7;
    border: 1px solid rgba(35, 106, 255, 0.25);
}

.tag-chip.neutral {
    background: #eff2f8;
    border-color: #dbe1ef;
    color: #5b6786;
}

.tag-chip.low {
    background: rgba(43, 109, 233, 0.16);
    border-color: rgba(43, 109, 233, 0.3);
    color: #2250a8;
}

.tag-chip.medium {
    background: rgba(246, 200, 95, 0.25);
    border-color: rgba(246, 200, 95, 0.35);
    color: #805d00;
}

.tag-chip.high {
    background: rgba(242, 107, 56, 0.22);
    border-color: rgba(242, 107, 56, 0.35);
    color: #9b3f18;
}

.coef-card,
.chain-card,
.assumption-card,
.firm-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
}

.coef-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 8px;
}

.coef-header h4 {
    margin: 0;
    font-size: 13px;
    line-height: 1.35;
}

.coef-metrics {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.metric-chip {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    border: 1px solid var(--line);
    background: #f8faff;
    border-radius: 999px;
    padding: 2px 7px;
}

.interpretation-item {
    border-top: 1px dashed #dfe5f1;
    padding-top: 8px;
    margin-top: 8px;
}

.interpretation-item p {
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.5;
}

.interpretation-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.logic-notes {
    color: #4d5c84;
    font-style: italic;
}

.chain-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.chain-flow {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1fr;
    gap: 6px;
    align-items: center;
}

.chain-node {
    border: 1px solid #dbe2f0;
    border-radius: 10px;
    padding: 8px;
    background: #f9fbff;
}

.chain-node strong {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    color: #5d6990;
    margin-bottom: 4px;
}

.chain-node p {
    margin: 0;
    font-size: 12px;
    line-height: 1.45;
}

.chain-arrow {
    color: #6d79a0;
    font-weight: 700;
}

.assumption-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.assumption-id {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: #344372;
    border: 1px solid #d8e0f1;
    padding: 2px 7px;
    border-radius: 999px;
}

.assumption-card p {
    margin: 6px 0;
    font-size: 12px;
    line-height: 1.5;
}

.subsection {
    margin-top: 8px;
}

.firm-card h5 {
    margin: 0 0 5px;
    font-size: 13px;
}

.firm-card a {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: #1f55cb;
    text-decoration: none;
}

.firm-card p {
    margin: 6px 0;
    font-size: 12px;
    line-height: 1.5;
}

.muted {
    color: #7a86a7;
    font-size: 12px;
}

.mechanism-container {
    display: grid;
    gap: 10px;
}

.mechanism-graph {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: #fff;
}

.tooltip {
    position: absolute;
    background: rgba(17, 22, 40, 0.92);
    color: #f8fbff;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.45;
    box-shadow: 0 10px 20px rgba(8, 12, 26, 0.28);
    pointer-events: none;
    z-index: 999;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #60719c;
    font-size: 14px;
}

.intro-screen {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 12% 10%, rgba(255, 205, 136, 0.26), transparent 38%),
        radial-gradient(circle at 88% 20%, rgba(92, 138, 255, 0.28), transparent 45%),
        linear-gradient(145deg, #f0eadf, #dce8ff);
    z-index: 2000;
    overflow-y: auto;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.intro-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.intro-content {
    max-width: 980px;
    margin: 36px auto;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.intro-content h1 {
    margin: 0 0 10px;
    font-family: 'Fraunces', serif;
    font-size: 42px;
    line-height: 1;
}

.intro-content p {
    margin: 0 0 10px;
    color: #23345f;
    line-height: 1.58;
}

.intro-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.intro-card {
    background: #f8fbff;
    border: 1px solid #dbe4f5;
    border-radius: 14px;
    padding: 12px;
}

.intro-card h3 {
    margin: 0 0 8px;
    font-size: 15px;
}

.intro-card ul {
    margin: 0;
    padding-left: 18px;
    color: #2f416e;
}

.intro-card li {
    margin: 6px 0;
    line-height: 1.45;
}

.intro-team {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 18px 0;
}

.team-member {
    width: 132px;
    text-align: center;
}

.team-member img {
    width: 100%;
    border-radius: 12px;
    border: 1px solid #dce3f1;
    box-shadow: 0 8px 18px rgba(32, 46, 82, 0.14);
}

.team-member h4 {
    margin: 7px 0 0;
    font-size: 12px;
    color: #2f3f67;
}

.intro-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.primary-btn {
    border: none;
    background: linear-gradient(135deg, #235dff, #2f83ff);
    color: #fff;
    border-radius: 999px;
    padding: 10px 16px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    cursor: pointer;
}

.primary-btn:hover {
    filter: brightness(1.04);
}

.intro-link {
    color: #1b4db4;
    text-decoration: none;
    font-size: 13px;
}

#spider-chart,
#scatter-chart {
    display: flex;
    justify-content: center;
    align-items: center;
}

@media (max-width: 1200px) {
    .dashboard {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 108px);
    }

    .tree-panel,
    .details-panel {
        min-height: 520px;
    }

    body {
        overflow-y: auto;
    }
}

@media (max-width: 760px) {
    .dashboard-header {
        padding: 14px 12px 8px;
    }

    .dashboard-header h1 {
        font-size: 24px;
    }

    .dashboard {
        padding: 0 8px 8px;
        gap: 8px;
    }

    .control-grid {
        grid-template-columns: 1fr;
    }

    .kpi-grid,
    .meta-grid {
        grid-template-columns: 1fr;
    }

    .chain-flow {
        grid-template-columns: 1fr;
    }

    .chain-arrow {
        display: none;
    }

    .intro-content {
        margin: 16px 8px;
        padding: 16px;
    }

    .intro-content h1 {
        font-size: 30px;
    }

    .intro-columns {
        grid-template-columns: 1fr;
    }
}
