:root {
  color-scheme: light;
  --canvas: #f4f5f0;
  --paper: #fff;
  --ink: #20312b;
  --muted: #596761;
  --line: #dce2dc;
  --sidebar: #1d302d;
  --accent: #1f6251;
  --accent-hover: #175142;
  --highlight: #d7eae1;
  --amber: #9a4d13;
  --danger: #9a2b30;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #70a99b;
  outline-offset: 2px;
}
h1, h2, p { margin: 0; }
h1 { font-size: clamp(25px, 3vw, 36px); letter-spacing: -.034em; line-height: 1.18; }
h2 { font-size: 19px; letter-spacing: -.018em; }
small { color: var(--muted); }
.layout { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: start;
  padding: 28px 15px 18px;
  background: var(--sidebar);
  color: #f5faf7;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 7px 30px; }
.brand-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  background: #bee4c9;
  color: #173b2c;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 800;
}
.brand div { display: flex; flex-direction: column; }
.brand strong { font-size: 17px; }
.brand div span { color: #b2c6be; font-size: 12px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav button {
  display: flex; align-items: center; gap: 10px;
  text-align: left; border: 0; border-radius: 8px; padding: 11px 12px;
  background: transparent; color: #d5e4dc;
  white-space: nowrap;
}
.sidebar nav button:hover { background: #2c4640; }
.sidebar nav button[aria-current="page"] { color: #fff; font-weight: 650; background: #34564c; }
.nav-dot { width: 8px; height: 8px; border: 1.5px solid currentColor; border-radius: 2px; }
.sidebar nav button[aria-current="page"] .nav-dot { background: #c0efd2; border-color: #c0efd2; }
.sidebar-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin-top: auto; padding: 18px 7px 0; color: #c3d7ce; font-size: 12px;
}
.text-button { background: none; border: 0; color: inherit; text-decoration: underline; padding: 4px 0; }
.main { width: 100%; max-width: 1480px; margin: 0 auto; padding: 30px clamp(16px, 4vw, 50px) 44px; }
.demo-banner, .notice { padding: 10px 13px; border-radius: 7px; margin-bottom: 14px; font-size: 13px; background: #e8efdc; color: #375329; }
.notice.error { background: #f8e5e5; color: var(--danger); }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin: 8px 0 24px; }
.page-head p, .panel-note { color: var(--muted); margin-top: 5px; font-size: 14px; }
.head-actions, .inline-actions, .editor-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 7px; min-height: 38px; padding: 7px 13px;
  font-weight: 600; white-space: nowrap;
}
.button:hover { border-color: #b4c5bb; background: #f3f8f4; }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-hover); }
.button.small { min-height: 30px; padding: 3px 8px; font-size: 13px; }
.button.quiet { border-color: transparent; background: none; color: var(--accent); }
.button.quiet:hover { background: var(--highlight); }
.close-button { width: 35px; min-height: 35px; padding: 0; font-size: 23px; font-weight: 400; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 13px 17px; border: 1px solid var(--line); background: var(--paper); border-radius: 9px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 27px; line-height: 1.25; margin-top: 2px; font-variant-numeric: tabular-nums; }
.panel { border: 1px solid var(--line); background: var(--paper); border-radius: 9px; }
.panel-pad { padding: 18px; }
.panel + .panel { margin-top: 14px; }
.panel-title { display: flex; align-items: baseline; gap: 10px; }
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding: 14px; }
.controls .search { flex: 1 1 220px; }
.controls > label { font-size: 13px; }
label { display: grid; gap: 5px; font-size: 14px; font-weight: 600; }
input, select, textarea {
  width: 100%; min-width: 0; min-height: 38px;
  border: 1px solid #c8d1ca; border-radius: 6px;
  padding: 7px 9px; color: var(--ink); background: white;
}
textarea { resize: vertical; min-height: 70px; }
select { max-width: 100%; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
thead { background: #f5f7f4; }
th { color: var(--muted); font-size: 13px; font-weight: 650; white-space: nowrap; }
th, td { padding: 10px 13px; border-top: 1px solid var(--line); }
td { overflow-wrap: anywhere; }
tbody tr:hover { background: #fafbf9; }
td.compact, th.compact { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-stack { display: grid; gap: 2px; min-width: 115px; }
.cell-stack .sub { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; white-space: nowrap; border-radius: 5px; padding: 2px 6px; font-size: 12px; background: #e6f0e9; color: #2f5b3e; }
.badge.low { background: #faead9; color: #8c4512; }
.badge.out { background: #e9edf5; color: #334a71; }
.badge.zero { background: #fae7e9; color: var(--danger); }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.full { grid-column: 1 / -1; }
.form-error { color: var(--danger); margin-top: 10px; font-size: 14px; overflow-wrap: anywhere; }
.form-row { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.form-row .wide { flex: 1 1 230px; }
.form-row .qty { flex: 0 1 130px; }
.form-row button { min-height: 38px; }
.result-heading { padding: 13px 15px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 15px; }
.result-heading > span { color: var(--muted); }
dialog {
  width: min(calc(100% - 24px), 650px); max-height: calc(100% - 30px);
  border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  color: var(--ink); background: var(--paper); box-shadow: 0 16px 55px #172d2940;
}
dialog::backdrop { background: #12221ec4; }
.editor-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }
.editor-actions { justify-content: flex-end; margin-top: 18px; }
.bom-items { display: grid; gap: 8px; margin: 10px 0; }
.bom-row { display: grid; align-items: end; grid-template-columns: minmax(0, 1fr) minmax(95px, 28%) auto; gap: 8px; }
.bom-row .button { height: 38px; }
.login-shell, .loading { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 380px); background: white; border: 1px solid var(--line); border-radius: 12px; padding: 26px; display: grid; gap: 14px; }
.login-card p { color: var(--muted); }
.login-card p.form-error { color: var(--danger); margin: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 174px minmax(0, 1fr); }
  .sidebar { padding-left: 9px; padding-right: 9px; }
  .brand { gap: 8px; }
}
@media (max-width: 680px) {
  .layout { display: block; }
  .sidebar { min-height: 0; position: static; padding: 9px 10px; display: grid; grid-template-columns: 1fr auto; gap: 9px; }
  .sidebar nav { display: flex; overflow-x: auto; grid-column: 1 / -1; grid-row: 2; gap: 3px; }
  .sidebar nav button { padding: 8px; font-size: 13px; }
  .nav-dot { display: none; }
  .sidebar-footer { margin: 0; padding: 6px 2px; grid-column: 2; grid-row: 1; }
  .brand { padding: 0 0 0 2px; }
  .brand-icon { width: 30px; height: 30px; font-size: 16px; }
  .brand strong { font-size: 15px; }
  .brand div span { display: none; }
  .main { padding: 13px 10px 24px; }
  .page-head { margin-bottom: 14px; }
  .stats { gap: 6px; margin-bottom: 10px; }
  .stat { padding: 9px; }
  .stat strong { font-size: 23px; }
  .panel-pad { padding: 12px; }
  th, td { padding-left: 9px; padding-right: 9px; }
}
@media (max-width: 400px) {
  .form-grid { grid-template-columns: 1fr; }
  .bom-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bom-row .bom-material-label { grid-column: 1 / -1; }
}
