/* ==========================================================================
   CARENOTE - SMART DOCUMENT AUTO-FILL DESIGN SYSTEM
   Pastel Glassmorphism, Clinical Clarity, Accessible & Interactive
   ========================================================================== */

:root {
  --saf-teal-50: #f0fdf4;
  --saf-teal-100: #ccfbf1;
  --saf-teal-500: #14b8a6;
  --saf-teal-600: #0d9488;
  --saf-teal-700: #0f766e;
  --saf-sky-50: #f0f9ff;
  --saf-sky-100: #e0f2fe;
  --saf-sky-500: #0ea5e9;
  --saf-sky-600: #0284c7;
  --saf-amber-50: #fffbeb;
  --saf-amber-100: #fef3c7;
  --saf-amber-600: #d97706;
  --saf-emerald-500: #10b981;
  --saf-emerald-600: #059669;
}

/* ==========================================================================
   1. SMART AUTO-FILL CARD (TOP OF FORM)
   ========================================================================== */
.smart-autofill-card {
  position: relative;
  background: linear-gradient(135deg, rgba(240, 253, 250, 0.95) 0%, rgba(240, 249, 255, 0.95) 55%, rgba(245, 243, 255, 0.92) 100%) !important;
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  border: 1.5px solid rgba(13, 148, 136, 0.25) !important;
  border-radius: 18px !important;
  box-shadow: 0 10px 25px -4px rgba(13, 148, 136, 0.1), 0 4px 10px -2px rgba(15, 23, 42, 0.04) !important;
  padding: 20px 24px !important;
  margin-bottom: 24px !important;
  margin-top: 8px !important;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  z-index: 10;
}

.smart-autofill-card:hover {
  border-color: rgba(13, 148, 136, 0.4) !important;
  box-shadow: 0 14px 32px -4px rgba(13, 148, 136, 0.16), 0 6px 14px -2px rgba(15, 23, 42, 0.06) !important;
}

/* Ambient subtle sparkle aura in top right */
.smart-autofill-card::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(20, 184, 166, 0.25) 0%, rgba(14, 165, 233, 0.1) 60%, transparent 80%);
  border-radius: 50%;
  pointer-events: none;
}

.smart-autofill-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.smart-autofill-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.smart-autofill-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #0d9488 0%, #0284c7 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
  flex-shrink: 0;
}

.smart-autofill-icon-badge svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.smart-autofill-title {
  font-size: 17px !important;
  font-weight: 700 !important;
  color: #0f172a !important;
  margin: 0 0 3px 0 !important;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.smart-autofill-pill-new {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.15), rgba(2, 132, 199, 0.15));
  color: #0d9488;
  padding: 3px 9px;
  border-radius: 9999px;
  border: 1px solid rgba(13, 148, 136, 0.3);
}

.smart-autofill-subtitle {
  font-size: 13px !important;
  color: #475569 !important;
  margin: 0 !important;
  line-height: 1.5;
}

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

.smart-autofill-btn-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.smart-autofill-btn-toggle:hover {
  background: #ffffff;
  color: #0f172a;
  border-color: #94a3b8;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* Collapsed state */
.smart-autofill-card.is-collapsed {
  padding: 12px 18px !important;
}

.smart-autofill-card.is-collapsed .smart-autofill-body {
  display: none;
}

.smart-autofill-card.is-collapsed .smart-autofill-header {
  margin-bottom: 0;
}

/* ==========================================================================
   2. DROPZONE & UPLOAD CONTROLS
   ========================================================================== */
.smart-autofill-dropzone {
  position: relative;
  border: 2px dashed rgba(13, 148, 136, 0.35);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease-in-out;
}

.smart-autofill-dropzone:hover,
.smart-autofill-dropzone.is-dragover {
  border-color: #0d9488;
  background: rgba(204, 251, 241, 0.45);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -2px rgba(13, 148, 136, 0.15);
}

.smart-autofill-dropzone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(13, 148, 136, 0.1);
  color: #0d9488;
  transition: transform 0.2s ease;
}

.smart-autofill-dropzone:hover .smart-autofill-dropzone-icon {
  transform: scale(1.08) translateY(-2px);
}

.smart-autofill-dropzone-text {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 6px;
}

.smart-autofill-dropzone-sub {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 14px;
}

.smart-autofill-format-badges {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.smart-autofill-badge-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(241, 245, 249, 0.9);
  color: #475569;
  border: 1px solid #e2e8f0;
}

.smart-autofill-badge-pill.is-ocr {
  background: rgba(224, 242, 254, 0.85);
  color: #0284c7;
  border-color: #bae6fd;
}

.smart-autofill-actions-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.smart-autofill-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  background: linear-gradient(135deg, #0d9488 0%, #0284c7 100%);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.25);
  transition: all 0.2s ease;
}

.smart-autofill-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.35);
  background: linear-gradient(135deg, #0f766e 0%, #0369a1 100%);
}

.smart-autofill-btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: rgba(255, 255, 255, 0.9);
  color: #334155;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 10px;
  border: 1.5px solid #cbd5e1;
  cursor: pointer;
  transition: all 0.2s ease;
}

.smart-autofill-btn-secondary:hover {
  background: #ffffff;
  border-color: #94a3b8;
  color: #0f172a;
}

/* Quick Demo Samples Pill Container */
.smart-autofill-samples-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed rgba(148, 163, 184, 0.3);
  font-size: 12px;
  color: #64748b;
  flex-wrap: wrap;
}

.smart-autofill-sample-btn {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: #0d9488;
  cursor: pointer;
  transition: all 0.15s ease;
}

.smart-autofill-sample-btn:hover {
  background: #ccfbf1;
  border-color: #0d9488;
}

/* ==========================================================================
   3. PROCESSING & PROGRESS BAR
   ========================================================================== */
.smart-autofill-processing {
  display: none;
  padding: 24px 20px;
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 14px;
  border: 1.5px solid rgba(13, 148, 136, 0.3);
}

.smart-autofill-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border: 3.5px solid rgba(13, 148, 136, 0.2);
  border-top-color: #0d9488;
  border-radius: 50%;
  animation: safSpin 0.9s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@keyframes safSpin {
  to { transform: rotate(360deg); }
}

.smart-autofill-processing-title {
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.smart-autofill-processing-desc {
  font-size: 12.5px;
  color: #64748b;
  margin-bottom: 14px;
}

.smart-autofill-progress-track {
  width: 100%;
  max-width: 320px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 9999px;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
}

.smart-autofill-progress-bar {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, #0d9488, #0ea5e9);
  border-radius: 9999px;
  animation: safProgressIndeterminate 1.8s infinite ease-in-out;
}

@keyframes safProgressIndeterminate {
  0% { left: -35%; width: 30%; }
  50% { left: 40%; width: 55%; }
  100% { left: 100%; width: 30%; }
}

/* ==========================================================================
   4. REVIEW-BEFORE-SAVE MODAL (MANDATORY CLINICAL REVIEW)
   ========================================================================== */
.saf-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: safFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes safFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.saf-modal-card {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 25px 60px -15px rgba(15, 23, 42, 0.35);
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.8);
  animation: safSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes safSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.saf-modal-header {
  padding: 20px 24px;
  background: linear-gradient(135deg, #f0fdfa 0%, #f0f9ff 100%);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.saf-modal-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.saf-modal-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0d9488 0%, #0284c7 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.saf-modal-title {
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
}

.saf-modal-sub {
  font-size: 12px;
  color: #64748b;
  margin: 2px 0 0 0;
}

.saf-modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
}

.saf-modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.saf-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Warnings / Mismatch Alert */
.saf-alert-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  color: #92400e;
  font-size: 12.5px;
  margin-bottom: 18px;
  line-height: 1.5;
}

.saf-alert-icon {
  flex-shrink: 0;
  font-size: 16px;
}

/* Meta info pills */
.saf-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.saf-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 12px;
  color: #334155;
}

.saf-meta-pill strong {
  color: #0f172a;
}

/* Extracted Fields Table */
.saf-fields-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 18px;
}

.saf-fields-table th {
  background: #f8fafc;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.saf-fields-table td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

.saf-fields-table tr:last-child td {
  border-bottom: none;
}

.saf-field-label {
  font-weight: 600;
  color: #1e293b;
  display: block;
}

.saf-field-input-cell input,
.saf-field-input-cell textarea {
  width: 100%;
  padding: 6px 10px;
  font-size: 12.5px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  font-family: inherit;
  color: #0f172a;
}

.saf-field-input-cell textarea {
  resize: vertical;
  min-height: 48px;
}

.saf-confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.saf-confidence-badge.high {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.saf-confidence-badge.medium {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

.saf-confidence-badge.low {
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

/* Missing Fields List */
.saf-missing-section {
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  margin-bottom: 16px;
}

.saf-missing-header {
  font-size: 12.5px;
  font-weight: 700;
  color: #475569;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.saf-missing-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.saf-missing-pill {
  font-size: 11.5px;
  padding: 3px 8px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #64748b;
}

/* Source text accordion */
.saf-source-preview {
  margin-top: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

.saf-source-toggle {
  width: 100%;
  padding: 8px 14px;
  background: #f8fafc;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.saf-source-content {
  display: none;
  padding: 12px 14px;
  background: #ffffff;
  font-family: monospace;
  font-size: 11px;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: #334155;
  border-top: 1px solid #e2e8f0;
}

/* Modal Footer */
.saf-modal-footer {
  padding: 16px 24px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.saf-modal-footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.saf-modal-footer-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.saf-btn-action-fill {
  background: linear-gradient(135deg, #0d9488 0%, #0284c7 100%);
  color: #ffffff;
  border: none;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.25);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.saf-btn-action-fill:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.35);
}

.saf-btn-action-missing {
  background: #0f172a;
  color: #ffffff;
  border: none;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.saf-btn-action-missing:hover {
  background: #1e293b;
}

.saf-btn-action-clear {
  background: transparent;
  color: #ef4444;
  border: 1px solid #fca5a5;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}

.saf-btn-action-clear:hover {
  background: #fee2e2;
}

.saf-btn-action-cancel {
  background: transparent;
  color: #64748b;
  border: 1px solid #cbd5e1;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}

.saf-btn-action-cancel:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* ==========================================================================
   5. FORM INPUT HIGHLIGHTING & BADGES
   ========================================================================== */
.carenote-field-autofilled {
  border-color: #0d9488 !important;
  background-color: rgba(240, 253, 250, 0.45) !important;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18) !important;
  transition: all 0.2s ease;
}

.carenote-autofill-badge-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.carenote-autofill-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  color: #0d9488;
  background: #ccfbf1;
  border: 1px solid #99f6e4;
  border-radius: 9999px;
  user-select: none;
}

.carenote-autofill-badge-undo {
  background: transparent;
  border: none;
  color: #0f766e;
  font-size: 11px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.carenote-autofill-badge-undo:hover {
  color: #ef4444;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .smart-autofill-card {
    padding: 16px !important;
  }
  .smart-autofill-header {
    flex-direction: column;
  }
  .smart-autofill-header-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .saf-modal-footer {
    flex-direction: column;
    align-items: stretch;
  }
  .saf-modal-footer-left,
  .saf-modal-footer-right {
    width: 100%;
    justify-content: stretch;
  }
  .saf-btn-action-fill,
  .saf-btn-action-missing,
  .saf-btn-action-clear,
  .saf-btn-action-cancel {
    flex: 1;
    justify-content: center;
  }
}
