/* D1 Mission Control — Tesla-style operator dashboard */
:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1c1c1c;
  --border: #2a2a2a;
  --text: #f5f5f5;
  --muted: #888;
  --healthy: #22c55e;
  --warning: #f59e0b;
  --critical: #ef4444;
  --accent: #3b82f6;
  --pnl-up: #22c55e;
  --pnl-down: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-bar h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.02em; }
.top-bar h1 span { color: var(--muted); font-weight: 400; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-meta { font-size: 12px; color: var(--muted); margin-right: 12px; }

.btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: #444; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--critical); border-color: rgba(239,68,68,0.4); }

.mission-band {
  padding: 16px 20px;
  max-width: 1600px;
  margin: 0 auto;
}

.mission-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr) 100px;
  gap: 10px;
  margin-bottom: 12px;
}

.mc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  min-height: 110px;
}
.mc-card-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.mc-card-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 6px;
}
.mc-card-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.mc-card-sub div { margin-top: 2px; }

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.healthy { background: var(--healthy); box-shadow: 0 0 8px var(--healthy); }
.status-dot.degraded { background: var(--warning); }
.status-dot.critical { background: var(--critical); box-shadow: 0 0 8px var(--critical); }

.ars-ring {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  min-height: 110px;
}
.ars-score {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}
.ars-label { font-size: 9px; text-transform: uppercase; color: var(--muted); margin-top: 4px; text-align: center; }
.ars-ring.autonomous .ars-score { color: var(--healthy); }
.ars-ring.degraded .ars-score { color: var(--warning); }
.ars-ring.intervention .ars-score { color: var(--critical); }

.action-banner {
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.action-banner.normal {
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: #86efac;
}
.action-banner.warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}
.action-banner.critical {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.secondary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.panel h3 {
  margin: 0 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.panel-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.panel-row .k { color: var(--muted); }
.rejection-list { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.rejection-list li { margin: 4px 0; }
.opp-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}
.opp-excellent { background: rgba(34,197,94,0.2); color: var(--healthy); }
.opp-good { background: rgba(59,130,246,0.2); color: var(--accent); }
.opp-average { background: rgba(245,158,11,0.2); color: var(--warning); }
.opp-poor { background: rgba(239,68,68,0.15); color: var(--critical); }

.positions-compact { font-size: 13px; }
.positions-compact table { width: 100%; border-collapse: collapse; }
.positions-compact th, .positions-compact td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.positions-compact th { color: var(--muted); font-weight: 500; }

.footer-links {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--muted);
}
.footer-links a { color: var(--accent); margin: 0 8px; }

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

.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-wide { max-width: 640px; }
.modal-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.modal-tab {
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.modal-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 14px;
}
.setting-row label { flex: 1; }
.setting-row input[type="number"], .setting-row select {
  width: 140px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-toggle {
  position: absolute; inset: 0; background: #333; border-radius: 24px; cursor: pointer; transition: 0.2s;
}
.slider-toggle:before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider-toggle { background: var(--accent); }
.switch input:checked + .slider-toggle:before { transform: translateX(20px); }

.kill-box {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid rgba(239,68,68,0.35);
  border-radius: 8px;
  background: rgba(239,68,68,0.06);
}
.kill-box p { margin: 0 0 12px; font-size: 12px; color: var(--muted); }

.accordion { margin-bottom: 8px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.accordion-head {
  padding: 12px 14px;
  background: var(--surface2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}
.accordion-body { display: none; padding: 14px; }
.accordion.open .accordion-body { display: block; }

.ars-breakdown {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ars-breakdown.open { display: flex; }
.ars-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  max-width: 400px;
  width: 100%;
}
.ars-factor {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ars-factor .pass { color: var(--healthy); }
.ars-factor .fail { color: var(--critical); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 18px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 400;
  display: none;
}
.toast.show { display: block; }

.mobile-summary {
  display: none;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 99;
}
.mobile-summary .line1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
}
.mobile-summary .line2 { font-size: 12px; color: var(--muted); margin-top: 4px; }

@media (max-width: 1023px) {
  .mission-grid { grid-template-columns: repeat(3, 1fr); }
  .secondary-grid { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .mobile-summary { display: block; }
  .mission-grid { grid-template-columns: 1fr; gap: 8px; }
  .mc-card { min-height: auto; }
  .action-banner.fixed-mobile {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 0;
    z-index: 150;
  }
  body { padding-bottom: 70px; }
  .top-meta { display: none; }
}
