:root {
  color-scheme: dark;
  --bg: #08110d;
  --panel: #101a15;
  --panel-2: #15221b;
  --line: #26382e;
  --text: #eef4ef;
  --muted: #9bad9f;
  --soft: #6f8275;
  --gold: #d6b766;
  --gold-2: #f1d98b;
  --green: #4fd184;
  --blue: #65a7ff;
  --red: #ff7575;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 0%, rgba(79, 209, 132, 0.12), transparent 30rem),
    linear-gradient(180deg, #08110d 0%, #0b1510 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px;
}

.control-panel,
.result-panel {
  min-width: 0;
  background: rgba(16, 26, 21, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px;
}

.result-panel {
  min-height: calc(100vh - 32px);
  padding: 18px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
}

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

h1 {
  font-size: 25px;
  line-height: 1.18;
}

h2 {
  font-size: 16px;
}

.status-pill {
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 1px solid rgba(214, 183, 102, 0.42);
  border-radius: 999px;
  color: var(--gold-2);
  font-size: 12px;
  font-weight: 700;
}

.field-stack {
  display: grid;
  gap: 16px;
  padding-top: 18px;
}

.field-group label,
.input-field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

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

.segmented button,
.panel-title button {
  min-height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1711;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  white-space: normal;
  overflow-wrap: anywhere;
}

.segmented button[aria-selected="true"],
.panel-title button:hover {
  border-color: rgba(214, 183, 102, 0.7);
  background: rgba(214, 183, 102, 0.14);
  color: var(--gold-2);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.input-field input,
.input-field select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1711;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.input-field input:focus,
.input-field select:focus {
  border-color: var(--gold);
}

.switch-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 34, 27, 0.7);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.switch-row input {
  margin-top: 2px;
  accent-color: var(--gold);
}

.switch-row small {
  grid-column: 2;
  color: var(--soft);
  font-size: 12px;
  font-weight: 500;
}

.income-panel {
  padding: 12px;
  border: 1px solid rgba(214, 183, 102, 0.24);
  border-radius: 8px;
  background: rgba(214, 183, 102, 0.08);
}

.notice-bar {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid rgba(214, 183, 102, 0.22);
  border-radius: 8px;
  background: rgba(214, 183, 102, 0.08);
  color: var(--gold-2);
  font-size: 13px;
  line-height: 1.5;
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(214, 183, 102, 0.24);
  border-radius: 8px;
  background: rgba(214, 183, 102, 0.08);
}

.action-bar .eyebrow {
  margin-bottom: 5px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.action-buttons button {
  min-height: 42px;
  border: 1px solid rgba(214, 183, 102, 0.58);
  border-radius: 8px;
  background: linear-gradient(180deg, #f0d98a 0%, #cba85a 100%);
  color: #122018;
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

.action-buttons button + button {
  background: #0c1711;
  color: var(--gold-2);
}

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

.metric-card,
.chart-panel,
.table-panel,
.disclaimer {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-card {
  min-height: 122px;
  padding: 16px;
}

.metric-card span,
.metric-card small,
.legend-note {
  color: var(--muted);
}

.metric-card span {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.08;
  letter-spacing: 0;
}

.metric-card small {
  display: block;
  margin-top: 8px;
  font-size: 12px;
}

.chart-panel,
.table-panel,
.disclaimer {
  margin-top: 12px;
  padding: 16px;
}

.compact-panel {
  background: rgba(214, 183, 102, 0.08);
}

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

.legend-note {
  font-size: 12px;
}

canvas {
  width: 100% !important;
  max-height: 360px;
}

.income-result {
  display: grid;
  gap: 4px;
}

.income-result strong {
  font-size: 34px;
  color: var(--gold-2);
}

.income-result span {
  color: var(--muted);
}

.table-scroll {
  max-height: 480px;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0d1712;
  color: var(--muted);
  font-size: 12px;
}

td {
  font-size: 13px;
}

tr.is-key td {
  color: var(--gold-2);
  font-weight: 700;
}

.disclaimer {
  color: var(--muted);
  line-height: 1.7;
}

.disclaimer h2 {
  color: var(--text);
  margin-bottom: 8px;
}

.disclaimer p {
  margin: 8px 0 0;
}

.delivery-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.delivery-card {
  max-width: 920px;
  margin: 0 auto;
  padding: 28px;
  overflow: hidden;
  border: 1px solid rgba(55, 46, 24, 0.13);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(214, 183, 102, 0.18) 0%, rgba(255, 255, 255, 0) 36%),
    #f7f2e8;
  color: #17231b;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.22);
}

.delivery-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(23, 35, 27, 0.14);
}

.delivery-header p {
  margin: 0 0 7px;
  color: #6d5520;
  font-size: 12px;
  font-weight: 800;
}

.delivery-header h2 {
  font-size: 26px;
  line-height: 1.16;
}

.delivery-header span,
.delivery-meta,
.delivery-summary span,
.delivery-footer {
  color: #667267;
}

.delivery-header strong {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: #17231b;
  color: #f0d98a;
  font-size: 12px;
}

.delivery-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
  font-size: 13px;
  font-weight: 700;
}

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

.delivery-summary div {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(23, 35, 27, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.56);
}

.delivery-summary span {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
}

.delivery-summary strong {
  display: block;
  color: #17231b;
  font-size: 22px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.delivery-chart {
  height: 236px;
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid rgba(23, 35, 27, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.delivery-table {
  min-width: 0;
  border: 1px solid rgba(23, 35, 27, 0.1);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.5);
}

.delivery-table th,
.delivery-table td {
  padding: 9px 8px;
  border-bottom: 1px solid rgba(23, 35, 27, 0.08);
  color: #17231b;
  font-size: 12px;
  white-space: normal;
}

.delivery-table th {
  position: static;
  background: rgba(23, 35, 27, 0.08);
  color: #455145;
  font-weight: 800;
}

.delivery-footer {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  font-size: 11px;
  line-height: 1.55;
}

.delivery-footer p {
  margin: 0;
}

.export-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
}

.export-modal[hidden] {
  display: none;
}

.export-dialog {
  position: relative;
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101a15;
  box-shadow: var(--shadow);
}

.export-dialog button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0c1711;
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.export-dialog h2 {
  margin-right: 42px;
}

.export-dialog p {
  color: var(--muted);
  line-height: 1.6;
}

.export-dialog img {
  display: block;
  width: 100%;
  border-radius: 8px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
    height: auto;
  }

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

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

@media (max-width: 560px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
  }

  .control-panel,
  .result-panel {
    padding: 14px;
  }

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

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

  #productTabs {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
  }

  .action-bar,
  .delivery-header,
  .delivery-meta {
    display: grid;
  }

  .action-buttons {
    justify-content: stretch;
  }

  .action-buttons button {
    flex: 1 1 130px;
  }

  .delivery-card {
    padding: 18px;
  }

  .delivery-meta,
  .delivery-summary {
    grid-template-columns: 1fr;
  }

  .delivery-table th,
  .delivery-table td {
    padding: 8px 5px;
    font-size: 10px;
  }

  h1 {
    font-size: 23px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  :root {
    color-scheme: light;
  }

  body {
    min-height: 0;
    background: #fff;
    color: #17231b;
  }

  .app-shell {
    display: block;
    max-width: none;
    padding: 0;
  }

  .control-panel,
  .action-bar,
  .notice-bar,
  .summary-grid,
  .chart-panel,
  .table-panel,
  .disclaimer,
  .delivery-panel > .panel-title,
  .export-modal {
    display: none !important;
  }

  .result-panel,
  .delivery-panel {
    min-height: 0;
    padding: 0;
    border: 0;
    background: #fff;
    box-shadow: none;
  }

  .delivery-card {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
    box-shadow: none;
  }

  .delivery-chart {
    break-inside: avoid;
  }

  .delivery-table,
  .delivery-footer {
    break-inside: avoid;
  }
}
