*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0b0e14;
    --bg-card: #131820;
    --border: #1e2530;
    --text: #d4d8e0;
    --text-dim: #6b7280;
    --accent: #60a5fa;

    --calm: #22c55e;
    --transition: #eab308;
    --dislocation: #f97316;
    --breakdown: #ef4444;

    --score-good: #22c55e;
    --score-mid: #eab308;
    --score-bad: #ef4444;
}

body {
    font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", "Fira Code", monospace;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 1px;
}

.subtitle {
    color: var(--text-dim);
    font-size: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.system-health {
    display: flex;
    align-items: center;
    gap: 6px;
}

#health-label {
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 1px;
}

.health-healthy { color: var(--calm); }
.health-degraded { color: var(--transition); }
.health-critical { color: var(--breakdown); }

.header-sep {
    width: 1px;
    height: 16px;
    background: var(--border);
    display: inline-block;
    margin: 0 4px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot-ok { background: var(--calm); }
.dot-warn { background: var(--transition); }
.dot-error { background: var(--breakdown); }
.dot-unknown { background: var(--text-dim); }

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px 24px;
}

h2 {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

/* System overview */
.system-overview-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.system-overview {
    display: flex;
    justify-content: space-around;
    text-align: center;
}

/* Regime gauge */
.regime-gauge {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gauge-track {
    position: relative;
    display: flex;
    height: 10px;
    border-radius: 5px;
    overflow: visible;
}

.gauge-seg {
    flex: 1;
    height: 100%;
}

.gauge-seg:first-child { border-radius: 5px 0 0 5px; }
.gauge-seg:nth-child(4) { border-radius: 0 5px 5px 0; }

.gauge-calm { background: var(--calm); opacity: 0.35; }
.gauge-transition { background: var(--transition); opacity: 0.35; }
.gauge-dislocation { background: var(--dislocation); opacity: 0.35; }
.gauge-breakdown { background: var(--breakdown); opacity: 0.35; }

.gauge-marker {
    position: absolute;
    top: -3px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 7px solid var(--text);
    transform: translateX(-5px);
    transition: left 0.4s ease;
    left: 0%;
}

.gauge-labels {
    display: flex;
    font-size: 9px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gauge-labels span {
    flex: 1;
    text-align: center;
}

.metric-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.metric-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
}

.metric-dim {
    color: var(--text-dim);
    font-weight: 400;
}

/* Regime transition pulse */
.regime-transition {
    animation: regimePulse 0.8s ease-out;
}

.regime-transition.state-calm {
    box-shadow: 0 0 16px rgba(34, 197, 94, 0.5);
}

.regime-transition.state-transition {
    box-shadow: 0 0 16px rgba(234, 179, 8, 0.5);
}

.regime-transition.state-dislocation {
    box-shadow: 0 0 16px rgba(249, 115, 22, 0.5);
}

.regime-transition.state-breakdown {
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.5);
}

@keyframes regimePulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* Baseline status */
.baseline-status {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.baseline-init {
    color: var(--text-dim);
}

.baseline-warmup {
    color: var(--transition);
}

.baseline-ready {
    color: var(--calm);
}

/* State badges */
.state-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
}

.state-calm { background: rgba(34, 197, 94, 0.15); color: var(--calm); }
.state-transition { background: rgba(234, 179, 8, 0.15); color: var(--transition); }
.state-dislocation { background: rgba(249, 115, 22, 0.15); color: var(--dislocation); }
.state-breakdown { background: rgba(239, 68, 68, 0.15); color: var(--breakdown); }
.state-unknown { background: rgba(107, 114, 128, 0.15); color: var(--text-dim); }

/* Feed states */
.state-stable { background: rgba(34, 197, 94, 0.15); color: var(--calm); }
.state-watch { background: rgba(234, 179, 8, 0.15); color: var(--transition); }
.state-stressed { background: rgba(249, 115, 22, 0.15); color: var(--dislocation); }
.state-critical { background: rgba(239, 68, 68, 0.15); color: var(--breakdown); }

/* Regime Drivers */
.drivers {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.driver-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.driver-label {
    font-size: 12px;
    color: var(--text-dim);
    min-width: 180px;
    flex-shrink: 0;
}

.driver-bar-track {
    flex: 1;
    height: 16px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.driver-bar {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    transition: width 0.4s ease, background-color 0.4s ease;
}

.driver-value {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    text-align: right;
}

/* Mode Toggle */
.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.timeline-header h2 {
    margin-bottom: 0;
}

.mode-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mode-btn {
    background: var(--border);
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 4px 14px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.mode-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.mode-btn:nth-child(2) {
    border-radius: 0 4px 4px 0;
}

.mode-btn-active {
    background: var(--accent);
    color: #0b0e14;
    border-color: var(--accent);
}

.mode-btn:not(.mode-btn-active):hover {
    background: #1e2530;
    color: var(--text);
}

.replay-status {
    font-size: 11px;
    color: var(--accent);
    margin-left: 8px;
    min-width: 80px;
}

/* Timeline heatmap strip */
.timeline-strip {
    display: flex;
    height: 14px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--border);
}

.timeline-segment {
    flex: 1;
    height: 100%;
}

.timeline-calm { background: var(--calm); }
.timeline-transition { background: var(--transition); }
.timeline-dislocation { background: var(--dislocation); }
.timeline-breakdown { background: var(--breakdown); }

.timeline-legend {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-dim);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

tr:last-child td {
    border-bottom: none;
}

.muted {
    color: var(--text-dim);
    text-align: center;
    font-size: 13px;
}

.score {
    font-weight: 600;
}

.score-good { color: var(--score-good); }
.score-mid { color: var(--score-mid); }
.score-bad { color: var(--score-bad); }

/* Events */
.events-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow-y: auto;
}

.event-row {
    display: flex;
    gap: 12px;
    align-items: baseline;
    font-size: 13px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.event-row:last-child {
    border-bottom: none;
}

.event-time {
    color: var(--text-dim);
    font-size: 11px;
    white-space: nowrap;
    min-width: 80px;
}

.event-type {
    font-weight: 600;
    min-width: 180px;
}

.event-detail {
    color: var(--text-dim);
    font-size: 12px;
}

/* Scrollbar */
.events-list::-webkit-scrollbar {
    width: 4px;
}

.events-list::-webkit-scrollbar-track {
    background: transparent;
}

.events-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}
