/* ── Darwin Dashboard — Bloomberg Terminal Theme ──────────────────────── */

:root {
  --bg-primary: #0a0e17;
  --bg-panel: #131722;
  --bg-panel-header: #1a1f2e;
  --border: #1e2738;
  --border-focus: #2a3548;
  --text-primary: #d1d4dc;
  --text-secondary: #787b86;
  --text-muted: #4a4e59;
  --amber: #ff9500;
  --amber-dim: #b36a00;
  --green: #26a69a;
  --green-bright: #4cceac;
  --red: #ef5350;
  --red-dim: #b33a38;
  --blue: #2962ff;
  --blue-dim: #1a3d99;
  --white: #e8eaed;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ─────────────────────────────────────────────────────────── */

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border);
  height: 36px;
  flex-shrink: 0;
}

#top-bar .strategy-name {
  color: var(--amber);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
}

#top-bar .state-badge {
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.state-QUOTING { background: var(--green); color: #000; }
.state-PARTIAL { background: var(--amber); color: #000; }
.state-PAUSED { background: var(--text-muted); color: var(--text-primary); }
.state-HALTED { background: var(--red); color: #fff; }
.state-DISCONNECTED { background: var(--red-dim); color: #fff; }

#top-bar .price-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
#top-bar .price-value { font-size: 14px; color: var(--white); font-weight: 600; }
#top-bar .price-change { font-size: 11px; }
.positive { color: var(--green); }
.negative { color: var(--red); }

#top-bar .conn-status { display: flex; align-items: center; gap: 6px; }
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.conn-dot.ok { background: var(--green); }
.conn-dot.warn { background: var(--amber); }
.conn-dot.err { background: var(--red); }

#top-bar .utc-clock {
  color: var(--text-secondary);
  font-size: 11px;
  min-width: 80px;
  text-align: right;
}

/* ── Alert Banner ────────────────────────────────────────────────────── */

#alert-banner {
  display: none;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
#alert-banner.visible { display: flex; }

.alert-item {
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.alert-item.critical {
  background: var(--red-dim);
  color: #fff;
  border-left: 3px solid var(--red);
}
.alert-item.warning {
  background: #3d2e00;
  color: var(--amber);
  border-left: 3px solid var(--amber);
}

/* ── Main Grid ───────────────────────────────────────────────────────── */

#dashboard {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 36px);
}

#main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto auto;
  gap: 1px;
  background: var(--border);
  flex: 1;
  overflow: auto;
}

/* ── Panel base ──────────────────────────────────────────────────────── */

.panel {
  background: var(--bg-panel);
  padding: 8px 10px;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  color: var(--amber);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.panel-subtitle {
  color: var(--text-muted);
  font-size: 10px;
}

/* Row 1: Tier status — spans full width */
#tier-status { grid-column: 1 / -1; }

.tier-zones {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 12px;
}

.tier-zone { padding: 4px 0; }

.zone-label {
  color: var(--text-muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.tier-big {
  font-size: 22px;
  font-weight: 700;
}

.rebate-rate {
  font-size: 16px;
  font-weight: 700;
}

.tier-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
}
.tier-T1 { background: var(--text-muted); color: var(--text-primary); }
.tier-T2 { background: var(--green); color: #000; }
.tier-T3 { background: var(--blue); color: #fff; }
.tier-T4 { background: var(--amber); color: #000; }
.tier-Below { background: var(--red-dim); color: #fff; }
.tier-Unknown { background: var(--text-muted); color: var(--text-primary); }

/* Progress gauge */
.gauge-container {
  margin: 6px 0 4px 0;
}
.gauge-bar-bg {
  height: 16px;
  background: var(--bg-primary);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}
.gauge-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.gauge-markers {
  position: relative;
  height: 18px;
  margin-top: 2px;
}
.gauge-marker {
  position: absolute;
  top: 0;
  width: 1px;
  height: 6px;
  background: var(--amber);
}
.gauge-marker-label {
  position: absolute;
  top: 7px;
  font-size: 9px;
  color: var(--text-secondary);
  transform: translateX(-50%);
  white-space: nowrap;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.status-QUALIFIED { background: var(--green); color: #000; }
.status-ON\ TRACK { background: var(--blue); color: #fff; }
.status-AT\ RISK { background: var(--red); color: #fff; }

/* Metric rows */
.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
}
.metric-label { color: var(--text-secondary); font-size: 10px; }
.metric-value { color: var(--text-primary); font-size: 11px; font-weight: 600; }
.metric-value.large { font-size: 14px; }
.metric-value.positive { color: var(--green); }
.metric-value.negative { color: var(--red); }

/* Row 4: History spans full width */
#weekly-history { grid-column: 1 / -1; }

/* ── Risk bars ───────────────────────────────────────────────────────── */

.risk-bar-container {
  margin: 4px 0;
}
.risk-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  margin-bottom: 2px;
}
.risk-bar-bg {
  height: 10px;
  background: var(--bg-primary);
  border-radius: 2px;
  overflow: hidden;
}
.risk-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.risk-ok { background: var(--green); }
.risk-warn { background: var(--amber); }
.risk-crit { background: var(--red); }

/* ── PNL waterfall ───────────────────────────────────────────────────── */

.waterfall {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 4px 0;
}
.wf-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 4px;
  font-size: 10px;
}
.wf-row.subtotal {
  border-top: 1px solid var(--border);
  font-weight: 700;
}
.wf-label { color: var(--text-secondary); }
.wf-arrow { color: var(--text-muted); margin: 0 4px; }

/* ── Activity feed table ─────────────────────────────────────────────── */

.feed-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
.feed-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  padding: 2px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.feed-table td {
  padding: 2px 4px;
  border-bottom: 1px solid #0f1420;
}
.feed-table tr:hover { background: rgba(255, 149, 0, 0.05); }
.side-BUY { color: var(--green); }
.side-SELL { color: var(--amber); }

/* ── Weekly history table ────────────────────────────────────────────── */

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
.history-table th {
  text-align: right;
  color: var(--text-muted);
  font-weight: 600;
  padding: 3px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.history-table th:first-child { text-align: left; }
.history-table td {
  text-align: right;
  padding: 3px 6px;
  border-bottom: 1px solid #0f1420;
}
.history-table td:first-child { text-align: left; }
.history-table tr.tier-row-T2,
.history-table tr.tier-row-T3,
.history-table tr.tier-row-T4 {
  background: rgba(38, 166, 154, 0.08);
}
.history-table tr.tier-row-Below {
  background: rgba(239, 83, 80, 0.08);
}
.history-table tr.current-week {
  border-left: 2px solid var(--amber);
}
.history-table tfoot td {
  font-weight: 700;
  border-top: 1px solid var(--border);
  color: var(--white);
}

/* ── Plotly overrides ────────────────────────────────────────────────── */

.chart-container {
  width: 100%;
  height: 120px;
}

/* ── Bottom bar ──────────────────────────────────────────────────────── */

#bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--bg-panel-header);
  border-top: 1px solid var(--border);
  font-size: 9px;
  color: var(--text-muted);
  height: 24px;
  flex-shrink: 0;
}

/* ── Utility ─────────────────────────────────────────────────────────── */

.text-amber { color: var(--amber); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.fw-bold { font-weight: 700; }
.mt-4 { margin-top: 4px; }
.mb-4 { margin-bottom: 4px; }
.gap-row { display: flex; gap: 16px; flex-wrap: wrap; }

/* ── Scrollbar ───────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-focus); border-radius: 2px; }
