:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1f242d;
  --bg-elev-3: #2a313c;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --fg-faint: #586069;
  --accent: #0e7c39;
  --accent-2: #16a34a;
  --accent-fg: #ffffff;
  --green: #26a69a;
  --green-faint: rgba(38, 166, 154, 0.15);
  --red: #ef5350;
  --red-faint: rgba(239, 83, 80, 0.15);
  --amber: #d29922;
  --border: #30363d;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; }
.hidden { display: none !important; }

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: inherit;
  background: var(--bg-elev-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus { outline: none; border-color: var(--accent-2); }
.muted { color: var(--fg-dim); } .small { font-size: 12px; }

/* Topbar */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--fg); font-weight: 700; font-size: 15px; }
.brand-mark { background: var(--accent); padding: 2px 8px; border-radius: 6px; font-size: 14px; }
.topbar-mid { display: flex; justify-content: center; }
.search-wrap { position: relative; width: 100%; max-width: 480px; }
#symbol-search { width: 100%; padding: 8px 12px; }
.search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 8px; max-height: 360px; overflow: auto;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.search-row { padding: 10px 12px; display: flex; gap: 8px; align-items: baseline; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-row:last-child { border-bottom: none; }
.search-row:hover { background: var(--bg-elev-3); }
.search-row .sym { font-weight: 700; font-family: ui-monospace, monospace; }
.search-row .nm { color: var(--fg-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-row .ex { color: var(--fg-faint); font-size: 11px; }
.topbar-right { display: flex; gap: 8px; align-items: center; justify-self: end; }

.btn {
  padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--fg);
  font-weight: 500;
  transition: border-color 0.12s, background 0.12s;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.user-menu { position: relative; }
.popover {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px; min-width: 160px;
  display: flex; flex-direction: column; z-index: 1000;
}
.popover a { padding: 8px 12px; color: var(--fg); text-decoration: none; border-radius: 4px; }
.popover a:hover { background: var(--bg-elev-3); }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
  overflow-x: auto; white-space: nowrap;
}
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.tb-grow { flex: 1; }
.tb {
  background: transparent; border: 1px solid transparent;
  padding: 5px 9px; border-radius: 5px;
  color: var(--fg-dim); font-size: 12.5px;
  font-family: inherit;
}
.tb:hover { background: var(--bg-elev-2); color: var(--fg); }
.tb.active { color: var(--fg); background: var(--bg-elev-3); border-color: var(--border); }
.tb:disabled { color: var(--fg-faint); cursor: not-allowed; opacity: 0.55; }
.tb:disabled:hover { background: transparent; color: var(--fg-faint); }
.tb.gated { position: relative; }
.tb.gated::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--amber);
}
.tb.gated.unlocked::after { display: none; }

#symbol-pill .symbol-name { font-weight: 700; font-family: ui-monospace, monospace; padding: 0 8px; }
#symbol-pill .symbol-price { font-weight: 600; padding: 0 8px; }
#symbol-pill .symbol-change.up { color: var(--green); }
#symbol-pill .symbol-change.down { color: var(--red); }

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
  overflow: hidden;
}
.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-header {
  padding: 10px 12px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.watchlist-picker {
  padding: 4px 8px; font-size: 11px;
  background: var(--bg-elev-2); border-radius: 4px;
  text-transform: none; letter-spacing: 0;
  max-width: 130px;
}
.watchlist-rows { flex: 1; overflow: auto; }
.watchlist-row {
  padding: 10px 12px;
  display: grid; grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.watchlist-row:hover { background: var(--bg-elev-2); }
.watchlist-row.active { background: var(--bg-elev-3); border-left: 2px solid var(--accent-2); }
.watchlist-row .sym { font-weight: 700; font-family: ui-monospace, monospace; }
.watchlist-row .price { font-family: ui-monospace, monospace; text-align: right; color: var(--fg); }
.watchlist-row .pct { font-family: ui-monospace, monospace; font-size: 11px; padding: 1px 6px; border-radius: 3px; min-width: 56px; text-align: right; }
.watchlist-row .pct.up { color: var(--green); background: var(--green-faint); }
.watchlist-row .pct.down { color: var(--red); background: var(--red-faint); }
.watchlist-row .remove { background: transparent; border: none; color: var(--fg-faint); padding: 0 4px; opacity: 0; transition: opacity 0.12s; }
.watchlist-row:hover .remove { opacity: 1; }
.watchlist-row .remove:hover { color: var(--red); }
.watchlist-add {
  display: flex; gap: 4px; padding: 8px 10px; border-top: 1px solid var(--border);
}
.watchlist-add input { flex: 1; }
.sidebar-footer { padding: 8px 10px; border-top: 1px solid var(--border); }

/* Chart pane */
.chart-pane {
  display: flex; flex-direction: column;
  position: relative;
  background: var(--bg);
  min-height: 0;
}
.chart-host { flex: 3; min-height: 0; position: relative; }
.chart-host.sub-pane {
  flex: 1; min-height: 120px;
  border-top: 1px solid var(--border);
}
.chart-legend {
  position: absolute; top: 8px; left: 12px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--fg-dim);
  pointer-events: none;
  z-index: 10;
  display: flex; flex-direction: column; gap: 2px;
}
.chart-legend .li-row { display: flex; gap: 8px; }
.chart-legend .li-label { min-width: 56px; }
.chart-legend .li-up { color: var(--green); }
.chart-legend .li-down { color: var(--red); }

/* Modal + toast */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000;
}
.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%; max-width: 420px;
  position: relative;
}
.modal-card h2 { margin: 0 0 8px; }
.modal-card p { margin: 0 0 12px; color: var(--fg-dim); }
.modal-close {
  position: absolute; top: 8px; right: 8px;
  background: transparent; border: none;
  color: var(--fg-dim); font-size: 22px;
  width: 32px; height: 32px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-elev-2); color: var(--fg); }

.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev-3);
  color: var(--fg);
  padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--border);
  z-index: 6000;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 200px 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}
