:root {
  --ink: #1c2333;
  --stamp: #a13d2c;
  --stamp-bg: #f7e9e5;
  --verified: #4c6b4f;
  --verified-bg: #e7efe8;
  --flag: #b8842b;
  --flag-bg: #faeeda;
  --reviewed: #2f5f8a;
  --reviewed-bg: #e6eef5;
  --surface: #ffffff;
  --surface-muted: #f6f5f2;
  --border: #e3e0d8;
  --border-strong: #c9c5b8;
  --text-primary: #1c2333;
  --text-secondary: #5c5a52;
  --text-muted: #8a8778;
  --radius: 10px;
  --font-display: Georgia, 'Times New Roman', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--surface-muted);
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 56px;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.app-header h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 24px;
  margin: 0 0 2px;
}

.subtitle {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 14px;
  font-family: var(--font-sans);
}

.tagline {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  white-space: nowrap;
  background: var(--surface);
}

.upload-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 14px;
  padding: 22px 20px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  background: var(--surface);
  color: var(--text-muted);
  margin-bottom: 18px;
}

.upload-zone:hover, .upload-zone.dragover {
  background: var(--surface-muted);
  border-color: var(--stamp);
}

.upload-title {
  margin: 8px 0 3px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.upload-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.upload-error {
  color: #a32d2d;
  font-size: 13px;
  margin: -8px 2px 14px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover:not(:disabled) { background: #2a3348; }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { background: var(--border-strong); cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--surface-muted); }
.btn-secondary:active { transform: scale(0.98); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
}
.btn-ghost:hover { background: var(--surface-muted); color: var(--stamp); }

/* Workspace: doc list + detail */
.workspace {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 800px) {
  .workspace { grid-template-columns: 1fr; }
}

.doc-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 74vh;
  overflow-y: auto;
  position: sticky;
  top: 20px;
}

.doc-list-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.doc-item:hover { background: var(--surface-muted); }
.doc-item.active { background: var(--surface-muted); border-color: var(--border-strong); }

.doc-item-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.doc-item-icon img { width: 100%; height: 100%; object-fit: cover; }

.doc-item-info { flex: 1; min-width: 0; }
.doc-item-name {
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-item-status { margin-top: 3px; }

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}
.status-dot.processing { background: var(--text-muted); }
.status-dot.flagged { background: var(--flag); }
.status-dot.verified { background: var(--verified); }
.status-dot.reviewed { background: var(--reviewed); }
.status-dot.error { background: #a32d2d; }

.status-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
}

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Detail panel */
.doc-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 300px;
  padding: 20px;
}

.doc-detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 260px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.detail-title { min-width: 0; }
.detail-filename {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-doctype {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

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

.stamp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.stamp.flagged { background: var(--flag-bg); color: var(--flag); }
.stamp.verified { background: var(--verified-bg); color: var(--verified); }
.stamp.reviewed { background: var(--reviewed-bg); color: var(--reviewed); }

.detail-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

@media (max-width: 900px) {
  .detail-body { grid-template-columns: 1fr; }
}

.preview-pane {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  max-height: 560px;
}
.preview-pane img { width: 100%; height: 100%; object-fit: contain; }
.preview-pane embed { width: 100%; height: 560px; }
.preview-empty { color: var(--text-muted); font-size: 13px; padding: 20px; text-align: center; }

.form-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 4px;
}

.field-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
}
.field-row.low-conf { border-color: var(--flag); background: var(--flag-bg); }
.field-row.manual { border-color: var(--reviewed); }

.field-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.field-label-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.confidence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.confidence-dot.high { background: var(--verified); }
.confidence-dot.mid { background: var(--flag); }
.confidence-dot.low { background: var(--stamp); }
.confidence-dot.manual { background: var(--reviewed); }

.field-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  display: flex;
  flex-shrink: 0;
}
.field-remove:hover { color: var(--stamp); background: var(--surface-muted); }

input.field-input, textarea.field-input {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 13.5px;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-primary);
  margin-bottom: 5px;
}
input.field-input:focus, textarea.field-input:focus {
  outline: none;
  border-color: var(--stamp);
}
.field-input-label {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
  display: block;
}

.notes-row textarea { min-height: 52px; resize: vertical; }

.add-field-row {
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.add-field-row input {
  flex: 1;
  min-width: 120px;
}
.add-field-row label {
  font-size: 10.5px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.save-hint { font-size: 12px; color: var(--text-muted); }

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

@media (max-width: 600px) {
  .app-header h1 { font-size: 20px; }
}
