/* ============================================================
   BN/CXMT Basis Monitor -- taste-skill formal edition v4.0.0
   Design dials: VARIANCE=9, MOTION=4, DENSITY=4
   Single accent: amber #E8A33D on zinc-950 off-black
   Font: Geist + Geist Mono (no Inter, no Instrument Serif)
   ============================================================ */

:root {
  --accent: #E8A33D;
  --accent-hi: #F2B45A;
  --bg: #0A0A0B;
  --surface: #111113;
  --elevated: #171719;
  --line: #1F1F23;
  --fg: #FFFFFF;
  --muted: #ffed57;
  --dim: #FFFFFF;
  --pos: #4ADE80;
  --neg: #F87171;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-full: 9999px;
}

* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; box-sizing: border-box; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: var(--bg); }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: var(--accent); }

html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: 'Geist', system-ui, sans-serif;
  overflow-x: hidden;
}
::selection { background: var(--accent); color: var(--bg); }

/* ---- Typography helpers ---- */
.eyebrow {
  font-family: 'Geist Mono', monospace; font-size: 15px;
  letter-spacing: 0.04em; color: var(--accent);
  display: block; margin-bottom: 8px;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; }
h1 { font-size: 14px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0; }
strong { font-weight: 600; }
small { font-size: 12px; color: var(--dim); }
a { color: inherit; text-decoration: none; }

/* ---- Layout shell ---- */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 24px;
  background: rgba(10,10,11,0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: rgba(232,163,61,0.1); border: 1px solid rgba(232,163,61,0.3);
  color: var(--accent);
}
.brand-mark svg { width: 16px; height: 16px; }
.brand-block h1 { font-size: 14px; }
.accent-slash { color: var(--accent); }
.brand-sub { color: var(--muted); font-weight: 400; }
.brand-block p { font-family: 'Geist Mono', monospace; font-size: 10px; color: var(--muted); margin-top: 2px; }

.view-tabs {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); border-radius: var(--radius-full); padding: 4px;
}
.view-tab {
  display: flex; align-items: center; gap: 6px;
  font-family: 'Geist Mono', monospace; font-size: 12px;
  color: var(--muted); background: transparent; border: none;
  padding: 6px 16px; border-radius: var(--radius-full); cursor: pointer;
  transition: color 0.2s, background 0.2s;
}
.view-tab:hover { color: var(--fg); }
.view-tab.active { background: transparent; color: var(--fg); border: 1px solid var(--fg); }
.view-tab svg { width: 14px; height: 14px; }
.count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--radius-full);
  background: rgba(255,255,255,0.1); color: var(--muted); font-size: 9px;
}
.view-tab.active .count-badge { background: rgba(255,255,255,0.15); color: var(--fg); }

.top-actions { display: flex; align-items: center; gap: 16px; }
.feed-hint { display: block; font-family: 'Geist Mono', monospace; font-size: 10px; color: var(--dim); margin-top: 2px; }
.feed-state { display: flex; align-items: center; gap: 8px; }
.feed-state > div { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.feed-state strong { font-size: 12px; }
.feed-state span { font-family: 'Geist Mono', monospace; font-size: 10px; color: var(--muted); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; }
.status-dot.live { background: var(--pos); animation: pulse 1.8s ease-in-out infinite; }
.status-dot.stale { background: var(--accent); }
.status-dot.demo { background: var(--muted); }
.status-dot.error, .status-dot.waiting { background: var(--neg); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.icon-button {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  cursor: pointer; transition: color 0.2s, border-color 0.2s;
}
.icon-button:hover { color: var(--accent); border-color: var(--accent); }
.icon-button.small { width: 32px; height: 32px; }
.icon-button svg { width: 16px; height: 16px; }
.icon-button.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Data banner ---- */
.data-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 24px; background: rgba(248,113,113,0.08);
  border-bottom: 1px solid rgba(248,113,113,0.2);
  font-size: 12px; color: var(--neg);
}
.data-banner svg { width: 14px; height: 14px; flex-shrink: 0; }
.data-banner.hidden { display: none; }

/* ---- Main ---- */
main { flex: 1; }

/* ---- KPI strip ---- */
.kpi-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--line); border-bottom: 1px solid var(--line);
}
.kpi-item { background: var(--bg); padding: 20px; }
.kpi-label { font-family: 'Geist Mono', monospace; font-size: 15px; color: var(--dim); display: block; margin-bottom: 8px; }
.kpi-item strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 24px; }
.kpi-item small { display: block; margin-top: 4px; }
.kpi-item.accent-green strong { color: var(--pos); }
.kpi-item.accent-amber strong { color: var(--accent); }
.kpi-item.positive strong { color: var(--pos); }
.kpi-item.negative strong { color: var(--neg); }
.kpi-item.neutral strong { color: var(--fg); }
.kpi-action { display: flex; align-items: center; }
.filter-trigger {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; cursor: pointer; padding: 0;
  text-align: left; color: var(--fg); transition: opacity 0.2s;
}
.filter-trigger:hover { opacity: 0.8; }
.filter-trigger-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: rgba(232,163,61,0.1); border: 1px solid rgba(232,163,61,0.3);
  color: var(--accent);
}
.filter-trigger-icon svg { width: 16px; height: 16px; }
.filter-trigger strong { font-size: 14px; display: block; }
.filter-trigger small { font-size: 12px; color: var(--muted); display: block; margin-top: 2px; }

@media (max-width: 768px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .kpi-action { grid-column: span 2; }
}

/* ---- View sections ---- */
.view-section { display: none; }
.view-section.active { display: block; }

/* ---- Scanner view ---- */
#scanner-view { padding: 24px; }
.opportunity-panel { margin-bottom: 24px; }
/* ---- Toolbar strip (3-cell like KPI strip) ---- */
.toolbar-strip {
  display: grid; grid-template-columns: auto 1fr auto; gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px;
}
.toolbar-cell { background: var(--bg); padding: 16px 20px; }
.toolbar-title-cell { display: flex; flex-direction: column; gap: 4px; justify-content: center; min-width: 120px; }
.toolbar-title-cell strong { font-size: 18px; }
.toolbar-filters-cell { display: flex; flex-direction: column; gap: 8px; font-size: 11px; }
.toolbar-filters-cell .inline-filter-label { font-size: 11px; }
.toolbar-filters-cell input { font-size: 11px; }
.toolbar-filters-cell .segment { font-size: 11px; }
.toolbar-pager-cell { display: flex; flex-direction: column; gap: 4px; justify-content: center; min-width: 140px; }
.toolbar-count { font-family: 'Geist Mono', monospace; font-size: 12px; color: var(--muted); }

@media (max-width: 768px) {
  .toolbar-strip { grid-template-columns: 1fr; }
}

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
.opportunity-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 800px; }
.opportunity-table th {
  font-family: 'Geist Mono', monospace; font-size: 15px; font-weight: 400;
  color: var(--dim); text-align: left; padding: 12px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.opportunity-table th:nth-child(n+2) { text-align: right; }
.opportunity-table th:last-child { text-align: center; }
.opportunity-table td { padding: 16px 12px; border-bottom: 1px solid rgba(31,31,35,0.5); vertical-align: top; }
.opportunity-table td:nth-child(n+2) { text-align: right; }
.opportunity-table td:last-child { text-align: center; }
/* 冻结首列 */
.opportunity-table th:first-child,
.opportunity-table td:first-child {
  position: sticky; left: 0; z-index: 2;
  background: var(--bg);
  box-shadow: 4px 0 6px -4px rgba(0,0,0,0.3);
}
.opportunity-table th:first-child { z-index: 3; }
.opportunity-row { transition: background 0.2s; border-left: 2px solid transparent; cursor: pointer; }
.opportunity-row:hover { background: rgba(232,163,61,0.04); border-left-color: var(--accent); }
.opportunity-row:hover td:first-child { background: var(--bg); }
.opportunity-row.selected { background: rgba(232,163,61,0.06); border-left-color: var(--accent); }
.opportunity-row.selected td:first-child { background: var(--bg); }
.loading-row td { text-align: center; color: var(--muted); padding: 40px; }

.symbol-cell { display: flex; align-items: center; gap: 10px; }
.symbol-cell strong { font-size: 14px; }
.symbol-cell small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.ticker-mark {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--elevated); border: 1px solid var(--line);
  font-family: 'Geist Mono', monospace; font-size: 10px; font-weight: 600;
  color: var(--accent); flex-shrink: 0;
}

.value-stack { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.value-stack strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 13px; }
.value-stack small { font-size: 11px; color: var(--muted); }
.value-stack .positive { color: var(--pos); }
.value-stack .negative { color: var(--neg); }
.value-stack .neutral { color: var(--fg); }

.market-links { display: flex; gap: 6px; margin-top: 4px; }
.market-links.full { margin-top: 8px; }
.market-link {
  display: inline-flex; align-items: center; gap: 3px;
  font-family: 'Geist Mono', monospace; font-size: 10px;
  padding: 2px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); color: var(--muted);
  transition: color 0.2s, border-color 0.2s;
}
.market-link:hover { color: var(--accent); border-color: var(--accent); }
.market-link svg { width: 10px; height: 10px; }
.market-link.futures:hover { color: var(--accent); }
.market-link.stock:hover { color: var(--fg); }

.risk-tag {
  display: inline-block; font-family: 'Geist Mono', monospace; font-size: 11px;
  padding: 2px 8px; border-radius: var(--radius-full);
}
.risk-tag.normal { background: rgba(74,222,128,0.1); color: var(--pos); }
.risk-tag.warning { background: rgba(232,163,61,0.1); color: var(--accent); }
.risk-tag.danger { background: rgba(248,113,113,0.1); color: var(--neg); }

/* ---- Empty state ---- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 60px 20px; text-align: center; color: var(--muted);
}
.empty-state svg { width: 32px; height: 32px; color: var(--line); }
.empty-state strong { font-size: 14px; color: var(--fg); }
.empty-state span { font-size: 12px; }
.empty-state.hidden { display: none; }

/* ---- Detail panel ---- */
.detail-panel { border-top: 1px solid var(--line); padding: 24px 0; }
.empty-detail {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 60px 20px; text-align: center; color: var(--muted);
}
.empty-detail svg { width: 32px; height: 32px; color: var(--line); }
.empty-detail strong { font-size: 14px; color: var(--fg); }
.empty-detail span { font-size: 12px; }

.detail-content { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.detail-block { background: var(--bg); padding: 16px; }
.detail-block-title { font-family: 'Geist Mono', monospace; font-size: 15px; color: var(--dim); margin-bottom: 12px; }
.detail-title { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 20px; background: var(--bg); }
.detail-title-main { display: flex; align-items: center; gap: 12px; }
.detail-title-main h2 { font-size: 24px; }
.detail-title-actions { display: flex; align-items: center; gap: 8px; }
.source-chip { font-family: 'Geist Mono', monospace; font-size: 11px; padding: 4px 10px; border-radius: var(--radius-full); background: var(--elevated); border: 1px solid var(--line); color: var(--muted); }

.detail-rate { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.detail-rate > div { display: flex; flex-direction: column; gap: 2px; }
.detail-rate span { font-size: 11px; color: var(--muted); }
.detail-rate strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 16px; }
.detail-rate .positive { color: var(--pos); }
.detail-rate .negative { color: var(--neg); }

.metric-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 12px; }
.metric-row span { color: var(--muted); }
.metric-row strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 12px; }
.metric-row .positive { color: var(--pos); }
.metric-row .negative { color: var(--neg); }

.leg-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12px; }
.leg-row span { color: var(--muted); }
.leg-row strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; margin-left: auto; }
.leg-side { font-family: 'Geist Mono', monospace; font-size: 10px; padding: 2px 8px; border-radius: var(--radius-full); }
.leg-side.long { background: rgba(74,222,128,0.1); color: var(--pos); }
.leg-side.short { background: rgba(248,113,113,0.1); color: var(--neg); }

.history-bars { display: flex; align-items: flex-end; gap: 2px; height: 60px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.history-bar { width: 4px; background: var(--accent); border-radius: 1px; }
.history-bar.negative { background: var(--neg); }

.projection-total { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 0; margin-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
.projection-total span { color: var(--muted); }
.projection-total strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 16px; color: var(--pos); }

.detail-action { width: 100%; margin-top: 12px; justify-content: center; }

/* ---- Formula stack ---- */
.formula-stack { display: flex; flex-direction: column; gap: 8px; }
.formula-line { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; border-bottom: 1px solid rgba(31,31,35,0.5); }
.formula-line span { font-size: 11px; color: var(--muted); }
.formula-line strong { font-size: 11px; font-weight: 400; color: var(--fg); }
.formula-line em { font-family: 'Geist Mono', monospace; font-style: normal; font-size: 10px; color: var(--accent); }
.formula-line.total { border-bottom: none; padding-top: 8px; }
.formula-line.total strong { color: var(--accent); }

/* ---- Fee audit ---- */
.fee-audit-list { display: flex; flex-direction: column; gap: 8px; }
.fee-audit-row { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(31,31,35,0.5); font-size: 11px; }
.fee-audit-row span { color: var(--fg); }
.fee-audit-row strong { color: var(--accent); }
.fee-audit-row em { color: var(--muted); font-style: normal; }
.fee-audit-row a { color: var(--accent); font-size: 10px; }

/* ---- Risk rows ---- */
.risk-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; font-size: 11px; color: var(--muted); }
.risk-row svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; color: var(--neg); }

/* ---- Positions view ---- */
#positions-view { padding: 24px; }
.positions-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; }
.positions-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.position-card { background: var(--bg); padding: 20px; }
.position-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.position-card-head-main { display: flex; align-items: center; gap: 10px; }
.position-card-head-main strong { font-size: 18px; }
.position-card-actions { display: flex; gap: 4px; }
.position-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; margin-bottom: 12px; }
.position-metric { display: flex; flex-direction: column; gap: 2px; }
.position-metric span { font-size: 11px; color: var(--muted); }
.position-metric strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 13px; }
.position-metric .positive { color: var(--pos); }
.position-metric .negative { color: var(--neg); }
.position-total { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 0; margin-top: 8px; border-top: 1px solid var(--line); }
.position-total span { font-size: 12px; color: var(--muted); }
.position-total strong { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 20px; }
.position-total .positive { color: var(--pos); }
.position-total .negative { color: var(--neg); }
.price-source { display: block; font-size: 11px; color: var(--muted); margin-top: 8px; }
.positions-empty { margin-top: 24px; border: 1px solid var(--line); border-radius: var(--radius); }

@media (max-width: 768px) {
  .positions-grid { grid-template-columns: 1fr; }
  .detail-content { grid-template-columns: 1fr; }
}

/* ---- Buttons ---- */
.command-button {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Geist Mono', monospace; font-size: 12px;
  background: var(--elevated); color: var(--fg); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: var(--radius-full); cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.command-button:hover { background: var(--surface); border-color: var(--accent); }
.command-button.primary { background: transparent; color: var(--fg); border: 1px solid var(--fg); }
.command-button.primary:hover { background: rgba(255,255,255,0.08); border-color: var(--fg); }
.command-button svg { width: 14px; height: 14px; }
.secondary-button {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Geist Mono', monospace; font-size: 12px;
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: var(--radius-full); cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.secondary-button:hover { color: var(--fg); border-color: var(--fg); }
.secondary-button svg { width: 14px; height: 14px; }

/* ---- Modal dialog ---- */
.modal-dialog {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0; width: 90vw; max-width: 640px; color: var(--fg);
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}
.modal-dialog::backdrop { background: rgba(10,10,11,0.8); backdrop-filter: blur(4px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 24px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 24px 24px; border-top: 1px solid var(--line); }

/* ---- Form fields ---- */
.modal-body label { display: flex; flex-direction: column; gap: 6px; }
.modal-body label > span { font-family: 'Geist Mono', monospace; font-size: 15px; color: var(--dim); }
.modal-body label.wide-field { grid-column: 1 / -1; }
.field-label-text { font-family: 'Geist Mono', monospace; font-size: 15px; color: var(--dim); display: block; margin-bottom: 6px; }
.modal-body input, .modal-body select, .modal-body textarea {
  background: transparent; border: none; border-bottom: 1px solid var(--line);
  color: var(--fg); font-family: 'Geist Mono', monospace; font-size: 13px;
  padding: 8px 0; outline: none; transition: border-color 0.25s; width: 100%;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus { border-bottom-color: var(--accent); }
.modal-body input::placeholder, .modal-body textarea::placeholder { color: var(--muted); }
.modal-body textarea { resize: vertical; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; }
.modal-body select { cursor: pointer; }
.modal-body .hint { font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }

/* ---- Symbol picker ---- */
.symbol-picker { margin-top: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.symbol-picker-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--elevated); flex-wrap: wrap; }
.symbol-picker-header .hint { margin: 0; }
.symbol-picker-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.page-size-label { display: flex; align-items: center; gap: 4px; font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--muted); }
.page-size-label input { width: 48px; font-family: 'Geist Mono', monospace; font-size: 11px; text-align: center; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px 4px; color: var(--fg); background: var(--bg); }
.page-info { font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--muted); min-width: 36px; text-align: center; }
.symbol-list { display: flex; flex-wrap: wrap; gap: 4px; padding: 12px; max-height: 200px; overflow-y: auto; }
.symbol-chip {
  font-family: 'Geist Mono', monospace; font-size: 11px;
  padding: 3px 8px; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  cursor: pointer; transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.symbol-chip:hover { color: var(--fg); border-color: var(--fg); }
.symbol-chip.active { background: rgba(232,163,61,0.1); border-color: var(--accent); color: var(--accent); }

/* ---- Config view ---- */
.config-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
}
.config-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column;
}
.config-card-wide { grid-column: span 2; }
.config-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.config-card-header h2 { font-size: 16px; }
.config-card-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.config-card-body label { display: flex; flex-direction: column; gap: 4px; }
.config-card-body label span { font-family: 'Geist Mono', monospace; font-size: 12px; color: var(--dim); }
.config-card-body input, .config-card-body select, .config-card-body textarea {
  font-family: 'Geist Mono', monospace; font-size: 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; color: var(--fg); background: var(--bg); outline: none;
  transition: border-color 0.2s;
}
.config-card-body input:focus, .config-card-body select:focus, .config-card-body textarea:focus {
  border-color: var(--accent);
}

/* ---- Compact config card (single row) ---- */
.config-card-compact { grid-column: span 2; }
.config-inline-row {
  flex-direction: row !important; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px !important;
}
.inline-field { display: flex; flex-direction: column; gap: 3px; }
.inline-field span { font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--dim); }
.inline-field input, .inline-field select {
  font-family: 'Geist Mono', monospace; font-size: 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 5px 8px; color: var(--fg); background: var(--bg); outline: none;
  transition: border-color 0.2s; width: 90px;
}
.inline-field select { width: 80px; }
.inline-field input:focus, .inline-field select:focus { border-color: var(--accent); }
.inline-divider { width: 1px; height: 32px; background: var(--line); margin: 0 4px; }
.config-hint { font-size: 12px; color: var(--muted); margin: 0 0 4px 0; }
.config-actions { grid-column: span 2; display: flex; justify-content: flex-end; }

/* ---- Symbol table ---- */
.symbol-table { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.symbol-table-header, .symbol-table-row {
  display: grid; grid-template-columns: 32px 80px 100px 1fr 100px 1fr 60px 32px; gap: 1px; background: var(--line);
}
.symbol-table-header > span { background: var(--surface); padding: 8px 10px; font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--dim); }
.symbol-table-row > * { background: var(--bg); padding: 4px 6px; }
.symbol-table-row:hover > * { background: var(--surface); }
.symbol-check { display: flex; align-items: center; justify-content: center; }
.symbol-check input { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.cell-input { font-family: 'Geist Mono', monospace; font-size: 12px; border: 1px solid transparent; border-radius: 3px; padding: 4px 6px; color: var(--fg); background: transparent; outline: none; width: 100%; }
.cell-input:focus { border-color: var(--accent); background: var(--bg); }
.cell-path { font-size: 11px; color: var(--muted); }
.alias-row-delete { margin: 2px; }
.row-delete { margin: 2px; }

.modal-dialog-sm { max-width: 400px; }
.modal-dialog-sm .modal-body { padding: 20px 24px; }
.modal-dialog-sm .modal-footer { gap: 8px; }

/* ---- Refresh dialog ---- */
#refresh-symbol-list { max-height: 500px; overflow-y: auto; }
.command-button.small, .secondary-button.small { padding: 6px 10px; font-size: 11px; }
.command-button.small svg, .secondary-button.small svg { width: 12px; height: 12px; }

@media (max-width: 768px) {
  .symbol-table-header, .symbol-table-row { grid-template-columns: 28px 50px 60px 1fr 60px 1fr 50px 28px; }
  .cell-path { display: none; }
  .symbol-table-header > span:nth-child(4), .symbol-table-header > span:nth-child(6) { display: none; }
}

/* ---- Symbol status ---- */
.cell-status { display: flex; align-items: center; justify-content: center; }
.status-badge { font-family: 'Geist', sans-serif; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.status-ok { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.status-dead { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.status-stale { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.symbol-table-row.row-dead > * { opacity: 0.5; }

@media (max-width: 768px) {
  .config-grid { grid-template-columns: 1fr; }
  .config-card-wide, .config-actions { grid-column: span 1; }
}

/* ---- Inline filters ---- */
.inline-filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
}
.inline-filter { display: flex; flex-direction: column; gap: 4px; }
.inline-filter-label { font-family: 'Geist Mono', monospace; font-size: 15px; color: var(--dim); white-space: nowrap; }
.inline-filter input { width: 100px; font-family: 'Geist Mono', monospace; font-size: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 8px; color: var(--fg); background: var(--bg); outline: none; transition: border-color 0.2s; }
.inline-filter input:focus { border-color: var(--accent); }
.inline-filter input[type="search"] { width: 140px; }
.inline-filter .input-with-icon { position: relative; }
.inline-filter .input-with-icon svg { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); width: 12px; height: 12px; color: var(--muted); }
.inline-filter .input-with-icon input { padding-left: 24px; }
.inline-filter .segmented-control { display: flex; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.inline-filter .segment { padding: 6px 12px; font-size: 11px; }
.toggle-line.compact { padding: 0; }
.secondary-button.compact { padding: 6px 12px; font-size: 11px; align-self: flex-end; }
.secondary-button.compact svg { width: 12px; height: 12px; }

@media (max-width: 768px) {
  .inline-filters { gap: 8px; }
  .inline-filter input { width: 80px; }
  .inline-filter input[type="search"] { width: 100px; }
}

/* ---- Heatmap view ---- */
#heatmap-view { padding: 24px; }
.heatmap-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; }
.heatmap-legend { display: flex; align-items: center; gap: 8px; }
.legend-label { font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--muted); }
.legend-gradient {
  width: 120px; height: 6px; border-radius: 3px;
  background: linear-gradient(to right, rgba(248,113,113,0.1), rgba(248,113,113,0.5), rgba(248,113,113,0.9));
}
.heatmap-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.heatmap-cell {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px; min-height: 72px; border: 1px solid transparent; border-radius: 0;
  background: var(--bg); cursor: pointer; transition: transform 0.15s;
  text-align: left; font-family: 'Geist', sans-serif;
}
.heatmap-cell:hover { transform: scale(1.03); z-index: 1; }
.heatmap-cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 2; }
.heatmap-ticker { font-size: 13px; font-weight: 600; color: var(--fg); }
.heatmap-rate { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; color: var(--fg); }
.heatmap-hourly { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted); }
.heatmap-name { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

@media (max-width: 768px) {
  .heatmap-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* ---- Pager (opportunity table) ---- */
.pager { display: flex; align-items: center; gap: 10px; }
.pager-info { display: flex; align-items: center; gap: 8px; }
.pager-controls { display: flex; align-items: center; gap: 4px; }
.pager-size-label { display: flex; align-items: center; gap: 4px; font-family: 'Geist Mono', monospace; font-size: 11px; color: var(--muted); }
.pager-size-label input { width: 48px; font-family: 'Geist Mono', monospace; font-size: 11px; text-align: center; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px 4px; color: var(--fg); background: var(--bg); }

.settings-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.position-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.filter-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.filter-actions { display: flex; justify-content: flex-end; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }

@media (max-width: 600px) {
  .settings-layout, .position-layout, .filter-layout { grid-template-columns: 1fr; }
}

/* ---- Input with icon ---- */
.input-with-icon { position: relative; }
.input-with-icon svg { position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--muted); }
.input-with-icon input { padding-left: 22px; }

/* ---- Field line ---- */
.field-line { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.field-line output { font-family: 'Geist Mono', monospace; font-size: 13px; color: var(--accent); }

/* ---- Range input ---- */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 2px; background: var(--line); border-radius: 1px; outline: none; width: 100%;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg); cursor: pointer;
}

/* ---- Allocation rail ---- */
.allocation-rail { display: flex; justify-content: space-between; font-family: 'Geist Mono', monospace; font-size: 9px; color: var(--muted); margin-top: 6px; }

/* ---- Segmented control ---- */
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.segment { background: var(--bg); color: var(--muted); border: none; font-family: 'Geist Mono', monospace; font-size: 12px; padding: 8px; cursor: pointer; transition: background 0.2s, color 0.2s; }
.segment:hover { color: var(--fg); }
.segment.active { background: var(--accent); color: var(--bg); }

/* ---- Toggle ---- */
.toggle-line { display: flex; align-items: center; justify-content: space-between; cursor: pointer; padding: 12px 0; }
.toggle-line span strong { font-size: 13px; display: block; }
.toggle-line span small { font-size: 11px; color: var(--muted); }
.toggle-line input { display: none; }
.toggle-control { position: relative; width: 36px; height: 20px; background: var(--line); border-radius: var(--radius-full); transition: background 0.25s; flex-shrink: 0; }
.toggle-control::before { content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: var(--muted); border-radius: 50%; transition: transform 0.25s, background 0.25s; }
.toggle-line input:checked + .toggle-control { background: rgba(232,163,61,0.3); }
.toggle-line input:checked + .toggle-control::before { transform: translateX(16px); background: var(--accent); }

/* ---- Source note ---- */
.source-note { display: flex; gap: 8px; font-size: 11px; color: var(--muted); line-height: 1.6; padding: 12px 0; border-top: 1px solid var(--line); }
.source-note svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 2px; }

/* ---- Toast ---- */
.toast-region { position: fixed; bottom: 24px; right: 24px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--elevated); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 20px; font-size: 13px; color: var(--fg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: toast-in 0.3s ease;
}
.toast.error { border-color: rgba(248,113,113,0.4); color: var(--neg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Hidden ---- */
.hidden { display: none !important; }

/* ---- Responsive table ---- */
@media (max-width: 1023px) {
  .opportunity-table { min-width: 0; }
  .opportunity-table th, .opportunity-table td { white-space: nowrap; }
  .opportunity-table td:first-child { white-space: normal; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .status-dot.live { animation: none; opacity: 1; }
  html { scroll-behavior: auto; }
}

/* ---- 角色权限：非管理员隐藏编辑功能 ---- */
body.role-user #settings-btn { display: none; }
body.role-user #save-config-btn { display: none; }
body.role-user #config-view { display: none; }
body.role-user .view-tab[data-view="config"] { display: none; }
body.role-user #symbol-refresh-btn { display: none; }
body.role-user #symbol-add-btn { display: none; }
body.role-user #symbol-check-status-btn { display: none; }
body.role-user .row-delete { display: none; }
body.role-user .cell-input { pointer-events: none; opacity: 0.7; }
body.role-user .symbol-check input { pointer-events: none; }
body.role-user #symbol-toggle-all { pointer-events: none; }
body.role-user #position-form button[type="submit"] { display: none; }
body.role-user .position-delete { display: none; }
body.role-user #reset-filter-btn { display: none; }
/* 执行方式切换、资金、持有天数、杠杆：纯前端计算，用户可操作 */

/* ============================================================
   手机端响应式优化（≤768px，不影响桌面端）
   ============================================================ */
@media (max-width: 768px) {
  /* ---- Topbar：两行布局 ---- */
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .brand-block { flex: 1; min-width: 0; }
  .brand-block h1 { font-size: 12px; }
  .brand-block p { font-size: 9px; }
  .top-actions { gap: 8px; }
  .feed-hint-refresh { display: block; }
  .view-tabs { flex-basis: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .view-tab { padding: 6px 10px; font-size: 11px; white-space: nowrap; }
  .view-tab span { font-size: 11px; }
  #auth-btn span { display: none; }
  .icon-button { width: 32px; height: 32px; }

  /* ---- KPI strip：紧凑 ---- */
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .kpi-item { padding: 12px; }
  .kpi-item strong { font-size: 18px; }
  .kpi-label { font-size: 13px; margin-bottom: 4px; }
  .kpi-item small { font-size: 10px; }

  /* ---- Scanner view padding ---- */
  #scanner-view { padding: 12px; }
  #heatmap-view { padding: 12px; }
  #positions-view { padding: 12px; }
  #config-view { padding: 12px; }

  /* ---- Toolbar strip：紧凑单列 ---- */
  .toolbar-strip { grid-template-columns: 1fr; }
  .toolbar-cell { padding: 10px 12px; }
  .toolbar-title-cell strong { font-size: 15px; }
  .toolbar-pager-cell { min-width: 0; }

  /* ---- Inline filters：紧凑 ---- */
  .inline-filters { gap: 8px; }
  .inline-filter-label { font-size: 13px; }
  .inline-filter input { width: 80px; font-size: 11px; }
  .inline-filter input[type="search"] { width: 100px; }
  .inline-filter .segment { padding: 4px 8px; font-size: 10px; }

  /* ---- 表格：紧凑横向滚动 ---- */
  .opportunity-table { font-size: 12px; min-width: 600px; }
  .opportunity-table th { padding: 8px 6px; font-size: 13px; }
  .opportunity-table td { padding: 8px 6px; }
  .ticker-mark { width: 28px; height: 28px; font-size: 9px; }
  .value-stack strong { font-size: 12px; }
  .value-stack small { font-size: 10px; }
  .market-links { flex-direction: column; gap: 4px; }

  /* ---- 弹窗：适配手机 ---- */
  .modal-dialog { width: 95vw; max-width: none; }
  .modal-header { padding: 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px 16px; flex-wrap: wrap; }
  .modal-dialog-sm { max-width: none; }

  /* ---- Pager 紧凑 ---- */
  .pager { gap: 6px; flex-wrap: wrap; }
  .pager-size-label { font-size: 10px; }

  /* ---- Heatmap：更小格子 ---- */
  .heatmap-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 4px; }
  .heatmap-cell { padding: 8px 6px; }
  .heatmap-ticker { font-size: 11px; }
  .heatmap-value { font-size: 11px; }
  .heatmap-name { font-size: 9px; }

  /* ---- Detail / Positions 单列 ---- */
  .detail-content { grid-template-columns: 1fr; gap: 12px; }
  .positions-grid { grid-template-columns: 1fr; gap: 12px; }

  /* ---- Config symbol table 紧凑 ---- */
  .symbol-table-header, .symbol-table-row { grid-template-columns: 24px 40px 50px 1fr 50px 1fr 40px 24px; gap: 2px; }
  .cell-path { display: none; }
  .symbol-table-header > span:nth-child(4), .symbol-table-header > span:nth-child(6) { display: none; }

  /* ---- Toast 位置 ---- */
  .toast-region { bottom: 12px; right: 12px; left: 12px; }
  .toast { font-size: 12px; padding: 10px 14px; }

  /* ---- Data banner 紧凑 ---- */
  .data-banner { padding: 8px 12px; font-size: 11px; }
}
