:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --purple: #a371f7;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand h1 { margin: 0; font-size: 1.1rem; font-weight: 650; }
.sub { margin: 0; font-size: 0.75rem; color: var(--muted); }
.logo { font-size: 1.4rem; }
.tabs { display: flex; gap: 0.35rem; flex: 1; }
.tab {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.tab:hover { color: var(--text); background: #21262d; }
.tab.active {
  color: var(--text);
  background: #21262d;
  border-color: var(--border);
}
.symbol-select {
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
}
.symbol-select:hover { border-color: #58a6ff66; }
.tf-badge {
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--accent);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid #1f6feb55;
  background: #1f6feb18;
  white-space: nowrap;
}
.status {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.status.ok { color: var(--green); border-color: #238636; }
.status.bad { color: var(--red); border-color: #da3633; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.icon-btn:hover { color: var(--text); background: #21262d; }
.icon-btn.active {
  color: var(--accent);
  border-color: #1f6feb88;
  background: #1f6feb18;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: #0008;
  z-index: 40;
}
.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(380px, 100vw);
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px #000a;
}
.settings-drawer.hidden,
.settings-backdrop.hidden { display: none; }
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.settings-head h2 { margin: 0; font-size: 1rem; }
.settings-hint {
  margin: 0;
  padding: 0.6rem 1rem;
  font-size: 0.72rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.settings-hint code {
  font-size: 0.68rem;
  color: var(--accent);
}
.settings-form {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem 1rem;
}
.settings-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.65rem;
  background: var(--bg);
}
.settings-section h3 {
  margin: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 650;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.settings-section .fields {
  padding: 0.55rem 0.65rem 0.65rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.55rem;
}
.settings-section label.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.68rem;
  color: var(--muted);
}
.settings-section label.field.wide { grid-column: 1 / -1; }
.settings-section label.field.check {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.35rem;
}
.settings-section input[type="number"],
.settings-section select {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
  font-size: 0.8rem;
}
.settings-section input[type="checkbox"] {
  accent-color: var(--accent);
  width: 0.95rem;
  height: 0.95rem;
}
.settings-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}
.settings-status {
  margin: 0;
  padding: 0 1rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1.2em;
}
.settings-status.ok { color: var(--green); }
.settings-status.err { color: var(--red); }
.muted { color: var(--muted); font-size: 0.8rem; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view.hidden { display: none; }

.live-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  /* Fixed track for open panel — avoids flex/max-width collapse bugs on re-open */
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 0;
}
.live-grid.side-collapsed {
  grid-template-columns: minmax(0, 1fr) 44px;
}
/* Chart expand control — desktop hidden (layout already balanced) */
.chart-expand-btn { display: none; }

.chart-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
}
.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chart { flex: 1; min-height: 280px; position: relative; }

/* Gold calendar rail — above time axis, no placeholder candles */
.chart-calendar-rail {
  position: absolute;
  left: 0;
  right: 48px; /* leave room for price scale */
  bottom: 22px; /* sit just above LWC time labels */
  height: 22px;
  pointer-events: none;
  z-index: 8;
  overflow: visible;
}
.chart-calendar-rail.hidden {
  display: none;
}
.chart-cal-mark {
  pointer-events: auto;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  padding: 0;
  margin: 0;
  border: 1px solid #3fb95099;
  border-radius: 50%;
  background: #0d1117ee;
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px #0008;
  line-height: 1;
}
.chart-cal-mark:hover {
  border-color: #3fb950;
  background: #161b22;
  z-index: 2;
}
.chart-cal-mark .cal-icon {
  font-size: 11px;
  line-height: 1;
}
.chart-cal-mark .cal-flag {
  font-size: 12px;
}
.chart-cal-mark .cal-count {
  position: absolute;
  top: -5px;
  right: -6px;
  min-width: 12px;
  height: 12px;
  padding: 0 3px;
  border-radius: 6px;
  background: #3fb950;
  color: #0d1117;
  font-size: 9px;
  font-weight: 700;
  line-height: 12px;
  text-align: center;
}

/* Hover tooltip for alert event dots under candles */
.chart-tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  max-width: 240px;
  padding: 0.45rem 0.6rem;
  background: #161b22ee;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px #0008;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--text);
}
.chart-tooltip.hidden { display: none; }
.chart-tooltip .tip-row + .tip-row {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}
.chart-tooltip .tip-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.chart-tooltip .tip-detail { color: var(--muted); font-size: 0.72rem; }
.chart-tooltip .mono { font-variant-numeric: tabular-nums; }

.price-badge {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tf-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-left: 0.25rem;
}
.tf-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  padding: 0.28rem 0.55rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.tf-btn:last-child { border-right: none; }
.tf-btn:hover { color: var(--text); background: #21262d; }
.tf-btn.active {
  color: var(--text);
  background: #1f6feb33;
  color: var(--accent);
}
.badge {
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #21262d;
  border: 1px solid var(--border);
  color: var(--text);
}
.badge.muted { color: var(--muted); }
.badge.open { color: var(--green); border-color: #238636; }
.badge.closed { color: var(--amber); border-color: #9e6a03; }

/* —— Right column: alerts OR full Grok (+ icon rail) —— */
.side-rail {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
}
.side-main {
  flex: 1 1 auto;
  /* width:0 + flex:1 = take remaining space without overflowing grid */
  width: 0;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}
/* Collapse: remove main entirely (icons-only). Avoid max-width:0 absolute bugs. */
.side-rail.mode-collapsed .side-main {
  display: none;
}
.side-view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.18s ease, visibility 0.18s;
}
.side-rail.mode-alerts .side-view-alerts,
.side-rail.mode-grok .side-view-grok {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 1;
}
.side-rail.mode-collapsed .side-view {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.side-icons {
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 0.35rem;
  border-left: 1px solid var(--border);
  background: #0f141b;
  box-sizing: border-box;
}
.side-rail.mode-collapsed .side-icons {
  border-left: none;
}
.side-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.side-icon:hover {
  color: var(--text);
  border-color: #484f58;
}
.side-icon.active {
  color: var(--accent);
  border-color: var(--accent);
  background: #58a6ff18;
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.side-view-grok {
  background: #12171e;
  padding: 0.65rem 0.75rem 0.75rem;
}
.grok-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  flex-shrink: 0;
  margin-bottom: 0.55rem;
}
.grok-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.grok-title h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}
.grok-actions {
  display: flex;
  gap: 0.25rem;
}
.btn.sm {
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
}
.grok-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  gap: 0.5rem;
}
.grok-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.2rem 0.1rem;
}
.grok-msg {
  font-size: 0.8rem;
  line-height: 1.45;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.grok-msg.user {
  background: #1a2332;
  border-color: #2d3a4d;
  color: var(--text);
  align-self: flex-end;
  max-width: 95%;
}
.grok-msg.assistant {
  background: var(--bg);
  color: var(--muted);
  align-self: flex-start;
  max-width: 100%;
}
.grok-msg.assistant strong,
.grok-msg.user strong {
  color: var(--text);
}
.grok-msg.system,
.grok-msg.error {
  font-size: 0.72rem;
  color: var(--muted);
  border-style: dashed;
  align-self: stretch;
}
.grok-msg.error {
  color: var(--red);
  border-color: #f8514944;
}
.grok-msg.pending {
  opacity: 0.75;
  font-style: italic;
}
.grok-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  flex-shrink: 0;
}
.chip {
  font-size: 0.68rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.chip:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.grok-form {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
  align-items: flex-end;
}
.grok-form textarea {
  flex: 1;
  resize: vertical;
  min-height: 3.2rem;
  max-height: 8rem;
  padding: 0.5rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.35;
}
.grok-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.grok-form .btn {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}
.grok-form .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.muted { color: var(--muted); }
.panel-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
  position: relative;
  flex-shrink: 0;
  z-index: 5;
}
.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}
.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.info-tip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1;
  cursor: help;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.info-tip-btn:hover,
.info-tip-btn:focus-visible,
.info-tip:hover .info-tip-btn,
.info-tip:focus-within .info-tip-btn {
  color: var(--accent);
  border-color: var(--accent);
  background: #58a6ff14;
  outline: none;
}
.info-tip-bubble {
  /* Panel sits on the right — open below icon, keep inside panel */
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  z-index: 40;
  width: min(15.5rem, 70vw);
  max-width: 18rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1c2128;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -2px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}
.info-tip-bubble strong {
  color: var(--text);
  font-weight: 600;
}
.info-tip:hover .info-tip-bubble,
.info-tip:focus-within .info-tip-bubble {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.hint { margin: 0 0 0.75rem; font-size: 0.75rem; color: var(--muted); }
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.6rem;
}
.card h3 {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}
.card.hidden-alert {
  opacity: 0.55;
  border-style: dashed;
}
.card.hidden-alert .card-body {
  display: none;
}
.card.hidden-alert h3 {
  margin-bottom: 0;
}
.card-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  flex: 1;
  min-width: 0;
}
.card-toggle input {
  accent-color: var(--accent);
  width: 0.95rem;
  height: 0.95rem;
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
}
.card-toggle span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tf { font-size: 0.7rem; color: var(--muted); font-weight: 500; flex-shrink: 0; }
.kv { font-size: 0.78rem; color: var(--muted); line-height: 1.45; }
.kv strong { color: var(--text); font-weight: 600; }
.kv .ok { color: var(--green); }
.kv .bad { color: var(--red); }
.kv .warn { color: var(--amber); }

.meter {
  height: 6px;
  background: #21262d;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.45rem;
}
.meter.meter-main {
  height: 7px;
  margin-bottom: 0.5rem;
}
.meter.meter-sm {
  height: 4px;
  margin-bottom: 0;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 0.25s ease;
}
.meter-fill.wick {
  background: linear-gradient(90deg, #7dd3fc88, #7dd3fc);
}
.meter-fill.sweep {
  background: linear-gradient(90deg, #f778ba88, #f778ba);
}
.meter-fill.spike {
  background: linear-gradient(90deg, var(--amber), var(--red));
}
.meter-fill.cooloff {
  background: linear-gradient(90deg, var(--purple), var(--accent));
}
.meter-fill.news {
  background: linear-gradient(90deg, #238636, var(--green));
}
.meter-fill.price {
  background: linear-gradient(90deg, #3fb950aa, #39d353);
}
.meter-fill.hot {
  background: var(--red);
}

/* Sub-metric progress rows on alert cards */
.prog-rows {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.prog-row {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.prog-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.68rem;
  color: var(--muted);
  gap: 0.4rem;
}
.prog-meta .prog-label {
  font-weight: 600;
  color: #9da7b3;
}
.prog-meta .prog-val {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 62%;
}
.prog-row.done .prog-label { color: var(--green); }
.prog-row.hot .prog-val { color: var(--amber); }

.btn {
  background: #238636;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.btn.hidden, .hidden { display: none !important; }

.replay-banner {
  padding: 0.4rem 0.75rem;
  background: #1f1328;
  border-top: 1px solid var(--purple);
  color: #d2a8ff;
  font-size: 0.8rem;
}

.history-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.history-bar label {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.history-bar select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
}
.table-wrap { overflow: auto; flex: 1; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--bg); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #161b22; }
td.mono { font-variant-numeric: tabular-nums; }
.source-pill {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.72rem;
  background: #21262d;
  border: 1px solid var(--border);
}
.source-pill.candle { border-color: var(--accent); color: var(--accent); }
.source-pill.candle_wick { border-color: #7dd3fc; color: #7dd3fc; }
.source-pill.liquidity_sweep { border-color: #f778ba; color: #f778ba; }
.source-pill.spike { border-color: var(--amber); color: var(--amber); }
.source-pill.cooloff { border-color: var(--purple); color: var(--purple); }
.source-pill.econ_calendar { border-color: var(--green); color: var(--green); }

/* —— Performance tab —— */
.perf-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
  overflow: auto;
  flex: 1;
}
.perf-hero {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: stretch;
  margin-bottom: 1.25rem;
}
.perf-hero-text { flex: 1 1 320px; min-width: 0; }
.perf-hero-text h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.perf-lead {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
  max-width: 52rem;
}
.perf-lead.muted { color: var(--muted); font-size: 0.85rem; }
.perf-hero-card {
  flex: 0 0 220px;
  background: linear-gradient(160deg, #161b22 0%, #0d1117 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
}
.perf-hero-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 650;
}
.perf-hero-value {
  font-size: 2.1rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.perf-hero-value.good { color: var(--green); }
.perf-hero-value.mid { color: var(--amber); }
.perf-hero-value.low { color: var(--red); }
.perf-hero-sub { font-size: 0.8rem; color: var(--muted); }

.perf-how {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.perf-how h3 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
}
.perf-how ol {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text);
}
.perf-how li { margin-bottom: 0.35rem; }
.perf-caveat {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.perf-toolbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.perf-window-label {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.perf-window-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0d1117;
}
.perf-win-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.perf-win-btn:last-child { border-right: none; }
.perf-win-btn:hover { color: var(--text); background: #21262d; }
.perf-win-btn.active {
  color: var(--text);
  background: #1f6feb33;
  box-shadow: inset 0 0 0 1px #1f6feb66;
}
.perf-source-switch {
  flex-wrap: wrap;
  max-width: 100%;
}
.perf-src-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.perf-src-btn:last-child { border-right: none; }
.perf-src-btn:hover { color: var(--text); background: #21262d; }
.perf-src-btn.active {
  color: var(--text);
  background: #3fb95022;
  box-shadow: inset 0 0 0 1px #3fb95055;
}
.perf-sample-bar {
  margin-top: -0.25rem;
  margin-bottom: 1rem;
}
.perf-mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.perf-mode-btn:last-child { border-right: none; }
.perf-mode-btn:hover { color: var(--text); background: #21262d; }
.perf-mode-btn.active {
  color: var(--text);
  background: #a371f722;
  box-shadow: inset 0 0 0 1px #a371f755;
}
.perf-sample-last,
.perf-sample-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.perf-field {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
}
.perf-input {
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.45rem;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.perf-input[type="number"] { width: 4.5rem; }
.perf-input[type="date"] { min-width: 9.5rem; }
.perf-select {
  min-width: 7rem;
  cursor: pointer;
}
.perf-opp-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.perf-opp-btn:last-child { border-right: none; }
.perf-opp-btn:hover { color: var(--text); background: #21262d; }
.perf-opp-btn.active {
  color: var(--text);
  background: #d2992228;
  box-shadow: inset 0 0 0 1px #d2992266;
}
.perf-hits-section {
  margin-bottom: 1.5rem;
}
.perf-hits-section h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}
.perf-hits-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  max-height: 420px;
}
.perf-hits-wrap table tbody tr {
  cursor: pointer;
}
.perf-hits-wrap table tbody tr:hover {
  background: #1c2128;
}
.perf-hit-clean {
  border-left: 3px solid var(--green);
}
.perf-hit-dirty {
  border-left: 3px solid var(--amber);
}
.perf-tag {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.perf-tag.clean {
  background: #3fb95022;
  color: var(--green);
  border: 1px solid #3fb95066;
}
.perf-tag.dirty {
  background: #d2992222;
  color: var(--amber);
  border: 1px solid #d2992266;
}
.perf-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.perf-sort:hover {
  color: var(--text);
}
.perf-sort.active {
  color: var(--accent);
}
.perf-sort-ind {
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}
.perf-sort.active .perf-sort-ind {
  color: var(--accent);
}
.perf-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  margin-bottom: 1.5rem;
}
.perf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.perf-table th,
.perf-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.perf-table th {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #0d1117;
  position: sticky;
  top: 0;
  z-index: 1;
  line-height: 1.25;
}
.perf-th-sub {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: #6e7681;
  line-height: 1.3;
}
.perf-table tbody tr { cursor: default; }
.perf-table tbody tr:hover { background: #1c2128; }
.perf-table tr.perf-row-best {
  background: #1f6feb14;
}
.perf-table tr.perf-row-best:hover { background: #1f6feb22; }
.perf-cell-sub {
  font-size: 0.72rem;
  margin-top: 0.2rem;
  color: var(--muted);
}

.perf-bar {
  position: relative;
  height: 1.35rem;
  background: #21262d;
  border-radius: 6px;
  overflow: hidden;
  min-width: 7rem;
  max-width: 14rem;
}
.perf-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  opacity: 0.85;
  transition: width 0.35s ease;
}
.perf-bar-fill.good { background: var(--green); }
.perf-bar-fill.mid { background: var(--amber); }
.perf-bar-fill.low { background: var(--red); }
.perf-bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-shadow: 0 1px 2px #000a;
}

.perf-sources h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}
.perf-sources-intro {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
}
.perf-source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.85rem;
}
.perf-source-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.perf-source-card h4 {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
}
.perf-source-focus {
  font-size: 0.88rem;
  margin-bottom: 0.55rem;
}
.perf-source-focus .good { color: var(--green); }
.perf-source-focus .mid { color: var(--amber); }
.perf-source-focus .low { color: var(--red); }
.perf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.perf-chip {
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: #21262d;
  border: 1px solid var(--border);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.perf-chip strong { color: var(--text); }

/* Collapsible Performance glossary (details) */
.perf-how-summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
  user-select: none;
}
.perf-how-summary::-webkit-details-marker { display: none; }
.perf-how-summary::before {
  content: "▸ ";
  color: var(--muted);
  font-size: 0.85em;
}
.perf-how[open] > .perf-how-summary::before { content: "▾ "; }
.perf-how[open] > .perf-how-summary { margin-bottom: 0.55rem; }
.perf-how h3 { display: none; } /* legacy if any */

/* ==========================================================================
   Responsive / mobile
   ========================================================================== */

/* Tablet + phone: stack Live (chart over alerts), scrollable page */
@media (max-width: 900px) {
  body {
    /* Allow the whole app to scroll instead of trapping content */
    min-height: 100dvh;
    height: auto;
    overflow-x: hidden;
  }
  html { height: auto; }

  .top {
    gap: 0.4rem 0.55rem;
    padding: 0.45rem 0.65rem;
    padding-top: max(0.45rem, env(safe-area-inset-top));
    padding-left: max(0.65rem, env(safe-area-inset-left));
    padding-right: max(0.65rem, env(safe-area-inset-right));
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .brand { gap: 0.4rem; min-width: 0; }
  .brand h1 { font-size: 1rem; }
  .sub {
    font-size: 0.65rem;
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Tabs full-width under brand row */
  .tabs {
    order: 10;
    flex: 1 1 100%;
    gap: 0.25rem;
  }
  .tab {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.35rem;
    font-size: 0.8rem;
  }
  .tf-badge { display: none; } /* chart toolbar already shows TF */
  .symbol-select {
    font-size: 0.72rem;
    padding: 0.28rem 0.35rem;
    max-width: 6.5rem;
  }
  .status {
    font-size: 0.65rem;
    max-width: 5.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  main {
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
  }
  .view {
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
  }
  #view-live {
    /* Page scrolls; chart stays a fixed-ish band at the top of content */
    overflow: visible;
  }

  .live-grid {
    display: flex;
    flex-direction: column;
    flex: none;
    min-height: 0;
    height: auto;
  }
  .live-grid.side-collapsed {
    grid-template-columns: unset;
  }

  .chart-wrap {
    flex: 0 0 auto;
    height: min(34vh, 260px);
    min-height: 180px;
    max-height: 260px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  body.chart-tall-mobile .chart-wrap {
    height: min(62vh, 480px);
    max-height: 480px;
    min-height: 280px;
  }
  /* Collapsed rail → slightly taller chart is ok */
  .live-grid.side-collapsed .chart-wrap {
    height: min(48vh, 360px);
    max-height: 360px;
  }
  body.chart-tall-mobile .live-grid.side-collapsed .chart-wrap {
    height: min(70vh, 520px);
    max-height: 520px;
  }

  .chart-toolbar {
    gap: 0.35rem;
    padding: 0.35rem 0.5rem;
  }
  .price-badge { font-size: 1rem; }
  .tf-switch { margin-left: 0; }
  .tf-btn {
    padding: 0.32rem 0.42rem;
    font-size: 0.7rem;
  }
  .chart-expand-btn {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    font-size: 0.72rem;
    padding: 0.28rem 0.5rem;
  }
  .chart-expand-btn.active {
    color: var(--accent);
    border-color: #1f6feb88;
    background: #1f6feb18;
  }
  .chart {
    flex: 1;
    min-height: 0;
  }

  /* Side rail becomes a bottom panel under the chart */
  .side-rail {
    flex: 1 1 auto;
    flex-direction: column;
    height: auto;
    min-height: 0;
    border-left: none;
    overflow: visible;
  }
  .side-icons {
    order: -1;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    max-width: none;
    flex-direction: row;
    justify-content: stretch;
    gap: 0.4rem;
    padding: 0.45rem 0.55rem;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }
  .side-rail.mode-collapsed .side-icons {
    border-bottom: none;
  }
  .side-icon {
    flex: 1;
    height: 40px;
    max-width: none;
    font-size: 0.95rem;
  }
  .side-icon::after {
    content: attr(data-label);
    margin-left: 0.35rem;
    font-size: 0.78rem;
    font-weight: 650;
  }
  .side-main {
    width: 100%;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  /* Relative stacking instead of absolute overlay (needs real height for scroll) */
  .side-view {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    height: auto;
    max-width: 100%;
    min-height: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    display: none;
    z-index: auto;
    transition: none;
    padding: 0.55rem 0.65rem 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
  .side-rail.mode-alerts .side-view-alerts,
  .side-rail.mode-grok .side-view-grok {
    display: flex;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  .side-rail.mode-collapsed .side-view {
    display: none;
  }
  .side-rail.mode-collapsed .side-main {
    display: none;
  }

  .panel-scroll {
    /* Let the page scroll; don't nest a tiny scroll trap */
    overflow: visible;
    flex: none;
    max-height: none;
  }
  .side-view-grok .grok-body {
    min-height: 280px;
  }
  .grok-messages {
    min-height: 140px;
    max-height: 40vh;
  }
  .grok-chips {
    gap: 0.3rem;
  }
  .grok-chips .chip {
    font-size: 0.72rem;
    padding: 0.28rem 0.5rem;
  }
  .grok-form textarea {
    font-size: 16px; /* avoid iOS zoom on focus */
  }

  /* Info tips: no hover on touch — open below on focus/tap */
  .info-tip-bubble {
    left: 0;
    right: auto;
    transform: none;
    max-width: min(18rem, calc(100vw - 2rem));
    width: max-content;
  }
  .info-tip:hover .info-tip-bubble,
  .info-tip:focus-within .info-tip-bubble {
    transform: none;
  }

  .card {
    padding: 0.55rem 0.6rem;
    margin-bottom: 0.5rem;
  }
  .card h3 { font-size: 0.82rem; }

  /* Settings full-bleed drawer */
  .settings-drawer {
    width: 100vw;
  }
  .settings-section .fields {
    grid-template-columns: 1fr;
  }

  /* History */
  .history-bar {
    flex-wrap: wrap;
    padding: 0.55rem 0.65rem;
    gap: 0.5rem;
  }
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }
  table { font-size: 0.78rem; }
  th, td { padding: 0.45rem 0.5rem; }

  /* Performance */
  .perf-page {
    padding: 0.85rem 0.75rem 2rem;
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
  .perf-hero {
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
  }
  .perf-hero-text h2 { font-size: 1.15rem; }
  .perf-lead { font-size: 0.88rem; }
  .perf-hero-card {
    flex: 1 1 auto;
    width: 100%;
    padding: 0.85rem 1rem;
  }
  .perf-hero-value { font-size: 1.75rem; }
  .perf-how {
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.75rem;
  }
  .perf-toolbar {
    gap: 0.4rem 0.5rem;
    margin-bottom: 0.55rem;
  }
  .perf-window-label {
    flex: 0 0 100%;
    margin-top: 0.15rem;
  }
  .perf-window-label:first-child { margin-top: 0; }
  .perf-window-switch {
    flex-wrap: wrap;
    max-width: 100%;
  }
  .perf-win-btn,
  .perf-src-btn,
  .perf-mode-btn,
  .perf-opp-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.78rem;
  }
  .perf-src-btn {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
  .perf-table {
    font-size: 0.78rem;
    min-width: 640px; /* horizontal scroll rather than crushing columns */
  }
  .perf-table th,
  .perf-table td {
    padding: 0.5rem 0.55rem;
  }
  .perf-bar {
    min-width: 5rem;
    max-width: 10rem;
    height: 1.2rem;
  }
  .perf-hits-wrap {
    max-height: none;
  }
  .perf-hits-wrap table {
    min-width: 520px;
  }
  .perf-input[type="date"] { min-width: 0; width: auto; }
  .perf-input {
    font-size: 16px; /* iOS focus zoom */
  }
}

/* Narrow phones */
@media (max-width: 480px) {
  .brand .logo { font-size: 1.15rem; }
  .sub { display: none; }
  .chart-wrap {
    height: min(32vh, 220px);
    min-height: 160px;
    max-height: 220px;
  }
  body.chart-tall-mobile .chart-wrap {
    height: min(58vh, 420px);
    max-height: 420px;
  }
  .badge { font-size: 0.65rem; padding: 0.15rem 0.4rem; }
  .side-icon::after { display: none; } /* icons only if very tight */
  .side-icon { font-size: 1.05rem; }
  .prog-meta { font-size: 0.64rem; }
  .kv { font-size: 0.72rem; }
}
