:root {
  --bg-dark: #0b0f19;
  --panel-bg: rgba(17, 24, 39, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-purple: #8b5cf6;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(at 0% 0%, rgba(6, 182, 212, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.08) 0px, transparent 50%);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  padding-bottom: 2rem;
}

/* Glass Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 2rem;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 1.8rem;
  color: var(--accent-cyan);
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo-text h1 span {
  color: var(--accent-cyan);
}

.logo-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.status-pill {
  padding: 0.45rem 0.95rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
}

.clickable-pill {
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.clickable-pill:hover {
  transform: translateY(-1px);
  filter: brightness(1.2);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
}

.mode-paper {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.mode-live {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Wallet Connection Indicator Light (Bombillito) */
.wallet-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  transition: all 0.3s ease;
}

.wallet-status-badge.hidden {
  display: none !important;
}

.status-indicator-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  transition: all 0.3s ease;
}

.status-indicator-dot.connected {
  background-color: #10b981;
  box-shadow: 0 0 10px #10b981, 0 0 18px rgba(16, 185, 129, 0.6);
  animation: pulse-dot-green 2s infinite;
}

.status-indicator-dot.disconnected {
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
  animation: pulse-dot-red 1.5s infinite;
}

.status-indicator-dot.warning {
  background-color: #f59e0b;
  box-shadow: 0 0 10px #f59e0b;
  animation: pulse-dot-amber 2s infinite;
}

@keyframes pulse-dot-green {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes pulse-dot-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

@keyframes pulse-dot-amber {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.engine-control,
.strategy-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Custom Select & Buttons */
.custom-select {
  background: #1f2937;
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.btn {
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.btn-success {
  background: #059669;
  color: white;
}

.btn-success:hover {
  background: #10b981;
}

.btn-paused {
  background: #d97706;
  color: white;
}

.btn-danger {
  background: #dc2626;
  color: white;
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.4);
}

.btn-danger:hover {
  background: #ef4444;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Modal Overlay & Card */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: #0f172a;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  width: 90%;
  max-width: 760px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: modal-slide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-large {
  max-width: 900px;
}

.kpi-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 1rem;
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.orderbook-inspector-grid {
  display: grid;
  grid-template-columns: 1fr 160px 1fr;
  gap: 1rem;
  align-items: center;
}

.ob-column h4 {
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ob-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.ob-table th {
  padding: 0.5rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--panel-border);
  text-align: left;
}

.ob-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.asks-column td:first-child {
  color: var(--accent-red);
  font-weight: 600;
}

.bids-column td:first-child {
  color: var(--accent-emerald);
  font-weight: 600;
}

.ob-mid-summary {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
}

.mid-box span {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
}

.mid-box h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

.text-red {
  color: var(--accent-red);
}

.modal-header {
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem 1.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.config-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 1.25rem;
}

.config-section h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.span-2 {
  grid-column: span 2;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input {
  background: #1e293b;
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.2);
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-icon input {
  width: 100%;
  padding-right: 2.5rem;
}

.field-icon-btn {
  position: absolute;
  right: 0.75rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}

.form-help {
  font-size: 0.72rem;
  color: #64748b;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--panel-border);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 1100;
}

.toast {
  background: #1e293b;
  color: var(--text-main);
  border-left: 4px solid var(--accent-emerald);
  padding: 0.85rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Grid Layout */
.dashboard-grid {
  padding: 2rem;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* KPI Row */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.kpi-card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  padding: 1.4rem;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 1.2rem;

  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.icon-cyan {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
}

.icon-emerald {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.icon-purple {
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-purple);
}

.icon-amber {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.kpi-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-content h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0.1rem 0;
  font-family: var(--font-mono);
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.positive-text {
  color: var(--accent-emerald);
}

.negative-text {
  color: var(--accent-red);
}

.text-amber {
  color: var(--accent-amber);
}

.text-emerald {
  color: var(--accent-emerald);
}

.text-cyan {
  color: var(--accent-cyan);
}

.text-purple {
  color: var(--accent-purple);
}

/* Panels & Tables */
.content-row {
  display: flex;
  gap: 1.5rem;
  align-items: stretch;
}

.panel-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.flex-1 {
  flex: 1;
}

.flex-2 {
  flex: 2;
}

.flex-grow {
  flex-grow: 1;
}

.panel-card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
}

.panel-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.table-container {
  overflow-x: auto;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.custom-table th {
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--panel-border);
}

.custom-table td {
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.custom-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.font-mono {
  font-family: var(--font-mono);
}

.price-pill {
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.82rem;
}

.pill-yes {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.pill-no {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
}

.history-summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.85rem;
}

.hist-stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.hist-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.trades-container {
  max-height: 380px;
  overflow-y: auto;
}

.full-width {
  width: 100%;
}

.terminal-body {
  background: #020617;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.log-line {
  line-height: 1.4;
  word-break: break-all;
}

.log-info {
  color: #94a3b8;
}

.log-warn {
  color: #fbbf24;
  font-weight: 500;
}

.log-error {
  color: #f87171;
  font-weight: 600;
}

.log-debug {
  color: #64748b;
}

/* Console Split View Tabs */
.console-tabs {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.7);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.console-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
  position: relative;
}

.console-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.console-tab.active {
  background: #1e293b;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  border-color: rgba(6, 182, 212, 0.3);
}

.console-tab.active[data-view="errors"] {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.error-count-badge {
  background: #ef4444;
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 3px;
}

/* ============================================================
   RESPONSIVE MOBILE & TABLET DESIGN STYLES
   ============================================================ */

/* Medium Devices (Tablets, < 992px) */
@media (max-width: 992px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    padding: 1rem;
  }

  .header-left,
  .header-right {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .content-row {
    flex-direction: column;
  }

  .orderbook-inspector-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .market-overview-bar {
    grid-template-columns: repeat(2, 1fr);
  }
}



/* ============================================================ */
/* MOBILE FLOATING ACTION BAR (FAB Dock)                        */
/* ============================================================ */
.mobile-fab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  padding: 0.6rem 0.5rem calc(0.6rem + env(safe-area-inset-bottom));
  background: rgba(10, 11, 20, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(99, 102, 241, 0.3);
  gap: 0.5rem;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
  /* Hidden on desktop - shown only on mobile via media query */
  display: none;
}

.fab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  flex: 1;
  padding: 0.6rem 0.4rem;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
}

.fab-btn i {
  font-size: 1.25rem;
  margin-bottom: 0.1rem;
}

.fab-btn:active {
  transform: scale(0.94);
}

.fab-primary {
  border-color: rgba(99, 102, 241, 0.4);
  color: #a78bfa;
  background: rgba(99, 102, 241, 0.1);
}
.fab-primary:hover { background: rgba(99, 102, 241, 0.22); }

.fab-info {
  border-color: rgba(6, 182, 212, 0.4);
  color: #22d3ee;
  background: rgba(6, 182, 212, 0.1);
}
.fab-info:hover { background: rgba(6, 182, 212, 0.22); }

.fab-success {
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
  background: rgba(16, 185, 129, 0.1);
}
.fab-success:hover { background: rgba(16, 185, 129, 0.22); }

.fab-success.active-run {
  border-color: rgba(239, 68, 68, 0.5);
  color: #f87171;
  background: rgba(239, 68, 68, 0.1);
}

.fab-warning {
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.1);
}
.fab-warning:hover { background: rgba(245, 158, 11, 0.22); }

/* ============================================================ */
/* FLOATING CONSOLE MODAL (bottom sheet style on mobile)        */
/* ============================================================ */
#console-modal .modal-card {
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

#console-modal .modal-body {
  flex: 1;
  overflow: hidden;
  padding: 0.75rem;
}

#console-modal #modal-live-console {
  height: 100%;
  max-height: 55vh;
  overflow-y: auto;
}

/* ============================================================ */
/* Small Devices (Mobile Phones, < 768px)                       */
/* ============================================================ */
@media (max-width: 768px) {
  /* Show FAB dock */
  .mobile-fab-bar {
    display: flex;
  }

  /* Global overflow fix — nothing escapes the screen */
  body {
    overflow-x: hidden;
  }

  /* Add bottom padding so cards aren't behind FAB dock */
  .dashboard-grid {
    padding: 1rem 0.75rem 6rem 0.75rem;
    gap: 1rem;
    width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* Hide desktop header controls (only show logo + mode badge) */
  .header-right .btn,
  .header-right .strategy-selector,
  .header-right .engine-control {
    display: none;
  }

  /* Stack content-row vertically instead of side-by-side */
  .content-row {
    flex-direction: column;
    gap: 1rem;
  }

  /* Remove flex-grow: 2 so all panels take full width */
  .flex-2,
  .flex-1,
  .flex-grow {
    flex: none;
    width: 100%;
    min-width: 0;
  }

  /* Panel columns also stacked */
  .panel-column {
    width: 100%;
    min-width: 0;
  }

  /* All panel cards take full width and don't overflow */
  .panel-card {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  /* All tables scroll horizontally inside their container */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .custom-table {
    min-width: 420px; /* allows horizontal scroll */
  }

  /* Show terminal panel on mobile with touch-friendly layout */
  .panel-card.terminal-panel {
    display: flex !important;
    width: 100%;
    margin-top: 1rem;
    padding: 0.9rem;
    box-sizing: border-box;
  }

  .terminal-panel .panel-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .console-tabs {
    display: flex;
    width: 100%;
    gap: 2px;
    box-sizing: border-box;
  }

  .console-tab {
    flex: 1;
    justify-content: center;
    padding: 0.45rem 0.35rem;
    font-size: 0.7rem;
    text-align: center;
    white-space: nowrap;
  }

  /* Logo area compact */
  .logo-text h1 {
    font-size: 1.05rem;
  }

  /* KPI 2-column grid — use fr not minmax to prevent overflow */
  .kpi-section {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    width: 100%;
  }

  .kpi-card {
    padding: 0.9rem;
    gap: 0.65rem;
    border-radius: 12px;
    min-width: 0;
  }

  .kpi-icon {
    width: 40px;
    height: 40px;
    font-size: 1rem;
    flex-shrink: 0;
  }

  .kpi-content {
    min-width: 0;
    overflow: hidden;
  }

  .kpi-content h2 {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-title {
    font-size: 0.68rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-subtitle {
    font-size: 0.65rem;
  }

  .panel-header h3 {
    font-size: 0.88rem;
  }

  /* Modals full width on mobile */
  .modal-card {
    width: 97%;
    max-height: 92vh;
    border-radius: 14px;
  }

  .modal-header {
    padding: 1rem;
  }

  .modal-body {
    padding: 1rem;
    gap: 1rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .modal-footer {
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  .modal-footer .btn {
    width: 100%;
  }

  .history-summary-bar {
    padding: 0.5rem;
    font-size: 0.75rem;
  }

  .terminal-body {
    max-height: 320px;
    font-size: 0.72rem;
    padding: 0.75rem;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 5rem; /* above FAB bar */
  }

  .toast {
    font-size: 0.8rem;
    padding: 0.75rem 1rem;
  }

  /* Market overview compact */
  .market-overview-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Header overflow fix on mobile */
  .app-header {
    padding: 0.85rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    overflow: hidden;
  }

  .header-left {
    gap: 0.6rem;
    min-width: 0;
    flex-wrap: wrap;
  }

  /* Bot ID badge compact */
  #badge-bot-id {
    font-size: 0.68rem;
    padding: 0.25rem 0.5rem;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Panel card padding reset for mobile */
  .panel-card {
    padding: 1rem 0.85rem;
  }

  /* Full-width panel */
  .panel-card.full-width {
    width: 100%;
  }

  /* Trades container scrollable */
  .trades-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .compact-table {
    min-width: 360px;
  }
}

/* Extra Small Devices (< 480px) */
@media (max-width: 480px) {
  .kpi-section {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-content h2 {
    font-size: 1.05rem;
  }
}