* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #1a5276;
  --primary-light: #2980b9;
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: pan-y;
}

.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  padding: 16px 24px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.header h1 { font-size: 20px; font-weight: 600; }
.header p { font-size: 12px; opacity: 0.85; }
.header-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

@media (min-width: 769px) {
  .header-inner { padding: 0 100px; }
  .header-btns { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-light);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .icon { font-size: 20px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full-width { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; }
.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(41,128,185,0.15);
}
.form-group textarea { resize: vertical; min-height: 60px; }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}
.upload-zone:hover { border-color: var(--primary-light); background: #f7faff; }
.upload-zone .icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone .text { font-size: 14px; color: var(--text-light); }
.upload-zone .hint { font-size: 12px; color: #bdc3c7; margin-top: 4px; }
.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.preview-img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  margin-top: 12px;
  display: none;
  cursor: zoom-in;
}
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  cursor: zoom-out;
  padding: 24px;
}
.lightbox.show { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
.ocr-status {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  display: none;
  align-items: center;
  gap: 8px;
}
.ocr-status.show { display: flex; }
.ocr-status.loading { background: #f0f7ff; color: var(--primary-light); }
.ocr-status.success { background: #eafaf1; color: var(--success); }
.ocr-status.error { background: #fdedec; color: var(--danger); }
.ocr-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 4px 12px rgba(26,82,118,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(26,82,118,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: #ecf0f1;
  color: var(--text);
}
.btn-secondary:hover { background: #d5dbdb; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; }

.loading {
  display: none;
  text-align: center;
  padding: 32px;
}
.loading.show { display: block; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid #ecf0f1;
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results { display: none; }
.results.show { display: block; }
.result-header {
  text-align: center;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.result-header.pass { background: #eafaf1; border: 2px solid var(--success); }
.result-header.fail { background: #fdedec; border: 2px solid var(--danger); }
.result-header .emoji { font-size: 48px; display: block; margin-bottom: 8px; }
.result-header .title { font-size: 20px; font-weight: 700; }
.result-header.pass .title { color: var(--success); }
.result-header.fail .title { color: var(--danger); }
.result-header .stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-light);
}

.audit-item {
  padding: 14px 16px;
  border-radius: 10px;
  margin-bottom: 10px;
  border-left: 4px solid;
  transition: all 0.2s;
}
.audit-item:hover { transform: translateX(2px); }
.audit-item.pass { background: #f0faf4; border-color: var(--success); }
.audit-item.fail { background: #fef0ef; border-color: var(--danger); }
.audit-item .item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.audit-item.pass .item-header { color: var(--success); }
.audit-item.fail .item-header { color: var(--danger); }
.audit-item .item-reason {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text);
  padding-left: 28px;
}
.audit-item .item-suggestion {
  margin-top: 6px;
  font-size: 12px;
  color: var(--primary-light);
  padding-left: 28px;
  background: #f7faff;
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-block;
}

.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.tab-btn {
  padding: 10px 16px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-light);
}

@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .header { padding: 12px 16px; }
  .header h1 { font-size: 17px; }
  .header p { font-size: 11px; }
  .container { padding: 12px; }
  .card { padding: 14px; }
  .btn-row { flex-direction: column; }
  .btn-row .btn { width: 100%; }
  .ocr-btn-row { flex-direction: row; }
  .ocr-btn-row .btn { width: 50%; }
  .tab-btn { padding: 8px 12px; font-size: 13px; }
  .result-header .stats { flex-direction: column; gap: 8px; }
  .audit-item .item-reason,
  .audit-item .item-suggestion { padding-left: 0; }
}

@media (max-width: 480px) {
  .header h1 { font-size: 15px; }
  .card-title { font-size: 14px; }
  .btn { font-size: 14px; padding: 10px 16px; }
}

.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-box h2 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 24px;
  font-size: 20px;
}
.login-box .form-group { margin-bottom: 16px; }
.login-box .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 6px;
}
.login-box .form-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.login-box .form-group input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(41,128,185,0.15);
}
.login-box .login-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.login-box .login-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(26,82,118,0.3); }
.login-box .login-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  display: none;
}
.login-error.show { display: block; }

.logout-btn,
#admin-rules-btn,
#admin-history-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.logout-btn:hover,
#admin-rules-btn:hover,
#admin-history-btn:hover { background: rgba(255,255,255,0.3); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.thumb-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
}
.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb-status {
  position: absolute;
  bottom: 2px;
  right: 2px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
}

.merge-progress {
  margin-top: 12px;
}
.progress-text {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 6px;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary-light);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

.field-conflict {
  border-color: var(--warning) !important;
  box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.2) !important;
  background: #fff9e6 !important;
}

.conflict-compare {
  margin-top: 6px;
  padding: 8px 10px;
  background: #fef9e7;
  border: 1px solid #f5d76e;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.6;
}
.conflict-selected {
  color: #27ae60;
  font-weight: 500;
}
.conflict-alt {
  color: #7f8c8d;
  margin-top: 2px;
}

/* Modal Dialog */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: white; border-radius: 12px; padding: 24px;
  width: 90%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-box h3 { margin: 0 0 20px; font-size: 18px; color: #1a5276; }
.modal-box .form-group { margin-bottom: 16px; }
.modal-box .form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: #555; }
.modal-box .form-group input {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 14px; box-sizing: border-box;
}
.modal-box .form-group input:focus { border-color: #1a5276; outline: none; }
.modal-error, .modal-success {
  padding: 10px; border-radius: 6px; margin-bottom: 16px;
  font-size: 13px; display: none;
}
.modal-error { background: #fee; color: #c33; }
.modal-success { background: #efe; color: #363; }
.modal-error.show, .modal-success.show { display: block; }
.modal-btns { display: flex; gap: 12px; justify-content: flex-end; }
.modal-btns button {
  padding: 10px 20px; border-radius: 6px; font-size: 14px; cursor: pointer; border: none;
}
.modal-btns .btn-primary { background: #1a5276; color: white; }
.modal-btns .btn-primary:hover { background: #154360; }
.modal-btns .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.modal-btns .btn-secondary { background: #eee; color: #333; }
.modal-btns .btn-secondary:hover { background: #ddd; }

/* Header Button */
.header-btn {
  padding: 6px 12px; background: #1a5276; color: white;
  border: none; border-radius: 4px; font-size: 13px; cursor: pointer;
}
.header-btn:hover { background: #154360; }
