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

/* ── CSS Variables ── */
:root {
  /* Colors */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-primary-lighter: #dbeafe;
  --color-text: #333;
  --color-text-dark: #1a1a1a;
  --color-text-secondary: #888;
  --color-text-muted: #bbb;
  --color-bg: #f5f5f5;
  --color-bg-card: #fff;
  --color-border: #d0d0d0;
  --color-border-light: #e8e8e8;
  --color-success: #16a34a;
  --color-warning: #f59e0b;
  --color-error: #dc2626;
  --color-error-bg: #fef2f2;
  --color-error-border: #fecaca;
  --color-notice-bg: #eff6ff;
  --color-notice-border: #bfdbfe;
  --color-upload-secondary: #999;
  --color-overlay: rgba(0, 0, 0, 0.5);
  --color-shadow: rgba(0, 0, 0, 0.1);

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 36px;
  --spacing-xxl: 40px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 12px;

  /* Font sizes */
  --font-xs: 13px;
  --font-sm: 14px;
  --font-md: 15px;
  --font-lg: 17px;
  --font-xl: 20px;
  --font-xxl: 28px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 40px 20px;
}

.container {
  width: 100%;
  max-width: 960px;
}

header {
  text-align: center;
  margin-bottom: 36px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text-dark);
  margin-bottom: 8px;
}

header .subtitle {
  font-size: 15px;
  color: #888;
}

/* Upload Section */
.upload-section {
  position: relative;
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  padding-top: 48px;
}

.upload-section > .btn-new-report {
  position: absolute;
  top: 0;
  right: 0;
}

.upload-box {
  flex: 1;
  border: 2px dashed var(--color-border);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: #fff;
}

.upload-box:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.upload-box.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-lighter);
}

.upload-box.has-file {
  border-color: var(--color-primary);
  border-style: solid;
  background: var(--color-primary-light);
}

.upload-box.optional {
  border-color: #e0e0e0;
}

.btn-new-report {
  border: 1px solid var(--color-primary);
  background: #fff;
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.4;
}

.btn-new-report:hover {
  background: var(--color-primary-light);
}

.btn-new-report:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.upload-icon {
  margin-bottom: 12px;
}

.upload-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upload-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.upload-hint {
  font-size: 12px;
  color: #aaa;
}

.file-name {
  margin-top: 10px;
  font-size: 13px;
  color: var(--color-primary);
  font-weight: 500;
  word-break: break-all;
}

.patent-verify-summary {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.6;
  text-align: left;
}

.patent-verify-loading {
  color: var(--color-primary);
  padding: 8px 0;
  font-weight: 500;
}

.patent-verify-error {
  color: #c0392b;
  padding: 8px 0;
}

/* Generate Button */
.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  background: var(--color-primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 24px;
}

.btn-generate:hover:not(:disabled) {
  background: #357abd;
}

.btn-generate:disabled {
  background: #c4cdd5;
  cursor: not-allowed;
}

.continue-generate-wrap {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e8e8e8;
}

.btn-continue-generate {
  background: #27ae60;
  margin-bottom: 8px;
}

.btn-continue-generate:hover:not(:disabled) {
  background: #219a52;
}

.continue-generate-hint {
  margin: 0;
  font-size: 13px;
  color: #666;
  text-align: center;
  line-height: 1.5;
}

/* Spinner */
.btn-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Progress Area — 禁止内部滚动，内容撑开整页 */
.progress-area {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  overflow: visible !important;
  max-height: none !important;
  height: auto !important;
}

#progressArea .progress-steps,
#progressArea .match-section,
#progressArea .match-list,
#progressArea .warning-list {
  overflow: visible !important;
  max-height: none !important;
  height: auto !important;
}

/* Step list */
.progress-steps {
  overflow: visible !important;
  max-height: none !important;
  height: auto !important;
}

.progress-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.progress-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.progress-subtitle {
  font-size: 13px;
  color: #888;
}

.progress-subtitle-active {
  color: var(--color-primary);
}

.progress-subtitle-error {
  color: #e74c3c;
  font-weight: 600;
}

.progress-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.progress-subtitle {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-primary);
  animation: progress-pulse 2s ease-in-out infinite;
}

@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.btn-cancel {
  padding: 6px 16px;
  font-size: 13px;
  color: #e74c3c;
  background: #fff;
  border: 1px solid #e74c3c;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-cancel:hover {
  background: #fdf0f0;
}

.btn-cancel:disabled {
  color: #ccc;
  border-color: #ccc;
  cursor: not-allowed;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.step-row.step-running {
  background: var(--color-primary-light);
}

.step-row.step-done {
  opacity: 0.7;
}

.step-row.step-error {
  background: #fff0f0;
}

.step-row.step-cancelled {
  opacity: 0.35;
}

.step-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.step-name {
  font-size: 14px;
  color: #555;
  flex: 1;
}

.step-row.step-running .step-name {
  color: var(--color-primary);
  font-weight: 600;
}

.step-row.step-done .step-name {
  color: #27ae60;
}

.step-row.step-error .step-name {
  color: #e74c3c;
  font-weight: 600;
}

.step-msg {
  font-size: 12px;
  color: #999;
  max-width: 45%;
  text-align: right;
  word-break: break-word;
}

.step-msg-error {
  color: #e74c3c;
  font-weight: 500;
}

.step-msg-ok {
  color: #666;
}

.step-msg-warn {
  color: #9ca3af;
}

.step-row.step-running.step-stuck {
  background: #fff8e6;
  outline: 1px dashed #f0ad4e;
}

/* Error Box */
.error-box {
  background: #fff0f0;
  border: 1px solid #ffd0d0;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.completion-notice {
  background: #fff8e6;
  border: 1px solid #f0c36d;
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 12px;
}

.completion-notice-text {
  font-size: 14px;
  line-height: 1.6;
  color: #9a6700;
  font-weight: 500;
}

.error-text {
  font-size: 14px;
  color: #c0392b;
}

/* Download Area */
.download-area {
  text-align: center;
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: #27ae60;
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-download:hover {
  background: #219a52;
}

/* Innovation match results */
.match-section {
  margin-top: 14px;
}

.match-section-title {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin-bottom: 8px;
}

.match-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: visible;
  max-height: none;
}

.match-item {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 8px;
}

.match-item-clickable {
  cursor: pointer;
  transition: filter 0.15s ease;
}

.match-item-clickable:hover {
  filter: brightness(0.98);
}

.match-item.open {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.match-item-head {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.match-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-item-status {
  flex-shrink: 0;
  font-weight: 600;
  white-space: nowrap;
}

.match-item-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(0, 0, 0, 0.12);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.match-matched {
  color: #1e6b3a;
  background: #edf9f0;
  border: 1px solid #b8e6c8;
}

.match-unmatched {
  color: #8b3a3a;
  background: #fdf0f0;
  border: 1px solid #f0c8c8;
}

.match-review {
  color: #8a6d1a;
  background: #fdf6e3;
  border: 1px solid #f0dfa8;
}

.match-redirect {
  color: #1a5276;
  background: #edf4fa;
  border: 1px solid #b8d4f0;
}

/* Warnings (legacy / extra notices) */
.warning-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.warning-item {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #8a6d1a;
  background: #fdf6e3;
  border: 1px solid #f0dfa8;
  border-radius: 8px;
  white-space: pre-wrap;
}

.warning-item-muted {
  color: #9ca3af;
  background: #f5f5f5;
  border-color: #e5e7eb;
}

/* Auth */
.auth-container {
  max-width: 420px;
}

.auth-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: #f0f2f5;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.auth-tab.active {
  background: var(--color-primary);
  color: #fff;
}

.auth-form label {
  display: block;
  margin-bottom: 14px;
  font-size: 14px;
  color: #555;
}

.auth-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 15px;
}

.auth-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: #888;
  line-height: 1.4;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  text-align: left;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #666;
  flex-shrink: 0;
}

.btn-link {
  border: none;
  background: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-step-skip-ocr {
  flex-shrink: 0;
  border: 1px solid var(--color-primary);
  background: #fff;
  color: var(--color-primary);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-step-skip-ocr:hover {
  background: var(--color-primary-light);
}

.notice-box {
  background: #fff8e6;
  border: 1px solid #f5d78e;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  color: #8a6d1d;
  font-size: 14px;
}

.usage-info {
  color: #888;
  font-size: 13px;
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
  color: #666;
}

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid #e8eaed;
  border-radius: 10px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #eef0f2;
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  background: #f8f9fb;
  font-weight: 600;
  color: #444;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.status-pending { background: #fff3cd; color: #856404; }
.status-approved { background: #d4edda; color: #155724; }
.status-rejected { background: #f8d7da; color: #721c24; }

.badge-admin {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--color-primary-lighter);
  color: #1a56db;
  font-size: 11px;
}

.limit-input {
  width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-action,
.btn-secondary {
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.btn-action:hover,
.btn-secondary:hover {
  background: var(--color-bg);
}

.btn-approve { color: #155724; border-color: #b7dfc3; }
.btn-reject { color: #721c24; border-color: #f1b8be; }
.btn-save { color: #1a56db; border-color: #b8cff7; }

.job-history {
  margin-top: 32px;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  padding: 16px 18px;
  background: #fafbfc;
}

.job-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.job-history-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.job-history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 超过 5 条报告时在列表区域内滚动 */
.job-history-list--scroll {
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.job-history-list--scroll::-webkit-scrollbar {
  width: 6px;
}

.job-history-list--scroll::-webkit-scrollbar-thumb {
  background: #c5cdd8;
  border-radius: 3px;
}

.job-history-empty {
  color: #888;
  font-size: 14px;
  padding: 8px 0;
}

.job-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #eef0f2;
  border-radius: 8px;
}

.job-history-main {
  flex: 1;
  min-width: 0;
}

.job-history-main--clickable {
  cursor: pointer;
}

.job-history-main--clickable:hover .job-history-name {
  color: var(--color-primary);
}

.job-history-name {
  font-size: 14px;
  color: var(--color-text);
  word-break: break-all;
}

.job-history-meta {
  font-size: 12px;
  color: #888;
  margin-top: 4px;
}

.job-history-error {
  font-size: 12px;
  color: #c0392b;
  margin-top: 6px;
  line-height: 1.4;
  word-break: break-word;
}

.job-history-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-job-download,
.btn-job-view,
.btn-job-delete {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  border: none;
}

.btn-job-download {
  background: var(--color-primary);
  color: #fff;
}

.btn-job-download:hover {
  background: var(--color-primary-hover);
}

.btn-job-view {
  background: #eef4fc;
  color: var(--color-primary);
}

.btn-job-view:hover {
  background: #dceaf8;
}

.btn-job-delete {
  background: #fff;
  color: #c0392b;
  border: 1px solid #e8b4b4;
}

.btn-job-delete:hover:not(:disabled) {
  background: #fdf0f0;
}

.btn-job-delete:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.job-status-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
}

.job-status-pending { background: #fff3cd; color: #856404; }
.job-status-running { background: var(--color-primary-lighter); color: #1a56db; }
.job-status-done { background: #d4edda; color: #155724; }
.job-status-error { background: #f8d7da; color: #721c24; }
.job-status-cancelled { background: #eee; color: #666; }

/* Contract manual fallback */
.contract-manual {
  margin-top: 20px;
  margin-bottom: 24px;
  padding: 20px;
  background: #fff;
  border: 1px solid #e0e6ef;
  border-radius: 12px;
}

.contract-manual-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-dark);
  margin-bottom: 6px;
}

.contract-manual-hint {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

.manual-section-hint {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 10px;
  line-height: 1.5;
}

.contract-att-panel {
  border-top: 1px solid #eef1f5;
  padding-top: 16px;
  margin-top: 16px;
}

.contract-att-panel:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.contract-att-panel-ok {
  padding-bottom: 4px;
}

.contract-att-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.contract-att-header .contract-att-title {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
  word-break: break-all;
}

.contract-att-badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.contract-att-badge:hover {
  filter: brightness(0.97);
}

.contract-att-badge.ok {
  background: #d4edda;
  color: #155724;
}

.contract-att-badge.warn {
  background: #fff3cd;
  color: #856404;
}

.contract-att-ok-summary {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.contract-att-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.contract-att-warn {
  font-size: 12px;
  color: var(--color-warning);
  margin-bottom: 10px;
}

.contract-att-page-summary {
  font-size: 12px;
  color: var(--color-text-muted);
  cursor: pointer;
  line-height: 1.5;
}

.contract-att-page-summary:hover {
  color: #0ea5e9;
}

.page-lightbox-ocr-hint {
  font-size: 12px;
  color: #0369a1;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0 4px;
  line-height: 1.5;
}

.contract-mode-btn.has-ocr {
  border-color: #7dd3fc;
}

.contract-mode-btn.page-selected:not(.active) {
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.page-lightbox-img-wrap.picker-selectable {
  cursor: pointer;
}

.page-lightbox-img-wrap.picker-selectable.page-marked img {
  box-shadow: 0 0 0 3px var(--color-primary);
}

.ocr-fields-review-compact {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #e2e8f0;
}

.att-page-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.att-page-chip {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
  line-height: 1.4;
}

.att-page-chip:hover {
  background: #e0f2fe;
  border-color: #38bdf8;
  color: #0c4a6e;
}

.att-page-chip.missing {
  color: var(--color-warning);
  border-color: #fcd34d;
  background: #fffbeb;
}

.att-page-chip.active {
  background: #0ea5e9;
  border-color: #0284c7;
  color: #fff;
}

.ocr-pages-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.ocr-pages-bar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.ocr-field-page-jump {
  font-size: 11px;
  padding: 1px 7px;
  margin-right: 6px;
  border-radius: 999px;
  border: 1px solid #bae6fd;
  background: #f0f9ff;
  color: #0369a1;
  cursor: pointer;
}

.ocr-field-page-jump:hover {
  background: #e0f2fe;
  border-color: #38bdf8;
}

.ocr-fields-review {
  margin: 10px 0 14px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.ocr-fields-review-title {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 8px;
}

.ocr-fields-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ocr-field-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
}

.ocr-field-row.need-review {
  background: #fff7ed;
  border: 1px solid #fdba74;
}

.ocr-field-label {
  color: var(--color-text-muted);
}

.ocr-field-value {
  color: #0f172a;
  word-break: break-all;
}

.ocr-field-meta {
  color: #94a3b8;
  font-size: 11px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.ocr-field-locate {
  border: none;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.ocr-field-locate:hover {
  background: #bae6fd;
}

.ocr-field-edit {
  grid-column: 2 / -1;
  margin-top: 4px;
  padding: 4px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 13px;
}

.ocr-fields-save-btn {
  margin-top: 8px;
  font-size: 12px;
  padding: 4px 12px;
}

.manual-section {
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
}

.manual-section-title {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 10px;
}

.page-picker-label {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.page-picker-grid {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.page-thumb-btn {
  flex: 0 0 auto;
  width: 180px;
  padding: 6px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.page-thumb-btn:hover {
  border-color: #93c5fd;
}

.page-thumb-btn.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.page-thumb-zoom {
  position: relative;
  display: block;
  cursor: zoom-in;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.page-thumb-zoom img {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
}

.page-thumb-zoom-btn {
  display: inline-block;
  margin: 4px auto 2px;
  padding: 2px 10px;
  font-size: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
}

.page-thumb-zoom-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.page-thumb-ocr-btn {
  display: inline-block;
  margin: 2px auto;
  padding: 2px 10px;
  font-size: 11px;
  border: 1px solid #bae6fd;
  border-radius: 4px;
  background: #f0f9ff;
  color: #0369a1;
  cursor: pointer;
}

.page-thumb-ocr-btn:hover {
  background: #e0f2fe;
  border-color: #7dd3fc;
}

.page-thumb-zoom-icon {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 20px;
  height: 20px;
  line-height: 20px;
  font-size: 11px;
  background: var(--color-overlay);
  color: #fff;
  border-radius: 4px;
  pointer-events: none;
}

.page-thumb-label {
  display: block;
  font-size: 11px;
  color: #475569;
  cursor: pointer;
  padding: 2px 0;
}

.page-picker-feedback {
  font-size: 13px;
  margin: -4px 0 12px;
  padding: 6px 10px;
  border-radius: 6px;
}

.page-picker-feedback.ok,
.field-feedback.ok {
  color: var(--color-success);
  background: #ecfdf5;
}

.field-feedback {
  display: block;
  font-size: 12px;
  margin-top: 6px;
}

.manual-dates label {
  display: block;
}

.page-thumb-btn.selected .page-thumb-label {
  color: var(--color-primary);
  font-weight: 600;
}

.page-thumb-btn.selected .page-thumb-label::after {
  content: ' ✓';
}

body.lightbox-open {
  overflow: hidden;
}

.page-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.page-lightbox[hidden] {
  display: none !important;
}

.page-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.page-lightbox-dialog {
  position: relative;
  z-index: 1;
  width: min(920px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.page-lightbox.picker-mode .page-lightbox-dialog {
  width: min(1280px, 98vw);
  max-height: 96vh;
}

.page-lightbox-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.page-lightbox-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page-lightbox-patent-ref {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid #e2e8f0;
  padding: 12px 10px;
  overflow-y: auto;
  background: #f8fafc;
}

.page-lightbox-patent-ref-title {
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
}

.page-lightbox-patent-ref-hint {
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.page-lightbox-patent-marked {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
  font-size: 12px;
  color: #475569;
  line-height: 1.45;
}

.page-lightbox-picker-fill {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-fill-title {
  font-size: 12px;
  font-weight: 700;
  color: #1e293b;
}

.picker-fill-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.picker-fill-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.picker-fill-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  color: #1e293b;
  background: #fff;
}

.picker-fill-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.15);
}

.picker-sign-date-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.picker-sign-date-row .picker-date-part {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
}

.picker-sign-date-sep {
  color: #94a3b8;
  font-size: 12px;
  flex-shrink: 0;
}

.picker-fill-readonly {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.picker-fill-label {
  font-size: 11px;
  color: var(--color-text-muted);
}

.picker-fill-value {
  font-size: 12px;
  color: #1e293b;
  font-weight: 600;
  line-height: 1.4;
}

.picker-page-slot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.picker-page-chip {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e293b;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.35;
}

.picker-page-chip:hover {
  border-color: var(--color-primary);
  background: #eef5fc;
}

.picker-page-chip.active {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

.picker-page-chip.missing {
  color: #94a3b8;
  border-style: dashed;
  font-weight: 500;
}

.picker-patent-marked {
  margin-top: 4px;
  font-size: 11px;
  color: #475569;
  line-height: 1.45;
}

.picker-patent-verify-wrap {
  margin: 10px 0;
  padding: 10px 0;
  border-top: 1px dashed #cbd5e1;
  border-bottom: 1px dashed #cbd5e1;
}

.picker-patent-match-banner {
  font-size: 11px;
  padding: 6px 8px;
  margin-bottom: 8px;
}

.picker-patent-verify-check {
  font-size: 11px;
  line-height: 1.45;
  align-items: flex-start;
}

.picker-patent-verify-check input {
  margin-top: 2px;
  flex-shrink: 0;
}

.contract-patent-list-ref {
  max-height: min(52vh, 420px);
  overflow-y: auto;
}

.contract-patent-list-ref .contract-patent-list-item {
  align-items: flex-start;
  gap: 6px;
}

.patent-ref-idx {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  margin-top: 1px;
}

.patent-ref-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.patent-ref-title {
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.35;
  word-break: break-all;
}

.page-lightbox-close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 4;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.page-lightbox-close:hover {
  background: rgba(0, 0, 0, 0.7);
}

.page-lightbox-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--color-border-light);
  line-height: 0;
  padding: 8px;
}

.page-lightbox-img-wrap {
  position: relative;
  display: inline-block;
  width: fit-content;
  height: fit-content;
  max-width: 100%;
  line-height: 0;
  transform-origin: center center;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.page-lightbox-side-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 44px;
  height: 72px;
  border: none;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 4px;
  transition: background 0.15s;
}

.page-lightbox-side-nav:hover:not(:disabled) {
  background: rgba(15, 23, 42, 0.78);
}

.page-lightbox-side-nav:disabled {
  opacity: 0.25;
  cursor: default;
}

.page-lightbox-side-nav.prev {
  left: 8px;
}

.page-lightbox-side-nav.next {
  right: 8px;
}

.page-lightbox-stage img {
  display: block;
  max-width: min(920px, 96vw);
  max-height: min(58vh, 720px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: var(--color-border-light);
  cursor: zoom-in;
}

.page-lightbox.picker-mode .page-lightbox-stage img {
  max-width: min(1000px, 72vw);
  max-height: min(72vh, 920px);
}

.page-lightbox-img-wrap.rotated-90 img {
  max-width: min(72vh, 920px) !important;
  max-height: min(1000px, 72vw) !important;
}

.page-lightbox-stage.zoomed {
  position: fixed;
  inset: 0;
  z-index: 6;
  flex: none;
  max-height: none;
  overflow: auto;
  background: rgba(15, 23, 42, 0.96);
  padding: 52px 20px 20px;
  align-items: flex-start;
}

.page-lightbox.lightbox-zoomed .page-lightbox-dialog {
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.page-lightbox.lightbox-zoomed .page-lightbox-toolbar,
.page-lightbox.lightbox-zoomed .page-lightbox-footer {
  opacity: 0.15;
  transition: opacity 0.15s;
}

.page-lightbox.lightbox-zoomed .page-lightbox-toolbar:hover,
.page-lightbox.lightbox-zoomed .page-lightbox-footer:hover {
  opacity: 1;
}

.page-lightbox-stage.zoomed img {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  margin: 0 auto;
  cursor: zoom-out;
  background: #fff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.page-lightbox-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.page-lightbox-bbox {
  position: absolute;
  border: 2px solid #3b82f6;
  background: rgba(59, 130, 246, 0.12);
  box-sizing: border-box;
  border-radius: 2px;
}

.page-lightbox-bbox.need-review {
  border-color: #f97316;
  background: rgba(249, 115, 22, 0.18);
}

.page-lightbox-bbox.ocr-line {
  border-width: 1px;
  background: rgba(59, 130, 246, 0.06);
}

.page-lightbox-bbox.ocr-line.need-review {
  border-color: #fb923c;
  background: rgba(251, 146, 60, 0.1);
}

.page-lightbox-bbox.ocr-line .page-lightbox-bbox-label {
  display: none;
}

.page-lightbox-bbox-label {
  position: absolute;
  left: 0;
  top: -20px;
  max-width: 160px;
  padding: 1px 6px;
  font-size: 11px;
  line-height: 1.4;
  color: #fff;
  background: rgba(15, 23, 42, 0.82);
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-lightbox-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}

.page-lightbox.picker-mode .page-lightbox-footer {
  justify-content: center;
}

.page-lightbox-footer span {
  font-size: 14px;
  color: #334155;
  font-weight: 600;
}

.btn-lightbox-select {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--color-primary);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.btn-lightbox-select:hover {
  background: var(--color-primary-hover);
}

.manual-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.manual-dates label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #475569;
  min-width: 140px;
}

.manual-input {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
}

.contract-preview-loading,
.contract-preview-error {
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 8px 0;
}

.contract-preview-error {
  color: var(--color-error);
}

/* OCR progress step list */
.contract-ocr-progress {
  padding: 12px 0;
}
.ocr-step {
  font-size: 13px;
  color: #94a3b8;
  padding: 4px 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.ocr-step-icon {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}
.ocr-step-active {
  color: #1e293b;
  font-weight: 500;
}
.ocr-step-active .ocr-step-icon {
  color: #2563eb;
}
.ocr-step-done {
  color: #16a34a;
}
.ocr-step-done .ocr-step-icon {
  color: #16a34a;
}

/* Patent API status panel */
.patent-status-panel {
  margin-top: 12px;
  margin-bottom: 0;
  padding: 12px 0 0;
  background: transparent;
  border: none;
  border-top: 1px solid #eef2f7;
  border-radius: 0;
}

.progress-area .contract-manual {
  margin-top: 12px;
  margin-bottom: 0;
  padding: 12px 0 0;
  background: transparent;
  border: none;
  border-top: 1px solid #eef2f7;
  border-radius: 0;
}

/* Compact contract review */
.contract-att-compact {
  border: 1px solid #e8edf3;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #fafbfd;
}

.contract-att-compact-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.contract-att-compact-main {
  flex: 1;
  min-width: 200px;
}

.contract-att-compact-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-dark);
  display: block;
}

.contract-att-compact-pages {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
  display: block;
}

.contract-att-ocr-brief {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 6px;
  line-height: 1.45;
  display: block;
}

.contract-att-status-detail {
  margin-top: 6px;
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.45;
}

.btn-pick-pages {
  border: 1px solid var(--color-primary);
  background: #fff;
  color: var(--color-primary);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-pick-pages:hover {
  background: #eef5fc;
}

.contract-att-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #e2e8f0;
}

.contract-field {
  font-size: 13px;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 8px;
}

.contract-field .manual-input {
  min-width: 120px;
}

.contract-field-hint {
  display: block;
  width: 100%;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.contract-patent-verify-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e8edf3;
}

.contract-patent-verify-title {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 8px;
}

.contract-patent-compare-wrap {
  margin-bottom: 10px;
  overflow-x: auto;
}

.patent-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.patent-compare-table th,
.patent-compare-table td {
  border: 1px solid #e2e8f0;
  padding: 6px 8px;
  text-align: left;
}

.patent-compare-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
}

.patent-compare-table tr.match td:last-child {
  color: var(--color-success);
}

.patent-compare-table tr.miss td:last-child {
  color: var(--color-warning);
}

.contract-patent-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.contract-patent-list-item {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--color-border-light);
  display: flex;
  gap: 10px;
}

.contract-patent-list-item.ok .patent-an { color: var(--color-success); }
.contract-patent-list-item.warn .patent-an { color: var(--color-warning); }
.contract-patent-list-empty {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 8px;
}

.contract-patent-verify-check {
  font-size: 13px;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.contract-patent-match-banner {
  font-size: 13px;
  color: var(--color-success);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.contract-patent-verify-check.patent-matched {
  color: #334155;
}

.page-lightbox-toolbar {
  padding: 10px 16px 0;
  border-bottom: 1px solid #eef2f7;
  flex-shrink: 0;
}

.contract-picker-confirm {
  display: flex;
  justify-content: center;
  padding: 0 0 10px;
}

.btn-lightbox-select-main {
  min-width: 200px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
}

.contract-picker-modes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.contract-mode-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #475569;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.contract-mode-btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

.contract-picker-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  padding-bottom: 12px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.contract-picker-nav-sep {
  width: 1px;
  height: 22px;
  background: #e2e8f0;
  flex-shrink: 0;
}

.btn-lightbox-nav {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  min-width: 72px;
}

.btn-lightbox-nav:disabled {
  opacity: 0.4;
  cursor: default;
}

.patent-status-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--color-text-dark);
}

.patent-status-item {
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border-light);
}

.patent-status-item.ok { color: var(--color-success); }
.patent-status-item.warn { color: var(--color-warning); }

.patent-status-loading,
.patent-status-error {
  font-size: 13px;
  color: var(--color-text-muted);
}

.patent-status-error { color: var(--color-error); }

/* Invalid patent confirm modal */
.invalid-patent-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.invalid-patent-modal[hidden] { display: none !important; }

.invalid-patent-backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
}

.invalid-patent-dialog {
  position: relative;
  z-index: 1;
  width: min(480px, 96vw);
  background: #fff;
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 16px 48px var(--color-shadow);
}

.invalid-patent-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
}

.invalid-patent-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.invalid-patent-list {
  margin: 0 0 16px 18px;
  font-size: 13px;
  color: var(--color-warning);
}

.invalid-patent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-modal-cancel,
.btn-modal-confirm {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
}

.btn-modal-cancel {
  background: var(--color-border-light);
  color: #475569;
}

.btn-modal-confirm {
  background: var(--color-primary);
  color: #fff;
}

.btn-modal-confirm:hover { background: var(--color-primary-hover); }

/* Responsive */
@media (max-width: 520px) {
  .upload-section {
    flex-direction: column;
  }
  header h1 {
    font-size: 22px;
  }
}
