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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f0f2f5;
  color: #1a1a1a;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #2d3748;
}

/* Drop zone */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 3rem 2rem;
  border: 2.5px dashed #a0aec0;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}

.drop-zone.dragover {
  border-color: #4f46e5;
  background: #eef2ff;
}

.drop-zone__icon {
  font-size: 3rem;
  line-height: 1;
}

.drop-zone__text {
  font-size: 1.1rem;
  color: #4a5568;
}

.drop-zone__subtext {
  font-size: 0.9rem;
  color: #a0aec0;
}

.btn {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.55rem 1.4rem;
  background: #4f46e5;
  color: #fff;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn:hover {
  background: #4338ca;
}

/* File info bar */
.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.2rem;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  font-size: 0.95rem;
  color: #2d3748;
  font-weight: 500;
}

.file-info #clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: #a0aec0;
  line-height: 1;
  transition: color 0.15s;
}

.file-info #clear-btn:hover {
  color: #e53e3e;
}

/* Detections list */
.detections {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

.detections__header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.2rem;
  background: #fefce8;
  border-bottom: 1px solid #fef08a;
}

.detections__title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #713f12;
}

.detections__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  background: #fef08a;
  color: #713f12;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.detections__list {
  list-style: none;
  padding: 0.5rem 0;
  margin: 0;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.75rem 1.2rem;
}

.detections__list li {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.7rem;
  background: #fef9c3;
  border: 1px solid #fde047;
  border-radius: 999px;
  font-size: 0.875rem;
  color: #713f12;
  font-weight: 500;
  cursor: default;
}

/* Preview */
.preview {
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  padding: 2.5rem 3rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  min-height: 200px;
}

/* Document content styles */
#preview-content {
  line-height: 1.75;
  font-size: 1rem;
  color: #1a202c;
  word-break: break-word;
}

#preview-content h1,
#preview-content h2,
#preview-content h3,
#preview-content h4,
#preview-content h5,
#preview-content h6 {
  margin: 1.2em 0 0.4em;
  line-height: 1.3;
  color: #2d3748;
}

#preview-content p {
  margin-bottom: 0.75em;
}

#preview-content ul,
#preview-content ol {
  margin: 0.5em 0 0.75em 1.5em;
}

#preview-content li {
  margin-bottom: 0.25em;
}

#preview-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.95rem;
}

#preview-content th,
#preview-content td {
  border: 1px solid #cbd5e0;
  padding: 0.5rem 0.75rem;
  text-align: left;
}

#preview-content th {
  background: #f7fafc;
  font-weight: 600;
}

#preview-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 0.5em 0;
}

#preview-content strong { font-weight: 700; }
#preview-content em    { font-style: italic; }
#preview-content u     { text-decoration: underline; }

.name-highlight {
  background-color: #fef08a;
  border-radius: 2px;
  padding: 0 1px;
}

.payment-highlight {
  background-color: #bbf7d0;
  border-radius: 2px;
  padding: 0 1px;
}

.dob-highlight {
  background-color: #e9d5ff;
  border-radius: 2px;
  padding: 0 1px;
}

.address-highlight {
  background-color: #fed7aa;
  border-radius: 2px;
  padding: 0 1px;
}

/* Legend — what the tool detects */
.legend {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  padding: 0.75rem 1.2rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.legend__title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #718096;
  white-space: nowrap;
}

.legend__items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: #4a5568;
}

.legend__swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend__swatch--name    { background: #fef08a; border: 1px solid #fde047; }
.legend__swatch--payment { background: #bbf7d0; border: 1px solid #86efac; }
.legend__swatch--dob     { background: #e9d5ff; border: 1px solid #c4b5fd; }
.legend__swatch--sig     { background: #fee2e2; border: 2px solid #ef4444; }
.legend__swatch--address { background: #fed7aa; border: 1px solid #fb923c; }
.legend__swatch--id      { background: #a5f3fc; border: 1px solid #0ea5e9; }
.legend__swatch--stamp   { background: #a7f3d0; border: 1px solid #10b981; }

.legend__sub {
  color: #a0aec0;
  font-size: 0.78rem;
}

/* Payment detections panel */
.detections--payment .detections__header {
  background: #f0fdf4;
  border-bottom-color: #bbf7d0;
}

.detections--payment .detections__title {
  color: #14532d;
}

.detections--payment .detections__count {
  background: #bbf7d0;
  color: #14532d;
}

.detections--payment .detections__list li {
  background: #dcfce7;
  border-color: #86efac;
  color: #14532d;
}

.detections__type-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: #86efac;
  color: #14532d;
  margin-right: 0.2rem;
}

/* Signature detections panel */
.detections--sig .detections__header {
  background: #fef2f2;
  border-bottom-color: #fecaca;
}

.detections--sig .detections__title { color: #991b1b; }
.detections--sig .detections__count { background: #fecaca; color: #991b1b; }
.detections--sig .detections__list {
  max-height: none;
  flex-direction: column;
  flex-wrap: nowrap;
}

.detections--sig .detections__list li {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.detections__type-badge--sig {
  background: #fca5a5;
  color: #991b1b;
}

/* DOB detections panel */
.detections--dob .detections__header {
  background: #faf5ff;
  border-bottom-color: #e9d5ff;
}

.detections--dob .detections__title {
  color: #581c87;
}

.detections--dob .detections__count {
  background: #e9d5ff;
  color: #581c87;
}

.detections--dob .detections__list li {
  background: #f3e8ff;
  border-color: #c4b5fd;
  color: #581c87;
}

.detections__type-badge--dob {
  background: #c4b5fd;
  color: #581c87;
}

.detections__type-badge--id {
  background: #a5f3fc;
  color: #0c4a6e;
}

/* Address detections panel */
.detections--address .detections__header {
  background: #fff7ed;
  border-bottom-color: #fed7aa;
}

.detections--address .detections__title { color: #7c2d12; }
.detections--address .detections__count { background: #fed7aa; color: #7c2d12; }
.detections--address .detections__list li {
  background: #ffedd5;
  border-color: #fb923c;
  color: #7c2d12;
}

.detections--id .detections__header {
  background: #ecfeff;
  border-bottom-color: #a5f3fc;
}

.detections--id .detections__title { color: #0c4a6e; }
.detections--id .detections__count { background: #a5f3fc; color: #0c4a6e; }
.detections--id .detections__list li {
  background: #e0f9ff;
  border-color: #0ea5e9;
  color: #0c4a6e;
}

.detections--stamp .detections__header {
  background: #ecfdf5;
  border-bottom-color: #a7f3d0;
}

.detections--stamp .detections__title { color: #064e3b; }
.detections--stamp .detections__count { background: #a7f3d0; color: #064e3b; }
.detections--stamp .detections__list li {
  background: #d1fae5;
  border-color: #10b981;
  color: #064e3b;
}

.detections__type-badge--stamp {
  background: #a7f3d0;
  color: #064e3b;
}

/* Error */
.error {
  padding: 1rem 1.25rem;
  background: #fff5f5;
  border: 1px solid #feb2b2;
  border-radius: 10px;
  color: #c53030;
  font-size: 0.95rem;
}

/* Loader */
.loader {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  color: #4a5568;
  font-size: 0.95rem;
}

.loader__text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.loader__sub {
  font-size: 0.8rem;
  color: #a0aec0;
}

.loader__spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2.5px solid #e2e8f0;
  border-top-color: #4f46e5;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* PDF preview */
.pdf-preview {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.pdf-page {
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.pdf-page__label {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #718096;
  background: #f7fafc;
  border-bottom: 1px solid #e2e8f0;
}

.pdf-page__img {
  width: 100%;
  height: auto;
  display: block;
}

/* Download bar */
.download-bar {
  display: flex;
  justify-content: flex-end;
}

.btn--download {
  display: inline-block;
  padding: 0.6rem 1.5rem;
  background: #0f766e;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn--download:hover {
  background: #0d6b63;
}

.btn--download:disabled {
  background: #a0aec0;
  cursor: not-allowed;
}

/* Process log */
.process-log {
  background: #0f172a;
  border-radius: 10px;
  overflow: hidden;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
}

.process-log__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.9rem;
  background: #1e293b;
  border-bottom: 1px solid #334155;
}

.process-log__title {
  color: #94a3b8;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

.process-log__elapsed {
  color: #64748b;
  font-size: 0.72rem;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

.process-log__body {
  max-height: 260px;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.log-entry {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.18rem 0.9rem;
  line-height: 1.55;
  border-left: 2px solid transparent;
  transition: background 0.1s;
}

.log-entry:hover {
  background: #1e293b;
}

.log-entry--done {
  border-left-color: #22c55e;
}

.log-entry--start {
  border-left-color: #3b82f6;
  opacity: 0.7;
}

.log-entry__elapsed {
  color: #475569;
  min-width: 4.5rem;
  text-align: right;
  flex-shrink: 0;
}

.log-entry__msg {
  color: #cbd5e1;
  flex: 1;
}

.log-entry__ms {
  color: #f59e0b;
  min-width: 5rem;
  text-align: right;
  flex-shrink: 0;
}

.log-entry--total .log-entry__msg {
  color: #86efac;
  font-weight: 600;
}

.log-entry--total .log-entry__ms {
  color: #86efac;
}

/* OCR text panel */
.ocr-panel {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

.ocr-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.2rem;
  cursor: pointer;
  user-select: none;
  background: #f8fafc;
  transition: background 0.15s;
}

.ocr-panel__header:hover { background: #f1f5f9; }

.ocr-panel__title {
  font-size: 0.88rem;
  font-weight: 600;
  color: #475569;
}

.ocr-panel__arrow {
  font-size: 0.7rem;
  color: #94a3b8;
  transition: transform 0.2s;
}

.ocr-panel__arrow--open { transform: rotate(90deg); }

.ocr-panel__body {
  border-top: 1px solid #e2e8f0;
  padding: 0.75rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.ocr-page {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ocr-page__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ocr-page__text {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  color: #334155;
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  line-height: 1.55;
}

/* Signature items with crop thumbnails */
.sig-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem !important;
  border-radius: 8px !important;
}

.sig-item__thumb {
  max-width: 220px;
  max-height: 80px;
  width: auto;
  height: auto;
  border-radius: 4px;
  border: 1px solid #fca5a5;
  display: block;
  background: #fff;
}

.sig-item__label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.875rem;
}

/* Utility */
.hidden { display: none !important; }
