:root {
  color-scheme: dark;
  --bg: #101518;
  --bg-deep: #0d1114;
  --shell: #151b1f;
  --surface: #1b2227;
  --surface-2: #20282d;
  --surface-3: #252e33;
  --line: #354047;
  --line-soft: rgba(138, 154, 164, 0.18);
  --text: #f5f7f7;
  --muted: #aeb7bd;
  --dim: #7c898f;
  --green: #41c955;
  --green-strong: #35b94a;
  --green-soft: rgba(65, 201, 85, 0.15);
  --red: #ff625d;
  --red-soft: rgba(255, 98, 93, 0.13);
  --radius: 7px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
input, select { color: var(--text); background: #151b1f; border: 1px solid var(--line); border-radius: 6px; outline: none; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(65, 201, 85, .12); }
input::placeholder { color: #7e898f; }

.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 12px; font-weight: 700; letter-spacing: .16em; }
.text-button { padding: 0; border: 0; background: none; cursor: pointer; }
.text-button:hover { color: var(--green); }
.top-divider, .summary-divider { display: inline-block; width: 1px; height: 22px; background: var(--line); }

.btn { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 9px; padding: 0 18px; border: 1px solid transparent; border-radius: 6px; font-weight: 650; cursor: pointer; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.btn:active { transform: translateY(1px); }
.btn-primary { color: white; background: var(--green); border-color: var(--green); }
.btn-primary:hover { background: var(--green-strong); border-color: var(--green-strong); }
.btn-outline { background: rgba(255, 255, 255, .015); border-color: #58646b; }
.btn-outline:hover { border-color: var(--green); color: var(--green); }
.btn-ghost { background: transparent; border-color: #5b666d; }
.btn-small { min-height: 36px; padding: 0 15px; font-size: 14px; }
.btn-large { min-height: 50px; padding: 0 30px; font-size: 16px; }
.btn-wide { width: 100%; }
.icon-button { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; border: 0; border-radius: 6px; background: transparent; cursor: pointer; font-size: 23px; }
.icon-button:hover { background: var(--surface-3); }
.danger-button { border: 0; background: none; color: var(--red); cursor: pointer; }

.input-with-icon { position: relative; display: block; }
.input-with-icon > i { position: absolute; left: 15px; top: 50%; z-index: 1; transform: translateY(-50%); color: #dbe0e2; font-size: 20px; }
.input-with-icon input { width: 100%; min-height: 48px; padding: 0 16px 0 46px; }

.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 1000; display: grid; gap: 10px; width: min(360px, calc(100vw - 40px)); }
.toast { padding: 14px 18px; border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: var(--radius); background: #1e272c; box-shadow: 0 12px 28px rgba(0,0,0,.28); }
.toast-error { border-left-color: var(--red); }

/* Login */
.login-page { min-height: 100vh; }
.login-shell { display: grid; min-height: 100vh; grid-template-columns: minmax(420px, 1.08fr) minmax(430px, .92fr); }
.login-brand { display: flex; flex-direction: column; justify-content: center; padding: 8vw; background: #11181c; border-right: 1px solid var(--line); }
.brand-mark { display: inline-flex; width: 72px; height: 72px; margin-bottom: 42px; align-items: center; justify-content: center; border-radius: 14px; color: white; background: var(--green); font-size: 36px; }
.login-brand h1 { margin: 0 0 18px; font-size: clamp(42px, 5vw, 72px); line-height: 1.05; }
.login-brand > p:last-child { max-width: 580px; margin: 0; color: var(--muted); font-size: 19px; line-height: 1.8; }
.login-panel { display: grid; place-items: center; padding: 40px; background: #0d1114; }
.login-panel-inner { width: min(440px, 100%); }
.login-panel h2 { margin: 0 0 8px; font-size: 34px; }
.login-panel .muted { margin: 0 0 34px; }
.login-form { display: grid; gap: 20px; }
.login-form label { display: grid; gap: 9px; color: #dce1e3; }
.login-form .btn { margin-top: 8px; min-height: 52px; }
.back-link { display: inline-flex; margin-top: 28px; align-items: center; gap: 8px; color: var(--muted); }
.back-link:hover { color: var(--green); }

/* Shared data grid */
.data-grid { border: 1px solid var(--line); border-radius: var(--radius); background: rgba(20, 27, 31, .76); overflow: hidden; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
thead { background: #1d252a; }
th { height: 52px; padding: 0 18px; color: #f0f3f4; font-weight: 700; text-align: left; white-space: nowrap; }
td { height: 56px; padding: 7px 18px; border-top: 1px solid var(--line-soft); color: #e8ecee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
tbody tr:hover { background: rgba(255,255,255,.018); }
.empty-state { height: 300px; text-align: center; color: var(--muted); }
.empty-state i { display: block; margin-bottom: 12px; font-size: 38px; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { color: var(--text); font-size: 18px; }
.table-footer { display: flex; min-height: 72px; padding: 0 18px; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); }
.pagination { display: flex; align-items: center; gap: 8px; }
.pagination a, .pagination span { display: inline-flex; min-width: 36px; height: 36px; padding: 0 9px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 5px; }
.pagination a:hover, .pagination a.active { border-color: var(--green); color: white; background: var(--green); }

/* Mapping page */
.mapping-page { min-width: 1120px; background: #151c20; }
.mapping-shell { min-height: 100vh; }
.mapping-topbar { display: flex; height: 68px; padding: 0 28px; align-items: center; justify-content: space-between; border-bottom: 1px solid #465159; background: #141a1e; }
.brand-row, .account-row { display: flex; align-items: center; gap: 28px; }
.brand-row strong { font-size: 23px; }
.brand-row a { color: var(--muted); font-size: 18px; }
.brand-row a:hover, .brand-row a.top-nav-active { color: var(--text); }
.account-row { gap: 12px; }
.account-row > i:first-child { font-size: 22px; }
.account-row .top-divider { margin: 0 12px; }
.mapping-main { padding: 20px; }
.mapping-commandbar { display: grid; grid-template-columns: auto minmax(320px, 560px) 1fr; gap: 26px; align-items: center; padding: 0 16px 20px; }
.mapping-search input { min-height: 50px; }
.command-actions { display: flex; justify-content: flex-end; gap: 18px; }
.mapping-summary { display: flex; height: 48px; padding: 0 17px; align-items: center; gap: 14px; color: var(--muted); }
.mapping-summary strong { color: var(--green); font-size: 17px; }
.mapping-summary .active-tab { position: relative; color: white; font-weight: 700; }
.mapping-summary .active-tab::after { position: absolute; right: 0; bottom: -10px; left: 0; height: 2px; background: var(--green); content: ""; }
.bulk-bar { display: flex; height: 52px; padding: 0 18px; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); }
.bulk-bar label { display: flex; align-items: center; gap: 10px; }
.bulk-bar.is-idle .danger-button { opacity: .45; pointer-events: none; }
.mapping-grid table { min-width: 1260px; }
.mapping-grid th:nth-child(2) { width: 150px; }
.mapping-grid th:nth-child(3) { width: 220px; }
.mapping-grid th:nth-child(4), .mapping-grid th:nth-child(5), .mapping-grid th:nth-child(6) { width: 190px; }
.mapping-grid th:nth-child(7) { width: 180px; }
.mapping-grid .check-col { width: 50px; }
.mapping-grid .action-col { width: 135px; }
.mapping-grid td { height: 116px; }
.mapping-grid input:not([type=checkbox]):not([type=file]) { width: 100%; min-height: 42px; padding: 0 12px; border-color: var(--green); }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--green); }
.table-product-image, .image-upload img { width: 84px; height: 92px; object-fit: cover; border: 1px solid #4b565c; border-radius: 2px; background: #2b3337; }
.table-image-empty { display: grid; width: 84px; height: 92px; place-items: center; border: 1px dashed #4b565c; color: var(--dim); font-size: 28px; }
.image-upload { position: relative; display: inline-grid; cursor: pointer; }
.image-upload input { display: none; }
.image-change { position: absolute; right: 0; bottom: 0; left: 0; padding: 5px 2px; color: white; background: rgba(0,0,0,.74); text-align: center; font-size: 11px; }
.image-placeholder { display: grid; width: 84px; height: 92px; place-items: center; align-content: center; border: 1px dashed #536066; color: var(--muted); gap: 4px; font-size: 12px; }
.image-placeholder i { font-size: 24px; }
.editing-row { background: rgba(65, 201, 85, .035); }
.table-action { padding: 8px 6px; border: 0; background: none; color: white; cursor: pointer; }
.table-action:hover { color: var(--green); }
.table-action.danger { color: var(--red); }

/* Records page */
.records-page { min-width: 1120px; }
.records-shell { display: grid; min-height: 100vh; grid-template-columns: 214px 1fr; }
.admin-sidebar { position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column; border-right: 1px solid #263037; background: #12191d; }
.sidebar-brand { padding: 32px 28px 42px; font-size: 22px; }
.admin-sidebar nav { display: grid; gap: 4px; }
.admin-sidebar nav a { position: relative; display: flex; height: 64px; padding: 0 28px; align-items: center; gap: 14px; color: #d8dddf; font-size: 16px; }
.admin-sidebar nav a i { font-size: 23px; }
.admin-sidebar nav a:hover, .admin-sidebar nav a.active { color: white; background: #222b30; }
.admin-sidebar nav a.active::before { position: absolute; top: 0; bottom: 0; left: 0; width: 5px; background: var(--green); content: ""; }
.admin-sidebar nav a.active i { color: var(--green); }
.sidebar-user { display: grid; gap: 22px; margin-top: auto; padding: 24px 28px 28px; }
.sidebar-user > div, .sidebar-user button { display: flex; align-items: center; gap: 12px; }
.sidebar-user > div i:first-child { font-size: 28px; }
.sidebar-user button { padding: 0; border: 0; background: none; cursor: pointer; }
.sidebar-user button:hover { color: var(--green); }
.records-main { min-width: 0; padding: 32px; }
.records-heading h1 { margin: 0; font-size: 32px; }
.records-heading p { margin: 8px 0 24px; color: var(--muted); }
.record-filters { display: grid; grid-template-columns: minmax(300px, 1.2fr) minmax(340px, .9fr) 125px auto auto; gap: 14px; margin-bottom: 20px; }
.date-range { display: grid; min-height: 48px; grid-template-columns: auto 1fr auto 1fr auto; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: #151b1f; }
.date-range input { width: 100%; padding: 0; border: 0; background: transparent; }
.record-filters select { min-height: 48px; padding: 0 12px; }
.records-grid th:nth-child(1) { width: 210px; }
.records-grid th:nth-child(2) { width: 230px; }
.records-grid th:nth-child(3) { width: 230px; }
.records-grid th:nth-child(4) { width: 210px; }
.records-grid td { height: 49px; }

/* Dialogs */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.72); }
.modal-dialog { width: min(540px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 10px; background: #182025; }
.modal-dialog form { padding: 26px; }
.modal-dialog header, .modal-dialog footer, .scan-dialog header { display: flex; align-items: center; justify-content: space-between; }
.modal-dialog h2, .scan-dialog h2 { margin: 0; }
.drop-zone { display: grid; min-height: 190px; margin: 24px 0 14px; place-items: center; align-content: center; gap: 8px; border: 1px dashed #5a666d; border-radius: 8px; cursor: pointer; }
.drop-zone:hover { border-color: var(--green); background: var(--green-soft); }
.drop-zone i { color: var(--green); font-size: 42px; }
.drop-zone span { color: var(--muted); font-size: 13px; }
.drop-zone input { width: 85%; margin-top: 12px; }
.modal-note { color: var(--muted); font-size: 13px; }
.modal-dialog footer { margin-top: 24px; justify-content: flex-end; gap: 12px; }

/* Mobile scan */
.scan-page { min-height: 100vh; background: #0d1113; }
.scan-app { position: relative; width: min(100%, 500px); min-height: 100vh; margin: 0 auto; background: #101416; }
.scan-header { display: flex; height: 92px; padding: 0 22px; align-items: center; justify-content: space-between; background: #101416; }
.scan-header strong { font-size: 24px; letter-spacing: .01em; }
.scan-history-button { display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; font-weight: 650; cursor: pointer; font-size: 17px; }
.scan-history-button i { font-size: 24px; }
.scan-result { min-height: calc(100vh - 92px); padding-bottom: 28px; }
.scan-product-media { height: min(49vh, 470px); background: #272b2d; overflow: hidden; }
.scan-product-media img { display: block; width: 100%; height: 100%; object-fit: contain; }
.scan-product-empty { display: grid; width: 100%; height: 100%; place-items: center; color: #68747a; font-size: 78px; }
.scan-content { padding: 24px 22px 0; }
.scan-content h1 { margin: 0 0 34px; font-size: clamp(27px, 7.2vw, 38px); line-height: 1.22; letter-spacing: -.02em; }
.spec-block { display: grid; gap: 3px; margin-bottom: 20px; }
.spec-block span { font-size: clamp(27px, 7vw, 36px); font-weight: 800; }
.spec-block strong { font-size: clamp(30px, 8vw, 41px); line-height: 1.35; }
.barcode-block { display: grid; gap: 8px; }
.barcode-block > span { color: #b9c0c4; font-size: 17px; }
.barcode-card { padding: 8px 14px 7px; border-radius: 7px; background: white; text-align: center; }
.barcode-card img { display: block; width: 84%; height: 20px; margin: 0 auto; object-fit: fill; }
.barcode-card strong { display: block; color: #0c1012; font-family: Arial, sans-serif; font-size: clamp(25px, 7vw, 34px); font-weight: 500; letter-spacing: .06em; line-height: 1.2; }
.continue-scan { display: flex; width: 100%; min-height: 72px; margin-top: 22px; align-items: center; justify-content: center; gap: 15px; border: 0; border-radius: 7px; color: white; background: var(--green); cursor: pointer; font-size: 27px; font-weight: 800; }
.continue-scan:hover { background: var(--green-strong); }
.continue-scan i { font-size: 36px; }
.scan-error-copy { margin: -20px 0 32px; color: var(--red); }
.is-hidden { display: none; }

.scan-status-screen { display: flex; min-height: calc(100vh - 92px); padding: 36px 22px 28px; flex-direction: column; background: #101416; }
.scan-status-screen.is-hidden { display: none; }
.scan-status-main { display: flex; flex: 1; min-height: 0; align-items: center; justify-content: center; flex-direction: column; text-align: center; }
.scan-status-main > i { color: var(--green); font-size: clamp(110px, 30vw, 150px); line-height: 1; }
.scan-status-screen.is-loading .scan-status-main > i { animation: scan-status-pulse 1.05s ease-in-out infinite; }
.scan-status-screen.is-not-found .scan-status-main > i,
.scan-status-screen.is-error .scan-status-main > i { color: var(--red); font-size: clamp(140px, 36vw, 180px); }
.scan-status-screen h1 { max-width: 100%; margin: 42px 0 0; font-size: clamp(42px, 11.5vw, 58px); line-height: 1.12; letter-spacing: -.035em; text-wrap: balance; }
.scan-status-screen.is-loading h1 { font-size: clamp(52px, 14vw, 68px); }
.scan-status-code { margin: 26px 0 0; color: #c4c9cc; font-family: Arial, sans-serif; font-size: clamp(22px, 6vw, 30px); letter-spacing: .035em; }
.scan-status-rescan { flex: 0 0 auto; margin-top: 24px; }
.scan-status-screen.is-loading .scan-status-rescan { display: none; }
@keyframes scan-status-pulse { 0%, 100% { opacity: .55; transform: scale(.94); } 50% { opacity: 1; transform: scale(1); } }

.scan-dialog { width: min(460px, calc(100vw - 22px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: #151c20; }
.scan-dialog-inner { padding: 22px; }
.camera-frame { position: relative; height: 270px; margin: 20px 0 14px; border-radius: 9px; background: #0b0e10; overflow: hidden; }
.camera-frame video { width: 100%; height: 100%; object-fit: cover; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 10px; color: var(--muted); }
.camera-placeholder i { font-size: 45px; }
.or-divider { display: flex; margin: 22px 0 16px; align-items: center; gap: 12px; color: var(--dim); font-size: 13px; }
.or-divider::before, .or-divider::after { flex: 1; height: 1px; background: var(--line); content: ""; }
.manual-scan-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.manual-scan-form input { min-width: 0; min-height: 46px; padding: 0 13px; }
.scan-feedback { min-height: 22px; margin: 12px 0 0; color: var(--green); font-size: 13px; }
.scan-feedback.is-error { color: var(--red); }
.scan-history-list { display: grid; gap: 1px; margin-top: 20px; max-height: 70vh; overflow: auto; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; padding: 14px 4px; border-bottom: 1px solid var(--line-soft); }
.history-item strong { font-size: 15px; }
.history-item span { display: grid; gap: 4px; text-align: left; }
.history-item small, .history-item time { color: var(--muted); font-size: 12px; }
.history-empty { padding: 50px 0; color: var(--muted); text-align: center; }
.toast.is-leaving { opacity: 0; transform: translateY(-8px); transition: opacity .25s ease, transform .25s ease; }

@media (max-width: 760px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-panel { min-height: 100vh; padding: 28px; }
  .scan-app { width: 100%; }
}

@media (max-width: 520px) {
  .scan-header { height: 76px; padding: 0 20px; }
  .scan-header strong { font-size: 22px; }
  .scan-history-button { font-size: 16px; }
  .scan-history-button i { font-size: 22px; }
  .scan-result { min-height: calc(100vh - 76px); padding-bottom: 16px; }
  .scan-status-screen { min-height: calc(100vh - 76px); padding: 28px 20px 16px; }
  .scan-product-media { height: 41vh; max-height: 360px; }
  .scan-content { padding: 18px 20px 0; }
  .scan-content h1 { margin-bottom: 24px; font-size: clamp(26px, 7vw, 34px); }
  .spec-block { margin-bottom: 16px; }
  .spec-block span { font-size: clamp(25px, 6.6vw, 32px); }
  .spec-block strong { font-size: clamp(29px, 7.5vw, 36px); }
  .barcode-block { gap: 6px; }
  .barcode-block > span { font-size: 16px; }
  .barcode-card { padding: 7px 12px 6px; }
  .barcode-card img { width: 84%; height: 18px; }
  .barcode-card strong { font-size: clamp(24px, 6.6vw, 30px); }
  .continue-scan { min-height: 60px; margin-top: 16px; font-size: 24px; }
  .continue-scan i { font-size: 31px; }
}

@media (min-width: 601px) and (min-height: 900px) {
  .scan-app { box-shadow: 0 0 0 1px #2d3539, 0 18px 60px rgba(0,0,0,.45); }
}
