/* ═══════════════════════════════════════
   Perps Dashboard v5 — Themed Trading Panel
   30-item upgrade pack
   ═══════════════════════════════════════ */

/* ── #21 — Unified spacing/typography tokens ── */
:root {
  /* Page */
  --bg: #F5F5F0;
  --card-bg: #FFFFFF;

  /* Borders & Shadow (bold border system) */
  --border: #1A1A2E;
  --border-lite: #D1D5DB;
  --shadow: #1A1A2E;
  --shadow-offset: 3px;

  /* Accent palette — #22 contrast-calibrated */
  --accent-green: #059669;
  --accent-green-bg: #ECFDF5;
  --accent-green-border: #6EE7B7;
  --accent-yellow: #D97706;
  --accent-yellow-bg: #FFFBEB;
  --accent-yellow-border: #FCD34D;
  --accent-red: #DC2626;
  --accent-red-bg: #FEF2F2;
  --accent-red-border: #FCA5A5;
  --accent-blue: #2563EB;
  --accent-blue-bg: #EFF6FF;
  --accent-blue-border: #93C5FD;
  --accent-purple: #7C3AED;
  --accent-purple-bg: #F5F3FF;
  --accent-purple-border: #C4B5FD;

  /* Text — #22 4.5:1+ contrast on white */
  --text-primary: #111827;
  --text-secondary: #374151;
  --text-muted: #6B7280;

  /* #21 — Spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Radius */
  --radius: 10px;
  --radius-sm: 7px;
  --radius-xs: 5px;

  /* #21 — Font scale */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 18px;

  /* #25 — Touch target minimum */
  --touch-min: 44px;
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh; min-height: 100dvh;
  color: var(--text-primary);
  line-height: 1.5;
}

/* ── Page Layout ── */
.perps-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* ── #24 Compact density ── */
.density-compact { gap: var(--sp-2); }
.density-compact .perps-header { padding: var(--sp-2) var(--sp-3); }
.density-compact .perps-filters { padding: var(--sp-3); gap: var(--sp-2); }
.density-compact .kpi-bar { gap: var(--sp-2); }
.density-compact .kpi-card { padding: var(--sp-1) var(--sp-2); }
.density-compact .chart-container { height: 420px; min-height: 300px; }
.density-compact .picker__list { max-height: 100px; }
.density-compact .tag { padding: 2px 8px; font-size: var(--fs-xs); }


/* ═══════════════════════════════════════
   Header
   ═══════════════════════════════════════ */
.perps-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--shadow);
  padding: var(--sp-3) var(--sp-5);
}

.perps-header__left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.perps-header__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  text-decoration: none;
  transition: transform .15s ease, opacity .15s ease;
  overflow: hidden;
}
.perps-header__back:hover {
  transform: translateY(-1px);
  opacity: .92;
}

.perps-header__logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.perps-header__title {
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.perps-header__badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-green);
  background: var(--accent-green-bg);
  border: 1.5px solid var(--accent-green-border);
  border-radius: 999px;
  animation: pulse-badge 2s ease-in-out infinite;
}
.perps-header__badge::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--accent-green);
  border-radius: 50%;
}
.badge--error {
  color: var(--accent-red) !important;
  background: var(--accent-red-bg) !important;
  border-color: var(--accent-red-border) !important;
  animation: none !important;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: .7; }
}

.perps-header__right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.perps-header__updated {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* #23 — Unified button states */
.perps-header__refresh,
.perps-header__density,
.chart-tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 1.5px solid var(--border-lite);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .15s ease;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
}
.perps-header__refresh:hover,
.perps-header__density:hover,
.chart-tool-btn:hover {
  border-color: var(--accent-blue-border);
  color: var(--accent-blue);
  background: var(--accent-blue-bg);
}
.perps-header__refresh:active,
.perps-header__density:active,
.chart-tool-btn:active {
  transform: scale(0.95);
}
.perps-header__refresh.spinning svg {
  animation: spin .6s linear;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ #17 — Freshness Dot ═══ */
.freshness-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.freshness-dot--fresh { background: var(--accent-green); }
.freshness-dot--warn  { background: var(--accent-yellow); }
.freshness-dot--stale { background: var(--accent-red); animation: pulse-badge 1s ease-in-out infinite; }


/* ═══════════════════════════════════════
   #16 — KPI Bar
   ═══════════════════════════════════════ */
.kpi-bar {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.kpi-bar__inner {
  display: flex;
  gap: var(--sp-3);
  min-width: max-content;
}

.kpi-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 2px 2px 0 var(--shadow);
  padding: var(--sp-2) var(--sp-4);
  min-width: 150px;
  flex-shrink: 0;
}
.kpi-card--placeholder {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.kpi-card__symbol {
  font-size: var(--fs-sm);
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}
.kpi-card__row {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  line-height: 1.8;
}
.kpi-label { color: var(--text-muted); }
.kpi-value { font-weight: 600; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.kpi-pos { color: var(--accent-green); }
.kpi-neg { color: var(--accent-red); }


/* ═══════════════════════════════════════
   Filter Section
   ═══════════════════════════════════════ */
.perps-filters {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--shadow);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  position: relative;
}

.filter-close-btn {
  display: none;
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  width: var(--touch-min);
  height: var(--touch-min);
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.filter-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
}

/* ── Period Chips ── */
.filter-row--period { align-items: center; }

.chip-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: var(--fs-sm);
  font-weight: 600;
  border: 1.5px solid var(--border-lite);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .12s ease;
  user-select: none;
  min-height: 32px;
}
.chip:hover {
  border-color: var(--accent-blue-border);
  background: var(--accent-blue-bg);
  color: var(--accent-blue);
}
.chip.active {
  background: var(--border);
  color: #fff;
  border-color: var(--border);
}
.chip--outline { border-style: dashed; }

/* #3 — Template chips */
.chip--template {
  border-color: var(--accent-purple-border);
  color: var(--accent-purple);
  font-size: var(--fs-xs);
}
.chip--template:hover {
  background: var(--accent-purple-bg);
  border-color: var(--accent-purple);
}

/* ── Custom Range ── */
.custom-range {
  display: flex;
  align-items: center;
  gap: 6px;
  animation: fadeSlideIn .2s ease;
}

.date-input {
  font-family: var(--font);
  font-size: var(--fs-sm);
  padding: 5px 10px;
  border: 1.5px solid var(--border-lite);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
  min-height: var(--touch-min);
}
.date-input:focus { border-color: var(--accent-blue); }

.range-sep { color: var(--text-muted); font-size: var(--fs-base); }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── #3 Templates row ── */
.filter-row--templates { align-items: center; }

/* ── Pickers (Symbol / Metric) ── */
.filter-row--pickers { gap: var(--sp-4); }

.picker {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.picker__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* #4 — Batch action buttons */
.picker__actions {
  display: flex;
  gap: 4px;
}
.picker__action-btn {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border: 1px solid var(--border-lite);
  border-radius: var(--radius-xs);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .12s;
  min-height: 24px;
}
.picker__action-btn:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.picker__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent-blue-bg);
  color: var(--accent-blue);
  border: 1px solid var(--accent-blue-border);
  border-radius: 999px;
}
.picker__count[data-n="0"] {
  background: var(--bg);
  color: var(--text-muted);
  border-color: var(--border-lite);
}

.picker__search {
  font-family: var(--font);
  font-size: var(--fs-base);
  padding: 7px 10px 7px 32px;
  border: 1.5px solid var(--border-lite);
  border-radius: var(--radius-sm);
  background: var(--card-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 10px center;
  outline: none;
  transition: border-color .15s;
  min-height: var(--touch-min);
}
.picker__search:focus { border-color: var(--accent-blue); }

.picker__list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 140px;
  overflow-y: auto;
  padding: var(--sp-1);
  border: 1.5px solid var(--border-lite);
  border-radius: var(--radius-sm);
  background: var(--bg);
  scrollbar-width: thin;
}
.picker__list::-webkit-scrollbar { width: 4px; }
.picker__list::-webkit-scrollbar-thumb { background: var(--border-lite); border-radius: 4px; }

/* #2 — Metric groups */
.metric-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
}
.metric-group__label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 2px 0;
  border-bottom: 1px solid var(--border-lite);
  margin-bottom: 2px;
}
.metric-group__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: var(--fs-sm);
  font-weight: 500;
  font-family: var(--mono);
  border: 1.5px solid var(--border-lite);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .12s ease;
  user-select: none;
  white-space: nowrap;
  min-height: 28px;
}
.tag:hover {
  border-color: var(--accent-purple-border);
  background: var(--accent-purple-bg);
}
.tag.selected {
  background: var(--accent-purple-bg);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
  font-weight: 600;
}
.tag.selected::before {
  content: '✓ ';
  font-size: 10px;
}
.tag[hidden] { display: none; }

/* Metric tags use blue */
.picker--metric .tag.selected {
  background: var(--accent-blue-bg);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

/* #12 — Gap strategy select */
.gap-select {
  font-family: var(--font);
  font-size: var(--fs-xs);
  padding: 3px 8px;
  border: 1px solid var(--border-lite);
  border-radius: var(--radius-xs);
  background: var(--card-bg);
  color: var(--text-secondary);
  outline: none;
  cursor: pointer;
  min-height: 28px;
}
.gap-select:focus { border-color: var(--accent-blue); }

/* ── Filter Actions ── */
.filter-row--actions {
  justify-content: space-between;
  align-items: center;
  padding-top: var(--sp-1);
  border-top: 1px solid var(--border-lite);
}

.filter-actions__left {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.filter-actions__right { display: flex; gap: 8px; }

.filter-hint {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Buttons — #23 unified states */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 600;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .12s ease;
  user-select: none;
  min-height: var(--touch-min);
}

.btn--ghost {
  background: var(--card-bg);
  color: var(--text-secondary);
  border-color: var(--border-lite);
}
.btn--ghost:hover { border-color: var(--border); background: var(--bg); }
.btn--ghost:active { transform: scale(0.97); }

.btn--primary {
  background: var(--border);
  color: #fff;
  box-shadow: 2px 2px 0 var(--shadow);
}
.btn--primary:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--shadow); }
.btn--primary:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--shadow); }


/* ═══════════════════════════════════════
   Chart Panel
   ═══════════════════════════════════════ */
.perps-chart-panel {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--shadow);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border-lite);
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.chart-toolbar__left {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}

.chart-toolbar__title {
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--text-primary);
}

.chart-toolbar__subtitle {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-toolbar__right {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* #9 — Legend search */
.legend-search {
  font-family: var(--font);
  font-size: var(--fs-xs);
  padding: 4px 8px;
  border: 1px solid var(--border-lite);
  border-radius: var(--radius-xs);
  background: var(--card-bg);
  color: var(--text-primary);
  outline: none;
  width: 120px;
  transition: border-color .15s, width .2s;
}
.legend-search:focus { border-color: var(--accent-blue); width: 160px; }

/* Chart Container */
.chart-container {
  height: 520px;
  min-height: 360px;
}

/* State Overlay */
.chart-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(2px);
  z-index: 10;
  transition: opacity .2s;
}
.chart-state[hidden] { display: none; }
.chart-state__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}
.chart-state__text {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-secondary);
  max-width: 400px;
  text-align: center;
  line-height: 1.6;
}

/* Spinner */
.chart-state__spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border-lite);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.chart-state__spinner[hidden] { display: none; }

.chart-state--error .chart-state__text { color: var(--accent-red); }
.chart-state--error .chart-state__spinner {
  border-top-color: var(--accent-red);
  animation: none;
  border-style: dashed;
}
.chart-state--empty .chart-state__text { color: var(--text-muted); }

/* Footer */
.chart-footer {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-1) var(--sp-4);
  border-top: 1px solid var(--border-lite);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
  gap: var(--sp-2);
}


/* ═══════════════════════════════════════
   #27 — Page Footer
   ═══════════════════════════════════════ */
.page-footer {
  display: flex;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-2) 0;
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--mono);
  opacity: 0.6;
}


/* ═══════════════════════════════════════
   Fullscreen mode
   ═══════════════════════════════════════ */
.perps-chart-panel.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  border-radius: 0;
  border: none;
  box-shadow: none;
}
.perps-chart-panel.fullscreen .chart-container {
  height: calc(100vh - 90px);
  height: calc(100dvh - 90px);
}


/* ═══════════════════════════════════════
   #18 — Coverage Modal
   ═══════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop[hidden] { display: none; }

.modal-content {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 6px 6px 0 var(--shadow);
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-lite);
}
.modal-header h3 { font-size: var(--fs-md); font-weight: 700; }
.modal-close {
  width: var(--touch-min);
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
  padding: var(--sp-4);
  overflow: auto;
  font-size: var(--fs-sm);
}

.coverage-table-wrap { overflow-x: auto; }
.coverage-table {
  border-collapse: collapse;
  font-size: var(--fs-xs);
  font-family: var(--mono);
  white-space: nowrap;
}
.coverage-table th, .coverage-table td {
  padding: 4px 8px;
  border: 1px solid var(--border-lite);
  text-align: center;
}
.coverage-table th {
  background: var(--bg);
  font-weight: 700;
  position: sticky;
  top: 0;
}
.cov-sym { text-align: left; font-weight: 600; }
.cov-src {
  font-size: 10px;
  color: var(--text-muted);
}
.cov-ok { background: var(--accent-green-bg); color: var(--accent-green); }
.cov-miss { background: var(--accent-red-bg); color: var(--accent-red); }


/* ═══════════════════════════════════════
   #25 — Mobile: Filter Drawer
   ═══════════════════════════════════════ */
.mobile-filter-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-3);
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 2px 2px 0 var(--shadow);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  min-height: var(--touch-min);
}
.mobile-filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent-blue-bg);
  color: var(--accent-blue);
  border: 1px solid var(--accent-blue-border);
  border-radius: 999px;
}

.filter-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 500;
}
.filter-backdrop.show { display: block; }


/* ═══════════════════════════════════════
   Responsive — #25 mobile drawer + touch targets
   ═══════════════════════════════════════ */
@media (max-width: 640px) {
  .perps-page {
    padding: var(--sp-2) var(--sp-2) var(--sp-4);
    gap: var(--sp-2);
  }

  .perps-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-1);
    padding: var(--sp-2) var(--sp-3);
  }
  .perps-header__right {
    width: 100%;
    justify-content: space-between;
  }

  /* Show mobile toggle, hide desktop filters */
  .mobile-filter-toggle { display: flex; }

  .perps-filters {
    display: none; /* hidden by default on mobile */
    position: fixed;
    inset: 0;
    z-index: 600;
    border-radius: 0;
    border: none;
    box-shadow: none;
    overflow-y: auto;
    padding: var(--sp-6) var(--sp-4) var(--sp-4);
    animation: slideUp .25s ease;
  }
  .perps-filters.drawer-open {
    display: flex;
  }
  .filter-close-btn { display: flex; }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .filter-row--pickers { flex-direction: column; }
  .picker { min-width: 0; }

  /* #25 — Touch targets */
  .chip { padding: 6px 14px; font-size: var(--fs-sm); min-height: var(--touch-min); }
  .tag { padding: 5px 12px; min-height: var(--touch-min); }
  .picker__action-btn { min-height: 36px; padding: 4px 10px; }

  .chart-container { height: 380px; min-height: 280px; }

  .legend-search { width: 90px; }
  .legend-search:focus { width: 120px; }

  .kpi-bar__inner { gap: var(--sp-2); }
  .kpi-card { min-width: 130px; }
}

@media (max-width: 400px) {
  .perps-header__title { font-size: 15px; }
  .chart-container { height: 300px; min-height: 240px; }
  .chip--template { font-size: 10px; }
}


/* ═══════════════════════════════════════
   Theme Switcher Control
   ═══════════════════════════════════════ */
.theme-select {
  font-family: var(--font);
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 4px 8px;
  border: 1.5px solid var(--border-lite);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  min-height: 32px;
  transition: border-color .15s;
}
.theme-select:hover { border-color: var(--accent-blue-border); }
.theme-select:focus { border-color: var(--accent-blue); }


/* ═══════════════════════════════════════
   Theme: Trading Dark
   ═══════════════════════════════════════ */
[data-theme="dark"] {
  --bg: #0B0F19;
  --card-bg: #151B2B;
  --border: #2A3352;
  --border-lite: #2A3352;
  --shadow: #000000;
  --shadow-offset: 2px;

  --accent-green: #34D399;
  --accent-green-bg: rgba(52,211,153,.12);
  --accent-green-border: rgba(52,211,153,.3);
  --accent-yellow: #FBBF24;
  --accent-yellow-bg: rgba(251,191,36,.12);
  --accent-yellow-border: rgba(251,191,36,.3);
  --accent-red: #F87171;
  --accent-red-bg: rgba(248,113,113,.12);
  --accent-red-border: rgba(248,113,113,.3);
  --accent-blue: #60A5FA;
  --accent-blue-bg: rgba(96,165,250,.12);
  --accent-blue-border: rgba(96,165,250,.3);
  --accent-purple: #A78BFA;
  --accent-purple-bg: rgba(167,139,250,.12);
  --accent-purple-border: rgba(167,139,250,.3);

  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #64748B;
}

[data-theme="dark"] body { background: var(--bg); color: var(--text-primary); }
[data-theme="dark"] .chart-state { background: rgba(11, 15, 25, .88); }
[data-theme="dark"] .chip.active { background: var(--accent-blue); color: #0B0F19; border-color: var(--accent-blue); }
[data-theme="dark"] .btn--primary { background: var(--accent-blue); color: #0B0F19; box-shadow: 2px 2px 0 rgba(0,0,0,.4); }
[data-theme="dark"] .picker__search {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
}
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.6); }
[data-theme="dark"] .coverage-table th { background: #1E293B; }


/* ═══════════════════════════════════════
   Theme: Colorblind Safe
   ═══════════════════════════════════════ */
[data-theme="colorblind"] {
  --accent-green: #228833;
  --accent-green-bg: #E8F5E9;
  --accent-green-border: #81C784;
  --accent-red: #AA3377;
  --accent-red-bg: #FCE4EC;
  --accent-red-border: #F48FB1;
  --accent-blue: #4477AA;
  --accent-blue-bg: #E3F2FD;
  --accent-blue-border: #90CAF9;
  --accent-yellow: #CCBB44;
  --accent-yellow-bg: #FFF9C4;
  --accent-yellow-border: #FFF176;
  --accent-purple: #AA3377;
  --accent-purple-bg: #F3E5F5;
  --accent-purple-border: #CE93D8;
}
