/* Engineering Runtime Control Plane — demo portal.
 *
 * Visual system aligned with engineeringruntime.com:
 *   - Header chrome: blue → black gradient (always)
 *   - Body: white (light) or dark slate (dark), via data-theme
 *
 * Component rules remain a hand-port of the enterprise portal so the two
 * products still read as one family. When the docs site banner tokens change,
 * change `--er-banner-gradient` here too.
 */

:root,
[data-theme="light"] {
  --ink: #ffffff;
  --panel: #ffffff;
  --panel-2: #f4f7fb;
  --canvas: #f8fafc;
  --line: rgba(15, 40, 80, 0.12);
  --text: #0f172a;
  --muted: #64748b;
  --soft: #334155;
  --accent: #3b82f6;
  --accent-bright: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #0284c7;
  --offline: #64748b;

  --serif: "Source Serif 4", Georgia, serif;
  --sans: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(15, 40, 80, 0.06);
  --bar-track: rgba(15, 40, 80, 0.08);
  --badge-neutral-bg: rgba(15, 40, 80, 0.06);
  --backdrop: rgba(15, 40, 80, 0.4);
  --nav-hover-bg: rgba(59, 130, 246, 0.08);
  --row-hover-bg: rgba(59, 130, 246, 0.06);

  /* Measured at runtime (app.js) so sticky layout clears the chrome. */
  --banner-h: 44px;
  --header-h: 64px;
  --chrome-h: calc(var(--banner-h) + var(--header-h));

  /* Same tokens as engineering-runtime-series/docs/stylesheets/extra.css */
  --er-header-bg: #041530;
  --er-banner-gradient: linear-gradient(90deg, #0b3d91 0%, #041530 42%, #000000 100%);
  --er-banner: url("/assets/header-banner.svg");
}

[data-theme="dark"] {
  --ink: #0b1220;
  --panel: #111827;
  --panel-2: #1a2438;
  --canvas: #0b1220;
  --line: rgba(147, 197, 253, 0.14);
  --text: #e8eef9;
  --muted: #8b9bb8;
  --soft: #c5d0e6;
  --accent: #3b82f6;
  --accent-bright: #60a5fa;
  --accent-2: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --danger: #f07178;
  --warn: #f0b429;
  --ok: #38bdf8;
  --offline: #64748b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --bar-track: rgba(255, 255, 255, 0.06);
  --badge-neutral-bg: rgba(255, 255, 255, 0.05);
  --backdrop: rgba(0, 6, 22, 0.65);
  --nav-hover-bg: rgba(59, 130, 246, 0.1);
  --row-hover-bg: rgba(59, 130, 246, 0.08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  background: var(--ink);
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ─── Demo banner ────────────────────────────────────────────────────────
   Sticky rather than fixed: it holds its place in flow, so nothing needs a
   compensating body offset, and it never scrolls out of view.
   Light theme uses opaque amber + dark ink (cream text was for the old dark
   canvas and went invisible on white). Dark theme keeps the translucent strip. */
.demo-banner {
  position: sticky;
  top: 0;
  /* Above the page and the rail, below the audit drawer/backdrop (30/40) —
     an open drawer is modal and should not have a strip sitting on it. */
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.87rem;
  line-height: 1.4;
  color: #78350f;
  background: #fff7ed;
  border-bottom: 1px solid #fbbf24;
}

.demo-tag {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  color: #0d0a02;
  background: #f59e0b;
  font-weight: 600;
}

.demo-copy strong { color: #92400e; }

[data-theme="dark"] .demo-banner {
  color: #ffe9c2;
  background: linear-gradient(90deg, rgba(240, 180, 41, 0.22), rgba(240, 180, 41, 0.1));
  border-bottom: 1px solid rgba(240, 180, 41, 0.4);
  backdrop-filter: blur(8px);
}

[data-theme="dark"] .demo-tag {
  background: var(--warn);
}

[data-theme="dark"] .demo-copy strong { color: #fff3d6; }

/* ─── Site header (blue → black, always) ─────────────────────────────── */
.site-header {
  position: sticky;
  top: var(--banner-h);
  z-index: 21;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  color: #ffffff;
  background-color: var(--er-header-bg);
  background-image: var(--er-banner-gradient), var(--er-banner);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-position: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.site-header .brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0;
}

.site-header .brand-mark {
  width: 40px;
  height: 40px;
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}

.site-header .brand-name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.site-header .brand-sub {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* White control on the blue→black header — same treatment as docs/header
   chrome: readable at a glance instead of a translucent ghost on black. */
.site-header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* White pill — same family as theme-toggle; back to the main website. */
.site-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.25rem;
  padding: 0 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: #041530;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}

.site-home-link:hover {
  background: #e8eef9;
  color: #0b3d91;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: #041530;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.theme-toggle:hover {
  background: #e8eef9;
  border-color: #ffffff;
  color: #0b3d91;
}

.theme-icon { display: none; }

[data-theme="light"] .theme-icon-moon { display: block; }
[data-theme="dark"] .theme-icon-sun { display: block; }

/* ─── Shell ──────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - var(--chrome-h));
}

.rail {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  position: sticky;
  /* Parks below the demo banner + site header. */
  top: var(--chrome-h);
  height: calc(100vh - var(--chrome-h));
  overflow-y: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 0.75rem;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  white-space: nowrap;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--soft);
  cursor: pointer;
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.nav button:hover {
  border-color: rgba(59, 130, 246, 0.2);
  background: var(--nav-hover-bg);
  color: var(--text);
}

.nav button.active {
  border-color: rgba(59, 130, 246, 0.4);
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

/* Nav icons are 24×24 stroke drawings sized down, matching the enterprise
   portal's lucide set in weight and metrics. */
.ic {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail-foot {
  margin-top: auto;
  display: grid;
  gap: 0.4rem;
  padding: 1rem 1.25rem 1.25rem;
}

.demo-mode {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.demo-mode-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.demo-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
}

.mode-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.4rem 0.35rem;
  border-radius: 6px;
  cursor: pointer;
}

.mode-btn[aria-pressed="true"] {
  border-color: var(--accent, #0b57d0);
  color: var(--text);
  background: color-mix(in srgb, var(--accent, #0b57d0) 12%, var(--panel));
}

#api-base-note {
  font-size: 0.68rem;
  word-break: break-all;
}

.content { min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem 1.5rem;
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.topbar-title {
  font-family: var(--serif);
  font-size: 1.125rem;
  font-weight: 600;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.main { padding: 1.5rem; }

/* ─── Page hero ──────────────────────────────────────────────────────── */
.hero {
  max-width: 48rem;
  margin-bottom: 2rem;
  animation: rise 420ms ease both;
}

.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.9rem, 2.6vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.025em;
}

.hero-lede {
  margin: 0.75rem 0 0;
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--accent-bright);
}

.hero-sub {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--muted);
}

.view { animation: rise 480ms ease both; }

/* Section header inside a page — "Overview", "Recent audit", filters. */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.section-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-head p {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* ─── Panels & stats ─────────────────────────────────────────────────── */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.grid { display: grid; gap: 1rem; }

.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* Sans, not serif: the enterprise portal renders stat values in the sans
   face at 1.875rem/600, and the two products must not diverge on the most
   glanced-at number on the page. */
.stat .value {
  margin-top: 0.5rem;
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.stat .hint {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.two-col { grid-template-columns: 1.4fr 1fr; }

/* ─── Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

thead th {
  padding: 0.5rem 1rem 0.5rem 0;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
}

tbody td {
  padding: 0.5rem 1rem 0.5rem 0;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr { cursor: pointer; transition: background 140ms ease; }
tbody tr:hover { background: var(--row-hover-bg); }

td.cmd { font-family: var(--mono); font-size: 0.78rem; }

.mono { font-family: var(--mono); font-size: 0.85rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ─── Badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--badge-neutral-bg);
  color: var(--soft);
}

.badge.ok, .badge.allowed, .badge.connected, .badge.online { background: rgba(56, 189, 248, 0.15); color: var(--ok); }
.badge.denied, .badge.degraded { background: rgba(240, 113, 120, 0.15); color: var(--danger); }
.badge.warn, .badge.idle { background: rgba(240, 180, 41, 0.15); color: var(--warn); }
.badge.offline { background: var(--badge-neutral-bg); color: var(--offline); }
.badge.accent { background: var(--accent-soft); color: var(--accent-bright); }

/* ─── Controls ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 140ms ease, border-color 140ms ease;
}

.btn:hover { background: var(--accent-2); }

.btn.secondary {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.btn.secondary:hover { background: var(--nav-hover-bg); }
.btn:disabled { opacity: 0.5; cursor: default; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.toolbar input, .toolbar select {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  min-width: 150px;
  outline: none;
}

.toolbar input { min-width: 240px; flex: 1; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); }

/* ─── Cards (fleet / providers / capabilities) ───────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.tile {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1rem;
  box-shadow: var(--shadow);
  transition: border-color 180ms ease, transform 180ms ease;
}

.tile:hover { border-color: rgba(59, 130, 246, 0.45); transform: translateY(-2px); }

.tile h4 {
  margin: 0.6rem 0 0.2rem;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
}

.tile-rows { margin-top: 0.75rem; display: grid; gap: 0.3rem; font-size: 0.85rem; }
.tile-rows .k { color: var(--muted); }

/* ─── Policies ───────────────────────────────────────────────────────── */
.policy-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; }
.policy-list { display: grid; gap: 0.5rem; align-content: start; }

.policy-item {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  cursor: pointer;
  color: inherit;
}

.policy-item:hover { border-color: rgba(59, 130, 246, 0.35); }
.policy-item.active-item { border-color: rgba(59, 130, 246, 0.55); background: var(--accent-soft); }

.policy-yaml {
  width: 100%;
  min-height: 380px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  resize: vertical;
  color: var(--text);
  outline: none;
}

.policy-yaml:focus { border-color: var(--accent); }

/* Publish failures (malformed YAML, duplicate version) render here instead
   of re-rendering the page, so the operator's unsaved edits survive. */
.policy-error.hidden { display: none; }

.policy-error {
  margin-bottom: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(240, 113, 120, 0.45);
  background: rgba(240, 113, 120, 0.12);
  color: var(--danger);
  font-size: 0.85rem;
}

/* ─── Bars ───────────────────────────────────────────────────────────── */
.bars { display: grid; gap: 0.6rem; }

.bar-row {
  display: grid;
  grid-template-columns: 96px 1fr 36px;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.85rem;
}

.bar-track { height: 8px; border-radius: 999px; background: var(--bar-track); overflow: hidden; }

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  width: 0;
  transition: width 700ms cubic-bezier(.2, .8, .2, 1);
}

/* Pulses on each successful auto-refresh — the page polls, and the ticking
   clock alone should not be the only thing implying the data is live. */
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.live-dot.pulse { background: var(--ok); box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.18); }

/* ─── Drawer ─────────────────────────────────────────────────────────── */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(440px, 100%);
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 40;
  padding: 1.25rem;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 220ms ease;
}

.drawer.hidden { transform: translateX(105%); }

.backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 30; }
.backdrop.hidden { display: none; }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.drawer-head h2 { margin: 0; font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }

.kv { display: grid; gap: 0.6rem; }

.kv div {
  display: grid;
  gap: 0.2rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.kv dt { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; }
.kv dd { margin: 0; font-size: 0.9rem; }

.empty { color: var(--muted); padding: 1.5rem 0; font-size: 0.9rem; }

/* ─── Footer ─────────────────────────────────────────────────────────── */
.demo-foot {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  max-width: 70ch;
  font-size: 0.85rem;
  color: var(--soft);
}

.demo-foot p { margin: 0 0 0.7rem; }
.demo-foot strong { color: var(--warn); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: relative;
    top: 0;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .two-col, .policy-layout { grid-template-columns: 1fr; }
  .main { padding: 1rem; }
  .topbar { padding: 0.85rem 1rem; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  .site-header { padding: 0.75rem 1rem; }
}
