/**
 * CuanBot UI component layer (PHASE 0)
 *
 * NAMESPACE RULE: All custom properties use --tb-* only. All component classes use .tb-*.
 * Scoped on .tb-ui; :root mirrors tokens for tooling. No element/type selectors, no global resets.
 * Safe to load alongside legacy pages — does not style anything outside .tb-ui unless a .tb-* class is used.
 */

/* ----- Tokens (:root + .tb-ui) ----- */
:root,
.tb-ui {
  --tb-bg-0: #07090f;
  --tb-bg-1: #0c111b;
  --tb-bg-2: #121a28;
  --tb-bg-3: #18233a;
  --tb-line: #1f2a40;
  --tb-line-2: #2a3858;
  --tb-tx-1: #e8edf6;
  --tb-tx-2: #a7b3c9;
  --tb-tx-3: #a3b4cc;
  --tb-pos: #22c55e;
  --tb-pos-bg: rgba(34, 197, 94, 0.12);
  --tb-neg: #f43f5e;
  --tb-neg-bg: rgba(244, 63, 94, 0.12);
  --tb-warn: #f59e0b;
  --tb-warn-bg: rgba(245, 158, 11, 0.12);
  --tb-info: #38bdf8;
  --tb-info-bg: rgba(56, 189, 248, 0.12);
  --tb-live: #ef4444;
  --tb-live-bg: rgba(239, 68, 68, 0.15);
  --tb-paper: #a78bfa;
  --tb-paper-bg: rgba(167, 139, 250, 0.14);
  --tb-shadow: #38bdf8;
  --tb-shadow-bg: rgba(56, 189, 248, 0.14);
  --tb-accent: #6366f1;
  --tb-accent-bg: rgba(99, 102, 241, 0.14);
  --tb-f-ui: "Inter var", "Segoe UI", system-ui, -apple-system, sans-serif;
  --tb-f-num: "JetBrains Mono var", ui-monospace, "SF Mono", monospace;
  --tb-t-xs: 11px;
  --tb-t-sm: 13px;
  --tb-t-md: 15px;
  --tb-t-lg: 20px;
  --tb-t-xl: 28px;
  --tb-t-2xl: 40px;
  --tb-s-1: 4px;
  --tb-s-2: 8px;
  --tb-s-3: 12px;
  --tb-s-4: 16px;
  --tb-s-5: 24px;
  --tb-s-6: 32px;
  --tb-r-sm: 6px;
  --tb-r-md: 10px;
  --tb-r-lg: 14px;
  --tb-focus-ring: 0 0 0 2px var(--tb-bg-0), 0 0 0 4px var(--tb-accent);
  --tb-z-base: 1;
  --tb-z-sticky: 10;
  --tb-z-nav: 40;
  --tb-z-modal: 50;
  --tb-z-toast: 60;
  --tb-motion-fast: 150ms ease;
  --tb-motion-normal: 250ms ease;
}

@font-face {
  font-family: "Inter var";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono var";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --tb-motion-fast: 0ms;
    --tb-motion-normal: 0ms;
  }
  .tb-ui {
    --tb-motion-fast: 0ms;
    --tb-motion-normal: 0ms;
  }
}

/* ----- Scope shell ----- */
.tb-ui {
  box-sizing: border-box;
  background: var(--tb-bg-0);
  color: var(--tb-tx-1);
  font: var(--tb-t-sm) / 1.5 var(--tb-f-ui);
}

/* ----- Utilities ----- */
.tb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tb-num {
  font-family: var(--tb-f-num);
  font-variant-numeric: tabular-nums;
}

.tb-stack {
  display: flex;
  flex-direction: column;
  gap: var(--tb-s-3);
}

.tb-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tb-s-2);
}

.tb-grid {
  display: grid;
  gap: var(--tb-s-4);
}

.tb-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tb-grid--auto {
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
}

/* ----- Card ----- */
.tb-card {
  min-width: 0;
  background: var(--tb-bg-1);
  border: 1px solid var(--tb-line);
  border-radius: var(--tb-r-lg);
  overflow: hidden;
}

.tb-card__head {
  padding: var(--tb-s-3) var(--tb-s-4);
  border-bottom: 1px solid var(--tb-line);
  font-size: var(--tb-t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tb-tx-2);
  display: flex;
  align-items: center;
  gap: var(--tb-s-2);
}

.tb-card__body {
  padding: var(--tb-s-4);
}

/* ----- Badges ----- */
.tb-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--tb-t-xs);
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 99px;
  letter-spacing: 0.04em;
  line-height: 1.3;
  border: 1px solid transparent;
}

.tb-badge--live {
  background: var(--tb-live-bg);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.45);
}

.tb-badge--paper {
  background: var(--tb-paper-bg);
  color: var(--tb-paper);
  border-color: rgba(167, 139, 250, 0.4);
}

.tb-badge--shadow {
  background: var(--tb-shadow-bg);
  color: var(--tb-shadow);
  border-color: rgba(56, 189, 248, 0.4);
}

.tb-badge--off {
  background: var(--tb-bg-3);
  color: var(--tb-tx-3);
}

.tb-badge--pos {
  background: var(--tb-pos-bg);
  color: var(--tb-pos);
}

.tb-badge--neg {
  background: var(--tb-neg-bg);
  color: var(--tb-neg);
}

.tb-badge--warn {
  background: var(--tb-warn-bg);
  color: var(--tb-warn);
}

.tb-badge--info {
  background: var(--tb-info-bg);
  color: var(--tb-info);
}

/* ----- Buttons ----- */
.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tb-s-2);
  border: 1px solid var(--tb-line-2);
  background: var(--tb-bg-2);
  color: var(--tb-tx-1);
  padding: 7px 12px;
  border-radius: var(--tb-r-sm);
  font: 600 var(--tb-t-sm) var(--tb-f-ui);
  cursor: pointer;
  transition: background var(--tb-motion-fast), border-color var(--tb-motion-fast);
}

.tb-btn:hover:not(:disabled) {
  background: var(--tb-bg-3);
}

.tb-btn:focus-visible {
  outline: none;
  box-shadow: var(--tb-focus-ring);
}

.tb-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tb-btn--primary {
  background: var(--tb-accent-bg);
  border-color: rgba(99, 102, 241, 0.55);
  color: #c7d2fe;
}

.tb-btn--danger {
  border-color: rgba(244, 63, 94, 0.5);
  color: #fda4af;
  background: rgba(244, 63, 94, 0.08);
}

.tb-btn--ghost {
  background: transparent;
  border-color: var(--tb-line);
}

.tb-btn--sm {
  padding: 4px 8px;
  font-size: var(--tb-t-xs);
}

/* ----- Toggle (checkbox switch) ----- */
.tb-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  min-height: 24px;
}

.tb-toggle__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.tb-toggle__track {
  width: 42px;
  height: 24px;
  border-radius: 99px;
  background: var(--tb-bg-3);
  border: 1px solid var(--tb-line-2);
  position: relative;
  transition: background var(--tb-motion-fast), border-color var(--tb-motion-fast);
}

.tb-toggle__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--tb-tx-3);
  transition: transform var(--tb-motion-fast), background var(--tb-motion-fast);
}

.tb-toggle__input:focus-visible + .tb-toggle__track {
  box-shadow: var(--tb-focus-ring);
}

.tb-toggle__input:checked + .tb-toggle__track {
  background: rgba(34, 197, 94, 0.25);
  border-color: rgba(34, 197, 94, 0.6);
}

.tb-toggle__input:checked + .tb-toggle__track::after {
  transform: translateX(18px);
  background: var(--tb-pos);
}

/* ----- KPI ----- */
.tb-kpi {
  background: var(--tb-bg-2);
  border: 1px solid var(--tb-line);
  border-radius: var(--tb-r-md);
  padding: var(--tb-s-3);
  min-width: 0;
}

.tb-kpi__label {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tb-kpi__value {
  font-size: var(--tb-t-lg);
  font-weight: 700;
  margin-top: var(--tb-s-1);
}

.tb-kpi__hint {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  margin-top: var(--tb-s-1);
}

/* ----- NET PnL hero ----- */
.tb-pnl {
  padding: var(--tb-s-5);
  background: radial-gradient(120% 140% at 0% 0%, rgba(34, 197, 94, 0.1), transparent 60%), var(--tb-bg-1);
  border: 1px solid var(--tb-line);
  border-radius: var(--tb-r-lg);
}

.tb-pnl__label {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tb-pnl__net {
  font-size: var(--tb-t-2xl);
  font-weight: 800;
  margin: 6px 0 2px;
}

.tb-pnl__net--pos {
  color: var(--tb-pos);
}

.tb-pnl__net--neg {
  color: var(--tb-neg);
}

.tb-pnl__net--zero {
  color: var(--tb-tx-2);
}

.tb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tb-pnl__sub {
  font-size: var(--tb-t-sm);
  color: var(--tb-tx-2);
}

.tb-pnl__breakdown {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  margin-top: var(--tb-s-3);
  border-top: 1px dashed var(--tb-line-2);
  padding-top: var(--tb-s-2);
}

.tb-pnl__mini {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-s-4);
  margin-top: var(--tb-s-4);
  padding-top: var(--tb-s-3);
  border-top: 1px solid var(--tb-line);
}

.tb-pnl__mini-item {
  min-width: 0;
  flex: 1 1 6rem;
}

.tb-pnl__mini-label {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tb-pnl__mini-value {
  font-size: var(--tb-t-sm);
  font-weight: 700;
  margin-top: 2px;
}

.tb-pnl__spread-note {
  display: block;
  margin-top: var(--tb-s-2);
  font-size: 10px;
  color: var(--tb-tx-3);
  line-height: 1.4;
}

.tb-dash-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--tb-s-4);
  margin-bottom: var(--tb-s-4);
  min-width: 0;
}

.tb-dash-secondary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--tb-s-3);
  align-content: start;
}

.tb-collapse {
  margin-bottom: var(--tb-s-4);
  border: 1px solid var(--tb-line);
  border-radius: var(--tb-r-lg);
  background: var(--tb-bg-1);
  min-width: 0;
  overflow: hidden;
}

.tb-collapse > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--tb-s-3) var(--tb-s-4);
  font-size: var(--tb-t-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tb-tx-2);
  border-bottom: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tb-s-2);
  user-select: none;
}

.tb-collapse > summary::-webkit-details-marker {
  display: none;
}

.tb-collapse > summary::after {
  content: "▸";
  color: var(--tb-tx-3);
  transition: transform var(--tb-motion-fast);
}

.tb-collapse[open] > summary {
  border-bottom-color: var(--tb-line);
}

.tb-collapse[open] > summary::after {
  transform: rotate(90deg);
}

.tb-collapse__body {
  min-width: 0;
}

.tb-collapse__body > .card {
  border: none;
  border-radius: 0;
  margin-bottom: 0 !important;
}

@media (max-width: 900px) {
  .tb-dash-hero {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ----- Mode strip ----- */
.tb-modestrip {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 6px var(--tb-s-5);
  font-size: var(--tb-t-xs);
  letter-spacing: 0.04em;
  border-bottom: 1px solid transparent;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--tb-z-nav);
}

.tb-modestrip--live {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.25), rgba(239, 68, 68, 0.05));
  border-bottom-color: rgba(239, 68, 68, 0.4);
}

.tb-modestrip--paper {
  background: linear-gradient(90deg, rgba(167, 139, 250, 0.22), rgba(167, 139, 250, 0.05));
  border-bottom-color: rgba(167, 139, 250, 0.4);
}

.tb-modestrip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.tb-modestrip--live .tb-modestrip__dot {
  background: var(--tb-live);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

.tb-modestrip--paper .tb-modestrip__dot {
  background: var(--tb-paper);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.25);
}

.tb-modestrip__label {
  flex-shrink: 0;
  font-weight: 700;
  white-space: nowrap;
}

.tb-modestrip__chips {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tb-modestrip__chips:focus-visible {
  outline: 2px solid var(--tb-accent);
  outline-offset: 2px;
  border-radius: var(--tb-r-sm);
}

.tb-modestrip__chips::-webkit-scrollbar {
  display: none;
}

.tb-modestrip__chip {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--tb-tx-2);
}

.tb-modestrip--live .tb-modestrip__chip--strategy {
  border-color: rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.tb-modestrip--paper .tb-modestrip__chip--sim {
  border-color: rgba(167, 139, 250, 0.45);
  color: #ddd6fe;
}

.tb-modestrip__chip--guard {
  border-color: rgba(59, 130, 246, 0.35);
  color: #bfdbfe;
}

.tb-diff__group-title {
  font-size: var(--tb-t-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tb-tx-3);
  margin: var(--tb-s-3) 0 var(--tb-s-2);
}

.tb-diff__group-title:first-child {
  margin-top: 0;
}

/* ----- Table ----- */
.tb-table-wrap {
  overflow-x: auto;
  min-width: 0;
}

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

.tb-table thead th {
  position: sticky;
  top: 0;
  z-index: var(--tb-z-sticky);
  background: var(--tb-bg-1);
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--tb-line);
}

.tb-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--tb-line);
  font-size: var(--tb-t-sm);
}

.tb-table .tb-table__num,
.tb-table th.tb-table__num {
  text-align: right;
}

/* ----- Meter (daily loss) ----- */
.tb-meter {
  height: 6px;
  background: var(--tb-bg-3);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}

.tb-meter__fill {
  display: block;
  height: 100%;
  background: var(--tb-warn);
  border-radius: 99px;
  transition: width var(--tb-motion-normal);
}

.tb-meter__fill--danger {
  background: var(--tb-neg);
}

/* ----- Diff block ----- */
.tb-diff {
  background: var(--tb-bg-2);
  border-radius: var(--tb-r-sm);
  padding: var(--tb-s-3);
  font-size: var(--tb-t-xs);
  font-family: var(--tb-f-num);
}

.tb-diff__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--tb-s-2);
  padding: 4px 0;
  border-bottom: 1px solid var(--tb-line);
}

.tb-diff__row:last-child {
  border-bottom: 0;
}

.tb-diff__key {
  color: var(--tb-tx-2);
}

.tb-diff__old {
  color: var(--tb-tx-3);
  text-decoration: line-through;
}

.tb-diff__new {
  color: var(--tb-tx-1);
  font-weight: 600;
}

.tb-diff__row--live-impact {
  background: rgba(239, 68, 68, 0.08);
  border-radius: var(--tb-r-sm);
  padding: 6px var(--tb-s-2);
  margin: 2px 0;
}

/* ----- Summary block (confirm dialogs) ----- */
.tb-summary {
  background: var(--tb-bg-2);
  border-radius: var(--tb-r-sm);
  padding: var(--tb-s-3);
  font-size: var(--tb-t-sm);
  margin-top: var(--tb-s-2);
}

.tb-summary__row {
  display: grid;
  grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
  gap: var(--tb-s-2);
  padding: 6px 0;
  border-bottom: 1px solid var(--tb-line);
  align-items: baseline;
}

.tb-summary__row:last-child {
  border-bottom: 0;
}

.tb-summary__label {
  color: var(--tb-tx-2);
  font-size: var(--tb-t-xs);
}

.tb-summary__value {
  color: var(--tb-tx-1);
  font-family: var(--tb-f-num);
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

.tb-summary__row--pos .tb-summary__value {
  color: var(--tb-pos);
}

.tb-summary__row--neg .tb-summary__value {
  color: var(--tb-neg);
}

.tb-summary__row--warn .tb-summary__value {
  color: var(--tb-warn);
}

/* ----- Modal (structure; visibility via .tb-modal--open on backdrop) ----- */
.tb-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 10, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--tb-z-modal);
  padding: var(--tb-s-4);
}

.tb-modal-backdrop.tb-modal--open {
  display: flex;
}

.tb-modal {
  width: min(460px, 92vw);
  background: var(--tb-bg-1);
  border: 1px solid var(--tb-line-2);
  border-radius: var(--tb-r-lg);
  padding: var(--tb-s-5);
  max-height: 90vh;
  overflow: auto;
}

.tb-modal--danger {
  border-color: rgba(239, 68, 68, 0.5);
}

.tb-modal__title {
  margin: 0 0 var(--tb-s-2);
  font-size: var(--tb-t-md);
  font-weight: 700;
}

.tb-modal__message {
  margin: 0 0 var(--tb-s-3);
  color: var(--tb-tx-2);
  font-size: var(--tb-t-sm);
  white-space: pre-line;
}

.tb-modal__input {
  width: 100%;
  background: var(--tb-bg-2);
  border: 1px solid var(--tb-line-2);
  color: var(--tb-tx-1);
  padding: 9px;
  border-radius: var(--tb-r-sm);
  font: var(--tb-t-sm) var(--tb-f-num);
}

.tb-modal__input:focus-visible {
  outline: none;
  box-shadow: var(--tb-focus-ring);
}

.tb-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--tb-s-2);
  margin-top: var(--tb-s-4);
}

/* ----- Toast ----- */
.tb-toast-host {
  position: fixed;
  right: var(--tb-s-4);
  bottom: var(--tb-s-4);
  z-index: var(--tb-z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--tb-s-2);
  pointer-events: none;
  max-width: min(360px, 92vw);
}

.tb-toast {
  pointer-events: auto;
  padding: var(--tb-s-3) var(--tb-s-4);
  border-radius: var(--tb-r-md);
  border: 1px solid var(--tb-line-2);
  background: var(--tb-bg-2);
  color: var(--tb-tx-1);
  font-size: var(--tb-t-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: tb-toast-in var(--tb-motion-normal);
}

.tb-toast--pos {
  border-color: rgba(34, 197, 94, 0.45);
  background: var(--tb-pos-bg);
}

.tb-toast--neg {
  border-color: rgba(244, 63, 94, 0.45);
  background: var(--tb-neg-bg);
}

.tb-toast--warn {
  border-color: rgba(245, 158, 11, 0.45);
  background: var(--tb-warn-bg);
}

.tb-toast--info {
  border-color: rgba(56, 189, 248, 0.45);
  background: var(--tb-info-bg);
}

@keyframes tb-toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ----- Nav skeleton ----- */
.tb-nav-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.tb-nav-side {
  background: var(--tb-bg-1);
  border-right: 1px solid var(--tb-line);
  padding: var(--tb-s-4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.tb-nav-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 800;
  font-size: var(--tb-t-md);
  margin-bottom: var(--tb-s-5);
}

.tb-nav-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: conic-gradient(from 200deg, #22c55e, #6366f1, #22c55e);
}

.tb-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tb-nav-link {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--tb-r-sm);
  color: var(--tb-tx-2);
  text-decoration: none;
  font-weight: 500;
}

.tb-nav-link:hover {
  background: var(--tb-bg-2);
  color: var(--tb-tx-1);
}

.tb-nav-link--active {
  background: var(--tb-bg-3);
  color: var(--tb-tx-1);
}

.tb-nav-grp {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: var(--tb-s-4) 10px var(--tb-s-1);
}

.tb-nav-main {
  padding: var(--tb-s-5) var(--tb-s-6);
  max-width: 1280px;
  min-width: 0;
}

.tb-nav-bottom {
  display: none;
}

/* ----- Responsive table → cards ----- */
@media (max-width: 639px) {
  .tb-nav-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .tb-nav-side {
    display: none;
  }

  .tb-nav-main {
    padding: var(--tb-s-4) var(--tb-s-3) 84px;
  }

  .tb-nav-bottom {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--tb-bg-1);
    border-top: 1px solid var(--tb-line);
    padding: 6px 0 10px;
    z-index: var(--tb-z-nav);
  }

  .tb-nav-bottom__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    color: var(--tb-tx-3);
    text-decoration: none;
    gap: 2px;
  }

  .tb-nav-bottom__item--active {
    color: var(--tb-tx-1);
  }

  .tb-table--stack thead,
  .tb-table--stack tr:has(> th) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .tb-table--stack tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--tb-s-1);
    padding: var(--tb-s-3) 0;
    border-bottom: 1px solid var(--tb-line);
  }

  .tb-table--stack td {
    border: 0;
    padding: 2px 0;
  }

  .tb-table--stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--tb-t-xs);
    color: var(--tb-tx-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .tb-table--stack td.tb-table__hide-sm {
    display: none;
  }

  .tb-modestrip {
    padding: 6px 0 6px var(--tb-s-3);
    flex-wrap: nowrap;
    max-width: 100vw;
    overflow: visible;
  }

  .tb-pnl__net {
    font-size: 34px;
  }
}

/* ----- Shared navigation (PHASE 2) ----- */
.tb-topbar {
  display: flex;
  align-items: center;
  gap: var(--tb-s-3);
  padding: var(--tb-s-2) var(--tb-s-4);
  min-height: 48px;
  background: var(--tb-bg-1);
  border-bottom: 1px solid var(--tb-line);
  position: sticky;
  top: var(--tb-strip-h, 30px);
  z-index: calc(var(--tb-z-nav) - 2);
  box-sizing: border-box;
}

.tb-topbar__brand {
  display: none;
  align-items: center;
  gap: var(--tb-s-2);
  color: var(--tb-tx-1);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--tb-t-sm);
  flex-shrink: 0;
}

.tb-topbar__brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--tb-r-sm);
  background: linear-gradient(135deg, var(--tb-accent), #4338ca);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tb-topbar__meta {
  display: flex;
  align-items: center;
  gap: var(--tb-s-3);
  margin-left: auto;
  min-width: 0;
  flex-shrink: 1;
}

.tb-topbar__conn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
}

.tb-topbar__conn .conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tb-warn);
  flex-shrink: 0;
}

.tb-topbar__user {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.tb-topbar__title {
  font-size: var(--tb-t-md);
  font-weight: 700;
  color: var(--tb-tx-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.tb-sidenav {
  display: none;
}

.tb-bottomnav {
  display: none;
}

.tb-sheet {
  display: none;
}

.tb-sheet__backdrop {
  display: none;
}

.tb-has-sidenav,
.tb-has-bottomnav {
  padding-top: var(--tb-strip-h, 30px);
}

@media (min-width: 1024px) {
  .tb-has-sidenav {
    --tb-sidenav-w: 240px;
    padding-left: var(--tb-sidenav-w);
  }

  .tb-has-sidenav.tb-nav-collapsed {
    --tb-sidenav-w: 64px;
  }

  .tb-sidenav {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: var(--tb-strip-h, 30px);
    bottom: 0;
    width: var(--tb-sidenav-w, 240px);
    z-index: calc(var(--tb-z-nav) - 1);
    background: var(--tb-bg-1);
    border-right: 1px solid var(--tb-line);
    box-sizing: border-box;
    transition: width var(--tb-motion-normal);
  }

  .tb-nav-collapsed .tb-sidenav {
    width: 64px;
  }

  .tb-sidenav__head {
    display: flex;
    align-items: center;
    gap: var(--tb-s-2);
    padding: var(--tb-s-3);
    border-bottom: 1px solid var(--tb-line);
    min-height: 52px;
    box-sizing: border-box;
  }

  .tb-sidenav__brand {
    display: flex;
    align-items: center;
    gap: var(--tb-s-2);
    color: var(--tb-tx-1);
    text-decoration: none;
    font-weight: 700;
    font-size: var(--tb-t-sm);
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }

  .tb-sidenav__brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--tb-r-sm);
    background: linear-gradient(135deg, var(--tb-accent), #4338ca);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .tb-sidenav__brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tb-nav-collapsed .tb-sidenav__brand-text {
    display: none;
  }

  .tb-sidenav__collapse {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 1px solid var(--tb-line-2);
    border-radius: var(--tb-r-sm);
    background: var(--tb-bg-2);
    color: var(--tb-tx-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .tb-sidenav__collapse:focus-visible {
    outline: none;
    box-shadow: var(--tb-focus-ring);
  }

  .tb-sidenav__scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--tb-s-2) 0 var(--tb-s-4);
  }

  .tb-sidenav__group {
    padding: var(--tb-s-2) var(--tb-s-3);
  }

  .tb-sidenav__group-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--tb-tx-3);
    margin: 0 0 var(--tb-s-2) var(--tb-s-1);
  }

  .tb-nav-collapsed .tb-sidenav__group-title {
    display: none;
  }

  .tb-sidenav__item {
    display: flex;
    align-items: center;
    gap: var(--tb-s-3);
    padding: var(--tb-s-2) var(--tb-s-3);
    margin-bottom: 2px;
    border-radius: var(--tb-r-sm);
    color: var(--tb-tx-2);
    text-decoration: none;
    font-size: var(--tb-t-sm);
    border: 1px solid transparent;
    background: transparent;
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
  }

  .tb-sidenav__item:hover {
    background: var(--tb-bg-2);
    color: var(--tb-tx-1);
  }

  .tb-sidenav__item[aria-current="page"] {
    background: var(--tb-accent-bg);
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--tb-tx-1);
  }

  .tb-sidenav__item:focus-visible {
    outline: none;
    box-shadow: var(--tb-focus-ring);
  }

  .tb-sidenav__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tb-sidenav__icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .tb-sidenav__label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
  }

  .tb-nav-collapsed .tb-sidenav__label,
  .tb-nav-collapsed .tb-sidenav__badges {
    display: none;
  }

  .tb-nav-collapsed .tb-sidenav__item {
    justify-content: center;
    padding-left: var(--tb-s-2);
    padding-right: var(--tb-s-2);
  }

  .tb-sidenav__badges {
    display: flex;
    flex-wrap: nowrap;
    gap: 3px;
    flex-shrink: 0;
  }

  .tb-sidenav__badges .tb-badge {
    font-size: 10px;
    padding: 1px 5px;
    letter-spacing: 0.02em;
    line-height: 1.2;
  }

  .tb-nav-collapsed .tb-sidenav__collapse svg {
    transform: rotate(180deg);
  }

  .tb-topbar__brand {
    display: none;
  }
}

@media (max-width: 1023px) {
  .tb-has-bottomnav {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .tb-topbar__brand {
    display: flex;
  }

  .tb-topbar__title {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .tb-bottomnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--tb-z-nav);
    background: var(--tb-bg-1);
    border-top: 1px solid var(--tb-line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    min-height: 64px;
    box-sizing: border-box;
  }

  .tb-bottomnav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--tb-s-1) var(--tb-s-1);
    color: var(--tb-tx-2);
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    background: transparent;
    border: 0;
    cursor: pointer;
    font-family: inherit;
  }

  .tb-bottomnav__item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .tb-bottomnav__item[aria-current="page"],
  .tb-bottomnav__item.is-active {
    color: #c4b5fd;
  }

  .tb-bottomnav__item:focus-visible {
    outline: none;
    box-shadow: var(--tb-focus-ring);
  }

  .tb-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(85vh, 520px);
    z-index: var(--tb-z-modal);
    background: var(--tb-bg-2);
    border-top: 1px solid var(--tb-line-2);
    border-radius: var(--tb-r-lg) var(--tb-r-lg) 0 0;
    transform: translateY(100%);
    transition: transform var(--tb-motion-normal);
    overflow: hidden;
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .tb-sheet.is-open {
    transform: translateY(0);
  }

  .tb-sheet__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: calc(var(--tb-z-modal) - 1);
    background: rgba(7, 9, 15, 0.65);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--tb-motion-normal);
  }

  .tb-sheet__backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .tb-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--tb-s-3) var(--tb-s-4);
    border-bottom: 1px solid var(--tb-line);
  }

  .tb-sheet__title {
    font-size: var(--tb-t-md);
    font-weight: 700;
    color: var(--tb-tx-1);
  }

  .tb-sheet__body {
    overflow-y: auto;
    max-height: calc(min(85vh, 520px) - 52px);
    padding: var(--tb-s-2) 0 var(--tb-s-4);
  }

  .tb-sheet .tb-sidenav__group {
    padding: var(--tb-s-2) var(--tb-s-4);
  }

  .tb-sheet .tb-sidenav__item {
    display: flex;
    align-items: center;
    gap: var(--tb-s-3);
    padding: var(--tb-s-3) var(--tb-s-3);
    margin-bottom: 2px;
    border-radius: var(--tb-r-sm);
    color: var(--tb-tx-2);
    text-decoration: none;
    font-size: var(--tb-t-sm);
    border: 1px solid transparent;
    background: transparent;
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
  }

  .tb-sheet .tb-sidenav__item[aria-current="page"],
  .tb-sheet .tb-sidenav__item.is-current {
    background: var(--tb-accent-bg);
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--tb-tx-1);
  }

  .tb-sheet .tb-sidenav__item:focus-visible {
    outline: none;
    box-shadow: var(--tb-focus-ring);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tb-sidenav,
  .tb-sheet,
  .tb-sheet__backdrop {
    transition: none;
  }
}

/* ----- Strategies page ----- */
.tb-strat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--tb-s-4);
}

@media (min-width: 1024px) {
  .tb-strat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1440px) {
  .tb-strat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tb-strat-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tb-s-3);
  text-transform: none;
  letter-spacing: normal;
}

.tb-strat-card__head > .tb-toggle {
  flex: 0 0 auto;
  margin-top: 0;
}

.tb-strat-card__title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px var(--tb-s-2);
  min-width: 0;
  flex: 1 1 0;
}

.tb-strat-card__label {
  font-size: var(--tb-t-md);
  font-weight: 700;
  text-transform: none;
  letter-spacing: normal;
  color: var(--tb-tx-1);
  margin: 0;
  flex: 0 1 auto;
  max-width: 100%;
  line-height: 1.3;
}

.tb-strat-card__title > .tb-badge {
  flex: 0 0 auto;
  white-space: nowrap;
}

.tb-strat-param {
  list-style: none;
  margin: 0 0 var(--tb-s-3);
  padding: 0;
  font-size: var(--tb-t-sm);
}

.tb-strat-param li {
  display: flex;
  justify-content: space-between;
  gap: var(--tb-s-2);
  padding: 4px 0;
  border-bottom: 1px solid var(--tb-line);
}

.tb-strat-param__label {
  color: var(--tb-tx-3);
}

.tb-strat-param__value {
  color: var(--tb-tx-1);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.tb-strat-param__value--warn {
  color: var(--tb-warn, #fbbf24);
}

.tb-strat-stat {
  font-size: var(--tb-t-sm);
  color: var(--tb-tx-2);
  margin: 4px 0;
}

.tb-strat-banner {
  font-size: var(--tb-t-xs);
  padding: 8px 10px;
  border-radius: var(--tb-r-sm);
  margin-bottom: var(--tb-s-2);
  line-height: 1.4;
}

.tb-strat-banner--warn {
  background: var(--tb-warn-bg);
  color: var(--tb-warn);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.tb-strat-banner--info {
  background: var(--tb-info-bg);
  color: var(--tb-info);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.tb-strat-banner--neutral {
  background: var(--tb-bg-3);
  color: var(--tb-tx-2);
  border: 1px solid var(--tb-line);
}

.tb-strat-banner--muted {
  background: var(--tb-bg-3);
  color: var(--tb-tx-3);
  border: 1px solid var(--tb-line-2);
  font-size: var(--tb-t-xs);
}

.tb-strat-guards {
  margin-top: var(--tb-s-3);
  padding-top: var(--tb-s-2);
  border-top: 1px dashed var(--tb-line-2);
}

.tb-strat-guards__title {
  font-size: var(--tb-t-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tb-tx-3);
  margin-bottom: var(--tb-s-2);
}

.tb-strat-guards__list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: var(--tb-t-xs);
}

.tb-strat-guards__list li {
  display: flex;
  justify-content: space-between;
  gap: var(--tb-s-2);
  padding: 4px 0;
}

.tb-strat-guard__label {
  color: var(--tb-tx-3);
}

.tb-strat-guard__value {
  color: var(--tb-tx-2);
  text-align: right;
}

.tb-strat-guard__value--warn {
  color: var(--tb-warn);
}

.tb-strat-note {
  font-size: var(--tb-t-xs);
  color: var(--tb-tx-3);
  margin-bottom: var(--tb-s-2);
}

.tb-strat-note--warn {
  color: var(--tb-warn);
}

.tb-strat-subs {
  margin-top: var(--tb-s-3);
  padding-top: var(--tb-s-3);
  border-top: 1px dashed var(--tb-line-2);
}

.tb-strat-subs__title {
  font-size: var(--tb-t-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tb-tx-3);
  margin-bottom: var(--tb-s-2);
}

.tb-strat-subs__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tb-strat-subs__name {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tb-strat-opt-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--tb-tx-2);
  background: rgba(148, 163, 184, 0.18);
  border: 1px solid rgba(148, 163, 184, 0.35);
  white-space: nowrap;
}

.tb-strat-opt-effective {
  display: block;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--tb-info);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tb-strat-subs__left {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tb-strat-card__toggle-block {
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(100%, 14rem);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.tb-toggle--optimizer-override .tb-toggle__track {
  opacity: 0.55;
  outline: 1px dashed rgba(148, 163, 184, 0.65);
  outline-offset: 2px;
}

.tb-strat-subs__item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--tb-s-2);
  padding: 6px 0;
  font-size: var(--tb-t-sm);
}

@media (max-width: 480px) {
  .tb-strat-card__head {
    flex-wrap: wrap;
  }

  .tb-strat-card__toggle-block {
    width: 100%;
    max-width: 100%;
    align-items: flex-start;
  }
}

.tb-strat-loading,
.tb-strat-empty {
  color: var(--tb-tx-3);
  font-size: var(--tb-t-sm);
  padding: var(--tb-s-4);
  text-align: center;
  grid-column: 1 / -1;
}

.tb-toggle--sm .tb-toggle__track {
  width: 36px;
  height: 20px;
}

.tb-toggle--sm .tb-toggle__track::after {
  width: 14px;
  height: 14px;
}

.tb-toggle--sm .tb-toggle__input:checked + .tb-toggle__track::after {
  transform: translateX(16px);
}

/* Dashboard strategy chip row */
.tb-dash-strategies {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border, var(--tb-line));
  font-size: 11px;
}

.tb-dash-strategies__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 99px;
  background: var(--tb-bg-3, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--tb-line, rgba(255, 255, 255, 0.06));
  color: var(--text-secondary, var(--tb-tx-2));
}

.tb-dash-strategies__link {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue, #3b82f6);
  text-decoration: none;
}

.tb-dash-strategies__link:hover {
  text-decoration: underline;
}

/* ----- Settings page (PHASE 5) ----- */
.tb-settings-page {
  font-family: var(--tb-f-ui, "Segoe UI", system-ui, sans-serif);
  background: var(--tb-bg-0, #0a0e17);
  color: var(--tb-tx-1, #f1f5f9);
  min-height: 100vh;
  overflow-x: clip;
  max-width: 100vw;
}

.tb-settings-container {
  max-width: 100%;
  margin: 0 auto;
  padding: 24px;
  padding-bottom: 80px;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

.tb-settings-page .page-header {
  margin-bottom: 24px;
}

.tb-settings-page .page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.tb-settings-page .page-header p {
  font-size: 14px;
  color: var(--tb-tx-3, #a3b4cc);
}

.tb-settings-page .settings-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  min-width: 0;
}

.tb-settings-page .settings-content {
  min-width: 0;
}

.tb-settings-page .settings-nav {
  align-self: start;
  z-index: var(--tb-z-sticky, 10);
}

@media (min-width: 1024px) {
  .tb-settings-page {
    --tb-settings-sticky-top: calc(var(--tb-strip-h, 30px) + 48px);
  }

  .tb-settings-container {
    max-width: 1224px;
  }

  .tb-settings-page .settings-layout {
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 24px;
  }

  .tb-settings-page .settings-content {
    max-width: 960px;
  }

  .tb-settings-page .settings-nav {
    position: sticky;
    top: var(--tb-settings-sticky-top);
    width: 240px;
    max-height: calc(100vh - var(--tb-settings-sticky-top) - 16px);
    overflow-y: auto;
  }
}

.tb-settings-page .settings-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--tb-tx-3, #a3b4cc);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}

.tb-settings-page .settings-nav a:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--tb-tx-2, #94a3b8);
}

.tb-settings-page .settings-nav a.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--tb-tx-1, #f1f5f9);
  font-weight: 600;
}

.tb-settings-page .sidebar-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.tb-settings-page .settings-group {
  background: var(--tb-bg-1, #111827);
  border: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  border-radius: 12px;
  margin-bottom: 20px;
  scroll-margin-top: calc(var(--tb-strip-h, 30px) + 16px);
  min-width: 0;
}

.tb-settings-page .group-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tb-settings-page .group-header-icon {
  font-size: 18px;
}

.tb-settings-page .group-header h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.tb-settings-page .group-body {
  padding: 4px 0;
}

.tb-settings-page .setting-row {
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  border-bottom: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  min-width: 0;
  box-sizing: border-box;
}

@media (min-width: 640px) {
  .tb-settings-page .setting-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto auto auto;
    column-gap: 20px;
    row-gap: 4px;
    align-items: start;
  }

  .tb-settings-page .setting-label {
    grid-column: 1;
    grid-row: 1;
  }

  .tb-settings-page .setting-desc {
    grid-column: 1;
    grid-row: 2;
  }

  .tb-settings-page .setting-rec-details {
    grid-column: 1;
    grid-row: 3;
  }

  .tb-settings-page .setting-control {
    grid-column: 2;
    grid-row: 1 / -1;
  }
}

.tb-settings-page .setting-row:last-child {
  border-bottom: none;
}

.tb-settings-page .setting-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--tb-tx-1, #f1f5f9);
  margin-bottom: 3px;
}

.tb-settings-page .setting-badge-modified {
  font-size: 10px;
  vertical-align: middle;
  margin-left: 4px;
  text-transform: lowercase;
  letter-spacing: 0;
}

.tb-settings-page .setting-desc {
  font-size: 12px;
  color: var(--tb-tx-3, #a3b4cc);
  line-height: 1.4;
}

.tb-settings-page input[type="text"],
.tb-settings-page input[type="number"],
.tb-settings-page input[type="password"],
.tb-settings-page select {
  width: 100%;
  max-width: 100%;
  padding: 9px 12px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  border-radius: 8px;
  color: var(--tb-tx-1, #f1f5f9);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}

.tb-settings-page input:focus,
.tb-settings-page select:focus {
  border-color: var(--tb-info, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.tb-settings-page .input-with-unit {
  display: flex;
  align-items: center;
  max-width: 100%;
}

.tb-settings-page .input-with-unit input {
  border-radius: 8px 0 0 8px;
  min-width: 0;
}

.tb-settings-page .input-unit {
  padding: 9px 12px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  border-left: none;
  border-radius: 0 8px 8px 0;
  font-size: 12px;
  color: var(--tb-tx-2);
  font-weight: 600;
  white-space: nowrap;
}

.tb-sidenav__group-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tb-sidenav__group-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--tb-tx-3);
}

.tb-sidenav__group-icon svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tb-sheet[hidden] {
  visibility: hidden;
  pointer-events: none;
}

.tb-settings-page .toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.tb-settings-page .toggle-track {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.tb-settings-page .toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.tb-settings-page .toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(100, 116, 139, 0.3);
  border-radius: 26px;
  transition: background 0.3s;
}

.tb-settings-page .toggle-slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
}

.tb-settings-page .toggle input:checked + .toggle-track .toggle-slider {
  background: var(--tb-pos, #10b981);
}

.tb-settings-page .toggle input:checked + .toggle-track .toggle-slider::before {
  transform: translateX(22px);
}

.tb-settings-page .toggle-label {
  font-size: 12px;
  font-weight: 700;
  min-width: 28px;
}

.tb-settings-page .toggle-label-off {
  color: var(--tb-tx-3, #a3b4cc);
}

.tb-settings-page .toggle-label-on {
  display: none;
  color: var(--tb-pos, #10b981);
}

.tb-settings-page .toggle input:checked ~ .toggle-label-off {
  display: none;
}

.tb-settings-page .toggle input:checked ~ .toggle-label-on {
  display: inline;
}

.tb-settings-page .password-wrap {
  position: relative;
  max-width: 100%;
}

.tb-settings-page .password-wrap input {
  padding-right: 40px;
}

.tb-settings-page .password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--tb-tx-3, #a3b4cc);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
}

.tb-settings-page .btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tb-settings-page .btn-green {
  background: var(--tb-pos, #10b981);
  color: white;
}

.tb-settings-page .btn-outline {
  background: transparent;
  border: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  color: var(--tb-tx-2, #94a3b8);
}

.tb-settings-page .btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.tb-settings-page .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tb-settings-page .btn-test {
  margin-top: 8px;
  font-size: 12px;
  padding: 6px 12px;
  background: var(--tb-info-bg, rgba(59,130,246,0.12));
  color: var(--tb-info, #3b82f6);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 6px;
  cursor: pointer;
}

.tb-settings-page .save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(17, 24, 39, 0.97);
  border-top: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  backdrop-filter: blur(12px);
  transform: translateY(100%);
  transition: transform 0.3s ease;
  box-sizing: border-box;
}

.tb-settings-page .save-bar.show {
  transform: translateY(0);
}

.tb-settings-page .save-bar .changes-count {
  font-size: 13px;
  color: var(--tb-warn, #f59e0b);
}

.tb-settings-page .toast-container {
  position: fixed;
  top: calc(var(--tb-strip-h, 30px) + 12px);
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 24px);
}

.tb-settings-page .toast {
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  max-width: 400px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.tb-settings-page .toast-success {
  background: rgba(16, 185, 129, 0.95);
  color: white;
}

.tb-settings-page .toast-error {
  background: rgba(239, 68, 68, 0.95);
  color: white;
}

.tb-settings-page .toast-info {
  background: rgba(59, 130, 246, 0.95);
  color: white;
}

.tb-settings-page .test-result {
  margin-top: 6px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  display: none;
}

.tb-settings-page .test-result.show {
  display: block;
}

.tb-settings-page .test-result.success {
  background: var(--tb-pos-bg, rgba(16,185,129,0.12));
  color: var(--tb-pos, #10b981);
}

.tb-settings-page .test-result.error {
  background: var(--tb-neg-bg, rgba(239,68,68,0.12));
  color: #fca5a5;
}

.tb-settings-page .setting-rec-details {
  margin-top: 6px;
}

.tb-settings-page .setting-rec-summary {
  font-size: 11px;
  font-weight: 600;
  color: #93c5fd;
  cursor: pointer;
  list-style: none;
}

.tb-settings-page .setting-rec-summary::-webkit-details-marker {
  display: none;
}

.tb-settings-page .setting-rec {
  margin-top: 6px;
  padding: 6px 10px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.15);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: #93c5fd;
}

.tb-settings-page .btn-use-rec {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 4px;
  color: #93c5fd;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
}

.tb-settings-ai-box {
  margin: 0 14px 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border: 1px solid var(--tb-line, rgba(255,255,255,0.06));
}

.tb-settings-ai-box__title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.tb-settings-ai-box__desc {
  font-size: 12px;
  color: var(--tb-tx-3, #a3b4cc);
  margin-bottom: 10px;
}

.tb-settings-ai-box__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tb-settings-ai-adv {
  margin: 0 14px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tb-settings-ai-adv__label {
  font-size: 13px;
  color: var(--tb-tx-3, #a3b4cc);
}

.tb-settings-toolbar {
  position: sticky;
  top: calc(var(--tb-strip-h, 30px) + 48px);
  z-index: calc(var(--tb-z-sticky, 10) + 1);
  background: var(--tb-bg-0, #0a0e17);
  padding: 12px 0 14px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--tb-line, rgba(255, 255, 255, 0.06));
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

@media (min-width: 1024px) {
  .tb-settings-toolbar {
    top: var(--tb-settings-sticky-top);
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
  }

  .tb-settings-toolbar__search-wrap {
    flex: 0 1 280px;
    max-width: 360px;
  }

  .tb-settings-toolbar__meta {
    flex-shrink: 0;
  }

  .tb-settings-filter-chips {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tb-settings-filter-chips::-webkit-scrollbar {
    display: none;
  }
}

.tb-settings-toolbar__search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tb-settings-search {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--tb-line, rgba(255, 255, 255, 0.08));
  background: rgba(30, 41, 59, 0.85);
  color: var(--tb-tx-1, #f1f5f9);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}

.tb-settings-search:focus {
  border-color: var(--tb-info, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.tb-settings-search-clear {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--tb-tx-2, #94a3b8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.tb-settings-search-count {
  font-size: 12px;
  color: var(--tb-tx-3, #a3b4cc);
}

.tb-settings-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.tb-settings-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--tb-line, rgba(255, 255, 255, 0.1));
  background: rgba(255, 255, 255, 0.04);
  color: var(--tb-tx-2, #94a3b8);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  max-width: 100%;
  white-space: normal;
  text-align: left;
}

.tb-settings-chip--active {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(59, 130, 246, 0.45);
  color: var(--tb-tx-1, #f1f5f9);
}

.tb-settings-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--tb-tx-3, #a3b4cc);
  font-size: 14px;
  margin: 0 0 12px;
}

.tb-settings-live-summary {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  min-width: 0;
}

.tb-settings-live-summary__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fca5a5;
  margin-bottom: 8px;
}

.tb-settings-live-summary__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.tb-settings-live-summary__list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  min-width: 0;
}

.tb-settings-live-summary__link {
  background: none;
  border: none;
  padding: 0;
  color: var(--tb-info, #60a5fa);
  cursor: pointer;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  min-width: 0;
  flex: 1;
}

.tb-settings-live-summary__link:hover {
  text-decoration: underline;
}

.tb-settings-live-summary__val {
  color: var(--tb-tx-2, #94a3b8);
  flex-shrink: 0;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-settings-page .setting-control {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

@media (min-width: 640px) {
  .tb-settings-page .setting-control {
    width: 320px;
    max-width: 100%;
  }
}

.tb-settings-page .setting-control > .btn-reset-default {
  grid-column: 2;
  grid-row: 1;
}

.tb-settings-page .setting-control > :not(.btn-reset-default) {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  width: 100%;
}

.tb-settings-page .setting-control .password-wrap,
.tb-settings-page .setting-control .input-with-unit {
  width: 100%;
  max-width: 100%;
}

.tb-settings-page .btn-reset-default {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--tb-line, rgba(255, 255, 255, 0.12));
  background: transparent;
  color: var(--tb-tx-3, #a3b4cc);
  cursor: pointer;
  white-space: nowrap;
}

.tb-settings-page .btn-reset-default:hover {
  color: var(--tb-tx-1, #f1f5f9);
  border-color: rgba(255, 255, 255, 0.2);
}

.tb-settings-page .setting-row.tb-setting-row--flash {
  animation: tb-setting-flash 2s ease-out;
}

@keyframes tb-setting-flash {
  0% { background: rgba(59, 130, 246, 0.22); }
  100% { background: transparent; }
}

.tb-settings-page .settings-group[hidden],
.tb-settings-page .setting-row[hidden] {
  display: none !important;
}

@media (max-width: 1023px) {
  .tb-settings-page .save-bar {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    z-index: calc(var(--tb-z-nav, 40) - 1);
    transform: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .tb-settings-page .save-bar.show {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }
}

@media (min-width: 1024px) {
  .tb-settings-page .save-bar {
    left: var(--tb-sidenav-w, 240px);
  }
}

@media (max-width: 768px) {
  .tb-settings-page .settings-layout {
    grid-template-columns: 1fr;
  }

  .tb-settings-page .settings-nav {
    position: sticky;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding: 8px 0 10px;
    margin: 0 -4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    top: calc(var(--tb-strip-h, 30px) + 48px);
    background: var(--tb-bg-0, #0a0e17);
    max-width: 100%;
    z-index: calc(var(--tb-z-sticky, 10) + 1);
  }

  .tb-settings-page .settings-nav::-webkit-scrollbar {
    display: none;
  }

  .tb-settings-page .settings-nav a {
    white-space: nowrap;
    padding: 6px 12px;
    font-size: 11px;
    flex-shrink: 0;
    margin-bottom: 0;
    border: 1px solid var(--tb-line, rgba(255,255,255,0.06));
  }

  .tb-settings-page .sidebar-icon {
    font-size: 14px;
    width: 18px;
  }

  .tb-settings-container {
    padding: 12px 8px 80px;
  }
}

@media (max-width: 639px) {
  .tb-settings-toolbar {
    top: calc(var(--tb-strip-h, 30px) + 48px);
    padding: 10px 0 12px;
  }

  .tb-settings-search {
    font-size: 16px;
  }

  .tb-settings-chip {
    font-size: 11px;
    padding: 5px 10px;
  }

  .tb-settings-page .setting-row {
    padding: 10px 14px;
  }

  .tb-settings-page .setting-control {
    width: 100%;
  }

  .tb-settings-page .password-wrap {
    width: 100%;
  }

  .tb-settings-page input[type="text"],
  .tb-settings-page input[type="number"],
  .tb-settings-page input[type="password"],
  .tb-settings-page select {
    font-size: 16px;
    padding: 10px 12px;
  }
}

/* ----- Empty / loading (PHASE 7) ----- */
.tb-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tb-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--tb-tx-3);
  font-size: var(--tb-t-sm);
  line-height: 1.5;
}

.tb-empty::before {
  content: "📭";
  display: block;
  font-size: 26px;
  margin-bottom: 8px;
  line-height: 1;
  opacity: 0.9;
}

.tb-skeleton {
  color: var(--tb-tx-3);
  font-size: var(--tb-t-sm);
  text-align: center;
  padding: 24px 16px;
  background: linear-gradient(
    90deg,
    var(--tb-bg-2) 0%,
    var(--tb-bg-3) 50%,
    var(--tb-bg-2) 100%
  );
  background-size: 200% 100%;
  animation: tb-skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--tb-r-sm);
}

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

.tb-ui [aria-busy="true"] > .tb-skeleton:only-child,
.tb-ui [aria-busy="true"] > .loading:only-child {
  min-height: 48px;
}

.tb-sheet .tb-sidenav__group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tb-tx-3);
  margin: var(--tb-s-3) 0 var(--tb-s-2);
  gap: 8px;
}

.tb-sheet .tb-sidenav__group-icon {
  width: 16px;
  height: 16px;
  color: var(--tb-tx-2);
}

.tb-sheet .tb-sidenav__group-icon svg {
  width: 16px;
  height: 16px;
}

.tb-sim-page .chart-scroll:focus-visible {
  outline: 2px solid var(--tb-info);
  outline-offset: 2px;
}
