:root {
  --bg: #f2efe7;
  --panel: #fffdf8;
  --ink: #1a1c18;
  --muted: #6a7068;
  --line: #d9d0c3;
  --brand: #194f4a;
  --brand-2: #cc6b2c;
  --danger: #b14128;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(204, 107, 44, 0.12), transparent 30%),
    linear-gradient(180deg, #f6f1e7 0%, var(--bg) 45%, #ece6d9 100%);
  color: var(--ink);
}
a { color: inherit; text-decoration: none; }
.site-header, .page-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.site-header {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 24px 0 18px;
}
.brand { font-size: 28px; font-weight: 800; color: var(--brand); }
.subtle { color: var(--muted); }
.top-nav { display: flex; gap: 16px; font-weight: 600; }
.page-shell { padding-bottom: 48px; }
body:has(.scan-shell) .page-shell { padding-top: 12px; padding-bottom: 16px; }
.scan-shell { display: flex; justify-content: center; }
.hero, .panel, .detail-header, .scan-card, .admin-device {
  background: rgba(255, 253, 248, 0.88);
  border: 1px solid rgba(217, 208, 195, 0.9);
  border-radius: 24px;
  box-shadow: 0 18px 60px rgba(67, 48, 25, 0.08);
}
.hero, .panel, .detail-header, .scan-card { padding: 24px; }
.hero h1, .detail-header h1, .scan-card h1, .admin-head h1 { margin-top: 0; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; margin-top: 24px; }
.holder-toolbar { margin-top: 24px; }
.holder-toolbar-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}
.holder-search-wrap {
  min-width: min(360px, 100%);
}
.holder-groups { display: grid; gap: 28px; margin-top: 24px; }
.compact-groups { gap: 14px; }
.holder-section {
  background: rgba(255, 253, 248, 0.88);
  border: 1px solid rgba(217, 208, 195, 0.9);
  border-radius: 24px;
  box-shadow: 0 18px 60px rgba(67, 48, 25, 0.08);
  padding: 24px;
}
.compact-section { padding: 12px 14px; }
.holder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.holder-header h1 { margin: 0 0 8px; }
.holder-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
.compact-list { gap: 6px; margin-top: 10px; }
.holder-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}
.compact-item { border-radius: 12px; }
.holder-item-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
}
.compact-link {
  gap: 10px;
  padding: 7px 10px;
}
.holder-item-main h2 {
  margin: 0 0 2px;
  font-size: 18px;
  line-height: 1.15;
}
.holder-item-main .asset-code {
  margin: 0;
  font-size: 12px;
  line-height: 1.1;
}
.holder-item-meta {
  text-align: right;
}
.holder-item-meta .meta {
  margin: 0 0 2px;
  font-size: 12px;
  line-height: 1.15;
}
.holder-item-meta .meta:last-child {
  margin-bottom: 0;
}
.device-card { background: var(--panel); border-radius: 24px; border: 1px solid var(--line); overflow: hidden; }
.card-link { display: block; padding: 18px; }
.qr-preview { width: 100%; aspect-ratio: 1/1; object-fit: contain; background: #fff; border-radius: 18px; border: 1px solid var(--line); }
.qr-preview.large { width: 220px; }
.asset-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--brand-2); word-break: break-all; overflow-wrap: break-word; }
.scan-title {
  font-size: clamp(20px, 6vw, 28px);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.2;
  margin: 4px 0 4px;
  letter-spacing: 0.5px;
  word-break: break-all;
  overflow-wrap: break-word;
}
.scan-asset-code { margin: 2px 0 0; font-size: 13px; word-break: break-all; overflow-wrap: break-word; }
.scan-device-name { margin: 4px 0 0; color: var(--ink); font-weight: 600; font-size: 15px; word-break: break-all; overflow-wrap: break-word; }
.scan-card { padding: 20px 18px; max-width: 560px; width: 100%; }
.scan-card .eyebrow { margin: 0 0 4px; font-size: 12px; }
.scan-card p { margin: 6px 0; }
.scan-card .meta { margin: 4px 0 8px; font-size: 13px; }
.scan-card .first-bind-notice { margin: 10px 0; padding: 10px 14px; font-size: 13px; }
.scan-card .first-bind-notice p { margin: 0; }
.scan-card .scan-status { margin-top: 10px; }
.scan-card .auth-channel-actions { display: grid; gap: 8px; margin-top: 10px; }
.scan-card .scan-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.uuid-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  margin: 4px 0 0;
  word-break: break-all;
  overflow-wrap: break-word;
  max-width: 100%;
}
.uuid-code {
  margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  color: var(--brand);
}
.uuid-label { color: var(--muted); font-size: 12px; }
.uuid-value { font-weight: 600; }
.uuid-suffix {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  margin-left: 8px;
}
.code-source { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.source-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.source-legacy { background: #e8e4dc; color: var(--muted); }
.source-system { background: #d4edda; color: #155724; }
.source-ocr { background: #cce5ff; color: #004085; }
.source-manual { background: #fff3cd; color: #856404; }
.holder { font-size: 17px; }
.meta { color: var(--muted); }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px; border: 1px solid var(--brand);
  padding: 11px 18px; font-weight: 700; background: transparent; cursor: pointer;
  color: var(--brand);
  font-size: 15px;
  line-height: 1.2;
}
.button-primary { background: var(--brand); color: #fff; }
.button-ghost { border-color: var(--line); color: var(--muted); }
.button-danger { border-color: var(--danger); color: var(--danger); }
.button-disabled,
.button:disabled {
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}
.detail-header { display: flex; justify-content: space-between; gap: 24px; align-items: center; margin-top: 24px; }
.detail-qr { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.history-block { margin-top: 24px; }
.history-table { width: 100%; border-collapse: collapse; background: var(--panel); overflow: hidden; border-radius: 20px; }
.history-table th, .history-table td { padding: 14px; border-bottom: 1px solid var(--line); text-align: left; }
.notify-ok { color: var(--brand); font-weight: 700; }
.notify-fail { color: var(--danger); font-weight: 700; }
.scan-shell { display: grid; place-items: center; min-height: 70vh; }
.scan-card { max-width: 560px; width: 100%; }
.eyebrow { color: var(--brand-2); text-transform: uppercase; letter-spacing: 0.12em; font-size: 13px; }
.auth-channel-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.scan-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.result-box { min-height: 24px; margin-top: 18px; font-weight: 700; }
.result-box.success { color: var(--brand); }
.result-box.error, .error { color: var(--danger); }
.admin-login { display: grid; place-items: center; min-height: 70vh; }
.form-stack, .grid-form, .row-form { display: grid; gap: 14px; }
.grid-form { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: end; }
.grid-form.compact { margin-top: 12px; }
label { display: grid; gap: 8px; font-weight: 600; }
input, button, textarea {
  font: inherit;
}
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
}
.admin-head, .admin-head-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-head-actions { justify-content: flex-end; }
.admin-list { display: grid; gap: 18px; }
.admin-device { display: grid; grid-template-columns: 1.3fr 180px 1.2fr auto; gap: 18px; padding: 18px; margin-top: 18px; align-items: start; }
.admin-qr { width: 180px; border-radius: 16px; background: #fff; border: 1px solid var(--line); }
.ocr-result {
  white-space: pre-wrap; background: #f7f1e8; border: 1px dashed var(--line);
  border-radius: 16px; padding: 12px; min-height: 72px;
}
.empty { margin-top: 24px; color: var(--muted); }
.hidden { display: none !important; }
.no-scroll { overflow: hidden; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 12px; }
.photo-grid .photo-item { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.photo-grid .photo-item img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 10px; background: #eee; }
.photo-trigger { padding: 0; border: 0; background: transparent; cursor: pointer; display: block; }
.photo-trigger img { transition: transform 0.15s ease; }
.photo-trigger:hover img { transform: scale(1.02); }
.photo-lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.88); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px; }
.photo-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45); }
.photo-lightbox-close { position: absolute; top: 16px; right: 20px; font-size: 32px; line-height: 1; background: rgba(255, 255, 255, 0.1); color: #fff; border: 0; border-radius: 999px; width: 44px; height: 44px; cursor: pointer; }
.photo-lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }
.photo-grid .photo-item p { margin: 0; font-size: 12px; }
.photo-grid .photo-item .photo-note { font-size: 13px; color: var(--ink); word-break: break-all; }
.photo-grid .photo-item form { margin: 0; }
#add-photo-form { margin-top: 10px; display: grid; gap: 8px; }
.scan-photo-section { margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 14px; background: rgba(255,255,255,0.6); }
.scan-photo-section summary { cursor: pointer; font-weight: 600; }
.scan-photo-section form { display: grid; gap: 8px; margin-top: 10px; }
.reset-log-list { display: grid; gap: 12px; margin-top: 12px; }
.reset-log-item { display: flex; justify-content: space-between; gap: 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: #fff; align-items: center; flex-wrap: wrap; }
.reset-log-item.is-reverted { opacity: 0.55; }
.reset-log-main { flex: 1; min-width: 260px; }
.reset-log-title { margin: 0 0 4px; font-size: 15px; }
.reset-log-item p { margin: 2px 0; }
.reset-log-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.admin-list-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.admin-list-head h2 { margin: 0; }
.admin-list-head h2 .subtle { font-weight: 500; font-size: 14px; margin-left: 6px; }
.admin-search-wrap { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 240px; max-width: 420px; font-weight: 400; }
.admin-search-wrap input { height: 40px; }
.admin-device-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.admin-device-actions form { display: flex; flex-direction: column; gap: 6px; }
.inline-check { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 12px; color: var(--muted); }
.inline-check input { width: auto; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eee; color: #555; margin-right: 6px; }
.tag-feishu { background: #e6f2ff; color: #1464d2; }
.tag-dingtalk { background: #e6f7ee; color: #188a52; }
.first-bind-notice {
  background: rgba(25, 79, 74, 0.08);
  border: 1px solid var(--brand);
  border-radius: 16px;
  padding: 14px 18px;
  margin-top: 16px;
}
.first-bind-notice p {
  margin: 0;
  color: var(--brand);
  font-weight: 600;
}
.button-secondary {
  background: var(--brand-2);
  color: #fff;
  border-color: var(--brand-2);
}
.button-small {
  padding: 7px 14px;
  font-size: 13px;
}
.qrcode-manage { margin-top: 24px; }
.qrcode-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.qrcode-header h1 { margin: 0; }
.qrcode-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--brand);
}
.stat-label {
  font-size: 14px;
  color: var(--muted);
}
.stat-used .stat-value { color: var(--brand-2); }
.stat-unused .stat-value { color: var(--brand); }
.batch-create-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 24px;
}
.batch-create-section h3 {
  margin: 0 0 14px;
  font-size: 16px;
}
.batch-create-form {
  display: flex;
  align-items: end;
  gap: 14px;
  flex-wrap: wrap;
}
.batch-input-group {
  display: grid;
  gap: 6px;
  min-width: 180px;
}
.batch-input-group label {
  font-size: 13px;
  font-weight: 600;
}
.batch-input-actions {
  display: flex;
  align-items: end;
}
.batch-message {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
}
.batch-message.error {
  color: var(--danger);
  background: rgba(177, 65, 40, 0.08);
  border: 1px solid rgba(177, 65, 40, 0.2);
}
.batch-message.warning {
  color: var(--brand-2);
  background: rgba(204, 107, 44, 0.08);
  border: 1px solid rgba(204, 107, 44, 0.2);
}
.qrcode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}
.qrcode-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.qrcode-image {
  display: grid;
  place-items: center;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 12px;
}
.qrcode-image img {
  width: 100%;
  max-width: 200px;
  aspect-ratio: 1/1;
  object-fit: contain;
}
.qrcode-info { display: grid; gap: 6px; }
.qrcode-info .asset-code { margin: 0; font-size: 14px; }
.qrcode-info .device-name { margin: 0; font-weight: 700; font-size: 16px; }
.qrcode-info .holder { margin: 0; font-size: 14px; }
.qrcode-info .type { margin: 0; font-size: 12px; color: var(--muted); }
.qrcode-card-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  max-width: 480px;
  width: 90%;
}
.modal-content h3 { margin-top: 0; }
.modal-content .success { color: var(--brand); font-weight: 700; }
.modal-content .error { color: var(--danger); font-weight: 700; }
.modal-content ul { padding-left: 20px; }
.detail-photos { margin-top: 24px; }
.detail-photos h2 { margin-top: 0; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.photo-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
  overflow: hidden;
  max-width: 200px;
}
.photo-item img {
  width: 100%;
  height: 160px;
  border-radius: 12px;
  object-fit: cover;
  display: block;
  margin: 0 auto;
}
.photo-item p {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .site-header, .detail-header, .admin-head { flex-direction: column; align-items: flex-start; }
  .holder-toolbar-head, .holder-header, .holder-item-link { flex-direction: column; align-items: flex-start; }
  .holder-item-meta { text-align: left; }
  .admin-device { grid-template-columns: 1fr; }
  .admin-qr, .qr-preview.large { width: 100%; max-width: 220px; }
  .stats-panel { grid-template-columns: 1fr; }
  .batch-create-form { flex-direction: column; align-items: stretch; }
  .batch-input-group { min-width: 100%; }
  .batch-input-actions { width: 100%; }
  .batch-input-actions .button { width: 100%; }
}
