/* ============================================================
   KAIROS AI — COMMAND CENTER
   Dark HUD. Gold = agency / signal. Cyan = system / structure.
   One machined grid: header, three panels, stats bar share the
   same 1px line, the same corner brackets, the same 20px rhythm.
   ============================================================ */

:root {
  --bg: #050508;
  --bg-panel: rgba(9, 10, 17, 0.82);
  --bg-raised: #0c0e17;
  --line: rgba(78, 201, 212, 0.2);
  --line-strong: rgba(78, 201, 212, 0.45);
  --gold: #d4a24e;
  --gold-dim: rgba(212, 162, 78, 0.4);
  --gold-glow: rgba(212, 162, 78, 0.22);
  --cyan: #4ec9d4;
  --cyan-dim: rgba(78, 201, 212, 0.35);
  --grey: #6b7080;
  --grey-dim: #3a3e4a;
  --text: #d7dae2;
  --text-dim: #8a8f9a;
  --alert: #ff5a5a;
  --working: #7ee081;
  --font-data: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-display: 'Rajdhani', 'JetBrains Mono', sans-serif;
  --header-h: 60px;
  --gap: 16px;
  --pad: 20px;
  --bracket: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 45%, rgba(78, 201, 212, 0.06), transparent 55%),
    radial-gradient(ellipse at 50% 110%, rgba(212, 162, 78, 0.07), transparent 55%);
  color: var(--text);
  font-family: var(--font-data);
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0.02em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- atmosphere ---------- */
.overlay-scan, .overlay-noise { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.overlay-scan {
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, 0.18) 3px);
  mix-blend-mode: multiply; opacity: 0.7;
}
.overlay-noise {
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- header ---------- */
.hud-header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: var(--gap);
  padding: 0 calc(var(--gap) + 4px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(12, 14, 23, 0.9), rgba(5, 5, 8, 0.6));
  position: relative; z-index: 5;
}
.hud-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim) 30%, var(--cyan-dim) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  background: radial-gradient(circle, var(--gold) 0 35%, transparent 40%);
  box-shadow: 0 0 0 1px var(--cyan-dim), 0 0 12px var(--gold-glow);
}
.brand h1 {
  margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: 0.22em;
  color: var(--gold); text-shadow: 0 0 14px var(--gold-glow);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sep { color: var(--cyan); opacity: 0.7; }

.header-meta { display: flex; gap: 28px; flex: none; }
.meta-block { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.meta-label { font-size: 9px; letter-spacing: 0.24em; color: var(--text-dim); }
.meta-value { font-size: 14px; font-weight: 500; color: var(--cyan); font-variant-numeric: tabular-nums; }
.meta-source .meta-value { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }

.status-pill {
  padding: 1px 8px; border: 1px solid var(--gold-dim); color: var(--gold);
  font-size: 11px; letter-spacing: 0.18em; animation: standby 3s ease-in-out infinite;
}
.status-pill[data-status="online"]  { border-color: var(--cyan-dim); color: var(--cyan); animation: none; }
.status-pill[data-status="alert"]   { border-color: var(--alert); color: var(--alert); animation: none; }
.status-pill[data-status="offline"] { border-color: var(--grey-dim); color: var(--grey); animation: none; }
@keyframes standby { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- deck grid ---------- */
.deck {
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 340px;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gap);
  padding: var(--gap);
  position: relative; z-index: 1;
}
.panel-roster { grid-column: 1; grid-row: 1; }
.panel-core   { grid-column: 2; grid-row: 1; }
.panel-feed   { grid-column: 3; grid-row: 1; }
.stats-bar    { grid-column: 1 / -1; grid-row: 2; }

/* ---------- panel chrome: same line + four brackets everywhere ---------- */
.panel, .stats-bar {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(4px);
}
.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.panel::before, .panel::after, .corners::before, .corners::after,
.stats-bar::before, .stats-bar::after, .stats-bar .corners::before, .stats-bar .corners::after,
.drawer-frame::before, .drawer-frame::after {
  content: ""; position: absolute; width: var(--bracket); height: var(--bracket);
  border: 0 solid var(--gold); pointer-events: none; z-index: 2;
}
.panel::before, .stats-bar::before, .drawer-frame::before { top: -1px; left: -1px; border-width: 1.5px 0 0 1.5px; }
.panel::after,  .stats-bar::after,  .drawer-frame::after  { bottom: -1px; right: -1px; border-width: 0 1.5px 1.5px 0; }
.corners::before { top: -1px; right: -1px; border-width: 1.5px 1.5px 0 0; }
.corners::after  { bottom: -1px; left: -1px; border-width: 0 0 1.5px 1.5px; }
.corners { position: absolute; inset: 0; pointer-events: none; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 var(--pad);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.panel-title { font-family: var(--font-display); font-weight: 600; font-size: 13px; letter-spacing: 0.26em; color: var(--cyan); }
.panel-count, .panel-hint { font-size: 10px; letter-spacing: 0.18em; color: var(--text-dim); }
.panel-hint { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- roster ---------- */
.roster {
  list-style: none; margin: 0; padding: 12px;
  overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 6px;
  scrollbar-width: thin; scrollbar-color: var(--grey-dim) transparent;
}
.agent-card {
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 14px; align-items: center;
  width: 100%; padding: 10px 12px; text-align: left;
  background: transparent; border: 1px solid transparent;
  color: inherit; font: inherit; cursor: pointer;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
}
.agent-card:hover, .agent-card:focus-visible {
  border-color: var(--line-strong); background: rgba(78, 201, 212, 0.05); outline: none;
}
.agent-card.is-selected {
  border-color: var(--gold-dim); background: rgba(212, 162, 78, 0.06);
  box-shadow: inset 0 0 18px rgba(212, 162, 78, 0.06);
}
.agent-portrait {
  width: 52px; height: 52px; border-radius: 50%; overflow: hidden;
  border: 1px solid var(--grey-dim); background: var(--bg-raised);
  filter: saturate(0.25) brightness(0.75);
  transition: filter 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.agent-portrait svg { display: block; width: 100%; height: 100%; }
.agent-card[data-status="online"] .agent-portrait,
.agent-card[data-status="working"] .agent-portrait {
  filter: none; border-color: var(--gold); box-shadow: 0 0 10px var(--gold-glow);
}
.agent-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.agent-name { font-family: var(--font-display); font-weight: 700; font-size: 16px; letter-spacing: 0.16em; color: var(--text); line-height: 1.1; }
.agent-role { font-size: 10px; color: var(--text-dim); letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; width: max-content; max-width: 100%;
  font-size: 9px; letter-spacing: 0.16em; padding: 2px 7px; white-space: nowrap;
  border: 1px solid var(--grey-dim); color: var(--grey);
}
.badge .dot { background: var(--grey-dim); }
.badge[data-status="online"]  { border-color: var(--gold-dim); color: var(--gold); }
.badge[data-status="online"] .dot { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.badge[data-status="working"] { border-color: rgba(126, 224, 129, 0.4); color: var(--working); }
.badge[data-status="working"] .dot { background: var(--working); box-shadow: 0 0 6px var(--working); }

/* ---------- core stage ---------- */
.core-stage { position: relative; flex: 1; min-height: 0; padding: var(--pad); }
#core-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#core-canvas.is-dragging { cursor: grabbing; }
.core-legend {
  position: absolute; left: var(--pad); bottom: 14px;
  display: flex; gap: 14px; font-size: 9px; letter-spacing: 0.18em; color: var(--text-dim);
}
.core-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex: none; }
.dot-online  { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.dot-working { background: var(--working); box-shadow: 0 0 6px var(--working); }
.dot-offline { background: var(--grey-dim); }
.dot-live    { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); animation: standby 1.6s ease-in-out infinite; }

/* ---------- feed ---------- */
.feed {
  list-style: none; margin: 0; padding: 12px var(--pad);
  overflow-y: auto; flex: 1; min-height: 0;
  scrollbar-width: thin; scrollbar-color: var(--grey-dim) transparent;
  font-size: 11px;
}
.feed li {
  display: grid; grid-template-columns: 60px minmax(0, 1fr); gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed rgba(78, 201, 212, 0.12);
  animation: feed-in 0.35s ease-out both;
}
.feed li:last-child { border-bottom: 0; }
.feed-ts { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.feed-agent { color: var(--gold); letter-spacing: 0.1em; }
.feed-agent.is-system { color: var(--cyan); }
.feed-msg { color: var(--text); overflow-wrap: anywhere; }
.feed-msg::before { content: "› "; color: var(--grey); }
.feed-empty { color: var(--text-dim); padding: 12px 0; font-style: italic; grid-template-columns: 1fr; }
@keyframes feed-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- stats bar ---------- */
.stats-bar { display: grid; grid-template-columns: repeat(5, 1fr); }
.stat {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  height: 64px; padding: 0 var(--pad); border-right: 1px solid var(--line); line-height: 1.15; min-width: 0;
}
.stat:last-child { border-right: 0; }
.stat-label { font-size: 9px; letter-spacing: 0.24em; color: var(--text-dim); white-space: nowrap; }
.stat-value {
  font-family: var(--font-display); font-weight: 600; font-size: 24px;
  color: var(--gold); font-variant-numeric: tabular-nums; text-shadow: 0 0 10px var(--gold-glow);
}
.stat-value.stat-sync { font-family: var(--font-data); font-size: 12px; color: var(--cyan); text-shadow: none; padding-top: 5px; }

/* ---------- drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(5, 5, 8, 0.55); }
.drawer-backdrop[hidden] { display: none; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 45;
  width: min(400px, 100vw); padding: var(--gap);
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.is-open { transform: none; }
.drawer-frame {
  position: relative; height: 100%; overflow-y: auto;
  background: rgba(8, 9, 15, 0.97);
  border: 1px solid var(--gold-dim);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(212, 162, 78, 0.04);
  padding: 30px 24px 24px;
  scrollbar-width: thin; scrollbar-color: var(--grey-dim) transparent;
}
.drawer-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: 1px solid var(--grey-dim); color: var(--text-dim);
  width: 28px; height: 28px; font-size: 18px; line-height: 1; cursor: pointer;
}
.drawer-close:hover, .drawer-close:focus-visible { border-color: var(--gold); color: var(--gold); outline: none; }
.drawer-portrait {
  width: 136px; height: 136px; margin: 6px auto 14px; border-radius: 50%; overflow: hidden;
  border: 1px solid var(--gold-dim); background: var(--bg-raised);
  box-shadow: 0 0 0 6px rgba(212, 162, 78, 0.05), 0 0 30px var(--gold-glow);
}
.drawer-portrait svg { display: block; width: 100%; height: 100%; }
.drawer[data-status="offline"] .drawer-portrait { filter: saturate(0.3) brightness(0.8); box-shadow: none; border-color: var(--grey-dim); }
.drawer-name {
  margin: 0; text-align: center; font-family: var(--font-display); font-weight: 700; font-size: 30px;
  letter-spacing: 0.24em; color: var(--gold); text-shadow: 0 0 16px var(--gold-glow);
}
.drawer-role { margin: 2px 0 10px; text-align: center; color: var(--cyan); letter-spacing: 0.14em; font-size: 12px; }
.drawer .badge { display: flex; margin: 0 auto 16px; }
.drawer-desc { margin: 0 0 18px; color: var(--text); font-size: 12px; line-height: 1.6; }
.drawer-brain {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; margin-bottom: 18px; border: 1px dashed var(--grey-dim);
}
.drawer-brain-value { font-size: 12px; letter-spacing: 0.16em; color: var(--grey); }
.drawer-brain[data-connected="true"] { border-style: solid; border-color: var(--gold-dim); }
.drawer-brain[data-connected="true"] .drawer-brain-value { color: var(--gold); }
.drawer-sections { margin: 0; }
.drawer-sections dt {
  font-family: var(--font-display); font-weight: 600; font-size: 12px; letter-spacing: 0.24em;
  color: var(--cyan); padding: 8px 0 4px; border-top: 1px solid var(--line); margin-top: 10px;
}
.drawer-sections dd { margin: 0; padding: 0 0 6px; color: var(--text); font-size: 11px; min-height: 22px; }
.drawer-sections dd ul { margin: 0; padding-left: 14px; }
.drawer-sections dd li { margin: 2px 0; }
.empty { color: var(--grey); font-style: italic; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .deck { grid-template-columns: 240px minmax(0, 1fr) 300px; }
  .brand h1 { font-size: 17px; letter-spacing: 0.16em; }
  .header-meta { gap: 18px; }
}

@media (max-width: 860px) {
  :root { --header-h: 52px; --gap: 16px; --pad: 16px; }
  html, body { height: auto; }
  body { overflow-x: hidden; overflow-y: auto; }

  .hud-header { position: sticky; top: 0; padding: 0 var(--gap); }
  .brand h1 { font-size: 14px; letter-spacing: 0.12em; }
  .meta-status, .meta-source { display: none; }         /* compact header: clock only */

  .deck {
    height: auto;
    display: flex; flex-direction: column;              /* explicit order, no grid guessing */
    gap: var(--gap); padding: var(--gap);
  }
  .panel-core   { order: 1; }
  .stats-bar    { order: 2; }
  .panel-roster { order: 3; }
  .panel-feed   { order: 4; }

  /* full-width square core */
  .panel-core .core-stage { aspect-ratio: 1 / 1; flex: none; padding: 8px; }
  .core-legend { left: 12px; bottom: 8px; }

  /* 2x2 stats */
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .stat { height: 60px; border-bottom: 1px solid var(--line); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-last-child(-n+1) { border-bottom: 0; }
  .stat:last-child { grid-column: 1 / -1; height: 44px; }
  .stat-value { font-size: 20px; }

  /* vertical agent list, no inner scroll */
  .roster { overflow: visible; padding: 8px; gap: 2px; }
  .agent-card { grid-template-columns: 40px minmax(0, 1fr); gap: 12px; padding: 8px 10px; }
  .agent-portrait { width: 40px; height: 40px; }
  .agent-name { font-size: 14px; }

  .feed { max-height: 50vh; }
  .drawer { padding: 8px; width: 100vw; }
}

@media (prefers-reduced-motion: reduce) {
  .status-pill, .dot-live, .feed li { animation: none !important; }
  .drawer { transition: none; }
}
