:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --border: #d8dde6;
  --accent: #0f6b5f;
  --accent-strong: #084d45;
  --danger-bg: #fff1f0;
  --danger-border: #ffccc7;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent-strong);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

nav {
  display: flex;
  gap: 1rem;
}

nav a {
  text-decoration: none;
  color: var(--muted);
}

.page {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.2;
}

.page-header p,
.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 1rem;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.125rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0 0.875rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.form {
  display: grid;
  gap: 1rem;
  max-width: 32rem;
}

label {
  display: grid;
  gap: 0.375rem;
  color: var(--muted);
}

input,
select {
  min-height: 2.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

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

th,
td {
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
}

.metrics div {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.metrics dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.metrics dd {
  margin: 0.25rem 0 0;
  font-weight: 700;
}

.alert {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--danger-border);
  border-radius: 6px;
  background: var(--danger-bg);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0 0.625rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 0.875rem;
  font-weight: 700;
}

.rule-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
}

.panel h3 {
  margin: 1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 1rem;
  }

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

/* Dashboard home */
:root {
  --surface-soft: #f9fafc;
  --ink: #17212b;
  --blue: #2d5bff;
  --amber: #b7791f;
  --rose: #b42318;
}

nav a:hover {
  color: var(--text);
}

.desk-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(20rem, 0.75fr);
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 18rem;
  padding: 1rem;
}

.eyebrow,
.section-kicker {
  margin: 0 0 0.5rem;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-copy h1 {
  max-width: 44rem;
  margin: 0;
  color: var(--text);
  font-size: 4rem;
  line-height: 1;
}

.hero-copy p:not(.eyebrow) {
  max-width: 42rem;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.market-board {
  display: grid;
  align-content: space-between;
  min-height: 18rem;
  padding: 1rem;
  border: 1px solid #263240;
  border-radius: 8px;
  background: var(--ink);
  color: #f8fafc;
}

.board-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.board-row span {
  color: #a8b3c2;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.board-row strong {
  overflow-wrap: anywhere;
  text-align: right;
}

.mini-chart {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: end;
  gap: 0.5rem;
  height: 7rem;
  margin-top: 1rem;
  padding-top: 1rem;
}

.mini-chart span {
  display: block;
  min-height: 0.5rem;
  border-radius: 4px 4px 0 0;
  background: #56c2a2;
}

.mini-chart span:nth-child(3n) {
  background: #7aa2ff;
}

.mini-chart span:nth-child(4n) {
  background: #e0a444;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.metrics-strip div {
  min-height: 6rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.metrics-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

.metrics-strip strong {
  display: block;
  margin-top: 0.5rem;
  font-size: 1.75rem;
  line-height: 1;
}

.workflow-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.workflow-card {
  display: grid;
  gap: 0.75rem;
  min-height: 14rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.workflow-card:hover {
  border-color: #a8b3c2;
}

.workflow-card h2 {
  margin: 0;
  font-size: 1.25rem;
}

.workflow-card p {
  margin: 0;
  color: var(--muted);
}

.workflow-card strong {
  align-self: end;
  color: var(--accent-strong);
}

.step-index {
  width: fit-content;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.primary-flow {
  border-color: rgba(15, 107, 95, 0.4);
  background: #f4fbf8;
}

.secondary-flow {
  background: #fbfcff;
}

.dashboard-grid {
  margin-bottom: 1rem;
}

.dense-panel {
  padding: 0;
}

.dense-panel .panel-header {
  padding: 1rem 1rem 0;
}

.dense-panel table {
  margin-top: 0.5rem;
}

.button:hover {
  border-color: #a8b3c2;
}

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

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.5rem;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 0.8125rem;
  font-weight: 700;
}

.empty-state {
  margin: 1rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-soft);
}

.compact-rules {
  margin-bottom: 0;
}

@media (max-width: 760px) {
  .desk-hero,
  .metrics-strip,
  .workflow-grid {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    min-height: auto;
    padding: 0;
  }

  .hero-copy h1 {
    font-size: 2.5rem;
  }

  .market-board {
    min-height: 16rem;
  }
}

/* Home dashboard responsive fixes */
.desk-hero,
.hero-copy,
.market-board,
.board-row,
.board-row strong {
  min-width: 0;
}

.hero-copy h1 {
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .page {
    width: min(100% - 1.5rem, 1120px);
  }

  .desk-hero {
    padding: 1rem;
  }

  .hero-copy h1 {
    font-size: 2.15rem;
    line-height: 1.08;
  }

  .hero-copy p:not(.eyebrow) {
    font-size: 1rem;
  }

  .market-board {
    padding: 1rem;
    overflow: hidden;
  }

  .board-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.25rem;
  }

  .board-row strong {
    text-align: left;
  }

  .mini-chart {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

.hero-copy h1 span,
.hero-copy h1 .title-break {
  display: inline;
}

@media (max-width: 760px) {
  .hero-copy h1 span,
  .hero-copy h1 .title-break {
    display: block;
  }
}


.chart-panel {
  overflow: hidden;
}

.chart-shell {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.kline-canvas {
  display: block;
  width: 100%;
  height: 24rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  color: var(--muted);
  font-size: 0.875rem;
}

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

.chart-legend i {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
}

.legend-up {
  background: #0f766e;
}

.legend-down {
  background: #b42318;
}

.legend-entry {
  border-radius: 999px !important;
  background: #2d5bff;
}

.legend-exit {
  border-radius: 999px !important;
  background: #b7791f;
}

@media (max-width: 760px) {
  .kline-canvas {
    height: 18rem;
  }
}


.kline-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 18rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}


.automation-strip {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.automation-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.automation-heading h2 {
  margin: 0;
  font-size: 1.125rem;
}

.automation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.automation-item {
  display: grid;
  align-content: start;
  gap: 0.5rem;
  min-height: 10rem;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.automation-item.warning {
  border-color: rgba(183, 121, 31, 0.38);
  background: #fffaf0;
}

.automation-item span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.automation-item strong {
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1.1;
}

.automation-item p {
  margin: 0;
  color: var(--muted);
}

.automation-item small {
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.backtest-overview {
  margin-bottom: 1rem;
}

.backtest-overview .panel-header {
  margin-bottom: 0.5rem;
}

.performance-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.performance-card {
  min-height: 5.5rem;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.performance-card span {
  display: block;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 700;
}

.performance-card strong {
  display: block;
  margin-top: 0.5rem;
  color: var(--text);
  font-size: 1.55rem;
  line-height: 1;
}

.performance-card.profit strong {
  color: var(--accent-strong);
}

.performance-card.loss strong,
.performance-card.risk strong {
  color: var(--rose);
}

@media (max-width: 900px) {
  .automation-grid,
  .performance-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .automation-grid,
  .performance-grid {
    grid-template-columns: 1fr;
  }

  .automation-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Inline help tooltip */
.hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  cursor: help;
  vertical-align: middle;
}
.hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cbd5e1;
  color: #1f2937;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}
.hint:hover .hint-icon,
.hint:focus .hint-icon {
  background: #2563eb;
  color: #fff;
}
.hint-bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 200px;
  max-width: 320px;
  padding: 8px 10px;
  background: #1f2937;
  color: #f9fafb;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  white-space: normal;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease-out;
  z-index: 100;
}
.hint-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1f2937;
}
.hint:hover .hint-bubble,
.hint:focus .hint-bubble,
.hint:focus-within .hint-bubble {
  opacity: 1;
  pointer-events: auto;
}
