:root {
  --bg: #f5efe4;
  --bg-accent: #ead8bc;
  --panel: rgba(255, 251, 245, 0.84);
  --line: rgba(60, 43, 17, 0.15);
  --text: #1d150b;
  --muted: #6d604f;
  --green: #0b7a53;
  --red: #b3452f;
  --gold: #d39218;
  --shadow: 0 24px 80px rgba(74, 52, 20, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(242, 187, 97, 0.32), transparent 30%),
    radial-gradient(circle at top right, rgba(175, 108, 58, 0.26), transparent 22%),
    linear-gradient(180deg, #fff8ed 0%, var(--bg) 48%, #ecdfca 100%);
}

.page-shell {
  width: 100%;
  margin: 0;
  min-height: 100vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.hero {
  padding: 4px 8px 12px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  color: var(--muted);
}

.hero h1 {
  margin: 0;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1.1;
  font-weight: 800;
  max-width: none;
}

.hero h1 .formula {
  font-size: 0.72em;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.hero-copy {
  max-width: none;
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: 28px;
  padding: 24px;
  min-height: 0;
  position: relative;
}

.controls-panel,
.table-panel {
  grid-column: 1;
}

.controls-panel {
  z-index: 3;
}

.summary-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.table-panel {
  z-index: 2;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 20px;
}

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

.status {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(29, 21, 11, 0.05);
}

.status.running {
  color: #fff7eb;
  background: linear-gradient(135deg, #b46415, #dc9b29);
}

.status.error {
  color: #fff4ef;
  background: linear-gradient(135deg, #8e3120, #c16035);
}

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

.controls-grid label {
  display: grid;
  gap: 6px;
}

.controls-grid span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.field-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(60, 43, 17, 0.18);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  cursor: help;
  outline: none;
}

.info-chip:focus-visible {
  box-shadow: 0 0 0 2px rgba(91, 59, 24, 0.18);
}

.info-tooltip {
  position: absolute;
  left: 100%;
  top: calc(100% + 8px);
  transform: translateX(-8px);
  width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f5f1e8;
  color: rgba(29, 21, 11, 0.92);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 5;
  border: 1px solid rgba(60, 43, 17, 0.12);
  box-shadow: 0 10px 24px rgba(20, 13, 5, 0.12);
  backdrop-filter: blur(8px);
}

.info-chip:hover .info-tooltip,
.info-chip:focus-visible .info-tooltip {
  opacity: 1;
  visibility: visible;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
}

input[type="range"] {
  padding: 0;
  accent-color: #5b3b18;
  background: transparent;
}

.slider-field {
  grid-column: 1 / -1;
}

.slider-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  align-items: center;
  gap: 10px;
}

.slider-meta output {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  font-weight: 700;
}

.primary-button {
  grid-column: 1 / -1;
  margin-top: 2px;
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  color: #fff8ec;
  font-weight: 800;
  background: linear-gradient(135deg, #22211e, #5b3b18);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(43, 30, 11, 0.25);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-card {
  border-radius: 16px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.95), rgba(244, 234, 218, 0.9));
  border: 1px solid rgba(71, 49, 20, 0.08);
  min-height: 82px;
}

.summary-card .label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.summary-card .value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
}

.value.positive {
  color: var(--green);
}

.value.negative {
  color: var(--red);
}

.chart-wrap {
  position: relative;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 233, 215, 0.75));
  padding: 18px;
  border: 1px solid rgba(71, 49, 20, 0.08);
  flex: 0 0 auto;
  height: 396px;
  overflow: hidden;
}

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

.chart-tooltip {
  position: absolute;
  min-width: 180px;
  max-width: 240px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(30, 22, 12, 0.92);
  color: #fff8ec;
  box-shadow: 0 16px 34px rgba(20, 13, 5, 0.24);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
  transition: opacity 120ms ease;
  z-index: 2;
}

.chart-tooltip.hidden {
  opacity: 0;
}

.chart-tooltip:not(.hidden) {
  opacity: 1;
}

.chart-tooltip .tooltip-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: rgba(255, 248, 236, 0.72);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chart-tooltip .tooltip-action {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.chart-tooltip .tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.chart-tooltip .tooltip-row span:last-child {
  font-weight: 700;
}

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

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

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid rgba(60, 43, 17, 0.08);
  white-space: nowrap;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

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

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .controls-panel,
  .table-panel,
  .summary-panel {
    grid-column: auto;
    grid-row: auto;
  }

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

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

@media (max-width: 640px) {
  .page-shell {
    width: 100%;
    padding: 12px;
  }

  .hero {
    padding: 2px 2px 10px;
  }

  .panel {
    border-radius: 22px;
    padding: 18px;
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }

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

  .slider-field,
  .primary-button {
    grid-column: auto;
  }

  .chart-wrap {
    height: 320px;
    padding: 14px;
  }
}
