:root {
  --bg: #04181B; --panel: #0A2A2F; --panel-2: #0D333A; --line: #14424A;
  --text: #E8F3F4; --muted: #9DB9BD; --accent: #7FD3E0;
  --ok: #3DD68C; --warn: #FFD400; --down: #FF4D6D; --idle: #5F7F84; --live: #22E5FF;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; }
#app { min-height: 100%; display: flex; flex-direction: column; padding: 20px 28px 24px; gap: 18px; }
[hidden] { display: none !important; }

/* header */
.bar { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.title { font-size: 26px; font-weight: 700; letter-spacing: .3px; }
.sub { font-size: 14px; color: var(--muted); }
.pills { display: flex; gap: 10px; flex: 1; justify-content: center; flex-wrap: wrap; }
.pill { display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px;
  font-size: 17px; font-weight: 600; border: 1px solid var(--line); }
.pill.ok { background: rgba(61,214,140,.12); border-color: rgba(61,214,140,.45); }
.pill.warn { background: rgba(255,212,0,.10); border-color: rgba(255,212,0,.5); }
.pill.down { background: rgba(255,77,109,.14); border-color: var(--down); }
.views { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.views button { background: none; border: 0; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.views button.on { background: var(--panel-2); color: var(--text); }
.views .sep { width: 1px; background: var(--line); margin: 4px 4px; }
body.status .views [data-level] { display: none; }
body.status .views .sep { display: none; }
.clock { text-align: right; }
.time { font-family: var(--mono); font-size: 26px; font-weight: 600; }

/* shapes so state never depends on color alone */
.mark { flex: none; display: inline-block; width: 12px; height: 12px; }
.mark.ok { border-radius: 50%; background: var(--ok); }
.mark.warn { border-radius: 3px; background: var(--warn); }
.mark.down { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 12px solid var(--down); }
.mark.idle { border-radius: 50%; border: 2px solid var(--idle); }

/* status view */
.view { flex: 1; display: flex; gap: 20px; min-height: 0; }
.main-col { flex: 1; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.band h2, .panel h2 { margin: 0 0 10px; font-size: 13px; font-weight: 600; letter-spacing: 2px;
  text-transform: uppercase; color: var(--accent); }
.band h2 span { margin-left: 10px; letter-spacing: 0; text-transform: none; color: var(--muted); font-weight: 400; font-size: 13px; }
.columns { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 7px; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px 4px; }
.col-head b { font-size: 16px; }
.col-head span { font-size: 12px; color: var(--muted); }
.tile { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px;
  border-radius: 9px; background: var(--panel-2); border: 1px solid transparent; }
.tile .nm { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .dt { font-size: 12px; color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tile.warn { border-color: rgba(255,212,0,.55); }
.tile.down { border-color: var(--down); background: rgba(255,77,109,.12); animation: glow 2s ease-in-out infinite; }
.tile.idle .nm { color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px rgba(255,77,109,.25); } }

.procs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.proc { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.proc .app { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.proc .val { font-family: var(--mono); font-size: 38px; font-weight: 700; line-height: 1; }
.proc .lbl { font-size: 14px; line-height: 1.3; }
.proc.warn { border-color: rgba(255,212,0,.55); }
.proc.flash { animation: pflash 1.2s ease-out; }
@keyframes pflash { from { box-shadow: 0 0 0 3px var(--live); } }

.side { width: 360px; flex: none; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.panel.grow { flex: 1; min-height: 0; overflow: hidden; }
.attention, .feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.attention li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.attention li .mark { margin-top: 4px; }
.attention small, .feed small { display: block; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.feed li { font-size: 14px; border-left: 3px solid var(--live); padding: 2px 0 2px 10px; }
.feed li.fail { border-left-color: var(--down); }
.feed li.new { animation: feedin .8s ease-out; }
@keyframes feedin { from { background: rgba(34,229,255,.18); } }

/* flow view */
.board-wrap { flex: 1; position: relative; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
#board { width: 100%; height: 100%; display: block; min-height: 420px; }
.node rect.box { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
.node.outside rect.box { fill: #082126; stroke-dasharray: 6 4; }
.node.down rect.box { stroke: var(--down); }
.node.warn rect.box { stroke: var(--warn); }
.node text.nm { fill: var(--text); font-size: 18px; font-weight: 700; }
.node text.st { fill: var(--muted); font-size: 12px; font-family: var(--mono); }
.chip rect { fill: #0F3B43; stroke: #1B5560; }
.chip.planned rect { stroke-dasharray: 4 3; opacity: .6; }
.chip text { fill: var(--text); font-size: 13px; }
.link path.wire { fill: none; stroke-width: 3; stroke-linecap: round; }
.link path.hit { fill: none; stroke: transparent; stroke-width: 18; cursor: pointer; }
.link.ok path.wire { stroke: var(--ok); opacity: .75; }
.link.warn path.wire { stroke: var(--warn); stroke-dasharray: 10 7; }
.link.down path.wire { stroke: var(--down); filter: drop-shadow(0 0 5px var(--down)); animation: wglow 1.6s ease-in-out infinite; }
.link.idle path.wire { stroke: var(--idle); opacity: .55; stroke-dasharray: 2 6; }
.link.hot path.wire { stroke: var(--live); opacity: 1; stroke-dasharray: none; filter: drop-shadow(0 0 6px var(--live)); }
@keyframes wglow { 50% { opacity: .55; } }
.pulse { fill: var(--live); filter: drop-shadow(0 0 6px var(--live)); }
.tag rect { fill: #062A30; stroke: var(--live); }
.tag text { fill: var(--live); font-size: 14px; font-weight: 600; font-family: var(--mono); }
.popup { position: absolute; z-index: 5; width: 330px; background: #061F23; border: 1px solid var(--accent); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); font-size: 13px; }
.popup h3 { margin: 0 0 4px; font-size: 15px; }
.popup .state { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); }
.popup ol { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.popup li { display: flex; justify-content: space-between; gap: 10px; }
.popup li span:last-child { color: var(--muted); font-family: var(--mono); white-space: nowrap; }
.popup li.fail span:first-child { color: var(--down); }
.popup .close { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.ln { display: inline-block; width: 36px; height: 0; border-top: 3px solid; }
.ln.ok { border-color: var(--ok); } .ln.warn { border-color: var(--warn); border-top-style: dashed; }
.ln.down { border-color: var(--down); box-shadow: 0 0 6px var(--down); } .ln.idle { border-color: var(--idle); border-top-style: dotted; }
.ln.live { border-color: var(--live); box-shadow: 0 0 6px var(--live); }

/* sign-in gate */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.card { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px 36px; max-width: 380px; }
.card h1 { margin: 12px 0 6px; font-size: 24px; }
.card p { color: var(--muted); margin: 0 0 20px; }
.btn { display: inline-block; background: #009AB1; color: #fff; text-decoration: none; font-weight: 600; padding: 10px 22px; border-radius: 9px; }
.demo-note { position: fixed; right: 16px; bottom: 12px; background: #FF9F1C; color: #1a1300; font-weight: 700; padding: 6px 12px; border-radius: 8px; font-size: 13px; }

/* phone and narrow screens */
@media (min-width: 1101px) {
  /* office screen: everything fits on one screen, no page scroll */
  #app { height: 100vh; }
  .main-col { overflow: hidden; }
}
@media (max-width: 1100px) {
  .columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .view { flex-direction: column; }
  .side { display: contents; }
  .side .panel:first-child { order: -1; }
  .side .panel.grow { order: 1; max-height: 70vh; }
}
@media (max-width: 640px) {
  #app { padding: 14px 16px 20px; gap: 14px; }
  .columns { grid-template-columns: 1fr; }
  .pills { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .views { order: 4; }
  .clock { display: none; }
  .procs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .proc .val { font-size: 30px; }
  .popup { width: calc(100% - 24px); left: 12px !important; }
}

#process-bands { display: flex; flex-direction: column; gap: 18px; }

/* settings panel, pairing */
.menu-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; font-size: 20px; width: 44px; height: 40px; cursor: pointer; }
.card .alt { margin: 18px 0 0; font-size: 14px; }
.card a:not(.btn), .sheet a { color: var(--accent); }
.card:has(#gate-pair:not([hidden])) { max-width: 640px; }
.code { white-space: nowrap; font-family: var(--mono); font-size: clamp(40px, 9vw, 96px); font-weight: 700; letter-spacing: 6px; margin: 10px 0; color: var(--live); }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; justify-content: flex-end; }
.sheet-card { position: relative; width: min(420px, 100%); height: 100%; overflow: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 22px 20px 30px; }
.sheet-card h2 { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--accent); margin: 18px 0 8px; }
.sheet-card .close { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { border: 0; cursor: pointer; font: inherit; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); padding: 9px 14px; }
.screens { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.screens li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 9px; padding: 10px 12px; }
.screens small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.pair-form { display: grid; gap: 10px; background: var(--panel-2); border-radius: 10px; padding: 12px; }
.pair-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.pair-form input:not([type=checkbox]) { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.pair-form fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0; padding: 8px 10px; display: grid; gap: 6px; }
.pair-form legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.pair-form .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
