/* ============================================================
   Similipal NetMon — control room styling.

   SCADA discipline, not decoration:
     * near-black ground: operators watch this for hours
     * colour means STATE and nothing else, never ornament
     * tabular monospace numerals so digits do not jitter on refresh
     * no animation except the 1 Hz liveness pulse — movement in
       peripheral vision reads as an event, so it must be rare
     * stale data is drawn AS STALE (hatched), never as a comforting
       green tile backed by three-hour-old numbers
   ============================================================ */

:root {
  --bg:        #080b0e;
  --panel:     #10151a;
  --panel-2:   #151c22;
  --line:      #1f2a33;
  --line-hi:   #2c3b47;

  --ink:       #c9d6df;
  --ink-dim:   #7d8f9c;
  --ink-faint: #4d5c68;

  --up:        #3fb950;
  --degraded:  #d9a121;
  --down:      #f0503a;
  --stale:     #6b7a87;
  --unbuilt:   #35424d;
  --accent:    #4aa8d8;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* numerals never reflow between refreshes */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------------- shell ---------------- */
#app { display: flex; flex-direction: column; height: 100vh; }

header {
  display: flex; align-items: center; gap: 20px;
  padding: 0 18px; height: 46px; flex: none;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header .brand {
  font-weight: 600; letter-spacing: .16em; font-size: 12px;
  text-transform: uppercase; color: var(--ink);
}
header .brand span { color: var(--accent); }
header .spacer { flex: 1; }
header .stat { font-size: 11px; color: var(--ink-dim); letter-spacing: .08em; }
header .stat b { color: var(--ink); font-weight: 600; }

/* 1 Hz liveness pulse — the ONLY animation in the interface. Its job is to
   prove the page is still receiving data, so a frozen tab is obvious. */
.pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--up); display: inline-block; margin-right: 6px;
  animation: beat 2s ease-in-out infinite;
}
.pulse.dead { background: var(--down); animation: none; }
@keyframes beat { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* ---------------- alarm banner ---------------- */
#alarmbar {
  flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 18px; height: 38px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
#alarmbar.crit { background: #2a1210; border-bottom-color: #5b2018; }
#alarmbar.warn { background: #241d0c; border-bottom-color: #4d3d12; }
#alarmbar .count {
  font-family: var(--mono); font-weight: 700; font-size: 13px;
  padding: 2px 8px; border-radius: 3px;
  background: var(--line); color: var(--ink);
}
#alarmbar.crit .count { background: var(--down); color: #180a08; }
#alarmbar.warn .count { background: var(--degraded); color: #1a1405; }
#alarmbar .msg { color: var(--ink-dim); }
#alarmbar .msg b { color: var(--ink); }

/* ---------------- layout ---------------- */
main {
  flex: 1; display: grid; gap: 1px; min-height: 0;
  grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr);
  background: var(--line);
}
section { background: var(--bg); overflow: auto; min-height: 0; }
/* Topology scrolls in both axes rather than being squeezed. */
#topowrap { overflow: auto; }

.panel-title {
  position: sticky; top: 0; z-index: 2;
  padding: 9px 16px;
  font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-faint);
  background: var(--panel); border-bottom: 1px solid var(--line);
}

/* ---------------- topology ---------------- */
/* Deliberately NOT width:100%. The real division tree is 9 hops deep, so
   the diagram is ~1500px wide; scaling that into a side panel shrinks the
   labels to illegibility. Keep it at natural size and let the panel scroll —
   an operator can pan, but must never have to squint. */
#topo { display: block; }
#topo .edge      { stroke: var(--line-hi); stroke-width: 1.5; fill: none; }
#topo .edge.up   { stroke: #2b6b39; }
#topo .edge.degraded { stroke: var(--degraded); stroke-width: 2; }
#topo .edge.down { stroke: var(--down); stroke-width: 2.5; }
/* A broken shot is the one thing on this screen allowed to draw attention. */
#topo .edge.broken {
  stroke: var(--down); stroke-width: 3;
  stroke-dasharray: 6 4;
}
#topo .node rect {
  fill: var(--panel-2); stroke: var(--line-hi); stroke-width: 1; rx: 3;
  cursor: pointer;
}
#topo .node.up       rect { stroke: var(--up); }
#topo .node.degraded rect { stroke: var(--degraded); }
#topo .node.down     rect { stroke: var(--down); fill: #1c0f0e; }
#topo .node.stale    rect { stroke: var(--stale); stroke-dasharray: 3 3; }
#topo .node.undeployed rect { stroke: var(--unbuilt); fill: #0d1116; }
#topo .node text  { fill: var(--ink); font-size: 10px; font-family: var(--sans); }
#topo .node .sub  { fill: var(--ink-faint); font-size: 8px; font-family: var(--mono); }
#topo .node.undeployed text { fill: var(--ink-faint); }
#topo .node.selected rect { stroke-width: 2; }

/* ---------------- site tiles ---------------- */
#tiles { padding: 10px; display: grid; gap: 8px;
         grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }

.tile {
  background: var(--panel); border: 1px solid var(--line);
  border-left-width: 3px; padding: 9px 11px; cursor: pointer;
}
.tile:hover { background: var(--panel-2); }
.tile.up       { border-left-color: var(--up); }
.tile.degraded { border-left-color: var(--degraded); }
.tile.down     { border-left-color: var(--down); }
.tile.stale    { border-left-color: var(--stale); }
.tile.undeployed { border-left-color: var(--unbuilt); opacity: .5; }

/* Stale = last-known-good, and must never masquerade as live. The hatch is
   the visual contract: "these numbers are old". */
.tile.stale .metrics,
.tile.down  .metrics {
  background-image: repeating-linear-gradient(45deg,
      transparent, transparent 5px,
      rgba(125,143,156,.07) 5px, rgba(125,143,156,.07) 10px);
}

.tile .head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; }
.tile .name { font-weight: 600; font-size: 12.5px; }
.tile .tier { font-family: var(--mono); font-size: 9px; color: var(--ink-faint); }
.tile .age  { margin-left: auto; font-family: var(--mono); font-size: 10px;
              color: var(--ink-faint); }

.tile .metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px 4px; }
.metric .k { font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase;
             color: var(--ink-faint); }
.metric .v { font-family: var(--mono); font-variant-numeric: tabular-nums;
             font-size: 13px; color: var(--ink); }
.metric .v.bad  { color: var(--down); }
.metric .v.warn { color: var(--degraded); }
.metric .v.null { color: var(--ink-faint); }

.tile .victim {
  margin-top: 7px; font-size: 10px; color: var(--degraded);
  border-top: 1px solid var(--line); padding-top: 5px;
}

/* ---------------- alarm list ---------------- */
#alarms { padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
.alarm {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--degraded); padding: 7px 10px; font-size: 12px;
}
.alarm.critical { border-left-color: var(--down); }
.alarm.suppressed { opacity: .45; border-left-style: dotted; }
.alarm .site { font-weight: 600; min-width: 118px; }
.alarm .rule { color: var(--ink-dim); flex: 1; }
.alarm .when { font-family: var(--mono); font-size: 10px; color: var(--ink-faint); }
.alarm button {
  background: var(--line); color: var(--ink); border: 1px solid var(--line-hi);
  padding: 3px 9px; font-size: 10.5px; cursor: pointer; border-radius: 2px;
  letter-spacing: .06em;
}
.alarm button:hover { background: var(--line-hi); }
.alarm .acked { font-size: 10px; color: var(--up); font-family: var(--mono); }

/* ---------------- detail drawer ---------------- */
#detail {
  position: fixed; right: 0; top: 0; bottom: 0; width: 460px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line-hi);
  transform: translateX(100%); transition: transform .16s ease-out;
  z-index: 30; overflow: auto; padding-bottom: 30px;
}
#detail.open { transform: none; }
#detail .dhead {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--panel);
}
#detail h2 { margin: 0; font-size: 15px; font-weight: 600; }
#detail .close { margin-left: auto; cursor: pointer; color: var(--ink-dim);
                 background: none; border: none; font-size: 18px; }
.chart { padding: 10px 16px; }
.chart h3 { margin: 0 0 4px; font-size: 9.5px; letter-spacing: .14em;
            text-transform: uppercase; color: var(--ink-faint); font-weight: 500; }
.chart svg { width: 100%; height: 52px; display: block; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.3; }
.chart .area { fill: rgba(74,168,216,.10); }
.chart .last { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }

/* ---------------- login ---------------- */
#login {
  position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
#login form {
  background: var(--panel); border: 1px solid var(--line);
  padding: 26px 28px; width: 310px;
}
#login h1 { margin: 0 0 3px; font-size: 13px; letter-spacing: .16em;
            text-transform: uppercase; }
#login p { margin: 0 0 18px; font-size: 11px; color: var(--ink-faint); }
#login input {
  width: 100%; margin-bottom: 9px; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
  font-family: var(--mono); font-size: 13px;
}
#login input:focus { outline: none; border-color: var(--accent); }
#login button {
  width: 100%; padding: 9px; margin-top: 5px; cursor: pointer;
  background: var(--accent); color: #061016; border: none;
  font-weight: 600; letter-spacing: .1em; font-size: 11px; text-transform: uppercase;
}
#login .err { color: var(--down); font-size: 11px; min-height: 15px; margin-top: 8px; }

.hidden { display: none !important; }

@media (max-width: 1000px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto auto; }
}
