:root {
  --ink: #17211e;
  --muted: #66716c;
  --surface: #ffffff;
  --canvas: #f1f4f0;
  --line: #d8dfd8;
  --green: #0b6e4f;
  --green-soft: #e2f1e9;
  --blue: #2b6cb0;
  --blue-soft: #e8f0fb;
  --orange: #c85b25;
  --orange-soft: #fce8db;
  --red: #b73a32;
  --red-soft: #f9e3e1;
  --radius: 7px;
  --shadow: 0 10px 28px rgba(23, 33, 30, 0.07);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(43, 108, 176, .28); outline-offset: 2px; }
.app-frame { min-height: 100vh; display: grid; grid-template-columns: 244px 1fr; grid-template-rows: 64px 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 28px 0 20px; color: #fff; background: #1b2823; border-bottom: 3px solid var(--green); }
.brand { color: inherit; display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; background: var(--green); color: #fff; font-family: "Arial Narrow", sans-serif; font-weight: 800; font-size: 13px; letter-spacing: 0; }
.brand strong, .brand small { display: block; line-height: 1.1; }
.brand strong { font-size: 15px; letter-spacing: 0; }
.brand small { margin-top: 3px; font-size: 11px; color: #c6d2cb; }
.topbar-actions { display: flex; align-items: center; gap: 15px; }
.connection { display: flex; align-items: center; gap: 7px; color: #d4ded8; font-size: 12px; }
.connection span { width: 8px; height: 8px; border-radius: 50%; background: #62d29a; }
.topbar-button { padding: 0; color: #d4ded8; border: 0; background: transparent; font-size: 12px; font-weight: 700; }
.topbar-button:hover { color: #fff; text-decoration: underline; }
.current-user { color: #d4ded8; font-size: 12px; font-weight: 700; }
.sidebar { grid-row: 2; padding: 18px 12px 16px; background: #e5ebe5; border-right: 1px solid #ccd6cd; display: flex; flex-direction: column; min-height: 0; }
.nav-list { display: grid; gap: 4px; }
.nav-item { min-height: 56px; padding: 10px 12px; border: 1px solid transparent; background: transparent; text-align: left; color: #405048; border-radius: 5px; }
.nav-item b, .nav-item small { display: block; }
.nav-item b { font-size: 14px; font-weight: 750; }
.nav-item small { margin-top: 3px; color: #718077; font-size: 11px; }
.nav-item:hover { background: rgba(255,255,255,.6); }
.nav-item.active { background: #fff; border-color: #ccd8cf; color: var(--green); box-shadow: 0 2px 6px rgba(31, 50, 39, .06); }
.nav-item.active small { color: #39775f; }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid #c9d3ca; color: #6e7c73; font-size: 11px; display: grid; gap: 5px; }
.workspace { width: min(1320px, 100%); margin: 0 auto; padding: 34px; }
.view { display: none; }
.view.active { display: block; }
.view-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: 12px; font-weight: 750; letter-spacing: 0; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 27px; line-height: 1.15; letter-spacing: 0; }
h2 { margin: 0; font-size: 16px; line-height: 1.3; letter-spacing: 0; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { min-height: 112px; display: flex; flex-direction: column; justify-content: space-between; padding: 17px; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid #84928a; border-radius: var(--radius); box-shadow: var(--shadow); }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { color: var(--ink); font-size: 31px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric.accent { border-top-color: var(--green); background: #f9fdfa; }
.metric.warm { border-top-color: var(--orange); background: #fffaf7; }
.work-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 24px 0; }
.work-action { min-height: 142px; padding: 18px; display: flex; flex-direction: column; align-items: flex-start; gap: 7px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-align: left; box-shadow: var(--shadow); transition: transform .16s ease, border-color .16s ease; }
.work-action:hover { transform: translateY(-2px); border-color: var(--green); }
.work-action span { color: var(--orange); font-size: 12px; font-family: ui-monospace, monospace; font-weight: 800; }
.work-action b { margin-top: auto; font-size: 16px; }
.work-action small { color: var(--muted); font-size: 12px; line-height: 1.45; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.compact-panel { padding: 20px; }
.panel-header { min-height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.55; }
.button { min-height: 39px; padding: 0 14px; border: 1px solid transparent; border-radius: 5px; font-weight: 750; font-size: 13px; white-space: nowrap; }
.button.primary { background: var(--green); color: #fff; }
.button.primary:hover { background: #075b41; }
.button.secondary { background: #fff; color: var(--ink); border-color: #bfcac0; }
.button.secondary:hover { border-color: var(--green); color: var(--green); }
.button.danger { background: var(--red); color: #fff; }
.button.danger:hover { background: #993028; }
.status-chip { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-chip.neutral { background: #eef1ee; color: #59655e; }
.status-chip.accent { background: var(--green-soft); color: #076142; }
.status-chip.warm { background: var(--orange-soft); color: #9b431a; }
.status-chip.danger { background: var(--red-soft); color: #972d27; }
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .62fr); gap: 18px; align-items: start; }
.form-panel { padding: 22px; }
.required-note { color: var(--red); font-size: 12px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 14px; position: relative; }
.field-grid > .span-2 { grid-column: span 2; }
.field { display: grid; gap: 7px; color: #45534b; font-size: 12px; font-weight: 700; }
.field input, .filter-bar input, .filter-bar select { min-width: 0; height: 42px; padding: 0 11px; color: var(--ink); background: #fcfdfc; border: 1px solid #bfcac0; border-radius: 5px; font-weight: 500; }
.field input[readonly] { color: #35453c; background: #f1f5f1; border-color: #d1dbd2; }
.field input::placeholder, .filter-bar input::placeholder { color: #98a39c; }
.form-actions { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.suggestion-list { grid-column: 1 / -1; display: none; gap: 5px; padding: 8px; margin-top: -9px; border: 1px solid #c7d2c8; background: #fff; border-radius: 5px; }
.suggestion-list.visible { display: grid; }
.suggestion { padding: 8px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 10px; text-align: left; border: 0; border-radius: 4px; background: #f7faf7; color: var(--ink); }
.suggestion:hover { background: var(--green-soft); }
.suggestion small { color: var(--muted); }
.catalog-match { min-height: 34px; padding: 8px 10px; border: 1px solid #d4ddd5; background: #f5f8f5; color: var(--muted); border-radius: 5px; font-size: 12px; }
.catalog-match.matched { border-color: #9bcbb0; background: var(--green-soft); color: #075b41; }
.catalog-match.unmatched { border-color: #e4b6a8; background: #fff5f1; color: #a6421e; }
.label-result { min-height: 360px; position: sticky; top: 22px; padding: 22px; display: flex; flex-direction: column; gap: 13px; border: 1px solid #cbd6cd; background: #eaf1ec; border-radius: var(--radius); }
.label-result.empty { align-items: center; justify-content: center; text-align: center; color: #657269; }
.label-result.empty strong { max-width: 180px; font-size: 16px; color: #47554c; }
.label-card { background: #fff; border: 1px solid #1b2823; min-height: 230px; padding: 17px; display: grid; grid-template-columns: 120px 1fr; gap: 14px; }
.label-card img { width: 112px; height: 112px; }
.label-card .model { font-size: 20px; line-height: 1.2; font-weight: 800; word-break: break-word; }
.label-card .meta { margin-top: 12px; display: grid; gap: 5px; font-size: 12px; }
.label-card .meta b { color: var(--muted); font-weight: 600; }
.label-card .code { grid-column: 1 / -1; padding-top: 9px; border-top: 1px solid var(--line); font-family: ui-monospace, monospace; font-size: 13px; font-weight: 800; }
.qr-label-preview { width: min(260px, 100%); aspect-ratio: 1; align-self: center; object-fit: contain; background: #fff; border: 1px solid #1b2823; }
.label-actions { display: flex; gap: 8px; }
.catalog-layout { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(300px, 1.2fr); gap: 18px; align-items: stretch; margin-bottom: 18px; }
.import-preview { min-height: 210px; padding: 21px; display: flex; flex-direction: column; gap: 14px; }
.import-preview.empty { align-items: center; justify-content: center; color: #657269; text-align: center; }
.import-preview.empty strong { color: #47554c; font-size: 16px; }
.import-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.import-summary div { padding: 10px; border: 1px solid #d8dfd8; background: #f8faf8; }
.import-summary span, .import-summary strong { display: block; }
.import-summary span { color: var(--muted); font-size: 11px; }
.import-summary strong { margin-top: 3px; font-size: 18px; font-variant-numeric: tabular-nums; }
.import-detail { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.mode-switch { display: inline-flex; overflow: hidden; margin-bottom: 16px; border: 1px solid #c4d0c6; background: #e8eee8; border-radius: 6px; }
.mode { min-width: 82px; min-height: 38px; border: 0; border-right: 1px solid #c4d0c6; background: transparent; color: #607067; font-size: 13px; font-weight: 700; }
.mode:last-child { border-right: 0; }
.mode.active { background: #fff; color: var(--green); }
.scan-layout { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(320px, 1.2fr); gap: 18px; align-items: start; }
.scan-panel, .carton-result, .operation-panel { padding: 21px; }
.scan-input-row { display: flex; gap: 8px; }
.scan-input-row input { min-width: 0; flex: 1; height: 46px; padding: 0 12px; border: 1px solid #a9b9ac; border-radius: 5px; font-family: ui-monospace, monospace; font-weight: 700; }
.camera-wrap { min-height: 184px; display: grid; place-items: center; gap: 12px; margin-top: 16px; padding: 10px; background: #edf2ee; border: 1px dashed #a7b8ab; }
#camera-preview { display: none; max-width: 100%; max-height: 260px; }
#camera-preview.active { display: block; }
.camera-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.scanner-note { margin: 12px 0 0; }
.carton-result { min-height: 248px; }
.empty-message { color: var(--muted); margin: 0; padding: 80px 0; text-align: center; }
.carton-summary { display: grid; grid-template-columns: 1fr auto; gap: 18px; }
.carton-summary .model { margin: 6px 0 4px; font-size: 23px; font-weight: 800; word-break: break-word; }
.carton-summary .product-name { color: var(--muted); font-size: 13px; }
.carton-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.carton-info div { min-width: 0; }
.carton-info span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.carton-info b { display: block; overflow-wrap: anywhere; font-size: 13px; }
.operation-panel { margin-top: 18px; }
.operation-panel.hidden, .history-panel.hidden { display: none; }
.inline-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: end; }
.inline-form .button { width: max-content; }
.history-panel, .table-panel { margin-top: 18px; padding: 20px; }
.catalog-editor { margin-top: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 690px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; white-space: nowrap; }
th { color: var(--muted); font-size: 11px; font-weight: 750; }
tbody tr:hover { background: #f8faf8; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-bar input { flex: 1; }
.filter-bar select { min-width: 130px; }
.table-link { border: 0; padding: 0; background: transparent; color: var(--blue); font-family: ui-monospace, monospace; font-weight: 750; }
.table-link:hover { text-decoration: underline; }
.hidden { display: none; }
.auth-overlay { position: fixed; z-index: 40; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(18, 31, 24, .54); }
.auth-overlay.hidden { display: none; }
.auth-card { width: min(410px, 100%); padding: 28px; background: #fff; border: 1px solid #c7d2c8; border-radius: var(--radius); box-shadow: 0 24px 60px rgba(17, 29, 22, .28); }
.auth-brand { margin-bottom: 25px; color: var(--ink); }
.auth-brand small { color: var(--muted); }
.auth-form { display: grid; gap: 16px; }
.auth-form.hidden { display: none; }
.auth-form h1 { font-size: 24px; }
.auth-form .button { margin-top: 4px; }
.toast-region { position: fixed; z-index: 20; right: 20px; bottom: 20px; display: grid; gap: 8px; width: min(360px, calc(100vw - 40px)); }
.toast { padding: 13px 14px; border: 1px solid #b8c7bb; background: #fff; border-left: 4px solid var(--green); box-shadow: var(--shadow); border-radius: 5px; font-size: 13px; line-height: 1.45; }
.toast.error { border-left-color: var(--red); }
.access-dialog { width: min(390px, calc(100vw - 28px)); padding: 0; border: 1px solid #bfcac0; border-radius: var(--radius); box-shadow: 0 24px 60px rgba(23, 33, 30, .22); }
.access-dialog::backdrop { background: rgba(20, 30, 25, .38); }
.access-dialog form { padding: 21px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.dialog-close { width: 30px; height: 30px; border: 0; border-radius: 4px; background: #eef2ee; color: var(--muted); font-size: 23px; line-height: 1; }
.dialog-actions { display: flex; justify-content: space-between; margin-top: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .app-frame { grid-template-columns: 1fr; grid-template-rows: 60px auto 1fr; }
  .topbar { grid-column: 1; padding: 0 16px; }
  .sidebar { grid-row: 2; padding: 7px 9px; overflow-x: auto; border-right: 0; border-bottom: 1px solid #ccd6cd; }
  .nav-list { min-width: max-content; grid-auto-flow: column; grid-auto-columns: 112px; }
  .nav-item { min-height: 47px; padding: 7px 8px; }
  .nav-item small { display: none; }
  .sidebar-footer { display: none; }
  .workspace { padding: 24px 16px 38px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .work-grid { grid-template-columns: 1fr; }
  .form-layout, .scan-layout, .catalog-layout { grid-template-columns: 1fr; }
  .label-result { position: static; min-height: 265px; }
}

@media (max-width: 560px) {
  .connection { font-size: 11px; }
  .workspace { padding: 20px 12px 32px; }
  .view-heading { align-items: flex-start; flex-direction: column; margin-bottom: 18px; }
  h1 { font-size: 24px; }
  .metrics { gap: 8px; }
  .metric { min-height: 95px; padding: 13px; }
  .metric strong { font-size: 27px; }
  .field-grid, .inline-form { grid-template-columns: 1fr; }
  .field-grid > .span-2 { grid-column: auto; }
  .import-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .label-card { grid-template-columns: 100px 1fr; padding: 13px; }
  .label-card img { width: 94px; height: 94px; }
  .scan-input-row { flex-direction: column; }
  .scan-input-row .button { width: 100%; }
  .camera-actions { width: 100%; }
  .camera-actions .button { flex: 1 1 130px; }
  .mode { min-width: 76px; }
  .filter-bar { flex-wrap: wrap; }
  .filter-bar input { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
