body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f5;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

header {
  background: white;
  padding: 12px 20px;
  border-radius: 8px;
  margin-bottom: 15px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.current-file-info {
  margin-top: 10px;
  padding: 6px 12px;
  background: #f8f9fa;
  border-left: 3px solid #1976d2;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: fit-content;
}

.current-file-info .file-icon {
  font-size: 16px;
}

.current-file-info .file-name {
  color: #495057;
  font-size: 13px;
  font-weight: 500;
}

.header-text {
  flex: 1;
}

.header-text p {
  margin: 0;
  color: #666;
  font-size: 13px;
}

h1 {
  margin: 0 0 4px 0;
  color: #333;
  font-size: 22px;
}

/* FHIR Data Widget in upper right */
.fhir-data-widget {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 10px 16px;
  border-radius: 6px;
  min-width: 220px;
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.widget-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.9;
  margin-bottom: 4px;
  font-weight: 600;
}

.widget-patient {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
  line-height: 1.3;
}

.widget-resources {
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 6px;
}

.widget-button {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.widget-button:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

.nav-link:hover {
  background: #e9ecef;
  border-color: #adb5bd;
  color: #495057;
}

.upload-section {
  background: white;
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 15px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.upload-row {
  display: flex;
  gap: 20px;
  margin-bottom: 15px;
}

.template-selector {
  flex: 1;
  border-right: 2px solid #e9ecef;
  padding-right: 20px;
}

.local-upload {
  flex: 1;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.template-selector h3,
.local-upload h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  color: #495057;
  font-weight: 600;
}

.template-search {
  position: relative;
  margin-bottom: 15px;
}

.template-search input {
  width: 100%;
  padding: 10px 35px 10px 12px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.template-search input:focus {
  outline: none;
  border-color: #667eea;
}

.template-search .search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
}

.template-results {
  min-height: 100px;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 20px;
}

.no-templates {
  text-align: center;
  color: #6c757d;
}

.no-templates .icon {
  font-size: 48px;
  display: block;
  margin-bottom: 10px;
  opacity: 0.3;
}

.no-templates p {
  margin: 0 0 5px 0;
  font-size: 14px;
  font-weight: 500;
}

.no-templates small {
  font-size: 12px;
  opacity: 0.7;
}

.upload-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-direction: column;
}

.upload-controls input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 2px dashed #dee2e6;
  border-radius: 6px;
  background: #f8f9fa;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-controls input[type="file"]:hover {
  border-color: #667eea;
  background: #f0f1ff;
}

.upload-controls button {
  width: 100%;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 500;
}

.mapping-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.mapping-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.action-button {
  background: #f8f9fa;
  color: #495057;
  border: 1px solid #dee2e6;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.action-button:hover {
  background: #e9ecef;
  border-color: #adb5bd;
}

.action-button.primary {
  background: #28a745;
  color: white;
  border-color: #28a745;
}

.action-button.primary:hover {
  background: #218838;
  border-color: #1e7e34;
}

.action-button.secondary {
  background: #6c757d;
  color: white;
  border-color: #6c757d;
}

.action-button.secondary:hover {
  background: #5a6268;
  border-color: #545b62;
}

.action-button.danger {
  background: #fff;
  color: #dc3545;
  border-color: #dc3545;
}

.action-button.danger:hover {
  background: #dc3545;
  color: white;
  border-color: #c82333;
}

.save-button {
  background: #1976d2;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s ease;
}

.save-button:hover {
  background: #1565c0;
}

.status-text {
  color: #666;
  font-size: 14px;
}

.status-text strong {
  color: #1976d2;
  font-weight: 600;
}

.content-wrapper {
  position: relative;
  display: grid;
  grid-template-columns: minmax(350px, 450px) 1fr;
  gap: 20px;
  align-items: stretch;
  height: calc(100vh - 320px);
  max-height: calc(100vh - 320px);
}

.field-mapper {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.field-mapper h2 {
  margin-top: 0;
  margin-bottom: 15px;
  flex-shrink: 0;
}

.page-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e9ecef;
  flex-shrink: 0;
}

.page-selector .page-btn {
  padding: 4px 12px;
  border: 1px solid #2196f3;
  background: white;
  color: #1565c0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.page-selector .page-btn:hover {
  background: #e3f2fd;
}

.page-selector .page-btn.active {
  background: #2196f3;
  color: white;
}

#fieldList {
  overflow-y: auto;
  overflow-x: hidden;
  flex-grow: 1;
  padding-right: 10px;
}

.pdf-viewer {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.pdf-viewer h2 {
  margin-top: 0;
  margin-bottom: 15px;
  flex-shrink: 0;
}

.pdf-canvas-container {
  position: relative;
  width: 100%;
  flex-grow: 1;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
}

#pdfCanvas {
  max-width: 100%;
  height: auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.field-item {
  padding: 10px;
  padding-right: 15px;
  border-bottom: 1px solid #eee;
  margin-right: 5px;
  position: relative;
  z-index: 1;
}

.field-item.autocomplete-active {
  z-index: 1000;
}

.field-item.autocomplete-active::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.02);
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  animation: fadeInOverlay 0.2s ease forwards;
}

@keyframes fadeInOverlay {
  to {
    opacity: 1;
  }
}

.field-item.highlighted {
  background: rgba(33, 150, 243, 0.1);
  border-left: 3px solid #2196f3;
  padding-left: 7px;
}

.field-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 10px;
}

.field-name {
  font-weight: 600;
  color: #333;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-right: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #666;
  flex-shrink: 0;
}

.field-type-icon[data-type="Text"] {
  color: #1976d2;
  background: #e3f2fd;
  border-radius: 3px;
  font-size: 12px;
  font-weight: bold;
}

.field-type-icon[data-type="CheckBox"] {
  color: #388e3c;
  font-size: 16px;
}

.field-type-icon[data-type="Radio"] {
  color: #f57c00;
  font-size: 14px;
}

.field-type-icon[data-type="Dropdown"] {
  color: #7b1fa2;
  font-size: 12px;
}

.field-type-icon[data-type="Button"] {
  color: #c62828;
  font-size: 12px;
}

.field-type-icon[data-type="Signature"] {
  color: #0288d1;
  font-size: 14px;
}

.mapping-input input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
}

.mapping-input input::placeholder {
  color: #ccc;
  font-style: italic;
}

.mapping-input input:not(:placeholder-shown) {
  color: #333;
  font-weight: 500;
}

#pdfFrame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 1px solid #ddd;
  border-radius: 4px;
}

button {
  background: #1976d2;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

button:hover {
  background: #1565c0;
}

#saveBtn {
  margin-top: 20px;
  width: 100%;
}

/* Autocomplete styles */
.autocomplete-container {
  position: relative;
  z-index: 100;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #c0c7d1;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 
    0 8px 25px rgba(0, 0, 0, 0.15),
    0 4px 10px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  display: none;
  backdrop-filter: blur(1px);
}

.autocomplete-dropdown.show {
  display: block;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.autocomplete-item {
  padding: 6px 12px;
  cursor: pointer;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.3;
  border-bottom: 1px solid #f5f6f7;
  color: #374151;
  background: rgba(255, 255, 255, 0.95);
  transition: all 0.15s ease;
  position: relative;
}

.autocomplete-item:last-child {
  border-bottom: none;
  border-radius: 0 0 8px 8px;
}

.autocomplete-item:first-child {
  border-radius: 0;
}

.autocomplete-item:hover {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  color: #1e293b;
  transform: translateX(2px);
}

.autocomplete-item.highlighted {
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  color: white;
  transform: translateX(4px);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(25, 118, 210, 0.2);
}

.autocomplete-item.highlighted .autocomplete-match {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.autocomplete-match {
  font-weight: 600;
  background: rgba(255, 193, 7, 0.25);
  color: #e65100;
  padding: 0px 2px;
  border-radius: 2px;
  font-size: 11px;
  letter-spacing: 0.2px;
}

/* PDF Diagnostics Warning Styles */
.pdf-diagnostics-warning {
  background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow:
    0 2px 4px rgba(255, 193, 7, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  position: relative;
}

.dismiss-warning {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: #856404;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.dismiss-warning:hover {
  background: rgba(133, 100, 4, 0.1);
}

.diagnostic-message {
  font-weight: 600;
  color: #856404;
  margin-bottom: 0.75rem;
  font-size: 14px;
}

.diagnostic-recommendations {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  padding: 0.75rem;
  border-left: 4px solid #ffc107;
}

.diagnostic-recommendations h4 {
  color: #856404;
  margin: 0 0 0.5rem 0;
  font-size: 14px;
  font-weight: 600;
}

.diagnostic-recommendations ul {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
  color: #6c757d;
  font-size: 13px;
}

.diagnostic-recommendations li {
  margin-bottom: 0.25rem;
  line-height: 1.4;
}

.diagnostic-recommendations p {
  margin: 0.5rem 0 0 0;
  font-size: 12px;
  color: #6c757d;
  font-style: italic;
}

/* Page Filtering Controls */
.page-filter-controls {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border: 1px solid #2196f3;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.page-filter-header h3 {
  color: #1565c0;
  margin: 0 0 0.5rem 0;
  font-size: 16px;
  font-weight: 600;
}

.page-filter-header p {
  color: #424242;
  margin: 0 0 1rem 0;
  font-size: 14px;
}

.page-filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.page-filter-btn {
  padding: 0.5rem 1rem;
  border: 2px solid #2196f3;
  background: white;
  color: #1565c0;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.page-filter-btn:hover {
  background: #f3f8ff;
  transform: translateY(-1px);
}

.page-filter-btn.active {
  background: #2196f3;
  color: white;
  box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

/* PDF Upload Overlay - positioned within content-wrapper */
.pdf-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pdf-overlay-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  transition: all 0.3s ease;
}

/* Blur the field mapper and pdf viewer beneath overlay (only when visible) */
.pdf-overlay[style*="display: flex"] ~ .field-mapper,
.pdf-overlay[style*="display: flex"] ~ .pdf-viewer {
  filter: blur(3px);
  pointer-events: none;
}

.pdf-overlay-content {
  position: relative;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 900px;
  width: 90%;
  max-height: 80vh;
  overflow: auto;
  z-index: 1;
}

.pdf-overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #e9ecef;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
  border-radius: 12px 12px 0 0;
}

.pdf-overlay-header h2 {
  margin: 0;
  font-size: 20px;
  color: #333;
}

.close-button {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.close-button:hover {
  background: #f5f5f5;
  color: #333;
}

.pdf-overlay-body {
  padding: 24px;
}

.pdf-overlay .upload-row {
  margin-bottom: 0;
}
