:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-muted: #eef3ed;
  --ink: #18211f;
  --muted: #62706b;
  --line: #d8e0d9;
  --accent: #0e7b64;
  --accent-strong: #075c4b;
  --accent-soft: #dff3ed;
  --warn: #b45d19;
  --blue: #2f6fb0;
  --violet: #7751a7;
  --red: #b94848;
  --shadow: 0 16px 40px rgba(24, 33, 31, 0.08);
  font-family:
    "Inter", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(14, 123, 100, 0.07), transparent 360px),
    var(--bg);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.icon-button,
.preset-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover,
.preset-button:hover,
.icon-only:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.icon-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 1.05fr) minmax(280px, 0.95fr) minmax(320px, 1.1fr);
  gap: 16px;
  padding: 18px 0 0;
  align-items: start;
}

.workspace[hidden] {
  display: none;
}

.multilayer-workspace {
  grid-template-columns: minmax(380px, 1.2fr) minmax(320px, 0.95fr) minmax(380px, 1.1fr);
}

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

.form-panel,
.config-panel,
.quote-panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.panel-heading h2,
.section-title h2,
.details h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.panel-heading p {
  max-width: 280px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: right;
}

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

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

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field.compact input {
  min-height: 38px;
}

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

.toggle,
.finish-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.toggle input,
.finish-item input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.fieldset {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.finish-list {
  display: grid;
  gap: 8px;
}

.finish-item {
  justify-content: space-between;
}

.finish-item span:first-of-type {
  flex: 1;
}

.finish-item em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 650;
  text-align: right;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.preset-button {
  min-width: 0;
  padding: 0 10px;
  font-size: 13px;
}

.preset-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.slider-field {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.slider-field div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.slider-field strong {
  color: var(--ink);
  font-size: 15px;
}

.slider-field input {
  width: 100%;
  accent-color: var(--accent);
}

.formula-box {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: var(--surface-muted);
}

.config-block {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.config-block h3 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.2;
}

.config-block.no-border {
  margin-top: 0;
  border-top: 0;
  padding-top: 0;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.layer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.layer-toolbar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.layer-toolbar button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.quote-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.quote-table th,
.quote-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.quote-table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

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

.quote-table tr.layer-disabled td {
  background: #f6f8f6;
  color: var(--muted);
}

.quote-table input {
  width: 92px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  color: var(--ink);
  outline: none;
}

.quote-table input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.quote-table input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.quote-table input:disabled,
.quote-table input[readonly] {
  background: #f3f6f3;
  color: var(--muted);
}

.layer-table {
  min-width: 1040px;
}

.scenario-table {
  min-width: 540px;
  font-size: 13px;
}

.scenario-table tr.active-scenario td {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 850;
}

.setup-fee-grid,
.print-rate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.setup-fee-item,
.print-rate-item {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.setup-fee-item input,
.print-rate-item input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  color: var(--ink);
  outline: none;
}

.setup-fee-item input:focus,
.print-rate-item input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.formula-box h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

.formula-box p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.quote-panel {
  position: sticky;
  top: 16px;
}

.quote-summary {
  border-radius: 8px;
  padding: 18px;
  background: #102822;
  color: #fff;
}

.quote-summary .eyebrow {
  color: #98e4d2;
}

.quote-summary strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1;
  letter-spacing: 0;
}

.quote-summary span {
  color: #d8eee8;
  font-size: 15px;
  font-weight: 800;
}

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

.metric {
  display: grid;
  gap: 6px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  font-size: 18px;
  line-height: 1.2;
}

.breakdown,
.details {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

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

.section-title span {
  border-radius: 999px;
  padding: 5px 9px;
  background: #fff3dc;
  color: var(--warn);
  font-size: 12px;
  font-weight: 850;
}

.cost-bars {
  display: grid;
  gap: 11px;
}

.cost-row {
  display: grid;
  gap: 6px;
}

.cost-row > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 800;
}

.cost-row span:last-child {
  color: var(--muted);
}

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

.bar-fill {
  height: 100%;
  min-width: 4px;
  border-radius: inherit;
}

.details {
  margin-top: 16px;
}

.details dl {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.details div {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.details dt {
  color: var(--muted);
  font-weight: 800;
}

.details dd {
  margin: 0;
  color: var(--ink);
  font-weight: 650;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 40, 34, 0.42);
}

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

.library-modal {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  width: min(980px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(16, 40, 34, 0.22);
  overflow: hidden;
}

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

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

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-note {
  margin: 0;
  padding: 13px 18px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.library-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 18px 0;
  overflow-x: auto;
}

.library-tab {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding: 0 14px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.library-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.library-content {
  min-height: 0;
  padding: 0 18px 18px;
  overflow: auto;
}

.library-table-wrap {
  min-width: 680px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.library-table th,
.library-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: middle;
}

.library-table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

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

.library-table input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  color: var(--ink);
  outline: none;
}

.library-table input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.library-help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  padding: 12px 14px;
  background: #102822;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

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

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

  .multilayer-workspace {
    grid-template-columns: minmax(320px, 1fr);
  }

  .quote-panel {
    grid-column: 1 / -1;
    position: static;
  }
}

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 14px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }

  .workspace,
  .field-grid.two,
  .toggle-grid,
  .preset-row,
  .metric-grid,
  .setup-fee-grid,
  .print-rate-grid {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    display: grid;
  }

  .panel-heading p {
    max-width: none;
    text-align: left;
  }

  .details div {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .library-modal {
    max-height: calc(100vh - 20px);
  }

  .modal-header,
  .modal-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-footer button {
    width: 100%;
  }
}
