:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --line: #d8e0e6;
  --text: #1f2933;
  --muted: #667481;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b91c1c;
  --warning: #b45309;
  --ok: #166534;
  --soft: #eef6f5;
}

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #edf4f3; }
.login-card { width: min(440px, 100%); padding: 40px; background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 14px 50px #163c3510; }
.login-eyebrow { color: var(--primary); font-size: 14px; font-weight: 700; }
.login-card h1 { margin: 22px 0 12px; font-size: 28px; }
.login-description, .login-note { color: var(--muted); font-size: 14px; line-height: 1.7; }
.login-note { margin: 24px 0 0; }
.login-form { display: grid; gap: 16px; margin-top: 24px; }
.login-form label { display: grid; gap: 8px; font-size: 14px; }
.login-form input { width: 100%; min-height: 44px; }
.login-form button { min-height: 44px; }
#login-error, #password-error { margin: 0; color: var(--danger); font-size: 14px; }
.sync-status { font-size: 12px; color: var(--ok); }
.sync-status.disconnected { color: var(--danger); }
.password-dialog { width: min(460px, 95vw); padding: 28px; border: 1px solid var(--line); border-radius: 16px; }
.password-dialog::backdrop { background: #10202070; }
.password-dialog .login-form { margin: 0; }
.password-dialog h2 { margin: 0; }
.password-dialog p { color: var(--muted); font-size: 14px; }
.top-actions { flex-wrap: wrap; justify-content: flex-end; }
[hidden] { display: none !important; }
#sku-editor { scroll-margin-top: 100px; padding: 12px 0 20px; }
#sku-editor-help { color: var(--muted); font-size: 13px; }
#sku-form label { display: grid; gap: 6px; color: var(--text); font-size: 13px; }
.sku-editor-actions { display: flex; align-items: end; gap: 8px; }
#sku-editor-error { grid-column: 1 / -1; margin: 0; color: var(--danger); font-size: 14px; }
.sku-selection-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.form-help { color: var(--muted); font-size: 13px; line-height: 1.65; }
#sku-delete-result { white-space: pre-line; font-size: 13px; line-height: 1.8; }
#quick-receive-form label { display: grid; gap: 6px; font-size: 13px; }
#quick-receive-form button { align-self: end; }
#quick-receive-result { font-size: 14px; line-height: 1.7; }
#replenishment .section-head { flex-wrap: wrap; gap: 12px; }
#replenishment .section-head h2, #create-po-from-risk { flex-shrink: 0; white-space: nowrap; }
#replenishment-search { flex: 1 1 260px; min-width: 200px; width: auto; }
.inventory-search-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.inventory-search-bar label { font-size: 14px; white-space: nowrap; }
#inventory-search { flex: 1 1 320px; min-width: 200px; width: auto; }
#inventory-search-count { font-size: 13px; color: var(--muted); }

* {
  box-sizing: border-box;
}

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

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 210px;
  background: #1f2933;
  color: #fff;
  padding: 16px 12px;
  overflow-y: auto;
}

.brand {
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-weight: 700;
  font-size: 14px;
}

.nav {
  width: 100%;
  height: 38px;
  margin: 3px 0;
  border: 0;
  border-radius: 6px;
  color: #e5edf2;
  background: transparent;
  text-align: left;
  padding: 0 12px;
  cursor: pointer;
}

.nav:hover,
.nav.active {
  background: #0f766e;
  color: #fff;
}

.main {
  margin-left: 210px;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 76px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 17px;
}

.meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.button-line {
  display: flex;
  gap: 10px;
  align-items: center;
}

button,
.export {
  height: 34px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

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

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page {
  display: none;
  padding: 20px 24px 36px;
}

.page.active {
  display: block;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

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

.subsection {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0 14px;
  background: #fbfcfd;
}

.subsection h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 92px;
}

.metric .label {
  color: var(--muted);
  font-size: 13px;
}

.metric .value {
  margin-top: 12px;
  font-size: 26px;
  font-weight: 700;
}

.attention-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
}

.attention-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.attention-item strong {
  display: block;
  font-size: 24px;
  margin-top: 8px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
  background: #fff;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.grid-form button {
  width: 100%;
}

.stack-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.form-row,
.inline-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

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

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

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

th {
  position: sticky;
  top: 0;
  background: #edf3f4;
  z-index: 1;
  font-weight: 700;
}

tr:hover td {
  background: #f8fbfb;
}

.risk-缺货,
.risk-高缺货风险,
.risk-严重库存异常 {
  color: var(--danger);
  font-weight: 700;
}

.risk-紧急补货,
.risk-建议补货,
.risk-关注 {
  color: var(--warning);
  font-weight: 700;
}

.risk-正常 {
  color: var(--ok);
  font-weight: 700;
}

.risk-库存偏高 {
  color: #334155;
  font-weight: 700;
}

.summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--soft);
  font-size: 13px;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  display: none;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

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

  .main {
    margin-left: 0;
  }

  .topbar {
    position: static;
    height: auto;
    padding: 14px;
    gap: 12px;
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .attention-grid,
  .grid-form,
  .form-row,
  .inline-form {
    grid-template-columns: 1fr;
  }
}

#bom .section-head { flex-wrap: wrap; gap: 12px; }
#bom .section-head h2, #bom .section-head h3 { flex-shrink: 0; }
.bom-load-bar { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin: 18px 0 24px; }
.bom-load-bar label { display: grid; gap: 6px; flex: 1 1 330px; font-size: 13px; }
.bom-load-bar button { flex-shrink: 0; white-space: nowrap; }
#bom-editor-title { scroll-margin-top: 100px; }
#bom-form { margin-top: 16px; }
#bom-form .grid-form label { display: grid; gap: 6px; font-size: 13px; }
.bom-parent-fields { margin: 0; }
.bom-picker { border: 1px solid var(--line); border-radius: 10px; padding: 16px; background: #f8fbfb; }
#bom-component-search { flex: 1 1 300px; min-width: 220px; width: auto; }
#bom-picker-results { max-height: 330px; overflow-y: auto; }
#bom-selected input[type=number] { width: 90px; min-width: 70px; }
#bom-selected select { width: 150px; }
.bom-summary { padding: 14px; border-radius: 8px; background: var(--soft); color: var(--primary-dark); font-size: 14px; }
.bom-batch-toggle { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.bom-batch-toggle input[type=checkbox] { width: auto; }
#bom-batch-fields { padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
#bom-batch-preview-table { margin-top: 16px; }
#bom-editor-error { margin: 0; color: var(--danger); font-size: 14px; line-height: 1.7; }
#bom-result { color: var(--ok); font-size: 14px; line-height: 1.8; overflow-wrap: anywhere; }
#bom-list-search { flex: 1 1 260px; min-width: 200px; width: auto; }

.bom-parent-fields, #bom-batch-fields > .grid-form { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.bom-bulk-fields { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.bom-bulk-fields label { display: grid; align-content: start; gap: 8px; font-size: 13px; }
.bom-bulk-fields label > span { display: flex; align-items: center; gap: 8px; }
.bom-bulk-fields input[type=checkbox], #bom-table input[type=checkbox] { width: auto; }
#bom-bulk-panel { margin: 18px 0; scroll-margin-top: 100px; }
#bom-bulk-preview-table { margin-top: 16px; }
#bom-bulk-error { color: var(--danger); line-height: 1.7; }
#bom-manage-result { color: var(--primary-dark); white-space: pre-line; line-height: 1.8; overflow-wrap: anywhere; }
#bom-table td { vertical-align: top; }
.finance-filters, .preview-search-bar { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; margin: 16px 0; }
.finance-filters label { display: grid; gap: 6px; font-size: 13px; flex: 1 1 180px; }
.finance-filters button { flex-shrink: 0; }
.finance-tabs, .preview-filter-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.finance-tabs button, .preview-filter-tabs button { background: white; color: var(--primary); border: 1px solid var(--primary); }
.finance-tabs button[aria-pressed=true], .preview-filter-tabs button[aria-pressed=true] { background: var(--primary); color: white; }
.preview-filter-tabs button[data-preview-filter=error] { border-color: var(--danger); color: var(--danger); }
.preview-filter-tabs button[data-preview-filter=error][aria-pressed=true] { background: var(--danger); color: white; }
#preview-search { flex: 1 1 260px; min-width: 160px; width: auto; }
#preview-reason { flex: 1 1 220px; min-width: 160px; width: auto; }
.preview-search-bar label { font-size: 13px; align-self: center; }
#preview-consumption { margin: 16px 0; font-size: 13px; }
#preview-consumption summary { cursor: pointer; color: var(--primary-dark); }
.finance-warning { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; border-radius: 8px; padding: 12px; line-height: 1.8; font-size: 13px; }
.finance-muted { display: block; color: var(--muted); font-size: 12px; line-height: 1.7; }
.finance-negative, #finance-error { color: var(--danger); }
.finance-drill { padding: 0; background: transparent; color: var(--primary-dark); text-decoration: underline; border: 0; text-align: left; }
#finance-table td { vertical-align: top; }
