:root {
  color-scheme: light;
  --ink: #172126;
  --muted: #667782;
  --line: #d7dee2;
  --page: #f5f7f6;
  --panel: #ffffff;
  --teal: #0f7f8d;
  --teal-dark: #0c3b42;
  --green: #0b7658;
  --purple: #69588e;
  --amber: #b56b00;
  --input: #fff2c7;
  --input-strong: #ffe39d;
  --soft: #eef4f2;
  --danger: #a83232;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    Arial,
    sans-serif;
  line-height: 1.4;
}

button,
input {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 94px;
  padding: 22px 24px;
  color: #ffffff;
  background: var(--teal-dark);
  border-radius: 8px 8px 0 0;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  color: #a9d6dc;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

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

.ghost-button,
.primary-button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  padding: 0 13px;
  cursor: pointer;
}

.ghost-button {
  background: transparent;
  color: #ffffff;
}

.primary-button {
  border-color: #f2be54;
  background: #f2be54;
  color: #18262c;
  font-weight: 700;
}

.ghost-button:hover,
.primary-button:hover {
  filter: brightness(1.05);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: 18px;
  align-items: start;
  padding: 18px;
  background: #eef3f2;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

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

.input-panel {
  grid-row: span 2;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 16px;
  color: #ffffff;
  background: var(--teal);
  font-weight: 800;
}

.results-panel .section-title {
  background: var(--green);
}

.breakdown-panel .section-title {
  background: var(--purple);
}

.sensitivity-panel .section-title {
  background: var(--amber);
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.muted {
  font-weight: 600;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(160px, 0.9fr);
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}

.field-row > span {
  font-weight: 800;
}

.highlight-row {
  background: #fff9e8;
}

.input-wrap {
  position: relative;
}

.input-wrap::before,
.input-wrap::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #52616b;
  font-weight: 800;
  pointer-events: none;
}

.input-wrap.currency::before {
  content: "$";
  left: 12px;
}

.input-wrap.percent::after {
  content: "%";
  right: 12px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #d3c37f;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--input);
  color: var(--ink);
  text-align: right;
  font-weight: 800;
  outline: none;
}

.currency input {
  padding-left: 30px;
}

.percent input {
  padding-right: 32px;
}

input:focus {
  border-color: #a06b00;
  background: var(--input-strong);
  box-shadow: 0 0 0 3px rgba(181, 107, 0, 0.16);
}

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

.metric {
  min-height: 92px;
  padding: 14px;
  border: 1px solid #cfddd6;
  border-radius: 8px;
  background: #edf7f2;
}

.metric.wide {
  grid-column: 1 / -1;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  font-size: 26px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric.negative strong,
.bar-row.negative strong,
td.negative {
  color: var(--danger);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  background: #f8faf9;
}

.summary-strip div {
  min-height: 72px;
  padding: 12px 16px;
  border-right: 1px solid var(--line);
}

.summary-strip div:last-child {
  border-right: 0;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-strip strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.bar-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: 74px minmax(110px, 1fr) 90px;
  align-items: center;
  gap: 10px;
}

.bar-row span {
  font-weight: 800;
}

.bar-row strong {
  text-align: right;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  background: #e9edf0;
  border-radius: 999px;
}

.bar-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 160ms ease;
}

.bar-row[data-key="referral"] .bar-track i {
  background: var(--purple);
}

.bar-row[data-key="ads"] .bar-track i {
  background: #d99b26;
}

.bar-row[data-key="other"] .bar-track i {
  background: #64748b;
}

.bar-row[data-key="profit"] .bar-track i {
  background: var(--green);
}

.bar-row[data-key="profit"].negative .bar-track i {
  background: var(--danger);
}

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

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

th,
td {
  min-height: 44px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th {
  background: #f3f5f6;
  color: #39464d;
  font-size: 13px;
}

th:first-child,
td:first-child {
  text-align: left;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  color: #ffffff;
  background: #172126;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(23, 33, 38, 0.22);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding-top: 12px;
  }

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

  .actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .input-panel {
    grid-row: auto;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 24px;
  }

  .topbar {
    padding: 18px;
  }

  .ghost-button,
  .primary-button {
    flex: 1 1 auto;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

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

  .summary-strip div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-strip div:last-child {
    border-bottom: 0;
  }

  .bar-row {
    grid-template-columns: 66px minmax(90px, 1fr) 82px;
    gap: 8px;
  }

  .metric strong {
    font-size: 22px;
  }
}
