:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #5f6b73;
  --line: #d9e0e5;
  --field: #f8fafb;
  --accent: #0f766e;
  --accent-dark: #0b5d56;
  --band: #eef4f3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #ffffff;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

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

p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.primary {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

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

.primary:disabled {
  opacity: 0.65;
  cursor: progress;
}

.form-grid {
  display: grid;
  gap: 24px;
  padding-top: 24px;
}

.section {
  padding: 20px 0 4px;
  border-bottom: 1px solid var(--line);
}

.fields {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #34424b;
  font-size: 13px;
  font-weight: 700;
}

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

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--field);
  font: inherit;
  font-weight: 500;
}

.products-heading, .products-footer { display:flex; align-items:center; justify-content:space-between; gap:16px; }
.products-heading { margin-bottom:18px; flex-wrap:wrap; }
.product-count { font-size:12px; color:var(--muted); font-weight:400; margin-left:8px; }
.text-button { display:inline-flex; align-items:center; justify-content:center; gap:6px; border:0; background:transparent; color:var(--accent-dark); padding:8px 0; font:inherit; font-size:13px; cursor:pointer; white-space:nowrap; }
.text-button:hover { color:var(--accent); text-decoration:underline; }
.lucide { width:16px; height:16px; flex-shrink:0; }
.product-columns, .product-row { display:grid; grid-template-columns:26px minmax(150px,1.7fr) minmax(110px,1.15fr) minmax(95px,1fr) minmax(75px,.85fr) minmax(70px,.7fr) minmax(58px,.6fr) minmax(85px,.8fr) 128px; gap:8px; align-items:center; }
.product-columns { background:var(--field); border-block:1px solid var(--line); padding:10px 0; color:var(--muted); font-size:12px; }
.product-columns span:first-child { text-align:center; }
.actions-heading { text-align:center; }
.product-row { padding:12px 0; border-bottom:1px solid var(--line); }
.row-number { color:var(--muted); font-size:12px; text-align:center; font-variant-numeric:tabular-nums; }
.product-cell { min-width:0; }
.product-cell > span { position:absolute; width:1px; height:1px; padding:0; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
.product-cell input { font-size:13px; min-width:0; background:white; padding:8px; }
.numeric input { text-align:right; font-variant-numeric:tabular-nums; }
.amount-cell input { border-color:transparent; background:transparent; font-weight:700; padding-right:4px; }
.row-actions { display:flex; gap:0; justify-content:flex-end; }
.icon-button { width:32px; height:34px; padding:0; display:inline-flex; align-items:center; justify-content:center; color:var(--muted); background:transparent; border:0; border-radius:4px; cursor:pointer; flex-shrink:0; }
.icon-button:hover { color:var(--accent-dark); background:var(--band); }
.icon-button[data-action="remove"]:hover { color:#b42318; background:#fff0ee; }
.icon-button:disabled { opacity:.25; cursor:default; }
button:focus-visible, select:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
.products-footer { padding:14px 0 18px; }
.product-total { display:flex; align-items:center; gap:14px; white-space:nowrap; }
.product-total input { width:140px; min-height:38px; border:0; background:transparent; text-align:right; font-size:20px; font-weight:700; font-variant-numeric:tabular-nums; padding:0; }
@media (max-width:1050px) {
  .product-columns { display:none; }
  .product-row { grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; padding:16px 0; }
  .row-number { grid-column:1 / 3; grid-row:1; text-align:left; }
  .row-number::before { content:"产品 "; }
  .row-actions { grid-column:3 / 5; grid-row:1; }
  .product-cell > span { position:static; width:auto; height:auto; clip-path:none; white-space:normal; }
  .product-cell input { min-height:40px; }
  .amount-cell input { background:var(--field); padding:8px; }
}
@media (max-width:540px) {
  .product-row { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .row-number { grid-column:1; }
  .row-actions { grid-column:2; }
  .productName, .material { grid-column:1 / -1; }
  .amount-cell { grid-column:1 / -1; display:flex; align-items:center; justify-content:space-between; }
  .amount-cell input { width:50%; background:transparent; }
  .product-total { gap:6px; }
  .product-total input { width:110px; }
}
dialog { width:min(620px, calc(100% - 32px)); max-height:90vh; overflow:auto; padding:24px; border:1px solid var(--line); border-radius:8px; }
dialog::backdrop { background:rgb(0 0 0 / 35%); }
dialog h2 { margin-bottom:16px; }
.preset-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:16px; }
.preset-heading h2 { margin:0; }
.preset-tools { display:flex; align-items:center; gap:20px; margin-bottom:12px; }
.preset-tools input { min-width:0; font-size:14px; }
.preset-list { list-style:none; margin:0; padding:0; max-height:52vh; overflow:auto; }
.preset-entry { display:flex; align-items:center; gap:16px; padding:16px 0; border-bottom:1px solid var(--line); }
.preset-details { flex:1; min-width:0; display:grid; gap:7px; }
.preset-details strong { font-size:14px; overflow-wrap:anywhere; }
.preset-details span { font-size:12px; color:var(--muted); overflow-wrap:anywhere; line-height:1.5; }
.preset-entry-actions { display:flex; align-items:center; gap:4px; flex-shrink:0; }
.preset-entry-actions .text-button { margin-right:8px; }
.preset-entry-actions [data-preset-action="delete"]:hover { color:#b42318; background:#fff0ee; }
.preset-empty { padding:24px 0; text-align:center; }
.preset-form-actions { display:flex; justify-content:flex-end; gap:24px; margin-top:24px; }
@media (max-width:540px) {
  #presetDialog { padding:18px; }
  .preset-entry { flex-wrap:wrap; gap:8px; }
  .preset-details { flex-basis:100%; }
  .preset-entry-actions { margin-left:auto; }
}

input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--accent);
}

input[readonly] {
  background: var(--band);
}

.result {
  margin-top: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.links a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .fields.two {
    grid-template-columns: 1fr;
  }
}
