:root {
  --bg: #f5f7f6;
  --paper: #ffffff;
  --paper-soft: #edf4f2;
  --ink: #142022;
  --muted: #58666a;
  --line: #d6e0dd;
  --accent: #0b6f74;
  --accent-dark: #07525a;
  --accent-soft: #dcefed;
  --positive: #176b45;
  --negative: #a43a36;
  --shadow: 0 16px 40px rgba(20, 32, 34, 0.07);
}

* {
  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.5;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 68px;
  padding: 0 4vw;
  background: rgba(245, 247, 246, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  color: var(--accent-dark);
  font-weight: 750;
  text-decoration: none;
}

.app-identity {
  display: flex;
  align-items: center;
  gap: 11px;
}

.app-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--accent-dark);
  font-weight: 850;
}

.app-identity div {
  display: grid;
}

.app-identity strong {
  font-size: 0.94rem;
}

.app-identity div span {
  color: var(--muted);
  font-size: 0.76rem;
}

.data-date {
  justify-self: end;
  color: var(--muted);
  font-size: 0.8rem;
}

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

.app-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 40px;
  margin-bottom: 28px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1.08;
}

.app-intro > div:first-child > p:last-child {
  max-width: 820px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.model-scope {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 430px;
}

.model-scope span {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(440px, 0.78fr) minmax(600px, 1.22fr);
  gap: 22px;
  align-items: start;
}

.control-panel,
.results-panel {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel-heading,
.legs-heading,
.results-heading,
.chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h2 {
  font-size: 1.22rem;
}

h3 {
  font-size: 1rem;
}

.text-button {
  padding: 7px 9px;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 750;
}

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

label,
.read-only-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label > span,
.read-only-field > span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
}

input,
select,
.read-only-field strong {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(11, 111, 116, 0.18);
  outline-offset: 1px;
  border-color: var(--accent);
}

.read-only-field strong {
  display: flex;
  align-items: center;
  background: var(--paper-soft);
}

.market-note {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 0.78rem;
}

.legs-heading {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.leg-actions {
  display: flex;
  gap: 7px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--accent-dark);
  font-size: 1.25rem;
  font-weight: 800;
}

.icon-button:hover {
  background: var(--paper-soft);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.legs-container {
  display: grid;
  gap: 12px;
  margin-top: 15px;
}

.leg-panel {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfc;
}

.leg-panel legend {
  padding: 0 7px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

.atmf-control {
  display: flex;
  align-items: center;
  align-self: end;
  min-height: 42px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.atmf-control input {
  width: 16px;
  min-height: auto;
  margin: 0 8px 0 0;
}

.atmf-control span {
  color: var(--ink);
}

.primary-action {
  width: 100%;
  min-height: 46px;
  margin-top: 18px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.result-status {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

.metric-strip > div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-soft);
}

.metric-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
}

.metric-strip strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 5px;
  font-size: 1.06rem;
}

.chart-section,
.breakdown-section {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.chart-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.72rem;
}

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

.chart-legend i {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--accent);
}

.chart-legend .legend-spot {
  height: 0;
  border-top: 2px dashed #7f8d90;
  background: transparent;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 360px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  overflow: hidden;
}

#pnl-chart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  white-space: nowrap;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

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

.empty-row td {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.assumption-note {
  margin-top: 20px;
  padding: 13px 14px;
  border-left: 3px solid var(--accent);
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 0.8rem;
}

.assumption-note strong {
  color: var(--ink);
}

.app-message {
  margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: 7px;
}

.error-message {
  border: 1px solid #e6bbb8;
  background: #fff2f1;
  color: #7e2926;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel,
  .results-panel {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .app-header {
    grid-template-columns: auto 1fr;
    gap: 16px;
    padding: 10px 18px;
  }

  .app-identity {
    justify-self: end;
  }

  .data-date {
    display: none;
  }

  .app-shell {
    width: calc(100% - 28px);
    padding-top: 34px;
  }

  .app-intro {
    display: block;
  }

  .model-scope {
    justify-content: flex-start;
    margin-top: 18px;
  }

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

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

@media (max-width: 540px) {
  .app-identity div {
    display: none;
  }

  .control-panel,
  .results-panel {
    padding: 17px;
  }

  .market-grid,
  .leg-grid {
    grid-template-columns: 1fr;
  }

  .notional-field {
    grid-column: auto;
  }

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

  .chart-wrap {
    height: 300px;
  }
}
