/* ============================================================
   Health PDF Parser — Stylesheet
   ============================================================ */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ---- Layout ---- */

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

header {
  margin-bottom: 28px;
}

header h1 {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a2e;
}

header p {
  color: #666;
  margin-top: 4px;
  font-size: 13px;
}

section {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  margin-bottom: 24px;
}

section h2 {
  font-size: 15px;
  font-weight: 600;
  padding: 16px 20px 0;
  color: #1a1a2e;
}

/* ---- Upload zone ---- */

#upload-zone {
  border: 2px dashed #c0c8d8;
  border-radius: 10px;
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin: 16px 20px 20px;
}

#upload-zone:hover,
#upload-zone.drag-over {
  border-color: #4a6cf7;
  background: #f5f7ff;
}

#upload-zone svg {
  display: block;
  margin: 0 auto 12px;
  color: #8a9bb8;
}

#upload-zone p {
  color: #8a9bb8;
  font-size: 14px;
}

#upload-zone p strong {
  color: #4a6cf7;
}

#upload-error {
  color: #e53e3e;
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

/* ---- Uploads table ---- */

#uploads-section h2 {
  padding-bottom: 12px;
}

/* ---- Filter bar ---- */

#filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 0 20px 16px;
  border-bottom: 1px solid #f0f2f5;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.filter-group label {
  font-size: 11px;
  font-weight: 600;
  color: #8a9bb8;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.filter-group select,
.filter-group input[type="date"] {
  padding: 6px 10px;
  border: 1px solid #d1d9e6;
  border-radius: 6px;
  font-size: 13px;
  background: #fafbfc;
  color: #1a1a2e;
  min-width: 140px;
  transition: border-color .15s;
}

.filter-group select:focus,
.filter-group input[type="date"]:focus {
  outline: none;
  border-color: #4a6cf7;
  background: #fff;
}

.filter-actions {
  margin-left: auto;
  justify-content: flex-end;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #8a9bb8;
  border-bottom: 1px solid #e8ecf2;
  background: #fafbfc;
}

tbody tr {
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  transition: background .15s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: #f5f7ff; }

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  vertical-align: middle;
}

td.filename {
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Status badges ---- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-processing    { background: #ebf8ff; color: #2b6cb0; }
.badge-ready         { background: #f0fff4; color: #276749; }
.badge-sent          { background: #e9d8fd; color: #553c9a; }
.badge-enhanced-sent { background: #c6f6d5; color: #22543d; }
.badge-failed        { background: #fff5f5; color: #c53030; }
.badge-unrecognised  { background: #fffaf0; color: #c05621; }
.badge-deleted       { background: #f0f2f5; color: #a0aec0; }

/* ---- Pagination ---- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  font-size: 13px;
  color: #666;
}

.pagination button {
  padding: 5px 14px;
  border: 1px solid #d1d9e6;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s;
}

.pagination button:hover:not(:disabled) { background: #f0f2f5; }
.pagination button:disabled { opacity: .4; cursor: default; }

/* ---- Empty state ---- */

.empty-row td {
  text-align: center;
  color: #aab;
  padding: 40px;
  cursor: default;
}

.empty-row:hover { background: transparent !important; }

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
}

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid #e8ecf2;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.modal-header h3 {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}

.modal-header .meta {
  font-size: 12px;
  color: #8a9bb8;
  margin-top: 2px;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #8a9bb8;
  font-size: 20px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background .15s;
}

.modal-close:hover { background: #f0f2f5; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px;
}

/* ---- Field groups ---- */

.field-group {
  margin-bottom: 20px;
}

.field-group h4 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #8a9bb8;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #f0f2f5;
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.field-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #8a9bb8;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field-item input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #d1d9e6;
  border-radius: 6px;
  font-size: 13px;
  background: #fafbfc;
  transition: border-color .15s, background .15s;
}

.field-item input:focus {
  outline: none;
  border-color: #4a6cf7;
  background: #fff;
}

.field-item input:disabled {
  background: #f0f2f5;
  color: #aab;
  cursor: not-allowed;
}

/* ---- Error message in detail view ---- */

.error-banner {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 8px;
  padding: 14px 16px;
  color: #c53030;
  font-size: 13px;
}

.processing-banner {
  background: #ebf8ff;
  border: 1px solid #bee3f8;
  border-radius: 8px;
  padding: 14px 16px;
  color: #2b6cb0;
  font-size: 13px;
}

/* ---- Modal footer / actions ---- */

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid #e8ecf2;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

button.btn {
  padding: 8px 20px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s, background .15s;
}

button.btn:disabled { opacity: .5; cursor: default; }

.btn-primary   { background: #4a6cf7; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #3a5ce6; }

.btn-warning   { background: #dd6b20; color: #fff; }
.btn-warning:hover:not(:disabled) { background: #c05621; }

.btn-secondary { background: #e8ecf2; color: #1a1a2e; }
.btn-secondary:hover:not(:disabled) { background: #d1d9e6; }

.btn-danger    { background: #e53e3e; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c53030; }

.btn-success   { background: #38a169; color: #fff; }
.btn-success:hover:not(:disabled) { background: #2f855a; }

/* ---- Confirm dialog (type selector / reprocess warning) ---- */

.confirm-dialog .modal {
  max-width: 440px;
}

.confirm-dialog .modal-body p {
  line-height: 1.6;
  color: #444;
}

.confirm-dialog .modal-body select {
  width: 100%;
  margin-top: 14px;
  padding: 8px 12px;
  border: 1px solid #d1d9e6;
  border-radius: 6px;
  font-size: 14px;
  background: #fafbfc;
}

.confirm-dialog .modal-body select:focus {
  outline: none;
  border-color: #4a6cf7;
}

/* ============================================================
   User bar (logged-in header)
   ============================================================ */

#user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 8px 24px;
  background: #fff;
  border-bottom: 1px solid #e8ecf2;
  font-size: 13px;
  color: #444;
}

#user-display {
  font-weight: 500;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 5px;
}

/* ============================================================
   Login page
   ============================================================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  width: 60%;
  display: block;
  margin: 0 auto 24px;
}

.login-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #1a1a2e;
}

.login-field {
  text-align: left;
  margin-bottom: 14px;
}

.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #8a9bb8;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}

.login-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d9e6;
  border-radius: 6px;
  font-size: 14px;
  background: #fafbfc;
  transition: border-color .15s;
}

.login-field input:focus {
  outline: none;
  border-color: #4a6cf7;
  background: #fff;
}

.login-error {
  color: #e53e3e;
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 8px;
}

.login-btn {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  margin-top: 4px;
}

/* ============================================================
   Deleted rows
   ============================================================ */

tr.row-deleted {
  opacity: .45;
  cursor: default !important;
}

tr.row-deleted:hover {
  background: transparent !important;
}

/* ============================================================
   Enhance modal
   ============================================================ */

.enhance-modal .modal {
  max-width: 820px;
}

.enhance-info {
  background: #ebf8ff;
  border: 1px solid #bee3f8;
  border-radius: 8px;
  padding: 10px 14px;
  color: #2b6cb0;
  font-size: 13px;
  margin-bottom: 14px;
}

.enhance-error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 8px;
  padding: 10px 14px;
  color: #c53030;
  font-size: 13px;
  margin-bottom: 14px;
}

.enhance-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 10px;
}

.enhance-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #8a9bb8;
  border-bottom: 1px solid #e8ecf2;
  background: #fafbfc;
}

.enhance-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: middle;
}

.enhance-table tbody tr {
  cursor: pointer;
  transition: background .15s;
}

.enhance-table tbody tr:hover {
  background: #f5f7ff;
}

.enhance-table tbody tr.selected-row {
  background: #ebf4ff;
  outline: 2px solid #4a6cf7;
  outline-offset: -2px;
}

.enhance-step-label {
  font-size: 12px;
  font-weight: 600;
  color: #8a9bb8;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

.enhance-loading {
  text-align: center;
  padding: 24px;
  color: #8a9bb8;
  font-size: 13px;
}

/* ============================================================
   Audit Panel (VO2 Max CRM progress)
   ============================================================ */

.modal-with-audit .modal {
  max-width: 1060px;
}

.modal-with-audit .modal-body {
  display: flex;
  gap: 1.5rem;
}

.modal-with-audit .modal-body .fields-col {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.audit-panel {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid #e0e0e0;
  padding-left: 1.5rem;
}

.audit-panel h4 {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a2e;
  margin-bottom: 12px;
  text-transform: none;
  letter-spacing: normal;
  border-bottom: none;
  padding-bottom: 0;
}

.audit-steps {
  list-style: none;
  padding: 0;
  margin: 0;
}

.audit-steps li {
  padding: 0.5rem 0;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 13px;
  color: #444;
}

.audit-steps li:last-child {
  border-bottom: none;
}

.step-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  margin-top: 1px;
}

.step-icon.pending { color: #d1d9e6; }
.step-icon.running { color: #4a6cf7; animation: audit-spin 1s linear infinite; }
.step-icon.success { color: #22c55e; }
.step-icon.error   { color: #ef4444; }
.step-icon.skipped { color: #a0aec0; }

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

.step-label {
  flex: 1;
  min-width: 0;
}

.step-detail {
  font-size: 0.8rem;
  color: #666;
  margin-top: 2px;
  word-break: break-word;
}

.step-detail.error-detail {
  color: #ef4444;
}

.audit-client-select {
  margin-top: 12px;
  border: 1px solid #e8ecf2;
  border-radius: 8px;
  overflow: hidden;
}

#audit-client-select,
#audit-result-select {
  overflow-x: auto;
}

#audit-client-select table,
#audit-result-select table {
  min-width: 520px;
}

.audit-client-select table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.audit-client-select th {
  text-align: left;
  padding: 6px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: #8a9bb8;
  background: #fafbfc;
  border-bottom: 1px solid #e8ecf2;
}

.audit-client-select td {
  padding: 6px 8px;
  border-bottom: 1px solid #f0f2f5;
}

.audit-client-select tbody tr {
  cursor: pointer;
  transition: background .15s;
}

.audit-client-select tbody tr:hover {
  background: #f5f7ff;
}

.audit-client-select tbody tr.selected-row {
  background: #ebf4ff;
  outline: 2px solid #4a6cf7;
  outline-offset: -2px;
}

.audit-result {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.audit-result.audit-success {
  background: #f0fff4;
  border: 1px solid #c6f6d5;
  color: #276749;
}

.audit-result.audit-error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: #c53030;
}

.audit-retry-btn {
  margin-top: 8px;
  padding: 5px 14px;
  border: 1px solid #d1d9e6;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #4a6cf7;
  font-weight: 500;
  transition: background .15s;
}

.audit-retry-btn:hover {
  background: #f5f7ff;
}
