/* Perseus operator console.
 *
 * Handwritten, no framework. A utility-class kit would have been faster to
 * type and would have made this look like every other dashboard; the tools
 * this one sits next to -- Aqua, Trivy, Falco's UI -- are recognisable partly
 * because their chrome is their own.
 *
 * Two rules drive every choice below:
 *
 *   1. Density over breathing room. The people using this scan hundreds of
 *      rows looking for one that is wrong. Generous padding is comfortable for
 *      ten rows and actively hostile at five hundred.
 *
 *   2. Colour is signal, never decoration. The palette is neutral so that the
 *      one amber row on screen is the thing the eye lands on. A console with a
 *      brand gradient competes with its own alerts.
 */

:root {
  /* Neutrals: cool-tinted, nine steps. The tint is slight on purpose -- pure
     grey reads as unfinished on OLED panels, a strong blue cast reads as a
     consumer app. */
  --n-950: #0a0d13;
  --n-900: #0f131b;
  --n-870: #141922;
  --n-840: #1a202b;
  --n-800: #212936;
  --n-700: #2c3542;
  --n-600: #3d4757;
  --n-500: #5b6779;
  --n-400: #7d8899;
  --n-300: #9aa5b5;
  --n-200: #c3ccd8;
  --n-100: #e2e8f0;

  /* Signal. Muted deliberately: saturated red on a dark panel vibrates and
     stops being readable at the exact moment someone needs to read it. */
  --sig-ok:    #34d399;
  --sig-warn:  #f0b429;
  --sig-crit:  #f87171;
  --sig-info:  #38bdf8;
  --sig-ok-dim:   rgba(52, 211, 153, .13);
  --sig-warn-dim: rgba(240, 180, 41, .13);
  --sig-crit-dim: rgba(248, 113, 113, .13);
  --sig-info-dim: rgba(56, 189, 248, .13);

  --bg:        var(--n-950);
  --surface:   var(--n-900);
  --surface-2: var(--n-870);
  --hover:     var(--n-840);
  --line:      var(--n-800);
  --line-2:    var(--n-700);

  --text:      var(--n-100);
  --text-2:    var(--n-300);
  --text-3:    var(--n-400);

  /* System stack. No webfont: a security console must not make a network
     request to a third party to render, and the first paint being instant is
     worth more here than a bespoke typeface. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  --topbar-h: 48px;
  --statusbar-h: 26px;
  --fleet-w: 246px;
  --detail-w: 400px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.mono {
  font-family: var(--mono);
  font-variant-ligatures: none;
  /* Tabular figures so PIDs and counters do not jitter as they update. */
  font-variant-numeric: tabular-nums;
}

/* Focus is visible everywhere. This tool gets driven from the keyboard during
   incidents, when nobody wants to hunt for the cursor. */
:focus-visible {
  outline: 2px solid var(--sig-info);
  outline-offset: 1px;
  border-radius: 2px;
}

/* ---------------------------------------------------------------- gate --- */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(56, 189, 248, .07), transparent 62%),
    var(--bg);
  z-index: 50;
}

.gate-card {
  width: 330px;
  padding: 30px 28px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  text-align: center;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .45);
}

.gate-mark { color: var(--sig-info); line-height: 0; }

.gate-title {
  margin: 12px 0 2px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.gate-sub {
  margin: 0 0 22px;
  color: var(--text-3);
  font-size: 12px;
}

.field { display: block; text-align: left; margin-bottom: 12px; }

.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.input {
  width: 100%;
  padding: 7px 9px;
  background: var(--n-950);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 12.5px;
}

.input::placeholder { color: var(--n-500); }

.input:focus {
  border-color: var(--sig-info);
  outline: none;
  box-shadow: 0 0 0 3px var(--sig-info-dim);
}

.gate-error {
  margin: 0 0 12px;
  padding: 7px 9px;
  background: var(--sig-crit-dim);
  border: 1px solid rgba(248, 113, 113, .3);
  border-radius: var(--r-sm);
  color: var(--sig-crit);
  font-size: 12px;
  text-align: left;
}

.gate-note {
  margin: 14px 0 0;
  color: var(--n-500);
  font-size: 11px;
  line-height: 1.5;
}

/* --------------------------------------------------------------- button --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-2);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  width: 100%;
  justify-content: center;
  padding: 8px 12px;
  background: var(--sig-info);
  color: #06212f;
  font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: default; filter: none; }

.btn-ghost { border-color: var(--line-2); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }

/* ---------------------------------------------------------------- shell --- */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  height: var(--topbar-h);
  flex: 0 0 auto;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--sig-info);
}

.brand-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.metrics {
  display: flex;
  gap: 20px;
  margin: 0;
}

.metric { display: flex; align-items: baseline; gap: 6px; }

.metric dt {
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.metric dd {
  margin: 0;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--n-500);
  flex: 0 0 auto;
}

.dot-live {
  background: var(--sig-ok);
  box-shadow: 0 0 0 3px var(--sig-ok-dim);
}

/* Paused is a solid, un-haloed dot rather than a different colour: pausing is
   a normal thing an operator does, not a fault, and colouring it amber would
   put a false warning in the corner of the screen. */
.is-paused .dot-live {
  background: var(--n-500);
  box-shadow: none;
}

.layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* ---------------------------------------------------------------- fleet --- */

.fleet {
  width: var(--fleet-w);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  flex: 0 0 auto;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.pane-title {
  margin: 0;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.count {
  margin-left: auto;
  padding: 1px 6px;
  background: var(--n-840);
  border-radius: 9px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10.5px;
}

.host-list {
  margin: 0;
  padding: 4px;
  list-style: none;
  overflow-y: auto;
  flex: 1 1 auto;
}

.host {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
}

.host:hover { background: var(--hover); }

.host.is-selected {
  background: var(--sig-info-dim);
  border-color: rgba(56, 189, 248, .28);
}

.host-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.host-id {
  display: block;
  color: var(--n-500);
  font-family: var(--mono);
  font-size: 10px;
}

.host-events {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* Host health is derived from silence, not from a heartbeat message. An agent
   that has stopped sending is the single most important thing this pane can
   show: it is what a host looks like after someone kills the collector. */
.host-state { width: 8px; height: 8px; border-radius: 50%; }
.state-live  { background: var(--sig-ok); }
.state-stale { background: var(--sig-warn); }
.state-gone  { background: var(--sig-crit); }

/* --------------------------------------------------------------- stream --- */

.stream {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.filterbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.filter-scope {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px 3px 9px;
  background: var(--n-840);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
}

.scope-clear {
  padding: 0 2px;
  border: none;
  background: none;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.scope-clear:hover { color: var(--text); }

.seg {
  display: flex;
  background: var(--n-950);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.seg-btn {
  padding: 4px 11px;
  border: none;
  border-right: 1px solid var(--line-2);
  background: none;
  color: var(--text-3);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--hover); color: var(--text-2); }

.seg-btn.is-active {
  background: var(--n-800);
  color: var(--text);
  font-weight: 500;
}

.input-search {
  width: auto;
  flex: 1 1 auto;
  max-width: 340px;
  padding: 5px 9px;
}

.stream-count {
  margin-left: auto;
  color: var(--text-3);
  font-size: 11px;
}

.table-wrap {
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
}

.events {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.events thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-2);
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  text-align: left;
}

.col-time   { width: 96px; }
.col-host   { width: 132px; }
.col-kind   { width: 66px; }
.col-proc   { width: 190px; }
.col-detail { width: auto; }

.events tbody tr {
  border-bottom: 1px solid rgba(44, 53, 66, .5);
  cursor: pointer;
}

.events tbody tr:hover { background: var(--hover); }

.events tbody tr.is-selected {
  background: var(--sig-info-dim);
  box-shadow: inset 2px 0 0 var(--sig-info);
}

.events td {
  padding: 5px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: baseline;
}

.cell-time { color: var(--text-3); font-family: var(--mono); font-size: 11.5px; }
.cell-host { color: var(--text-2); font-size: 12px; }
.cell-proc { color: var(--text); font-family: var(--mono); font-size: 11.5px; }
.cell-detail { color: var(--text-2); font-family: var(--mono); font-size: 11.5px; }

/* New rows announce themselves once and then stop. A permanent highlight on
   recent events turns the whole table into a colour gradient by the time
   anyone looks at it. */
@keyframes arrive {
  from { background: var(--sig-info-dim); }
  to   { background: transparent; }
}

.events tbody tr.is-new { animation: arrive 1.1s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .events tbody tr.is-new { animation: none; }
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .02em;
}

.badge-exec { background: var(--sig-info-dim); color: var(--sig-info); }
.badge-file { background: var(--sig-warn-dim); color: var(--sig-warn); }
.badge-net  { background: var(--sig-ok-dim);   color: var(--sig-ok); }
.badge-other{ background: var(--n-800);        color: var(--text-3); }

/* Root is worth a glance in a list of five hundred rows. */
.uid-root { color: var(--sig-warn); }

.tag-container {
  margin-left: 6px;
  padding: 0 4px;
  background: var(--n-800);
  border-radius: 3px;
  color: var(--text-3);
  font-size: 10px;
}

/* --------------------------------------------------------------- detail --- */

.detail {
  width: var(--detail-w);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  min-height: 0;
}

.detail-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
}

.dsec { margin-bottom: 16px; }

.dsec-title {
  margin: 0 0 6px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.dgrid {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 3px 10px;
  font-size: 12px;
}

.dgrid dt { color: var(--text-3); }

.dgrid dd {
  margin: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  word-break: break-all;
}

.cmdline {
  margin: 0;
  padding: 9px 10px;
  background: var(--n-950);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--n-200);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.truncated {
  margin: 6px 0 0;
  color: var(--sig-warn);
  font-size: 11px;
}

/* ------------------------------------------------------------ statusbar --- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 7px;
  height: var(--statusbar-h);
  flex: 0 0 auto;
  padding: 0 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: 11px;
}

.status-sep { color: var(--n-600); }
.status-spacer { flex: 1 1 auto; }
.status-item.is-error { color: var(--sig-crit); }

.empty {
  margin: 0;
  padding: 26px 14px;
  color: var(--n-500);
  font-size: 12px;
  text-align: center;
}

/* Narrow screens: the detail pane becomes an overlay rather than squeezing the
   table into unreadability. */
@media (max-width: 1100px) {
  .detail {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: var(--statusbar-h);
    z-index: 20;
    box-shadow: -12px 0 34px rgba(0, 0, 0, .5);
  }
}

@media (max-width: 800px) {
  .metrics { display: none; }
  .fleet { width: 180px; }
  .detail { width: 100%; }
}
