:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e0e8;
  --blue: #1457d9;
  --green: #087443;
  --amber: #b25e09;
  --red: #b42318;
  --grapefruit: #f15f4b;
  --water: #1486e8;
  --mayo: #d6a928;
  --shadow: 0 14px 38px rgba(31, 42, 55, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

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

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 30px; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: 0; }

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px 32px 40px;
}

.run-picker {
  display: grid;
  gap: 6px;
  min-width: 260px;
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--blue);
  background: #eef4ff;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

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

.summary-grid article,
.panel,
.decision {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-grid article {
  padding: 16px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-grid strong {
  font-size: 22px;
}

.decision {
  padding: 16px 18px;
  margin-bottom: 16px;
  border-left: 5px solid var(--green);
}

.decision.alert { border-left-color: var(--red); }
.decision.watch { border-left-color: var(--amber); }
.decision h2 { margin-bottom: 6px; }
.decision p { margin: 0; color: var(--muted); line-height: 1.45; }

.layout {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel { padding: 18px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head p {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 13px;
}

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

.leader {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}

.leader.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 87, 217, 0.12);
}

.leader-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.ticker {
  font-weight: 850;
  font-size: 18px;
}

.company {
  color: var(--muted);
  font-size: 13px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  color: var(--ink);
  display: block;
  font-size: 15px;
}

.metrics.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  background: #ecfdf3;
  color: var(--green);
  white-space: nowrap;
}

.badge.bad { background: #fef3f2; color: var(--red); }
.badge.watch { background: #fffaeb; color: var(--amber); }

.frames {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 180px;
}

.frame h3 {
  margin: 0 0 12px;
  font-size: 15px;
  text-transform: capitalize;
}

.frame dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

.frame div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.frame dt { color: var(--muted); }
.frame dd { margin: 0; font-weight: 750; text-align: right; }

.status {
  display: inline-block;
  margin-top: 14px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #eef4ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.status.overextended { background: #fffaeb; color: var(--amber); }
.status.alert { background: #fef3f2; color: var(--red); }

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

.candidate-panel {
  margin-top: 16px;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.candidate-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

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

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

.candidate-list button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.candidate-list strong {
  display: block;
  color: var(--ink);
}

.candidate-list span {
  color: var(--muted);
  font-size: 12px;
}

.chart-panel {
  margin-top: 16px;
}

.timeframe-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.timeframe-toggle button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.timeframe-toggle button.active {
  color: #fff;
  background: var(--blue);
}

.chart-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.data-note {
  margin: -6px 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  max-width: 980px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 18px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.swatch.price { background: #17202a; }
.swatch.rsi { background: #1457d9; }
.swatch.k { background: #087443; }
.swatch.d { background: #b25e09; }
.swatch.ema22 { background: var(--grapefruit); }
.swatch.ema50 { background: var(--water); }
.swatch.ema200 { background: var(--mayo); }

.technical-chart {
  width: 100%;
  min-height: 520px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.technical-chart svg {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
}

.plot-border {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
}

.grid-line {
  stroke: #edf1f5;
  stroke-width: 1;
}

.threshold {
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
}

.threshold.high { stroke: rgba(180, 35, 24, 0.65); }
.threshold.low { stroke: rgba(8, 116, 67, 0.65); }

.price-line,
.ema22-line,
.ema50-line,
.ema200-line,
.rsi-line,
.k-line,
.d-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.price-line { stroke: #17202a; }
.ema22-line { stroke: var(--grapefruit); stroke-width: 2; stroke-dasharray: 5 5; }
.ema50-line { stroke: var(--water); stroke-width: 2; stroke-dasharray: 6 4; }
.ema200-line { stroke: var(--mayo); stroke-width: 2.2; stroke-dasharray: 8 5; }
.rsi-line { stroke: #1457d9; }
.k-line { stroke: #087443; }
.d-line { stroke: #b25e09; }

.axis-title {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.empty-chart {
  padding: 24px;
  color: var(--muted);
}

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

th, td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ib-panel {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-top: 16px;
}

.explainer-panel {
  margin-top: 16px;
}

.options-panel {
  margin-top: 16px;
}

.watchlist-panel {
  margin-top: 16px;
}

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

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

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

.watch-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  text-align: left;
}

button.watch-card {
  cursor: pointer;
}

.watch-card.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 87, 217, 0.12);
}

.watch-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  min-height: 38px;
}

.watch-card.unavailable {
  opacity: 0.75;
}

.options-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.options-grid article.option-verdict {
  border-left: 5px solid var(--red);
}

.options-grid article.option-verdict.watch {
  border-left-color: var(--amber);
}

.options-grid article.option-verdict.good {
  border-left-color: var(--green);
}

.options-grid h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.options-grid ul {
  margin: 0;
  padding-left: 20px;
}

.options-grid li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.options-grid li + li {
  margin-top: 7px;
}

.explainer-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.explainer-grid h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.explainer-grid p,
.explainer-grid li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.explainer-grid p {
  margin-bottom: 10px;
}

.explainer-grid p:last-child {
  margin-bottom: 0;
}

.explainer-grid ul,
.explainer-grid ol {
  margin: 0;
  padding-left: 20px;
}

.explainer-grid li + li {
  margin-top: 7px;
}

.explainer-grid strong {
  color: var(--ink);
}

.ib-panel p {
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.45;
}

.ib-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button.secondary {
  background: #eef4ff;
  color: var(--blue);
}

@media (max-width: 1100px) {
  .summary-grid,
  .frames,
  .rankings,
  .candidate-grid,
  .explainer-grid,
  .options-grid,
  .watchlist-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .top-actions,
  .ib-panel {
    flex-direction: column;
    align-items: stretch;
  }
  main,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }
  .summary-grid,
  .frames,
  .rankings,
  .candidate-grid,
  .explainer-grid,
  .options-grid,
  .watchlist-grid {
    grid-template-columns: 1fr;
  }
}
