/* ==========================================================================
   TDX Light Mode Financial Web Application Stylesheet
   Designed for desktop-like dense financial presentation, light theme,
   extensible modular views, pure keyboard navigation, and drawer menu.
   ========================================================================== */

:root {
  --bg-app: #f1f5f9;
  --bg-panel: #ffffff;
  --bg-header: #f8fafc;
  --bg-hover: #f1f5f9;
  --bg-selected: #e0e7ff;
  --bg-selected-border: #4f46e5;
  
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;
  
  /* Chinese standard: Red for Up, Green for Down */
  --color-up: #dc2626;
  --color-up-bg: #fee2e2;
  --color-down: #16a34a;
  --color-down-bg: #dcfce7;
  --color-flat: #64748b;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
  --font-mono: "JetBrains Mono", Consolas, "SF Mono", Monaco, "Courier New", monospace;
}

/* Color Reversed (International standard: Green for Up, Red for Down) */
body.color-reversed {
  --color-up: #16a34a;
  --color-up-bg: #dcfce7;
  --color-down: #dc2626;
  --color-down-bg: #fee2e2;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: var(--font-family);
  background-color: var(--bg-panel);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

/* ==========================================================================
   App Shell & Floating Hamburger Button
   ========================================================================== */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.btn-hamburger.floating-hamburger {
  position: fixed;
  top: 4px;
  left: 6px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3.5px;
  width: 28px;
  height: 28px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.15s ease;
}

.btn-hamburger.floating-hamburger:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.btn-hamburger.floating-hamburger span {
  display: block;
  width: 15px;
  height: 2px;
  background-color: var(--text-main);
  border-radius: 1px;
  transition: transform 0.2s;
}

/* ==========================================================================
   Main Content Views
   ========================================================================== */
.main-viewport {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-panel);
}

.view-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.view-container.active {
  display: flex;
}

/* Rise / Fall Color Utilities */
.color-up {
  color: var(--color-up) !important;
}

.color-down {
  color: var(--color-down) !important;
}

.color-flat {
  color: var(--color-flat) !important;
}

.badge-up {
  background-color: var(--color-up-bg);
  color: var(--color-up);
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
}

.badge-down {
  background-color: var(--color-down-bg);
  color: var(--color-down);
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
}

.kbd-badge {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--text-main);
  font-weight: 600;
}

/* ==========================================================================
   View 1: Watchlist Table (.2) - 100% Height Pure Table
   ========================================================================== */
#view-watchlist .table-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
}

.tdx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: right;
}

.tdx-table th {
  position: sticky;
  top: 0;
  background-color: #f1f5f9;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  z-index: 10;
}

.tdx-table th:first-child,
.tdx-table td:first-child {
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}

.tdx-table th:nth-child(2),
.tdx-table td:nth-child(2),
.tdx-table th:nth-child(3),
.tdx-table td:nth-child(3) {
  text-align: left;
}

.tdx-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.tdx-table tr {
  cursor: pointer;
  transition: background-color 0.08s;
}

.tdx-table tr:hover {
  background-color: #f8fafc;
}

.tdx-table tr.selected {
  background-color: var(--bg-selected) !important;
  box-shadow: inset 3px 0 0 var(--bg-selected-border);
  font-weight: 600;
}

.stock-symbol {
  font-weight: 700;
  color: var(--primary);
  font-family: var(--font-mono);
}

.stock-name {
  font-family: var(--font-family);
  font-weight: 500;
}

.exchange-pill {
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 2px;
  background: #e2e8f0;
  color: #475569;
  margin-left: 4px;
}

/* ==========================================================================
   View 2: Pure K-Line Chart (.3)
   ========================================================================== */
.kline-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 6px 42px; /* Leave space on left for floating hamburger button */
  background-color: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
  min-height: 38px;
}

.kline-stock-summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.kline-stock-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.kline-stock-symbol {
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.kline-price-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-mono);
}

.kline-current-price {
  font-size: 18px;
  font-weight: 700;
}

.kline-change-pct {
  font-size: 13px;
  font-weight: 600;
}

.kline-period-toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  background: #e2e8f0;
  padding: 2px;
  border-radius: 4px;
}

.btn-period {
  padding: 3px 8px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}

.btn-period:hover {
  color: var(--text-main);
}

.btn-period.active {
  background: var(--bg-panel);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.kline-chart-viewport {
  flex: 1;
  position: relative;
  width: 100%;
  height: calc(100% - 38px);
  background-color: #ffffff;
  overflow: hidden;
}

#kline-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.kline-tooltip {
  position: absolute;
  top: 10px;
  left: 16px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  gap: 12px;
  z-index: 15;
}

/* ==========================================================================
   View 3: Debug Diagnostics (10)
   ========================================================================== */
.debug-view-container {
  padding: 16px 16px 16px 42px; /* Leave space on left for hamburger button */
  overflow-y: auto;
  gap: 16px;
  height: 100%;
  background: #f8fafc;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.debug-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.debug-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.debug-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.debug-info-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.debug-info-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--border-subtle);
  padding-bottom: 4px;
}

.debug-info-label {
  color: var(--text-secondary);
}

.debug-info-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-main);
}

.key-stream-box {
  background: #0f172a;
  color: #38bdf8;
  padding: 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  min-height: 80px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}

.telemetry-table-container {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 14px;
  flex: 1;
}

.telemetry-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 8px;
  font-family: var(--font-mono);
}

.telemetry-table th {
  text-align: left;
  background: #f1f5f9;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-color);
}

.telemetry-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

/* ==========================================================================
   TDX Keyboard Wizard (键盘精灵)
   ========================================================================== */
.keyboard-wizard-modal {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 280px;
  background: #ffffff;
  border: 2px solid var(--primary);
  border-radius: 6px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  z-index: 100;
  display: none;
  overflow: hidden;
  animation: wizardPop 0.15s ease-out;
}

@keyframes wizardPop {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.keyboard-wizard-modal.active {
  display: block;
}

.wizard-header {
  background: var(--primary);
  color: #ffffff;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wizard-input-box {
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
}

.wizard-matches-list {
  max-height: 160px;
  overflow-y: auto;
  list-style: none;
}

.wizard-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 12px;
}

.wizard-item:hover, .wizard-item.selected {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.wizard-footer {
  padding: 4px 10px;
  background: #f1f5f9;
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
}

/* ==========================================================================
   Hamburger Side Drawer (侧边抽屉)
   ========================================================================== */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100vh;
  background: #ffffff;
  box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  z-index: 95;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-header);
}

.drawer-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.btn-close-drawer {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.drawer-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.drawer-nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drawer-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s;
}

.drawer-nav-item:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.drawer-nav-item.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.drawer-nav-item.active .kbd-badge {
  background: rgba(255,255,255,0.2);
  color: #ffffff;
  border-color: transparent;
}

.drawer-nav-item.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f8fafc;
  border-style: dashed;
}

.drawer-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-select {
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 12px;
  outline: none;
  background: #ffffff;
}

.drawer-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}
