:root {
  /* Refined Institutional Color Palette */
  --bg-main: #0a0b10;
  --bg-card: #14161f;
  --bg-elevated: #1c1e29;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-active: rgba(59, 130, 246, 0.4);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-dim: #64748b;
  
  --accent-blue: #3b82f6;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;
  --accent-indigo: #6366f1;
  
  --font-sans: 'Inter', 'Outfit', -apple-system, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --transition-smooth: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

/* Base Layout Components */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand .logo {
  font-size: 32px;
  filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.3));
}

.brand h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
}

.brand h1 span {
  color: var(--accent-blue);
  font-weight: 400;
}

/* Metrics Grid */
.metrics-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
  margin-bottom: 48px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 24px;
  transition: var(--transition-smooth);
}

.metric-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  background: var(--bg-elevated);
  transform: translateY(-2px);
}

.metric-lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 12px;
  display: block;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -1px;
}

.accent-cyan { color: var(--accent-blue); }
.accent-emerald { color: var(--accent-emerald); }
.accent-amber { color: var(--accent-amber); }

/* Timeline Bar */
.date-metrics-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 40px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.date-sub-card {
  min-width: 200px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  cursor: pointer;
}

/* City Grid */
.cities-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 40px;
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 20px;
  font-weight: 700;
}

.city-ribbon-container {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  margin-top: 16px;
  margin-bottom: 24px;
  overflow: hidden;
  max-height: 600px;
  display: flex;
  flex-direction: column;
}

.ribbon-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.cities-ribbon {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  padding-bottom: 4px;
  flex: 1;
  overflow-y: auto; /* Allow internal scrolling if needed, but hidden */
  scrollbar-width: none; 
}
.cities-ribbon::-webkit-scrollbar {
  display: none;
}

.city-chip {
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.city-chip:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--accent-blue);
}

.city-chip.selected {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.city-chip.city-held {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}

.chip-rank {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 10px;
}

.chip-wr {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
}

.full-width-display {
  width: 100%;
}

.dense-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* Market Grid */
.markets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.market-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: var(--transition-smooth);
}

.market-box:hover {
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-4px);
}

.market-box.card-buy {
  border-color: var(--accent-emerald);
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(16, 185, 129, 0.03) 100%);
}

.market-box.card-forecast {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
}

.market-box.card-current-temp {
  background: rgba(255, 255, 255, 0.14) !important;
  border-color: rgba(255, 255, 255, 0.5) !important;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

.market-box.card-purchased {
  border-color: rgba(139, 92, 246, 0.5);
  background: rgba(139, 92, 246, 0.04);
}

.badge-forecast {
  background: rgba(255, 153, 0, 0.15) !important;
  color: var(--accent-amber) !important;
  border: 1px solid rgba(255, 153, 0, 0.3) !important;
}

.badge-purchased {
  background: rgba(139, 92, 246, 0.15) !important;
  color: #a78bfa !important;
  border: 1px solid rgba(139, 92, 246, 0.3) !important;
}

.badge-buy {
  background: rgba(0, 255, 0, 0.1) !important;
  color: var(--accent-emerald) !important;
  border: 1px solid rgba(0, 255, 0, 0.25) !important;
}

.price-container {
  background: #000;
  padding: 10px 14px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.price-lbl {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
}

.price-val {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-emerald);
}

/* Badges */
.badge {
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-buy {
  background: rgba(16, 185, 129, 0.1);
  color: var(--accent-emerald);
}

.badge-purchased {
  background: rgba(245, 158, 11, 0.1);
  color: var(--accent-amber);
}

/* Modals & Terminal */
.modal-overlay {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
}

.modal-content {
  background: #11131a;
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
}

.terminal-window {
  background: #000;
  border-radius: 12px;
  padding: 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}

/* Utilities */
.view-logs-trigger {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.view-logs-trigger:hover {
  background: #252836;
  color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #2d3142; border-radius: 10px; }

.market-box:hover {
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.1);
}

/* Responsive Grid Helper */
.responsive-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Scrollable Table Container */
.table-container {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  margin-bottom: 16px;
}
.table-container::-webkit-scrollbar {
  height: 4px;
}
.table-container::-webkit-scrollbar-thumb {
  background: #2d3142;
  border-radius: 10px;
}

/* ══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE BREAKPOINTS
   ══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Strict Zero Horizontal Scroll */
  html, body {
    padding: 0 !important;
    margin: 0 !important;
    overflow-x: hidden !important;
    max-width: 100vw !important;
    width: 100% !important;
  }
  .app-container, .content {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }

  /* Viewport */
  .view-viewport {
    padding: 16px !important;
  }

  /* Top Bar */
  .top-bar {
    height: auto !important;
    padding: 12px 16px !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .view-title h2 {
    font-size: 14px !important;
  }

  .view-title .uptime {
    font-size: 9px;
  }

  .top-actions {
    display: flex;
    gap: 6px;
  }

  .top-actions .btn-primary,
  .top-actions .btn-secondary {
    padding: 6px 12px;
    font-size: 11px;
  }

  /* Metrics Grid Reflow */
  .metrics-bar {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
    margin-bottom: 24px !important;
  }

  /* Global Monitor Ribbon */
  .city-ribbon-container {
    padding: 8px 10px;
    margin-top: 8px;
    margin-bottom: 16px;
  }

  .ribbon-header {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 6px;
  }

  /* Scrollable City Ribbon without overflow */
  .cities-ribbon {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 6px !important;
    padding-bottom: 6px !important;
  }

  .city-chip {
    flex: 0 0 auto !important;
    padding: 5px 10px;
    font-size: 11px;
  }

  .bloomberg-input {
    width: 120px !important;
    font-size: 10px !important;
  }

  .bloomberg-btn {
    padding: 3px 8px;
    font-size: 9px;
  }

  /* Market Grid */
  .markets-grid,
  .dense-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .market-box {
    padding: 16px;
    gap: 12px;
    border-radius: 12px;
  }

  .price-container {
    padding: 10px;
  }

  .price-val {
    font-size: 20px !important;
  }

  /* Badges */
  .badge {
    font-size: 9px;
    padding: 3px 8px;
  }

  /* Active City Header */
  #active-city-title {
    font-size: 14px !important;
  }

  #active-city-sub {
    font-size: 10px !important;
  }

  /* Config View */
  .config-container .config-header {
    flex-direction: column;
    gap: 12px;
  }

  .cfg-row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 8px;
  }

  .cfg-input {
    min-width: 100% !important;
    text-align: left !important;
  }

  select.cfg-input {
    width: 100%;
  }

  /* Responsive Grid column reflow */
  .responsive-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Tab Ribbon Swipe Scrollable */
  .analytics-tab-ribbon {
    display: flex !important;
    gap: 8px !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    padding-bottom: 8px !important;
    border-bottom: 1px solid var(--border-color) !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }
  .analytics-tab-ribbon::-webkit-scrollbar {
    display: none !important;
  }
  .analytics-tab-ribbon .bloomberg-btn {
    flex: 0 0 auto !important;
    font-size: 10px !important;
    padding: 6px 12px !important;
  }

  /* Table column hides for mobile */
  .stability-table th:nth-child(2),
  .stability-table td:nth-child(2),
  .stability-table th:nth-child(3),
  .stability-table td:nth-child(3),
  .stability-table th:nth-child(7),
  .stability-table td:nth-child(7) {
    display: none !important;
  }

  /* Stat widgets single column on tiny screens */
  #stat-widgets {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .stat-box {
    padding: 12px;
  }

  .stat-box p {
    font-size: 20px !important;
  }

  .stat-box h4 {
    font-size: 10px !important;
  }

  /* Leaderboard Table spacing */
  .leaderboard-table {
    font-size: 11px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 6px 8px !important;
  }

  /* Logs View */
  .terminal-window {
    font-size: 10px;
    padding: 12px;
  }

  .logs-container .view-header {
    flex-direction: column !important;
    gap: 12px;
  }

  .log-controls {
    flex-wrap: wrap;
  }

  /* Date Metrics */
  .date-sub-card {
    padding: 8px;
  }

  /* Aggregate Cards */
  .agg-item {
    font-size: 11px;
  }

  /* Modal */
  .modal-content {
    width: 95% !important;
    max-width: none !important;
    border-radius: 12px;
  }

  /* Admin Operations stack */
  .admin-op-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 12px !important;
  }
  .admin-op-btn {
    width: 100% !important;
    padding: 10px !important;
    font-size: 11px !important;
    text-align: center !important;
  }
}

@media (max-width: 480px) {
  .view-viewport {
    padding: 10px !important;
  }

  .top-bar {
    padding: 8px 12px !important;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions .btn-primary,
  .top-actions .btn-secondary {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    font-size: 10px;
  }

  /* Single Column Metrics Grid */
  .metrics-bar {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Market cards full width */
  .market-box {
    padding: 12px;
  }

  /* Stat widgets single column on tiny screens */
  #stat-widgets {
    grid-template-columns: 1fr !important;
  }

  /* Ribbon chips wrap tighter */
  .city-chip {
    padding: 4px 8px;
    font-size: 10px;
  }

  .chip-rank {
    display: none;
  }

  /* Config inputs */
  .cfg-title {
    font-size: 10px;
    padding: 8px 12px;
  }

  .cfg-lbl {
    font-size: 11px;
  }

  /* Table column hides for tiny screens */
  .leaderboard-table th:nth-child(1),
  .leaderboard-table td:nth-child(1),
  .leaderboard-table th:nth-child(3),
  .leaderboard-table td:nth-child(3) {
    display: none !important;
  }

  /* Docked Bottom Drawer AI Copilot */
  .copilot-panel {
    width: 100% !important;
    height: 82vh !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
  }

  .copilot-toggle-btn {
    bottom: 16px !important;
    right: 16px !important;
    padding: 8px 14px !important;
    font-size: 10px !important;
  }
}

/* Streaming Micro-Animations */
@keyframes flashGreen {
  0% { background-color: rgba(16, 185, 129, 0.4); box-shadow: 0 0 15px rgba(16, 185, 129, 0.5); }
  100% { background-color: transparent; box-shadow: none; }
}

@keyframes flashRed {
  0% { background-color: rgba(244, 63, 94, 0.4); box-shadow: 0 0 15px rgba(244, 63, 94, 0.5); }
  100% { background-color: transparent; box-shadow: none; }
}

@keyframes slideInRight {
  0% { opacity: 0; transform: translateX(30px); }
  100% { opacity: 1; transform: translateX(0); }
}

.tick-up {
  animation: flashGreen 0.6s ease-out forwards !important;
}

.tick-down {
  animation: flashRed 0.6s ease-out forwards !important;
}

.flash-active {
  animation: flashGreen 0.8s ease-out forwards !important;
}

.slide-in-row {
  opacity: 0;
  animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

