:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --text: #111827;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-green: #16a34a;
  --accent-green-bg: #dcfce7;
  --accent-red: #dc2626;
  --accent-red-bg: #fee2e2;
  --accent-amber: #d97706;
  --accent-amber-bg: #fef3c7;
  --accent-purple: #7c3aed;
  --accent-purple-bg: #ede9fe;
  --sidebar-width: 240px;
  --sidebar-collapsed: 72px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.04);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b20;
  --surface-2: #20242a;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --border: #2d333b;
  --border-light: #21262d;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-green: #22c55e;
  --accent-green-bg: #14532d;
  --accent-red: #f87171;
  --accent-red-bg: #7f1d1d;
  --accent-amber: #fbbf24;
  --accent-amber-bg: #78350f;
  --accent-purple: #a78bfa;
  --accent-purple-bg: #4c1d95;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.22s ease;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
  align-items: center;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  height: 64px;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-purple));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  flex-shrink: 0;
}

.brand-text {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-footer .text,
.sidebar.collapsed .sidebar-quick-status {
  display: none;
}

.collapse-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.collapse-btn:hover { color: var(--text); background: var(--border-light); }

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

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

.nav-section-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  padding: 12px 10px 6px;
}

.sidebar.collapsed .nav-section-label { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
  width: 100%;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37,99,235,0.28);
}

.nav-item .nav-text { white-space: nowrap; font-size: 13px; }

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 700;
}

.nav-item.active .nav-badge { background: rgba(255,255,255,0.18); color: #fff; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar.collapsed .sidebar-footer { align-items: center; }

.sidebar-quick-status { font-size: 11px; color: var(--text-muted); }

.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}

.sidebar.collapsed .theme-toggle-btn { padding: 8px; justify-content: center; }
.sidebar.collapsed .theme-text { display: none; }

/* Main */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.top-bar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  flex-shrink: 0;
}

.top-bar-left { display: flex; align-items: center; gap: 12px; }
.top-bar-title { font-size: 18px; font-weight: 800; letter-spacing: -0.2px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-green { background: var(--accent-green-bg); color: var(--accent-green); }
.badge-amber { background: var(--accent-amber-bg); color: var(--accent-amber); }
.badge-red { background: var(--accent-red-bg); color: var(--accent-red); }
.badge-purple { background: var(--accent-purple-bg); color: var(--accent-purple); }
.badge-dark { background: var(--surface-2); color: var(--text-muted); }

.top-bar-right { display: flex; align-items: center; gap: 14px; }

/* Content */
.content-body {
  flex: 1;
  overflow: auto;
  display: flex;
  padding: 22px;
  gap: 22px;
}

.main-column { flex: 1; min-width: 0; }

.page { display: none; animation: fade 0.15s ease; }
.page.active { display: block; }

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

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

.section-title { font-size: 22px; font-weight: 800; margin: 0 0 4px; }
.section-subtitle { margin: 0; color: var(--text-muted); font-size: 13px; }

/* Cards */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 18px;
}

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

.panel-card-title { font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }

.panel-card-body { padding: 18px; }

.metric-value { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.metric-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.metric-delta { font-size: 13px; font-weight: 700; margin-top: 4px; }
.metric-delta.pos { color: var(--accent-green); }
.metric-delta.neg { color: var(--accent-red); }

/* Tables */
.table-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; overflow-y: hidden; }

table { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; }

thead { background: var(--surface-2); }

th, td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border-light); vertical-align: middle; overflow: hidden; text-overflow: ellipsis; }

td { white-space: nowrap; }
th { white-space: normal; overflow: visible; text-overflow: clip; }

th { font-weight: 700; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }

tbody tr:hover { background: var(--surface-2); }

tbody tr:last-child td { border-bottom: none; }

/* Positions column widths */
.positions-table th:nth-child(1), .positions-table td:nth-child(1) { width: 25%; }
.positions-table th:nth-child(2), .positions-table td:nth-child(2) { width: 16%; }
.positions-table th:nth-child(3), .positions-table td:nth-child(3) { width: 9%; }
.positions-table th:nth-child(4), .positions-table td:nth-child(4),
.positions-table th:nth-child(5), .positions-table td:nth-child(5),
.positions-table th:nth-child(6), .positions-table td:nth-child(6) { width: 10%; }
.positions-table th:nth-child(7), .positions-table td:nth-child(7) { width: 11%; }
.positions-table th:nth-child(8), .positions-table td:nth-child(8) { width: 9%; }

/* Traders column widths */
.traders-table th:nth-child(1), .traders-table td:nth-child(1) { width: 7%; }
.traders-table th:nth-child(2), .traders-table td:nth-child(2) { width: 28%; }
.traders-table th:nth-child(3), .traders-table td:nth-child(3) { width: 22%; }
.traders-table th:nth-child(4), .traders-table td:nth-child(4) { width: 18%; }
.traders-table th:nth-child(5), .traders-table td:nth-child(5),
.traders-table th:nth-child(6), .traders-table td:nth-child(6) { width: 12.5%; }

/* Market/title cells wrap in a constrained width so the table does not blow out. */
.positions-table td:first-child,
.positions-table th:first-child {
  max-width: 280px;
  min-width: 160px;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
}

.positions-table td:first-child > div:first-child,
.traders-table td:nth-child(2) > div:first-child {
  font-weight: 700;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.positions-table td:first-child > div:last-child {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

@media (max-width: 900px) {
  th, td { padding: 10px 12px; font-size: 12px; }
}

.text-right { text-align: right; }

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

.empty-state svg { width: 48px; height: 48px; stroke-width: 1.5; margin-bottom: 12px; opacity: .5; }

.loading-row td { text-align: center; padding: 32px; color: var(--text-muted); }

/* Buttons & forms */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
}

.btn:hover { background: var(--surface-2); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-danger { border-color: var(--accent-red); color: var(--accent-red); }
.btn-danger:hover { background: var(--accent-red-bg); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.search-box { position: relative; max-width: 320px; }
.search-box .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-dim); }
.search-input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.form-input-wrap { position: relative; }
.form-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-weight: 700; }
.form-input.with-prefix { padding-left: 26px; }

select.form-input { 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='%236b7280' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .form-row { grid-template-columns: 1fr; } }

/* Cards for journal */
.journal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

.journal-card-header {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
}

.journal-card-header:hover { background: var(--surface-2); }

.journal-card-header > div:first-child { min-width: 0; }

.journal-card-body { padding: 18px; display: none; }
.journal-card-body.open { display: block; }

.journal-title {
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 2px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.journal-sub {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trade-list { display: flex; flex-direction: column; gap: 8px; }
.trade-item {
  display: grid;
  grid-template-columns: 120px 60px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  overflow: hidden;
}
.trade-item > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) { .trade-item { grid-template-columns: 1fr 1fr; gap: 8px; } .trade-item > * { white-space: normal; } }

.trade-badge { font-size: 11px; font-weight: 800; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; display: inline-block; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.trade-badge.buy { background: var(--accent-green-bg); color: var(--accent-green); }
.trade-badge.sell { background: var(--accent-red-bg); color: var(--accent-red); }

/* Trader mode controls */
.mode-select {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  min-width: 110px;
}

.mode-active { color: var(--accent-green); }
.mode-listen { color: var(--accent-amber); }
.mode-disabled { color: var(--text-dim); }

.link-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
}

.link-chip:hover { background: var(--border-light); }

.wallet { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; color: var(--text-muted); word-break: break-all; overflow-wrap: anywhere; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  padding: 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-title { font-size: 17px; font-weight: 800; margin: 0 0 2px; }
.modal-sub { color: var(--text-muted); font-size: 12px; margin: 0; }

.modal-close-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px;
}

.modal-body { padding: 18px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: 10px; }

/* Right column */
.sidebar-right {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-right.collapsed { display: none; }

#toggleRightPanelBtn { display: inline-flex; }
@media (max-width: 1000px) { .sidebar-right { display: none; } #toggleRightPanelBtn { display: none; } }

.info-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-light); }
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 12px; color: var(--text-muted); }
.info-val { font-size: 13px; font-weight: 700; }

/* Toasts */
.toast-stack {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-weight: 700;
  max-width: 320px;
  animation: slideUp 0.2s ease;
}

.toast.success { border-left: 4px solid var(--accent-green); }
.toast.error { border-left: 4px solid var(--accent-red); }

@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* Mobile */
@media (max-width: 720px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar.collapsed { width: 100%; }
  .main-wrapper { height: calc(100vh - 60px); }
  .content-body { flex-direction: column; padding: 14px; }
  .top-bar { padding: 0 14px; }
}

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; height: 14px; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Table sort, filters and P/L */
.controls-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 18px;
}
th.sortable:hover { background: var(--border-light); }

.sort-indicator {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.4;
}
.sort-indicator.active { opacity: 1; color: var(--accent); }

.pos { color: var(--accent-green); }
.neg { color: var(--accent-red); }

.metric-value.pos { color: var(--accent-green); }
.metric-value.neg { color: var(--accent-red); }

/* Journal detail rows */
.journal-detail-row { display: none; background: var(--surface-2); }
.journal-detail-row.open { display: table-row; }
.journal-detail-row > td { padding: 16px; border-bottom: 1px solid var(--border); }

.expand-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--border-light);
  color: var(--text);
  font-weight: 800;
  margin-right: 6px;
}

.journal-row-toggle { cursor: pointer; }

/* Journal table column widths */
.journal-table th:nth-child(1), .journal-table td:nth-child(1) { width: 12%; }
.journal-table th:nth-child(2), .journal-table td:nth-child(2) { width: 15%; }
.journal-table th:nth-child(3), .journal-table td:nth-child(3) { width: 22%; }
.journal-table th:nth-child(4), .journal-table td:nth-child(4) { width: 9%; }
.journal-table th:nth-child(5), .journal-table td:nth-child(5),
.journal-table th:nth-child(6), .journal-table td:nth-child(6),
.journal-table th:nth-child(7), .journal-table td:nth-child(7),
.journal-table th:nth-child(8), .journal-table td:nth-child(8),
.journal-table th:nth-child(9), .journal-table td:nth-child(9) { width: 9%; }
.journal-table th:nth-child(10), .journal-table td:nth-child(10) { width: 6%; }

/* Signals table column widths */
.signals-table th:nth-child(1), .signals-table td:nth-child(1) { width: 12%; }
.signals-table th:nth-child(2), .signals-table td:nth-child(2) { width: 14%; }
.signals-table th:nth-child(3), .signals-table td:nth-child(3) { width: 26%; }
.signals-table th:nth-child(4), .signals-table td:nth-child(4) { width: 8%; }
.signals-table th:nth-child(5), .signals-table td:nth-child(5),
.signals-table th:nth-child(6), .signals-table td:nth-child(6),
.signals-table th:nth-child(7), .signals-table td:nth-child(7),
.signals-table th:nth-child(8), .signals-table td:nth-child(8) { width: 10%; }

.hidden { display: none !important; }

/* ---------- Trader Lab ---------- */
.lab-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.lab-params { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.lab-params .form-group { margin-bottom: 8px; }
.lab-check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.lab-hint { margin: 10px 0 0; font-size: 12px; color: var(--text-muted); }
.lab-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.lab-inline .form-input { flex: 1 1 140px; width: auto; }
.lab-jobs { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.lab-job { font-size: 12px; }
.lab-job-text { font-weight: 700; margin-bottom: 4px; }
.lab-job-text span { font-weight: 500; color: var(--text-muted); margin-left: 4px; }
.lab-job-error { color: var(--accent-red); }
.lab-progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.lab-progress div { height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s ease; }
.lab-discover { margin-top: 16px; }
.lab-discover-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.lab-storage { font-size: 12px; color: var(--accent-amber); }
.lab-table td { vertical-align: middle; }
.lab-trader { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.lab-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--surface-2); }
.lab-avatar-empty { display: inline-block; border: 1px solid var(--border); }
.lab-score { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.lab-score b { font-size: 15px; min-width: 22px; text-align: right; }
.lab-sub { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.lab-actions { white-space: nowrap; }
.lab-actions .btn { margin-left: 4px; }
.lab-col-current { background: var(--surface-2); }

.lab-detail-box { width: min(1100px, calc(100vw - 32px)); max-width: none; max-height: calc(100vh - 48px); display: flex; flex-direction: column; }
.lab-detail-box .modal-body { overflow-y: auto; }
.lab-detail-top { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.lab-assumptions { font-size: 13px; color: var(--text-muted); }
.lab-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lab-kpi { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.lab-kpi .metric-label { margin: 0 0 2px; }
.lab-kpi-value { font-size: 18px; font-weight: 800; }
.lab-kpi-value.pos { color: var(--accent-green); }
.lab-kpi-value.neg { color: var(--accent-red); }
.lab-reasons { margin: 14px 0 0; padding-left: 18px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.lab-chart { position: relative; }
.lab-grid-line { stroke: var(--border-light); stroke-width: 1; }
.lab-zero { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 3 3; }
.lab-axis { fill: var(--text-muted); font-size: 11px; }
.lab-line { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lab-line.pos { stroke: var(--accent-green); }
.lab-line.neg { stroke: var(--accent-red); }
.lab-cross { stroke: var(--text-dim); stroke-width: 1; }
.lab-dot { fill: var(--surface); stroke: var(--text); stroke-width: 2; }
.lab-tip { position: absolute; top: 4px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 6px 10px; font-size: 12px; pointer-events: none; display: flex; flex-direction: column; white-space: nowrap; }
.lab-tip span { color: var(--text-muted); }
.lab-skip-line { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.lab-pos-box { max-height: 360px; overflow-y: auto; }
.lab-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }

@media (max-width: 1100px) {
  .lab-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .lab-params { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
#tab-lab table, #tab-paper table, #labDetailModal table { table-layout: auto; }
.lab-table { min-width: 1280px; }
#tab-paper table { min-width: 980px; }
#labDetailModal table { min-width: 900px; }
#tab-lab td, #tab-paper td, #labDetailModal td { overflow: visible; }
#labDetailModal td:nth-child(2), #tab-paper td:nth-child(3) { white-space: normal; min-width: 220px; }
.lab-trader > div { min-width: 0; max-width: 190px; }
.lab-trader > div > div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
