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

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --accent:   #58a6ff;
  --green:    #3fb950;
  --red:      #f85149;
  --header-h: 52px;
  --stats-h:  48px;
  --table-w:  420px;
}

.hidden { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.stock-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.stock-select-wrap::-webkit-scrollbar { display: none; }

.stock-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.stock-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.stock-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(88,166,255,0.08);
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  margin-left: auto;
  transition: background 0.3s;
}
.connection-dot.connected    { background: var(--green); }
.connection-dot.reconnecting { background: #e3b341; }

/* ── Notification bell ── */
.notif-widget {
  position: relative;
  flex-shrink: 0;
  margin-left: auto;
}

.notif-bell-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.notif-bell-btn:hover { color: var(--text); background: var(--border); }
.notif-bell-btn.has-notifications { color: var(--text); }

.notif-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  pointer-events: none;
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 200;
  overflow: hidden;
}

.notif-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.notif-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
}

.notif-clear-all {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}
.notif-clear-all:hover { text-decoration: underline; }

.notif-list {
  max-height: 320px;
  overflow-y: auto;
}

.notif-empty {
  padding: 20px 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.notif-item:last-child { border-bottom: none; }

.notif-text {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}

.notif-time {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.notif-dismiss-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.notif-dismiss-btn:hover { color: var(--red); }

/* ── API key / user widget ── */
.api-key-widget {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.api-key-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.api-key-input {
  width: 160px;
  height: 26px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  outline: none;
  transition: border-color 0.15s;
}
.api-key-input:focus { border-color: var(--accent); }
.api-key-input::placeholder { color: var(--muted); }

.api-key-connect-btn {
  height: 26px;
  padding: 0 10px;
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.api-key-connect-btn:hover  { opacity: 0.85; }
.api-key-connect-btn:active { opacity: 0.7; }
.api-key-connect-btn:disabled { opacity: 0.5; cursor: default; }

.api-key-error {
  font-size: 11px;
  color: var(--red);
  max-width: 220px;
  text-align: right;
}

.api-key-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-key-username {
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  white-space: nowrap;
}

.api-key-disconnect-btn {
  width: 20px;
  height: 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
.api-key-disconnect-btn:hover { color: var(--red); border-color: var(--red); }

/* ── Stats bar ── */
.stats-bar {
  height: var(--stats-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  flex-shrink: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stat-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-value.up   { color: var(--green); }
.stat-value.down { color: var(--red);   }

.stock-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

/* ── Main area (chart + table side by side) ── */
.main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
  padding: 0 14px 12px;
}

/* ── Chart ── */
.chart-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chart {
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

/* ── RSI panel ── */
.rsi-panel {
  height: 120px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: relative;
}

#rsiChart {
  width: 100%;
  height: 100%;
}

.rsi-value-label {
  position: absolute;
  top: 4px;
  left: 8px;
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: var(--muted);
  z-index: 5;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}

/* ── MACD panel ── */
.macd-panel {
  height: 120px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: relative;
}

#macdChart {
  width: 100%;
  height: 100%;
}

.macd-legend {
  position: absolute;
  top: 4px;
  left: 8px;
  z-index: 5;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}

.macd-legend span { white-space: nowrap; }

/* ── Loading overlay ── */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  z-index: 5;
}

/* ── Chart toolbar (drawing tools) ── */
.chart-toolbar {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 10;
  display: flex;
  gap: 4px;
}

.chart-dd {
  position: relative;
}

.chart-dd-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.chart-dd-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface);
}
.chart-dd-btn.tool-active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(88,166,255,0.12);
}
.chart-dd-btn .dd-chevron {
  opacity: 0.5;
  transition: transform 0.15s;
}
.chart-dd-btn.open .dd-chevron { transform: rotate(180deg); }

.chart-dd-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 20;
}

.chart-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.chart-dd-item:hover  { background: rgba(255,255,255,0.06); }
.chart-dd-item.active { color: var(--accent); }

/* ── Trendline dropdown section labels ── */
.trendline-section-label {
  padding: 6px 10px 2px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  pointer-events: none;
}

/* ── Fullscreen button ── */
.fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 72px;
  z-index: 10;
  width: 28px;
  height: 28px;
  padding: 5px;
  background: rgba(22, 27, 34, 0.80);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.fullscreen-btn svg { width: 100%; height: 100%; }
.fullscreen-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface);
}

/* ensure the chart fills the wrapper when the browser takes it fullscreen */
.chart-wrap:fullscreen,
.chart-wrap:-webkit-full-screen {
  background: var(--bg);
}
.chart-wrap:fullscreen #chart,
.chart-wrap:-webkit-full-screen #chart {
  width: 100vw;
  height: 100vh;
}

/* ── Free Draw Line dots ── */
.fl-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d4d4d4;
  border: 2px solid #0d1117;
  pointer-events: none;
  z-index: 25;
  transition: transform 0.1s;
}
.fl-dot.hover {
  width: 14px;
  height: 14px;
  background: transparent;
  border: 2px solid #d4d4d4;
  transform: translate(-2px, -2px);
}
.fl-dot.fl-dot-preview { opacity: 0.6; }

/* ── Free Draw Line text label ── */
.fl-label {
  position: absolute;
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  pointer-events: none;
  z-index: 25;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  transform: translateX(-50%);
}

/* ── Free Draw Line context menu ── */
.fl-ctx-menu {
  position: absolute;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  min-width: 220px;
  overflow: hidden;
}
.fl-ctx-section {
  padding: 8px 10px 6px;
}
.fl-ctx-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}
.fl-ctx-sublabel {
  font-size: 11px;
  color: var(--muted);
}
.fl-ctx-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}
.fl-color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.fl-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.12s, transform 0.1s;
}
.fl-color-swatch:hover    { transform: scale(1.15); }
.fl-color-swatch.active   { border-color: var(--text); }
.fl-custom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.fl-color-custom {
  width: 36px;
  height: 22px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  padding: 1px;
}
.fl-btn-row {
  display: flex;
  gap: 4px;
}
.fl-option-btn {
  flex: 1;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}
.fl-option-btn:hover  { color: var(--text); border-color: var(--accent); }
.fl-option-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(88,166,255,0.1); }
.fl-text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  padding: 5px 8px;
  outline: none;
}
.fl-text-input:focus { border-color: var(--accent); }

/* ── Free Lines list panel ── */
.freelines-section {
  border-top: 1px solid var(--border);
  padding: 8px 0 4px;
}
.fl-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  transition: background 0.1s;
}
.fl-list-item:hover { background: rgba(255,255,255,0.04); }
.fl-list-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fl-list-info {
  flex: 1;
  min-width: 0;
}
.fl-list-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  display: block;
}
.fl-list-range {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: block;
}
.fl-list-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s;
  flex-shrink: 0;
}
.fl-list-del:hover { color: var(--red); }

/* ── S/R context menu ── */
.sr-ctx-menu {
  position: absolute;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.sr-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
}
.sr-ctx-item:hover { background: rgba(255,255,255,0.06); }
.sr-ctx-item[data-action="delete"] { color: var(--red); }
.sr-ctx-item[data-action="delete"]:hover { background: rgba(248,81,73,0.1); }

/* ── In-app alarm banner ── */
.alarm-banner {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 40;
  background: rgba(248,81,73,0.92);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.alarm-banner--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Alarm bell overlays ── */
.sr-alarm {
  position: absolute;
  left: 8px;
  color: #e3b341;
  pointer-events: none;
  z-index: 8;
  line-height: 1;
}

/* ── Resize handle ── */
.resize-handle {
  width: 4px;
  flex-shrink: 0;
  background: var(--border);
  cursor: col-resize;
  transition: background 0.15s;
  position: relative;
}
/* wider invisible hit-target so it's easy to grab */
.resize-handle::after {
  content: '';
  position: absolute;
  inset: 0 -4px;
  cursor: col-resize;
}
.resize-handle:hover,
.resize-handle.dragging { background: var(--accent); }

/* ── Table panel ── */
.table-panel {
  width: var(--table-w);
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.table-panel-header {
  height: 36px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
}

.table-panel-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.refresh-info {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.table-scroll {
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.table-scroll::-webkit-scrollbar { width: 4px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Stock table ── */
.stock-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.stock-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.stock-table th.num,
.stock-table td.num { text-align: right; }

.stock-table tbody td {
  padding: 5px 8px;
  border-bottom: 1px solid #1c2128;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stock-table .col-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.stock-table .col-ticker {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.4px;
}

.stock-table .col-price  { color: var(--text); }
.stock-table .col-shares { color: var(--muted); font-size: 11px; }

.stock-table td.up   { color: var(--green); }
.stock-table td.down { color: var(--red); }

.stock-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.stock-table tbody tr:hover  { background: rgba(255,255,255,0.03); }
.stock-table tbody tr.active { background: rgba(88,166,255,0.08); }

/* ── Timeframe dropdown ── */
.tf-group-label {
  padding: 6px 10px 2px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  pointer-events: none;
}

.tf-item {
  font-variant-numeric: tabular-nums;
}

/* ── Not-enough-data overlay ── */
.tf-not-enough {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
}

.tf-not-enough-msg {
  background: rgba(22,27,34,0.88);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 340px;
  line-height: 1.5;
}

/* ── BB toolbar group ── */
.bb-group {
  display: flex;
  gap: 1px;
}

.bb-gear-btn {
  padding: 0 7px;
}

.bb-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  gap: 12px;
}

.bb-settings-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.bb-settings-input {
  width: 58px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  text-align: right;
}
.bb-settings-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── BB hover label overlay ── */
.bb-hover-label {
  position: absolute;
  top: 44px;
  left: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
}

.bb-hover-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: var(--text);
  background: rgba(13,17,23,0.72);
  padding: 2px 6px 2px 5px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── EMA dropdown items ── */
.ema-menu-item {
  cursor: pointer;
  gap: 8px;
}

.ema-check {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.ema-dot {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.ema-legend-dot {
  width: 18px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

/* ── Spinner ── */
.tbl-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 36px auto;
}

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

.tbl-error {
  padding: 24px 16px;
  color: var(--red);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

/* ── Panel resize handle (between stocks table and portfolio) ── */
.panel-resize-handle {
  height: 6px;
  flex-shrink: 0;
  cursor: ns-resize;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.panel-resize-handle:hover,
.panel-resize-handle.dragging {
  background: rgba(88,166,255,0.06);
  border-color: rgba(88,166,255,0.4);
}
/* Three-dot horizontal grip indicator */
.panel-resize-handle::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
  box-shadow: 9px 0 0 var(--border), -9px 0 0 var(--border);
  transition: background 0.12s, box-shadow 0.12s;
}
.panel-resize-handle:hover::after,
.panel-resize-handle.dragging::after {
  background: var(--muted);
  box-shadow: 9px 0 0 var(--muted), -9px 0 0 var(--muted);
}

/* ── Watchlist section ── */
.watchlist-section {
  height: 150px;
  min-height: 80px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.watchlist-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.watchlist-scroll::-webkit-scrollbar { width: 4px; }
.watchlist-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.watchlist-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

/* ── Portfolio section ── */
.portfolio-section {
  height: clamp(220px, 38vh, 420px);
  min-height: 80px;
  flex-shrink: 0;
  /* border-top handled by the panel-resize-handle above */
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.portfolio-header {
  height: 36px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
}

.portfolio-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.portfolio-refresh-btn {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.portfolio-refresh-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.07);
}


.portfolio-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.portfolio-scroll::-webkit-scrollbar { width: 4px; }
.portfolio-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.portfolio-msg {
  padding: 16px 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}
.portfolio-msg.error { color: var(--red); }

/* Portfolio table compact overrides */
.portfolio-table thead th {
  padding: 5px 5px;
  font-size: 9px;
}
.portfolio-table tbody td {
  padding: 4px 5px;
  font-size: 11px;
}
.portfolio-table .col-ticker {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.3px;
}

/* Profit / loss row tints */
.portfolio-table tbody tr.pf-profit { background: rgba(29,158,117,0.06); }
.portfolio-table tbody tr.pf-loss   { background: rgba(226,75,74,0.06);  }
.portfolio-table tbody tr.pf-profit:hover { background: rgba(29,158,117,0.12); }
.portfolio-table tbody tr.pf-loss:hover   { background: rgba(226,75,74,0.12);  }
.portfolio-table td.pf-profit { color: #1D9E75; }
.portfolio-table td.pf-loss   { color: #E24B4A; }

/* Summary row */
.portfolio-table tr.pf-summary td {
  background: rgba(255,255,255,0.04) !important;
  border-top: 1px solid var(--border) !important;
  font-weight: 700;
  font-size: 11px;
  cursor: default;
}
.portfolio-table tbody tr.active { background: rgba(88,166,255,0.08); }

/* ── Mobile tabs ── */
.mobile-tabs { display: none; }

@media (max-width: 767px) {
  .mobile-tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .mobile-tab-btn {
    flex: 1;
    padding: 10px 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
  }
  .mobile-tab-btn:hover { color: var(--text); }
  .mobile-tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  /* Hide the drag handle — not useful on mobile */
  .resize-handle { display: none; }

  /* Stack panels vertically */
  .main-area { flex-direction: column; }

  /* Stocks tab: hide chart, expand table to full width */
  .main-area[data-tab="stocks"] .chart-wrap  { display: none !important; }
  .main-area[data-tab="stocks"] .table-panel {
    width: 100%;
    border-left: none;
    flex: 1;
    min-height: 0;
  }

  /* Chart tab: hide table panel, chart fills remaining space */
  .main-area[data-tab="chart"] .table-panel { display: none !important; }

  /* Fullscreen button: pinned to top-right corner of the chart area,
     clear of the scrollable toolbar row */
  .fullscreen-btn {
    top: 8px;
    right: 8px;
    z-index: 15;
  }

  /* Chart toolbar: scrolls horizontally on mobile */
  .chart-toolbar {
    left: 0;
    right: 0;
    overflow-x: auto;
    overflow-y: visible;
    flex-wrap: nowrap;
    white-space: nowrap;
    scrollbar-width: none;
    padding: 8px 8px 4px;
    top: 0;
  }
  .chart-toolbar::-webkit-scrollbar { display: none; }

  /* Stats bar: scrolls horizontally so all stat columns are reachable */
  .stats-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    padding: 0 12px;
    gap: 16px;
  }
  .stats-bar::-webkit-scrollbar { display: none; }

  .stock-name {
    flex-shrink: 0;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Toolbar dropdowns: use position:fixed to escape the overflow-x:auto
     clipping context on .chart-toolbar. z-index alone cannot escape
     an overflow container — fixed positioning is the only CSS-only solution.
     Top is calculated as: header + mobile-tabs (~36px) + stats-bar + toolbar (~40px). */
  .chart-dd-menu {
    position: fixed;
    top: calc(var(--header-h) + var(--stats-h) + 76px);
    left: 4px;
    right: 4px;
    min-width: 0;
    z-index: 300;
  }
}
