:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef3ee;
  --text: #18211d;
  --muted: #68736c;
  --line: #dce5df;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --profit: #9b2c2c;
  --stock: #2f5f98;
  --green: #12733a;
  --red: #b42318;
  --shadow: 0 12px 28px rgba(24, 33, 29, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

.shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3,
p {
  margin: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin-top: 8px;
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 18px;
}

.subtle {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.focus-panel,
.section,
.kpi-card,
.version-footer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.focus-panel {
  min-width: 220px;
  padding: 13px 15px;
}

.focus-panel span,
.module-label,
.select-control span,
.kpi-card span,
.kpi-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.focus-panel strong {
  display: block;
  margin-top: 7px;
  font-size: 18px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.tab-button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.tab-button.is-active {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--surface-soft);
  color: var(--accent-dark);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head.compact {
  align-items: center;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  flex-wrap: wrap;
}

.title-row h3 {
  flex: 0 0 auto;
}

.module-label {
  margin-bottom: 5px;
  font-weight: 700;
}

.select-control {
  display: flex;
  align-items: center;
  gap: 9px;
}

.select-control.inline {
  margin-top: 0;
  flex: 0 0 auto;
}

select {
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
}

.kpi-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.kpi-grid.five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.kpi-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.kpi-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-card {
  padding: 15px;
}

.kpi-card strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 22px;
  line-height: 1.15;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.overview-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.overview-card span,
.overview-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.overview-card strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 22px;
  line-height: 1.15;
}

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

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

.section {
  padding: 16px;
  margin-top: 14px;
}

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

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

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

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

th {
  position: sticky;
  top: 0;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 800;
}

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

.note-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.shipping-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.shipping-note p + p {
  margin-top: 5px;
}

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

.product-analysis-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.product-analysis-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.product-analysis-head > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.product-analysis-head h4 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.product-analysis-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  word-break: break-all;
}

.product-analysis-head span,
.product-analysis-card p {
  color: var(--muted);
  font-size: 13px;
}

.product-analysis-head > span {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-soft);
}

.product-analysis-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.product-analysis-metrics span {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

.product-analysis-metrics strong {
  display: block;
  color: var(--text);
  font-size: 20px;
  line-height: 1.25;
}

.product-analysis-metrics strong.positive {
  color: var(--red);
}

.product-analysis-metrics strong.negative {
  color: var(--green);
}

.profit-curve {
  width: 100%;
  height: 112px;
  margin-top: 8px;
}

.profit-curve polyline {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.profit-curve circle {
  fill: var(--accent);
}

.profit-curve text {
  fill: var(--muted);
  font-size: 9px;
  text-anchor: middle;
}

.product-analysis-card p {
  margin-top: 6px;
  line-height: 1.45;
}

.product-bucket-wrap {
  overflow-x: auto;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.product-bucket-table {
  min-width: 560px;
  font-size: 12px;
}

.product-bucket-table th,
.product-bucket-table td {
  padding: 8px;
  white-space: normal;
  text-align: left;
  vertical-align: top;
}

.product-bucket-table th {
  color: var(--muted);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 18px;
}

.empty-state strong {
  display: block;
  font-size: 18px;
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.forecast-product {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.forecast-product + .forecast-product {
  margin-top: 12px;
}

.forecast-table-wrap {
  margin-top: 12px;
}

.forecast-subtable + .forecast-subtable {
  margin-top: 16px;
}

.forecast-subtable-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.forecast-subtable-head div {
  display: grid;
  gap: 3px;
}

.forecast-subtable-head strong {
  color: var(--text);
  font-size: 15px;
}

.forecast-subtable-head span {
  color: var(--muted);
  font-size: 13px;
}

.forecast-table {
  min-width: 720px;
}

.forecast-table th,
.forecast-table td {
  text-align: right;
}

.forecast-table th:first-child,
.forecast-table td:first-child {
  min-width: 120px;
  text-align: left;
}

.forecast-cell {
  min-width: 136px;
  text-align: right;
  vertical-align: top;
}

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

.forecast-cell strong {
  font-size: 20px;
  color: var(--green);
}

.forecast-cell.needs-stock strong {
  color: var(--red);
}

.forecast-cell span {
  margin-top: 4px;
  color: var(--text);
  font-weight: 700;
}

.forecast-cell small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.forecast-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.forecast-actions span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.export-forecast-button {
  appearance: none;
  border: 1px solid rgba(15, 118, 110, 0.35);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-dark);
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.export-forecast-button:hover {
  background: var(--surface-soft);
}

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

.doc-card {
  display: block;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.doc-card span,
.doc-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.doc-card strong {
  display: block;
  margin: 8px 0 7px;
  font-size: 18px;
}

.doc-card:hover {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--surface-soft);
}

.version-footer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
  padding: 15px;
}

.version-footer strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.version-footer p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 900px) {
  .kpi-grid.five,
  .kpi-grid.four,
  .kpi-grid.three,
  .two-columns,
  .version-footer,
  .product-analysis-grid,
  .overview-grid,
  .doc-list {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  .shell {
    width: min(100vw - 20px, 1500px);
    padding-top: 16px;
  }

  .topbar {
    display: block;
  }

  h1 {
    font-size: 27px;
  }

  .focus-panel {
    min-width: 0;
    margin-top: 13px;
  }

  .select-control {
    width: 100%;
    justify-content: space-between;
  }

  .select-control.inline {
    width: auto;
  }

  select {
    min-width: 0;
    width: 180px;
  }

  .product-analysis-head,
  .forecast-subtable-head {
    flex-direction: column;
    align-items: stretch;
  }

  .product-analysis-head h4 {
    font-size: 18px;
    line-height: 1.45;
    overflow-wrap: anywhere;
  }

  .forecast-actions {
    width: 100%;
  }

  .forecast-actions span {
    width: 100%;
    border-radius: 12px;
    padding: 8px 10px;
  }

  .forecast-subtable-head {
    gap: 10px;
  }

  .forecast-subtable-head div {
    width: 100%;
  }

  .export-forecast-button {
    align-self: flex-start;
  }
}
