:root {
    color-scheme: dark;
    --bg: #090d14;
    --panel: #111824;
    --panel-2: #151f2f;
    --line: #263244;
    --text: #e7edf7;
    --muted: #94a3b8;
    --faint: #65758b;
    --accent: #2dd4bf;
    --accent-2: #60a5fa;
    --warn: #f59e0b;
    --bad: #fb7185;
    --good: #34d399;
    --shadow: 0 20px 70px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { min-width: 0; }
body {
    margin: 0;
    background:
        radial-gradient(circle at 18% 0%, rgba(45, 212, 191, .10), transparent 30%),
        radial-gradient(circle at 85% 8%, rgba(96, 165, 250, .12), transparent 28%),
        var(--bg);
    color: var(--text);
    font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
    overflow-x: hidden;
}

button, input, textarea { font: inherit; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
    width: min(1440px, 100vw);
    margin: 0 auto;
    padding: 22px;
    display: grid;
    gap: 16px;
    overflow-x: clip;
}
.app-shell > * { min-width: 0; max-width: 100%; }

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-end;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(28px, 4vw, 48px); line-height: 1.02; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 16px; letter-spacing: 0; }
h3 { margin-bottom: 8px; font-size: 15px; letter-spacing: 0; }
h1, h2, h3, p, span, div { overflow-wrap: anywhere; }
.subtle, .muted { color: var(--muted); }
.subtle { margin-bottom: 0; max-width: 760px; }

.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.icon-btn, .ghost-link, .tab {
    border: 1px solid var(--line);
    color: var(--text);
    background: rgba(17, 24, 36, .92);
    border-radius: 8px;
    padding: 10px 12px;
    min-height: 40px;
    cursor: pointer;
}
.icon-btn:hover, .ghost-link:hover, .tab:hover { border-color: var(--accent-2); text-decoration: none; }

.tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-color: var(--line) transparent;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}
.tab {
    white-space: nowrap;
    color: var(--muted);
}
.tab.active {
    color: #06201d;
    background: linear-gradient(135deg, var(--accent), #7dd3fc);
    border-color: transparent;
    font-weight: 800;
}

.status-strip, .panel, .metric-card, .selector-panel {
    background: rgba(17, 24, 36, .88);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.status-strip {
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    min-width: 0;
    max-width: 100%;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; min-width: 0; max-width: 100%; }

.grid { display: grid; gap: 14px; }
.metrics-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); margin-top: 14px; }

.panel, .metric-card, .selector-panel { padding: 14px; min-width: 0; }
.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}
.panel-head.compact { margin-bottom: 8px; }

.metric-card .label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.metric-card .value { font-size: 28px; line-height: 1.1; font-weight: 850; margin-top: 6px; overflow-wrap: anywhere; }
.metric-card .note { color: var(--faint); margin-top: 6px; font-size: 12px; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    white-space: nowrap;
}
.pill.good { color: #022c22; background: var(--good); border-color: transparent; }
.pill.warn { color: #331b00; background: var(--warn); border-color: transparent; }
.pill.bad { color: #3f0612; background: var(--bad); border-color: transparent; }

.kv-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kv {
    padding: 10px;
    background: rgba(21, 31, 47, .78);
    border: 1px solid rgba(38, 50, 68, .8);
    border-radius: 8px;
    min-width: 0;
}
.kv .k { color: var(--faint); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.kv .v { margin-top: 4px; overflow-wrap: anywhere; }

.log-box {
    max-height: 360px;
    overflow: auto;
    display: grid;
    gap: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: #cbd5e1;
}
.log-line { padding: 5px 8px; background: rgba(4, 8, 15, .42); border-radius: 6px; overflow-wrap: anywhere; }

.report-list, .case-list { display: grid; gap: 8px; }
.report-item, .select-item {
    width: 100%;
    text-align: left;
    color: var(--text);
    background: rgba(21, 31, 47, .78);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
}
.report-item:hover, .select-item:hover, .select-item.active { border-color: var(--accent); }
.select-item.active { background: rgba(45, 212, 191, .12); }
.small-line { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }

.split-layout {
    display: grid;
    grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}
.selector-panel {
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    overflow: auto;
}
.detail-stack { display: grid; gap: 14px; min-width: 0; }

.ledger-grid, .agent-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.compact-ledger { grid-template-columns: 1fr; }
.ledger-card, .agent-card {
    background: rgba(17, 24, 36, .88);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    min-width: 0;
}
.prob-row { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); margin-bottom: 8px; }
.meter { height: 8px; border-radius: 999px; overflow: hidden; background: #0b1220; border: 1px solid #1e293b; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.evidence-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.evidence-box { background: rgba(4, 8, 15, .38); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-width: 0; }
.evidence-box strong { display: block; margin-bottom: 6px; }
ul.clean { margin: 0; padding-left: 18px; }
ul.clean li { margin: 3px 0; overflow-wrap: anywhere; }

details {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: rgba(4, 8, 15, .30);
}
summary { cursor: pointer; color: var(--accent-2); font-weight: 800; }

.flowchart {
    display: flex;
    gap: 10px;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 4px;
}
.flow-node {
    border: 1px solid var(--line);
    background: rgba(21, 31, 47, .78);
    border-radius: 8px;
    padding: 12px;
    min-height: 104px;
    min-width: 120px;
    flex: 1 0 120px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}
.flow-node:hover, .flow-node:focus-visible { border-color: var(--accent-2); outline: none; }
.flow-node.done { border-color: rgba(52, 211, 153, .75); }
.flow-node.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.flow-node.blocked { border-color: var(--warn); }
.flow-node h3 { margin-bottom: 6px; }

.monitor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(280px, .85fr);
    gap: 14px;
    align-items: start;
}

.monitor-main, .stage-panel { min-height: 100%; }

.monitor-flowchart {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    min-width: 0;
}

.monitor-node {
    position: relative;
    min-height: 178px;
    display: grid;
    align-content: start;
    gap: 7px;
    flex: initial;
    min-width: 0;
}

.monitor-node::after {
    content: "";
    position: absolute;
    right: -11px;
    top: 50%;
    width: 11px;
    height: 1px;
    background: var(--line);
}

.monitor-node:last-child::after { display: none; }
.monitor-node.visited { border-color: rgba(52, 211, 153, .70); }
.monitor-node.pending { opacity: .78; }
.monitor-node.selected {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent), 0 12px 36px rgba(45, 212, 191, .10);
}

.phase-index {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(45, 212, 191, .14);
    color: var(--accent);
    font-weight: 850;
    border: 1px solid rgba(45, 212, 191, .32);
}

.stage-detail {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.monitor-lower { margin-top: 14px; }

.data-tree { display: grid; gap: 10px; }
.data-section {
    border: 1px solid var(--line);
    background: rgba(21, 31, 47, .66);
    border-radius: 8px;
    padding: 10px;
    min-width: 0;
}
.data-title { color: var(--accent); font-weight: 850; margin-bottom: 8px; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th, .data-table td { border-top: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.data-table th { width: 190px; color: var(--muted); font-weight: 750; }

.empty {
    color: var(--muted);
    padding: 16px;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

@media (max-width: 1180px) {
    .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .ledger-grid, .agent-grid { grid-template-columns: 1fr; }
    .monitor-grid { grid-template-columns: 1fr; }
    .monitor-flowchart { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .monitor-node::after { display: none; }
}

@media (max-width: 820px) {
    .app-shell { padding: 14px; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .metrics-grid, .two-col, .split-layout { grid-template-columns: 1fr; }
    .selector-panel { position: static; max-height: none; }
    .kv-list, .evidence-grid { grid-template-columns: 1fr; }
    .flow-node { flex: 1 0 150px; }
    .monitor-flowchart { grid-template-columns: 1fr; }
    .monitor-node { min-height: 132px; }
    .data-table th, .data-table td { display: block; width: 100%; }
    .data-table td { border-top: 0; padding-top: 0; }
}

@media (max-width: 430px) {
    .app-shell { padding: 10px; gap: 12px; }
    h1 { font-size: 28px; }
    .panel, .metric-card, .selector-panel { padding: 12px; }
    .metric-card .value { font-size: 24px; }
    .top-actions { align-self: stretch; width: auto; }
    .icon-btn, .ghost-link { flex: 1 1 0; min-width: 0; text-align: center; }
}
