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

:root {
  --bg:       #0d1117;
  --bg2:      #161b22;
  --bg3:      #1c2128;
  --border:   #30363d;
  --text:     #c9d1d9;
  --dim:      #6e7681;
  --accent:   #58a6ff;
  --green:    #3fb950;
  --red:      #f85149;
  --orange:   #d29922;
  font-size: 13px;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────── */
header {
  height: 44px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 16px;
  flex-shrink: 0;
}

.logo { font-weight: 700; font-size: 14px; color: var(--accent); letter-spacing: .4px; }

.symbol-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}

.tf-group { display: flex; gap: 4px; }

.tf-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 4px;
  padding: 3px 9px;
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.tf-btn:hover  { border-color: var(--accent); color: var(--accent); }
.tf-btn.active { background: #1c2e4a; border-color: var(--accent); color: var(--accent); font-weight: 600; }

.conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--dim);
  margin-left: auto;
  transition: background .3s;
}
.conn-dot.connected    { background: var(--green); }
.conn-dot.disconnected { background: var(--red); }

/* ── Main area ──────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.chart-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#main-chart { width: 100%; height: 100%; }

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: 180px;
  flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 12px 16px;
  gap: 20px;
}

.match-block { text-align: center; }

.match-number {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
}

.match-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--dim);
  text-transform: uppercase;
  margin-top: 4px;
}

.session-info {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}
.info-row .label { color: var(--dim); }
.info-row .value { font-weight: 600; color: var(--text); }
.info-row .value.positive { color: var(--green); }
.info-row .value.negative { color: var(--red); }

.sidebar-divider {
  width: 100%;
  height: 1px;
  background: var(--border);
}

.ghost-label {
  font-size: 10px;
  color: var(--dim);
  text-align: center;
  line-height: 1.4;
}

.btn-clear-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
  display: none;
}
.btn-clear-ghost.visible { display: block; }
.btn-clear-ghost:hover { border-color: var(--red); color: var(--red); }

/* ── Mini-chart strip ───────────────────────────────── */
.strip-wrap {
  height: 148px;
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg2);
}

.strip {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  height: 100%;
  align-items: center;
}

.mini-card {
  flex-shrink: 0;
  width: 170px;
  height: 120px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color .15s, background .15s;
}
.mini-card:hover           { border-color: var(--dim); }
.mini-card.selected        { border-color: var(--accent); background: #131c2e; }

.mini-header {
  padding: 5px 7px 3px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.mini-date  { font-size: 10px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mini-gap {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  white-space: nowrap;
}
.mini-gap.pos { background: #1a2e1a; color: var(--green); border: 1px solid var(--green); }
.mini-gap.neg { background: #2e1a1a; color: var(--red);   border: 1px solid var(--red); }
.mini-gap.neu { background: var(--bg); color: var(--dim); border: 1px solid var(--border); }

.mini-match {
  font-size: 9px;
  color: var(--dim);
  padding: 0 7px 2px;
  flex-shrink: 0;
}

.mini-canvas-wrap {
  flex: 1;
  min-height: 0;
  padding: 0 6px 6px;
}

.mini-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── No matches placeholder ─────────────────────────── */
.strip-placeholder {
  color: var(--dim);
  font-size: 12px;
  padding: 0 16px;
  white-space: nowrap;
}

/* ── Bar direction labels ───────────────────────────── */
.bar-dir-section { width: 100%; }

.bar-dir-header {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--dim);
  text-transform: uppercase;
  margin-bottom: 7px;
  text-align: center;
}

.bar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-bottom: 8px;
}

.bar-chip {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1.5;
}
.bar-chip.bull  { background: #1a2e1a; color: var(--green); border: 1px solid var(--green); }
.bar-chip.bear  { background: #2e1a1a; color: var(--red);   border: 1px solid var(--red); }
.bar-chip.more  { background: var(--bg); color: var(--dim); border: 1px solid var(--border); }

.composite-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.comp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
}
.comp-label { color: var(--dim); font-weight: 600; }

/* ── Fit button ─────────────────────────────────────── */
.btn-fit {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 10;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s;
}
.btn-fit:hover { border-color: var(--accent); color: var(--accent); }

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Historical Bias badge ──────────────────────────── */
.bias-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
  pointer-events: none;
}
.bias-badge.bull { background: rgba(63,185,80,.18); border: 1px solid var(--green); color: var(--green); }
.bias-badge.bear { background: rgba(248,81,73,.18);  border: 1px solid var(--red);   color: var(--red); }
.bias-badge.neut { background: rgba(110,118,129,.18); border: 1px solid var(--dim); color: var(--dim); }

/* ── OHLCV tooltip ──────────────────────────────────── */
.ohlcv-tooltip {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 11px;
  pointer-events: none;
  min-width: 160px;
}
.ohlcv-row { display: flex; justify-content: space-between; gap: 12px; line-height: 1.7; }
.ohlcv-label { color: var(--dim); }
.ohlcv-val   { font-weight: 600; font-variant-numeric: tabular-nums; }
.ohlcv-sep   { height: 1px; background: var(--border); margin: 4px 0; }
.ohlcv-ghost { color: rgba(88,166,255,.85); }
.ohlcv-section-title { font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim); margin-bottom: 2px; }

/* ── Summary button ─────────────────────────────────── */
.btn-summary {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.btn-summary:hover { border-color: var(--accent); color: var(--accent); }

/* ── Summary modal ──────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 520px;
  max-width: 96vw;
  max-height: 82vh;
  overflow-y: auto;
  padding: 0;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 13px; font-weight: 700; color: var(--text); }
.modal-close {
  background: transparent; border: none; color: var(--dim);
  font-size: 14px; cursor: pointer; padding: 0 2px;
}
.modal-close:hover { color: var(--text); }

.summary-stats {
  padding: 14px 18px 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
}
.stat-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px 12px;
}
.stat-card .s-label { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.stat-card .s-val   { font-size: 20px; font-weight: 800; color: var(--accent); margin-top: 2px;
  font-variant-numeric: tabular-nums; }
.stat-card .s-sub   { font-size: 10px; color: var(--dim); margin-top: 1px; }

.summary-ai {
  margin: 8px 18px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}
.summary-ai.loading { color: var(--dim); font-style: italic; }

/* ── Research mode ──────────────────────────────────────── */
.research-section { width: 100%; display: flex; flex-direction: column; gap: 6px; }

.research-date-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  color-scheme: dark;
}

.research-buttons { display: flex; gap: 6px; }

.btn-research {
  flex: 1;
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 4px;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.btn-research:hover { opacity: 0.85; }
.btn-research:disabled { opacity: 0.5; cursor: default; }

.btn-live {
  flex: 1;
  background: var(--bg3);
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 4px;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.btn-live:hover { background: rgba(63,185,80,0.12); }

.research-banner {
  background: rgba(88,166,255,0.1);
  border: 1px solid rgba(88,166,255,0.3);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 10px;
  color: var(--accent);
  text-align: center;
  font-weight: 600;
}
