/* ═══════════════════════════════════════════════════════════════
   QDCode — Dark Quant Platform Theme
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg-0: #0d1117;
  --bg-1: #161b22;
  --bg-2: #1f2937;
  --bg-3: #30363d;
  --border: #30363d;
  --border-light: #3d4450;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-dim: #1f6feb22;
  --green: #3fb950;
  --green-dim: #1a7f3722;
  --red: #f85149;
  --red-dim: #da363522;
  --yellow: #d29922;
  --purple: #a371f7;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --topnav-h: 52px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

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

html { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg-0);
  color: var(--text-primary);
  height: 100%;
  overflow-x: hidden;
  line-height: 1.5;
}

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Typography ─────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
h4 { font-size: .875rem; font-weight: 600; }

.text-primary  { color: var(--text-primary); }
.text-muted    { color: var(--text-muted); }
.text-green    { color: var(--green); }
.text-red      { color: var(--red); }
.text-accent   { color: var(--accent); }
.sm            { font-size: 12px; }

/* ── Top Navigation ─────────────────────────────────────────────── */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topnav-h);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 1rem;
  gap: 0;
}
.topnav-left  { display: flex; align-items: center; gap: 1.5rem; flex: 1; }
.topnav-right { display: flex; align-items: center; gap: .75rem; }

.logo {
  display: flex; align-items: center; gap: .5rem;
  text-decoration: none; color: var(--text-primary);
  font-weight: 700; font-size: 1.1rem;
  letter-spacing: -.3px;
}
.logo-icon { font-size: 1.4rem; color: var(--accent); }
.logo-icon.large { font-size: 2.5rem; }
.logo-text.large { font-size: 1.8rem; }

.nav-links { display: flex; gap: .25rem; }
.nav-link {
  display: flex; align-items: center; gap: .4rem;
  padding: .4rem .75rem; border-radius: var(--radius);
  color: var(--text-secondary); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: color .15s, background .15s;
}
.nav-link:hover, .nav-link.active { color: var(--text-primary); background: var(--bg-2); }
.nav-link.active { color: var(--accent); }

/* ── User Menu ──────────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 20px; padding: .3rem .75rem;
  color: var(--text-primary); cursor: pointer;
  font-size: 13px; font-family: var(--font);
}
.user-btn:hover { border-color: var(--border-light); }
.user-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 200px;
  box-shadow: var(--shadow); display: none; flex-direction: column;
  overflow: hidden; z-index: 200;
}
.user-dropdown.open { display: flex; }
.dropdown-header { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.dropdown-header strong { display: block; font-size: 13px; }
.dropdown-header small { color: var(--text-muted); font-size: 11px; }
.dropdown-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem 1rem; color: var(--text-secondary);
  text-decoration: none; font-size: 13px;
  transition: background .1s, color .1s;
}
.dropdown-item:hover { background: var(--bg-3); color: var(--text-primary); }
.dropdown-item.danger:hover { color: var(--red); }

/* ── Main Content ───────────────────────────────────────────────── */
.main-content {
  margin-top: var(--topnav-h);
  min-height: calc(100vh - var(--topnav-h));
  padding: 1.5rem;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem; border-radius: var(--radius);
  font-family: var(--font); font-size: 13px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer;
  text-decoration: none; transition: all .15s;
  white-space: nowrap; line-height: 1;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--bg-2); color: var(--text-secondary); border-color: var(--border); }
.btn-secondary:hover { color: var(--text-primary); border-color: var(--border-light); }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-2); color: var(--text-primary); }
.btn-sm { padding: .3rem .7rem; font-size: 12px; }
.btn-xs { padding: .2rem .5rem; font-size: 11px; }
.btn-lg { padding: .65rem 1.4rem; font-size: 14px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon {
  background: transparent; border: none; color: var(--text-secondary);
  padding: .45rem; border-radius: var(--radius); cursor: pointer;
  font-size: 16px; line-height: 1;
  transition: color .15s, background .15s;
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-2); }
.btn-icon-sm {
  background: transparent; border: none; color: var(--text-muted);
  padding: .25rem .4rem; border-radius: 4px; cursor: pointer;
  font-size: 12px; line-height: 1; transition: all .15s;
}
.btn-icon-sm:hover { color: var(--text-primary); background: var(--bg-3); }
.btn-icon-sm.danger:hover { color: var(--red); }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.label-hint { font-weight: 400; color: var(--text-muted); }
.form-input {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  padding: .5rem .75rem; font-family: var(--font); font-size: 13px;
  outline: none; transition: border-color .15s;
  width: 100%;
}
.form-input:focus { border-color: var(--accent); }
.form-input.sm { padding: .3rem .6rem; font-size: 12px; }
.form-select {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  padding: .45rem .75rem; font-family: var(--font); font-size: 13px;
  outline: none; cursor: pointer;
}
.form-select.sm { padding: .3rem .5rem; font-size: 12px; }
.form-select:focus { border-color: var(--accent); }
.form-error { color: var(--red); font-size: 12px; padding: .4rem .6rem; background: var(--red-dim); border-radius: var(--radius); }
.form-row-between { display: flex; justify-content: space-between; align-items: center; }
.input-icon-wrap { position: relative; }
.input-icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; pointer-events: none; }
.form-input.with-icon { padding-left: 2.25rem; }
.toggle-password { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-muted); cursor: pointer; padding: .2rem; }
.toggle-password:hover { color: var(--text-primary); }

/* ── Checkbox / Radio ───────────────────────────────────────────── */
.checkbox-label { display: flex; align-items: center; gap: .4rem; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.radio-group { display: flex; flex-direction: column; gap: .5rem; }
.radio-option { display: flex; align-items: flex-start; gap: .5rem; font-size: 13px; cursor: pointer; padding: .5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.radio-option:hover { border-color: var(--border-light); }
.radio-option input { margin-top: 3px; accent-color: var(--accent); }
.radio-desc { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Modals ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  animation: fadeIn .15s;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 480px; max-width: 96vw;
  box-shadow: var(--shadow); animation: slideUp .2s;
}
.modal-lg { width: 640px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { display: flex; align-items: center; gap: .5rem; font-size: 14px; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; line-height: 1; padding: 0 .25rem;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Flash Messages ─────────────────────────────────────────────── */
.flash-container { position: fixed; top: calc(var(--topnav-h) + 8px); right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.flash {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem 1rem;
  font-size: 13px; box-shadow: var(--shadow);
  animation: slideIn .2s; min-width: 280px; max-width: 420px;
}
.flash-success { border-color: var(--green); }
.flash-error { border-color: var(--red); }
.flash-info { border-color: var(--accent); }
.flash-close { background: none; border: none; color: var(--text-muted); cursor: pointer; margin-left: auto; font-size: 16px; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .1rem .45rem; border-radius: 10px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
}
.badge-blue { background: #1f6feb33; color: #58a6ff; }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-purple { background: #a371f722; color: var(--purple); }

/* ── Tags ───────────────────────────────────────────────────────── */
.tag { display: inline-block; padding: .1rem .4rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; font-size: 10px; color: var(--text-muted); }
.tag-btn { padding: .3rem .7rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: 20px; color: var(--text-secondary); font-size: 12px; cursor: pointer; }
.tag-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.tag-btn:hover { border-color: var(--border-light); color: var(--text-primary); }

/* ── Panels ─────────────────────────────────────────────────────── */
.panel { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.panel-header h2 { display: flex; align-items: center; gap: .5rem; font-size: 13px; color: var(--text-secondary); }

/* ── Dashboard ──────────────────────────────────────────────────── */
.dashboard-layout { display: flex; flex-direction: column; gap: 1.25rem; max-width: 1400px; margin: 0 auto; }
.stats-bar { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; }
.stat-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.stat-icon { width: 40px; height: 40px; border-radius: var(--radius); background: var(--bg-3); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 16px; }
.stat-icon.green { background: var(--green-dim); color: var(--green); }
.stat-icon.blue { background: var(--accent-dim); color: var(--accent); }
.stat-icon.red { background: var(--red-dim); color: var(--red); }
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: .15rem; }

.dashboard-body { display: grid; grid-template-columns: 1fr 380px; gap: 1.25rem; }
.panel-projects, .panel-backtests { display: flex; flex-direction: column; }
.project-list { display: flex; flex-direction: column; gap: .5rem; padding: .75rem; overflow-y: auto; max-height: 600px; }
.project-card {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1rem;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.project-card:hover { border-color: var(--border-light); background: var(--bg-2); }
.project-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .3rem; }
.project-name { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: 13px; }
.project-actions { display: flex; gap: .25rem; opacity: 0; transition: opacity .15s; }
.project-card:hover .project-actions { opacity: 1; }
.project-desc { font-size: 12px; color: var(--text-muted); margin: .25rem 0; }
.project-meta { display: flex; align-items: center; gap: .75rem; font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }
.project-tags { display: flex; gap: .25rem; flex-wrap: wrap; }

.backtest-list { display: flex; flex-direction: column; overflow-y: auto; max-height: 600px; }
.backtest-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
.backtest-row:hover { background: var(--bg-2); }
.backtest-row.running { animation: pulse 2s infinite; }
.bt-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.bt-status-dot.completed { background: var(--green); }
.bt-status-dot.error { background: var(--red); }
.bt-status-dot.running { background: var(--accent); animation: pulse 1s infinite; }
.bt-status-dot.pending { background: var(--text-muted); }
.bt-info { flex: 1; min-width: 0; }
.bt-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-project { font-size: 11px; color: var(--text-muted); }
.bt-stats { display: flex; gap: .5rem; font-size: 11px; font-family: var(--mono); }
.bt-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.bt-stat { color: var(--text-secondary); }

/* ── Empty States ───────────────────────────────────────────────── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 3rem 1rem; text-align: center; color: var(--text-muted); }
.empty-state i { opacity: .3; }
.empty-state h3 { color: var(--text-secondary); }
.empty-state.small { padding: 2rem 1rem; font-size: 13px; }

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { padding: .5rem .75rem; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg-1); position: sticky; top: 0; }
.data-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--bg-2); }
.data-table tr:last-child td { border-bottom: none; }
.table-controls { display: flex; align-items: center; gap: 1rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); }

/* ── Auth Pages ─────────────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-bg { position: fixed; inset: 0; background: radial-gradient(ellipse at top, #1f2937 0%, #0d1117 70%); z-index: 0; }
.auth-grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(88,166,255,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(88,166,255,.03) 1px, transparent 1px);
  background-size: 40px 40px;
}
.auth-container { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 1.5rem; }
.auth-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2rem;
  box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-tagline { color: var(--text-muted); font-size: 13px; margin-top: .25rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-divider { position: relative; text-align: center; margin: 1rem 0; }
.auth-divider::before { content: ''; position: absolute; top: 50%; left: 0; right: 0; border-top: 1px solid var(--border); }
.auth-divider span { position: relative; background: var(--bg-1); padding: 0 .75rem; font-size: 12px; color: var(--text-muted); }

/* ── Results Page ───────────────────────────────────────────────── */
.results-page { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.5rem; }
.results-page-header { display: flex; align-items: flex-start; gap: 1.5rem; flex-wrap: wrap; }
.results-status { display: flex; align-items: center; gap: .5rem; padding: .3rem .75rem; border-radius: 20px; font-size: 13px; font-weight: 500; margin-left: auto; }
.results-status.completed { background: var(--green-dim); color: var(--green); }
.results-status.error { background: var(--red-dim); color: var(--red); }
.error-banner { background: var(--red-dim); border: 1px solid var(--red); border-radius: var(--radius); padding: 1rem; }
.error-banner pre { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; }
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.metric-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.metric-card-label { font-size: 11px; color: var(--text-muted); margin-bottom: .25rem; }
.metric-card-value { font-size: 1.1rem; font-weight: 700; font-family: var(--mono); }
.charts-row { display: flex; gap: 1rem; }
.charts-row.two-col > .chart-card { flex: 1; }
.chart-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; flex: 1; }
.chart-card.full { width: 100%; }
.chart-card-header { display: flex; align-items: center; justify-content: space-between; padding: .65rem 1rem; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.stats-detail-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.stats-section { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; }
.stats-section h3 { font-size: 12px; color: var(--text-muted); margin-bottom: .75rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.stats-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.stats-table .stat-label { color: var(--text-muted); padding: .3rem 0; }
.stats-table .stat-value { text-align: right; font-family: var(--mono); padding: .3rem 0; font-weight: 500; }

/* ── Metrics Bar (editor) ───────────────────────────────────────── */
.metrics-bar { display: flex; gap: 1.5rem; padding: .5rem 1rem; background: var(--bg-0); border-bottom: 1px solid var(--border); overflow-x: auto; flex-wrap: nowrap; }
.metric-item { display: flex; flex-direction: column; align-items: center; white-space: nowrap; }
.metric-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.metric-value { font-size: 13px; font-weight: 700; font-family: var(--mono); }

/* ── Research Page ──────────────────────────────────────────────── */
.research-layout { display: flex; height: calc(100vh - var(--topnav-h)); margin: calc(-1.5rem) -1.5rem 0; overflow: hidden; }
.notebook-sidebar { width: 220px; background: var(--bg-1); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.sidebar-empty { padding: 1rem; font-size: 12px; color: var(--text-muted); text-align: center; }
.notebook-item { display: flex; align-items: center; gap: .5rem; padding: .55rem .75rem; cursor: pointer; font-size: 13px; color: var(--text-secondary); border-radius: var(--radius); margin: .15rem .5rem; }
.notebook-item:hover { background: var(--bg-2); color: var(--text-primary); }
.notebook-item.active { background: var(--accent-dim); color: var(--accent); }
.notebook-main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.notebook-topbar { display: flex; align-items: center; gap: 1rem; padding: .65rem 1rem; border-bottom: 1px solid var(--border); background: var(--bg-1); }
.notebook-title-input { flex: 1; background: transparent; border: none; color: var(--text-primary); font-size: 14px; font-weight: 600; outline: none; font-family: var(--font); }
.notebook-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.cell-container { flex: 1; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.notebook-cell { display: flex; gap: 0; border: 1px solid transparent; border-radius: var(--radius); }
.notebook-cell:hover { border-color: var(--border); }
.notebook-cell.code-cell { flex-direction: row; }
.cell-gutter { width: 80px; flex-shrink: 0; padding: .5rem .5rem 0; display: flex; flex-direction: column; align-items: flex-end; }
.cell-prompt { font-size: 11px; color: var(--accent); font-family: var(--mono); white-space: nowrap; }
.md-prompt { color: var(--text-muted); }
.cell-body { flex: 1; min-width: 0; }
.cell-toolbar { display: flex; gap: .25rem; padding: .25rem 0; opacity: 0; transition: opacity .1s; }
.notebook-cell:hover .cell-toolbar { opacity: 1; }
.cell-btn { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: .2rem .35rem; border-radius: 3px; font-size: 11px; }
.cell-btn:hover { background: var(--bg-3); color: var(--text-primary); }
.cell-editor { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cell-output { font-family: var(--mono); font-size: 12px; }
.cell-output-pre { padding: .5rem .75rem; background: var(--bg-0); border-left: 3px solid var(--accent); white-space: pre-wrap; line-height: 1.5; }
.output-error { border-left-color: var(--red); color: var(--red); }
.markdown-cell-input { font-family: var(--mono); resize: vertical; }
.research-reference { border-top: 1px solid var(--border); }
.ref-header { display: flex; align-items: center; justify-content: space-between; padding: .65rem 1rem; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.ref-header:hover { background: var(--bg-2); }
.ref-body { padding: 1rem; background: var(--bg-1); }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.ref-section h4 { font-size: 11px; color: var(--text-muted); margin-bottom: .4rem; }
.ref-section code { display: block; font-family: var(--mono); font-size: 11px; color: var(--green); background: var(--bg-0); padding: .2rem .4rem; border-radius: 3px; margin: .2rem 0; }

/* ── Data Explorer ──────────────────────────────────────────────── */
.data-explorer-layout { display: flex; height: calc(100vh - var(--topnav-h)); margin: -1.5rem; overflow: hidden; }
.data-sidebar { width: 200px; background: var(--bg-1); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; }
.data-search-wrap { padding: .5rem; border-bottom: 1px solid var(--border); }
.data-main { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.data-toolbar { display: flex; align-items: center; justify-content: space-between; padding: .5rem 1rem; border-bottom: 1px solid var(--border); background: var(--bg-1); gap: 1rem; flex-wrap: wrap; }
.data-toolbar-left { display: flex; align-items: center; gap: 1rem; }
.data-toolbar-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.symbol-display { display: flex; align-items: center; gap: .75rem; }
.price-display { font-size: 1.1rem; font-weight: 700; font-family: var(--mono); }
.price-change { font-size: 13px; font-family: var(--mono); }
.resolution-tabs, .indicator-btns { display: flex; gap: .25rem; flex-wrap: wrap; }
.res-btn, .ind-btn {
  padding: .2rem .5rem; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-secondary); font-size: 11px; cursor: pointer;
}
.res-btn:hover, .ind-btn:hover { border-color: var(--border-light); color: var(--text-primary); }
.res-btn.active, .ind-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.explorer-chart { flex: 1; min-height: 380px; padding: .5rem; }
.sub-chart { padding: .25rem .5rem; }
.sub-chart-label { font-size: 10px; color: var(--text-muted); padding: .15rem .5rem; }
.asset-categories { overflow-y: auto; flex: 1; }
.asset-category { border-bottom: 1px solid var(--border); }
.category-header { display: flex; align-items: center; gap: .4rem; padding: .55rem .75rem; cursor: pointer; font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.category-header:hover { background: var(--bg-2); }
.cat-chevron { font-size: 9px; transition: transform .15s; }
.asset-item { display: flex; align-items: center; padding: .35rem .75rem .35rem 1.5rem; cursor: pointer; font-size: 12px; color: var(--text-secondary); }
.asset-item:hover, .asset-item.active { background: var(--bg-2); color: var(--accent); }
.asset-symbol { font-family: var(--mono); font-weight: 500; }
.fundamentals-panel { padding: .75rem 1rem; border-top: 1px solid var(--border); }
.fund-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; }
.fund-item { display: flex; flex-direction: column; }
.fund-label { font-size: 10px; color: var(--text-muted); }
.fund-value { font-size: 12px; font-weight: 500; }
.ohlcv-panel { border-top: 1px solid var(--border); }

/* ── Library Page ───────────────────────────────────────────────── */
.library-page { max-width: 1200px; margin: 0 auto; }
.page-header { margin-bottom: 1.5rem; }
.library-filters { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.library-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.library-card:hover { border-color: var(--border-light); }
.lib-card-header { display: flex; align-items: flex-start; justify-content: space-between; }
.lib-card-title { font-weight: 600; font-size: 14px; }
.lib-card-owner { font-size: 11px; color: var(--text-muted); }
.lib-card-desc { font-size: 12px; color: var(--text-secondary); }
.lib-card-tags { display: flex; gap: .25rem; flex-wrap: wrap; }
.lib-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }

/* ── Admin Page ─────────────────────────────────────────────────── */
.admin-page { max-width: 1100px; margin: 0 auto; }
.admin-tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.admin-tab { padding: .4rem .85rem; background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-secondary); font-size: 13px; cursor: pointer; }
.admin-tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Error Pages ────────────────────────────────────────────────── */
.error-page { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 60vh; gap: 1rem; text-align: center; }
.error-code { font-size: 6rem; font-weight: 800; color: var(--border-light); line-height: 1; }
.error-msg { font-size: 1.2rem; color: var(--text-muted); }

/* ── Log Output ─────────────────────────────────────────────────── */
.log-output { background: var(--bg-0); padding: .75rem; font-family: var(--mono); font-size: 12px; height: 100%; overflow-y: auto; line-height: 1.6; }
.log-placeholder { color: var(--text-muted); font-style: italic; }
.log-line { color: var(--text-secondary); }
.log-error { color: var(--red); }
.log-debug { color: var(--text-muted); }
.log-toolbar { display: flex; gap: .5rem; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }

/* ── Running Overlay ────────────────────────────────────────────── */
.running-overlay { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.65); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; }
.running-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2rem; text-align: center; width: 320px; box-shadow: var(--shadow); }
.running-spinner { font-size: 2.5rem; color: var(--accent); margin-bottom: 1rem; }
.running-title { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; }
.running-status { font-size: 12px; color: var(--text-muted); margin-bottom: 1rem; }
.running-progress { height: 3px; background: var(--bg-3); border-radius: 2px; margin-bottom: 1.5rem; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s ease; }

/* ── Animations ─────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes shimmer { 0% { background-position: -1000px 0; } 100% { background-position: 1000px 0; } }
@keyframes glow {
  0%,100% { box-shadow: 0 0 0 0 rgba(88,166,255,.4); }
  50% { box-shadow: 0 0 0 8px rgba(88,166,255,0); }
}

/* ── Polish: hover lifts, focus rings, smoother transitions ─────────── */
.btn { transition: transform .06s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:hover { box-shadow: 0 4px 12px rgba(88,166,255,.25); }
.btn-success:hover { box-shadow: 0 4px 12px rgba(63,185,80,.25); }

.project-card { transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.project-card:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,.25); }
[data-theme="light"] .project-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); }

.stat-card { transition: transform .15s ease, border-color .15s ease; }
.stat-card:hover { border-color: var(--border-light); transform: translateY(-1px); }

.metric-card { transition: border-color .15s ease, transform .15s ease; }
.metric-card:hover { border-color: var(--accent); }

.library-card { transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.library-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.editor-tab { transition: color .15s ease, background .15s ease; }
.nav-link { transition: color .15s ease, background .15s ease; }
.bt-status-dot.running { animation: glow 1.5s infinite; }

/* Focus visible — accessibility */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%);
  background-size: 1000px 100%;
  animation: shimmer 1.6s linear infinite;
  border-radius: var(--radius);
}

/* Tooltips */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(2px);
  background: var(--bg-3);
  color: var(--text-primary);
  font-size: 11px;
  padding: .25rem .5rem;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 200;
  border: 1px solid var(--border);
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Keyboard hint chips */
kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-secondary);
  box-shadow: inset 0 -1px 0 var(--border);
  line-height: 1.4;
}
[data-theme="light"] kbd { background: #f0f0f0; border-color: #b0b0b0; color: #1e1e1e; box-shadow: inset 0 -1px 0 #999; }

/* Subtle scrollbar in light theme is too gray — give it some accent on hover */
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #0066cc; }

/* Notepad++ classic menu bar (only shows in light mode at top) */
.menu-bar {
  display: none;
  background: linear-gradient(to bottom, #f0f0f0 0%, #e0e0e0 100%);
  border-bottom: 1px solid #999;
  padding: 0;
  height: 24px;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  font-size: 12px;
}
[data-theme="light"] .menu-bar { display: flex; align-items: stretch; }
.menu-item {
  padding: 0 .75rem;
  display: flex;
  align-items: center;
  cursor: default;
  color: #1e1e1e;
  user-select: none;
}
.menu-item:hover { background: #cce0f5; }
.menu-item u { text-decoration: underline; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .dashboard-body { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: repeat(2,1fr); }
  .stats-detail-row { grid-template-columns: 1fr; }
  .charts-row.two-col { flex-direction: column; }
  .config-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .topnav { padding: 0 .75rem; }
  .nav-links .nav-link span { display: none; }
  .user-name { display: none; }
  .main-content { padding: 1rem; }
  .stats-bar { grid-template-columns: repeat(2,1fr); }
  .data-sidebar { display: none; }
  .notebook-sidebar { display: none; }
}
