/* CommandCenter · ops console styling. Dark first, light via prefers-color-scheme. */

:root {
  --bg: #0d0f13;
  --panel: #151820;
  --panelRaised: #1b1f29;
  --line: #262b37;
  --text: #e7e9ee;
  --muted: #8b93a5;
  --faint: #5a6275;
  --ok: #34c37a;
  --warn: #e8a33d;
  --down: #ef5350;
  --blocked: #7c84a0;
  --idle: #4a5163;
  --pending: #3a4050;
  --accent: #5b8def;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panelRaised: #fafbfc;
    --line: #e1e4ea;
    --text: #1a1d24;
    --muted: #5d6576;
    --faint: #9aa1b0;
    --ok: #1f9d5c;
    --warn: #c47d12;
    --down: #d93a37;
    --blocked: #8b93a8;
    --idle: #c3c8d2;
    --pending: #d9dce3;
    --accent: #2f6fe0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panelRaised);
  padding: 6px 12px;
}
button:hover { border-color: var(--faint); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }

/* ---------- top bar ---------- */
.topBar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .01em; }
.brandMark { width: 12px; height: 12px; border-radius: 50%; background: var(--pending); }
.tally { display: flex; gap: 12px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.tally span b { color: var(--text); font-weight: 600; }
.topActions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.updated { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.updated.stale { color: var(--down); }

main { padding: 16px; max-width: 1500px; margin: 0 auto; display: grid; gap: 22px; }

/* ---------- status colors ---------- */
.s-ok { --s: var(--ok); }
.s-warn { --s: var(--warn); }
.s-down { --s: var(--down); }
.s-blocked { --s: var(--blocked); }
.s-idle { --s: var(--idle); }
.s-pending { --s: var(--pending); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--s); flex: none; }
.s-down .dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 25%, transparent); }

/* ---------- access strip ---------- */
.accessStrip { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.gatewayCard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--s);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid; gap: 8px;
}
.gatewayCard.s-down { background: color-mix(in srgb, var(--down) 7%, var(--panel)); }
.gatewayHead { display: flex; align-items: center; gap: 10px; }
.gatewayHead h2 { margin: 0; font-size: 15px; }
.gatewayHead .host { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.gatewaySummary { font-size: 14px; }
.gatewayMeta { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.gatewayActions { display: flex; gap: 8px; flex-wrap: wrap; }
.tunnelRow { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--muted);
}
.pill strong { color: var(--text); font-weight: 500; }

/* ---------- sections and cards ---------- */
.sections { display: grid; gap: 22px; }
.section h2, .eventsPanel h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 10px; display: flex; gap: 10px; align-items: center;
}
.section h2 .sectionTally { font-family: var(--mono); text-transform: none; letter-spacing: 0; color: var(--faint); }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 10px;
  display: grid; gap: 8px; align-content: start;
  cursor: pointer; text-align: left;
  position: relative;
}
.card:hover { border-color: var(--faint); }
.card::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--s);
}
.cardHead { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cardHead h3 { margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cardHead .sub { flex: 0 1000 auto; }
.cardHead .sub { color: var(--faint); font-family: var(--mono); font-size: 11px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.summary { color: var(--muted); font-size: 12.5px; min-height: 18px; overflow-wrap: anywhere; }
.s-down .summary { color: var(--text); }

.meters { display: grid; gap: 4px; }
.meter { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.meterBar { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.meterBar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meterBar i.hot { background: var(--warn); }
.meterBar i.crit { background: var(--down); }
.meter span:last-child { text-align: right; color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 5px; background: var(--panelRaised); border: 1px solid var(--line); color: var(--muted); font-family: var(--mono); }
.chip.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.chip.off { color: var(--faint); text-decoration: line-through; }

.cardFoot { display: flex; align-items: end; gap: 8px; }
.ticks { display: flex; gap: 1.5px; height: 14px; align-items: stretch; flex: 1; min-width: 0; overflow: hidden; }
.ticks i { flex: 1 1 0; max-width: 5px; border-radius: 1px; background: var(--s); opacity: .85; }
.age { font-family: var(--mono); font-size: 10.5px; color: var(--faint); white-space: nowrap; }

/* ---------- events ---------- */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 12.5px; }
.events li { display: grid; grid-template-columns: 70px 16px minmax(120px, 220px) 1fr; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 6px; }
.events li:nth-child(odd) { background: var(--panel); }
.events time { font-family: var(--mono); color: var(--faint); font-size: 11.5px; }
.events .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.events .why { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- dialog ---------- */
dialog {
  width: min(720px, 94vw); max-height: 86vh;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
.dialogHead { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); margin: 0; }
.dialogHead h3 { margin: 0; font-size: 15px; display: flex; gap: 8px; align-items: center; }
#detailBody { padding: 14px 18px 18px; display: grid; gap: 14px; overflow: auto; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.raw { font-family: var(--mono); font-size: 11.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 300px; overflow: auto; }
.spark { width: 100%; height: 70px; display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--panelRaised); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; opacity: 0; transition: .2s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  main { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
  .events li { grid-template-columns: 56px 12px 1fr; }
  .events .why { display: none; }
  .tally { order: 3; width: 100%; }
}
