:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --primary: #0f172a;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --emerald: #059669;
  --emerald-bg: #ecfdf5;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: #0f172a;
  color: #ffffff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 3px solid #0284c7;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-badge {
  background: #0284c7;
  color: #fff;
  font-weight: 800;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 15px;
  letter-spacing: 0.04em;
}
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; }
.brand p { margin: 2px 0 0 0; font-size: 12.5px; color: #94a3b8; }

.zero-ai-pill {
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid #34d399;
  color: #6ee7b7;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.nav-tabs {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 14px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.container {
  max-width: 1360px;
  margin: 24px auto;
  padding: 0 24px 48px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.card h2 { margin: 0 0 6px 0; font-size: 18px; }
.card-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

.trust-strip {
  background: var(--emerald-bg);
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  padding: 18px;
  background: #f8fafc;
  transition: border-color 0.15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 4px; }
.dropzone .hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.dropzone input[type="file"] { width: 100%; font-size: 12.5px; }

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  margin-top: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: #f1f5f9; color: #0f172a; border: 1px solid #cbd5e1; }
.btn.secondary:hover { background: #e2e8f0; }
.btn.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.btn.danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
}
.kpi-card.danger { border-left-color: var(--red); }
.kpi-card.amber { border-left-color: var(--amber); }
.kpi-card.emerald { border-left-color: var(--emerald); }
.kpi-card .lbl { font-size: 11.5px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kpi-card .val { font-size: 22px; font-weight: 800; margin-top: 4px; color: var(--text); }
.kpi-card .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.cert-box {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.cert-box .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; color: #38bdf8; font-size: 12.5px; }
.tamper-banner {
  background: #fef2f2;
  border: 2px solid #dc2626;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 16px;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top; }
th { background: #f1f5f9; font-weight: 700; color: #334155; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge.unbilled_job { background: #fee2e2; color: #991b1b; }
.badge.duplicate_invoice { background: #ffedd5; color: #9a3412; }
.badge.amount_mismatch { background: #fef3c7; color: #92400e; }
.badge.unpaid_with_payment { background: #dbeafe; color: #1e40af; }
.badge.orphan_payment { background: #f3e8ff; color: #6b21a8; }
.badge.clean_no_flag { background: #dcfce7; color: #166534; }
.badge.confirmed { background: #dcfce7; color: #166534; }
.badge.needs-review { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }

.diag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
  padding: 3px 8px;
  background: #fffbeb;
  border: 1px solid #f59e0b;
  color: #b45309;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  cursor: pointer;
}
.diag-chip:hover { background: #fef3c7; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  padding: 22px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
}
