:root {
  /* Premium Dark Theme Palette */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-primary: #3b82f6;
  /* Blue */
  --accent-hover: #2563eb;
  --success: #10b981;
  /* Green */
  --warning: #f59e0b;
  /* Amber/Orange */
  --danger: #ef4444;
  /* Red */
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

  /* Spacing */
  --space-xs: 0.4rem;
  --space-sm: 0.75rem;
  --space-md: 1.25rem;
  --space-lg: 2rem;
  --space-xl: 2rem;

  /* Transitions */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;

  --font-size-base: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

@media (max-width: 600px) {
  :root {
    --font-size-base: 16px;
    --space-md: 0.5rem; /* Narrower space on mobile */
  }
  .main-content {
    padding: 0 0 100px 0 !important; /* [FIX] Keep bottom spacing on mobile to avoid overlap with bottom-nav */
  }
  .card {
    border-radius: 4px !important;
    border-left: none !important;
    border-right: none !important;
  }
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  /* Prioritize English-friendly UI fonts, and fallback to system fonts */
  font-family: 'Roboto', 'Inter', 'Segoe UI', Arial, sans-serif;
  font-size: var(--font-size-base);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* Ensure numbers take up consistent horizontal space (tabular nums) */
  font-variant-numeric: tabular-nums;
}

/* Base Layout */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Header */
.app-header {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  padding: var(--space-md);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

/* Emergency Stop Button - Prominent */
.btn-emergency {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-weight: 700;
  padding: var(--space-sm) var(--space-md);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: pulse-red 2s infinite;
}

.btn-emergency:hover {
  background: var(--danger);
  color: white;
}

@keyframes pulse-red {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

/* Main Content */
.main-content {
  flex: 1;
  padding: var(--space-md);
  max-width: 1800px;
  /* Increased for Big Screen */
  width: 100%;
  margin: 0 auto;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-md);
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: var(--space-lg);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: var(--transition-normal);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.2);
}

.strategy-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: var(--transition-fast);
}

.strategy-card:hover {
  border-color: var(--accent-primary);
}

.strategy-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.strategy-actions {
  display: flex !important; /* Force flex for control over gaps */
  gap: 0.3rem !important;
  margin-top: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.strategy-actions .btn {
  flex: 1;
  min-width: 0; /* Allow buttons to shrink */
  padding: 8px 2px !important;
  font-size: 0.7rem !important;
}

.strategy-actions .btn span:last-child {
  display: block;
  margin-top: 2px;
}


.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: var(--space-sm);
}

.card-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}


/* Data Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: var(--space-sm);
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.9rem;
}

.data-table th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.data-table tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.03);
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Status Badges */
.badge {
  padding: 0.3em 0.8em;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}


.badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.badge-neutral {
  background: rgba(157, 168, 182, 0.2);
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
  font-size: 0.9rem;
  white-space: nowrap;
  outline: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #323842;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: 6px;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  min-height: 44px;
}

.btn-xs {
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  min-height: 38px;
  border-radius: 6px;
}



/* Horizontal Market List */
#market-horizontal-list::-webkit-scrollbar {
  display: none;
}

#market-horizontal-list {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#market-horizontal-list .btn-secondary {
  flex-shrink: 0;
  border: 1px solid var(--glass-border);
}

/* Bottom Nav handled below */

/* Modal Container - hidden by default */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-normal);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Icon Buttons for tables */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: var(--transition-fast);
  font-size: 0.9rem;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

.btn-icon:active {
  transform: scale(0.9);
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: var(--space-lg);
  width: 90%;
  max-width: 500px;
  transform: translateY(20px);
  transition: transform var(--transition-fast);
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 2rem;
  margin-bottom: calc(60px + 1rem);
  /* Avoid overlapping bottom nav */
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

/* Form Elements */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  margin-bottom: var(--space-xs);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem;
  background: var(--bg-primary);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  transition: var(--transition-fast);
}

.form-control:focus {
  border-color: var(--accent-primary);
  outline: none;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Responsive Adjustments */
.main-content {
  padding-bottom: 95px;
}

/* Support bottom nav on all screens */

@media (max-width: 768px) {
  .card {
    padding: var(--space-md);
  }
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 65px;
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: stretch;
  z-index: 1000;
  /* Ensure it stays on top */
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.75rem;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  transition: var(--transition-fast);
  padding: 0.25rem 0;
  min-height: 100%;
}

.nav-item .nav-icon {
  font-size: 1.3rem;
}

.nav-item.active,
.nav-item:hover {
  color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.05);
}

/* Emergency button in bottom nav */
.btn-emergency-nav {
  flex: 1;
  background: rgba(239, 68, 68, 0.12) !important;
  color: var(--danger) !important;
  border-left: 1px solid rgba(239, 68, 68, 0.3);
  animation: pulse-red 2s infinite;
}

.btn-emergency-nav:hover {
  background: rgba(239, 68, 68, 0.3) !important;
}

/* Home View & Market Depth Styles */
#home-bid-table-body td,
#home-ask-table-body td {
  padding: 0.4rem 4px;
  border: none;
}

#home-bid-table-body tr:nth-child(odd),
#home-ask-table-body tr:nth-child(odd) {
  background: #05080f;
}

#home-bid-table-body tr:nth-child(even),
#home-ask-table-body tr:nth-child(even) {
  background: rgba(10, 46, 92, 0.50);
}

.broker-item {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px 2px;
  border-radius: 4px;
  margin: 1px 0;
}

.broker-pos {
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.1;
}

.broker-pos-bid {
  color: var(--success);
}

.broker-pos-ask {
  color: var(--danger);
}

.broker-id {
  font-size: 0.72rem;
  font-family: monospace;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.broker-name {
  font-size: 1.1rem;
  /* Slightly smaller for better fit */
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 2px;
  flex: 1;
  /* Allow name to take available space */
  min-width: 0;
  /* Allow name to shrink/truncate */
}

/* Panic Button Styling */
.btn-emergency {
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-emergency:hover {
  background: rgba(239, 68, 68, 0.25) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}

.btn-emergency:active {
  transform: translateY(0);
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #0f172a;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.login-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.login-card {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.login-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: #f8fafc;
}

.login-subtitle {
  color: #94a3b8;
  font-size: 0.85rem;
  margin-bottom: 2rem;
}

.login-btn {
  width: 100%;
  padding: 0.8rem;
  font-size: 1rem;
  background: #3b82f6;
  color: white;
  border-radius: 8px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}

/* Vertical Wheel Picker Styles ("上下去搓") */
.wheel-picker-wrapper {
  margin-top: 0.5rem;
}

/* Modal Overlay for Wheel Picker */
.wheel-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 3000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.wheel-modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.wheel-bottom-sheet {
  width: 100%;
  max-width: 500px;
  background: var(--bg-secondary);
  border-radius: 16px 16px 0 0;
  padding: 1rem;
  padding-bottom: env(safe-area-inset-bottom, 1.5rem);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.wheel-modal-overlay.open .wheel-bottom-sheet {
  transform: translateY(0);
}

.wheel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
}

.wheel-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.wheel-confirm {
  color: var(--accent-primary);
  font-weight: bold;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.wheel-cancel {
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.wheel-container {
  position: relative;
  width: 100%;
  height: 120px;
  background: var(--bg-primary);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.wheel-container::before,
.wheel-container::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 40px;
  z-index: 5;
  pointer-events: none;
}

.wheel-container::before {
  top: 0;
  background: linear-gradient(to bottom, var(--bg-secondary) 0%, rgba(30, 41, 59, 0) 100%);
}

.wheel-container::after {
  bottom: 0;
  background: linear-gradient(to top, var(--bg-secondary) 0%, rgba(30, 41, 59, 0) 100%);
}

.wheel-scroller {
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 40px 0;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.wheel-scroller::-webkit-scrollbar {
  display: none;
}

.wheel-item {
  height: 40px;
  line-height: 40px;
  text-align: center;
  scroll-snap-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  color: var(--text-secondary);
  opacity: 0.5;
  transition: all 0.2s;
  cursor: pointer;
  flex-shrink: 0;
  width: 100%;
}

.wheel-item.active {
  color: var(--accent-primary);
  opacity: 1;
  font-size: 1.3rem;
  font-weight: 800;
  text-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.wheel-center-mask {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 95%;
  height: 40px;
  border-top: 1px solid rgba(59, 130, 246, 0.2);
  border-bottom: 1px solid rgba(59, 130, 246, 0.2);
  background: rgba(59, 130, 246, 0.05);
  pointer-events: none;
  z-index: 2;
  border-radius: 4px;
}

/* --- Tab Navigation --- */
.tab-header {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--glass-border);
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 700;
  padding: 1rem;
  cursor: pointer;
  transition: var(--transition-fast);
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.tab-btn.active {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

/* --- Responsive Grid Utilities --- */
.grid {
  display: grid;
}

.grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.gap-4 {
  gap: 1rem;
}

.gap-6 {
  gap: 1.5rem;
}

@media (min-width: 600px) {
  .md\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (min-width: 800px) {
  .lg\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
  }

  .lg\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .lg\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .lg\:col-span-2 {
    grid-column: span 3 / span 3 !important;
  }
}

@media (min-width: 1200px) {
  .xl\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .xl\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .xl\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .xl\:col-span-1 {
    grid-column: span 1 / span 1 !important;
  }

  .xl\:col-span-2 {
    grid-column: span 2 / span 2 !important;
  }

  .xl\:col-span-3 {
    grid-column: span 3 / span 3 !important;
  }
}