@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;600&display=swap');

:root {
  --bg: #dce3e8;
  --bg-2: #cfd8e0;
  --ink: #171a1d;
  --muted: #4f5a63;
  --accent: #0d5b63;
  --accent-2: #d97706;
  --card: #edf2f7dd;
  --card-border: #cbd5df;
  --ok: #0f766e;
  --warn: #b45309;
  --down: #b91c1c;
  --shadow: 0 12px 24px rgba(0,0,0,0.08);
  --page-max-width: 1560px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, #ced9e2 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #c7d6cf 0%, transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  z-index: -1;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 28px 36px 12px;
  gap: 24px;
  max-width: var(--page-max-width);
  margin: 0 auto 0 0;
}

.hero__left {
  min-width: 0;
  flex: 1 1 420px;
}

.hero__kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--muted);
}

.hero h1 {
  margin: 6px 0 8px;
  font-size: 36px;
}

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--muted);
}

.hero__right {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
}

.pill {
  border: 1px solid var(--card-border);
  background: #edf2f6;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: var(--shadow);
}

.nav-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--card-border);
  background: #eef3f7;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.nav-link-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: #cbd5e1;
}

.nav-link-btn--disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: not-allowed;
  box-shadow: none;
}

.grid {
  padding: 16px 36px 36px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  max-width: var(--page-max-width);
  margin: 0 auto 0 0;
}

.card {
  background: var(--card);
  backdrop-filter: blur(4px);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.card--compact {
  padding: 10px 12px;
}

.card--compact h2 {
  margin-bottom: 8px;
}

.card--compact .table th,
.card--compact .table td {
  padding-top: 6px;
  padding-bottom: 6px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.card h3 {
  margin: 18px 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.auth-panel {
  border: 1px dashed #e2e8f0;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 14px;
  background: rgba(231, 238, 245, 0.82);
}

.auth-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.auth-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: center;
}

.auth-row input {
  width: 100%;
}

.auth-status {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.kv {
  display: grid;
  gap: 10px;
  font-size: 13px;
}

.kv__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px dashed #e5e7eb;
}

.kv__row span:last-child {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink);
}

.span-2 {
  grid-column: span 2;
}

.actions, .worker-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

button {
  border: 1px solid var(--card-border);
  background: #eef3f7;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: #cbd5e1;
}

button.danger {
  border-color: #f3b4b4;
  color: #7f1d1d;
  background: #fff1f2;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table th, .table td {
  padding: 8px 6px;
  border-bottom: 1px solid #e7ebef;
  text-align: left;
}

.table-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.table-link:hover {
  text-decoration: underline;
}

.table-row-link {
  cursor: pointer;
}

.table-row-link:hover td,
.table-row-link:focus-visible td {
  background: rgba(0, 109, 119, 0.08);
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

.per-symbol-performance-table {
  min-width: 2050px;
  white-space: nowrap;
}

.per-symbol-performance-table th:first-child,
.per-symbol-performance-table td:first-child {
  text-align: left;
}

.per-symbol-performance-table th:not(:first-child),
.per-symbol-performance-table td:not(:first-child) {
  text-align: right;
}

.per-symbol-performance-table .per-symbol-totals-row td {
  font-weight: 700;
  border-top: 2px solid #d9e2ea;
  background: rgba(255, 255, 255, 0.72);
}

.adaptive-grace-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 12px 0 16px;
}

.adaptive-grace-card {
  padding: 10px 12px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.adaptive-grace-card__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.adaptive-grace-card__value {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}

.adaptive-grace-empty {
  margin: 12px 0 0;
  padding: 14px 16px;
  border: 1px dashed var(--card-border);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.adaptive-grace-table td {
  vertical-align: middle;
}

.audit-pill--watch {
  background: rgba(255, 173, 66, 0.18);
  color: #b45309;
  border: 1px solid rgba(255, 173, 66, 0.45);
}

.health-ok { color: var(--ok); font-weight: 600; }
.health-warn { color: var(--warn); font-weight: 600; }
.health-down { color: var(--down); font-weight: 600; }
.health-idle { color: var(--muted); font-weight: 600; }

.log-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

select, input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  font-size: 13px;
  background: #fff;
}

.toggle {
  grid-auto-flow: row;
}

.toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.log {
  margin-top: 12px;
  background: #0b1020;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 12px;
  max-height: 420px;
  overflow: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.log-path {
  margin-top: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--muted);
}

.footer {
  display: flex;
  justify-content: space-between;
  padding: 10px 36px 24px;
  font-size: 12px;
  color: var(--muted);
  max-width: var(--page-max-width);
  margin: 0 auto 0 0;
}

.paper-layout {
  padding: 16px 36px 36px;
  display: grid;
  gap: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 4px 0 0;
}

.range-toggle {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-toggle button {
  min-width: 74px;
}

.range-toggle button.is-active {
  border-color: var(--accent);
  background: #e0f2f1;
  color: #0f5a60;
}

.paper-summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.paper-stat,
.mini-stat {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px;
}

.paper-stat span,
.mini-stat span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.paper-stat strong,
.mini-stat strong {
  font-size: 20px;
  font-weight: 700;
}

.mini-stat strong {
  font-size: 15px;
}

.pnl-trend {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 82px;
  margin-top: 6px;
  padding: 2px 6px;
  border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pnl-trend--up {
  background: #dcfce7;
  color: #166534;
}

.pnl-trend--down {
  background: #fee2e2;
  color: #991b1b;
}

.pnl-trend--flat {
  background: #f1f5f9;
  color: #475569;
}

.chart-shell {
  margin-top: 16px;
  padding: 12px;
  position: relative;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.85), rgba(240,247,246,0.8));
  border: 1px solid #d9e7e6;
}

.chart-shell--bot {
  margin-top: 14px;
}

.chart-svg {
  width: 100%;
  height: 100%;
  min-height: 170px;
  display: block;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line-overlay {
  stroke: #334155;
  stroke-width: 1.5;
  stroke-dasharray: 7 6;
  opacity: 0.85;
}

.chart-area {
  stroke: none;
  opacity: 0.14;
}

.chart-area.pnl-pos {
  fill: var(--ok);
}

.chart-area.pnl-neg {
  fill: var(--down);
}

.chart-area.pnl-flat {
  fill: #64748b;
}

.chart-dot {
  stroke-width: 1.5;
  fill: #fff;
}

.chart-zero {
  stroke: #cbd5e1;
  stroke-width: 2;
  stroke-dasharray: 8 8;
}

.chart-marker-line,
.chart-marker-tip {
  fill: none;
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-marker-buy .chart-marker-line,
.chart-marker-buy .chart-marker-tip {
  stroke: var(--ok);
}

.chart-marker-sell .chart-marker-line,
.chart-marker-sell .chart-marker-tip {
  stroke: var(--down);
}

.pnl-pos {
  color: var(--ok);
  stroke: var(--ok);
}

.pnl-neg {
  color: var(--down);
  stroke: var(--down);
}

.pnl-flat {
  color: var(--muted);
  stroke: #64748b;
}

.exposure-warning { color: var(--warn, #f59e0b); margin-left: 3px; font-weight: bold; }

.chart-neutral {
  color: #111827;
  stroke: #111827;
}

.chart-area.chart-neutral {
  fill: #111827;
  opacity: 0.08;
}

.chart-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 10px 0;
}

.chart-overlay-card {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  min-width: 136px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.chart-overlay-card__title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chart-overlay-card__row {
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  font-weight: 700;
}

.chart-overlay-card__meta {
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
}

.paper-note {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.paper-bot-stack {
  display: grid;
  gap: 18px;
}

.lane-summary-grid {
  display: grid;
  gap: 12px;
}

.lane-summary-card {
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.76);
}

.lane-summary-card--excluded {
  background: rgba(241, 245, 249, 0.9);
  border-style: dashed;
  opacity: 0.9;
}

.lane-summary-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.lane-summary-card__title {
  font-size: 15px;
  font-weight: 700;
}

.lane-summary-card__subtitle {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.lane-summary-grid__stats {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.lane-summary-card__meta,
.lane-summary-card__note {
  margin-top: 8px;
}

.lane-summary-card__note {
  font-weight: 700;
}

.symbol-chart-grid {
  display: grid;
  gap: 16px;
}

.symbol-chart-card {
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.paper-bot-card {
  padding: 20px;
  scroll-margin-top: 24px;
}

.paper-bot-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.paper-bot-title {
  font-size: 24px;
  font-weight: 700;
}

.paper-bot-title-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted rgba(138, 180, 255, 0.5);
}

.paper-bot-title-link:hover,
.paper-bot-title-link:focus-visible {
  color: var(--accent);
  border-bottom-color: currentColor;
}

.paper-bot-link {
  color: inherit;
  text-decoration: none;
}

.paper-bot-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.paper-stat-link {
  color: inherit;
  text-decoration: none;
}

.paper-stat-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.paper-symbol-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted rgba(138, 180, 255, 0.5);
}

.paper-symbol-link:hover,
.paper-symbol-link:focus-visible {
  color: var(--accent);
  border-bottom-color: currentColor;
}

.paper-bot-subtitle {
  margin-top: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--muted);
}

.paper-bot-detail {
  margin-top: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: #35525b;
}

.trade-row-detail {
  background: #f8fafc;
}

.trade-detail-sub {
  margin: 8px 12px;
}

.trade-detail-sub summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  color: #475569;
  padding: 6px 0;
}

.trade-detail-sub summary:hover {
  color: #1e293b;
}

.exit-snapshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  padding: 12px 0 8px 0;
}

.exit-snapshot-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.exit-snapshot-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  font-weight: 600;
}

.exit-snapshot-value {
  font-size: 12px;
  color: #1e293b;
  font-family: 'IBM Plex Mono', monospace;
}

.paper-bot-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.era-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.era-current,
.era-rebased {
  background: #dcfce7;
  color: #166534;
}

.era-mixed {
  background: #fef3c7;
  color: #92400e;
}

.era-excluded {
  background: #fee2e2;
  color: #991b1b;
}

.status-live {
  background: #dcfce7;
  color: #166534;
}

.status-ready {
  background: #e0f2fe;
  color: #075985;
}

.status-paused {
  background: #f1f5f9;
  color: #475569;
}

.status-stale,
.status-error {
  background: #fee2e2;
  color: #991b1b;
}

/* Live polling status indicators */
.bot-status--up {
  background: #22c55e;
  color: #fff;
}

.bot-status--down {
  background: #ef4444;
  color: #fff;
}

.heartbeat-warn {
  color: #f59e0b;
}

.heartbeat-crit {
  color: #ef4444;
  font-weight: 700;
}

.paper-bot-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.paper-bot-metrics--secondary {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.paper-stat--hero strong {
  font-size: 24px;
}

.paper-stat--wide {
  grid-column: span 2;
}

.paper-bot-meta-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.latency-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  align-items: stretch;
  gap: 12px;
  margin-top: 12px;
}

.latency-summary-card {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.latency-summary-card span {
  margin-bottom: 4px;
  line-height: 1.2;
}

.latency-summary-card strong {
  line-height: 1.25;
}

.latency-summary-card--meta strong {
  font-size: 13px;
  line-height: 1.35;
  font-family: 'IBM Plex Mono', monospace;
}

.latency-note {
  margin-top: 12px;
  line-height: 1.45;
}

.latency-primary {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

.latency-primary-group-title {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.latency-table {
  margin-top: 0;
  table-layout: fixed;
}

.latency-table .latency-stage-col {
  width: 46%;
}

.latency-table .latency-num-col {
  width: 9%;
}

.latency-table th:first-child,
.latency-table td:first-child {
  text-align: left;
}

.latency-table th:not(:first-child),
.latency-table td:not(:first-child) {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.latency-row--sparse {
  opacity: 0.82;
}

.latency-row--very-sparse {
  background: rgba(245, 158, 11, 0.10);
}

.latency-stage-label {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.latency-stage-note {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.25;
}

.latency-stage-flag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
}

.latency-stage-flag--warn {
  color: #92400e;
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.latency-stage-flag--low {
  color: #475569;
  background: rgba(148, 163, 184, 0.22);
  border: 1px solid rgba(148, 163, 184, 0.42);
}

.latency-stage-flag--ok {
  color: #166534;
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.38);
}

.latency-count-note {
  margin-left: 5px;
  font-size: 11px;
  color: var(--muted);
}

.latency-debug,
.latency-worst,
.latency-notes {
  margin-top: 14px;
}

.latency-debug-metrics {
  margin-top: 12px;
}

.audit-summary-card {
  margin-top: 14px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.8);
}

.audit-summary-card--ok {
  border-color: rgba(15, 118, 110, 0.28);
  background: rgba(240, 253, 250, 0.92);
}

.audit-summary-card--warn {
  border-color: rgba(180, 83, 9, 0.32);
  background: rgba(255, 247, 237, 0.94);
}

.audit-summary-card--error {
  border-color: rgba(185, 28, 28, 0.32);
  background: rgba(254, 242, 242, 0.94);
}

.audit-summary-card--na {
  border-style: dashed;
}

.audit-summary-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.audit-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.audit-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  border: 1px solid transparent;
}

.audit-pill--ok {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.audit-pill--warn {
  background: #ffedd5;
  border-color: #fdba74;
  color: #9a3412;
}

.audit-pill--error {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.audit-pill--na {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}

.audit-overview-row {
  margin-top: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.audit-overview-row--na {
  border-style: dashed;
  opacity: 0.7;
}

.audit-overview-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.audit-overview-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  min-width: 0;
}

.audit-overview-pills .audit-pill {
  padding: 3px 8px;
  font-size: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.baseline-pill-grid {
  margin-top: 10px;
}

#baselinePills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.baseline-pill-card {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.baseline-pill-card--trend .pnl-trend {
  margin-top: 0;
}

.metrics-table th,
.metrics-table td {
  white-space: nowrap;
}

/* Metrics page: allow table to fill wide screens (1920px+). */
@media (min-width: 1600px) {
  /* .grid and .metrics-layout are the same <main> element — target it directly */
  .metrics-layout {
    max-width: none;
    padding-left: 48px;
    padding-right: 48px;
  }

  .metrics-layout .hero {
    max-width: none;
    padding-left: 48px;
    padding-right: 48px;
  }

  .metrics-layout .table-wrap {
    overflow-x: visible;
  }

  .metrics-layout .table th,
  .metrics-layout .table td {
    padding-left: 10px;
    padding-right: 10px;
    font-size: 13px;
  }

  .metrics-layout .metrics-group-head {
    font-size: 12px;
  }

  .metrics-layout .footer {
    max-width: none;
    padding-left: 48px;
    padding-right: 48px;
  }

  /* Cards on the metrics page expand to fill the full available width */
  .metrics-layout .card {
    min-width: 0;
    width: 100%;
  }

  /* Strategy Health pill grid fills the full card width */
  .metrics-layout .baseline-pill-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

  .metrics-layout #metricsHealthPills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
}

.metrics-table .metrics-group-head {
  border-bottom: 1px solid var(--card-border);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.metric-validity {
  display: inline-block;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  line-height: 1.4;
}

.metric-validity--ok {
  color: var(--ok);
  background: rgba(15, 118, 110, 0.08);
}

.metric-validity--mixed,
.metric-validity--warn {
  color: var(--warn);
  background: rgba(180, 83, 9, 0.08);
}

.metric-validity--bad {
  color: var(--danger);
  background: rgba(220, 38, 38, 0.08);
}

.metric-basis {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metrics-layout .card--compact {
  padding: 14px;
}

.metrics-layout .baseline-pill-grid {
  margin-top: 8px;
}

.metrics-layout #metricsHealthPills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.metrics-layout .baseline-pill-card {
  min-height: 0;
  padding: 6px 8px;
  display: inline-grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "label metric"
    "submeta submeta";
  align-items: baseline;
  column-gap: 6px;
  row-gap: 1px;
  border-radius: 8px;
}

.metrics-layout .baseline-pill-label {
  grid-area: label;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.metrics-layout .baseline-pill-metric {
  grid-area: metric;
  font-size: 12px;
  font-weight: 700;
}

.metrics-layout .baseline-pill-submeta {
  grid-area: submeta;
  font-size: 10px;
  line-height: 1.15;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics-layout .table th,
.metrics-layout .table td {
  padding: 5px 7px;
  font-size: 12px;
}

/* Wider screens: stretch the metrics table columns */
.metrics-layout .table th:not(:first-child),
.metrics-layout .table td:not(:first-child) {
  text-align: center;
}

.metrics-layout .pnl-trend {
  min-width: 68px;
  padding: 1px 5px;
  font-size: 10px;
  border-radius: 7px;
}

.metrics-trend-cell {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.metrics-trend-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 5px;
  background: #e2e8f0;
  color: #334155;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 700;
}

.metrics-row--empty {
  color: var(--muted);
}

.baseline-pill-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-primary);
}

.baseline-pill-metric {
  font-size: 12px;
  font-weight: 600;
}

.baseline-pill-dd {
  color: var(--text-secondary);
}

.baseline-pill-submeta {
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.25;
  word-break: break-word;
}

.audit-overview-divider {
  width: 1px;
  height: 16px;
  background: var(--card-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.audit-overview-na {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
}

.audit-detail,
.audit-subdetail {
  margin-top: 16px;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.audit-detail > summary,
.audit-subdetail > summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 700;
}

.audit-detail > summary::-webkit-details-marker,
.audit-subdetail > summary::-webkit-details-marker {
  display: none;
}

.audit-detail__body {
  padding: 0 16px 16px;
}

.positions-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.position-chip {
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 14px;
  padding: 12px;
}

.position-chip__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
}

.position-chip__meta {
  font-size: 12px;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.45;
}

.closed-trades-wrap {
  margin-top: 14px;
}

.closed-trades-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.trade-chip {
  border: 1px solid var(--card-border);
  background: rgba(246, 250, 252, 0.9);
  border-radius: 14px;
  padding: 12px;
}

.trade-chip__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
}

.trade-chip__meta {
  font-size: 12px;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.45;
}

.tools-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

.tools-layout {
  grid-template-columns: minmax(0, 1fr) 260px;
  align-items: start;
  gap: 12px;
}

.tools-sidebar {
  position: sticky;
  top: 14px;
  width: 100%;
  max-width: 260px;
  justify-self: end;
  padding: 12px;
}

.tools-access-panel {
  margin-bottom: 0;
}

.tools-auth-fields {
  display: grid;
  gap: 6px;
}

.tools-auth-actions {
  margin-top: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tools-target-block {
  margin-top: 10px;
  border-top: 1px dashed #e2e8f0;
  padding-top: 8px;
}

.tools-launch-btn--wide {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
}

.tools-subhead {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tools-group h3 {
  margin: 0 0 4px;
  font-size: 12px;
}

.tools-group {
  border: 1px solid #c7d1da;
  border-radius: 10px;
  padding: 8px;
  background: rgba(224, 232, 240, 0.62);
}

.tools-group[data-group="training-maintenance"] {
  order: 1;
}

.tools-group[data-group="ranking-inspection"] {
  order: 2;
}

.tools-group[data-group="promotion"] {
  order: 3;
}

.tools-group[data-group="reporting"] {
  order: 4;
}

.tools-group[data-group="data-pipeline"] {
  order: 5;
  grid-column: 1 / -1;
}

.tools-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 4px;
}

.tools-card {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 5px 6px;
  background: rgba(233, 239, 245, 0.82);
}

.tools-card .hint {
  margin-top: 2px;
  font-size: 11px;
}

.tools-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.tools-card-title {
  font-weight: 700;
}

.tools-bank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.tools-bank-name {
  font-weight: 700;
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tools-bank-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
  flex: 0 0 auto;
}

.tools-launch-btn {
  padding: 2px 8px;
  font-size: 12px;
  width: auto;
  inline-size: fit-content;
  flex: 0 0 auto;
  white-space: nowrap;
  border-radius: 6px;
  min-height: 0;
  line-height: 1.1;
  box-shadow: none;
}

.tools-launch-btn:hover {
  transform: none;
  box-shadow: none;
}

.tools-controls {
  margin-top: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.tools-options {
  margin-top: 2px;
}

.tools-options > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  user-select: none;
}

.tools-targets {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tools-targets--stack {
  display: grid;
  gap: 8px;
}

.tools-target {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(233, 239, 245, 0.92);
  font-size: 11px;
}

.tools-card-actions,
.tools-shell-actions {
  margin-top: 6px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.tools-history {
  margin-top: 3px;
  display: grid;
  gap: 2px;
}

.tools-history-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.tools-shell-panel {
  display: grid;
  gap: 6px;
}

.tools-shell-inline {
  margin-top: 8px;
  border-top: 1px dashed #c7d1da;
  padding-top: 8px;
}

.tools-shell-inline h3 {
  margin: 0 0 6px;
  font-size: 12px;
}

.tools-shell-inline .tools-shell-actions {
  margin-top: 4px;
  gap: 6px;
}

.tools-runs {
  margin-top: 10px;
  display: grid;
  gap: 12px;
}

.tools-run-card {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(233, 239, 245, 0.8);
}

.tools-run-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.tools-run-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.tools-stop-btn {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 6px;
  width: auto;
  inline-size: fit-content;
  line-height: 1.1;
  white-space: nowrap;
  box-shadow: none;
}

.tools-stop-btn:hover {
  transform: none;
  box-shadow: none;
}

.tools-target-run-grid {
  margin-top: 10px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.tools-target-run {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px;
  background: rgba(226, 234, 241, 0.92);
  width: 100%;
}

.tools-target-run-head {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 8px;
}

.tools-log {
  margin-top: 0;
  width: 100%;
  max-height: 360px;
  min-height: 180px;
  font-size: 12px;
}

.tools-inline-log {
  margin-top: 2px;
  padding: 8px;
  max-height: 170px;
  font-size: 11px;
}

.nav-link-btn--small {
  display: inline-flex;
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 12px;
}

.tb-report-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.tb-report-table {
  min-width: 1480px;
}

.tb-report-table th,
.tb-report-table td {
  white-space: nowrap;
  vertical-align: middle;
}

.tb-report-table th:nth-child(n+6),
.tb-report-table td:nth-child(n+6) {
  text-align: center;
}

.tb-report-table th:nth-child(2),
.tb-report-table th:nth-child(3),
.tb-report-table th:nth-child(n+9),
.tb-report-table td:nth-child(2),
.tb-report-table td:nth-child(3),
.tb-report-table td:nth-child(n+9) {
  font-variant-numeric: tabular-nums;
  font-family: 'IBM Plex Mono', monospace;
}

.tb-report-table th:nth-child(7),
.tb-report-table td:nth-child(7) {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-run-detail-table {
  min-width: 1700px;
}

.tb-run-detail-table th,
.tb-run-detail-table td {
  white-space: nowrap;
  vertical-align: middle;
}

.tb-run-detail-table th:nth-child(n+2),
.tb-run-detail-table td:nth-child(n+2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: 'IBM Plex Mono', monospace;
}

.tb-run-detail-table th:nth-child(1),
.tb-run-detail-table td:nth-child(1) {
  width: 36%;
  min-width: 320px;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.3;
}

.tb-run-detail-table td:nth-child(1) code {
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

.tb-run-detail-table td:nth-child(1) .hint {
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

.tb-run-detail-table td:nth-child(1) .hint code {
  display: block;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

.tb-sortable {
  cursor: pointer;
  user-select: none;
}

.tb-selected-row td {
  background: rgba(13, 91, 99, 0.08);
}

.tb-compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 12px;
}

.tb-compare-card {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.76);
}

.tb-compare-card h3 {
  margin: 0 0 6px;
  font-size: 14px;
  line-height: 1.3;
}

.tb-compare-card h4 {
  margin: 10px 0 8px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tb-compare-section + .tb-compare-section {
  margin-top: 10px;
}

.tb-analysis-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.tb-analysis-panel {
  margin-top: 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.76);
}

.tb-analysis-panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.tb-analysis-section + .tb-analysis-section {
  margin-top: 10px;
}

.tb-analysis-section h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tb-kv {
  display: grid;
  gap: 5px;
}

.tb-kv-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px dashed #e5e7eb;
  padding-bottom: 4px;
  font-size: 12px;
}

.tb-kv-row strong {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.tb-kv-row--emph strong {
  font-weight: 800;
  color: #0f172a;
}

@media (max-width: 900px) {
  .tb-report-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tb-report-table {
    min-width: 1320px;
  }

  .tb-run-detail-table {
    min-width: 1100px;
  }

  .tb-run-detail-table th:nth-child(1),
  .tb-run-detail-table td:nth-child(1) {
    min-width: 280px;
  }

  #tbRunMetaRun,
  #tbRunMetaFamily,
  #tbRunMetaProfile,
  #tbRunMetaWinner,
  #tbRunMetaSummary {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .tb-report-table th,
  .tb-report-table td {
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
  }
}

.tb-delta {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
}

.tb-delta--up {
  color: var(--ok);
}

.tb-delta--down {
  color: var(--down);
}

.llm-summary-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.llm-summary-text {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 15px;
}

.llm-kpi {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.llm-kpi__meta {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.llm-card-reason {
  margin-top: 10px;
  line-height: 1.5;
}

.llm-list {
  display: grid;
  gap: 8px;
}

.llm-list-item {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px;
  background: rgba(233, 239, 245, 0.72);
}

.llm-list-item__title {
  font-weight: 700;
}

.llm-list-item__detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.llm-list-item__meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.llm-list-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.llm-subhead {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.llm-alert {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
}

.llm-alert--error {
  border: 1px solid rgba(185, 28, 28, 0.22);
  background: rgba(254, 226, 226, 0.72);
  color: #991b1b;
}

.llm-inline-log {
  max-height: 320px;
  min-height: 0;
  margin-top: 0;
}

.llm-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}

.llm-badge--up {
  background: rgba(15, 118, 110, 0.12);
  color: #0f766e;
  border-color: rgba(15, 118, 110, 0.2);
}

.llm-badge--down {
  background: rgba(185, 28, 28, 0.12);
  color: #991b1b;
  border-color: rgba(185, 28, 28, 0.2);
}

.llm-badge--warn {
  background: rgba(180, 83, 9, 0.12);
  color: #9a3412;
  border-color: rgba(180, 83, 9, 0.2);
}

.llm-badge--early {
  background: rgba(217, 119, 6, 0.12);
  color: #92400e;
  border-color: rgba(217, 119, 6, 0.2);
}

.llm-badge--flat {
  background: rgba(79, 90, 99, 0.1);
  color: #475569;
  border-color: rgba(79, 90, 99, 0.18);
}

@media (max-width: 900px) {
  .tools-cards {
    grid-template-columns: 1fr;
  }
  .tools-sidebar {
    position: static;
    top: auto;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
  .actions, .worker-actions {
    grid-template-columns: 1fr;
  }
  .log-controls {
    grid-template-columns: 1fr 1fr;
  }
  .auth-row {
    grid-template-columns: 1fr 1fr;
  }
  .paper-summary-grid,
  .adaptive-grace-summary,
  .paper-bot-metrics,
  .paper-bot-metrics--secondary,
  .paper-bot-meta-grid,
  .latency-summary-grid,
  .audit-summary-grid,
  .positions-grid,
  .closed-trades-grid,
  .tools-controls,
  .tools-target-run-grid {
    grid-template-columns: 1fr 1fr;
  }
  .llm-list-columns {
    grid-template-columns: 1fr;
  }
  .paper-stat--wide {
    grid-column: span 1;
  }
  .section-head,
  .paper-bot-head,
  .audit-summary-card__head {
    flex-direction: column;
  }
  .paper-bot-badges {
    justify-content: flex-start;
  }
}

@media (max-width: 1600px) {
  .tools-cards {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

@media (max-width: 1300px) {
  .tools-layout {
    grid-template-columns: minmax(0, 1fr) 240px;
  }
  .tools-groups {
    grid-template-columns: 1fr;
  }
  .tools-sidebar {
    max-width: 240px;
  }
}

@media (max-width: 900px) {
  .tools-layout {
    grid-template-columns: 1fr;
  }
  .tools-cards {
    grid-template-columns: 1fr;
  }
  .tools-sidebar {
    position: static;
    top: auto;
    max-width: none;
    justify-self: stretch;
  }
}

@media (max-width: 1100px) {
  .hero {
    align-items: flex-start;
  }
  .hero__right {
    justify-content: flex-start;
  }
  .table {
    min-width: 760px;
  }
}

@media (max-width: 1200px) {
  .paper-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .paper-bot-metrics--secondary,
  .paper-bot-meta-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .latency-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .positions-grid,
  .closed-trades-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .audit-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }
  .hero h1 {
    font-size: 28px;
  }
  .log-controls {
    grid-template-columns: 1fr;
  }
  .auth-row {
    grid-template-columns: 1fr;
  }
  .paper-layout,
  .grid,
  .footer {
    padding-left: 18px;
    padding-right: 18px;
  }
  .paper-summary-grid,
  .adaptive-grace-summary,
  .paper-bot-metrics,
  .paper-bot-metrics--secondary,
  .paper-bot-meta-grid,
  .latency-summary-grid,
  .audit-summary-grid,
  .positions-grid,
  .closed-trades-grid,
  .tools-controls,
  .tools-target-run-grid {
    grid-template-columns: 1fr;
  }
  .paper-stat--wide {
    grid-column: span 1;
  }
  .range-toggle {
    width: 100%;
  }
  .range-toggle button {
    flex: 1 1 0;
  }
}

.execution-timing-wrap {
  width: 100%;
  overflow-x: auto;
}

/* Execution timing chain: rebalance width and add a stronger center gutter between entry and exit halves. */
.execution-timing-chain-table {
  width: 100%;
  min-width: 1120px;
  table-layout: fixed;
}

.execution-timing-chain-table th:nth-child(1),
.execution-timing-chain-table td:nth-child(1),
.execution-timing-chain-table th:nth-child(5),
.execution-timing-chain-table td:nth-child(5) {
  width: 22%;
}

.execution-timing-chain-table th:nth-child(2),
.execution-timing-chain-table th:nth-child(3),
.execution-timing-chain-table th:nth-child(4),
.execution-timing-chain-table th:nth-child(6),
.execution-timing-chain-table th:nth-child(7),
.execution-timing-chain-table th:nth-child(8),
.execution-timing-chain-table td:nth-child(2),
.execution-timing-chain-table td:nth-child(3),
.execution-timing-chain-table td:nth-child(4),
.execution-timing-chain-table td:nth-child(6),
.execution-timing-chain-table td:nth-child(7),
.execution-timing-chain-table td:nth-child(8) {
  width: 9.333%;
  white-space: nowrap;
}

.execution-timing-chain-table th:nth-child(4),
.execution-timing-chain-table td:nth-child(4) {
  padding-right: 22px;
}

.execution-timing-chain-table th:nth-child(5),
.execution-timing-chain-table td:nth-child(5) {
  padding-left: 58px;
  border-left: 2px solid rgba(148, 163, 184, 0.45);
}

@media (max-width: 900px) {
  .execution-timing-chain-table {
    min-width: 980px;
  }

  .execution-timing-chain-table th:nth-child(4),
  .execution-timing-chain-table td:nth-child(4) {
    padding-right: 12px;
  }

  .execution-timing-chain-table th:nth-child(5),
  .execution-timing-chain-table td:nth-child(5) {
    padding-left: 28px;
  }
}

/* Connector pipeline dashboard */
.pipeline-layout { align-items: start; }
.pipeline-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.pipeline-stat {
  padding: 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  min-width: 0;
}
.pipeline-stat__label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pipeline-stat__value {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.pipeline-detail { display: grid; gap: 8px; }
.pipeline-kv {
  display: grid;
  grid-template-columns: minmax(105px, 0.6fr) minmax(0, 1.4fr);
  gap: 12px;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--card-border);
}
.pipeline-kv > span { color: var(--muted); }
.pipeline-kv strong { min-width: 0; overflow-wrap: anywhere; }
.pipeline-url {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  padding-top: 6px;
}
.pipeline-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.pipeline-badge--running,
.pipeline-badge--ready,
.pipeline-badge--clear,
.pipeline-badge--verified,
.pipeline-badge--yes,
.pipeline-badge--done,
.pipeline-badge--present { border-color: rgba(81, 207, 102, 0.55); }
.pipeline-badge--failed,
.pipeline-badge--blocked,
.pipeline-badge--active,
.pipeline-badge--thread_full { border-color: rgba(255, 107, 107, 0.65); }
.pipeline-badge--pending,
.pipeline-badge--generating { border-color: rgba(255, 212, 59, 0.55); }
.pipeline-badge--cancelled,
.pipeline-badge--consumed { opacity: 0.75; }
.pipeline-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}
.pipeline-filters label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}
.pipeline-filters input,
.pipeline-filters select { min-width: 150px; }
.pipeline-table-wrap { max-height: 68vh; }
.pipeline-table td:nth-child(3) { min-width: 280px; }
.pipeline-task-id { margin-top: 4px; overflow-wrap: anywhere; }
.pipeline-row--runnable td { background: rgba(255, 212, 59, 0.035); }
.pipeline-error { min-height: 90px; max-height: 260px; }

@media (max-width: 760px) {
  .pipeline-kv { grid-template-columns: 1fr; gap: 4px; }
  .pipeline-filters { width: 100%; }
  .pipeline-filters label,
  .pipeline-filters input,
  .pipeline-filters select { width: 100%; }
}
