/* SignalTrader — Clean Minimalist Dashboard
   Professional dark theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ============================================================
   1. CSS VARIABLES
   ============================================================ */

:root {
  --bg-base: #0b0e11;
  --bg-surface: #12161c;
  --bg-elevated: #1a1f2e;
  --bg-hover: #1e2435;
  --bg-input: #0f1318;

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --green: #22c55e;
  --green-dim: #166534;
  --green-bg: rgba(34, 197, 94, 0.08);
  --red: #ef4444;
  --red-dim: #991b1b;
  --red-bg: rgba(239, 68, 68, 0.08);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.08);
  --cyan: #06b6d4;
  --orange: #f59e0b;
  --orange-bg: rgba(245, 158, 11, 0.08);
  --purple: #a855f7;
  --yellow: #eab308;

  --profit: var(--green);
  --loss: var(--red);

  --border: #1e293b;
  --border-hover: #334155;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --sidebar-width: 220px;
  --sidebar-collapsed-width: 56px;
  --topbar-height: 52px;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;

  --transition: 0.15s ease;
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--text-primary); }

/* ============================================================
   3. LAYOUT — Sidebar + Main
   ============================================================ */

.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--transition);
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.brand-icon {
  width: 22px; height: 22px;
  color: var(--green);
  flex-shrink: 0;
}

.brand-text {
  font-weight: 600;
  font-size: 0.93rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.sidebar-instance-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.nav-item svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  stroke-width: 1.5;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--bg-elevated);
  color: var(--green);
}

.nav-item.active svg { color: var(--green); }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 4px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-red { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot-yellow { background: var(--orange); box-shadow: 0 0 6px var(--orange); }

.status-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Sidebar app info footer */
.sidebar-info {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar-info-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.sidebar-info-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
}
.sidebar-info-sep {
  font-size: 0.55rem;
  color: var(--border);
}
.sidebar-info-uptime {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.7;
  font-family: var(--font-mono);
}

/* Collapsed sidebar */
.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
.sidebar-collapsed .brand-text,
.sidebar-collapsed .sidebar-instance-name,
.sidebar-collapsed .nav-item span,
.sidebar-collapsed .status-label,
.sidebar-collapsed .sidebar-footer { display: none; }
.sidebar-collapsed .sidebar-footer { padding: 8px; align-items: center; }
.sidebar-collapsed .sidebar-nav { padding: 8px 4px; }
.sidebar-collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed-width); }

/* Sidebar overlay (mobile only) */
.sidebar-overlay { display: none; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ============================================================
   4. TOP BAR
   ============================================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: var(--radius-sm);
}

.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar-toggle svg { width: 18px; height: 18px; }

.page-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.topbar-stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.topbar-stat-value {
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.topbar-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
  letter-spacing: 0.08em;
}

/* Topbar divider */
.topbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.badge-warn {
  background: var(--orange-bg);
  color: var(--orange);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-live {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

/* ============================================================
   5. PAGE CONTENT
   ============================================================ */

.page-content {
  padding: 24px;
  max-width: 1400px;
}

/* ============================================================
   6. CARDS
   ============================================================ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-body { padding: 18px; }
.card-body-tight { padding: 0; }

/* Metric cards */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.metric-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.2;
}

.metric-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ============================================================
   7. TABLES
   ============================================================ */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

td.mono {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* ============================================================
   8. BADGES & PILLS
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-muted { background: rgba(100, 116, 139, 0.1); color: var(--text-muted); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ============================================================
   9. BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.btn:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.btn-sm { padding: 4px 10px; font-size: 0.72rem; }

.btn-primary {
  background: var(--green);
  color: #000;
  border-color: var(--green);
  font-weight: 600;
}
.btn-primary:hover { background: #16a34a; border-color: #16a34a; }

.btn-success {
  background: var(--green);
  color: #000;
  border-color: var(--green);
  font-weight: 600;
}
.btn-success:hover { background: #16a34a; border-color: #16a34a; }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ============================================================
   10. FORMS
   ============================================================ */

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  transition: border-color var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.form-textarea {
  min-height: 200px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
}

.form-hint {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.form-input[readonly] {
  opacity: 0.7;
  cursor: default;
}

select.form-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-label input[type="checkbox"] {
  margin-right: 6px;
  accent-color: var(--blue);
  vertical-align: middle;
}

details summary {
  list-style: none;
  user-select: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: '+ ';
  color: var(--text-muted);
}
details[open] summary::before {
  content: '- ';
}

code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--cyan);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
}

.toggle input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-hover);
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.toggle input:checked + .toggle-track {
  background: var(--green-dim);
  border-color: var(--green);
}

.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle input:checked ~ .toggle-thumb {
  left: 19px;
  background: var(--green);
}

/* ============================================================
   11. GRIDS & LAYOUT HELPERS
   ============================================================ */

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }

.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.w-full { width: 100%; }

/* ============================================================
   12. TEXT UTILITIES
   ============================================================ */

.text-green { color: var(--green) !important; }
.text-red { color: var(--red) !important; }
.text-blue { color: var(--blue) !important; }
.text-orange { color: var(--orange) !important; }
.text-purple { color: var(--purple) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.font-mono { font-family: var(--font-mono); }
.font-sm { font-size: 0.78rem; }
.font-xs { font-size: 0.7rem; }
.font-lg { font-size: 1.1rem; }
.font-bold { font-weight: 600; }

/* PnL coloring */
.pnl-positive { color: var(--green) !important; }
.pnl-negative { color: var(--red) !important; }
.pnl-neutral { color: var(--text-muted) !important; }

/* ============================================================
   13. CHART CONTAINERS
   ============================================================ */

.chart-container {
  position: relative;
  height: 240px;
  width: 100%;
}

.chart-container canvas {
  cursor: crosshair;
}

.chart-container-lg {
  position: relative;
  height: 340px;
  width: 100%;
}

.chart-container-lg canvas {
  cursor: crosshair;
}

/* ============================================================
   14. TABS
   ============================================================ */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  padding: 8px 16px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-sans);
}

.tab:hover { color: var(--text-secondary); }
.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--green);
}

/* ============================================================
   15. LOG VIEWER
   ============================================================ */

.log-viewer {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: 600px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.7;
}

.log-line { white-space: pre-wrap; word-break: break-all; }
.log-ts { color: var(--text-muted); }
.log-debug { color: var(--text-muted); }
.log-info { color: var(--text-secondary); }
.log-warning { color: var(--orange); }
.log-error { color: var(--red); }
.log-critical { color: var(--red); font-weight: 600; }

/* ============================================================
   16. PAGINATION
   ============================================================ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
}

.pagination a, .pagination span {
  padding: 6px 10px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
}

.pagination a:hover { background: var(--bg-hover); color: var(--text-primary); }
.pagination .active { background: var(--bg-elevated); color: var(--text-primary); font-weight: 600; }
.pagination .disabled { color: var(--text-muted); pointer-events: none; }

/* ============================================================
   17. TOAST NOTIFICATIONS
   ============================================================ */

#toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  animation: slideIn 0.2s ease;
  border-left: 3px solid var(--blue);
}

.toast-signal { border-left-color: var(--green); }
.toast-error { border-left-color: var(--red); }
.toast-title { font-size: 0.75rem; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.toast-body { font-size: 0.72rem; color: var(--text-secondary); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   18. MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 90%;
}

.modal-box h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.modal-box p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============================================================
   19. FLASH MESSAGES
   ============================================================ */

.flash-container {
  padding: 12px 24px 0;
}

.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  animation: slideIn 0.2s ease;
}

.flash-info { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(59,130,246,0.2); }
.flash-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34,197,94,0.2); }
.flash-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.flash-warning { background: var(--orange-bg); color: var(--orange); border: 1px solid rgba(245,158,11,0.2); }
.flash-close { background: none; border: none; color: inherit; cursor: pointer; font-size: 1.1rem; opacity: 0.7; }

/* ============================================================
   20. POSITION-SPECIFIC
   ============================================================ */

.position-pair {
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.dca-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dca-clickable {
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.15s ease;
}
.dca-clickable:hover {
  background: var(--bg-hover);
}
.dca-expand-icon {
  font-size: 0.55rem;
  color: var(--text-muted);
  margin-left: 2px;
  transition: transform 0.2s ease;
}
.dca-expanded .dca-expand-icon {
  color: var(--blue);
}

.dca-legs-row td {
  border-top: none !important;
}

.dca-legs-container table {
  margin: 0;
  font-size: 0.75rem;
}
.dca-legs-container th,
.dca-legs-container td {
  padding: 4px 8px !important;
}

.dca-bar-track {
  flex: 1;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}

.dca-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.dca-bar-label {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
}

/* ============================================================
   21. EMPTY STATES
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 40px; height: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.85rem;
}

/* ============================================================
   22. SCROLLBAR
   ============================================================ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ============================================================
   23. ANIMATIONS
   ============================================================ */

.flash-green {
  animation: flashGreen 0.5s ease;
}

.flash-red {
  animation: flashRed 0.5s ease;
}

@keyframes flashGreen {
  0%, 100% { color: inherit; }
  50% { color: var(--green); }
}

@keyframes flashRed {
  0%, 100% { color: inherit; }
  50% { color: var(--red); }
}

/* ============================================================
   24. RESPONSIVE
   ============================================================ */

/* Tablet */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .topbar-stat:nth-child(n+3) { display: none; }
  .topbar-divider { display: none; }
  .settings-grid { grid-template-columns: 160px 1fr; }
}

/* Mobile */
@media (max-width: 768px) {
  /* Sidebar: off-screen by default, slide in on toggle */
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-overlay {
    display: block;
  }
  .main-content { margin-left: 0 !important; }

  /* Grid layouts stack to single column */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }

  /* Reduce padding */
  .page-content { padding: 12px; }
  .topbar { padding: 0 12px; }
  .card-body { padding: 12px; }
  .card-header { padding: 10px 12px; }

  /* Settings page: stack nav above panel */
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav {
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
  }
  .settings-nav-item { padding: 6px 10px; font-size: 0.72rem; }
  .settings-panel { padding: 16px; }

  /* Table cells compact */
  thead th, tbody td { padding: 8px 10px; font-size: 0.75rem; }
  .hide-mobile { display: none !important; }

  /* All tables must scroll horizontally on mobile */
  .card-body-tight { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Topbar compact — only show balance on mobile */
  .topbar { gap: 8px; }
  .topbar-right { gap: 8px; flex-shrink: 1; min-width: 0; }
  .topbar-stat-label { font-size: 0.6rem; }
  .topbar-stat-value { font-size: 0.72rem; }
  .page-title { font-size: 0.85rem; white-space: nowrap; }

  /* BTC ticker: show only price, hide 24h change */
  #btc-ticker { gap: 10px !important; }
  #btc-ticker .topbar-stat:nth-child(n+2) { display: none; }
  .topbar-divider { display: none; }

  /* Topbar stats: show balance only on mobile */
  #topbar-stats .topbar-stat:nth-child(n+2) { display: none; }
  #topbar-stats { gap: 10px !important; }

  /* Metric cards smaller text */
  .metric-value { font-size: 1.1rem; }
  .metric-label { font-size: 0.65rem; }

  /* Modal full-width on mobile */
  .modal-box { max-width: 95%; padding: 16px; }
  .modal-content { max-width: 95vw; }

  /* Filter bar wrap */
  .filter-bar { gap: 6px; flex-wrap: wrap; }
  .filter-bar .form-input,
  .filter-bar .form-select { min-width: 80px; max-width: 100%; font-size: 0.72rem; }
  .filter-bar select[style*="width"] { width: auto !important; min-width: 80px; }

  /* Toast wider */
  #toast-container { max-width: 90vw; right: 8px; top: 56px; }

  /* Quick controls: wrap and fill width */
  .quick-controls .flex,
  .card-body > .flex.gap-8 { flex-wrap: wrap; }
  .card-body > .flex.gap-8 > .btn { min-width: auto; flex: 1 1 calc(50% - 4px); font-size: 0.72rem; padding: 8px 10px; }

  /* Trade detail grid: allow stacking */
  .detail-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 12px; }

  /* Rules sections: stack on mobile */
  .rules-sections { flex-direction: column; gap: 16px; }
  .rules-section { min-width: 0; }
  .rules-label { min-width: 100px; font-size: 0.68rem; }

  /* Card header with buttons: wrap */
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-header .flex.gap-8 { flex-wrap: wrap; }

  /* Page header wrap */
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }

  /* Inline form inputs: never overflow */
  .form-input[style*="width"],
  input[style*="width:200px"],
  input[style*="width: 200px"] { width: 100% !important; max-width: 100%; }

  /* Settings inline forms: stack vertically */
  .settings-section form > div[style*="display:flex"] { flex-direction: column; align-items: stretch !important; }
  .settings-section form > div[style*="display:flex"] .btn { margin-bottom: 0; align-self: flex-start; }

  /* Tabs: scrollable on mobile */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .tab { flex-shrink: 0; }

  /* DCA legs sub-table */
  .dca-legs-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Update banner: stack on mobile */
  #update-banner > div { flex-direction: column; gap: 8px; align-items: flex-start !important; }
}

/* Small phone */
@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { padding: 10px; }
  .metric-value { font-size: 0.95rem; }
  .topbar-badge { display: none; }

  /* Quick controls: full-width stack */
  .card-body > .flex.gap-8 > .btn { flex: 1 1 100%; min-width: 0; }

  /* Even more compact topbar on small phones */
  .topbar-right { gap: 6px; }

  /* Trade/Price dialogs: full width */
  #trade-dialog > div,
  #price-dialog > div { width: 95vw !important; max-width: 95vw !important; }

  /* Reduce card padding further */
  .card-header { padding: 8px 10px; }
  .card-body { padding: 10px; }
  .settings-panel { padding: 12px; }

  /* AI chat input area */
  .ai-chat-input-area { padding: 8px 10px; }

  /* Fix flex-between on small screens */
  .flex-between { flex-wrap: wrap; gap: 8px; }

  /* Section header: stack */
  .section-header { flex-direction: column; align-items: flex-start; gap: 6px; }
}

/* ============================================================
   25. CONFIG EDITOR (CodeMirror-like)
   ============================================================ */

.config-editor {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.config-editor-toolbar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
}

/* ============================================================
   26. SETTINGS PAGE
   ============================================================ */

.settings-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
}

.settings-nav {
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 8px;
}

.settings-nav-item {
  display: block;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
}

.settings-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.settings-nav-item.active { background: var(--bg-elevated); color: var(--green); }

.settings-panel { padding: 24px; }

.settings-section {
  margin-bottom: 24px;
}

.settings-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Exchange key status */
.key-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.key-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}

.key-configured { background: var(--green); }
.key-missing { background: var(--red); }

.key-status-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ============================================================
   27. LOADING SKELETON
   ============================================================ */

.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-elevated) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   28. SECTION HEADERS
   ============================================================ */

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

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.section-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   29. FILTER BAR
   ============================================================ */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  min-width: 120px;
  padding: 6px 10px;
  font-size: 0.75rem;
}

/* ============================================================
   30. WEBSOCKET STATUS INDICATOR
   ============================================================ */

.ws-connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.ws-disconnected {
  background: var(--text-muted);
  box-shadow: none;
}

/* ============================================================
   31. INDICATOR PAGE
   ============================================================ */

.indicator-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.indicator-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ind-card-header { display: flex; flex-direction: column; gap: 6px; }

.ind-card-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 4px;
}

.ind-card-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.ind-category-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}
.cat-oscillator { background: rgba(168, 85, 247, 0.15); color: var(--purple); }
.cat-trend { background: rgba(6, 182, 212, 0.15); color: var(--cyan); }
.cat-volatility { background: rgba(245, 158, 11, 0.15); color: var(--orange); }
.cat-volume { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.cat-momentum { background: rgba(34, 197, 94, 0.15); color: var(--green); }

.ind-status-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
}
.badge-on { background: var(--green-bg); color: var(--green); }
.badge-off { background: rgba(71, 85, 105, 0.2); color: var(--text-muted); }

.ind-card-live {
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}

.ind-live-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}
.ind-live-pair { color: var(--text-secondary); min-width: 50px; font-weight: 500; }
.ind-live-value { flex: 1; text-align: right; }

.ind-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.signal-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}
.signal-buy { background: var(--green-bg); color: var(--green); }
.signal-sell { background: var(--red-bg); color: var(--red); }
.signal-neutral { background: rgba(71, 85, 105, 0.2); color: var(--text-muted); }
.signal-pass { background: var(--green-bg); color: var(--green); }
.signal-fail { background: var(--red-bg); color: var(--red); }

.cat-filter.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.btn-xs {
  padding: 2px 8px;
  font-size: 0.68rem;
  border-radius: var(--radius-sm);
}

/* ============================================================
   32. STRATEGY BUILDER PAGE
   ============================================================ */

.strategy-slot {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.strategy-slot:last-child { border-bottom: none; }

.slot-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.slot-letter {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--cyan);
  min-width: 20px;
  text-align: center;
}

.form-input-sm {
  padding: 4px 8px !important;
  font-size: 0.78rem !important;
  height: 30px;
}

.slot-live {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-left: 28px;
}

.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }

/* ============================================================
   33. AI STRATEGY CHAT PAGE
   ============================================================ */

.ai-chat-container {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  height: calc(100vh - var(--topbar-height) - 80px);
  min-height: 500px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.ai-chat-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.ai-chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.ai-chat-conv-list {
  flex: 1;
  overflow-y: auto;
}

.ai-chat-conv-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.ai-chat-conv-item:hover { background: var(--bg-hover); }
.ai-chat-conv-item.active { background: var(--bg-elevated); border-left: 2px solid var(--cyan); }

.ai-conv-title {
  display: block;
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-conv-date { display: block; margin-top: 2px; }

.ai-chat-sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.ai-chat-main {
  display: flex;
  flex-direction: column;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-msg {
  max-width: 85%;
}
.ai-msg-user {
  align-self: flex-end;
}
.ai-msg-user .ai-msg-content {
  background: var(--bg-elevated);
  border-radius: var(--radius) var(--radius) var(--radius-sm) var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
}
.ai-msg-assistant .ai-msg-content {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius) var(--radius) var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  line-height: 1.6;
}
.ai-msg-error .ai-msg-content {
  background: var(--red-bg);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--red);
}

.ai-typing {
  color: var(--text-muted);
  font-style: italic;
}

.ai-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.ai-action-preview {
  margin: 0 16px 8px;
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  overflow: hidden;
}
.ai-action-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(6, 182, 212, 0.08);
  border-bottom: 1px solid var(--cyan);
}
.ai-action-code {
  padding: 12px;
  background: var(--bg-base);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ============================================================
   34. INFO BANNERS (help sections on pages)
   ============================================================ */

.info-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

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

.info-banner-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.info-banner-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
}

.info-banner-body {
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.info-banner-body p { margin-bottom: 8px; }
.info-banner-body ul, .info-banner-body ol {
  padding-left: 20px;
  margin: 6px 0;
}
.info-banner-body li { margin-bottom: 4px; }

.info-details {
  margin: 8px 0;
}
.info-details summary {
  cursor: pointer;
  color: var(--cyan);
  font-weight: 500;
  font-size: 0.82rem;
  padding: 4px 0;
}
.info-details summary:hover { color: var(--text-primary); }
.info-details[open] summary { margin-bottom: 6px; }

.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin: 8px 0;
}
.info-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.info-table td:first-child {
  font-family: var(--font-mono);
  color: var(--cyan);
  white-space: nowrap;
  width: 120px;
}

.info-example {
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: 6px 0;
  font-size: 0.78rem;
  border-left: 2px solid var(--cyan);
}

/* ============================================================
   35. MODAL STYLES (reusable)
   ============================================================ */

#modal-root {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
}
#modal-root:has(.modal-content) { display: flex; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

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

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
}

/* ============================================================
   36. RESPONSIVE — NEW PAGES
   ============================================================ */

@media (max-width: 768px) {
  .indicator-grid { grid-template-columns: 1fr; }
  .ai-chat-container {
    grid-template-columns: 1fr;
    height: calc(100vh - var(--topbar-height) - 60px);
  }
  .ai-chat-sidebar { display: none; }
  .slot-header { gap: 4px; flex-wrap: wrap; }
  .slot-header .form-input-sm { min-width: 0; flex: 1 1 auto; }
  .info-banner-body { padding: 10px 12px; }

  /* Strategy slot selects */
  .slot-header select { max-width: 100%; }

  /* Indicator card footer */
  .ind-card-footer { flex-wrap: wrap; }

  /* Info table first column */
  .info-table td:first-child { width: auto; min-width: 80px; }
}


/* ============================================================
   37. HELP PAGE
   ============================================================ */

.help-page { max-width: 100%; }

.help-search-wrap {
  position: relative;
  margin-bottom: 24px;
}
.help-search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-muted); pointer-events: none;
}
.help-search {
  width: 100%; padding: 12px 14px 12px 42px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary); font-size: 0.95rem;
  font-family: inherit; outline: none; transition: border-color 0.2s;
}
.help-search:focus { border-color: var(--cyan); }
.help-search::placeholder { color: var(--text-muted); }
.help-search-count {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 0.75rem; color: var(--text-muted);
}

.help-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 32px;
  align-items: start;
}

/* TOC sidebar */
.help-toc {
  position: sticky; top: calc(var(--topbar-height) + 16px);
  max-height: calc(100vh - var(--topbar-height) - 40px);
  overflow-y: auto; padding-right: 8px;
  border-right: 1px solid var(--border);
}
.help-toc-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 12px; font-weight: 600;
}
.toc-link {
  display: block; padding: 4px 12px 4px 0; font-size: 0.78rem;
  color: var(--text-secondary); text-decoration: none;
  border-left: 2px solid transparent; transition: all 0.15s;
  line-height: 1.5;
}
.toc-link:hover { color: var(--text-primary); }
.toc-link.toc-active { color: var(--cyan); border-left-color: var(--cyan); }
.toc-h1 { font-weight: 600; padding-left: 10px; margin-top: 6px; }
.toc-h2 { padding-left: 22px; font-weight: 400; }

/* Help content */
.help-content { min-width: 0; }

.help-section {
  margin-bottom: 36px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--border);
}
.help-section:last-of-type { border-bottom: none; }

.help-section h1 {
  font-size: 1.5rem; font-weight: 700; color: var(--text-primary);
  margin: 0 0 12px 0; padding-bottom: 8px;
  border-bottom: 2px solid var(--cyan);
}
.help-section h2 {
  font-size: 1.15rem; font-weight: 600; color: var(--text-primary);
  margin: 0 0 10px 0;
}
.help-section h3 {
  font-size: 0.95rem; font-weight: 600; color: var(--text-secondary);
  margin: 20px 0 8px 0;
}
.help-section p {
  color: var(--text-secondary); font-size: 0.88rem; line-height: 1.7;
  margin: 0 0 12px 0;
}
.help-section ul, .help-section ol {
  color: var(--text-secondary); font-size: 0.88rem; line-height: 1.8;
  margin: 0 0 12px 0; padding-left: 24px;
}
.help-section li { margin-bottom: 4px; }
.help-section code {
  background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 0.82rem;
  color: var(--cyan);
}
.help-section strong { color: var(--text-primary); }

/* Help tables */
.help-table {
  width: 100%; border-collapse: collapse; margin: 12px 0 16px;
  font-size: 0.84rem;
}
.help-table th {
  text-align: left; padding: 8px 12px;
  background: var(--bg-elevated); color: var(--text-muted);
  font-weight: 600; font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
.help-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  color: var(--text-secondary); vertical-align: top;
}
.help-table tr:hover td { background: var(--bg-hover); }

/* Code blocks */
.help-code {
  background: var(--bg-base); border: 1px solid var(--border);
  border-radius: 6px; padding: 14px 16px; margin: 8px 0 16px;
  overflow-x: auto;
}
.help-code pre {
  margin: 0; font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem; line-height: 1.6; color: var(--text-secondary);
  white-space: pre; tab-size: 2;
}

/* Page mockups (inline CSS screenshots) */
.help-mockup {
  background: var(--bg-base); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; margin: 14px 0 18px;
  overflow: hidden;
}
.help-mockup-topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; margin: -14px -14px 12px -14px;
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.help-mockup-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
}
.help-mockup-card-label {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin-bottom: 2px;
}
.help-mockup-card-value {
  font-size: 1rem; font-weight: 700; color: var(--text-primary);
}

/* Callout boxes */
.help-callout {
  padding: 12px 16px; border-radius: 6px; margin: 12px 0 16px;
  font-size: 0.84rem; line-height: 1.6;
  border-left: 3px solid;
}
.help-callout-info {
  background: rgba(6,182,212,0.06); border-color: var(--cyan);
  color: var(--text-secondary);
}
.help-callout-warn {
  background: rgba(234,179,8,0.06); border-color: var(--yellow);
  color: var(--text-secondary);
}
.help-callout-danger {
  background: rgba(239,68,68,0.06); border-color: var(--red);
  color: var(--text-secondary);
}
.help-callout strong { color: var(--text-primary); }

/* Flow steps */
.help-flow { margin: 16px 0; }
.help-flow-step {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 12px 0; border-left: 2px solid var(--border);
  margin-left: 14px; padding-left: 20px;
  position: relative;
}
.help-flow-step:last-child { border-left-color: transparent; }
.help-flow-num {
  position: absolute; left: -12px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--cyan); color: #000;
  font-size: 0.72rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.help-flow-step strong {
  display: block; color: var(--text-primary); font-size: 0.88rem;
  margin-bottom: 2px;
}
.help-flow-step p {
  margin: 0; font-size: 0.82rem; color: var(--text-muted);
}

/* Badges inline */
.help-badge {
  display: inline-block; padding: 1px 8px; border-radius: 4px;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
}
.help-badge-green { background: rgba(34,197,94,0.15); color: var(--green); }
.help-badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.help-badge-yellow { background: rgba(234,179,8,0.15); color: var(--yellow); }
.help-badge-cyan { background: rgba(6,182,212,0.15); color: var(--cyan); }
.help-badge-gray { background: var(--bg-elevated); color: var(--text-muted); }

/* Condition dots */
.help-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle;
}
.help-dot-green { background: var(--green); }
.help-dot-red { background: var(--red); }

/* FAQ accordion */
.help-faq { margin-top: 16px; }
.help-faq-item {
  border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 8px; overflow: hidden;
}
.help-faq-q {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; cursor: pointer;
  color: var(--text-primary); font-size: 0.88rem; font-weight: 500;
  background: var(--bg-surface); transition: background 0.15s;
}
.help-faq-q:hover { background: var(--bg-hover); }
.help-faq-chevron {
  width: 18px; height: 18px; flex-shrink: 0;
  transition: transform 0.2s; color: var(--text-muted);
}
.help-faq-item.open .help-faq-chevron { transform: rotate(180deg); }
.help-faq-a {
  max-height: 0; overflow: hidden; transition: max-height 0.3s ease;
  padding: 0 16px;
}
.help-faq-item.open .help-faq-a {
  max-height: 500px; padding: 12px 16px;
}
.help-faq-a p {
  color: var(--text-secondary); font-size: 0.84rem; line-height: 1.6;
  margin: 0 0 8px 0;
}

/* Image placeholders */
.help-img-placeholder {
  background: var(--bg-surface); border: 1px dashed var(--border);
  border-radius: 8px; padding: 32px 24px; text-align: center;
  margin: 12px 0 16px;
}
.help-img-label {
  font-size: 0.88rem; font-weight: 600; color: var(--text-primary);
  margin-bottom: 6px;
}
.help-img-desc {
  font-size: 0.78rem; color: var(--text-muted); max-width: 500px;
  margin: 0 auto;
}

/* Search highlight */
.help-highlight {
  background: rgba(234,179,8,0.3); color: var(--text-primary);
  border-radius: 2px; padding: 0 1px;
}

/* No results */
.help-no-results {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.help-no-results p { text-align: center; }

/* Responsive */
@media (max-width: 900px) {
  .help-layout { grid-template-columns: 1fr; gap: 16px; }
  .help-toc {
    position: static; max-height: none; overflow: visible;
    border-right: none; border-bottom: 1px solid var(--border);
    padding-bottom: 16px; margin-bottom: 8px;
    display: flex; flex-wrap: wrap; gap: 4px 8px;
  }
  .help-toc-title { width: 100%; }
  .toc-link { border-left: none; padding: 4px 8px; font-size: 0.74rem; }
  .toc-h1 { padding-left: 8px; }
  .toc-h2 { padding-left: 8px; }
  .help-section h1 { font-size: 1.2rem; }
  .help-table { font-size: 0.78rem; }
  .help-table th, .help-table td { padding: 6px 8px; }
}


/* ── 38. TRADING GROUPS PAGE ── */

#modal-root .modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#modal-root .modal-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; min-width: 0; width: 90vw; max-width: 460px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#modal-root .modal-box h3 { margin-bottom: 12px; font-size: 1rem; }
#modal-root .modal-box p { font-size: 0.85rem; margin-bottom: 8px; }
#modal-root .modal-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px;
}

/* ── 37. Futures / Leverage Trading ────────────────────────────── */

.badge-futures {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.03em;
}
.badge-long {
  background: rgba(34,197,94,0.15);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.3);
}
.badge-short {
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
}
.liq-warn { color: var(--orange); }
.liq-danger { color: var(--red); font-weight: 600; }
.liq-safe { color: var(--text-muted); }

/* ── 39. Calendar Heatmap (Stats) ────────────────────────────── */

.cal-heatmap-container { padding: 4px 0; }
.cal-grid { display: flex; gap: 0; }
.cal-day-labels {
  display: flex; flex-direction: column; gap: 3px;
  margin-right: 6px; padding-top: 20px;
}
.cal-day-label {
  width: 28px; height: 14px;
  font-size: 0.65rem; color: var(--text-muted);
  line-height: 14px; text-align: right;
}
.cal-weeks { display: flex; flex-direction: column; gap: 0; }
.cal-month-row {
  display: flex; gap: 3px; height: 18px; margin-bottom: 3px;
}
.cal-month-label {
  width: 14px; font-size: 0.65rem; color: var(--text-muted);
  text-align: center; line-height: 18px;
  white-space: nowrap; overflow: visible;
}
.cal-row { display: flex; gap: 3px; }
.cal-cell {
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.04);
  cursor: default;
  transition: transform 0.1s;
}
.cal-cell:hover { transform: scale(1.5); z-index: 2; }
.cal-empty { background: transparent !important; border-color: transparent; }
.cal-legend {
  display: flex; align-items: center; gap: 3px;
  justify-content: flex-end;
}
.cal-legend .cal-cell {
  width: 14px; height: 14px; cursor: default;
}
.cal-legend .cal-cell:hover { transform: none; }

.cal-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.12s;
  white-space: nowrap;
  min-width: 120px;
  text-align: center;
}
.cal-tooltip.visible { opacity: 1; }
.cal-tooltip-date {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.cal-tooltip-pnl {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}
.cal-tooltip-pnl.green { color: var(--green); }
.cal-tooltip-pnl.red { color: var(--red); }
.cal-tooltip-pnl.muted { color: var(--text-muted); }
.cal-tooltip-trades {
  font-size: 0.6rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

@media (max-width: 768px) {
  .cal-cell { width: 10px; height: 10px; }
  .cal-month-label { width: 10px; }
  .cal-day-label { width: 22px; font-size: 0.55rem; height: 10px; line-height: 10px; }
  .cal-row { gap: 2px; }
  .cal-month-row { gap: 2px; }
  .cal-legend .cal-cell { width: 10px; height: 10px; }
}

/* ── 40. Backtesting Page ──────────────────────────────────── */

#bt-results .metric-card { text-align: center; }
#equity-chart { max-height: 300px; }
#trade-log-body tr:hover { background: var(--bg-hover); }
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 41. Grid Bot Page ─────────────────────────────────────── */

.grid-bot-card { transition: border-color 0.2s; }
.grid-bot-card:hover { border-color: var(--cyan) !important; }

/* ── 42. Cava Signals Trend Monitor ───────────────────────── */

.cava-trend-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.cava-trend-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cava-trend-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-weight: 600;
}
.cava-trend-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.cava-trend-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 16px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  white-space: nowrap;
}
/* Weekly trend badges */
.cava-trend-badge-bull {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.cava-trend-badge-bear {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
/* Daily zone badges */
.cava-trend-badge-overbought {
  background: rgba(217, 70, 239, 0.15);
  color: #d946ef;
  border: 1px solid rgba(217, 70, 239, 0.3);
}
.cava-trend-badge-bullish {
  background: rgba(6, 182, 212, 0.15);
  color: var(--cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}
.cava-trend-badge-neutral {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-secondary);
  border: 1px solid rgba(148, 163, 184, 0.25);
}
.cava-trend-badge-bearish {
  background: rgba(251, 146, 60, 0.15);
  color: var(--orange);
  border: 1px solid rgba(251, 146, 60, 0.3);
}
.cava-trend-badge-deep_oversold {
  background: rgba(132, 204, 22, 0.15);
  color: #84cc16;
  border: 1px solid rgba(132, 204, 22, 0.3);
}
/* K/D values */
.cava-trend-values {
  display: flex;
  gap: 12px;
}
.cava-trend-kd {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
}
.cava-trend-num {
  color: var(--text-primary);
  font-weight: 600;
}
/* StochRSI bar */
.cava-trend-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cava-trend-bar {
  position: relative;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: visible;
}
.cava-trend-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
.cava-trend-bar-bull   { background: linear-gradient(90deg, rgba(34,197,94,0.2), rgba(34,197,94,0.5)); }
.cava-trend-bar-bear   { background: linear-gradient(90deg, rgba(239,68,68,0.2), rgba(239,68,68,0.5)); }
.cava-trend-bar-overbought   { background: linear-gradient(90deg, rgba(217,70,239,0.2), rgba(217,70,239,0.5)); }
.cava-trend-bar-bullish      { background: linear-gradient(90deg, rgba(6,182,212,0.2), rgba(6,182,212,0.5)); }
.cava-trend-bar-neutral      { background: linear-gradient(90deg, rgba(148,163,184,0.1), rgba(148,163,184,0.3)); }
.cava-trend-bar-bearish      { background: linear-gradient(90deg, rgba(251,146,60,0.2), rgba(251,146,60,0.5)); }
.cava-trend-bar-deep_oversold { background: linear-gradient(90deg, rgba(132,204,22,0.2), rgba(132,204,22,0.5)); }

.cava-trend-bar-marker {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 12px;
  background: var(--text-primary);
  border-radius: 2px;
  transform: translateX(-50%);
  transition: left 0.6s ease;
}
.cava-trend-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.55rem;
  color: var(--text-muted);
  opacity: 0.5;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
}
/* Footer */
.cava-trend-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.cava-trend-updated,
.cava-trend-source {
  font-size: 0.62rem;
  color: var(--text-muted);
  opacity: 0.6;
}
/* Error state */
.cava-trend-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.cava-trend-error svg { opacity: 0.5; }

/* Responsive: stack on mobile */
@media (max-width: 640px) {
  .cava-trend-container {
    grid-template-columns: 1fr;
    gap: 18px;
  }
}


/* ── 43. PWA & Mobile Enhancements ────────────────────────── */

/* PWA standalone mode — hide browser UI elements */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top); }
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  .sidebar { padding-top: env(safe-area-inset-top); }
  .page-content { padding-bottom: env(safe-area-inset-bottom); }
}

/* Touch-friendly tap targets on mobile */
@media (max-width: 768px) {
  .btn, .nav-item, .settings-nav-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .form-input, .form-select, .form-textarea {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .toggle { transform: scale(1.1); }

  /* Prevent any element from overflowing the viewport */
  .page-content > * { max-width: 100%; overflow-wrap: break-word; }
  .card { max-width: 100%; }

  /* Symbol search on Charts page */
  .symbol-search-wrap { max-width: 100%; }
  .symbol-results { max-width: 100%; left: 0; right: 0; }

  /* Help page: tables horizontal scroll */
  .help-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Help code blocks: horizontal scroll */
  .help-code { overflow-x: auto; }

  /* Calendar heatmap: horizontal scroll */
  .cal-heatmap-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Form input-sm: prevent iOS zoom on focus ── */
  .form-input-sm {
    font-size: 16px !important;
    min-height: 40px;
  }

  /* ── Sidebar overlay: proper clickable area ── */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    display: none;
  }
  .sidebar-open .sidebar-overlay { display: block; }

  /* ── Toggle switch: ensure 44px tap target ── */
  .toggle {
    transform: scale(1.2);
    margin: 4px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Small buttons: enforce 44px tap target ── */
  .btn-xs {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-sm {
    min-height: 44px;
    padding: 8px 14px;
  }

  /* ── Strategy Builder: slot header stacking ── */
  .slot-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .slot-header .form-input-sm,
  .slot-header select {
    width: 100% !important;
    min-width: 0 !important;
  }
  .slot-header .slot-letter {
    align-self: flex-start;
  }
  .slot-header input[style*="width:100px"],
  .slot-header input[style*="width:80px"],
  .slot-header input[style*="width: 100px"],
  .slot-header input[style*="width: 80px"] {
    width: 100% !important;
  }

  /* ── Strategy card-footer: stack formula + trailing inputs ── */
  .card-footer {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .card-footer .form-input-sm { width: 100% !important; }
  .card-footer input[style*="width:70px"] { width: 100% !important; }

  /* Settings page mobile rules moved to section 44 (iOS-style index/detail) */

  /* ── Backtest DCA ladder: 2-column on mobile ── */
  .bt-ladder-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Backtest tier row: stack vertically ── */
  .bt-tier-row {
    grid-template-columns: 1fr !important;
    gap: 4px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }
  .bt-tier-row .bt-tier-label {
    font-weight: 600;
    color: var(--text-primary);
  }

  /* ── Backtest slot builder: ensure touch-friendly ── */
  .bt-slot-row {
    gap: 6px !important;
  }
  .bt-slot-row select,
  .bt-slot-row input[type="number"],
  .bt-slot-row input[type="text"] {
    width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
  }
  .bt-slot-remove {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Backtest tabs: scrollable horizontally ── */
  .bt-tabs {
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .bt-tab {
    flex-shrink: 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* ── w-full utility ── */
  .w-full { width: 100%; }

  /* ── Backtest run buttons: full width + large tap ── */
  #cs-run-btn,
  #cu-run-btn {
    width: 100%;
    min-height: 52px;
    font-size: 1rem;
  }

  /* ── AI Chat: full height on mobile ── */
  .ai-chat-container {
    height: calc(100vh - var(--topbar-height) - 48px) !important;
  }

  /* ── Inline styled width overrides for settings forms ── */
  input[style*="width:200px"],
  input[style*="width: 200px"],
  input[style*="width:120px"],
  input[style*="width: 120px"],
  select[style*="width:200px"],
  select[style*="width: 200px"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ── Modal: full screen on mobile ── */
  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0;
  }
  .modal-overlay {
    align-items: flex-end !important;
  }
  .modal-box {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: var(--radius) var(--radius) 0 0 !important;
  }

  /* ── Indicator param modal: full width ── */
  #modal-root .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
  }

  /* ── Positions trade dialog: ensure scroll if tall ── */
  #trade-dialog > div,
  #price-dialog > div {
    max-height: 90vh;
    overflow-y: auto;
  }

  /* ── Log viewer: slightly smaller font and full height ── */
  .log-viewer {
    max-height: calc(100vh - 220px);
    font-size: 0.65rem;
  }

  /* ── Indicator grid: already 1fr via section 36 ── */

  /* ── Metric card span overrides on mobile ── */
  [style*="grid-column: span 2"],
  [style*="grid-column: span 3"],
  [style*="grid-column:span 2"],
  [style*="grid-column:span 3"] {
    grid-column: span 1 !important;
  }

  /* ── Charts page controls: stacked vertically ── */
  .chart-controls {
    flex-direction: column;
    align-items: stretch !important;
  }
  .chart-controls > div {
    width: 100%;
  }
  .chart-controls select,
  .chart-controls input {
    width: 100%;
  }
  .symbol-search-wrap {
    width: 100% !important;
  }

  /* ── Pair chips: scrollable row ── */
  .pair-chips {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 4px;
  }
  .pair-chip {
    flex-shrink: 0;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  /* ── Info table: horizontal scroll wrapper ── */
  .info-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Grid bot card: prevent overflow ── */
  .grid-bot-card { overflow: hidden; }

  /* ── Sidebar footer buttons: ensure tap targets ── */
  .sidebar-footer .btn {
    min-height: 44px;
    justify-content: center;
  }

  /* ── Filter category buttons: wrap nicely ── */
  .cat-filter {
    min-height: 36px;
    padding: 6px 12px !important;
  }

  /* ── Pagination: larger tap targets ── */
  .pagination a,
  .pagination span {
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Checkbox label rows: minimum 44px ── */
  .bt-label-row {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .bt-label-check {
    width: 20px;
    height: 20px;
    min-width: 20px;
  }

  /* ── Positions rules section: ensure readable ── */
  .rules-item {
    flex-wrap: wrap;
  }
  .rules-label {
    min-width: 0 !important;
    flex-shrink: 1;
  }
  .rules-detail {
    word-break: break-all;
  }

  /* ── Update banner: proper stacking ── */
  #update-banner {
    padding: 8px 12px !important;
  }

  /* ── Flash messages: full-width on mobile ── */
  .flash-container { padding: 8px 12px 0; }

  /* ── Cava trend: ensure readability ── */
  .cava-trend-badge {
    font-size: 0.7rem;
    padding: 4px 12px;
  }
}

/* ── 375px: iPhone SE / small phones ── */
@media (max-width: 414px) {
  /* Even more compact metric cards */
  .metric-grid {
    grid-template-columns: 1fr !important;
    gap: 6px;
  }
  .metric-card {
    padding: 10px 12px;
  }
  .metric-value {
    font-size: 0.9rem;
  }

  /* Page title truncation */
  .page-title {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Topbar: minimal */
  .topbar {
    padding: 0 8px;
    height: 48px;
  }
  .topbar-stat-value {
    font-size: 0.68rem;
  }
  .topbar-stat-label {
    font-size: 0.55rem;
  }

  /* Strategy slot: even more compact */
  .strategy-slot {
    padding: 8px 10px;
  }

  /* Backtest: DCA ladder single column on very small */
  .bt-ladder-grid {
    grid-template-columns: 1fr !important;
  }

  /* Charts page (not dashboard chart cards): minimum height */
  #chart-wrap {
    min-height: 300px;
    height: calc(100vh - 300px);
  }

  /* Hide non-essential sidebar footer items */
  .sidebar-info-row .sidebar-info-sep,
  .sidebar-info-row .sidebar-info-label:nth-child(n+4) {
    display: none;
  }
}

/* ============================================================
   44. SETTINGS — MOBILE (iOS-style index/detail)
   ============================================================ */

/* Default: hide the back link on desktop */
.settings-back-link { display: none; }

@media (max-width: 768px) {
  /* Full-bleed: drop the card chrome on mobile */
  .settings-grid {
    grid-template-columns: 1fr !important;
    border: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    overflow: visible !important;
  }

  /* ─────────────── INDEX VIEW (/settings) ─────────────── */
  .settings-grid.is-index .settings-panel { display: none !important; }

  .settings-grid.is-index .settings-nav {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    gap: 0 !important;
    padding: 0 !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    background: var(--bg-surface) !important;
    overflow: hidden !important;
  }

  .settings-grid.is-index .settings-nav-item {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    min-height: 52px !important;
    padding: 14px 16px !important;
    font-size: 0.95rem !important;
    color: var(--text-primary) !important;
    border-radius: 0 !important;
    border-bottom: 1px solid var(--border) !important;
    white-space: nowrap !important;
  }

  .settings-grid.is-index .settings-nav-item:last-child {
    border-bottom: none !important;
  }

  .settings-grid.is-index .settings-nav-item::after {
    content: "›";
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text-secondary);
    margin-left: 12px;
    opacity: 0.6;
  }

  .settings-grid.is-index .settings-nav-item:hover,
  .settings-grid.is-index .settings-nav-item.active {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
  }

  /* Group separators (the inline-styled <div>s in the template) become
     iOS-style gaps between sections. */
  .settings-grid.is-index .settings-nav > div[style*="border-top"] {
    display: block !important;
    height: 14px !important;
    margin: 0 !important;
    border-top: none !important;
    background: transparent !important;
  }
  /* Remove the bottom border from the row right above a group gap */
  .settings-grid.is-index .settings-nav-item:has(+ div[style*="border-top"]) {
    border-bottom: none !important;
  }

  /* ─────────────── DETAIL VIEW (/settings/{panel}) ─────────────── */
  .settings-grid.is-detail .settings-nav { display: none !important; }

  .settings-grid.is-detail .settings-panel {
    padding: 12px 14px 24px !important;
    border: none !important;
    background: transparent !important;
    width: 100% !important;
  }

  .settings-grid.is-detail .settings-back-link {
    display: inline-flex !important;
    align-items: center !important;
    min-height: 44px;
    margin: 0 0 12px;
    padding: 10px 4px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--green);
    text-decoration: none;
  }
  .settings-grid.is-detail .settings-back-link:hover { opacity: 0.85; }

  /* ─────────────── Form overflow safety net (mobile, scoped) ─────────────── */
  .settings-panel .form-group {
    width: 100% !important;
    margin-bottom: 14px !important;
  }

  .settings-panel .form-input,
  .settings-panel .form-select,
  .settings-panel .form-textarea,
  .settings-panel input[type="text"],
  .settings-panel input[type="number"],
  .settings-panel input[type="password"],
  .settings-panel input[type="email"],
  .settings-panel input[type="url"],
  .settings-panel select,
  .settings-panel textarea {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Inline flex form rows in the template (e.g. instance-name + Save button)
     stack vertically and stretch full-width. */
  .settings-panel form > div[style*="display:flex"],
  .settings-panel form > div[style*="display: flex"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .settings-panel .grid-2,
  .settings-panel .grid-3,
  .settings-panel .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Buttons inside settings forms shouldn't carry desktop bottom margins
     that were tuned for inline alignment with input rows. */
  .settings-panel form .btn[style*="margin-bottom"] {
    margin-bottom: 0 !important;
  }
}
