:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #151c24;
  --surface-2: #1b2430;
  --surface-3: #223044;
  --line: #334155;
  --line-soft: #263241;
  --ink: #eef4ff;
  --muted: #9aa8b8;
  --faint: #6f7b8a;
  --green: #4fd071;
  --green-bg: rgba(79, 208, 113, 0.12);
  --amber: #f2c14e;
  --amber-bg: rgba(242, 193, 78, 0.13);
  --red: #ff5d57;
  --red-bg: rgba(255, 93, 87, 0.13);
  --blue: #5da2ff;
  --cyan: #35c9d0;
  --purple: #a47ce8;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(14px, 3vw, 32px);
  background: rgba(15, 20, 25, 0.92);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 850;
  text-decoration: none;
}

.brand img {
  width: 34px;
  height: 34px;
}

.status-pill,
mark {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid rgba(79, 208, 113, 0.24);
  border-radius: 999px;
  background: var(--green-bg);
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

mark.warning {
  border-color: rgba(242, 193, 78, 0.26);
  background: var(--amber-bg);
  color: var(--amber);
}

main {
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 56px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.3rem, 5vw, 4.8rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 0.98rem;
  letter-spacing: 0;
}

.workspace-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.dirty-indicator {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.dirty-indicator.is-dirty {
  border-color: rgba(242, 193, 78, 0.35);
  background: var(--amber-bg);
  color: var(--amber);
}

.primary-action,
.secondary-action,
.segmented button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 850;
}

.primary-action {
  padding: 0 16px;
  background: var(--amber);
  color: #121416;
  border-color: var(--amber);
}

.primary-action.is-dirty {
  box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.2);
}

.secondary-action {
  padding: 0 16px;
  background: var(--surface-2);
}

.full-width-action {
  width: 100%;
  margin: 4px 0 12px;
}

.notice-bar {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.notice-bar strong {
  color: var(--ink);
}

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

.control-panel {
  position: sticky;
  top: 78px;
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 94px);
  overflow: auto;
  padding-right: 2px;
}

.control-section,
.panel,
.metric-card,
.contract-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-section {
  padding: 16px;
}

.control-section h3 {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.84rem;
  text-transform: uppercase;
}

.source-row {
  margin-bottom: 12px;
}

.control-row,
.toggle-row {
  display: grid;
  gap: 7px;
  margin-bottom: 8px;
}

.control-row span,
.toggle-row span,
.metric-card span,
.contract-card span,
.phase-card span,
.research-item span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--amber);
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10161d;
  color: var(--ink);
  padding: 0 10px;
}

input[type="range"] {
  min-height: 26px;
  padding: 0;
  accent-color: var(--amber);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(93, 162, 255, 0.32);
  outline-offset: 2px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(76px, auto);
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.range-row strong {
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.segmented button {
  background: var(--surface-2);
}

.segmented button.is-active {
  background: var(--amber);
  border-color: var(--amber);
  color: #111418;
}

.strategy-workspace {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.panel {
  padding: 18px;
}

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

.muted,
.fine-print {
  color: var(--muted);
}

.fine-print {
  margin: 10px 0 0;
  font-size: 0.86rem;
}

.trade-thesis {
  color: var(--muted);
  font-size: 1.02rem;
}

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

.contract-card {
  padding: 15px;
}

.contract-card h3 {
  margin-top: 4px;
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.contract-symbol {
  display: block;
  margin: -6px 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

dl {
  margin: 0;
}

.contract-card dl,
.planner-stats {
  display: grid;
  gap: 9px;
}

.contract-card dl {
  grid-template-columns: 1fr;
}

.contract-card dl div,
.planner-stats div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}

dt {
  color: var(--muted);
  font-weight: 750;
}

dd {
  margin: 0;
  color: var(--ink);
  font-weight: 850;
  text-align: right;
}

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

.metric-grid.tight {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card {
  min-height: 112px;
  padding: 15px;
  display: grid;
  align-content: space-between;
  gap: 8px;
}

.metric-card strong {
  color: var(--ink);
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-card small {
  color: var(--muted);
}

.metric-card.positive,
.positive-text {
  color: var(--green);
}

.metric-card.positive strong {
  color: var(--green);
}

.metric-card.warning strong {
  color: var(--amber);
}

.metric-card.danger strong,
.negative-text {
  color: var(--red);
}

.warning-panel {
  border-color: rgba(242, 193, 78, 0.28);
}

.warning-panel ul {
  margin: 0;
  padding-left: 20px;
  color: var(--amber);
}

.ticket-list {
  margin: 0 0 16px;
  padding-left: 22px;
}

.ticket-list li {
  margin-bottom: 7px;
}

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

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-panel .panel-head {
  margin: 0;
  padding: 18px 18px 0;
}

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

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.group-row td {
  background: var(--surface-2);
  color: var(--amber);
  font-weight: 850;
}

.selected-row {
  background: rgba(79, 208, 113, 0.08);
}

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

.roll-grid div {
  padding: 13px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
}

.roll-grid strong {
  display: block;
  margin-bottom: 4px;
  color: var(--amber);
  font-size: 1.45rem;
}

.roll-grid span {
  color: var(--muted);
}

.chart-panel {
  margin-top: 12px;
  padding-bottom: 12px;
}

.chart-canvas {
  display: block;
  width: 100%;
  height: 260px;
}

.workflow {
  margin: 0;
  padding-left: 20px;
}

.workflow li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
}

.workflow li:first-child {
  border-top: 0;
}

.workflow strong {
  color: var(--blue);
  white-space: nowrap;
}

.feed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}

.feed-row:first-child {
  border-top: 0;
}

.feed-row div {
  display: grid;
  gap: 2px;
}

.feed-row span {
  color: var(--muted);
  font-size: 0.86rem;
}

@media (max-width: 980px) {
  .strategy-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
    max-height: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-section:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  main {
    width: min(100% - 20px, 760px);
    padding-top: 18px;
  }

  .workspace-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .head-actions {
    justify-content: stretch;
  }

  .head-actions button,
  .primary-action,
  .secondary-action {
    flex: 1 1 auto;
  }

  .control-panel,
  .contract-grid,
  .metric-grid,
  .metric-grid.tight,
  .planner-stats.compact,
  .roll-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding-inline: 10px;
  }

  .brand span {
    display: none;
  }

  .status-pill {
    max-width: 56vw;
    justify-content: center;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  h1 {
    font-size: 2.35rem;
  }

  .panel,
  .control-section {
    padding: 14px;
  }

  .contract-card dl {
    grid-template-columns: 1fr;
  }

  .workflow li,
  .planner-stats div {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  dd {
    text-align: left;
  }
}
