@import url("https://fonts.googleapis.com/css2?family=Archivo:wdth,wght@85..115,400..750&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

:root {
  --fog: #e9eef0;
  --paper: #f8faf9;
  --paper-strong: #ffffff;
  --ledger: #152a35;
  --ledger-soft: #2e434c;
  --muted: #64767d;
  --line: #cbd5d7;
  --line-soft: #dde4e5;
  --copper: #c4512d;
  --copper-soft: #f3ded6;
  --settle: #1e7466;
  --settle-soft: #d9ebe7;
  --loss: #b23a48;
  --loss-soft: #f4dce0;
  --signal: #2f6985;
  --signal-soft: #dbe9ef;
  --shadow: 0 18px 48px rgba(21, 42, 53, 0.08);
  --font-ui: "Archivo", "Aptos", "Segoe UI", sans-serif;
  --font-data: "IBM Plex Mono", "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--fog);
  color: var(--ledger);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

button {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--copper);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  transform: translateY(-160%);
  border-radius: 8px;
  background: var(--ledger);
  color: white;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(1460px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 68px;
  margin-bottom: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ledger);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-width: 2.3;
}

.brand-mark circle {
  fill: var(--copper);
  stroke: var(--copper);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.12rem;
  font-variation-settings: "wdth" 108;
  letter-spacing: -0.025em;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.76rem;
}

.sync-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sync-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.refresh-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--ledger);
  border-radius: 10px;
  background: transparent;
  color: var(--ledger);
  cursor: pointer;
  font-weight: 650;
}

.refresh-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.refresh-button:hover {
  background: var(--ledger);
  color: white;
}

.refresh-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.error-banner {
  margin-bottom: 18px;
  padding: 13px 16px;
  border: 1px solid var(--loss);
  border-radius: 10px;
  background: var(--loss-soft);
  color: #7b1f2c;
  font-weight: 600;
}

.readiness {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.72fr);
  min-height: 300px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left: 10px solid var(--copper);
  border-radius: 22px 22px 7px 22px;
  background: var(--paper-strong);
  box-shadow: var(--shadow);
}

body[data-entry="live"] .readiness {
  border-left-color: var(--settle);
}

.readiness-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(30px, 5vw, 70px);
}

.status-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.entry-indicator {
  width: 11px;
  height: 11px;
  border: 2px solid var(--copper);
  border-radius: 50%;
  background: var(--copper-soft);
}

body[data-entry="live"] .entry-indicator {
  border-color: var(--settle);
  background: var(--settle-soft);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 29px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--copper-soft);
  color: #853217;
  font-size: 0.75rem;
  font-weight: 700;
}

body[data-entry="live"] #entry-state {
  background: var(--settle-soft);
  color: #115b4e;
}

.status-chip-muted {
  background: var(--fog);
  color: var(--ledger-soft);
}

.readiness h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 4.7rem);
  font-variation-settings: "wdth" 92;
  font-weight: 720;
  letter-spacing: -0.065em;
  line-height: 0.98;
}

.readiness-copy {
  max-width: 680px;
  margin: 24px 0 0;
  color: var(--ledger-soft);
  font-size: clamp(1rem, 1.5vw, 1.18rem);
  line-height: 1.55;
}

.readiness-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-top: 28px;
  color: var(--muted);
  font-family: var(--font-data);
  font-size: 0.72rem;
}

.risk-ticket {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 38px;
  background: var(--ledger);
  color: white;
}

.risk-ticket h2 {
  margin: 0 0 8px;
  color: #b9c8cd;
  font-size: 0.87rem;
  font-weight: 500;
}

.risk-primary {
  margin: 0;
  font-family: var(--font-data);
  font-size: clamp(1.9rem, 3vw, 3.2rem);
  font-weight: 600;
  letter-spacing: -0.05em;
}

.risk-scale {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 4px;
  height: 7px;
  margin: 24px 0 14px;
}

.risk-scale span {
  display: block;
}

.risk-scale-loss { background: #dc6672; }
.risk-scale-hold { background: #9caeb4; }
.risk-scale-win { background: #4db09e; }

.risk-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 0;
}

.risk-detail div:last-child {
  text-align: right;
}

.risk-detail dt {
  color: #9fb0b6;
  font-size: 0.73rem;
}

.risk-detail dd {
  margin: 3px 0 0;
  font-family: var(--font-data);
  font-size: 1rem;
  font-weight: 600;
}

.risk-footnote {
  max-width: 36ch;
  margin: 28px 0 0;
  color: #b9c8cd;
  font-size: 0.76rem;
  line-height: 1.55;
}

.execution-flow {
  margin-top: 22px;
  padding: 24px 0 18px;
  border-top: 1px solid var(--ledger);
  border-bottom: 1px solid var(--ledger);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line-soft);
}

.flow-heading {
  padding: 0 0 18px;
  border: 0;
}

.section-heading h2,
.section-heading p {
  margin: 0;
}

.section-heading h2 {
  font-size: 1.18rem;
  font-variation-settings: "wdth" 108;
  letter-spacing: -0.025em;
}

.section-heading p {
  max-width: 62ch;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.quiet-count {
  flex: 0 0 auto;
  padding-top: 2px;
  color: var(--muted);
  font-family: var(--font-data);
  font-size: 0.74rem;
}

.flow-rail {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  margin: 0;
  padding: 0;
  list-style: none;
}

.flow-rail li {
  position: relative;
  min-width: 0;
  padding: 13px 14px 8px 0;
}

.flow-rail li:not(:last-child)::after {
  position: absolute;
  z-index: 0;
  top: 24px;
  right: 0;
  left: 34px;
  height: 1px;
  background: var(--line);
  content: "";
}

.flow-node {
  position: relative;
  z-index: 1;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  margin-bottom: 12px;
  border: 1px solid var(--ledger);
  border-radius: 50%;
  background: var(--fog);
  font-family: var(--font-data);
  font-size: 0.66rem;
}

.flow-rail strong,
.flow-rail small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-rail strong {
  font-size: 0.85rem;
}

.flow-rail small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
}

.ledger-strip {
  display: grid;
  grid-template-columns: 1.45fr repeat(4, 1fr);
  margin: 22px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px 18px 18px 18px;
  background: var(--paper);
}

.ledger-strip article {
  min-width: 0;
  padding: 24px;
  border-left: 1px solid var(--line-soft);
}

.ledger-strip .ledger-primary {
  border-left: 0;
  background: #dfe7e8;
}

.ledger-strip p,
.ledger-strip strong,
.ledger-strip small {
  display: block;
  margin: 0;
}

.ledger-strip p {
  color: var(--muted);
  font-size: 0.76rem;
}

.ledger-strip strong {
  margin-top: 9px;
  overflow: hidden;
  font-family: var(--font-data);
  font-size: clamp(1.25rem, 2vw, 1.85rem);
  font-weight: 600;
  letter-spacing: -0.055em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-strip small {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.positive { color: var(--settle) !important; }
.negative { color: var(--loss) !important; }
.warning { color: var(--copper) !important; }

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper-strong);
}

.position-panel {
  margin-bottom: 22px;
  border-radius: 18px 6px 18px 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.scroll-hint {
  display: none;
}

table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #eef2f2;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #f5f8f7;
}

.token-cell strong,
.token-cell small {
  display: block;
}

.token-cell strong {
  font-size: 0.9rem;
}

.token-cell small,
.table-muted {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.68rem;
}

.data-cell {
  font-family: var(--font-data);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 7px;
  background: var(--signal-soft);
  color: #24536a;
  font-size: 0.7rem;
  font-weight: 700;
}

.status-open {
  background: var(--settle-soft);
  color: #115b4e;
}

.status-loss,
.status-rug {
  background: var(--loss-soft);
  color: #862536;
}

.status-target {
  background: var(--settle-soft);
  color: #115b4e;
}

.status-manual,
.status-empty {
  background: #e4e9ea;
  color: #52656c;
}

.risk-flag {
  display: block;
  margin-top: 5px;
  color: var(--loss);
  font-size: 0.67rem;
  font-weight: 700;
}

.row-link {
  color: var(--signal);
  font-weight: 650;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.row-link:hover {
  color: var(--copper);
}

.loading-state,
.empty-state {
  display: grid;
  min-height: 170px;
  place-items: center;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.empty-state div {
  max-width: 48ch;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state strong {
  margin-bottom: 5px;
  color: var(--ledger);
}

.loading-state.compact,
.empty-state.compact {
  min-height: 90px;
  padding: 18px 0;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  align-items: start;
  gap: 22px;
}

.calls-chart {
  min-height: 232px;
  padding: 22px 22px 10px;
}

.calls-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-grid {
  stroke: var(--line-soft);
  stroke-width: 1;
}

.chart-bar {
  fill: var(--signal);
}

.chart-bar-zero {
  fill: var(--line);
}

.chart-label,
.chart-value {
  fill: var(--muted);
  font-family: var(--font-data);
  font-size: 10px;
}

.chart-value {
  fill: var(--ledger);
  font-weight: 600;
  text-anchor: middle;
}

.chart-label {
  text-anchor: middle;
}

.activity-columns {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 26px;
  padding: 4px 24px 24px;
}

.activity-columns h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.source-row,
.call-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 43px;
  border-top: 1px solid var(--line-soft);
  font-size: 0.76rem;
}

.source-row strong {
  font-family: var(--font-data);
}

.source-row span,
.call-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-row a {
  flex: 0 0 auto;
  color: var(--signal);
  font-family: var(--font-data);
  font-size: 0.69rem;
}

.decision-list {
  max-height: 555px;
  overflow-y: auto;
}

.decision-item {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.decision-item:last-child {
  border-bottom: 0;
}

.decision-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.decision-token {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.decision-token strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.decision-score {
  flex: 0 0 auto;
  color: var(--muted);
  font-family: var(--font-data);
  font-size: 0.72rem;
}

.decision-item details {
  margin-top: 11px;
}

.decision-item summary {
  color: var(--signal);
  cursor: pointer;
  font-size: 0.73rem;
  font-weight: 650;
}

.decision-item details p {
  margin: 10px 0 0;
  color: var(--ledger-soft);
  font-size: 0.77rem;
}

.decision-meta {
  margin-top: 10px;
  color: var(--muted);
  font-family: var(--font-data);
  font-size: 0.67rem;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 4px 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.footer p {
  margin: 0;
}

.footer a {
  color: var(--signal);
  font-family: var(--font-data);
}

@media (max-width: 1080px) {
  .readiness {
    grid-template-columns: 1fr minmax(300px, 0.72fr);
  }

  .readiness-main {
    padding: 38px;
  }

  .ledger-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .ledger-strip article:nth-child(4) {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .ledger-strip article:nth-child(5) {
    border-top: 1px solid var(--line-soft);
  }

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

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 28px, 720px);
    padding-top: 14px;
  }

  .masthead {
    align-items: flex-start;
  }

  .sync-tools {
    align-items: flex-end;
    flex-direction: column-reverse;
  }

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

  .risk-ticket {
    min-height: 250px;
  }

  .flow-rail {
    grid-template-columns: repeat(3, 1fr);
    row-gap: 8px;
  }

  .flow-rail li:nth-child(3)::after {
    display: none;
  }

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

  .ledger-strip article:nth-child(odd) {
    border-left: 0;
  }

  .ledger-strip article:nth-child(n+3) {
    border-top: 1px solid var(--line-soft);
  }

  .ledger-strip .ledger-primary {
    grid-column: 1 / -1;
  }
}

@media (max-width: 580px) {
  .app-shell {
    width: min(100% - 20px, 520px);
  }

  .masthead {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .sync-tools {
    align-items: center;
    justify-content: space-between;
    flex-direction: row;
  }

  .brand small {
    font-size: 0.7rem;
  }

  .readiness {
    border-left-width: 7px;
    border-radius: 16px 16px 5px 16px;
  }

  .readiness-main,
  .risk-ticket {
    padding: 28px 23px;
  }

  .readiness h1 {
    font-size: 2.55rem;
  }

  .readiness-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .flow-heading,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .flow-rail {
    grid-template-columns: repeat(2, 1fr);
  }

  .flow-rail li:nth-child(3)::after {
    display: block;
  }

  .flow-rail li:nth-child(even)::after {
    display: none;
  }

  .ledger-strip {
    grid-template-columns: 1fr;
  }

  .ledger-strip article,
  .ledger-strip article:nth-child(odd),
  .ledger-strip article:nth-child(even) {
    border-top: 1px solid var(--line-soft);
    border-left: 0;
  }

  .ledger-strip .ledger-primary {
    border-top: 0;
  }

  .scroll-hint {
    display: block;
    margin: 0;
    padding: 9px 22px;
    border-bottom: 1px solid var(--line-soft);
    background: #eef2f2;
    color: var(--muted);
    font-size: 0.7rem;
  }

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

  .calls-chart {
    min-height: 190px;
    padding-right: 10px;
    padding-left: 10px;
  }

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

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
