:root {
  --ink: #14221c;
  --muted: #66736c;
  --paper: #f4f3ee;
  --paper-raised: #fbfbf7;
  --line: #d7ddd8;
  --line-strong: #bdc8c1;
  --navy: #102923;
  --accent: #0b6b4f;
  --accent-dark: #07523d;
  --accent-soft: #dcece5;
  --danger: #9c3434;
  --danger-soft: #f2dddd;
  --warning: #7a5a16;
  --warning-soft: #f3e7c8;
  --white: #fff;
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --content-width: 1480px;
  --page-gutter: clamp(18px, 4vw, 56px);
  --control-height: 42px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.94rem;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.btn,
.form-control,
.form-select {
  min-height: var(--control-height);
  border-radius: 3px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-dark);
  --bs-btn-hover-border-color: var(--accent-dark);
  --bs-btn-active-bg: var(--accent-dark);
  --bs-btn-active-border-color: var(--accent-dark);
}

.btn:focus-visible,
.form-control:focus,
.form-select:focus,
.section-nav a:focus-visible,
summary:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 79, 0.18);
  outline: none;
}

.topbar {
  min-height: 138px;
  background: var(--navy);
  color: #f7faf8;
}

.topbar-inner {
  width: min(var(--content-width), 100%);
  min-height: 138px;
  margin: 0 auto;
  padding: 28px var(--page-gutter);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 3.25rem);
  font-weight: 400;
  letter-spacing: -0.025em;
}

.topbar-subtitle {
  margin: 4px 0 0;
  color: #afc1ba;
  font-size: 0.78rem;
}

.brand-mark,
.eyebrow {
  margin: 0;
  color: #68aa92;
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-actions form {
  margin: 0;
}

.simulation-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
}

.simulation-label span {
  color: #68aa92;
  font-size: 0.6rem;
}

.mode-banner {
  min-height: 42px;
  font-size: 0.8rem;
}

.mode-banner-inner {
  width: min(var(--content-width), 100%);
  min-height: 42px;
  margin: 0 auto;
  padding: 10px var(--page-gutter);
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-indicator {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: currentColor;
}

.auto-mode {
  background: var(--accent-soft);
  color: #09513c;
}

.manual-mode {
  background: #e9e7df;
  color: #39453f;
}

.workspace {
  width: min(var(--content-width), 100%);
  margin: 0 auto;
  padding: 30px var(--page-gutter) 88px;
}

.app-alert {
  margin: 0 0 20px;
  border-radius: 3px;
}

.control-section {
  padding: 10px 0 34px;
  border-bottom: 1px solid var(--line);
}

.automation-summary {
  margin-bottom: 34px;
  padding: 22px 0 24px;
  display: grid;
  grid-template-columns: minmax(280px, 1.15fr) minmax(420px, 1fr);
  gap: 16px 40px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
}

.automation-on {
  box-shadow: inset 4px 0 0 var(--accent);
  padding-left: 22px;
}

.automation-off {
  grid-template-columns: 1fr;
  box-shadow: inset 4px 0 0 var(--line-strong);
  padding-left: 22px;
}

.automation-copy h2 {
  margin: 10px 0 4px;
  font-family: var(--serif);
  font-size: clamp(1.35rem, 2.2vw, 1.85rem);
  font-weight: 400;
  letter-spacing: -0.02em;
}

.automation-copy p,
.automation-timezone {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.automation-copy code {
  color: var(--ink);
}

.automation-timeline {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-self: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  list-style: none;
}

.automation-timeline li {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.automation-timeline li:last-child {
  border-right: 0;
}

.automation-timeline time,
.automation-timeline span {
  display: block;
}

.automation-timeline time {
  font-family: var(--serif);
  font-size: 1.28rem;
  font-variant-numeric: tabular-nums;
}

.automation-timeline span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.automation-timezone {
  grid-column: 2;
  text-align: right;
}

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

.section-heading h2 {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: clamp(1.75rem, 3vw, 2.55rem);
  font-weight: 400;
  letter-spacing: -0.02em;
}

.section-heading > p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.compact-heading h2 {
  font-size: clamp(1.55rem, 2.4vw, 2.1rem);
}

.manual-workflow {
  margin: 0 0 22px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
}

.manual-workflow > summary {
  width: 100%;
  min-height: 62px;
  padding: 14px 2px;
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}

.manual-workflow > summary::-webkit-details-marker {
  display: none;
}

.manual-workflow > summary span {
  font-size: 0.84rem;
  font-weight: 800;
}

.manual-workflow > summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
}

.manual-workflow > summary::after {
  content: "+";
  width: 30px;
  height: 30px;
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--accent);
  font-size: 1.2rem;
  line-height: 1;
}

.manual-workflow[open] > summary::after {
  content: "−";
}

.manual-workflow-body {
  padding: 24px 0 28px;
  border-top: 1px solid var(--line);
}

.workflow-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
}

.workflow-step {
  min-width: 0;
  min-height: 330px;
  padding: 22px;
  display: grid;
  grid-template-rows: auto auto minmax(52px, 1fr) auto auto auto;
  gap: 10px;
  border-right: 1px solid var(--line);
  transition: background-color 180ms ease, transform 180ms ease;
}

.workflow-step:last-child {
  border-right: 0;
}

.workflow-step:hover,
.workflow-step:focus-within {
  background: rgba(255, 255, 255, 0.52);
}

.workflow-step.featured-step {
  box-shadow: inset 0 3px 0 var(--accent);
}

.step-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.step-number {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.workflow-step h3,
.mode-control h3,
.subsection-heading h3,
.table-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 750;
}

.workflow-step > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
}

.workflow-step label,
.mode-field label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 750;
}

.workflow-button {
  width: 100%;
  margin-top: 2px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--white);
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.workflow-button:hover,
.workflow-button:focus-visible {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  color: var(--white);
  transform: translateY(-1px);
}

.mode-control {
  margin-top: 22px;
  padding-top: 22px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.55fr) minmax(230px, 0.6fr) auto;
  align-items: end;
  gap: 18px;
  border-top: 1px solid var(--line);
}

.mode-control-copy p:last-child {
  max-width: 620px;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.mode-control-copy .eyebrow {
  margin-bottom: 4px;
}

.mode-field {
  display: grid;
  gap: 5px;
}

.mode-button {
  min-width: 132px;
}

[hidden] {
  display: none !important;
}

.section-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 28px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 15px 0 13px;
  background: rgba(244, 243, 238, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.section-nav::-webkit-scrollbar {
  display: none;
}

.section-nav a {
  position: relative;
  flex: 0 0 auto;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 750;
  transition: color 160ms ease;
}

.section-nav a::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -14px;
  left: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 180ms ease;
}

.section-nav a:hover,
.section-nav a.is-active {
  color: var(--accent);
}

.section-nav a.is-active::after {
  transform: scaleX(1);
}

.dashboard-section {
  padding: 52px 0;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 50px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-strip > div {
  min-width: 0;
  min-height: 102px;
  padding: 20px 18px;
  border-right: 1px solid var(--line);
}

.metric-strip > div:nth-child(4n) {
  border-right: 0;
}

.metric-strip > div:nth-child(n + 5) {
  border-top: 1px solid var(--line);
}

.metric-strip span,
.proposal-metrics dt {
  display: block;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metric-strip strong {
  display: block;
  margin-top: 7px;
  overflow-wrap: anywhere;
  font-family: var(--serif);
  font-size: clamp(1.12rem, 1.7vw, 1.42rem);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  line-height: 1.22;
}

.status-strip > div {
  min-height: 112px;
}

.metric-time {
  font-family: var(--sans) !important;
  font-size: 0.98rem !important;
  font-weight: 700 !important;
}

.metric-model {
  font-family: var(--sans) !important;
  font-size: 1rem !important;
  font-weight: 750 !important;
  text-transform: capitalize;
}

.metric-model small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: none;
}

.compact-metrics > div {
  min-height: 104px;
}

.freshness-row,
.chart-labels {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  padding: 14px 0;
  color: var(--muted);
  font-size: 0.73rem;
}

.freshness-row strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.chart-wrap {
  margin-top: 24px;
}

.chart-wrap canvas {
  width: 100%;
  min-height: 220px;
  border-bottom: 1px solid var(--line);
}

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

.legend-line {
  width: 24px;
  height: 2px;
  display: inline-block;
}

.portfolio-line {
  background: var(--accent);
}

.benchmark-line {
  background: #738078;
}

.subsection-heading,
.table-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
}

.subsection-heading {
  margin: 34px 0 14px;
}

.subsection-heading p,
.table-header span {
  margin: 0;
  color: var(--muted);
  font-size: 0.73rem;
}

.table-header {
  margin: 36px 0 10px;
}

.operator-table {
  min-width: 820px;
  margin: 0;
  border-color: var(--line);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.operator-table th {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.63rem;
  font-weight: 750;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  white-space: nowrap;
}

.operator-table td {
  padding: 14px 12px;
  vertical-align: middle;
}

.operator-table tbody tr {
  transition: background-color 140ms ease;
}

.operator-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.48);
}

.operator-table small {
  display: block;
  max-width: 320px;
  margin-top: 3px;
  color: var(--muted);
}

.correlation {
  max-width: 132px !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state,
.side {
  display: inline-flex !important;
  width: fit-content;
  align-items: center;
  min-height: 24px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.62rem !important;
  font-weight: 800;
  letter-spacing: 0.045em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.state-success,
.state-succeeded,
.state-completed,
.state-executed,
.state-approved,
.side.buy {
  background: var(--accent-soft);
  color: #09513c !important;
}

.state-danger,
.state-failed,
.state-rejected,
.state-execution_rejected,
.side.sell {
  background: var(--danger-soft);
  color: #842b2b !important;
}

.state-running,
.state-awaiting_approval,
.state-queued {
  background: var(--warning-soft);
  color: var(--warning) !important;
}

.state-neutral,
.state-skipped,
.state-expired,
.state-pending {
  background: #e7e7e1;
  color: #566159 !important;
}

.proposal-list {
  border-top: 1px solid var(--line);
}

.proposal-row {
  padding: 26px 0;
  border-bottom: 1px solid var(--line);
  transition: background-color 180ms ease, padding 180ms ease;
}

.proposal-row:hover,
.proposal-row:focus-within {
  padding-right: 12px;
  padding-left: 12px;
  background: rgba(255, 255, 255, 0.48);
}

.proposal-primary {
  display: flex;
  align-items: center;
  gap: 12px;
}

.proposal-primary h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.58rem;
  font-weight: 400;
}

.proposal-primary .state {
  margin-left: auto;
}

.proposal-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(100px, 1fr));
  gap: 0;
  margin: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.proposal-metrics > div {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.proposal-metrics > div:last-child {
  border-right: 0;
}

.proposal-metrics dd {
  margin: 5px 0 0;
  font-variant-numeric: tabular-nums;
}

.rationale {
  margin-bottom: 4px;
}

.evidence {
  color: var(--muted);
  font-size: 0.82rem;
}

details {
  margin-top: 16px;
}

summary {
  width: fit-content;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 750;
}

.rule-list {
  margin: 12px 0 0;
  padding: 0;
  columns: 2;
  list-style: none;
}

.rule-list li {
  padding: 5px 0;
  break-inside: avoid;
  font-size: 0.75rem;
}

.rule-list li span {
  display: inline-block;
  width: 74px;
  font-weight: 800;
}

.rule-list .pass span {
  color: var(--accent);
}

.rule-list .fail span {
  color: var(--danger);
}

.proposal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 20px;
}

.proposal-actions form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 8px;
}

.audit-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.audit-list li {
  display: grid;
  grid-template-columns: 172px 1fr;
  gap: 28px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}

.audit-list time {
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.audit-list p {
  margin: 3px 0;
  color: var(--muted);
}

.empty-state {
  padding: 28px !important;
  color: var(--muted);
  text-align: center;
}

.login-shell,
.empty-shell {
  min-height: 100svh;
  padding: 24px;
  display: grid;
  place-items: center;
  background: var(--navy);
}

.login-panel {
  width: min(440px, 100%);
  padding: 46px;
  background: var(--paper-raised);
  border-top: 3px solid var(--accent);
  animation: rise 420ms ease both;
}

.login-panel h1,
.empty-shell h1 {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.02em;
}

.login-panel > .text-secondary {
  margin-top: 8px;
}

.login-form {
  display: grid;
  gap: 9px;
  margin-top: 30px;
}

.login-form label:not(:first-of-type) {
  margin-top: 8px;
}

.login-form button {
  margin-top: 13px;
}

.security-note {
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.security-note span {
  margin-right: 5px;
  color: var(--accent);
}

.empty-shell {
  display: block;
  color: var(--white);
}

.empty-shell pre {
  padding: 14px;
  overflow-x: auto;
  background: #071d18;
}

.reveal {
  animation: rise 360ms ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

  .workflow-step:nth-child(2) {
    border-right: 0;
  }

  .workflow-step:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .mode-control {
    grid-template-columns: minmax(280px, 1fr) minmax(220px, 0.7fr) minmax(230px, 0.7fr);
  }

  .mode-button {
    grid-column: 3;
  }
}

@media (max-width: 900px) {
  .automation-summary {
    grid-template-columns: 1fr;
  }

  .automation-timezone {
    grid-column: auto;
    text-align: left;
  }

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

  .metric-strip > div:nth-child(2n) {
    border-right: 0;
  }

  .metric-strip > div:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

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

  .proposal-metrics > div:nth-child(2n) {
    border-right: 0;
  }

  .proposal-metrics > div:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .proposal-metrics > div:last-child {
    border-right: 1px solid var(--line);
  }

  .rule-list {
    columns: 1;
  }

  .section-heading {
    display: block;
  }

  .section-heading > p {
    margin-top: 8px;
  }

  .topbar-inner {
    align-items: flex-start;
  }

  .topbar-actions {
    display: grid;
    justify-items: end;
    gap: 10px;
  }

  .mode-control {
    grid-template-columns: 1fr 1fr;
  }

  .mode-control-copy {
    grid-column: 1 / -1;
  }

  .mode-button {
    grid-column: 2;
  }
}

@media (max-width: 660px) {
  :root {
    --page-gutter: 16px;
    --control-height: 44px;
  }

  .topbar,
  .topbar-inner {
    min-height: 118px;
  }

  .topbar-inner {
    padding-top: 20px;
    padding-bottom: 20px;
  }

  .topbar h1 {
    font-size: 1.7rem;
  }

  .topbar-subtitle,
  .simulation-label {
    display: none;
  }

  .mode-banner-inner {
    align-items: flex-start;
  }

  .workspace {
    padding-top: 20px;
    padding-bottom: 64px;
  }

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

  .manual-workflow > summary {
    gap: 10px;
  }

  .manual-workflow > summary small {
    display: none;
  }

  .automation-summary,
  .automation-on,
  .automation-off {
    padding-left: 16px;
    padding-right: 4px;
  }

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

  .automation-timeline li:nth-child(2) {
    border-right: 0;
  }

  .automation-timeline li:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .workflow-step {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workflow-step:last-child {
    border-bottom: 0;
  }

  .mode-control {
    grid-template-columns: 1fr;
  }

  .mode-control-copy,
  .mode-button {
    grid-column: auto;
  }

  .mode-button {
    width: 100%;
  }

  .section-nav {
    gap: 22px;
  }

  .dashboard-section {
    padding: 42px 0;
  }

  .freshness-row,
  .chart-labels,
  .subsection-heading,
  .table-header {
    display: grid;
    gap: 6px;
  }

  .proposal-actions {
    grid-template-columns: 1fr;
  }

  .proposal-actions form {
    grid-template-columns: 1fr;
  }

  .audit-list li {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .login-panel {
    padding: 34px 26px;
  }
}

@media (max-width: 430px) {
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .metric-strip > div {
    min-height: 88px;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .metric-strip > div:first-child {
    border-top: 0;
  }

  .proposal-primary {
    flex-wrap: wrap;
  }

  .proposal-primary .state {
    width: 100%;
    margin-left: 0;
  }

  .proposal-metrics {
    grid-template-columns: 1fr;
  }

  .proposal-metrics > div {
    border-right: 0 !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
