/* TradingView Dark + Zenith-Quant Teal Theme */
:root {
  --bg-page: #0b1018;
  --bg-shell: #131722;
  --bg-header: #111822;
  --bg-card: #111822;
  --bg-card-inner: #171b26;
  --bg-card-header: #1c2030;
  --bg-elevated: #182231;
  --bg-control: #2a2e39;
  --border-subtle: #263244;
  --border-strong: #334155;
  --border-tv: #2a2e39;
  --text-primary: #d8e1ea;
  --text-secondary: #8b98aa;
  --text-muted: #787b86;
  --text-bright: #ffffff;
  --primary-teal: #2dd4bf;
  --primary-teal-bright: #5eead4;
  --primary-teal-hover: #14b8a6;
  --primary-teal-bg: rgba(45, 212, 191, 0.16);
  --primary-teal-border: rgba(45, 212, 191, 0.58);
  --primary-gold: #fbbf24;
  --primary-gold-bright: #fcd34d;
  --color-up-cn: #f23645;
  --color-down-cn: #089981;
  --color-up-us: #089981;
  --color-down-us: #f23645;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.zq-header {
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
}

.zq-footer {
  background-color: #11151f;
  border-top: 1px solid var(--border-tv);
  color: var(--text-secondary);
}

.card-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  transition: border-color 0.2s ease;
}

.card-panel:hover {
  border-color: var(--border-strong);
}

.zq-insight-card {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-tv);
  border-radius: 8px;
}

.zq-status-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  color: var(--text-secondary);
}

/* Segmented Switch matching zenith-quant analysisModeSwitch */
.seg-group {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 4px;
  gap: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.seg-btn {
  border: 1px solid transparent;
  background: transparent;
  color: #9aa7b8;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.seg-btn:hover {
  color: var(--text-bright);
}

.seg-btn.active {
  background-color: var(--primary-teal-bg);
  border-color: var(--primary-teal-border);
  color: var(--primary-teal-bright);
}

.seg-btn.active-gold {
  background-color: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.58);
  color: var(--primary-gold-bright);
}

/* Action Buttons matching zenith-quant header controls */
.zq-btn-secondary {
  background-color: var(--bg-control);
  border: 1px solid #363c4e;
  color: #d1d4dc;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.zq-btn-secondary:hover {
  background-color: #363c4e;
  color: var(--text-bright);
}

.zq-btn-teal {
  background-color: rgba(45, 212, 191, 0.14);
  border: 1px solid rgba(45, 212, 191, 0.55);
  color: var(--primary-teal-bright);
  padding: 6px 13px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.zq-btn-teal:hover {
  background-color: rgba(45, 212, 191, 0.24);
  border-color: var(--primary-teal);
  color: var(--text-bright);
}

.zq-btn-teal:disabled {
  opacity: 0.65;
  cursor: wait;
}

.zq-input {
  background-color: var(--bg-control);
  border: 1px solid #363c4e;
  border-radius: 5px;
  color: var(--text-bright);
  outline: none;
  transition: border-color 0.2s ease;
}

.zq-input:focus {
  border-color: var(--primary-teal);
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.table-container {
  overflow-x: auto;
}

table.etf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.etf-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-card-header);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border-tv);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

table.etf-table thead th:first-child,
table.etf-table thead th:nth-child(2),
table.etf-table thead th:nth-child(3) {
  text-align: left;
}

table.etf-table thead th:hover {
  color: var(--text-bright);
}

table.etf-table tbody tr {
  border-bottom: 1px solid var(--border-tv);
  cursor: pointer;
  transition: background-color 0.12s ease;
}

table.etf-table tbody tr:hover {
  background-color: var(--bg-elevated);
}

table.etf-table tbody td {
  padding: 10px 12px;
  text-align: right;
  white-space: nowrap;
}

table.etf-table tbody td:first-child,
table.etf-table tbody td:nth-child(2),
table.etf-table tbody td:nth-child(3) {
  text-align: left;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 16, 24, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(94, 234, 212, 0.3);
  border-top-color: #5eead4;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* Custom scrollbar matching zenith-quant */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
  background: #363c4e;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4c5265;
}

/* Primary Dual-Card Mode Switcher */
.mode-hero-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 768px) {
  .mode-hero-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.mode-hero-card {
  position: relative;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-hero-card:hover {
  border-color: #475569;
  background: #151e2b;
  transform: translateY(-1px);
}

.mode-hero-card.active-teal {
  border-color: rgba(45, 212, 191, 0.72);
  border-left: 4px solid #2dd4bf;
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.15) 0%, rgba(17, 24, 34, 0.96) 72%);
  box-shadow: 0 6px 20px rgba(45, 212, 191, 0.14);
}

.mode-hero-card.active-gold {
  border-color: rgba(251, 191, 36, 0.72);
  border-left: 4px solid #fbbf24;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.15) 0%, rgba(17, 24, 34, 0.96) 72%);
  box-shadow: 0 6px 20px rgba(251, 191, 36, 0.14);
}

/* Session Status Banner for Realtime Mode */
.session-banner {
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.session-banner-prev {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.16) 0%, rgba(251, 191, 36, 0.05) 100%);
  border: 1px solid rgba(251, 191, 36, 0.55);
  border-left: 4px solid #fbbf24;
}

.session-banner-closed {
  background: linear-gradient(90deg, rgba(45, 212, 191, 0.14) 0%, rgba(45, 212, 191, 0.04) 100%);
  border: 1px solid rgba(45, 212, 191, 0.5);
  border-left: 4px solid #2dd4bf;
}

.session-banner-live {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.18) 0%, rgba(16, 185, 129, 0.05) 100%);
  border: 1px solid rgba(16, 185, 129, 0.58);
  border-left: 4px solid #10b981;
}

/* 2x2 Quadrant Rotation Matrix */
.quadrant-matrix-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#pm-quadrant-matrix {
  height: 460px;
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

#pm-quadrant-matrix .quadrant-cell {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

#pm-quadrant-matrix .quadrant-cell-list {
  flex: 1;
  min-height: 0;
  max-height: none;
}

@media (max-width: 640px) {
  .quadrant-matrix-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  #pm-quadrant-matrix {
    height: auto;
    grid-template-rows: none;
  }
  #pm-quadrant-matrix .quadrant-cell {
    height: auto;
    min-height: 200px;
  }
  #pm-quadrant-matrix .quadrant-cell-list {
    max-height: 220px;
  }
}

.quadrant-cell {
  background: #141a25;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 240px;
}

.quadrant-cell-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}

.q-item-row {
  position: relative;
  flex-shrink: 0;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 6px;
  background: rgba(11, 16, 24, 0.55);
  border: 1px solid rgba(38, 50, 68, 0.6);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
}

.q-item-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  opacity: 0.13;
}
