/* ChangeProof — blast-radius review UI
   Single design system. Impact score is radial distance; risk is color. */

:root {
    --bg: #0e1117;
    --bg-elev: #161b22;
    --bg-sink: #0a0d12;
    --panel: #12161d;
    --border: #232a34;
    --border-soft: #1b212a;
    --text: #e6edf3;
    --text-dim: #9aa7b4;
    --text-faint: #64707d;
    --accent: #6ea8fe;
    --accent-glow: rgba(110, 168, 254, 0.35);

    /* risk ramp — perceptually spaced, works in both themes */
    --risk-low: #3fb950;
    --risk-medium: #d9a441;
    --risk-high: #f0883e;
    --risk-critical: #f85149;

    /* node kinds */
    --kind-file: #58a6ff;
    --kind-class: #f0883e;
    --kind-function: #3fb950;
    --kind-type: #a78bfa;
    --kind-test: #8b949e;

    --ring-line: rgba(255, 255, 255, 0.05);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 340px;
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #f6f8fa;
    --bg-elev: #ffffff;
    --bg-sink: #eaeef2;
    --panel: #ffffff;
    --border: #d5dbe1;
    --border-soft: #e6ebf0;
    --text: #1c2530;
    --text-dim: #556170;
    --text-faint: #8b96a2;
    --accent: #2f6fed;
    --accent-glow: rgba(47, 111, 237, 0.2);
    --ring-line: rgba(0, 0, 0, 0.05);
    --shadow: 0 8px 30px rgba(20, 30, 45, 0.12);
    color-scheme: light;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
}

/* ---- sidebar ---- */

#sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-soft);
}

.brand-mark svg {
    display: block;
}

.bm-core {
    fill: var(--accent);
}

.bm-ring {
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.2;
    opacity: 0.6;
}

.bm-ring-faint {
    opacity: 0.25;
}

.brand h1 {
    font-size: 18px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 1px;
}

.controls {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-bottom: 1px solid var(--border-soft);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
}

.field>span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    font-weight: 600;
}

.field-row {
    display: flex;
    gap: 10px;
}

input[type="text"] {
    background: var(--bg-sink);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 9px 11px;
    font-size: 13px;
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

button.primary {
    position: relative;
    background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 82%, #000));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s var(--ease), filter 0.15s, box-shadow 0.2s;
    box-shadow: 0 2px 10px var(--accent-glow);
}

button.primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 18px var(--accent-glow);
}

button.primary:active {
    transform: translateY(1px);
}

button.primary:disabled {
    cursor: wait;
    filter: saturate(0.5) brightness(0.9);
}

.spinner {
    display: none;
    position: absolute;
    right: 14px;
    top: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

button.primary.loading .spinner {
    display: block;
}

button.primary.loading .btn-label {
    opacity: 0.6;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.status-line {
    font-size: 12px;
    color: var(--text-dim);
    min-height: 16px;
}

#export-btn {
    width: 100%;
    padding: 9px;
}

/* embedded-snapshot note (replaces controls in exported HTML) */
.snapshot-note {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.snap-tag {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--accent);
    width: fit-content;
    padding: 2px 7px;
    border: 1px solid var(--accent);
    border-radius: 5px;
    margin-bottom: 4px;
}

.snap-repo {
    font-family: ui-monospace, monospace;
    font-size: 13px;
    color: var(--text);
    word-break: break-all;
}

.snap-range {
    font-family: ui-monospace, monospace;
    font-size: 12px;
    color: var(--text-dim);
}

.snap-when {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 2px;
}

.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    padding: 6px 11px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ghost:hover {
    background: var(--bg-elev);
    color: var(--text);
    border-color: var(--text-faint);
}

/* ---- verdict ---- */

.verdict {
    margin: 16px 20px 4px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elev);
    position: relative;
    overflow: hidden;
    animation: rise 0.4s var(--ease);
}

.verdict::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--verdict-color, var(--text-faint));
}

.verdict .v-score {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
    color: var(--verdict-color);
}

.verdict .v-level {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--verdict-color);
    margin-top: 4px;
}

.verdict .v-meta {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 8px;
    line-height: 1.5;
}

.verdict .v-driver {
    font-family: ui-monospace, monospace;
    color: var(--text);
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* "nothing found" is an answer, not a dead end — explain and offer a next step */
.nothing-found {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px 15px;
    animation: rise 0.4s var(--ease);
}

.nf-title {
    font-size: 13px;
    font-weight: 650;
    color: var(--text);
    margin-bottom: 6px;
}

.nothing-found p {
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--text-dim);
}

.nothing-found code {
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
    color: var(--text);
    background: var(--bg-sink);
    padding: 1px 5px;
    border-radius: 4px;
}

.nf-files {
    list-style: none;
    margin: 8px 0 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nf-files li {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- findings ---- */

.findings {
    flex: 1;
    overflow-y: auto;
    padding: 8px 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

.finding {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 13px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.12s var(--ease), box-shadow 0.2s;
    animation: rise 0.4s var(--ease) backwards;
}

.finding:hover {
    border-color: var(--f-color);
    transform: translateX(2px);
    box-shadow: var(--shadow);
}

.finding.active {
    border-color: var(--f-color);
    box-shadow: 0 0 0 1px var(--f-color), var(--shadow);
}

.finding-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.sev-badge {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 5px;
    color: #fff;
    background: var(--f-color);
    flex-shrink: 0;
}

.finding-name {
    font-family: ui-monospace, monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.finding-risk {
    margin-left: auto;
    font-size: 12px;
    font-weight: 700;
    color: var(--f-color);
    font-variant-numeric: tabular-nums;
}

.finding-loc {
    font-size: 11px;
    color: var(--text-faint);
    font-family: ui-monospace, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.finding-reasons {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 6px;
    line-height: 1.4;
}

.finding-stats {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-faint);
}

.finding-stats b {
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* ---- footer ---- */

.side-footer {
    border-top: 1px solid var(--border-soft);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logs {
    flex: 1;
    font-size: 11px;
}

.logs summary {
    cursor: pointer;
    color: var(--text-faint);
    list-style: none;
}

.logs summary::-webkit-details-marker {
    display: none;
}

.logs pre {
    margin-top: 8px;
    max-height: 120px;
    overflow-y: auto;
    color: var(--text-faint);
    font-family: ui-monospace, monospace;
    font-size: 10.5px;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* ---- stage / graph ---- */

#stage {
    position: relative;
    background:
        radial-gradient(1200px 800px at 60% 40%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 70%),
        var(--bg);
    overflow: hidden;
}

#graph {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#graph:active {
    cursor: grabbing;
}

.graph-toolbar {
    position: absolute;
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 5;
    pointer-events: none;
}

.graph-toolbar>* {
    pointer-events: auto;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    background: color-mix(in srgb, var(--panel) 82%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-dim);
}

.legend-swatch {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.legend-line {
    width: 14px;
    height: 0;
    border-top: 1.5px solid var(--text-faint);
}

.legend-line.inferred {
    border-top-style: dashed;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    background: color-mix(in srgb, var(--panel) 82%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
}
.view-switch { display: flex; gap: 3px; }
.view-btn { padding: 4px 7px; font-size: 10px; }
.view-btn.active { color: var(--text); background: var(--bg-elev); }
.view-hidden { opacity: 0 !important; pointer-events: none !important; }

.toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}

/* ring guides */
.ring-guide {
    fill: none;
    stroke: var(--ring-line);
    stroke-width: 1;
}

.ring-label {
    fill: var(--text-faint);
    font-size: 10px;
    font-family: ui-monospace, monospace;
    opacity: 0.55;
}

/* edges */
.edge {
    fill: none;
    stroke: var(--border);
    stroke-width: 1;
    opacity: 0.5;
    transition: opacity 0.2s, stroke 0.2s;
}

.edge.inferred {
    stroke-dasharray: 5 4;
    opacity: 0.38;
}

.edge.verified {
    opacity: 0.58;
}

.edge.dim {
    opacity: 0.07;
}

.edge.hot {
    stroke: var(--accent);
    opacity: 0.9;
    stroke-width: 1.6;
}

.dp-evidence {
    margin: 10px 0 14px;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 11px;
}

.dp-evidence.inferred {
    border-style: dashed;
    color: var(--text-faint);
}

.dp-status { margin-top: 8px; font: 700 11px ui-monospace, monospace; }
.dp-assertion { max-height: 180px; overflow: auto; white-space: pre-wrap; font-size: 10px; }

.timeline {
    position: absolute; left: 18px; right: 18px; bottom: 16px; z-index: 6;
    display: flex; gap: 16px; overflow-x: auto; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: 10px;
    background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(10px);
}
.timeline-event { display: grid; grid-template-columns: auto auto; gap: 2px 6px; min-width: max-content; color: var(--text-dim); font-size: 10px; }
.timeline-event b { color: var(--text); font-size: 11px; }
.timeline-dot { grid-row: 1 / 3; align-self: center; width: 7px; height: 7px; border-radius: 50%; background: #888fa3; }
.timeline-event[data-status="PROVEN_REGRESSION"] .timeline-dot,
.timeline-event[data-status="FAIL"] .timeline-dot { background: #ff5964; }
.timeline-event[data-status="PATCH_VERIFIED"] .timeline-dot,
.timeline-event[data-status="PASS"] .timeline-dot { background: #65d69e; }

.stage-rail { position:absolute; top:72px; right:16px; z-index:5; display:flex; flex-direction:column; gap:5px; }
.stage-pill { display:grid; grid-template-columns:70px 78px; text-align:left; border:1px solid var(--border); border-radius:7px; padding:6px 8px; background:color-mix(in srgb,var(--panel) 90%,transparent); color:var(--text-dim); cursor:pointer; }
.stage-pill b { color:var(--text); font-size:10px; }.stage-pill span { font-size:9px; text-align:right; }
.stage-pill[data-status="PASSED"] { border-color:#65d69e66; }.stage-pill[data-status="FAILED"] { border-color:#ff596488; }
.stage-pill[data-status="RUNNING"] { border-color:#8b7cff88; }.stage-pill.active { box-shadow:0 0 0 1px var(--accent); }

/* nodes */
.node {
    cursor: pointer;
}

.node-dot {
    stroke: var(--bg);
    stroke-width: 1.5;
    transition: opacity 0.2s, filter 0.15s;
}

.node.seed .node-dot {
    stroke: var(--text);
    stroke-width: 2;
}

.node.dim {
    opacity: 0.22;
}

.node:hover .node-dot,
.node.active .node-dot {
    filter: brightness(1.3);
}

.node-halo {
    fill: none;
    opacity: 0;
}

.node.seed .node-halo {
    opacity: 0.4;
    animation: pulse 2.6s var(--ease) infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.15;
    }

    50% {
        opacity: 0.4;
    }
}

.node-label {
    fill: var(--text-dim);
    font-size: 10px;
    font-family: ui-monospace, monospace;
    pointer-events: none;
    text-anchor: middle;
    paint-order: stroke;
    stroke: var(--bg);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.node.seed .node-label {
    fill: var(--text);
    font-weight: 600;
}

.labels-hidden .node-label {
    display: none;
}

/* detail panel */
.detail-panel {
    position: absolute;
    top: 64px;
    right: 14px;
    width: 300px;
    max-height: calc(100% - 90px);
    overflow-y: auto;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    z-index: 8;
    animation: slideIn 0.28s var(--ease);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(16px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.detail-panel .dp-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.detail-panel .dp-close:hover {
    color: var(--text);
}

.dp-kind {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    margin-bottom: 4px;
}

.dp-name {
    font-family: ui-monospace, monospace;
    font-size: 15px;
    font-weight: 650;
    word-break: break-word;
    margin-bottom: 2px;
}

.dp-loc {
    font-size: 11px;
    color: var(--text-faint);
    font-family: ui-monospace, monospace;
    margin-bottom: 14px;
    word-break: break-all;
}

.dp-metric-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
}

.dp-metric {
    flex: 1;
    background: var(--bg-sink);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    text-align: center;
}

.dp-metric .m-val {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.dp-metric .m-lbl {
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

.dp-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    font-weight: 600;
    margin: 14px 0 6px;
}

.dp-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.dp-list li {
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
    color: var(--text-dim);
    padding: 4px 7px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.12s;
}

.dp-list li:hover {
    background: var(--bg-elev);
    color: var(--text);
}

.dp-list li .li-score {
    color: var(--accent);
    margin-right: 6px;
}

/* tooltip */
.tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--bg-sink);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 9px;
    font-size: 11.5px;
    font-family: ui-monospace, monospace;
    color: var(--text);
    box-shadow: var(--shadow);
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 20;
    max-width: 280px;
}

.tooltip.show {
    opacity: 1;
}

.tooltip .tt-score {
    color: var(--accent);
}

/* empty state */
.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    gap: 6px;
    pointer-events: none;
}

.empty-state.hidden {
    display: none;
}

.empty-art {
    margin-bottom: 12px;
    opacity: 0.9;
}

.es-ring {
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.5;
    transform-origin: center;
}

.es-r1 {
    opacity: 0.5;
    animation: breathe 3s var(--ease) infinite;
}

.es-r2 {
    opacity: 0.28;
    animation: breathe 3s var(--ease) 0.4s infinite;
}

.es-r3 {
    opacity: 0.14;
    animation: breathe 3s var(--ease) 0.8s infinite;
}

.es-core {
    fill: var(--accent);
}

@keyframes breathe {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.empty-state p {
    font-size: 13.5px;
    color: var(--text-dim);
    max-width: 380px;
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* scrollbars */
::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

::-webkit-scrollbar-track {
    background: transparent;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
