:root {
  --bg: #0e1117;
  --surface: #161b26;
  --surface-2: #1d2432;
  --border: #262e3d;
  --text: #e6eaf2;
  --muted: #8b95a8;
  --accent: #3ea6ff;
  --up: #26c281;
  --down: #ef5350;
  /* Amber: distinct from the accent blue used for signals and from the
     up/down candle colours, so retracements never read as price direction. */
  --fib: #e0a640;
  --radius: 10px;
}

/* Tell the browser this is a dark UI. Without it the scrollbars, and any other
   control the browser paints itself, come out in the light scheme — the grid's
   horizontal scrollbar showed up as a white bar across the bottom. */
:root { color-scheme: dark; }

* { box-sizing: border-box; }

/* The layout rules below set `display`, which outranks the default UA style for
   [hidden] — without this, hidden elements stay visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { margin: 0; font-weight: 600; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { color: var(--up); font-size: 22px; }
.brand h1 { font-size: 17px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Busy state: a spinner slides in ahead of the label, which stays readable so
   the button never changes width mid-action. */
.btn-busy { opacity: 1; cursor: progress; }

.btn-busy::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .btn-busy::before { animation-duration: 2.4s; }
  .job-fill { transition: none; }
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #07121e; font-weight: 600; }
.btn-ghost { background: transparent; }

/* ── Job progress ────────────────────────────────────────────────────────── */

.job-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.btn-small { padding: 3px 10px; font-size: 12px; }

.job-notice {
  margin: 0;
  padding: 8px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.job-track { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.job-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }
.job-count { font-variant-numeric: tabular-nums; }

/* ── Stats ───────────────────────────────────────────────────────────────── */

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.stat b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Filters ─────────────────────────────────────────────────────────────── */

.head-filters input,
.search-box input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.head-filters input:focus,
.search-box input:focus { outline: none; border-color: var(--accent); }
.head-filters input::placeholder { color: #5a6478; }

/* Two inputs per numeric/date column: "between X and Y". */
.range { display: flex; gap: 5px; }
.range input { min-width: 0; }

/* Global search sitting above the grid. */
.search-box { position: relative; display: inline-flex; align-items: center; }
.search-box input { width: 260px; padding-left: 27px; }

.search-icon {
  position: absolute;
  left: 8px;
  color: var(--muted);
  pointer-events: none;
}

/* Dim the rows while a debounced re-query is in flight. */
#signals-table.filtering tbody { opacity: 0.45; transition: opacity 0.15s ease; }

/* Copy button tucked inside the symbol field's right edge. */
.input-with-action { position: relative; display: inline-flex; }
.input-with-action input { padding-right: 28px; }
.head-filters .input-with-action { width: 100%; }

.icon-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Swap the clipboard glyph for a tick for a moment after a successful copy. */
.icon-btn .icon-check { display: none; }
.icon-btn.copied { color: var(--up); }
.icon-btn.copied .icon-copy { display: none; }
.icon-btn.copied .icon-check { display: block; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  gap: 0;
  min-height: calc(100vh - 220px);
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .detail { border-left: none !important; border-top: 1px solid var(--border); }
}

.results { padding: 16px 24px 40px; min-width: 0; }

.results-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.results-head h2 { font-size: 14px; }
.results-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.count { color: var(--muted); font-size: 12px; font-weight: 400; }

.table-wrap { overflow-x: auto; }

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

th {
  text-align: left;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  white-space: nowrap;
}

/* Only the label row sorts; the filter row below it must stay clickable-into. */
.head-labels th { cursor: pointer; user-select: none; position: relative; }
.head-labels th:hover { color: var(--text); }

/* Column resizing. */
table.resizable { table-layout: fixed; }
table.resizable th, table.resizable td { overflow: hidden; text-overflow: ellipsis; }
table.resizable .sym small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.col-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
  touch-action: none;
}

.col-resize::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 3px;
  width: 1px;
  background: var(--border);
}

.col-resize:hover::after,
.col-resize.dragging::after { background: var(--accent); top: 0; bottom: 0; width: 2px; }
.head-filters th { padding: 0 8px 9px; border-bottom: 1px solid var(--border); vertical-align: top; }

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th[data-dir="asc"]::after { content: " ↑"; color: var(--accent); }
th[data-dir="desc"]::after { content: " ↓"; color: var(--accent); }

td { padding: 8px 10px; border-bottom: 1px solid rgba(38, 46, 61, 0.5); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface); }
tbody tr.selected { background: var(--surface-2); }

.sym { font-weight: 600; }
.sym small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }

/* The ticker is its own control — clicking it opens the enlarged chart. */
.sym-link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}

.sym-link:hover { color: var(--accent); text-decoration: underline; }
.sym-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.hot { color: var(--up); font-weight: 600; }

.empty { padding: 40px 10px; text-align: center; color: var(--muted); }
.empty-action { margin-top: 14px; }

/* ── Detail ──────────────────────────────────────────────────────────────── */

.detail { border-left: 1px solid var(--border); background: var(--surface); padding: 16px 20px 40px; }
.detail-empty { color: var(--muted); padding-top: 60px; text-align: center; }
.detail h2 { font-size: 16px; }
.detail-meta { color: var(--muted); font-size: 12px; margin: 4px 0 16px; }
/* user-select: none — dragging across the chart used to highlight the text
   above it instead of doing anything useful. */
.chart { width: 100%; position: relative; user-select: none; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar-hit { cursor: pointer; }
.chart-hint { margin: 8px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

/* ── Fibonacci retracements ──────────────────────────────────────────────── */

.fib-caption {
  margin: 8px 0 0;
  color: var(--fib);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  opacity: 0.85;
}

.chart-tools { display: flex; justify-content: center; margin-top: 10px; }
.modal-actions { display: flex; align-items: center; gap: 14px; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.switch:hover { color: var(--text); }

/* Measure / clear icons, shown only while retracements are on. */
.chart-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
}

.chart-tool:hover { color: var(--text); border-color: var(--fib); }
.chart-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chart-tool.active {
  color: var(--bg);
  background: var(--fib);
  border-color: var(--fib);
}

/* Crosshair while picking, so it is obvious the next click lands a point. */
.chart.picking { cursor: crosshair; }
.chart.picking .bar-hit { cursor: crosshair; }
.switch input { accent-color: var(--fib); cursor: pointer; margin: 0; }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Values for the clicked candle, tracking it horizontally. */
.chart-readout {
  position: absolute;
  top: 4px;
  z-index: 3;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(22, 27, 38, 0.96);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  font-size: 11px;
  line-height: 1.45;
  pointer-events: none;
  white-space: nowrap;
}

.readout-date { font-weight: 600; margin-bottom: 3px; }

.readout-grid {
  display: grid;
  grid-template-columns: auto auto auto auto;
  gap: 1px 6px;
  font-variant-numeric: tabular-nums;
}

.readout-grid span { color: var(--muted); }
.readout-foot { margin-top: 3px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-readout .up { color: var(--up); }
.chart-readout .down { color: var(--down); }

/* ── Enlarged chart modal ────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 7, 12, 0.72); }

.modal-panel {
  position: relative;
  width: min(1120px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 18px 22px 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

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

.modal-head h2 { font-size: 20px; }
.modal-head .detail-meta { margin: 4px 0 0; }
.modal .chart { cursor: default; }
.modal .chart-readout { font-size: 12px; padding: 9px 12px; }

kbd {
  padding: 1px 5px;
  margin-left: 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}

/* ── Login ───────────────────────────────────────────────────────────────── */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 26px 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.login-card .brand { margin-bottom: 22px; }
.login-card .brand h1 { font-size: 16px; }

.login-form { display: grid; gap: 14px; }

.field { display: grid; gap: 5px; }
.field span { color: var(--muted); font-size: 12px; }

.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

.field input:focus { outline: none; border-color: var(--accent); }

.btn-block { width: 100%; padding: 10px 14px; font-size: 14px; }

.login-error {
  margin: 0;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--down) 45%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--down) 12%, transparent);
  color: var(--down);
  font-size: 13px;
}

.login-hint {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ── Signed-in user ──────────────────────────────────────────────────────── */

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.user-chip strong { color: var(--text); font-weight: 600; }
