:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --panel: #ffffff;
  --ink: #1e2520;
  --muted: #6f796f;
  --line: #dfe4dc;
  --green: #1e6f54;
  --green-soft: #e3f1e9;
  --amber: #b36b12;
  --amber-soft: #fff0d6;
  --red: #b73e3e;
  --red-soft: #fce5e3;
  --blue: #245f9f;
  --shadow: 0 16px 42px rgba(29, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 22px;
  box-shadow: 0 8px 24px rgba(29, 38, 31, 0.06);
}

.icon-button:hover {
  border-color: #b8c3b7;
}

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

.summary-strip article {
  min-height: 94px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-strip span,
.panel-title span,
.metric-list dt,
.range-stack span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-strip strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  line-height: 1.1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 14px;
  align-items: start;
}

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

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

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

.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}

.panel-title span {
  white-space: nowrap;
  padding-top: 3px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30, 111, 84, 0.12);
}

.suffix-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
}

.suffix-field input {
  border-radius: 8px 0 0 8px;
}

.suffix-field b {
  display: grid;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background: #eef2eb;
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.profit-mode,
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 16px 0;
}

.radio-chip {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  color: var(--ink);
}

.radio-chip input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.detail-fields {
  display: none;
  padding-top: 0;
}

.sheet-import {
  margin: 0 16px 16px;
}

.sheet-import textarea {
  min-height: 92px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

.is-detail-mode .detail-fields {
  display: grid;
}

.is-detail-mode .profit-rate-fields {
  display: none;
}

.result-column {
  display: grid;
  gap: 14px;
  position: sticky;
  top: 14px;
}

.result-panel {
  overflow: hidden;
}

.metric-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 12px 16px 16px;
}

.metric-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.metric-list div:last-child {
  border-bottom: 0;
}

.metric-list dd {
  margin: 0;
  font-weight: 850;
  text-align: right;
}

.range-stack {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.range-stack div {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
}

.range-stack strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.advice-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 16px;
  list-style: none;
}

.advice-list li {
  padding: 12px;
  border-radius: 8px;
  background: var(--green-soft);
  color: #194b3c;
  font-size: 14px;
  line-height: 1.55;
}

.advice-list li.warn {
  background: var(--amber-soft);
  color: #70450e;
}

.advice-list li.danger {
  background: var(--red-soft);
  color: #7b2424;
}

.output-area {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scenario-panel {
  margin-top: 14px;
}

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

.table-scroll {
  margin: 0 16px 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.compact-table {
  margin-top: 10px;
}

.scenario-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  background: #ffffff;
}

.scenario-table th,
.scenario-table td {
  padding: 13px 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.scenario-table th {
  background: #f7f8f4;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
}

.scenario-table th:first-child,
.scenario-table td:first-child {
  text-align: left;
  font-weight: 850;
}

.scenario-table tr:last-child td {
  border-bottom: 0;
}

.scenario-table th:last-child,
.scenario-table td:last-child {
  border-right: 0;
}

.import-status {
  margin: 0 16px 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.import-status.ready {
  border-color: #bdd8c9;
  background: var(--green-soft);
  color: #194b3c;
}

.tab {
  min-width: 94px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

#outputText {
  display: block;
  min-height: 350px;
  margin: 16px;
  padding: 16px;
  resize: vertical;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
}

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

.neutral {
  color: var(--amber);
}

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

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

  .result-column {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 16px;
  }

  .topbar {
    align-items: stretch;
  }

  .summary-strip,
  .input-grid,
  .field-grid,
  .scenario-controls,
  .result-column {
    grid-template-columns: 1fr;
  }

  .summary-strip article {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
  }

  .panel-title {
    display: grid;
  }

  .panel-title span {
    white-space: normal;
  }
}
