:root {
  --bg: #0b0f12;
  --panel: #12181d;
  --panel-2: #182027;
  --line: #26313a;
  --line-soft: #1d262d;
  --text: #e8eef0;
  --muted: #8d9aa0;
  --green: #21c77a;
  --red: #ff5b57;
  --amber: #e9b949;
  --blue: #6aa7ff;
}

* { box-sizing: border-box; }

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

.app-shell {
  min-height: 100vh;
  padding: 14px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.eyebrow {
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 2px;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 22px; line-height: 1.15; margin-bottom: 0; }
h2 { font-size: 14px; line-height: 1.2; margin-bottom: 0; }
h3 { font-size: 16px; margin-bottom: 14px; }

.topbar-actions,
.panel-heading {
  align-items: center;
  display: flex;
  gap: 8px;
}

.topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
.panel-heading { justify-content: space-between; margin-bottom: 10px; }

button, input, select { font: inherit; }

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  min-height: 34px;
  padding: 0 12px;
}
button:disabled { cursor: not-allowed; opacity: .45; }

.primary { background: var(--green); color: #04110b; }
.primary.danger, .panic { background: var(--red); color: #210303; }
.secondary, .small, .icon-button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
}

.small { min-height: 28px; padding: 0 9px; }
.icon-button { min-height: 30px; min-width: 32px; padding: 0; }
.full { width: 100%; }
.broker-top-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  margin-bottom: 10px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 64px;
  padding: 10px 12px;
}

.metric span,
label,
small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 700;
}

.metric strong {
  display: block;
  font-size: 20px;
  line-height: 1;
  margin-top: 8px;
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  min-width: 0;
  padding: 14px;
}

.main-panel,
.list-panel,
.orders-panel {
  grid-column: span 1;
}

.control-form {
  display: grid;
  gap: 10px;
}

.control-form.two-col {
  grid-template-columns: 1fr 1fr;
}

.full-field {
  grid-column: 1 / -1;
}

label input,
label select {
  background: #090d10;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  margin-top: 5px;
  min-height: 32px;
  padding: 0 9px;
  width: 100%;
}

label select {
  appearance: none;
}

.broker-summary {
  align-items: center;
  background: #0f1519;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto auto;
  margin-bottom: 12px;
  padding: 9px;
}

.broker-summary strong {
  margin-left: 6px;
}

.status-dot {
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
  height: 8px;
  width: 8px;
}

.green { color: var(--green); }
.bad, .red { color: var(--red); }
.good { color: var(--green); }
.muted { color: var(--muted); }
.status-dot.green { background: var(--green); }
.status-dot.red {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(255, 91, 87, 0.14);
}

.pill {
  background: #202a32;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 5px 8px;
  white-space: nowrap;
}

.pill.ready { color: var(--green); }
.pill.rejected { color: var(--red); }
.pill.inside_bar { color: var(--amber); }
.pill.not_qualified { color: var(--muted); }
.pill.scanning { color: var(--amber); }
.pill.side-buy { background: rgba(33, 199, 122, 0.16); border-color: rgba(33, 199, 122, 0.4); color: var(--green); }
.pill.side-sell { background: rgba(255, 91, 87, 0.16); border-color: rgba(255, 91, 87, 0.4); color: var(--red); }

.heading-actions { align-items: center; display: flex; gap: 8px; }
.heading-actions form { display: inline; margin: 0; }

.process-panel {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(280px, 1fr) minmax(220px, 1fr) auto;
}
.process-copy { align-items: center; display: flex; gap: 12px; }
.process-copy p { color: var(--muted); margin: 4px 0 0; }
.process-spinner {
  border: 3px solid var(--line);
  border-radius: 50%;
  border-top-color: var(--muted);
  height: 24px;
  width: 24px;
}
.process-panel.active .process-spinner { animation: spin .8s linear infinite; border-top-color: var(--amber); }
.process-panel.complete .process-spinner { border-color: var(--green); }
.process-panel.error .process-spinner { border-color: var(--red); }
.process-track { background: var(--line); border-radius: 20px; height: 8px; overflow: hidden; }
.process-track span {
  background: linear-gradient(90deg, var(--blue), var(--green));
  display: block;
  height: 100%;
  transition: width .35s ease;
  width: 0;
}
.panel-heading h2 small { color: var(--muted); font-size: 12px; font-weight: 500; margin-left: 8px; }

.spinner {
  animation: spin 0.7s linear infinite;
  border: 2px solid var(--line);
  border-radius: 50%;
  border-top-color: var(--amber);
  display: inline-block;
  height: 10px;
  vertical-align: -1px;
  width: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.table-wrap {
  overflow: auto;
}

.strategy-table { min-height: 240px; }
.symbol-table { max-height: 360px; }
.compact { max-height: 210px; }

.universe-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.universe-column {
  background: #10171d;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-width: 0;
  overflow: hidden;
}

.universe-column.buy { box-shadow: inset 3px 0 0 var(--green); }
.universe-column.sell { box-shadow: inset 3px 0 0 var(--red); }

.universe-title {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

.universe-title h3 {
  font-size: 13px;
  margin: 0;
}

.universe-table {
  max-height: 320px;
}

.universe-table th,
.universe-table td {
  font-size: 11px;
  padding: 7px 6px;
}

.universe-table td:last-child {
  min-width: 260px;
  white-space: normal;
}

/* --- Sector Stocks: live board -------------------------------------- */
.panel-title { align-items: center; display: flex; gap: 10px; }

.live-badge {
  align-items: center;
  background: #17232b;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  gap: 6px;
  padding: 4px 10px;
  white-space: nowrap;
}
.live-dot { background: var(--muted); border-radius: 50%; height: 7px; width: 7px; }
.live-badge.online { color: var(--green); }
.live-badge.online .live-dot { background: var(--green); animation: livePulse 1.8s infinite; }
.live-badge.offline { color: var(--red); }
.live-badge.offline .live-dot { background: var(--red); }
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(33, 199, 122, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(33, 199, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(33, 199, 122, 0); }
}

.sector-leaders {
  align-items: stretch;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr minmax(120px, 180px);
  margin-bottom: 12px;
}
.leader-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
.leader-card.gain {
  background: linear-gradient(135deg, rgba(33, 199, 122, 0.16), rgba(33, 199, 122, 0) 72%);
  border-color: rgba(33, 199, 122, 0.35);
}
.leader-card.lose {
  background: linear-gradient(135deg, rgba(255, 91, 87, 0.16), rgba(255, 91, 87, 0) 72%);
  border-color: rgba(255, 91, 87, 0.35);
}
.leader-label {
  color: var(--muted);
  display: block;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.leader-main {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-top: 5px;
}
.leader-main strong {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.leader-main em {
  font-size: 17px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}
.leader-card.gain em { color: var(--green); }
.leader-card.lose em { color: var(--red); }
.leader-note {
  align-self: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
}

.sector-board {
  display: grid;
  gap: 12px;
  grid-auto-columns: minmax(300px, 1fr);
  grid-auto-flow: column;
  max-height: 540px;
  overflow: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.sector-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-width: 300px;
  overflow: hidden;
}
.sector-card.up { box-shadow: inset 3px 0 0 var(--green); }
.sector-card.down { box-shadow: inset 3px 0 0 var(--red); }
.sector-card.flat { box-shadow: inset 3px 0 0 var(--line); }
.sector-card.leader-gain { border-color: rgba(33, 199, 122, 0.55); }
.sector-card.leader-lose { border-color: rgba(255, 91, 87, 0.55); }

.sector-card-head {
  align-items: center;
  background: #10171d;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.sec-name { font-size: 12px; font-weight: 800; letter-spacing: 0.3px; text-transform: uppercase; }
.sec-count {
  background: #20303a;
  border-radius: 999px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  margin-left: 6px;
  padding: 2px 6px;
}
.sec-perf { font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 900; }
.sec-perf.up { color: var(--green); }
.sec-perf.down { color: var(--red); }
.sec-perf.flat { color: var(--muted); }

.sector-card-body { max-height: 470px; overflow: auto; scrollbar-width: thin; }

.stock-row {
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 4px;
  padding: 8px 12px;
  transition: background 0.15s ease;
}
.stock-row:first-child { border-top: none; }
.stock-row:hover { background: rgba(106, 167, 255, 0.06); }

.row-top { align-items: center; display: flex; gap: 6px; justify-content: flex-start; min-width: 0; }
.sym { flex: 0 1 auto; font-size: 12.5px; font-weight: 800; max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ltp {
  border-radius: 5px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  padding: 1px 5px;
  transition: background 0.25s ease, color 0.25s ease;
  white-space: nowrap;
}
.ltp i { color: var(--muted); font-size: 9px; font-style: normal; font-weight: 800; margin-right: 3px; }
.ltp.flash-up { background: rgba(33, 199, 122, 0.2); color: var(--green); }
.ltp.flash-down { background: rgba(255, 91, 87, 0.2); color: var(--red); }

.row-bottom { align-items: center; display: flex; gap: 8px; }
.pct {
  border-radius: 4px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  min-width: 60px;
  padding: 2px 6px;
  text-align: center;
}
.pct.up { background: rgba(33, 199, 122, 0.15); color: var(--green); }
.pct.down { background: rgba(255, 91, 87, 0.15); color: var(--red); }
.pct.flat { background: #202a32; color: var(--muted); }
.rng { color: var(--amber); font-size: 10.5px; font-weight: 800; white-space: nowrap; }
.ohlc {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ohlc i { color: #5c6a72; font-style: normal; font-weight: 800; margin: 0 2px 0 6px; }
.ohlc i:first-child { margin-left: 0; }
.ohlc b { color: #c2ccd0; font-weight: 700; }

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

th, td {
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
  padding: 8px 7px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
  background: var(--panel);
}

td {
  color: #dce4e6;
}

.empty {
  color: var(--muted);
  margin: 0;
  padding: 22px 0;
  text-align: center;
}

.modal {
  align-items: center;
  background: rgba(5, 7, 10, 0.72);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 20;
}

.modal.open { display: flex; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 390px;
  padding: 20px;
  position: relative;
  width: 100%;
}

.modal-card form {
  display: grid;
  gap: 12px;
}

.close-modal {
  background: transparent;
  color: var(--muted);
  min-height: 28px;
  min-width: 28px;
  padding: 0;
  position: absolute;
  right: 10px;
  top: 8px;
}

.flash-stack {
  display: grid;
  gap: 8px;
  max-width: 560px;
  position: fixed;
  right: 14px;
  top: 14px;
  z-index: 30;
}

.flash {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 7px;
  color: var(--text);
  font-size: 12px;
  padding: 10px 12px;
}

.flash.danger { border-left-color: var(--red); }
.flash.warning { border-left-color: var(--amber); }

@media (max-width: 760px) {
  .process-panel { grid-template-columns: 1fr auto; }
  .process-track { grid-column: 1 / -1; grid-row: 2; }
  .app-shell { padding: 10px; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
  .panic { grid-column: 1 / -1; }
  .metrics-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .sector-board {
    grid-auto-flow: row;
    grid-template-columns: 1fr;
    max-height: none;
  }
  .sector-leaders {
    grid-template-columns: 1fr;
  }
  .universe-grid {
    grid-template-columns: 1fr;
  }
  .leader-note {
    justify-self: start;
  }
  .sector-card {
    min-width: 0;
  }
  .sector-card-body {
    max-height: 380px;
  }
  .control-form.two-col {
    grid-template-columns: 1fr;
  }
  .broker-summary {
    grid-template-columns: 1fr;
  }
  h1 { font-size: 19px; }
}
