:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #232f42;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --border: #2d3a4f;
  --accent: #3b82f6;
  --buy: #22c55e;
  --buy-bg: rgba(34, 197, 94, 0.15);
  --exit: #ef4444;
  --exit-bg: rgba(239, 68, 68, 0.15);
  --wait: #f59e0b;
  --wait-bg: rgba(245, 158, 11, 0.12);
  --warn: #fbbf24;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  --radius: 6px;
  --control-h: 32px;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.top-bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.subtitle {
  font-size: 11px;
  color: var(--muted);
  margin-left: 8px;
}
.top-bar-left {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  min-width: 0;
}
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.clock {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 650;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip-ok { color: var(--buy); border-color: rgba(34, 197, 94, 0.4); background: var(--buy-bg); }
.chip-bad { color: var(--exit); border-color: rgba(239, 68, 68, 0.4); background: var(--exit-bg); }
.chip-warn { color: var(--wait); border-color: rgba(245, 158, 11, 0.35); background: var(--wait-bg); }
.chip-muted { color: var(--muted); }

.connect-panel {
  margin: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.connect-panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}
.connect-inner { margin-top: 10px; }
.connect-inner label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.connect-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.connect-row input {
  flex: 1;
  min-width: 180px;
  height: var(--control-h);
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.connect-message {
  margin: 8px 0 0;
  font-size: 12px;
  min-height: 1.2em;
}
.connect-message.err { color: var(--exit); }
.connect-message.ok { color: var(--buy); }

.btn {
  height: var(--control-h);
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: #2563eb;
  color: #fff;
}
.btn-icon {
  width: 32px;
  padding: 0;
  background: transparent;
}
.btn-sm {
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
}
.btn-danger {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--exit);
}

.banner {
  margin: 0 14px 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
}
.banner-hidden { display: none; }
.banner-error {
  background: var(--exit-bg);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}
.banner-warn {
  background: var(--wait-bg);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

.tab-nav {
  display: flex;
  gap: 4px;
  padding: 0 14px 8px;
  border-bottom: 1px solid var(--border);
}
.tab {
  height: 30px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-color: var(--panel);
  margin-bottom: -1px;
}

.panel {
  padding: 10px 14px 48px;
  max-width: 100%;
  overflow-x: hidden;
}
.panel[hidden] { display: none !important; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.watchlist-add {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}
.watchlist-add input {
  width: 100%;
  height: var(--control-h);
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.search-hidden { display: none; }
.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.search-item:last-child { border-bottom: none; }
.meta-muted { font-size: 11px; color: var(--muted); }

.loading-msg, .empty-msg {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.hidden { display: none !important; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.screener-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.screener-table th,
.screener-table td,
.data-table th,
.data-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.screener-table th,
.data-table th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  font-weight: 650;
  color: var(--muted);
  white-space: nowrap;
}
.screener-table tr.row-disabled { opacity: 0.55; }
.screener-table tr:last-child td,
.data-table tr:last-child td { border-bottom: none; }

.sym-cell { font-weight: 650; white-space: nowrap; }
.num { font-family: var(--mono); }
.notes-cell {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 10px;
}

.signal-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.signal-buy { background: var(--buy-bg); color: var(--buy); }
.signal-exit { background: var(--exit-bg); color: var(--exit); }
.signal-wait { background: var(--wait-bg); color: var(--wait); }
.signal-none { color: var(--muted); font-weight: 500; }
.confirm-sub { display: block; font-size: 9px; color: var(--muted); font-weight: 500; }

.quote-ok { color: var(--buy); }
.quote-stale { color: var(--wait); }
.quote-bad { color: var(--exit); }
.quote-muted { color: var(--muted); }

.gap-chip {
  display: inline-block;
  margin: 1px 2px 0 0;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 9px;
  background: var(--wait-bg);
  color: var(--warn);
}

.paper-banner {
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.1);
  font-size: 12px;
}
.paper-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-card .lbl {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}
.stat-card .val {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.val-pos { color: var(--buy); }
.val-neg { color: var(--exit); }
.section-title {
  font-size: 12px;
  font-weight: 700;
  margin: 16px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.health-grid {
  display: grid;
  gap: 12px;
}
.health-block {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.health-block h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
}
.health-block dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12px;
}
.health-block dt { color: var(--muted); }
.health-block dd { margin: 0; font-family: var(--mono); font-size: 11px; }

.mobile-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}
.mobile-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.mobile-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 11px;
}
.mobile-card-grid .lbl { color: var(--muted); font-size: 10px; }

.footer-meta {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  font-size: 10px;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.mobile-only { display: none; }
.desktop-only { display: block; }

@media (max-width: 768px) {
  .mobile-only { display: block; }
  .desktop-only { display: none; }
  .subtitle { display: none; }
  .top-bar h1 { font-size: 14px; }
  .chip { max-width: 100px; overflow: hidden; text-overflow: ellipsis; }
}
