/* ===== CSS Custom Properties ===== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --transition: 150ms ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navigation ===== */
.nav {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--gray-900);
  padding: 0.85rem 1rem 0.85rem 0;
  margin-right: 1.5rem;
  border-right: 1px solid var(--gray-200);
  white-space: nowrap;
}
.nav-links { display: flex; gap: 0; }
.nav-link {
  padding: 0.85rem 1.1rem;
  color: var(--gray-600);
  font-weight: 500;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.nav-link:hover { color: var(--primary); text-decoration: none; }
.nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ===== Layout ===== */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
}
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
}
.page-header p {
  color: var(--gray-500);
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

/* ===== Cards ===== */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  border: 1px solid var(--gray-100);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--gray-100);
}
.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
}

/* ===== Stat Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  border: 1px solid var(--gray-100);
}
.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-top: 0.25rem;
}
.stat-card .stat-detail {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-top: 0.25rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.4;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; }

/* ===== Tables ===== */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead {
  background: var(--gray-50);
}
th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--gray-600);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--gray-50); }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ===== Status Dot ===== */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
}
.status-dot.green { background: var(--success); }
.status-dot.red { background: var(--danger); }
.status-dot.yellow { background: var(--warning); }
.status-dot.gray { background: var(--gray-400); }

/* ===== Upload Zone ===== */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--gray-50);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-zone .upload-icon {
  font-size: 2.5rem;
  color: var(--gray-400);
  margin-bottom: 0.5rem;
}
.upload-zone .upload-text {
  color: var(--gray-600);
  font-size: 0.9rem;
}
.upload-zone .upload-text strong {
  color: var(--primary);
}
.upload-zone input[type="file"] { display: none; }
.upload-options {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-top: 1rem;
}
.upload-options label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--gray-600);
  cursor: pointer;
}

/* ===== Progress Bar ===== */
.progress-section {
  margin-top: 1.5rem;
}
.progress-bar-container {
  background: var(--gray-200);
  border-radius: 9999px;
  height: 8px;
  overflow: hidden;
  margin: 0.75rem 0;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 9999px;
  transition: width 0.5s ease;
  width: 0%;
}
.progress-stages {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
}
.progress-stage {
  font-size: 0.75rem;
  color: var(--gray-400);
  font-weight: 500;
  position: relative;
}
.progress-stage.active {
  color: var(--primary);
  font-weight: 600;
}
.progress-stage.done {
  color: var(--success);
}
.progress-status {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--gray-600);
}
.progress-status .current-stage {
  font-weight: 600;
  color: var(--primary);
  text-transform: capitalize;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--gray-700);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: #fff;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
textarea.form-control {
  resize: vertical;
  min-height: 100px;
}
select.form-control {
  cursor: pointer;
}
.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.form-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}
.form-hint {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-top: 0.25rem;
}

/* ===== Split View ===== */
.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: calc(100vh - 180px);
  min-height: 500px;
}
.split-view .panel {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--gray-700);
  background: var(--gray-50);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.panel-body {
  flex: 1;
  overflow: auto;
  padding: 0;
}
.panel-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.panel-body img {
  max-width: 100%;
  height: auto;
}

/* ===== JSON Tree ===== */
.json-tree {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  padding: 1rem;
}
.json-tree .json-key {
  color: #0451a5;
  font-weight: 600;
}
.json-tree .json-string { color: #a31515; }
.json-tree .json-number { color: #098658; }
.json-tree .json-boolean { color: #0000ff; }
.json-tree .json-null { color: var(--gray-400); font-style: italic; }
.json-tree .json-toggle {
  cursor: pointer;
  user-select: none;
  color: var(--gray-500);
  margin-right: 0.25rem;
}
.json-tree .json-toggle:hover { color: var(--primary); }
.conflict-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 3px;
  padding: 0 0.3rem;
  margin-left: 0.4rem;
  cursor: default;
  vertical-align: middle;
}
.json-tree .json-collapsible {
  margin-left: 1.25rem;
}
.json-tree .json-collapsible.collapsed { display: none; }
.json-tree .json-bracket { color: var(--gray-500); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.tab {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}
.tab:hover { color: var(--gray-700); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  animation: toastIn 0.3s ease;
  max-width: 400px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--primary); color: #fff; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  min-width: 350px;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
}
.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}
.modal p {
  color: var(--gray-600);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 1.25rem;
}
.pagination .page-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  color: var(--gray-600);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}
.pagination .page-btn:hover { background: var(--gray-100); }
.pagination .page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.pagination .page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin: 0 0.5rem;
}

/* ===== Filters Bar ===== */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filters-bar .form-control {
  width: auto;
  min-width: 160px;
}

/* ===== PII Highlight ===== */
.pii-highlight {
  padding: 1rem;
  font-size: 0.9rem;
  line-height: 1.8;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}
mark.pii-entity {
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-weight: 500;
  cursor: default;
}
mark.pii-PERSON { background: #fde68a; color: #92400e; }
mark.pii-EMAIL_ADDRESS { background: #c4b5fd; color: #5b21b6; }
mark.pii-PHONE_NUMBER { background: #a7f3d0; color: #065f46; }
mark.pii-LOCATION { background: #fbcfe8; color: #9d174d; }
mark.pii-CREDIT_CARD { background: #fecaca; color: #991b1b; }
mark.pii-IBAN_CODE { background: #fed7aa; color: #9a3412; }
mark.pii-IP_ADDRESS { background: #bfdbfe; color: #1e40af; }
mark.pii-DATE_TIME { background: #e9d5ff; color: #6b21a8; }
mark.pii-NRP { background: #ccfbf1; color: #115e59; }
mark.pii-DEFAULT { background: var(--gray-200); color: var(--gray-700); }

/* ===== Metadata Bar ===== */
.metadata-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.metadata-item {
  font-size: 0.85rem;
  color: var(--gray-600);
}
.metadata-item strong {
  color: var(--gray-800);
}

/* ===== Slider ===== */
input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

/* ===== Loading Spinner ===== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}
.empty-state p {
  font-size: 0.9rem;
}

/* ===== Grid layouts ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .split-view { grid-template-columns: 1fr; height: auto; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .nav { flex-wrap: wrap; }
  .nav-brand { border-right: none; margin-right: 0; }
  .nav-links { width: 100%; overflow-x: auto; }
  .filters-bar { flex-direction: column; align-items: stretch; }
}

/* ===== File Queue (Multi-upload) ===== */
.file-queue {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
}
.file-queue:empty {
  display: none;
}
.queue-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.85rem;
  transition: background 0.2s ease;
}
.queue-item:last-child {
  border-bottom: none;
}
.queue-filename {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gray-700);
}
.queue-status {
  font-size: 0.75rem;
  color: var(--gray-500);
  min-width: 80px;
  text-align: right;
}
.queue-progress {
  width: 80px;
  height: 6px;
  background: var(--gray-200);
  border-radius: 9999px;
  overflow: hidden;
  flex-shrink: 0;
}
.queue-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 9999px;
  transition: width 0.5s ease;
  width: 0%;
}
.queue-remove {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}
.queue-remove:hover {
  color: var(--danger);
}
.queue-class-select {
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  background: #fff;
  color: var(--gray-700);
  flex-shrink: 0;
}
.queue-class-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.queue-item.queue-completed {
  background: #f0fdf4;
}
.queue-item.queue-completed .queue-progress-fill {
  background: var(--success);
}
.queue-item.queue-failed {
  background: #fef2f2;
}
.queue-item.queue-failed .queue-progress-fill {
  background: var(--danger);
}
.queue-item.queue-processing .queue-progress-fill {
  background: var(--primary);
}
