* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft JhengHei", "Segoe UI", sans-serif;
  background: #f5f6f8;
  color: #222;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1f2937;
  color: white;
  padding: 12px 24px;
}

.topbar .brand {
  font-weight: bold;
}

.topbar nav a {
  color: white;
  text-decoration: none;
  margin-left: 20px;
}

.topbar nav a:hover {
  text-decoration: underline;
}

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

.drop-zone {
  border: 2px dashed #9aa5b1;
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  background: white;
  cursor: pointer;
}

.drop-zone.dragover {
  border-color: #2563eb;
  background: #eef2ff;
}

.form-row {
  margin-top: 12px;
}

.form-row label {
  margin-right: 8px;
}

button {
  margin-top: 12px;
  padding: 8px 16px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

button:hover {
  background: #1d4ed8;
}

.progress-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-wrap {
  flex: 1;
  background: #e5e7eb;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.button-link {
  display: inline-block;
  margin-top: 12px;
  padding: 8px 16px;
  background: #2563eb;
  color: white;
  border-radius: 6px;
  font-size: 14px;
  text-decoration: none;
}

.button-link:hover {
  background: #1d4ed8;
}

.danger-btn-inline {
  margin-top: 0;
  padding: 4px 12px;
  background: #dc2626;
  font-size: 13px;
  white-space: nowrap;
}

.danger-btn-inline:hover {
  background: #b91c1c;
}

.duplicate-zone {
  margin-top: 32px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 8px;
}

.duplicate-zone h2 {
  margin-top: 0;
}

.duplicate-group {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
}

.duplicate-group p {
  margin: 0 0 6px 0;
  font-weight: bold;
}

.duplicate-group ul {
  margin: 0;
  padding-left: 20px;
}

.duplicate-group li {
  font-size: 13px;
  margin-bottom: 4px;
}

.danger-zone {
  margin-top: 32px;
  padding: 16px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  border-radius: 8px;
}

.danger-zone h2 {
  margin-top: 0;
  color: #b91c1c;
}

.danger-btn {
  background: #dc2626;
}

.danger-btn:hover {
  background: #b91c1c;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.15s ease-out;
}

.page-progress {
  display: inline-block;
  min-width: 90px;
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
  margin-left: 6px;
}

.page-progress-fill {
  height: 100%;
  background: #f59e0b;
}

.progress-percent {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  color: #b45309;
  font-variant-numeric: tabular-nums;
}

#search-form {
  display: flex;
  gap: 8px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 10px;
  font-size: 13px;
}

.filter-row select, .filter-row input {
  padding: 4px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 13px;
}

.issue-meta {
  color: #6b7280;
}

#search-input {
  flex: 1;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.overall-progress {
  margin-top: 8px;
  padding: 12px 16px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.overall-progress-text {
  font-size: 14px;
  margin-bottom: 8px;
}

.overall-progress-breakdown {
  margin-left: 10px;
  font-size: 12.5px;
  color: #6b7280;
}

.overall-progress .progress-wrap {
  height: 8px;
}

.overall-progress-eta {
  margin-top: 6px;
  font-size: 12.5px;
  color: #6b7280;
}

.doc-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: white;
  margin-top: 12px;
}

.doc-table col.col-filename { width: 22%; }
.doc-table col.col-issue { width: 13%; }
.doc-table col.col-uploader { width: 8%; }
.doc-table col.col-time { width: 12%; }
.doc-table col.col-status { width: 14%; }
.doc-table col.col-pages { width: 7%; }
.doc-table col.col-engine { width: 12%; }
.doc-table col.col-actions { width: 12%; }

.doc-table th, .doc-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  font-size: 14px;
}

.doc-table th {
  white-space: nowrap;
}

.doc-table td.cell-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-table td.cell-status,
.doc-table td.cell-wrap {
  white-space: normal;
}

.doc-table td.cell-actions a,
.doc-table td.cell-actions button {
  display: inline-block;
}

.doc-table .muted {
  display: block;
  color: #9ca3af;
  font-size: 12px;
  white-space: normal;
  overflow-wrap: break-word;
}

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

.status-queued { background: #9ca3af; }
.status-processing { background: #f59e0b; }
.status-done { background: #16a34a; }
.status-failed { background: #dc2626; }

.engine-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: white;
  white-space: nowrap;
}

.engine-tesseract { background: #6b7280; }
.engine-paddle { background: #2563eb; }
.engine-embedded { background: #8b5cf6; }

.search-results {
  list-style: none;
  padding: 0;
  margin-top: 16px;
}

.search-results li {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
}

.pagination button {
  margin-top: 0;
  padding: 6px 14px;
  font-size: 13px;
}

.pagination button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.pagination .page-indicator {
  font-size: 13px;
  color: #6b7280;
}

.pdf-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
  background: #fee2e2;
  color: #b91c1c;
  text-decoration: none;
}

.pdf-link:hover {
  background: #fecaca;
  color: #991b1b;
}

.search-results li > .pdf-link {
  margin-top: 6px;
}

.pdf-link svg {
  fill: currentColor;
}

.snippet-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 6px;
}

.snippet-row .pdf-link {
  margin-top: 1px;
}

.snippet-row .snippet {
  flex: 1;
  min-width: 0;
}

.search-results .meta {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 6px;
}

.search-results mark, .search-results .hl {
  background: #fde047;
  padding: 0 2px;
}

.debug-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.auto-refresh-label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}

#checked-at {
  font-size: 12px;
  color: #6b7280;
}

.debug-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.debug-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
}

.debug-card h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
}

.debug-card p {
  margin: 4px 0;
}

.debug-card .path {
  font-family: monospace;
  font-size: 11px;
  color: #6b7280;
  word-break: break-all;
}

.debug-card .muted {
  color: #9ca3af;
  font-size: 12px;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stats-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
}

.stats-card .stats-value {
  font-size: 22px;
  font-weight: bold;
  color: #1f2937;
}

.stats-card .stats-label {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.chart-box {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}

.chart-box h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}

.bar-row .bar-label {
  width: 90px;
  flex-shrink: 0;
  color: #4b5563;
}

.bar-row .bar-track {
  flex: 1;
  background: #f1f5f9;
  border-radius: 4px;
  height: 16px;
  overflow: hidden;
}

.bar-row .bar-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: #2563eb;
  transition: width 0.2s ease-out;
}

.bar-row .bar-value {
  width: 40px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.bar-fill.status-queued { background: #9ca3af; }
.bar-fill.status-processing { background: #f59e0b; }
.bar-fill.status-done { background: #16a34a; }
.bar-fill.status-failed { background: #dc2626; }

.bar-fill.engine-tesseract { background: #6b7280; }
.bar-fill.engine-paddle { background: #2563eb; }
.bar-fill.engine-embedded { background: #8b5cf6; }
.bar-fill.engine-unknown { background: #cbd5e1; }

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 130px;
}

.trend-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.trend-bar {
  width: 100%;
  background: #2563eb;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}

.trend-bar-count {
  font-size: 10px;
  color: #6b7280;
  margin-bottom: 2px;
}

.trend-bar-date {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 4px;
  white-space: nowrap;
}

.uploader-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.uploader-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}

.uploader-list li:last-child {
  border-bottom: none;
}

.table-scroll {
  overflow-x: auto;
  margin-bottom: 24px;
}

#documents-table col.col-doc-id { width: 4%; }
#documents-table col.col-doc-filename { width: 18%; }
#documents-table col.col-doc-uploader { width: 8%; }
#documents-table col.col-doc-time { width: 10%; }
#documents-table col.col-doc-status { width: 8%; }
#documents-table col.col-doc-num { width: 7%; }
#documents-table col.col-doc-error { width: 16%; }
#documents-table col.col-doc-path { width: 15%; }

#pages-table col.col-page-id { width: 6%; }
#pages-table col.col-page-docid { width: 9%; }
#pages-table col.col-page-num { width: 8%; }
#pages-table col.col-page-engine { width: 12%; }
#pages-table col.col-page-charcount { width: 9%; }
#pages-table col.col-page-preview { width: 56%; }

.table-scroll table {
  font-size: 12px;
  white-space: nowrap;
}

.link-btn {
  background: none;
  border: none;
  color: #2563eb;
  cursor: pointer;
  padding: 0;
  font-size: 13px;
  margin-top: 12px;
  text-decoration: underline;
}
