/* ========== CSS Custom Properties ========== */
:root {
  --bg-primary: #080b0e;
  --bg-secondary: #0d1117;
  --bg-tertiary: #111720;
  --border: #1e2a35;
  --border-light: #243040;
  --text-primary: #e8f0f8;
  --text-secondary: #5a7080;
  --text-tertiary: #5a7080;
  --green: #00e09e;
  --green-dim: rgba(0, 224, 158, 0.12);
  --red: #ff4b6e;
  --red-dim: rgba(255, 75, 110, 0.12);
  --yellow: #f0a500;
  --yellow-dim: rgba(240, 165, 0, 0.12);
  --cyan: #4b9eff;
  --cyan-dim: rgba(75, 158, 255, 0.12);
  --orange: #f0a500;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  --font-size-xs: 0.6875rem;
  --font-size-sm: 0.75rem;
  --font-size-base: 0.8125rem;
  --font-size-lg: 0.9375rem;
  --font-size-xl: 1.125rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 2rem;
  --radius: 6px;
  --radius-sm: 4px;
  --topbar-height: 48px;
  --ticker-height: 28px;
  --sidebar-left: 210px;
  --sidebar-right: 290px;
}

/* ========== Reset ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-mono);
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== Typography ========== */
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-cyan { color: var(--cyan); }
.text-orange { color: var(--orange); }
.text-muted { color: var(--text-secondary); }
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }
.text-3xl { font-size: var(--font-size-3xl); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.uppercase { text-transform: uppercase; }
.whitespace-nowrap { white-space: nowrap; }

/* ========== App Layout ========== */
.app-container {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--topbar-height) var(--ticker-height) 1fr;
}
.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-left) 1fr var(--sidebar-right);
  overflow: hidden;
}
.sidebar-left {
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 12px;
}
.sidebar-right {
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding: 12px;
}
.content-main {
  overflow-y: auto;
  padding: 16px;
}

/* ========== TopBar ========== */
.topbar {
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-size-lg);
  font-weight: 700;
  white-space: nowrap;
}
.topbar-nav {
  display: flex;
  gap: 4px;
  margin-left: 24px;
}
.nav-tab {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.nav-tab:hover { color: var(--text-primary); background: var(--bg-tertiary); text-decoration: none; }
.nav-tab.active { color: var(--yellow); background: var(--yellow-dim); }
.nav-tab.disabled { color: var(--text-tertiary); cursor: not-allowed; opacity: 0.5; }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  white-space: nowrap;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
}
.connected-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  animation: pulse-green 2s infinite;
}
.btn-sign-out {
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  cursor: pointer;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.btn-sign-out:hover { color: var(--text-primary); border-color: var(--text-muted); }
.kill-switch {
  padding: 6px 16px;
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s;
}
.kill-switch:hover { background: var(--red-dim); }

/* ========== Ticker Tape ========== */
.ticker-tape {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  height: var(--ticker-height);
  display: flex;
  align-items: center;
  font-size: var(--font-size-xs);
}
.ticker-track {
  display: flex;
  gap: 32px;
  animation: ticker-scroll 60s linear infinite;
  white-space: nowrap;
}
.ticker-item {
  display: flex;
  gap: 6px;
  align-items: center;
}
.ticker-symbol { color: var(--text-secondary); font-weight: 600; }
.ticker-price { color: var(--text-primary); }
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* ========== Cards ========== */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}
.stat-card.accent-amber::before { background: var(--yellow); }
.stat-card.accent-green::before { background: var(--green); }
.stat-card.accent-blue::before { background: var(--cyan); }
.stat-card.accent-red::before { background: var(--red); }
.stat-card .stat-title {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  line-height: 1.2;
}
.stat-card .stat-subtitle {
  font-size: var(--font-size-xs);
  margin-top: 4px;
}

/* ========== Badge ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-cyan { background: rgba(88, 166, 255, 0.12); color: var(--cyan); }
.badge-gray { background: rgba(110, 118, 129, 0.15); color: var(--text-secondary); }

/* ========== Tables ========== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}
.data-table tr:hover td { background: var(--bg-tertiary); }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.section-header h3 {
  font-size: var(--font-size-base);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.section-header .section-meta {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
}

/* ========== Progress Bar ========== */
.progress-container { margin-bottom: 8px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.progress-bar {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ========== Confidence Bar ========== */
.confidence-bar-container {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.confidence-bar {
  width: 60px;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  display: block;
}
.confidence-fill {
  height: 100%;
  border-radius: 3px;
  display: block;
  min-width: 2px;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-transform: uppercase;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-green { background: var(--green); color: #000; border-color: var(--green); }
.btn-green:hover:not(:disabled) { background: #2ea043; }
.btn-red { background: transparent; color: var(--red); border-color: var(--red); }
.btn-red:hover:not(:disabled) { background: var(--red-dim); }
.btn-cyan { background: var(--cyan); color: #000; border-color: var(--cyan); }
.btn-cyan:hover:not(:disabled) { background: #4a93db; }
.btn-full { width: 100%; }
.btn-sm { padding: 4px 12px; font-size: var(--font-size-xs); }

/* ========== Panels (Sidebar) ========== */
.panel {
  margin-bottom: 20px;
}
.panel-title {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 600;
}
.watchlist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.watchlist-item:hover { background: var(--bg-tertiary); }
.watchlist-item.active { border-left: 3px solid var(--cyan); padding-left: 5px; }
.watchlist-symbol { font-weight: 600; font-size: var(--font-size-sm); }
.watchlist-change { font-size: var(--font-size-xs); }
.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: var(--font-size-xs);
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.green { background: var(--green); }
.status-dot.red { background: var(--red); }
.status-dot.yellow { background: var(--yellow); }

/* ========== Pending Approval Card ========== */
.approval-card {
  background: var(--bg-secondary);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}
.approval-card .approval-header {
  font-size: var(--font-size-xs);
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  margin-bottom: 8px;
}
.approval-card .approval-signal {
  font-size: var(--font-size-sm);
  margin-bottom: 4px;
}
.approval-card .approval-reasoning {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  font-style: italic;
  padding: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin: 8px 0;
}
.approval-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.approval-actions .btn { flex: 1; }

/* ========== Sentiment Bars ========== */
.sentiment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: var(--font-size-xs);
}
.sentiment-symbol { width: 70px; font-weight: 600; }
.sentiment-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}
.sentiment-fill {
  height: 100%;
  border-radius: 4px;
}
.sentiment-score { width: 30px; text-align: right; font-weight: 600; }

/* ========== AI Cost Tracker ========== */
.cost-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-size-xs);
  padding: 3px 0;
}
.cost-label { color: var(--text-secondary); }
.cost-value { font-weight: 600; }

/* ========== System Alerts ========== */
.alert-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: var(--font-size-xs);
}
.alert-item:last-child { border-bottom: none; }
.alert-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.alert-dot.amber { background: var(--yellow); }
.alert-dot.blue { background: var(--cyan); }
.alert-dot.red { background: var(--red); }
.alert-message { color: var(--text-secondary); line-height: 1.4; }
.alert-time {
  margin-left: auto;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ========== Equity Chart ========== */
.chart-container { margin-bottom: 16px; }
.chart-controls {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.chart-btn {
  padding: 4px 12px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  font-weight: 600;
  cursor: pointer;
}
.chart-btn:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.chart-btn.active { background: var(--yellow-dim); border-color: rgba(240, 165, 0, 0.4); color: var(--yellow); }
.axis-label { fill: var(--text-tertiary); font-size: 10px; font-family: var(--font-mono); }
.grid-line { stroke: var(--border-light); stroke-width: 0.5; }

/* ========== Auth Layout ========== */
.auth-layout {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}
.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: var(--font-size-xl);
  font-weight: 700;
}
.auth-logo-text { letter-spacing: 1px; }
.auth-title {
  font-size: var(--font-size-lg);
  margin-bottom: 20px;
  color: var(--text-primary);
}
.auth-error {
  padding: 8px 12px;
  background: var(--red-dim);
  color: var(--red);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  margin-bottom: 12px;
}
.auth-success {
  padding: 8px 12px;
  background: var(--green-dim);
  color: var(--green);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  margin-bottom: 12px;
}
.auth-footer {
  margin-top: 16px;
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ========== Forms ========== */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.form-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--cyan); }
.form-input::placeholder { color: var(--text-tertiary); }
select.form-input { appearance: none; cursor: pointer; }
.form-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--font-size-sm);
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ========== Animations ========== */
@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ========== Pagination ========== */
.pagination { display: flex; gap: 4px; justify-content: center; align-items: center; margin-top: 16px; }
.page-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  cursor: pointer;
  transition: background 0.15s;
}
.page-btn:hover { background: var(--border); color: var(--text-primary); }
.page-btn.active { background: var(--cyan); color: var(--bg-primary); border-color: var(--cyan); }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-btn:disabled:hover { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 90%;
}
.modal-card h3 { font-size: var(--font-size-lg); margin-bottom: 12px; }
.modal-card p { color: var(--text-secondary); font-size: var(--font-size-sm); margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ========== Loading ========== */
.loading-indicator { text-align: center; padding: 32px; color: var(--text-secondary); font-size: var(--font-size-sm); }

/* ========== Filter Bar ========== */
.filter-bar { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-group label { font-size: var(--font-size-xs); margin-bottom: 2px; }

/* ========== Tier Gate ========== */
.tier-gate-message {
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}
.tier-gate-message strong { color: var(--yellow); }

/* ========== Detail Panel ========== */
.detail-panel {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 8px 0;
  font-size: var(--font-size-sm);
}
.detail-panel h4 { font-size: var(--font-size-sm); color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-panel p { color: var(--text-primary); margin-bottom: 8px; line-height: 1.6; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.detail-grid .detail-item label { display: block; font-size: var(--font-size-xs); color: var(--text-tertiary); margin-bottom: 2px; }
.detail-grid .detail-item span { color: var(--text-primary); font-weight: 600; }

/* ========== Auth Success ========== */
.auth-success { background: var(--green-dim); color: var(--green); padding: 10px 14px; border-radius: var(--radius-sm); font-size: var(--font-size-sm); margin-bottom: 16px; }

/* ========== Empty State ========== */
.empty-state { text-align: center; padding: 32px; color: var(--text-tertiary); font-size: var(--font-size-sm); }

/* ========== Clickable Row ========== */
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--bg-tertiary); }

/* ========== Blazor overrides ========== */
#blazor-error-ui { display: none; background: var(--red-dim); color: var(--red); padding: 8px 16px; position: fixed; bottom: 0; width: 100%; z-index: 1000; text-align: center; }
#blazor-error-ui .dismiss { cursor: pointer; margin-left: 8px; }
#blazor-error-ui .reload { color: var(--cyan); }
