:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --line: #dfe4e8;
  --text: #18212b;
  --muted: #66727f;
  --blue: #1769e0;
  --blue-dark: #0e54bb;
  --green: #16805c;
  --amber: #a45c05;
  --red: #c43d3d;
  --sidebar: #17212b;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
a { color: var(--blue); text-decoration: none; }
h1, h2, p { margin: 0; }
h1 { font-size: 21px; line-height: 1.3; }
h2 { font-size: 16px; line-height: 1.4; }
p { color: var(--muted); line-height: 1.6; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: #fff; padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; }
.brand { color: #fff; display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; padding: 0 8px; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { width: 32px; height: 32px; flex: 0 0 32px; display: inline-grid; place-items: center; border-radius: 6px; background: #e54a42; color: #fff; font-weight: 800; }
.sidebar nav { display: grid; gap: 4px; }
.nav-link { display: flex; align-items: center; min-height: 42px; padding: 0 12px; border-radius: 6px; color: #bfc9d3; font-weight: 600; }
.nav-link:hover { color: #fff; background: #243342; }
.nav-link.active { color: #fff; background: #1769e0; }
.nav-link.secondary { margin-top: auto; border-top: 1px solid #30404f; border-radius: 0; padding-top: 14px; }

.main { min-width: 0; }
.topbar { min-height: 68px; padding: 0 30px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar > div { display: flex; align-items: center; gap: 10px; }
.environment { color: var(--green); background: #eaf7f1; border: 1px solid #bde4d4; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 700; }
.page-content { width: min(1320px, 100%); padding: 26px 30px 46px; }

.button { appearance: none; min-height: 36px; border: 1px solid #cbd3da; border-radius: 6px; background: #fff; color: #283643; padding: 7px 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; font-weight: 650; white-space: nowrap; }
.button:hover { border-color: #9aa7b3; background: #f7f9fa; }
.button:disabled { cursor: wait; opacity: .7; }
.button-primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button-primary:hover { color: #fff; background: var(--blue-dark); border-color: var(--blue-dark); }
.button-quiet { background: transparent; }
.button-danger { color: var(--red); border-color: #e5b5b5; }
.button-small { min-height: 31px; padding: 5px 10px; font-size: 13px; }
.button-full { width: 100%; }

.summary-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 22px; }
.summary-strip > div { padding: 19px 22px; border-right: 1px solid var(--line); display: grid; gap: 6px; }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip span { color: var(--muted); font-size: 13px; }
.summary-strip strong { font-size: 22px; line-height: 1.2; }
.text-ok { color: var(--green); }
.text-warn { color: var(--amber); }

.section-head { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 4px; }
.section-head > div { display: grid; gap: 3px; }
.section-head.compact { padding: 15px 18px; margin: 0; border-bottom: 1px solid var(--line); }
.table-section { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 22px; overflow: hidden; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { color: #53616e; background: #f8fafb; text-align: left; font-size: 12px; font-weight: 750; padding: 11px 16px; border-bottom: 1px solid var(--line); }
td { padding: 13px 16px; border-bottom: 1px solid #edf0f2; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
.empty-cell { height: 100px; text-align: center; color: var(--muted); }
.muted-row { opacity: .68; }
.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 700; }
.status.ok { color: var(--green); background: #eaf7f1; }
.status.warn { color: var(--amber); background: #fff3df; }
.status.bad { color: var(--red); background: #fdecec; }
.status.neutral { color: #63707c; background: #edf1f3; }
.product-cell { display: flex; align-items: center; gap: 12px; min-width: 310px; }
.product-cell img, .thumb-placeholder { width: 52px; height: 52px; object-fit: cover; border-radius: 5px; border: 1px solid var(--line); flex: 0 0 52px; }
.thumb-placeholder { display: grid; place-items: center; color: var(--muted); font-size: 11px; background: #f2f4f5; }
.product-cell div, td:first-child > div { display: grid; gap: 4px; }
.product-main-row td { border-top: 1px solid #d5dce2; }
.product-main-row:first-child td { border-top: 0; }
.sku-row { background: #fbfcfd; }
.sku-row:hover { background: #f5f8fb; }
.sku-row td { padding-top: 10px; padding-bottom: 10px; }
.sku-cell { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: start; gap: 7px; padding-left: 58px; min-width: 360px; }
.sku-cell > div { display: grid; gap: 4px; }
.sku-branch { color: #9aa7b3; font-family: Consolas, monospace; }
.sku-empty { padding: 12px 20px 12px 94px; color: var(--muted); background: #fbfcfd; }
.product-sku-table td:nth-child(5) small { margin-top: 5px; }
td small { display: block; color: var(--muted); font-size: 12px; }
.actions { display: flex; align-items: center; gap: 8px; }
.actions form { margin: 0; }
.message-preview { color: #4f5c67; max-width: 520px; white-space: pre-line; overflow-wrap: anywhere; }

.notice { padding: 12px 14px; border: 1px solid; border-radius: 6px; margin-bottom: 16px; }
.notice.success { color: #116c4d; background: #eaf7f1; border-color: #bde4d4; }
.modal-open { overflow: hidden; }
.sku-modal[hidden], .sku-material-delete-form[hidden] { display: none !important; }
.sku-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; background: rgba(17, 27, 37, .48); }
.sku-dialog { width: min(620px, 100%); max-height: min(780px, calc(100vh - 48px)); display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 22px 65px rgba(10, 20, 30, .24); }
.sku-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.sku-dialog-head > div { display: grid; gap: 3px; min-width: 0; }
.sku-dialog-head p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-close { appearance: none; width: 32px; height: 32px; flex: 0 0 32px; border: 0; border-radius: 5px; background: transparent; color: #56636f; cursor: pointer; font-size: 24px; line-height: 1; }
.modal-close:hover { background: #f0f3f5; color: var(--text); }
.sku-dialog-body { padding: 18px 20px; overflow-y: auto; }
.sku-select-label, .sku-material-form label { display: grid; gap: 7px; color: #36424d; font-weight: 650; }
.sku-summary { display: grid; gap: 4px; margin: 12px 0 16px; padding: 11px 12px; border-radius: 6px; background: #f4f7fa; }
.sku-summary small { color: var(--muted); }
.sku-material-form { display: grid; gap: 14px; }
.sku-material-form textarea { min-height: 120px; }
.sku-dialog-actions { display: flex; gap: 9px; }
.sku-material-delete-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.sku-dialog-foot { display: flex; justify-content: space-between; gap: 16px; padding: 13px 20px; border-top: 1px solid var(--line); background: #f8fafb; color: var(--muted); font-size: 12px; }
.sku-dialog-empty { max-width: 520px; }
.form-page { max-width: 980px; }
.back-link { display: inline-block; margin: 0 0 14px; }
.editor-form, .upload-panel, .guide-preview { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.editor-form { padding: 22px; display: grid; gap: 18px; }
.form-title { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.form-title > div { display: grid; gap: 4px; }
.editor-form label, .form-stack label { display: grid; gap: 7px; color: #36424d; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #cbd3da; border-radius: 5px; background: #fff; color: var(--text); padding: 9px 11px; outline: 0; }
input, select { min-height: 40px; }
textarea { resize: vertical; min-height: 220px; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, .12); }
.form-grid { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 14px; }
.readonly-field { background: #f7f9fa; border: 1px solid var(--line); border-radius: 5px; padding: 11px 13px; display: flex; justify-content: space-between; gap: 20px; }
.readonly-field span { color: var(--muted); }
.form-actions { display: flex; gap: 10px; }

.manual-redeem-panel { max-width: 980px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 22px; overflow: hidden; }
.manual-redeem-form { padding: 20px; display: grid; gap: 17px; }
.manual-fields { grid-template-columns: minmax(280px, 1.3fr) minmax(220px, 1fr); }
.manual-redeem-form label { display: grid; gap: 7px; color: #36424d; font-weight: 650; }
.manual-code-field { width: min(560px, 100%); }
.check-line { display: flex !important; align-items: center; gap: 9px !important; width: fit-content; cursor: pointer; }
.check-line input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--blue); }
.job-result { padding: 12px 14px; border: 1px solid #cbd3da; border-radius: 5px; background: #f7f9fa; color: #43515e; line-height: 1.55; }
.job-result.success { color: #116c4d; background: #eaf7f1; border-color: #bde4d4; }
.job-result.warn { color: #84501a; background: #fff3df; border-color: #eed2a4; }
.job-result.error { color: var(--red); background: #fdecec; border-color: #f1c3c3; }
.manual-order-list table { min-width: 1040px; }
.code-text { font-family: Consolas, "Microsoft YaHei", sans-serif; }
.error-text { max-width: 250px; margin-top: 4px; color: var(--red); line-height: 1.4; overflow-wrap: anywhere; }

.guide-layout { display: grid; grid-template-columns: minmax(320px, 620px) minmax(280px, 380px); gap: 22px; align-items: start; }
.guide-preview { overflow: hidden; }
.guide-preview > img { display: block; width: 100%; max-height: 680px; object-fit: contain; background: #f3f5f6; }
.image-empty { min-height: 420px; display: grid; place-items: center; color: var(--muted); }
.upload-panel { padding: 20px; }
.upload-panel h2 { margin-bottom: 16px; }
.form-stack { display: grid; gap: 16px; }
.file-picker input { padding: 8px; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 15px; border-radius: 6px; color: #fff; background: #26333f; box-shadow: 0 8px 24px rgba(16, 28, 39, .18); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef2f5; }
.login-panel { width: min(390px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 28px; box-shadow: 0 14px 38px rgba(23, 34, 45, .10); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-panel h1 { font-size: 20px; margin-bottom: 18px; }
.login-error { color: var(--red); background: #fdecec; border: 1px solid #f1c3c3; border-radius: 5px; padding: 10px 12px; margin-bottom: 14px; }

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 10px 12px; gap: 10px; }
  .brand { padding: 2px 0 6px; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; }
  .nav-link { min-height: 38px; flex: 0 0 auto; padding: 0 11px; }
  .nav-link.secondary { display: none; }
  .topbar { min-height: 60px; padding: 0 16px; }
  .topbar h1 { font-size: 18px; }
  .page-content { padding: 16px 14px 36px; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-strip > div:nth-child(2) { border-right: 0; }
  .summary-strip > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .summary-strip strong { font-size: 19px; }
  .section-head { align-items: flex-start; }
  .section-head > .button { margin-top: 2px; }
  .guide-layout { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .manual-fields { grid-template-columns: 1fr; }
  .form-title { display: grid; }
  .form-title > .button { width: 100%; }
  .sku-modal { padding: 12px; }
  .sku-dialog { max-height: calc(100vh - 24px); }
  .sku-dialog-foot { display: grid; }
}

@media (max-width: 440px) {
  .environment { display: none; }
  .section-head { display: grid; }
  .section-head > .button { width: 100%; }
  .summary-strip > div { padding: 15px 14px; }
  .login-panel { padding: 22px; }

  .responsive-table { min-width: 0; }
  .manual-order-list table { min-width: 0; }
  .responsive-table thead { display: none; }
  .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
  .responsive-table tr { padding: 13px 14px; border-bottom: 1px solid var(--line); }
  .responsive-table tr:last-child { border-bottom: 0; }
  .responsive-table td { padding: 6px 0; border: 0; display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; align-items: center; }
  .responsive-table td > * { min-width: 0; }
  .responsive-table td:not(.actions) { overflow-wrap: anywhere; }
  .responsive-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 650; }
  .responsive-table td.product-data { display: block; padding-bottom: 10px; }
  .responsive-table td.product-data::before { display: none; }
  .responsive-table .product-cell { min-width: 0; align-items: flex-start; }
  .responsive-table .product-cell strong { overflow-wrap: anywhere; }
  .responsive-table .sku-cell { min-width: 0; padding-left: 8px; }
  .responsive-table .sku-empty { padding: 10px 0; }
  .responsive-table td.actions { display: flex; padding-top: 9px; }
  .responsive-table td.actions::before { display: none; }
  .responsive-table td.actions .button { flex: 1; }
  .responsive-table .message-preview { max-width: none; }
}
