:root {
  --navy: #0f172a;
  --navy-2: #071426;
  --slate: #334155;
  --blue: #3b82f6;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #7c3aed;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #111827;
  --muted: #6b7280;
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }

button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 14px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
  font-size: 30px;
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 18px; }
.brand span { color: #bfdbfe; font-size: 13px; margin-top: 2px; }

.nav { display: grid; gap: 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  box-sizing: border-box;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  background: transparent;
  color: #e5eefb;
  text-align: left;
  text-decoration: none;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.08); }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-item:first-letter { font-size: 20px; }

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.side-card {
  border: 1px solid rgba(226, 232, 240, 0.16);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.side-card p {
  margin: 8px 0 0;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.4;
}

.side-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
}

.status::before, .market-chip span, .dot {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.status.live, .positive { color: var(--green); }
.status.live::before, .market-chip span, .dot.green { background: var(--green); }
.negative, .dot.red { color: var(--red); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }

.main { min-width: 0; }

.topbar {
  height: 72px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.search {
  flex: 1 1 420px;
  max-width: 560px;
  display: flex;
  gap: 10px;
  align-items: center;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--muted);
  background: #fff;
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
}

.date-button, .market-chip, .icon-button, .primary-button, .secondary-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--slate);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
  white-space: nowrap;
}

.market-chip {
  font-weight: 700;
  color: var(--text);
}

.icon-button {
  position: relative;
  width: 44px;
  padding: 0;
  font-size: 20px;
}

.icon-button b {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  line-height: 20px;
  min-width: 20px;
}

.mobile-menu { display: none; }

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile strong, .profile span { display: block; white-space: nowrap; }
.profile span { color: var(--blue); font-size: 12px; font-weight: 700; }

.logout-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  padding: 0;
}

.avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-weight: 800;
}

.view {
  display: none;
  padding: 28px 32px 48px;
}

.view.active { display: block; }

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; line-height: 1.15; margin-bottom: 6px; }
h2 { font-size: 18px; margin-bottom: 4px; }
p { color: var(--muted); }

.primary-button {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  font-weight: 700;
}

.secondary-button { font-weight: 700; }
.link-button {
  border: 0;
  background: transparent;
  color: #0b63f6;
  font-weight: 700;
  padding: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.kpi-card, .panel, .chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card {
  min-height: 160px;
  padding: 22px;
}

.kpi-top, .card-header, .panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.kpi-top span:first-child {
  font-weight: 700;
  color: #172033;
}

.round {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(16, 185, 129, 0.14);
  font-weight: 900;
}

.round.blue { color: #2563eb; background: rgba(59, 130, 246, 0.14); }
.round.purple { color: var(--purple); background: rgba(124, 58, 237, 0.12); }

.kpi-card strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
  line-height: 1;
}

.kpi-card em {
  display: block;
  margin-top: 8px;
  font-style: normal;
  font-weight: 700;
  font-size: 14px;
}

.kpi-card small {
  display: block;
  color: var(--muted);
  margin-top: 8px;
}

.spark { width: 100%; max-width: 190px; height: 48px; margin-top: 6px; }

.chart-card {
  padding: 20px 22px 24px;
  margin-bottom: 20px;
}

.rule-overview {
  margin-bottom: 20px;
}

.rule-summary-list {
  display: grid;
  gap: 10px;
}

.rule-summary-item {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) repeat(4, minmax(74px, auto)) auto;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.rule-summary-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.rule-summary-item strong,
.rule-summary-item small,
.rule-summary-item span {
  min-width: 0;
}

.rule-summary-item small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.rule-summary-item > span:not(.chip) {
  color: var(--muted);
  font-size: 12px;
}

.rule-summary-item > span:not(.chip) strong {
  display: block;
  color: #172033;
  font-size: 13px;
}

.card-header { margin-bottom: 16px; }
.card-header.compact { margin-bottom: 12px; }
.card-header p { margin-bottom: 0; }
.card-header strong { color: #0b63f6; font-size: 24px; }

.tabs {
  display: flex;
  align-items: center;
  gap: 18px;
}

.tabs button {
  border: 0;
  background: transparent;
  color: #64748b;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
}

.tabs button.active {
  color: #0b63f6;
  border-bottom-color: #0b63f6;
  font-weight: 800;
}

#mainChart {
  width: 100%;
  min-height: 230px;
}

.lower-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.1fr;
  gap: 20px;
}

.panel { padding: 20px; }
.panel.full { overflow: auto; }

.market-picker {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(180px, 260px) minmax(260px, 1fr) auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
}

.market-picker label {
  margin-bottom: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  color: #334155;
  text-align: left;
  font-size: 12px;
  padding: 12px 0;
}

td {
  border-top: 1px solid var(--border);
  padding: 13px 0;
  vertical-align: middle;
}

td strong { color: #0b63f6; }
td small { color: var(--muted); display: block; margin-top: 2px; }

.testing-panel {
  padding: 0;
}

.forward-panel {
  margin-bottom: 18px;
}

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

.forward-table table {
  table-layout: fixed;
  min-width: 920px;
  font-size: 12px;
}

.forward-table th {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  color: #475569;
  padding: 10px 8px;
}

.forward-table td {
  padding: 10px 8px;
  vertical-align: top;
}

.forward-table th:nth-child(1),
.forward-table td:nth-child(1) {
  width: 260px;
}

.forward-table th:nth-child(3),
.forward-table th:nth-child(4),
.forward-table th:nth-child(5),
.forward-table th:nth-child(6),
.forward-table th:nth-child(7),
.forward-table td:nth-child(3),
.forward-table td:nth-child(4),
.forward-table td:nth-child(5),
.forward-table td:nth-child(6),
.forward-table td:nth-child(7) {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.research-table {
  max-width: 100%;
  overflow-x: auto;
}

.research-table table {
  table-layout: fixed;
  min-width: 1040px;
  font-size: 12px;
}

.research-col-model { width: 150px; }
.research-col-market { width: 105px; }
.research-col-rule { width: 235px; }
.research-col-money { width: 82px; }
.research-col-small { width: 58px; }
.research-col-result { width: 104px; }
.research-col-decision { width: 210px; }

.research-table th {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  color: #475569;
  padding: 10px 8px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.research-table td {
  padding: 10px 8px;
  vertical-align: top;
}

.research-table tbody tr:nth-child(even) {
  background: #fbfdff;
}

.research-table td:nth-child(3),
.research-table td:nth-child(10) {
  color: #334155;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.research-table td:nth-child(4),
.research-table td:nth-child(5),
.research-table td:nth-child(6),
.research-table td:nth-child(7),
.research-table td:nth-child(8) {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.research-table .chip {
  min-height: 22px;
  padding: 0 8px;
  white-space: normal;
}

.symbol-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #eff6ff;
  color: #0b63f6;
  font-size: 11px;
  font-weight: 900;
}

.mini-trend {
  width: 70px;
  height: 26px;
}

.activity-list {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.activity {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(16, 185, 129, 0.12);
  color: var(--green);
  font-weight: 900;
}

.activity-icon.down { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.activity-icon.volume { background: rgba(124, 58, 237, 0.1); color: var(--purple); }

.activity strong, .activity small { display: block; }
.activity small, .activity time { color: var(--muted); font-size: 12px; }

.empty-state {
  color: var(--muted);
  font-weight: 700;
  text-align: left;
}

td.empty-state {
  padding: 18px;
}

.rule-card.empty-state,
.activity.empty-state {
  display: block;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.delivery {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin: 20px 0;
}

.donut {
  width: 160px;
  aspect-ratio: 1;
  border-radius: 999px;
  background: conic-gradient(var(--blue) 0 96%, var(--amber) 96% 98%, var(--red) 98% 100%);
  display: grid;
  place-items: center;
}

.donut span {
  width: 112px;
  aspect-ratio: 1;
  background: #fff;
  border-radius: 999px;
  display: grid;
  place-items: center;
  align-content: center;
  font-size: 30px;
  font-weight: 900;
}

.donut small {
  display: block;
  font-size: 13px;
  font-weight: 800;
}

.delivery-list p {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.delivery-list small {
  grid-column: 3;
  color: var(--muted);
}

.panel-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.panel-footer span {
  color: var(--muted);
  font-size: 13px;
}

.panel-footer strong { color: var(--slate); }

.success-icon {
  width: 32px;
  height: 32px;
  border: 2px solid var(--green);
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--green) !important;
  font-size: 18px !important;
  font-weight: 900;
}

.alert-rules {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.rule-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.rule-card h2 { font-size: 16px; }
.rule-card p { font-size: 14px; margin-bottom: 12px; }

.rule-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.rule-detail-grid span {
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 8px;
}

.rule-stat-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.rule-stat-row span {
  color: var(--muted);
  font-size: 11px;
}

.rule-stat-row strong {
  color: #172033;
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.rules-market-panel,
.rules-detail-panel {
  min-width: 0;
}

#alertsView {
  width: 100%;
}

#alertsView .rules-detail-panel {
  display: block;
  max-width: none;
  overflow: hidden;
  width: 100%;
}

#alertsView .table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

#alertsView .rules-table {
  min-width: 980px;
  width: 100%;
}

.rules-research-note {
  caption-side: top;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 0 0 12px;
  text-align: left;
}

.research-data-modal {
  max-width: min(860px, 92vw);
  width: 860px;
}

.research-data-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.research-data-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
  padding: 10px 12px;
}

.research-data-item span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.research-data-item strong {
  color: #172033;
  display: block;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.rules-actions-cell {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.rules-actions-cell .secondary-button {
  min-height: 38px;
  padding: 0 14px;
}

.rules-market-list {
  display: grid;
  gap: 8px;
}

.rules-market-select {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
}

.rules-market-native-select {
  display: none;
}

.rules-market-select select {
  appearance: auto;
  background: #ffffff;
  color: #172033;
  flex: 0 0 auto;
  min-width: 260px;
  width: min(380px, 42vw);
}

.rules-market-menu {
  display: inline-block;
  position: relative;
}

.rules-market-toggle {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #172033;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: space-between;
  min-height: 44px;
  min-width: 260px;
  padding: 0 38px 0 14px;
  position: relative;
  text-align: left;
  width: min(380px, 42vw);
}

.rules-market-toggle::after {
  border-bottom: 2px solid currentColor;
  border-right: 2px solid currentColor;
  content: "";
  height: 8px;
  position: absolute;
  right: 16px;
  top: 15px;
  transform: rotate(45deg);
  width: 8px;
}

.rules-market-toggle[aria-expanded="true"] {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.rules-market-menu-list {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.16);
  display: grid;
  left: 0;
  max-height: 340px;
  min-width: 320px;
  overflow-y: auto;
  padding: 6px;
  position: absolute;
  top: calc(100% + 6px);
  width: max(100%, 360px);
  z-index: 25;
}

.rules-market-menu-list[hidden] {
  display: none;
}

.rules-market-menu-option {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #172033;
  cursor: pointer;
  display: grid;
  gap: 2px;
  justify-items: start;
  padding: 9px 10px;
  text-align: left;
}

.rules-market-menu-option:hover,
.rules-market-menu-option.selected {
  background: #eff6ff;
  color: #0f4fd6;
}

.rules-market-menu-option small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.rules-market-item {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
  text-align: left;
  width: 100%;
}

.rules-market-item:hover,
.rules-market-item.selected {
  border-color: #2563eb;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.09);
}

.rules-market-item.market-open {
  border-color: #86efac;
}

.rules-market-item.market-open.selected,
.rules-market-item.market-open:hover {
  border-color: #16a34a;
  box-shadow: 0 10px 24px rgba(22, 163, 74, 0.11);
}

.rules-market-item strong,
.rules-market-item small {
  display: block;
}

.rules-market-item strong {
  color: #172033;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.rules-market-item small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.rules-market-item .market-hours {
  color: #475569;
  margin-top: 6px;
}

.rules-market-item .market-hours b {
  color: #64748b;
  display: inline;
  font-size: 12px;
  margin-right: 4px;
}

.rules-market-item.market-open .market-hours b {
  color: #15803d;
}

.rules-market-stats {
  text-align: right;
}

.rules-market-stats b {
  color: #172033;
  display: block;
  font-size: 18px;
}

.rules-detail-header p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.rules-detail-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented-control {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-flex;
  padding: 3px;
}

.segmented-control button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #475569;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  min-height: 32px;
  padding: 0 11px;
}

.segmented-control button.active {
  background: #ffffff;
  color: #0b63f6;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.rule-plain-english {
  color: #475569;
  font-size: 12px;
  line-height: 1.45;
  margin: 6px 0 0;
  max-width: 420px;
}

.rule-status-note {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
  white-space: nowrap;
}

.time-replacement-banner {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  max-width: 560px;
}

.time-replacement-banner small {
  color: #475569;
}

.trade-lab-hero {
  align-items: stretch;
  background: #0f172a;
  border-radius: 8px;
  color: #f8fafc;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  margin-bottom: 20px;
  padding: 22px;
}

.trade-lab-hero h2 {
  color: #ffffff;
  font-size: 28px;
  margin: 6px 0 8px;
}

.trade-lab-hero p {
  color: #cbd5e1;
  margin: 0;
  max-width: 760px;
}

.lab-eyebrow {
  color: #93c5fd;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.lab-status-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.lab-status-grid article {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 12px;
}

.lab-status-grid span,
.lab-status-grid small {
  color: #cbd5e1;
  display: block;
  font-size: 12px;
}

.lab-status-grid strong {
  color: #ffffff;
  display: block;
  font-size: 24px;
  margin: 3px 0;
}

.trade-lab-grid,
.agent-findings-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.2fr) minmax(260px, 0.8fr);
  margin-bottom: 20px;
}

.lab-team-list,
.lab-candidate-list,
.lab-loop-list {
  display: grid;
  gap: 10px;
}

.lab-team-member,
.lab-candidate {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.lab-team-member {
  grid-template-columns: minmax(0, 1fr) auto;
}

.lab-team-member strong,
.lab-team-member small,
.lab-candidate strong,
.lab-candidate small {
  display: block;
}

.lab-team-member small,
.lab-candidate small,
.lab-loop-list span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.lab-candidate {
  grid-template-columns: 34px minmax(0, 1fr) minmax(52px, auto) minmax(78px, auto) auto;
}

.lab-rank {
  background: #e0f2fe;
  border-radius: 8px;
  color: #075985;
  display: grid;
  font-weight: 900;
  height: 34px;
  place-items: center;
}

.lab-candidate > span:not(.chip) {
  text-align: right;
}

.lab-candidate b {
  color: #172033;
  display: block;
}

.lab-loop-list {
  counter-reset: labLoop;
  list-style: none;
  margin: 0;
  padding: 0;
}

.lab-loop-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  counter-increment: labLoop;
  display: grid;
  gap: 2px;
  grid-template-columns: 32px minmax(0, 1fr);
  padding: 10px;
}

.lab-loop-list li::before {
  color: #2563eb;
  content: counter(labLoop);
  font-weight: 900;
}

.lab-loop-list strong,
.lab-loop-list span {
  grid-column: 2;
}

.agent-findings-panel {
  min-width: 0;
}

.agent-market-findings,
.agent-test-list {
  display: grid;
  gap: 12px;
}

.agent-finding-card,
.agent-action-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.agent-finding-card header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.agent-finding-card header strong {
  color: #172033;
  font-size: 16px;
}

.agent-finding-card p,
.agent-action-item p {
  color: #334155;
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
}

.agent-risk-note {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.22);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  margin-top: 12px;
  padding: 10px;
}

.agent-risk-note strong,
.agent-risk-note span {
  display: block;
  font-size: 12px;
}

.agent-risk-note strong {
  color: #92400e;
}

.agent-risk-note span {
  color: #78350f;
}

.agent-rule-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.agent-rule-list span {
  background: #f1f5f9;
  border-radius: 999px;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  padding: 5px 8px;
}

.agent-action-item {
  display: grid;
  gap: 8px;
}

.agent-report-panel {
  margin-bottom: 20px;
}

.protection-status-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.protection-status-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 96px;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 5px;
  background: #fff;
}

.protection-status-card span,
.protection-status-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.protection-status-card strong {
  color: var(--text);
  font-size: 16px;
  line-height: 1.2;
}

.protection-status-card .chip {
  justify-self: start;
  margin-top: 2px;
}

.agent-report-table {
  min-width: 1080px;
}

.agent-report-table td {
  vertical-align: top;
}

.agent-report-table td:nth-child(3),
.agent-report-table td:nth-child(4) {
  max-width: 360px;
}

.agent-report-table strong,
.agent-report-table small {
  display: block;
}

.agent-report-table small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.protection-summary {
  color: #0f766e;
  font-weight: 700;
}

.agent-report-table .trade-lab-market-row td {
  background: #f8fafc;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.agent-report-table .trade-lab-market-row strong {
  font-size: 14px;
}

.agent-report-table .trade-lab-family-row {
  cursor: pointer;
}

.agent-report-table .trade-lab-family-row td {
  background: #ffffff;
}

.agent-report-table .trade-lab-result-row td {
  background: #fbfdff;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.chip.active { background: rgba(16, 185, 129, 0.12); color: #047857; }
.chip.draft { background: #f1f5f9; color: var(--slate); }
.chip.paused { background: rgba(245, 158, 11, 0.14); color: #b45309; }

.compact-action {
  min-height: 34px;
  padding: 7px 12px;
  white-space: nowrap;
}

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

.danger-link {
  color: #b91c1c;
}

.danger-link:hover {
  color: #7f1d1d;
}

.strategy-grid, .settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.backtest-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 0 14px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.backtest-results {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1.2fr);
  gap: 20px;
  margin-top: 20px;
}

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

.detail-kpis.compact article {
  padding: 12px;
}

.detail-kpis.compact strong {
  font-size: 18px;
}

.result-note {
  margin: 12px 0 0;
  font-size: 13px;
}

.strategy p { min-height: 70px; }

label {
  display: grid;
  gap: 8px;
  color: var(--slate);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 16px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: #fff;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

input:disabled {
  color: var(--muted);
  background: #f8fafc;
}

.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 16px;
}

#dashboardView > .kpi-grid,
#dashboardView > .chart-card,
#dashboardView > .rule-overview,
#dashboardView > .lower-grid {
  display: none;
}

.dashboard-focus-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.dashboard-primary-trades {
  margin-bottom: 20px;
}

.dashboard-primary-trades table {
  min-width: 980px;
}

.dashboard-historic-trades {
  margin-bottom: 20px;
}

.dashboard-secondary-grid {
  grid-template-columns: minmax(0, 1fr);
}

.dashboard-rules-panel {
  margin-bottom: 20px;
}

.table-toggle {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
}

.table-toggle input {
  width: auto;
}

.rules-table {
  table-layout: fixed;
  min-width: 1280px;
}

.rules-table th,
.rules-table td {
  padding: 12px 10px;
}

.rules-table th:nth-child(1),
.rules-table td:nth-child(1) {
  width: 15%;
}

.rules-table th:nth-child(2),
.rules-table td:nth-child(2) {
  width: 27%;
}

.rules-table th:nth-child(3),
.rules-table td:nth-child(3) {
  width: 12%;
}

.rules-table th:nth-child(4),
.rules-table td:nth-child(4) {
  width: 11%;
}

.rules-table th:nth-child(5),
.rules-table td:nth-child(5) {
  width: 14%;
}

.rules-table th:nth-child(6),
.rules-table td:nth-child(6) {
  width: 21%;
}

.rules-table td strong,
.rules-table td small {
  line-height: 1.35;
}

.status-switch {
  align-items: center;
  appearance: none;
  border: 1px solid #dbe4f0;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  height: 38px;
  justify-content: flex-start;
  margin: 0;
  min-width: 124px;
  padding: 0 10px;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
  user-select: none;
  white-space: nowrap;
}

.status-switch:disabled {
  cursor: progress;
  opacity: 0.72;
}

.status-switch input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.status-switch-text {
  color: #475569;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.status-switch-track {
  align-items: center;
  background: #cbd5e1;
  border-radius: 999px;
  display: inline-flex;
  flex: 0 0 auto;
  height: 18px;
  padding: 2px;
  transition: background 150ms ease;
  width: 34px;
}

.status-switch-track span {
  background: #ffffff;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.22);
  display: block;
  height: 14px;
  transform: translateX(0);
  transition: transform 150ms ease;
  width: 14px;
}

.status-switch.is-active {
  background: #f0fdf4;
  border-color: #86efac;
}

.status-switch.is-active .status-switch-track {
  background: #22c55e;
}

.status-switch.is-active .status-switch-track span {
  transform: translateX(16px);
}

.status-switch.is-active .status-switch-text {
  color: #166534;
}

.status-switch.is-inactive {
  background: #f8fafc;
}

.status-switch.is-inactive .status-switch-text {
  color: #64748b;
}

.status-switch:focus-within {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.24);
}

.status-switch:hover {
  border-color: #60a5fa;
}

.status-switch.is-saving .status-switch-track {
  background: #94a3b8;
}

.compact-select {
  border-radius: 8px;
  font-size: 13px;
  min-height: 36px;
  padding: 8px 28px 8px 10px;
}

.ig-rule-list {
  display: grid;
  gap: 14px;
}

.ig-rule-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.ig-rule-heading,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ig-rule-heading {
  margin-bottom: 12px;
}

.ig-rule-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 10px;
}

.portfolio-risk-preview {
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 2px 0 16px;
  padding: 12px;
}

.portfolio-risk-preview span,
.portfolio-risk-preview strong {
  display: block;
}

.portfolio-risk-preview span {
  color: var(--muted);
  font-size: 12px;
}

.portfolio-risk-preview strong {
  color: #172033;
  font-size: 15px;
  margin-top: 2px;
}

.toggle-row {
  grid-template-columns: auto 1fr;
  justify-content: start;
}

.toggle-row input {
  width: auto;
}

.trade-agent-button {
  min-width: 72px;
}

.trade-commentary-drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  visibility: hidden;
}

.trade-commentary-drawer.open {
  pointer-events: auto;
  visibility: visible;
}

.trade-commentary-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  opacity: 0;
  transition: opacity 160ms ease;
}

.trade-commentary-drawer.open .trade-commentary-backdrop {
  opacity: 1;
}

.trade-commentary-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(520px, 100vw);
  height: 100%;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 50px rgba(15, 23, 42, 0.16);
  transform: translateX(100%);
  transition: transform 180ms ease;
}

.trade-commentary-drawer.open .trade-commentary-panel {
  transform: translateX(0);
}

.trade-commentary-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--border);
}

.trade-commentary-header span,
.trade-commentary-meta small,
.trade-commentary-live-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.trade-commentary-header h2 {
  margin: 4px 0 4px;
  font-size: 22px;
}

.trade-commentary-header p {
  margin: 0;
  color: var(--slate);
  font-size: 13px;
  line-height: 1.45;
}

.trade-commentary-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.trade-commentary-meta span {
  min-width: 0;
}

.trade-commentary-meta strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.trade-commentary-live-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
}

.trade-commentary-list {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
  padding: 18px 22px 28px;
}

.trade-commentary-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.trade-commentary-entry.latest {
  border-color: rgba(59, 130, 246, 0.35);
  background: #f8fbff;
}

.trade-commentary-entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.trade-commentary-entry time,
.trade-commentary-entry small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.trade-commentary-entry p {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.trade-commentary-empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 16px;
  color: var(--slate);
  background: #f8fafc;
}

.modal {
  width: min(680px, calc(100vw - 32px));
  border: 0;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
  padding: 0;
}

.modal.market-modal {
  width: min(1120px, calc(100vw - 32px));
}

.market-modal form {
  max-height: min(86vh, 920px);
  overflow: auto;
}

.modal-header p {
  margin: 4px 0 0;
  font-size: 13px;
}

.detail-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.detail-kpis article {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.detail-kpis span,
.detail-list small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-kpis strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
  color: var(--text);
}

#detailChart {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.detail-grid h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-list article {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.detail-list strong,
.detail-list span {
  display: block;
}

.detail-list strong {
  color: #0b63f6;
  font-size: 13px;
}

.detail-list span {
  margin-top: 3px;
  color: var(--slate);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.modal::backdrop { background: rgba(15, 23, 42, 0.48); }
.modal form { padding: 24px; }

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

.large .activity {
  grid-template-columns: 34px minmax(0, 1fr) 130px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .protection-status-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-focus-grid { grid-template-columns: 1fr; }
  .lower-grid, .strategy-grid, .settings-grid, .alert-rules, .rules-market-layout, .trade-lab-hero, .trade-lab-grid, .agent-findings-grid { grid-template-columns: 1fr; }
  .rule-summary-item { grid-template-columns: minmax(0, 1fr) repeat(2, minmax(74px, auto)); }
  .rule-summary-item .chip { justify-self: start; }
  .backtest-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .backtest-results { grid-template-columns: 1fr; }
  .topbar { padding: 0 20px; }
  .date-button, .profile { display: none; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  #alertsView .rules-detail-panel { width: 100% !important; }
  .protection-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    width: 264px;
    z-index: 20;
    transition: transform 160ms ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-flex; }
  .topbar { gap: 10px; padding: 0 14px; }
  .search { min-width: 0; height: 42px; }
  .market-chip { display: none; }
  .view { padding: 22px 16px 36px; }
  .page-heading { display: grid; }
  .market-picker { grid-template-columns: 1fr; }
  .backtest-form { grid-template-columns: 1fr; }
  .detail-kpis,
  .detail-grid { grid-template-columns: 1fr; }
  .research-data-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .card-header { align-items: flex-start; flex-direction: column; }
  .tabs { flex-wrap: wrap; gap: 14px; }
  .delivery { grid-template-columns: 1fr; justify-items: center; }
  .form-grid { grid-template-columns: 1fr; }
  .lab-status-grid,
  .lab-candidate { grid-template-columns: 1fr; }
  .lab-candidate > span:not(.chip) { text-align: left; }
  .trade-commentary-panel { width: 100vw; }
  .trade-commentary-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  table { min-width: 620px; }
  .table-wrap { overflow-x: auto; }
}

.ig-market-feed-panel {
  margin-bottom: 20px;
}

.ig-market-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.ig-market-tile {
  display: grid;
  gap: 6px;
  min-height: 126px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.ig-market-tile strong,
.ig-market-tile small {
  display: block;
}

.ig-market-tile small,
.ig-market-tile em {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.ig-market-tile b {
  color: var(--text);
  font-size: 20px;
  letter-spacing: 0;
}

.ig-market-tile span {
  font-size: 13px;
  font-weight: 800;
}

.ig-market-tile.up span { color: #047857; }
.ig-market-tile.down span { color: #b91c1c; }
.ig-market-tile.live { border-color: rgba(16, 185, 129, 0.35); }
.ig-market-tile.delayed { border-color: rgba(245, 158, 11, 0.4); }
.ig-market-tile.stale,
.ig-market-tile.missing { opacity: 0.72; }
