:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel-2: #18212f;
  --line: #243042;
  --text: #e6edf6;
  --dim: #8295ad;
  --accent: #5b8cff;
  --good: #2ecc8f;
  --warn: #f2b134;
  --gold: #f4c25e;
  --bad: #ff5c63;
  --rogue: #ff5c63;
  --paused: #f2b134;
  --healthy: #2ecc8f;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #16243b 0%, var(--bg) 55%);
  color: var(--text);
}
h1, h2 { margin: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(11,15,23,0.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brandmark { width: 28px; height: 28px; color: var(--accent); display: block; transition: transform .2s ease; }
@keyframes brandpulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 transparent); }
  35% { transform: scale(1.18); filter: drop-shadow(0 0 6px rgba(91, 140, 255, .7)); }
}
.brandmark.pulse { animation: brandpulse 0.75s ease; }
.brand h1 { font-family: var(--mono); font-size: 22px; letter-spacing: 4px; font-weight: 700; line-height: 1.1; }
.tagline { margin: 0; font-size: 12px; color: var(--dim); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--dim);
}
.badge.tick { color: var(--accent); font-variant-numeric: tabular-nums; font-family: var(--mono); }
.badge { font-family: var(--mono); font-size: 11px; }
.badge.loading { color: var(--dim); animation: badgepulse 1.4s ease-in-out infinite; }
@keyframes badgepulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

.btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); padding: 7px 12px; border-radius: 8px; font-size: 13px;
  transition: transform .05s ease, background .15s ease;
}
.btn:hover { background: #202c3e; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.approve { background: rgba(46,204,143,.15); border-color: var(--good); color: var(--good); }
.btn.deny { background: rgba(255,92,99,.15); border-color: var(--bad); color: var(--bad); }

.approval {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin: 14px 22px; padding: 14px 18px; border-radius: 12px;
  background: linear-gradient(90deg, rgba(242,177,52,.18), rgba(242,177,52,.04));
  border: 1px solid var(--warn);
  animation: pulse 1.6s infinite;
}
.approval.hidden { display: none; }
.approval-text span { color: var(--dim); margin-left: 8px; }
.approval-actions { display: flex; gap: 10px; flex-shrink: 0; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(242,177,52,.25);} 50% { box-shadow: 0 0 0 6px rgba(242,177,52,0);} }

.metrics {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
  padding: 16px 22px;
}
.metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 6px;
}
.m-label { font-size: 12px; color: var(--dim); }
.m-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.metric.good .m-value { color: var(--good); }
.metric.good .m-value.has-value { color: var(--gold); } /* warm gold when recovered $ > 0 */
.metric.bad .m-value { color: var(--bad); }

.grid {
  display: grid; grid-template-columns: 300px 1fr 360px; gap: 16px;
  padding: 6px 22px 28px;
  transition: opacity 0.3s ease, filter 0.3s ease;
}
.grid.resetting { opacity: 0.35; filter: blur(1px); pointer-events: none; }
.btn:disabled { opacity: 0.55; cursor: progress; pointer-events: none; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; min-height: 60vh;
}
.panel h2 {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text); margin-bottom: 14px; line-height: 1.4;
}
.panel h2 .section-num {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  color: var(--accent); opacity: 0.5; letter-spacing: 1px;
}
.panel h2 .dim { text-transform: none; letter-spacing: 0; font-size: 11px; }

.fleet { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.agent {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-radius: 10px; background: var(--panel-2);
  border: 1px solid var(--line); transition: border-color .2s;
}
.agent .name { font-weight: 600; }
.agent .domain { font-size: 11px; color: var(--dim); }
.state {
  font-size: 11px; padding: 4px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .5px;
}
.state.healthy { background: rgba(46,204,143,.15); color: var(--healthy); }
.state.rogue { background: rgba(255,92,99,.18); color: var(--rogue); }
.state.paused { background: rgba(242,177,52,.18); color: var(--paused); }
.agent.rogue { border-color: var(--rogue); animation: shake .4s; }
@keyframes shake { 25%{transform:translateX(-2px)} 75%{transform:translateX(2px)} }

.scenarios { display: flex; flex-direction: column; gap: 8px; }
.scenario-btn { text-align: left; }
.scenario-btn small { display: block; color: var(--dim); margin-top: 3px; font-size: 11px; }

.feed { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow-y: auto; font-size: 13px; }
.line { padding: 8px 12px; border-radius: 8px; background: var(--panel-2); border-left: 3px solid var(--line); }
.line .tag { font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 1.5px; margin-right: 8px; }
.line.sense { border-left-color: var(--accent); }
.line.diagnose { border-left-color: #b07cff; }
.line.plan { border-left-color: var(--warn); }
.line.action { border-left-color: var(--good); }
.line.incident { border-left-color: var(--bad); background: rgba(255,92,99,.08); }
.line.chaos { border-left-color: var(--bad); background: rgba(255,92,99,.12); font-weight: 600; }
.line.approval { border-left-color: var(--warn); }
.line .tag.sense { color: var(--accent); }
.line .tag.diagnose { color: #b07cff; }
.line .tag.plan { color: var(--warn); }
.line .tag.action { color: var(--good); }
.line .tag.incident, .line .tag.chaos { color: var(--bad); }

.incidents { display: flex; flex-direction: column; gap: 10px; }
.incident {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  transition: border-color .15s ease, transform .05s ease;
}
.incident.clickable { cursor: pointer; }
.incident.clickable:hover { border-color: var(--accent); }
.incident.clickable:active { transform: translateY(1px); }
.incident .ihead { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
.pill {
  display: inline-block; font-family: var(--mono); font-size: 9px;
  padding: 2px 7px; border-radius: 4px; text-transform: uppercase;
  letter-spacing: 1px; font-weight: 600; margin-left: 6px; vertical-align: middle;
  white-space: nowrap;
}
.pill.autonomous { background: rgba(46, 204, 143, .15); color: var(--good); }
.pill.gated      { background: rgba(242, 177, 52, .18); color: var(--warn); }
.incidents-empty {
  border: 1px dashed var(--line); border-radius: 10px;
  padding: 14px 16px; background: rgba(91, 140, 255, .04);
}
.incidents-empty p { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.6; }
.incidents-empty .arrow {
  color: var(--accent); font-weight: 700; margin-right: 6px;
  font-family: var(--mono);
}
.incident .imeta { font-size: 12px; color: var(--dim); line-height: 1.7; }
.incident .ok { color: var(--good); }
.incident .no { color: var(--bad); }

/* Incident detail modal */
.modal {
  position: fixed; inset: 0; background: rgba(7, 11, 18, 0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 20; padding: 24px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px 28px; max-width: 760px; width: 100%; max-height: 84vh; overflow-y: auto;
  position: relative; box-shadow: 0 24px 48px rgba(0,0,0,.6);
}
.modal-card h2 { font-size: 18px; margin-bottom: 4px; }
.modal-card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); margin: 18px 0 8px; }
.modal-card p { font-size: 13px; line-height: 1.55; color: var(--text); margin: 8px 0; }
.modal-close {
  position: absolute; top: 12px; right: 14px; background: transparent; border: 0;
  color: var(--dim); font-size: 24px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.modal-card table.kv th { text-align: left; color: var(--dim); font-weight: 500; padding: 4px 12px 4px 0; width: 36%; vertical-align: top; }
.modal-card table.kv td { padding: 4px 0; vertical-align: top; }
.modal-card table.plan th { text-align: left; color: var(--dim); font-weight: 500; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
.modal-card table.plan td { padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.modal-card .ok { color: var(--good); }
.modal-card .no { color: var(--bad); }

.dim { color: var(--dim); }
.hidden { display: none; }

/* Skeleton placeholders shown during the brief window between page load and
   first-state hydration. Server-rendered initial state usually beats this to
   the screen; this is the belt-and-suspenders for slow connections / cold
   starts so the operator console never paints blank. */
.skeleton-row, .skeleton-btn, .feed-placeholder {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  animation: skel 1.6s ease-in-out infinite;
}
.skeleton-row { height: 56px; margin-bottom: 10px; }
.skeleton-btn { height: 50px; margin-bottom: 8px; }
.feed-placeholder { padding: 8px 12px; }
@keyframes skel {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 0.7; }
}

/* Tabs */
.tabs {
  display: flex; gap: 4px; padding: 14px 22px 0;
  border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.tab {
  background: transparent; border: 0; color: var(--dim);
  padding: 10px 18px 12px; font-family: var(--mono); font-size: 12px;
  letter-spacing: 1.5px; text-transform: uppercase; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color .15s ease, border-color .15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 1px dashed var(--accent); outline-offset: -2px; }

/* Live Evidence view */
.evidence-intro {
  margin: 8px 22px 16px; padding: 18px 20px;
  min-height: auto;
}
.evidence-intro h2 { margin-bottom: 10px; }
.evidence-intro p { font-size: 13px; line-height: 1.65; color: var(--text); margin: 0 0 14px; max-width: 880px; }
.evidence-meta { display: flex; flex-wrap: wrap; gap: 8px; }

.evidence-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px; padding: 0 22px 28px;
}
.evidence-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.evidence-card h3 {
  margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .2px;
}
.evidence-card .caption { font-size: 12.5px; color: var(--dim); line-height: 1.55; margin: 0; }
.evidence-card .frame {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--panel-2); aspect-ratio: 16 / 9;
  display: flex; align-items: center; justify-content: center;
}
.evidence-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.evidence-card .placeholder {
  text-align: center; padding: 24px; color: var(--dim); font-family: var(--mono);
  font-size: 12px; line-height: 1.6;
}
.evidence-card .placeholder strong { color: var(--text); font-weight: 600; display: block; margin-bottom: 6px; }
.evidence-card .tags {
  display: flex; flex-wrap: wrap; gap: 6px;
  font-family: var(--mono); font-size: 10px;
}
.evidence-card .tags span {
  padding: 2px 7px; border-radius: 4px; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--dim);
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics .metric:last-child { grid-column: span 2; }
  .evidence-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .brandmark.pulse { animation: none; }
  .approval { animation: none; }
  .agent.rogue { animation: none; }
  .grid.resetting { transition: none; }
  .badge.loading, .skeleton-row, .skeleton-btn, .feed-placeholder { animation: none; opacity: 0.5; }
}
