* { box-sizing: border-box; }
:root {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Helvetica Neue', sans-serif;
  color: #1c1c1e;
  background: #f2f2f7;
  font-synthesis: none;
}
html { background: #f2f2f7; }
body { margin: 0; min-width: 320px; background: #f2f2f7; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; transition: transform .2s ease, opacity .2s ease, background-color .2s ease, border-color .2s ease; }
button:active, a.btn:active, label.btn:active { transform: scale(.97); opacity: .8; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 3px solid rgba(0,122,255,.55); outline-offset: 2px; }

.main-container { width: min(1024px, 100%); margin: 0 auto; padding: 0 16px 48px; }
.page-header { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: 0 -16px 24px; padding: max(14px, env(safe-area-inset-top)) 16px 14px; background: rgba(242,242,247,.82); border-bottom: 1px solid rgba(60,60,67,.16); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); }
.eyebrow { display: block; color: #8e8e93; font-size: 11px; font-weight: 700; letter-spacing: .08em; }
h1 { margin: 3px 0 1px; font-size: clamp(28px, 7vw, 36px); line-height: 1.1; letter-spacing: 0; }
.page-header p { margin: 4px 0 0; color: #8e8e93; font-size: 14px; }

.quick-search, .panel-toolbar, .admin-panel { border: 0; border-radius: 16px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.quick-search { margin-bottom: 16px; padding: 17px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.section-heading strong { font-size: 17px; }
.section-heading span { color: #8e8e93; font-size: 12px; }
.toolbar-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
label { color: #3a3a3c; font-size: 13px; font-weight: 600; }
input, select { min-width: 0; border: 1px solid #d1d1d6; border-radius: 10px; padding: 10px 11px; color: #1c1c1e; background: #fff; outline: none; transition: border-color .2s ease, box-shadow .2s ease; }
input:focus, select:focus { border-color: #007aff; box-shadow: 0 0 0 3px rgba(0,122,255,.16); }
.quick-search input { flex: 1; min-width: 160px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; border: 0; border-radius: 10px; padding: 10px 17px; font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap; transition: transform .2s ease, opacity .2s ease, background-color .2s ease, border-color .2s ease; }
.btn-search { border-radius: 999px; color: #fff; background: #007aff; }
.btn-search:hover:not(:disabled) { background: #006ee6; }
.btn-outline { color: #007aff; background: #f2f2f7; border: 1px solid #d1d1d6; }
.btn-outline:hover:not(:disabled) { background: #e5e5ea; }
.btn-danger { color: #ff3b30; border-color: rgba(255,59,48,.45); background: rgba(255,59,48,.06); }
.btn-danger:hover:not(:disabled) { color: #d70015; border-color: rgba(215,0,21,.55); background: rgba(255,59,48,.12); }

.browser-layout { display: block; min-height: 0; }
.access-panel { display: grid; min-height: min(520px, calc(100vh - 150px)); min-height: min(520px, calc(100dvh - 150px)); place-items: center; padding: 24px 0 72px; }
.access-card { width: min(420px, 100%); border-radius: 16px; padding: 22px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.access-card h2 { margin: 0 0 18px; font-size: 22px; }
.access-card label, .access-card input { display: block; width: 100%; }
.access-card input { margin-top: 7px; }
.access-card .btn { width: 100%; margin-top: 16px; }
.access-card .error { margin-bottom: 0; text-align: center; }
.left-panel { min-width: 0; }
.panel-toolbar { margin-bottom: 12px; padding: 14px 17px; }
.panel-toolbar .toolbar-row > label { margin-right: -4px; }
.image-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; align-content: start; min-height: 390px; padding: 2px; }
.empty-state, .placeholder { grid-column: 1/-1; color: #8e8e93; text-align: center; padding: 76px 12px; font-size: 14px; }
.image-card { position: relative; overflow: hidden; border: 2px solid transparent; border-radius: 14px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); cursor: pointer; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
.image-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.image-card.selected { border-color: #007aff; box-shadow: 0 0 0 2px rgba(0,122,255,.18); }
.image-card.selected::after { content: '✓'; position: absolute; top: 7px; right: 7px; width: 23px; height: 23px; border-radius: 50%; color: #fff; background: #007aff; font-size: 15px; line-height: 23px; text-align: center; }
.card-img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #f2f2f7; }
.card-label { overflow: hidden; padding: 8px 7px 9px; color: #3a3a3c; background: #fff; font-size: 12px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 18px 0 2px; }
.pagination span { min-width: 180px; color: #8e8e93; font-size: 13px; text-align: center; }
.btn-page { color: #007aff; background: #fff; border: 1px solid #d1d1d6; }

dialog { width: min(480px, calc(100% - 28px)); border: 0; border-radius: 20px; padding: 24px; box-shadow: 0 12px 40px rgba(0,0,0,.22); }
dialog::backdrop { background: rgba(0,0,0,.4); backdrop-filter: blur(4px); }
dialog label { display: block; margin: 12px 0; }
dialog input { display: block; width: 100%; margin-top: 6px; }
dialog select { display: block; width: 100%; margin-top: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.error { min-height: 1.2em; color: #ff3b30; }

/* Admin */
.admin-container { width: min(1024px, 100%); }
.admin-panel { margin: 0 0 16px; padding: 18px; }
.admin-panel h2 { margin: 0 0 8px; font-size: 22px; }
.admin-panel > p { color: #8e8e93; font-size: 14px; }
.admin-login { width: min(420px, 100%); margin: 72px auto 0; }
.admin-login input { display: block; width: 100%; margin-top: 7px; }
.admin-login .btn { width: 100%; margin-top: 8px; }
.admin-notice { position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; z-index: 10000; max-width: min(520px, calc(100% - 28px)); border: 1px solid rgba(52,199,89,.25); border-radius: 12px; padding: 11px 16px; color: #1f6f32; background: rgba(235,255,240,.96); box-shadow: 0 8px 28px rgba(0,0,0,.18); font-size: 14px; line-height: 1.45; transform: translateX(-50%); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.admin-notice.is-error { border-color: rgba(255,59,48,.25); color: #b42318; background: rgba(255,241,240,.97); }
.admin-notice:empty { display: none; }
.checkbox-label { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 10px; white-space: nowrap; cursor: pointer; }
.checkbox-label input { position: relative; width: 42px; height: 24px; min-width: 42px; margin: 0; border: 0; border-radius: 999px; padding: 0; appearance: none; -webkit-appearance: none; background: #e5e5ea; box-shadow: none; cursor: pointer; transition: background-color .2s ease; }
.checkbox-label input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.22); transition: transform .2s ease; }
.checkbox-label input:checked { background: #34c759; }
.checkbox-label input:checked::after { transform: translateX(18px); }
.checkbox-label input:focus-visible { box-shadow: 0 0 0 3px rgba(0,122,255,.2); }
#settingsForm label:not(.checkbox-label) { display: block; margin-bottom: 12px; }
#settingsForm label:not(.checkbox-label) input { display: block; width: min(520px,100%); margin-top: 6px; }
#settingsForm label small { display: block; margin-top: 6px; color: #6e6e73; }
.admin-filters { margin-bottom: 13px; }
.admin-filters label { display: inline-flex; align-items: center; gap: 6px; }
.admin-filters input { width: 150px; }
.batch-bar { margin-bottom: 13px; padding: 11px; border-radius: 12px; background: #f2f2f7; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(180px,1fr)); gap: 12px; }
.admin-card { overflow: hidden; border: 0; border-radius: 14px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.admin-card > input { align-self: flex-start; width: 20px; height: 20px; margin: 10px; accent-color: #007aff; }
.admin-card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #f2f2f7; }
.admin-image-placeholder { display: grid; width: 100%; aspect-ratio: 1; place-items: center; padding: 12px; color: #8e8e93; background: #f2f2f7; font-size: 13px; text-align: center; }
.admin-card-info { display: grid; gap: 3px; padding: 10px 11px; font-size: 12px; }
.admin-card-info strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.admin-card-info small { overflow: hidden; color: #8e8e93; text-overflow: ellipsis; white-space: nowrap; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 9px 11px 11px; border-top: 1px solid #e5e5ea; }
.admin-actions .btn { min-height: 32px; padding: 7px 11px; font-size: 12px; }
.admin-result { margin-top: 12px; }
.product-card { margin-bottom: 9px; padding: 13px; border: 0; border-radius: 12px; background: #f2f2f7; }
.product-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.product-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex: 1; }
.product-title strong { font-size: 14px; }
.product-title span { overflow: hidden; color: #8e8e93; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.product-desc { display: -webkit-box; overflow: hidden; margin-top: 7px; color: #636366; font-size: 13px; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.product-form { display: grid; gap: 9px; margin-top: 11px; padding-top: 11px; border-top: 1px solid #d1d1d6; }
.product-field { display: grid; gap: 4px; color: #636366; font-size: 12px; }
.product-field input { width: 100%; }
.product-form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; color: #248a3d; background: #d8f5df; font-size: 11px; font-weight: 600; }
.up-item { padding: 5px 0; font-size: 13px; line-height: 1.5; }
.up-match { color: #248a3d; }
.up-miss { color: #b25000; }
.work-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 7px; padding: 11px 12px; border-bottom: 1px solid #e5e5ea; }
.work-name { font-size: 13px; font-weight: 600; }
.work-actions { display: flex; gap: 6px; }

/* Dynamic preview and image viewer */
.modal-overlay { position: fixed; inset: 0; z-index: 9998; display: flex; width: 100%; height: 100vh; height: 100dvh; align-items: flex-end; justify-content: center; padding: 12px; background: rgba(0,0,0,.4); backdrop-filter: blur(4px); }
.modal-box { position: relative; display: flex; flex-direction: column; width: min(720px, 100%); max-height: 92vh; max-height: 92dvh; overflow: hidden; border-radius: 20px 20px 0 0; background: #fff; box-shadow: 0 -4px 30px rgba(0,0,0,.18); }
.modal-box::before { content: ''; align-self: center; width: 36px; height: 5px; margin: 10px 0 2px; border-radius: 99px; background: #c7c7cc; }
.modal-close { position: absolute; top: 12px; right: 12px; z-index: 2; width: 34px; height: 34px; border: 0; border-radius: 50%; color: #3a3a3c; background: rgba(242,242,247,.9); font-size: 16px; }
.modal-img { width: 100%; max-height: 58vh; max-height: 58dvh; object-fit: contain; background: #f2f2f7; cursor: zoom-in; }
.modal-detail { min-height: 0; max-height: 42vh; max-height: 42dvh; overflow-y: auto; padding: 15px 17px 22px; font-size: 14px; line-height: 1.65; -webkit-overflow-scrolling: touch; }
.modal-detail table { width: 100%; border-collapse: collapse; }
.modal-detail td { padding: 6px; vertical-align: top; }
.modal-detail .label { width: 84px; color: #8e8e93; font-weight: 600; white-space: nowrap; }
.modal-detail .section { padding-top: 12px; color: #007aff; font-weight: 700; border-top: 1px solid #e5e5ea; }
.lightbox { position: fixed; inset: 0; z-index: 9999; display: flex; width: 100%; height: 100vh; height: 100dvh; align-items: center; justify-content: center; cursor: zoom-out; background: rgba(0,0,0,.93); }
.lightbox img { max-width: 96%; max-height: 90vh; max-height: 90dvh; object-fit: contain; border-radius: 10px; }
.lightbox-hint { position: fixed; right: 0; bottom: calc(18px + env(safe-area-inset-bottom)); left: 0; color: rgba(255,255,255,.6); font-size: 13px; text-align: center; pointer-events: none; }
.upload-progress { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.progress-track { flex: 1; height: 8px; overflow: hidden; border-radius: 99px; background: #e5e5ea; }
.progress-bar { width: 0%; height: 100%; border-radius: 99px; background: #007aff; transition: width .2s ease; }
.upload-progress span { min-width: 112px; color: #636366; font-size: 13px; text-align: right; }
.upload-progress[hidden] { display: none !important; }

@media (max-width: 700px) {
  .main-container { padding: 0 12px 36px; }
  .page-header { margin-right: -12px; margin-left: -12px; padding-right: 12px; padding-left: 12px; }
  .toolbar-row > label { width: 100%; }
  .toolbar-row > input, .toolbar-row > select { flex: 1; width: 100%; }
  .toolbar-row > .btn { flex: 1; }
  input:not([type="checkbox"]), select { min-height: 44px; font-size: 16px; }
  .btn { min-height: 44px; padding: 11px 17px; }
  .image-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
  .admin-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .admin-panel { padding: 15px; }
  .admin-actions .btn { min-height: 44px; padding: 10px 12px; }
  .modal-overlay { padding: 0; }
  .modal-box { max-height: 100vh; max-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
  .modal-close { width: 44px; height: 44px; }
}
@media (min-width: 900px) { .image-grid { grid-template-columns: repeat(5, minmax(0,1fr)); } }

/* 补齐动态元素样式 */
.item-check { width: 20px; height: 20px; accent-color: #007aff; position: absolute; top: 8px; left: 8px; z-index: 2; margin: 0; opacity: 0; pointer-events: none; }
.upload-code { padding: 7px 10px; border: 1px solid #d1d1d6; border-radius: 10px; font-size: 14px; background: #fff; color: #1c1c1e; }
.upload-code:focus { border-color: #007aff; outline: none; box-shadow: 0 0 0 3px rgba(0,122,255,.15); }

/* 后台卡片选中态：蓝描边 + 对勾角标 */
.admin-card.selected { border-color: #007aff; box-shadow: 0 0 0 1.5px #007aff, 0 4px 14px rgba(0,122,255,.18); }
.admin-card.selected::after { content: '✓'; position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; background: #007aff; color: #fff; font-size: 13px; font-weight: 700; line-height: 22px; text-align: center; z-index: 3; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.admin-card { position: relative; }

/* 修复：hidden 属性被元素 display 样式覆盖（批量栏/按钮/进度条等一律生效） */
[hidden] { display: none !important; }
