/* homepage — terminal blueprint theme
   Colour, glyph and motion rules come from homepage/DESIGN.md §3. Containers use
   1px CSS borders (the fieldset-legend technique puts the title on the border, the
   same way a TUI would draw it); dense inner content uses real box-drawing and
   block characters on a fixed-width grid so density survives without reflow. */

:root {
  --bg: #0b0f14;
  --text: #c9d1d9;
  --dim: #7d8590;
  --hair: #3a4450;

  --blue: #79a8ff;
  --cyan: #5ad1e6;
  --green: #6fdc8c;
  --amber: #e8b25d;
  --purple: #b48cff;
  --red: #ff7b72;

  --gap: 14px;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: Consolas, "DejaVu Sans Mono", Menlo, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
  font-variant-ligatures: none;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

body { padding: var(--gap); min-height: 100vh; }

/* ---------- scanline: fixed chrome only, never over data ---------- */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.014) 0 1px,
    transparent 1px 3px
  );
}

/* ---------- terminal window chrome: pure atmosphere, touches no data path ---------- */
.term-window {
  border: 1px solid var(--hair);
  padding: var(--gap);
  padding-top: 0;
}
.term-chrome {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 calc(-1 * var(--gap));
  padding: 8px var(--gap);
  border-bottom: 1px solid var(--hair);
  background: rgba(255, 255, 255, 0.018);
}
.term-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.term-dot-red   { background: #ff5f57; }
.term-dot-amber { background: #febc2e; }
.term-dot-green { background: #28c840; }
.term-title {
  margin-left: 8px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.5px;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- chrome ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 8px;
  margin-bottom: var(--gap);
}

.brand { color: var(--cyan); font-weight: 700; letter-spacing: 0.5px; }
.brand small { color: var(--dim); font-weight: 400; }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  color: var(--dim);
  text-decoration: none;
  padding: 2px 9px;
  border: 1px solid transparent;
  letter-spacing: 0.5px;
  white-space: pre;
}
.nav a:hover { color: var(--text); border-color: var(--hair); }
.nav a.active {
  color: var(--bg);
  background: var(--cyan);
  font-weight: 700;
}

.footer {
  margin-top: var(--gap);
  padding-top: 8px;
  border-top: 1px solid var(--hair);
  color: var(--dim);
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

/* ---------- grid + boxes ---------- */
/* Panels pack into columns rather than sitting in grid rows. A grid row is as tall as its
   tallest member, so a short panel beside a tall one left a large void beneath it and the
   next row started below the tall panel. Multicolumn packs them and balances the columns. */
.grid {
  columns: 420px;
  column-gap: var(--gap);
}
.grid > * {
  break-inside: avoid;
  margin-bottom: var(--gap);
}
.grid.wide { columns: 1; }

/* Page roots are CSS multi-column, not grid, so grid-column does nothing there. Dense
   panels that must not be squeezed into a 420px track use column-span instead. */
.box.full { column-span: all; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: var(--gap);
}
.tiles > * { margin-bottom: 0; }

.box {
  position: relative;
  border: 1px solid var(--hair);
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.012);
}

.box-title {
  position: absolute;
  top: -8px;
  left: 9px;
  background: var(--bg);
  padding: 0 6px;
  color: var(--blue);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: pre;
}
.box-title.cyan   { color: var(--cyan); }
.box-title.green  { color: var(--green); }
.box-title.amber  { color: var(--amber); }
.box-title.purple { color: var(--purple); }
.box-title.dim    { color: var(--dim); }

/* status badge on the box's top-right border corner, same fieldset-legend technique as
   .box-title on the top-left - confirmed against source frames, see REFERENCE_SOURCES.md */
.box-badge {
  position: absolute;
  top: -8px;
  right: 9px;
  background: var(--bg);
  padding: 0 6px;
  font-size: 11px;
  letter-spacing: 0.5px;
  white-space: pre;
}

.box-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 6px;
  white-space: pre;
}
.box-name { color: var(--text); font-weight: 700; }
.box-meta { color: var(--dim); font-size: 11px; }

/* ---------- rows: the fixed-width character grid ---------- */
.rows { margin-top: 8px; display: flex; flex-direction: column; gap: 1px; }
.row {
  display: flex;
  gap: 10px;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .k { color: var(--dim); flex: 0 0 auto; }
.row .v { color: var(--text); }
.row .v.wide { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }

/* Ellipsis, not hard clip: these cells were cutting values mid-glyph. */
.row.dense { font-size: 11px; }
.row.dense > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.dense:nth-of-type(odd) { background: rgba(255, 255, 255, 0.022); }

/* ---------- bars + sparklines, drawn in characters ---------- */
.bar { color: var(--cyan); letter-spacing: -1px; }
.bar.green { color: var(--green); }
.bar.amber { color: var(--amber); }
.bar.red   { color: var(--red); }
.spark { letter-spacing: -1px; }

/* ---------- status glyphs: one set, used everywhere ---------- */
.g-ok    { color: var(--green); }
.g-warn  { color: var(--amber); }
.g-busy  { color: var(--amber); }
.g-bad   { color: var(--red); }
.g-idle  { color: var(--dim); }
.g-done  { color: var(--green); }
.g-info  { color: var(--blue); }

.pulse { display: inline-block; animation: pulse 2.4s ease-in-out infinite; }
.pulse.d1 { animation-delay: 0.3s; }
.pulse.d2 { animation-delay: 0.6s; }
.pulse.d3 { animation-delay: 0.9s; }
.pulse.d4 { animation-delay: 1.2s; }
.pulse.d5 { animation-delay: 1.5s; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* travelling dash on connectors between nodes, with a junction dot at the origin and an
   arrowhead at the terminus (both confirmed in the reference frames, see REFERENCE_SOURCES.md) */
.flow { position: relative; height: 1px; background: var(--hair); overflow: visible; margin-right: 12px; }
.flow::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--hair);
}
.flow.active::before { background: var(--cyan); }
.flow::after {
  content: "";
  position: absolute;
  top: 0;
  width: 34px;
  height: 1px;
  background: var(--cyan);
  animation: flow var(--flow-dur, 2.8s) linear infinite;
}
.flow.idle::after { display: none; }
.flow-arrow {
  position: absolute;
  right: -11px;
  top: -7px;
  color: var(--hair);
  font-size: 11px;
  line-height: 1;
}
.flow.active + .flow-arrow,
.flow-arrow.active { color: var(--cyan); }
@keyframes flow {
  from { left: -34px; }
  to   { left: 100%; }
}

/* generic tree node, shared by the agent tree and the network topology tree */
.node-card { transition: opacity 0.6s linear; }
.node-card.idle { opacity: 0.4; }

/* ---------- agent tree: recursive cards joined by flow connectors ---------- */
.agent-card {
  border-left: 2px solid var(--hair);
  padding: 5px 0 3px 9px;
  margin-top: 7px;
  transition: opacity 0.6s linear;
}
.agent-card.depth-0 { margin-left: 0; }
.agent-card.depth-1 { border-left-style: solid; }
.agent-card.depth-2 { border-left-style: dashed; }
.agent-card.depth-3 { border-left-style: dotted; opacity: 0.9; }
.agent-card .flow { margin: 6px 0 2px; }

/* ---------- weather icons ----------
   Adapted from start.danfry.net's pure-CSS technique but shrunk and recoloured to the
   blueprint palette. Each shape is a real element with a solid background so pieces
   overlap cleanly; the earlier box-shadow-mask version rendered as a lumpy blob. */

.wx {
  position: relative;
  display: inline-block;
  width: 3.4em;
  height: 2.6em;
  overflow: visible;
  /* 25% larger: every child shape is sized in em relative to this element's own
     font-size (inherited 13px body default), so bumping it here scales the whole
     icon uniformly without touching each wx-* shape individually. */
  font-size: 1.25em;
}

/* Outlined rather than filled, matching start.danfry.net: the reference draws a dark cloud
   with a light rim so it reads as line art. drop-shadow follows the merged silhouette of
   the element and its lobes, so one tight glow rings the whole cloud instead of each
   circle separately - box-shadow would outline the lobes and show seams across the body. */
.wx-cloud {
  position: absolute;
  left: 50%;
  bottom: 0.5em;
  width: 2.3em;
  height: 1em;
  margin-left: -1.15em;
  background: var(--bg);
  border-radius: 0.5em;
  filter: drop-shadow(0 0 0.085em var(--cyan));
}

.wx-cloud::before,
.wx-cloud::after {
  content: "";
  position: absolute;
  background: var(--bg);
  border-radius: 50%;
}

.wx-cloud::before { width: 1.15em; height: 1.15em; left: 0.28em; bottom: 0.72em; }
.wx-cloud::after  { width: 0.9em;  height: 0.9em;   right: 0.32em; bottom: 0.7em; }

.wx-sun {
  position: absolute;
  left: 50%;
  bottom: 0.75em;
  width: 1.1em;
  height: 1.1em;
  margin-left: -0.55em;
  background: var(--amber);
  border-radius: 50%;
}

.wx-rays {
  position: absolute;
  left: 50%;
  bottom: 0.45em;
  width: 0.14em;
  height: 1.7em;
  margin-left: -0.07em;
  background: var(--amber);
  border-radius: 0.07em;
  transform-origin: 50% 50%;
  animation: wx-spin 14s linear infinite;
}

.wx-rays::before,
.wx-rays::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--amber);
  border-radius: inherit;
}

.wx-rays::before { transform: rotate(60deg); }
.wx-rays::after  { transform: rotate(120deg); }

.wx-rain {
  position: absolute;
  left: 50%;
  bottom: -0.32em;
  width: 0.9em;
  height: 0.5em;
  margin-left: -0.45em;
}

.wx-rain::after {
  content: "";
  position: absolute;
  left: 0.05em;
  width: 0.22em;
  height: 0.56em;
  background: var(--blue);
  border-radius: 0.11em;
  box-shadow: 0.34em 0em 0 var(--blue), 0.68em 0em 0 var(--blue);
  animation: wx-drop 1.9s linear infinite;
}

.wx-snow {
  position: absolute;
  left: 50%;
  bottom: -0.34em;
  margin-left: -0.7em;
  width: 1.4em;
  color: var(--text);
  font-size: 1.3em;
  line-height: 1;
  text-align: center;
  animation: wx-spin 9s linear infinite reverse;
}

.wx-bolt {
  position: absolute;
  left: 50%;
  bottom: -0.42em;
  width: 0;
  height: 0;
  margin-left: -0.32em;
  border-left: 0.32em solid transparent;
  border-right: 0.32em solid transparent;
  border-top: 0.72em solid var(--amber);
  animation: wx-flash 2.6s steps(1) infinite;
}

.wx-fog {
  position: absolute;
  left: 0.45em;
  bottom: 1em;
  width: 2.5em;
  height: 0.09em;
  background: var(--dim);
  border-radius: 0.05em;
  box-shadow: 0 0.42em 0 0 var(--dim), 0 0.84em 0 0 var(--dim);
}

@keyframes wx-spin  { to { transform: rotate(360deg); } }
@keyframes wx-drop  { 0%   { transform: translateY(-0.25em); opacity: 0; }
                      25%  { opacity: 1; }
                      100% { transform: translateY(0.3em); opacity: 0; } }
@keyframes wx-flash { 0%, 44% { opacity: 0.2; }
                      47%, 54% { opacity: 1; }
                      57%, 100% { opacity: 0.2; } }
                      45%, 52% { opacity: 1; }
                      55%, 100% { opacity: 0.25; } }

/* ---------- log strip ---------- */
.logstrip {
  margin-top: var(--gap);
  border: 1px solid var(--hair);
  padding: 8px 12px;
  max-height: 168px;
  overflow-y: auto;
}
.logline { white-space: pre; color: var(--dim); font-size: 12px; }
.logline .t { color: var(--blue); }
.logline.new { animation: slidein 0.35s ease-out; }
.logline { transition: opacity 2s linear; }
.logline.age-1 { opacity: 0.65; }
.logline.age-2 { opacity: 0.4; }
.logline.age-3 { opacity: 0.22; }
  .logline .dup { color: var(--amber); font-weight: 600; }
@keyframes slidein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- modal overlay: never touches the grid beneath ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 11, 0.82);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.scrim.open { display: flex; }
.modal {
  background: var(--bg);
  border: 1px solid var(--hair);
  padding: 14px 16px;
  max-width: 900px;
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
}
.modal h3 { color: var(--cyan); font-size: 12px; letter-spacing: 1px; margin-bottom: 10px; font-weight: 700; }
.modal-close { color: var(--dim); cursor: pointer; float: right; font-size: 11px; }
.modal-close:hover { color: var(--red); }

/* ---------- live-update pulse ---------- */
.flash { animation: flash 900ms ease-out; }
@keyframes flash {
  0%   { background: rgba(90, 209, 230, 0.28); }
  100% { background: transparent; }
}

/* Agents still active or recently ended breathe on the left edge, then fade out with the
   card opacity as they age past the window. */
.agent-card.linger { animation: linger 2.6s ease-in-out infinite; }
@keyframes linger {
  0%, 100% { box-shadow: inset 3px 0 7px -3px rgba(90, 209, 230, 0); }
  50%      { box-shadow: inset 3px 0 7px -3px rgba(90, 209, 230, 0.6); }
}

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { border: 1px solid var(--hair); padding: 18px 22px; min-width: 320px; }
.login-title {
  color: var(--cyan);
  letter-spacing: 3px;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 9px;
  margin-bottom: 14px;
}
.login-mark { color: var(--amber); margin-right: 6px; }
.login-body-row { display: flex; align-items: center; gap: 10px; color: var(--text); margin-top: 6px; }
.login-lbl { width: 36px; color: var(--dim); font-size: 11px; letter-spacing: 1px; }
.login-body-row input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hair);
  color: var(--text);
  font: inherit;
  outline: none;
  flex: 1;
}
.login-body-row input:focus { border-bottom-color: var(--cyan); }
.login-submit-row { margin-top: 16px; }
.login-submit-row button {
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--cyan);
  cursor: pointer;
  font: inherit;
  letter-spacing: 2px;
  padding: 5px 14px;
  width: 100%;
}
.login-submit-row button:hover { border-color: var(--cyan); color: var(--amber); }
.login-submit-row button:focus-visible { outline: 1px solid var(--cyan); outline-offset: 2px; }
.login-foot { color: var(--dim); margin-top: 12px; font-size: 11px; letter-spacing: 1px; text-align: center; }
.login-fail { color: var(--red); margin-top: 10px; text-align: center; }

.clickable { cursor: pointer; }
.clickable:hover { color: var(--cyan); }

/* ---------- splash footer ticker ----------
   Splash never wired up #foot-health, so it just sat at its static "—" default forever.
   Repurposed into a continuously side-scrolling strip of recent real events instead -
   same /api/home/logstrip feed the site-wide log strip already polls. */
#foot-health.ticker {
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  height: 1.3em;
  position: relative;
}
#foot-health.ticker .ticker-track {
  display: inline-block;
  white-space: pre;
  animation: foot-ticker-scroll linear infinite;
}
@keyframes foot-ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* ---------- splash critical-alert toasts ----------
   Same pulsing-glow technique as itocsnow/dashboard.html's .critical-banner
   (bannerFlash keyframe) - adapted to this page's flat/square blueprint language
   instead of that page's rounded-corner gradient style. Hidden entirely (empty
   container) when nothing is wrong; stacks one box per active alert. */
.splash-toasts {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  text-align: left;
}
.splash-toast {
  border: 1px solid var(--red);
  background: rgba(255, 123, 114, 0.08);
  padding: 8px 12px;
  font-size: 11px;
  letter-spacing: 0.3px;
  color: var(--red);
  animation: toast-glow 1.6s ease-in-out infinite alternate;
}
.splash-toast .toast-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.splash-toast .toast-detail { color: var(--text); margin-top: 2px; }
@keyframes toast-glow {
  0%   { box-shadow: 0 0 6px rgba(255, 123, 114, 0.25); border-color: rgba(255, 123, 114, 0.5); }
  100% { box-shadow: 0 0 20px rgba(255, 123, 114, 0.65); border-color: var(--red); }
}

/* ---------- itoc alarm toggle (static/itoc-alarm.js, mounted on splash + /itoc) ---------- */
.itoc-audio-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 950;
  background: var(--bg);
  border: 1px solid var(--hair);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  padding: 3px 9px;
  line-height: 1.4;
}
.itoc-audio-btn:hover { border-color: var(--cyan); }

.tag-chip {
  display: inline-block;
  border: 1px solid var(--hair);
  color: var(--cyan);
  padding: 0 4px;
  margin: 0 3px 2px 0;
  font-size: 10px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

/* Playbook output. Rows wrap instead of truncating, indentation reads as depth, and
   headings get their own treatment so a briefing is scannable. */
.row.brief-row {
  align-items: flex-start;
  gap: 8px;
  padding: 1px 0;
}
.brief-gut {
  flex: 0 0 10px;
  color: var(--dim);
  text-align: right;
  white-space: pre;
}
.row.brief-row[data-depth="1"] .brief-gut { color: var(--cyan); }
.row.brief-row[data-depth="2"] .brief-gut { color: var(--dim); }
.row.brief-row[data-depth="3"] .brief-gut { color: var(--dim); opacity: 0.6; }
.row.brief-item .brief-txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.row.brief-head {
  margin-top: 7px;
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.row.brief-head .brief-txt {
  color: var(--amber);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-size: 11px;
}
.row.brief-head:first-child { margin-top: 0; }
.row.brief-more { padding-top: 4px; }
.row.brief-more .brief-txt { font-size: 11px; }

.bright-bar { display: inline-block; min-width: 96px; }
.net-sig { display: inline-block; min-width: 150px; }

/* ---------- Nikki chat tab ---------- */
.nikki-layout {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
  flex-wrap: wrap;
}
.nikki-main { flex: 2 1 480px; min-width: 0; }
.nikki-side { flex: 1 1 280px; min-width: 0; }

.nikki-chat {
  flex: 1 1 auto;
  overflow-y: auto;
  margin-top: 10px;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nikki-line { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.nikki-line .who { color: var(--dim); font-size: 11px; letter-spacing: 0.5px; display: block; margin-bottom: 2px; }
.nikki-line.user .who { color: var(--cyan); }
.nikki-line.assistant .who { color: var(--purple); }
.nikki-line.error { color: var(--red); }

.nikki-input-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--hair);
  padding-top: 10px;
}
.nikki-input {
  flex: 1 1 auto;
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--text);
  font: inherit;
  padding: 7px 9px;
  resize: none;
  max-height: 120px;
}
.nikki-input:focus { outline: none; border-color: var(--purple); }
.nikki-send {
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--purple);
  cursor: pointer;
  font: inherit;
  letter-spacing: 1px;
  padding: 0 16px;
}
.nikki-send:hover { border-color: var(--purple); }
.nikki-send:disabled { color: var(--dim); cursor: default; }

.nikki-activity {
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.nikki-activity .logline { white-space: pre-wrap; }
