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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #ddd;
  --text: #1a1a1a;
  --text-muted: #666;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warning: #d97706;
  --success: #16a34a;
  --conf-high: #16a34a;
  --conf-med: #d97706;
  --conf-low: #dc2626;
  --default-badge: #6366f1;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.app-header h1 { font-size: 16px; font-weight: 600; }
.app-header nav { display: flex; gap: 16px; align-items: center; }
.app-header nav a { color: var(--text-muted); text-decoration: none; font-size: 13px; }
.app-header nav a:hover { color: var(--text); }

.page { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: background 0.15s, color 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-warning { background: var(--warning); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Cards / panels ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Status badges ── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
}
.badge-pending    { background: #e5e7eb; color: #374151; }
.badge-extracting { background: #dbeafe; color: #1d4ed8; }
.badge-awaiting_review { background: #fef3c7; color: #92400e; }
.badge-approved   { background: #dcfce7; color: #166534; }
.badge-exported   { background: #dcfce7; color: #166534; }
.badge-flagged_manual { background: #fee2e2; color: #991b1b; }
.badge-error      { background: #fee2e2; color: #991b1b; }

/* ── Queue table ── */
.queue-table { width: 100%; border-collapse: collapse; }
.queue-table th {
  text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); background: #fafafa;
}
.queue-table td { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.queue-table tr:hover td { background: #fafafa; cursor: pointer; }
.queue-table .filename { font-weight: 500; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text-muted);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary); background: #eff6ff; color: var(--primary);
}
.upload-zone input[type=file] { display: none; }

/* ── Batch defaults panel ── */
.defaults-panel { margin-top: 16px; display: none; }
.defaults-panel.open { display: block; }
.defaults-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-top: 12px;
}

/* ── Form fields ── */
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.field-group input, .field-group select, .field-group textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; background: var(--surface);
  transition: border-color 0.15s;
  width: 100%;
}
.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.field-group input.edited { border-color: var(--warning); background: #fffbeb; }
.field-group input.error, .field-group select.error { border-color: var(--conf-low); }

/* ── Confidence indicator ── */
.conf-indicator {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; margin-top: 2px;
}
.conf-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.conf-high .conf-dot  { background: var(--conf-high); }
.conf-med .conf-dot   { background: var(--conf-med); }
.conf-low .conf-dot   { background: var(--conf-low); }
.conf-high { color: var(--conf-high); }
.conf-med  { color: var(--conf-med); }
.conf-low  { color: var(--conf-low); }
.badge-default { background: #ede9fe; color: #5b21b6; font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 600; }

/* ── Validation message ── */
.val-msg { font-size: 11px; margin-top: 2px; }
.val-msg.invalid { color: var(--conf-low); }
.val-msg.valid   { color: var(--conf-high); }
.val-msg.warning { color: var(--conf-med); }
.val-apply { color: inherit; font-weight: 600; text-underline-offset: 2px; cursor: pointer; }
.val-apply:hover { opacity: 0.75; }

/* ── Review layout ── */
.review-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  gap: 16px;
  height: calc(100vh - 52px - 48px - 56px); /* header + breadcrumb + action bar */
  min-height: 600px;
}
.review-left {
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.review-right {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.review-right embed, .review-right img {
  width: 100%; height: 100%; border: none; flex: 1;
}

/* ── Field sections ── */
.field-section { margin-bottom: 20px; }
.field-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-muted);
  margin-bottom: 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields-grid.single { grid-template-columns: 1fr; }
.fields-grid.three  { grid-template-columns: 1fr 1fr 1fr; }

/* ── Checkbox field ── */
.checkbox-field {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
}
.checkbox-field input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; }
.checkbox-field label { font-size: 13px; cursor: pointer; user-select: none; }

/* ── Action bar ── */
.action-bar {
  position: sticky; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -1px 4px rgba(0,0,0,0.07);
}
.action-bar-left { display: flex; gap: 8px; align-items: center; }
.action-bar-right { display: flex; gap: 8px; align-items: center; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(40px);
  background: #1a1a1a; color: #fff; padding: 10px 20px;
  border-radius: var(--radius); font-size: 13px;
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: 1000;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }
#toast.success { background: var(--success); }

/* ── Modal ── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 200;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; max-width: 480px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal h3 { margin-bottom: 12px; }
.modal textarea { width: 100%; height: 80px; resize: vertical; }
.modal-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* ── Breadcrumb ── */
.breadcrumb {
  font-size: 12px; color: var(--text-muted); padding: 8px 0;
  display: flex; align-items: center; gap: 6px;
}
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ── Login ── */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card { width: 360px; padding: 32px; }
.login-card h2 { margin-bottom: 24px; font-size: 20px; }
.login-card .field-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; display: none; }

/* ── Misc ── */
.text-muted { color: var(--text-muted); }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex  { display: flex; }
.gap-8 { gap: 8px; }
.gap-12{ gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
