/* ==========================================================================
   Financial Terminal Design System - Dark Bloomberg Mode
   Optimized for Desktop (Mac) & Tablet (iPad Air / Pro Landscape)
   ========================================================================== */

:root {
  --bg-primary: #080c14;
  --bg-secondary: #0f172a;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(30, 41, 59, 0.95);
  --bg-input: #1e293b;
  --border-subtle: #1e293b;
  --border-focus: #3b82f6;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-blue: #2563eb;
  --accent-cyan: #06b6d4;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;

  /* Financial Colors (International Default: Green Up, Red Down) */
  --color-up: #10b981;
  --color-up-bg: rgba(16, 185, 129, 0.12);
  --color-down: #ef4444;
  --color-down-bg: rgba(239, 68, 68, 0.12);
  --color-neutral: #94a3b8;

  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --header-height: 56px;
  --barometer-height: 40px;
  --sidebar-width: 380px;
  --border-radius: 10px;
}

/* Red-Up/Green-Down Color Mode Toggle */
body.palette-cn {
  --color-up: #ef4444;
  --color-up-bg: rgba(239, 68, 68, 0.12);
  --color-down: #10b981;
  --color-down-bg: rgba(16, 185, 129, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Header Bar
   ========================================================================== */
.terminal-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.brand-badge {
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #fff;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* Tab Navigation */
.nav-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px;
  border-radius: 8px;
  gap: 4px;
  border: 1px solid var(--border-subtle);
}

.nav-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.nav-tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab-btn.active {
  color: #ffffff;
  background: var(--accent-blue);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.market-status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.active {
  background: var(--color-up);
  box-shadow: 0 0 8px var(--color-up);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* ==========================================================================
   Macro Barometer Ribbon
   ========================================================================== */
.macro-ribbon {
  height: var(--barometer-height);
  background: #0b1120;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 18px;
  flex-shrink: 0;
}

.macro-ribbon::-webkit-scrollbar {
  display: none;
}

.macro-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
}

.macro-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.macro-item .name {
  color: var(--text-muted);
  font-weight: 600;
}

.macro-item .val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

.macro-item .chg {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
}

.chg.up {
  color: var(--color-up);
}

.chg.down {
  color: var(--color-down);
}

/* ==========================================================================
   Terminal Main Workspace (Split Grid)
   ========================================================================== */
.terminal-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.view-container {
  display: none;
  width: 100%;
  height: 100%;
}

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

/* Left / Main Chart Area */
.main-chart-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle);
  overflow: hidden;
  background: #000000;
}

.chart-toolbar {
  height: 44px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}

.active-ticker-info {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.active-ticker-title {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #ffffff;
}

.active-ticker-name {
  font-size: 12px;
  color: var(--text-muted);
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-toggle-group {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}

.pill-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.chart-frame-wrapper {
  flex: 1;
  width: 100%;
  position: relative;
}

.chart-frame-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Bottom Feature Drawer (Foreign Flow / Valuation Strip) */
.feature-drawer {
  height: 170px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.drawer-header {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.drawer-body {
  flex: 1;
  display: flex;
  padding: 10px 14px;
  gap: 16px;
  overflow-x: auto;
}

/* Foreign Flow Barometer Component */
.flow-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius);
  padding: 10px 14px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.flow-title {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.flow-amount {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  margin: 6px 0;
}

.flow-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 48px;
  padding-top: 4px;
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.flow-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.flow-bar {
  width: 100%;
  border-radius: 2px;
  min-height: 4px;
}

.flow-bar.positive {
  background: var(--color-up);
}

.flow-bar.negative {
  background: var(--color-down);
}

.flow-bar-day {
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ==========================================================================
   Right Sidebar: Watchlist & Multi-Asset Monitor
   ========================================================================== */
.terminal-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

/* Quick Add / Search Input */
.search-add-bar {
  display: flex;
  gap: 6px;
}

.search-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  border-radius: 6px;
  outline: none;
  text-transform: uppercase;
}

.search-input:focus {
  border-color: var(--border-focus);
}

.add-btn {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.add-btn:hover {
  opacity: 0.9;
}

/* Watchlist Items Scroll */
.watchlist-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stock-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.15s ease;
  position: relative;
}

.stock-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.stock-card.active {
  border-color: var(--accent-blue);
  background: rgba(37, 99, 235, 0.12);
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.25);
}

.stock-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.ticker-symbol {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: #ffffff;
}

.ticker-sector {
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  padding: 1px 5px;
  border-radius: 3px;
}

.stock-card-mid {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stock-name {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.stock-badge-chg {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.stock-badge-chg.up {
  color: var(--color-up);
  background: var(--color-up-bg);
}

.stock-badge-chg.down {
  color: var(--color-down);
  background: var(--color-down-bg);
}

.stock-card-bot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--text-muted);
  border-top: 1px dashed rgba(255, 255, 255, 0.05);
  padding-top: 4px;
}

.stock-card-note {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.delete-card-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: none;
  border-radius: 4px;
  width: 18px;
  height: 18px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.stock-card:hover .delete-card-btn {
  opacity: 1;
}

/* ==========================================================================
   Modal: Configuration & Export
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}

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

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
}

.modal-textarea {
  width: 100%;
  height: 240px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: #38bdf8;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 12px;
  border-radius: 6px;
  resize: vertical;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================================
   Mobile & Tablet Pro Responsive System (Auto-Fit for iPhone/iPad/Android)
   ========================================================================== */

/* Tablet Landscape (iPad Pro / Air) */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 320px;
    --header-height: 52px;
  }
}

/* Mobile Devices (iPhone / Android Phone Portrait <= 768px) */
@media (max-width: 768px) {
  :root {
    --header-height: 50px;
    --barometer-height: 36px;
  }

  body {
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom, 16px);
  }

  /* Header optimization for narrow screens */
  .terminal-header {
    padding: 0 10px;
  }

  .brand span:first-child {
    font-size: 14px;
  }

  .brand-badge {
    display: none; /* Hide for space saving */
  }

  .nav-tab-btn {
    padding: 5px 8px;
    font-size: 11px;
  }

  .market-status-pill {
    display: none; /* Auto collapse status on small screens */
  }

  .icon-btn {
    padding: 4px 6px;
    font-size: 11px;
  }

  /* Scrollable ribbon on touch screens */
  .macro-ribbon {
    padding: 0 10px;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .macro-item {
    font-size: 11px;
  }

  /* Main Workspace flows vertically */
  .terminal-workspace {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .view-container.active {
    flex-direction: column;
    height: auto;
  }

  /* Chart section on mobile */
  .main-chart-stage {
    width: 100%;
    height: 48vh;
    min-height: 320px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .chart-toolbar {
    padding: 0 10px;
    height: 38px;
  }

  .active-ticker-title {
    font-size: 14px;
  }

  .active-ticker-name {
    font-size: 10px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Bottom drawer on mobile becomes horizontally scrollable */
  .feature-drawer {
    height: auto;
    min-height: 150px;
    border-bottom: 1px solid var(--border-subtle);
  }

  .drawer-body {
    padding: 8px 10px;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .flow-card {
    min-width: 240px;
    padding: 8px 10px;
  }

  /* Sidebar becomes full width bottom watchlist */
  .terminal-sidebar {
    width: 100%;
    height: auto;
    min-height: 400px;
  }

  .sidebar-header {
    padding: 10px 12px;
  }

  .watchlist-scroll {
    max-height: none;
    overflow-y: visible;
    padding: 8px 12px 30px 12px;
  }

  .stock-card {
    padding: 12px 14px;
    touch-action: manipulation;
  }

  .stock-name {
    max-width: 220px;
  }
}

/* Mobile Landscape (Turn phone sideways for ultra-wide chart view) */
@media (max-width: 900px) and (orientation: landscape) {
  .terminal-workspace {
    flex-direction: row;
    height: calc(100vh - var(--header-height) - var(--barometer-height));
  }

  .main-chart-stage {
    flex: 1;
    height: 100%;
  }

  .terminal-sidebar {
    width: 260px;
    height: 100%;
  }

  .feature-drawer {
    display: none; /* Hide bottom drawer in landscape to maximize chart height */
  }
}

