:root {
  --bg: #0A0B0D;
  --surface: #0F1114;
  --surface-alt: #12151A;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --fg: #E7E9EC;
  --dim: rgba(231, 233, 236, 0.55);
  --dimmer: rgba(231, 233, 236, 0.35);
  --accent: #00D4C8;
  --green: #00C389;
  --red: #E5484D;
  --warn: #F5A524;
  --radius: 2px;
  --font-display: "Inter Tight", "Inter", system-ui, -apple-system, sans-serif;
  --font-body: "Inter Tight", "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--fg);
  background: var(--bg);
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 64px 64px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}

.page-shell {
  width: min(1380px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.auth-shell {
  display: grid;
  align-items: center;
  min-height: 100vh;
}

.session-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
}

.session-toolbar-actions-only {
  justify-content: flex-end;
}

.session-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.session-email {
  display: block;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.session-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.admin-tab-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.admin-tab {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  cursor: pointer;
}

.admin-tab-active {
  color: var(--fg);
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.admin-tab-row a.admin-tab {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.9fr);
  gap: 16px;
  margin-bottom: 24px;
  align-items: stretch;
}

.hero-copy,
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.hero-copy {
  padding: 32px 32px 28px;
  position: relative;
  overflow: hidden;
}

.hero-copy::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(ellipse at 90% 30%, #000 30%, transparent 75%);
  mask-image: radial-gradient(ellipse at 90% 30%, #000 30%, transparent 75%);
  opacity: 0.5;
  pointer-events: none;
}

.hero-copy > * {
  position: relative;
}

.eyebrow,
.section-label {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 500;
  font-family: var(--font-mono);
}

.hero h1,
.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.025em;
  color: var(--fg);
}

.hero h1 {
  max-width: 18ch;
  font-size: clamp(1.85rem, 3.2vw, 3rem);
  line-height: 1.04;
}

.hero-text {
  margin: 18px 0 0;
  max-width: 64ch;
  color: var(--dim);
  line-height: 1.6;
  font-size: 0.97rem;
}

.hero-status {
  padding: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.card {
  padding: 22px;
}

.authority-shell {
  width: min(1540px, calc(100vw - 48px));
}

.authority-hero {
  min-height: 116px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border: 1px solid var(--border);
  background:
    linear-gradient(120deg, rgba(0, 212, 200, 0.12), transparent 42%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  padding: 28px 30px;
  margin-bottom: 16px;
}

.authority-hero h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4.8rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 0.96;
}

.authority-flow {
  position: relative;
  min-height: 248px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  overflow: hidden;
  margin-bottom: 16px;
}

.authority-flow-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.7;
  pointer-events: none;
}

.authority-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 10 14;
  filter: drop-shadow(0 0 8px rgba(0, 212, 200, 0.35));
  animation: authorityFlow 7s linear infinite;
}

.authority-line-b {
  stroke: rgba(0, 195, 137, 0.8);
  animation-duration: 9s;
  animation-direction: reverse;
}

@keyframes authorityFlow {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -120; }
}

.authority-node {
  position: relative;
  z-index: 1;
  min-height: 178px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(15, 17, 20, 0.82);
  padding: 22px;
}

.authority-node span,
.authority-node small {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--dim);
  font-size: 0.68rem;
}

.authority-node strong {
  font-size: clamp(2.2rem, 5vw, 4.6rem);
  font-weight: 500;
  line-height: 0.95;
}

.authority-kpi-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 16px;
}

.authority-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 16px;
}

.authority-panel-wide {
  grid-column: 1 / -1;
}

.authority-table {
  display: grid;
  gap: 8px;
}

.authority-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 68px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.025);
}

.authority-row strong,
.authority-row span,
.authority-row small {
  display: block;
}

.authority-row strong {
  font-weight: 500;
  margin-bottom: 4px;
}

.authority-row span,
.authority-row small {
  color: var(--dim);
  font-size: 0.82rem;
  line-height: 1.35;
}

.authority-row small {
  margin-top: 5px;
  font-family: var(--font-mono);
  color: var(--dimmer);
  overflow-wrap: anywhere;
}

/* Asset-grouped authority panels (feeds + warmup): exceptions-first, one
   expandable row per asset instead of one row per (asset x TF). Scales to
   hundreds of assets; non-green assets open by default, green collapse. */
.auth-group {
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: 6px;
  overflow: hidden;
}
.auth-group-success { border-left-color: rgba(0, 195, 137, 0.55); }
.auth-group-pending { border-left-color: rgba(245, 165, 36, 0.7); }
.auth-group-danger  { border-left-color: rgba(229, 72, 77, 0.8); }

.auth-group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.auth-group-head:hover { background: rgba(255, 255, 255, 0.03); }
.auth-group-head strong { font-weight: 600; letter-spacing: 0.03em; }
.auth-group-caret { width: 12px; color: var(--dim); font-size: 0.72rem; }
.auth-group-provider { color: var(--dim); font-size: 0.8rem; font-family: var(--font-mono); }
.auth-group-bind { color: var(--dimmer); font-size: 0.78rem; font-family: var(--font-mono); margin-left: auto; }
.auth-group-covers { color: var(--dimmer); font-size: 0.78rem; font-family: var(--font-mono); margin-left: 14px; }

.auth-group-body {
  padding: 2px 12px 10px 34px;
  display: grid;
  gap: 5px;
}
.auth-tf-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--dim);
  font-family: var(--font-mono);
}
.auth-tf { min-width: 44px; color: rgba(255, 255, 255, 0.86); font-weight: 500; }
.auth-tf-cov { min-width: 74px; color: var(--dimmer); }
.auth-tf-meta { color: var(--dimmer); overflow-wrap: anywhere; }

.warmup-bar {
  display: inline-block;
  width: 84px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  vertical-align: middle;
}
.warmup-bar-fill { display: block; height: 100%; background: rgba(245, 165, 36, 0.85); }
.warmup-pct { font-size: 0.74rem; color: var(--dimmer); min-width: 34px; }

/* Unified asset pipeline: one row per asset (feed -> warmup -> decisions),
   exceptions surfaced, healthy assets collapsed into a chip strip. */
.authority-pipeline { display: grid; gap: 6px; }
.pipe-section-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--warn); margin: 6px 2px 2px;
}
.auth-group-head .pipe-facet {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.76rem; color: var(--dim); font-family: var(--font-mono);
  margin-left: 16px;
}
.auth-group-head .pipe-facet:first-of-type { margin-left: auto; }
.pipe-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0; }
.pipe-chip {
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 500;
  letter-spacing: 0.04em; padding: 3px 9px; border-radius: var(--radius);
  background: rgba(0, 195, 137, 0.08); color: var(--green);
  border: 1px solid rgba(0, 195, 137, 0.25);
}
.pipe-detail-sep {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--dimmer); margin: 9px 0 3px; border-top: 1px solid var(--border); padding-top: 7px;
}

.authority-row-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 240px;
  text-align: right;
}

.authority-row-meta span:not(.pill) {
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.authority-mini-pill {
  min-height: 24px;
  padding: 0 9px;
  font-size: 0.66rem;
}

.authority-row-danger {
  border-color: rgba(229, 72, 77, 0.42);
}

.authority-row-pending {
  border-color: rgba(245, 165, 36, 0.38);
}

@media (max-width: 960px) {
  .authority-flow,
  .authority-kpi-grid,
  .authority-grid {
    grid-template-columns: 1fr;
  }

  .authority-flow-lines {
    display: none;
  }

  .authority-row {
    grid-template-columns: 1fr;
  }

  .authority-row-meta {
    justify-content: flex-start;
    min-width: 0;
    text-align: left;
  }
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-head h2 {
  font-size: 1.45rem;
  margin-top: 4px;
}

.current-time-line {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: var(--radius);
  font-size: 0.7rem;
  font-weight: 500;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid transparent;
}

.pill-neutral {
  background: rgba(255, 255, 255, 0.04);
  color: var(--dim);
  border-color: var(--border);
}

.pill-success {
  background: rgba(0, 195, 137, 0.1);
  color: var(--green);
  border-color: rgba(0, 195, 137, 0.25);
}

.pill-pending {
  background: rgba(245, 165, 36, 0.08);
  color: var(--warn);
  border-color: rgba(245, 165, 36, 0.22);
}

.pill-danger {
  background: rgba(229, 72, 77, 0.1);
  color: var(--red);
  border-color: rgba(229, 72, 77, 0.28);
}

/* Zero-delta Algo intent: an open Algo position that netted to zero broker
   delta (equal-and-opposite Algos on the same bar). No broker order, no fee.
   Amber/informational — NOT a broker fill. */
.pill-netted {
  background: rgba(245, 165, 36, 0.08);
  color: var(--warn);
  border-color: rgba(245, 165, 36, 0.22);
}

.stack {
  display: grid;
  gap: 16px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-mono);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input::placeholder {
  color: var(--dimmer);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 212, 200, 0.15);
}

input:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23E7E9EC' opacity='0.55' d='M0 0h10L5 6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 0.85rem;
  line-height: 1;
  letter-spacing: -0.005em;
  cursor: pointer;
  font-family: var(--font-display);
  text-decoration: none;
  transition: opacity 140ms ease, background 140ms ease, border-color 140ms ease;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.78rem;
}

.button-tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.72rem;
}

.button-primary {
  color: #0A0B0D;
  background: var(--accent);
}

.button-primary:not(:disabled):hover {
  background: #2EE1D6;
}

.button-secondary {
  color: var(--fg);
  background: transparent;
  border-color: var(--border-strong);
}

.button-secondary:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.04);
}

.auth-card {
  padding: 20px;
}

.auth-tab-row {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  padding: 6px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.auth-tab {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  cursor: pointer;
}

.auth-tab-active {
  color: var(--fg);
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.allowlist-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.allowlist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.allowlist-row strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}

.allowlist-meta {
  color: var(--dim);
  font-size: 0.76rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.message,
.empty-state {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  line-height: 1.55;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.message-muted,
.empty-state {
  color: var(--dim);
  background: rgba(255, 255, 255, 0.02);
}

.message-error {
  color: var(--red);
  background: rgba(229, 72, 77, 0.06);
  border-color: rgba(229, 72, 77, 0.22);
}

.message-success {
  color: var(--green);
  background: rgba(0, 195, 137, 0.06);
  border-color: rgba(0, 195, 137, 0.22);
}

.message-warning {
  color: var(--warn);
  background: rgba(245, 165, 36, 0.06);
  border-color: rgba(245, 165, 36, 0.24);
}

.metrics,
.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--border);
  border-bottom: none;
  border-right: none;
}

.metric,
.mini-card {
  padding: 8px 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.metric-label,
.mini-label {
  margin: 0 0 4px;
  font-size: 0.58rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-mono);
  font-weight: 500;
}

.metric-value,
.mini-value {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(0.85rem, 1.4vw, 1.05rem);
  font-weight: 500;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.net-position-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--fg);
}

.net-position-summary:empty,
.net-position-summary.hidden {
  display: none;
}

.kv {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
}

.kv div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
}

.kv dt {
  color: var(--dim);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-mono);
}

.kv dd {
  margin: 0;
  font-weight: 400;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.recommendations {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.recommendation {
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
}

.recommendation-launched {
  border-color: rgba(0, 195, 137, 0.42);
  background:
    linear-gradient(180deg, rgba(0, 195, 137, 0.08), rgba(0, 195, 137, 0.02)),
    var(--surface-alt);
}

.recommendation-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.recommendation h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.015em;
}

.recommendation-meta {
  margin: 4px 0 0;
  color: var(--dim);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.recommendation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--border);
  border-bottom: none;
  border-right: none;
}

.rec-stat {
  padding: 12px 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.rec-stat-label {
  margin: 0 0 6px;
  color: var(--dim);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-family: var(--font-mono);
}

.rec-stat-value {
  margin: 0;
  font-weight: 500;
  font-size: 0.95rem;
  font-family: var(--font-mono);
  color: var(--fg);
}

.recommendation-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
}

.recommendation-disclaimer {
  margin: 14px 0 0;
  color: var(--dim);
  font-size: 0.76rem;
  line-height: 1.6;
  font-family: var(--font-mono);
}

.recommendation-status {
  margin: 0;
  color: var(--dim);
  font-size: 0.78rem;
  line-height: 1.5;
  font-family: var(--font-mono);
}

.recommendation-status-success {
  color: var(--green);
}

.recommendation-status-pending {
  color: var(--warn);
}

.button-confirmed,
.button-confirmed:disabled {
  border-color: rgba(0, 195, 137, 0.32);
  background: rgba(0, 195, 137, 0.16);
  color: var(--green);
  opacity: 1;
  cursor: default;
}

.engine-row {
  align-items: center;
  cursor: pointer;
}

.engine-row-selected {
  background: rgba(255, 255, 255, 0.04);
  border-left: 2px solid var(--green);
}

.engine-row-selected.engine-row-health-yellow {
  border-left-color: #f59e0b;
}

.engine-row-selected.engine-row-health-red {
  border-left-color: #dc2626;
}

.engine-summary {
  display: grid;
  gap: 4px;
}

.engine-metrics {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.engine-metrics-row {
  align-items: center;
  gap: 10px;
}

.engine-metrics-tabs {
  align-items: center;
  gap: 8px;
}

.engine-metric-tab {
  display: inline-grid;
  gap: 3px;
  min-width: 118px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  font-family: var(--font-mono);
}

.catalog-row .engine-metric-tab-label {
  color: var(--dim);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.engine-metric-tab-values {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.catalog-row .engine-metric-tab-value {
  color: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.engine-metric-tab-success {
  border-color: rgba(0, 195, 137, 0.3);
  background: rgba(0, 195, 137, 0.08);
  color: var(--green);
}

.engine-metric-tab-danger {
  border-color: rgba(229, 72, 77, 0.35);
  background: rgba(229, 72, 77, 0.08);
  color: var(--red);
}

.engine-metric-tab-neutral {
  color: var(--dim);
}

.catalog-row .engine-metric-equity {
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

/* Traffic-light health dot before each engine name. Green = no marker
 * is needed conceptually, but we still render a small dim dot so the
 * row anchors visually. Yellow + red are the actionable colors. */
.engine-health-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  background: #16a34a;
}
.engine-health-yellow { background: #f59e0b; box-shadow: 0 0 6px rgba(245, 158, 11, 0.6); }
.engine-health-red    { background: #dc2626; box-shadow: 0 0 6px rgba(220, 38, 38, 0.6); }

/* Top alert strip — hidden when all engines are green. */
.engine-health-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 8px 0 12px;
  padding: 8px 12px;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.08);
  color: #f59e0b;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.engine-health-strip-red {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
}
.engine-health-strip-yellow {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  color: #f59e0b;
}
.engine-health-strip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

/* Inspector health banner — shown only when health != green. */
.engine-health-banner {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  white-space: pre-wrap;
}
.engine-health-banner-yellow {
  border: 1px solid #f59e0b;
  background: rgba(245, 158, 11, 0.10);
  color: #f59e0b;
}
.engine-health-banner-red {
  border: 1px solid #dc2626;
  background: rgba(220, 38, 38, 0.10);
  color: #dc2626;
}

/* Recent incidents drawer — collapsed by default; hidden when empty. */
.engine-incidents-drawer {
  margin-bottom: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border, #374151);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.15);
}
.engine-incidents-drawer summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--dim, #9ca3af);
}
.engine-incidents-list {
  margin: 8px 0 0;
  padding: 0 0 0 16px;
  list-style: disc;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--dim, #9ca3af);
  max-height: 200px;
  overflow-y: auto;
}
.engine-incidents-list li {
  margin: 4px 0;
}

/* Trade row latency badges — three numbers showing where time goes:
 *   feed   = bar close → engine event_received
 *   engine = event_received → broker submit
 *   broker = submit → broker fill
 * Hidden if the trade row has no latency timestamps (legacy rows). */
.trade-latency {
  display: block;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--dim, #9ca3af);
  margin-top: 2px;
}
.trade-latency-missing {
  opacity: 0.5;
}
.detail-subhead-hint {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--dim, #9ca3af);
  margin-left: 8px;
  font-family: var(--font-mono);
}

/* Recent trades drawer — closed by default to keep the page clean. The
 * latency data is still streamed; expand to inspect when needed. */
.engine-recent-trades-drawer summary {
  cursor: pointer;
  font-weight: 500;
  margin-bottom: 8px;
}
.engine-recent-trades-drawer summary::-webkit-details-marker {
  color: var(--dim, #9ca3af);
}

/* Auto-backtest verdict badge in engine row status line. Smaller than the
 * normal pills so it doesn't dominate the status line. */
.pill-tiny {
  min-height: 18px;
  padding: 0 6px;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  margin-left: 4px;
}

/* Restart chooser modal — opens when admin clicks the Restart row button.
 * Replaces the previous two-button row layout with a single Restart button
 * that asks the operator which type they want. */
.engine-restart-chooser-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.engine-restart-chooser-card {
  background: var(--card, #1f2937);
  border: 1px solid var(--border, #374151);
  border-radius: 8px;
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.engine-restart-chooser-card h3 {
  margin: 0 0 4px;
}
.engine-restart-chooser-subtitle {
  margin: 0 0 14px;
  color: var(--dim, #9ca3af);
  font-size: 0.85rem;
}
.engine-restart-chooser-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.engine-restart-chooser-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 14px;
  text-align: left;
  white-space: normal;
}
.engine-restart-chooser-option strong {
  font-size: 0.95rem;
}
.engine-restart-chooser-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.78);
  white-space: normal;
}
.engine-restart-chooser-cancel {
  width: 100%;
}

.engine-metric-block {
  display: grid;
  gap: 6px;
}

.engine-metric-label {
  color: var(--dim);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-family: var(--font-mono);
}

.engine-metric-pnl {
  font-weight: 700;
  font-family: var(--font-mono);
}

.engine-metric-dim {
  color: var(--dim);
  font-size: 0.72rem;
  font-family: var(--font-mono);
}

.engine-metric-success {
  color: #16a34a;
}

.engine-metric-danger {
  color: #dc2626;
}

.engine-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.engine-backtest {
  margin-right: 8px;
}

.engine-detail-danger-actions {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.engine-detail-danger-actions .button-danger {
  max-width: 180px;
}

.section-head-tight {
  margin-bottom: 14px;
}

.section-head-tight h3 {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.015em;
}

.engine-dock {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(0, 1.25fr);
  gap: 16px;
  margin-top: 18px;
}

.engine-groups {
  display: grid;
  gap: 16px;
  align-content: start;
}

.engine-group .catalog-list {
  margin-top: 0;
}

.engine-detail {
  padding: 18px;
}

.engine-mini-grid {
  margin-top: 18px;
}

.detail-section {
  margin-top: 18px;
}

.report-card {
  margin-top: 20px;
  padding: 22px;
}

.detail-section h4 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.detail-list {
  display: grid;
  gap: 0;
  border: 1px solid var(--border);
  border-bottom: none;
}

.detail-row {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.detail-row strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
}

.detail-row span {
  color: var(--dim);
  font-size: 0.76rem;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  overflow-wrap: anywhere;
}

.report-actions {
  justify-content: flex-end;
}

.report-identity {
  margin: 6px 0 0;
  color: var(--fg);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.report-identity-accent {
  color: #60a5fa;
}

.report-table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  max-width: 100%;
}

.report-table-wrap-wide {
  max-height: min(68vh, 900px);
  overflow: auto;
}

.report-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.report-table th,
.report-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.report-table th:last-child,
.report-table td:last-child {
  border-right: none;
}

.report-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0d1014;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.66rem;
  font-weight: 500;
}

.report-table tbody tr:nth-child(odd) td {
  background: rgba(255, 255, 255, 0.02);
}

.report-table tbody tr:hover td {
  background: rgba(0, 212, 200, 0.05);
}

.report-table-trades {
  min-width: 1900px;
}

.report-neg {
  color: var(--red);
}

.catalog-list {
  display: grid;
  gap: 0;
  margin-top: 18px;
  border: 1px solid var(--border);
  border-bottom: none;
}

.catalog-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.catalog-row strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
  font-size: 0.92rem;
}

.catalog-row span {
  color: var(--dim);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.hidden {
  display: none !important;
}

/* Tablet */
@media (max-width: 1080px) {
  .grid,
  .hero {
    grid-template-columns: 1fr;
  }
  .page-shell {
    width: min(100vw - 32px, 100%);
  }
}

/* Mobile */
@media (max-width: 720px) {
  .page-shell {
    width: 100%;
    padding: 16px 12px 32px;
  }

  .hero-copy {
    padding: 24px 20px 22px;
  }

  .hero h1 {
    font-size: clamp(1.5rem, 7vw, 2rem);
    line-height: 1.06;
    max-width: 100%;
  }

  .hero-text {
    font-size: 0.92rem;
  }

  .card {
    padding: 18px 16px;
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .section-head h2 {
    font-size: 1.2rem;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .session-toolbar,
  .session-nav,
  .session-actions,
  .allowlist-row {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-tab-row {
    width: 100%;
    justify-content: stretch;
  }

  .admin-tab {
    flex: 1 1 0;
  }

  .metrics,
  .mini-grid {
    grid-template-columns: 1fr;
  }

  .recommendation-grid {
    grid-template-columns: 1fr;
  }

  .kv div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .kv dt {
    font-size: 0.65rem;
  }

  .recommendation-top {
    flex-direction: column;
  }

  .recommendation-actions,
  .engine-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .engine-backtest {
    margin-right: 0;
    order: -1;
  }

  .engine-metrics-tabs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .engine-metric-tab {
    min-width: 0;
  }

  .engine-detail-danger-actions .button-danger {
    max-width: none;
  }

  .engine-dock {
    grid-template-columns: 1fr;
  }

  .report-actions {
    width: 100%;
    justify-content: stretch;
  }

  .button-row {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  input,
  select {
    font-size: 1rem; /* prevent iOS zoom on focus */
  }
}

/* engine dock: stop button + P/L colorization */
.button-danger {
  background: #b91c1c;
  color: #fff;
  border: 1px solid #991b1b;
}
.button-danger:not(:disabled):hover {
  background: #dc2626;
}
.button-danger:disabled {
  background: #4b5563;
  color: #9ca3af;
  cursor: not-allowed;
}
.engine-pnl {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
.engine-pnl-inline .pnl-pill {
  min-height: 26px;
  padding-inline: 10px;
  letter-spacing: 0.04em;
}
.engine-pnl .pnl-meta {
  color: #94a3b8;
  font-size: 0.78rem;
}
.mini-value-success {
  color: #22c55e;
}
.mini-value-danger {
  color: #ef4444;
}
.mini-value-neutral {
  color: inherit;
}

.engine-row-dead {
  border-color: #b91c1c;
  background: rgba(185, 28, 28, 0.08);
}
.engine-row-dead strong { color: #fca5a5; }

.kv-tight dt { font-size: 0.78rem; color: #94a3b8; }
.detail-subhead { margin-top: 1rem; font-size: 0.95rem; color: #cbd5e1; }
.dim-meta { color: #64748b; font-size: 0.75rem; margin-top: 0.5rem; word-break: break-all; }

.sound-menu-wrap {
  position: relative;
  display: inline-block;
}
.sound-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 6px;
  z-index: 50;
}
.sound-menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: 0;
  color: #e5e7eb;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.sound-menu-row:hover { background: #1f2937; }
.sound-menu-row.is-selected { background: #1e3a8a; }
.sound-menu-toggle { font-weight: 600; }
.sound-menu-state { font-size: 0.78rem; }
.sound-menu-state.is-on { color: #22c55e; }
.sound-menu-state.is-off { color: #94a3b8; }
.sound-menu-divider {
  height: 1px;
  background: #1f2937;
  margin: 4px 2px;
}
.sound-menu-check { color: #93c5fd; font-weight: 700; }
.sound-menu-list { display: flex; flex-direction: column; gap: 2px; }

/* ============================================================
 * Apex polish — engine dashboard accents.
 * Cyan accent on the live state, pulsing RUNNING dot, soft halo on
 * the focused row, colored left bar on open positions, smooth scroll.
 * ============================================================ */

:root {
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.18);
  --accent-glow: rgba(56, 189, 248, 0.35);
}

html {
  scroll-behavior: smooth;
}

/* First three mini-cards in the engine detail grid get the hero
 * treatment: bigger value type, accent border, subtle inset glow. */
.mini-card:nth-child(-n+3) {
  border-top: 1px solid var(--accent);
  box-shadow: inset 0 1px 0 var(--accent-glow);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.06), transparent 60%), var(--surface-alt);
}
.mini-card:nth-child(-n+3) .mini-value {
  font-size: clamp(1.05rem, 1.7vw, 1.35rem);
  letter-spacing: -0.015em;
}
.mini-card:nth-child(-n+3) .mini-label {
  color: var(--accent);
  letter-spacing: 0.16em;
}

/* Pulsing live indicator on the RUNNING pill. */
@keyframes apex-pulse-live {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.pill-success::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 6px;
  vertical-align: middle;
  animation: apex-pulse-live 1.8s infinite;
}

/* Soft accent halo on selected engine row + report card. */
.engine-row-selected {
  box-shadow: 0 0 0 1px var(--accent-glow), 0 0 24px -8px var(--accent-glow);
}
.report-card {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-soft), 0 8px 32px -16px rgba(56, 189, 248, 0.2);
}

/* Open positions list — colored left border per side. */
#engine-open-positions > * {
  border-left: 3px solid var(--border);
  padding-left: 10px;
}
#engine-open-positions > *:has(.pill-success) {
  border-left-color: #22c55e;
}
#engine-open-positions > *:has(.pill-danger) {
  border-left-color: #ef4444;
}

/* Backtest-Live report verdict banner. Always rendered as a single-line
 * hero strip at the top of the report card; color depends on the kind. */
.report-verdict {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.report-verdict.hidden { display: none; }
.report-verdict-ok {
  color: #34d399;
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.35);
}
.report-verdict-divergent {
  color: #f87171;
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
}
.report-verdict-failed {
  color: #f87171;
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
}
.report-verdict-stale {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.35);
}
.report-verdict-pending,
.report-verdict-running,
.report-verdict-unavailable {
  color: var(--dim);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}
.report-verdict-offline_gap {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.35);
}

.report-section {
  margin-top: 14px;
}
.report-section-head {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.report-section-collapsible > summary {
  cursor: pointer;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  user-select: none;
}
.report-section-collapsible > summary::-webkit-details-marker { display: none; }
.report-section-collapsible > summary::before {
  content: "▶  ";
  display: inline-block;
  transition: transform 0.15s ease;
}
.report-section-collapsible[open] > summary::before { content: "▼  "; }
.report-section-collapsible[open] > summary { color: var(--accent); }

/* Trade-comparison polish. Tint diff cells by sign so the eye locks
 * onto deltas without re-reading the number. */
.report-table-trades td.report-pos { color: #34d399; }
.report-table-trades td.report-neg { color: #f87171; }

/* Net-position summary — soft accent strip. */
.net-position-summary {
  font-size: 0.95rem;
  padding: 6px 10px;
  border: 1px solid var(--accent-soft);
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-soft), transparent 70%);
}
