/* mapping.css */

/* Reset and Typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body { /* This body style is likely for testing mapping.html in isolation */
  background-color: #f5f5f5;
}

/* Modal Backdrop and Container */
.mapping-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.85); /* Darker overlay like CodeIQ */
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.3s ease-out;
}

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

.mapping-modal-container {
  background: #fff;
  border-radius: 16px; /* Rounder like CodeIQ */
  max-width: 95vw;
  width: fit-content;
  min-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0; /* Remove padding, sections will have their own */
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); /* Stronger shadow */
  display: flex;
  flex-direction: column;
  border: 3px solid #1e3a8a; /* ReconcileIQ royal blue border */
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.mapping-modal-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%); /* Royal blue to baby blue gradient */
  border-bottom: 2px solid #1e3a8a;
  padding: 0.85rem 1rem;
  text-align: center;
  flex-shrink: 0;
}

.mapping-modal-header h2 {
  font-weight: 700;
  color: #ffffff;
  font-size: 1.15rem;
  margin: 0 0 0.25rem 0;
  letter-spacing: -0.01em;
}

.mapping-modal-header p {
  font-size: 0.8rem;
  color: #ffffff;
  margin: 0;
  font-weight: 500;
  opacity: 0.9;
}

.mapping-close-modal {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.5);
  font-size: 1.5rem;
  line-height: 1;
  color: #ffffff;
  cursor: pointer;
  padding: 0.5rem;
  transition: all 0.2s;
  border-radius: 8px;
  font-weight: 700;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.mapping-close-modal:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.8);
  transform: scale(1.1);
}

/* RiQ Avatar Section */
.mapping-modal-avatar {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: linear-gradient(180deg, #3b82f6 0%, white 100%);
}

.mapping-modal-avatar img {
  width: 50px;
  height: 50px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Instruction Notice */
.mapping-instruction {
  text-align: center;
  font-size: 0.8rem;
  color: #1e3a8a;
  margin: 0.75rem 1rem;
  line-height: 1.4;
  flex-shrink: 0;
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  border: 2px solid #1e3a8a;
}

.mapping-instruction strong {
  color: #1e3a8a;
  font-weight: 700;
}


/* Panel Sections - EXTRA CONDENSED for 2 statements */
.mapping-panel-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-grow: 1;
  overflow-x: hidden;
  overflow-y: visible;
  min-height: 0;
}

.mapping-section {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  background-color: #fafafa;
  flex-shrink: 0;
}

.mapping-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 0.65rem;
  text-align: center;
}

/* Credit Card Option */
.credit-card-option {
  margin-bottom: 0.65rem;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  border: 2px solid #1e3a8a;
  border-radius: 6px;
}

.credit-card-option label {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  font-size: 0.8rem;
  color: #1e3a8a;
  font-weight: 600;
}

.credit-card-option input[type="checkbox"] {
  margin-right: 0.45rem;
  margin-top: 0.1rem;
  flex-shrink: 0;
  accent-color: #1e3a8a;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.credit-card-option .help-text {
  display: block;
  font-size: 0.7rem;
  color: #1d4ed8;
  margin-top: 0.2rem;
  font-weight: 500;
}

/* Toggle Buttons */
.mapping-toggle-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mapping-toggle-button {
  padding: 0.5rem 0.75rem;
  border: 2px solid #d1d5db;
  background-color: #fff;
  color: #374151;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.2s;
  user-select: none;
}

.mapping-toggle-button:hover {
  background-color: #dbeafe;
  border-color: #1e3a8a;
  color: #1e3a8a;
}

.mapping-toggle-button.active {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  border-color: #1e3a8a;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.3);
}

/* Table Container (Horizontal Scrolling) */
.mapping-table-container {
  overflow-x: auto;
  overflow-y: hidden; /* Completely prevent vertical scrollbar here */
  border: 1px solid #d1d5db;
  border-radius: 6px;
  position: relative;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  z-index: 1;
  background-color: #fff;
  width: 100%;
  /* Allow container to grow with content up to available space */
  max-width: 100%;
  /* This container will contain both table and overlays */
}

/* Custom blue scrollbar for table container */
.mapping-table-container::-webkit-scrollbar {
  height: 12px;
}
.mapping-table-container::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 6px;
}
.mapping-table-container::-webkit-scrollbar-thumb {
  background: #3b82f6;
  border-radius: 6px;
  border: 2px solid #f1f5f9;
}
.mapping-table-container::-webkit-scrollbar-thumb:hover {
  background: #2563eb;
}
/* Firefox */
.mapping-table-container {
  scrollbar-width: auto;
  scrollbar-color: #3b82f6 #f1f5f9;
}

/* Use default scrollbar styling to avoid conflicts */


/* Scroll Fader Indicators with Icons */
.mapping-table-container::before,
.mapping-table-container::after {
  content: ''; /* Gradient is primary */
  position: absolute;
  top: 0;
  bottom: 0; /* Cover full height */
  width: 50px; /* Wider fader for better effect */
  pointer-events: none;
  z-index: 3; /* Above table content, below overlays */
  opacity: 0;
  transition: opacity 0.3s;
}
.mapping-table-container::before {
  left: 0;
  background: linear-gradient(to right, rgba(255,255,255,1) 20%, rgba(255,255,255,0));
}
.mapping-table-container::after {
  right: 0;
  background: linear-gradient(to left, rgba(255,255,255,1) 20%, rgba(255,255,255,0));
}

/* Icons within faders */
.mapping-table-container.is-scrollable-left::before,
.mapping-table-container.is-scrollable-right::after {
  opacity: 1; /* Show fader when scrollable in that direction */
}

.mapping-table-container.is-scrollable-left::before::after, /* Using ::after on the ::before */
.mapping-table-container.is-scrollable-right::after::after { /* Using ::after on the ::after */
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5rem; /* Adjust icon size */
    color: #0066ff; /* Icon color */
    font-weight: bold;
    opacity: 0.7;
}
.mapping-table-container.is-scrollable-left::before::after {
    content: '‹'; /* Left chevron */
    left: 5px;
}
.mapping-table-container.is-scrollable-right::after::after {
    content: '›'; /* Right chevron */
    right: 5px;
}


/* Table Wrapper and Positioning */
.mapping-table-wrapper {
  position: relative;
  background-color: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  min-height: 200px;
}

/* Overlay Container */
#mapping-bankColumnOverlays,
#mapping-bookColumnOverlays {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 20px; /* Leave space for horizontal scrollbar */
  pointer-events: none; 
  z-index: 2; 
  transform: translateX(0);
  /* Let overlays be visible and functional, even if it creates a second scrollbar */
  overflow: visible;
}

table {
  width: max-content; /* Size to content width */
  min-width: 100%; /* Ensure it fills container minimum */
  border-collapse: collapse;
  font-size: 0.9rem; /* Slightly smaller table text */
  table-layout: auto; /* Allow columns to size based on content and overlays */
}
th {
  padding: 0.6rem 0.75rem; /* Adjusted padding */
  background-color: #f0f5fa; /* Lighter header background */
  border: 1px solid #ddd;
  position: relative; /* For overlay positioning reference if needed */
  text-align: left; /* Align header text left */
  font-weight: 500; /* Slightly less bold */
  color: #333;
  white-space: nowrap; /* Prevent header text wrapping */
  min-width: 100px; /* Ensure reasonable minimum width */
  max-width: 200px; /* Prevent excessively wide columns */
}

/* Sample Transaction Rows */
.mapping-sample-rows {
  font-size: 0.8rem; /* Smaller sample text */
  color: #444;
  background: #fff;
}
.mapping-sample-rows td {
  padding: 0.4rem 0.75rem; /* Adjusted padding */
  border: 1px solid #e0e0e0;
  white-space: nowrap; /* Keep sample data on one line if possible */
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 100px; /* Ensure minimum readable width */
  max-width: 250px; /* Increased max width for better readability */
}

/* Column Overlays */
.mapping-column-overlay {
  position: absolute;
  top: 0;
  height: 100%;
  background-color: rgba(30, 58, 138, 0.15);
  border: 3px solid #1e3a8a;
  border-radius: 8px;
  pointer-events: auto;
  cursor: grab;
  transition: all 0.2s ease;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.5rem;
}

.mapping-column-overlay:hover {
  background-color: rgba(30, 58, 138, 0.25);
  border-color: #1d4ed8;
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.4);
}

.mapping-column-overlay.dragging {
  opacity: 0.8;
  cursor: grabbing;
  z-index: 20;
  transform: rotate(2deg);
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.5);
}

.mapping-column-overlay::after {
  content: attr(data-type);
  font-size: 0.75rem;
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Drop Target Highlighting */
.mapping-drop-target {
  background-color: rgba(30, 58, 138, 0.2) !important;
  border-color: #1e3a8a !important;
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.3) !important;
}

/* Footer */
.mapping-footer {
  flex-shrink: 0;
  padding: 0.85rem 1rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.mapping-error-message {
  color: #dc2626;
  background-color: #fef2f2;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #fecaca;
  font-size: 0.8rem;
  font-weight: 500;
}

.mapping-confirm-mapping {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: white;
  border: none;
  padding: 0.65rem 1.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  align-self: center;
  box-shadow: 0 3px 8px rgba(30, 58, 138, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.mapping-confirm-mapping:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(30, 58, 138, 0.4);
}

.mapping-confirm-mapping:active {
  transform: translateY(0);
  box-shadow: 0 3px 8px rgba(30, 58, 138, 0.3);
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 768px) {
  .mapping-modal-container {
    max-width: 98vw;
    max-height: 98vh;
    padding: 1rem;
    margin: 0.5rem;
  }
  
  .mapping-section {
    padding: 0.75rem;
    min-height: 150px;
  }
  
  .mapping-table-wrapper {
    min-height: 100px; /* Reduced since showing fewer rows */
  }
  
  .mapping-sample-rows td {
    min-width: 80px;
    max-width: 150px;
    font-size: 0.75rem;
  }
  
  th {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
  }
  
  .mapping-confirm-mapping {
    padding: 0.6rem 1.5rem;
    font-size: 0.9rem;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .mapping-modal-container {
    padding: 0.75rem;
  }
  
  .mapping-section h3 {
    font-size: 1rem;
  }
  
  .mapping-sample-rows td {
    min-width: 60px;
    max-width: 120px;
  }
}

/* High zoom levels and very small screens */
@media (max-height: 600px) {
  .mapping-modal-container {
    max-height: 98vh;
    padding: 0.75rem 1rem;
  }
  
  .mapping-section {
    min-height: 140px;
    padding: 0.75rem 1rem;
  }
  
  .mapping-table-wrapper {
    min-height: 90px;
  }
  
  .mapping-modal-header h2 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
  }
  
  .mapping-instruction {
    font-size: 0.8rem;
    margin-bottom: 1rem;
  }
}

/* Very high zoom or extremely constrained screens */
@media (max-height: 450px) {
  .mapping-modal-container {
    max-height: 99vh;
    padding: 0.5rem;
  }
  
  .mapping-section {
    min-height: 120px;
    padding: 0.5rem;
  }
  
  .mapping-table-wrapper {
    min-height: 80px;
  }
  
  .mapping-footer {
    padding-top: 0.75rem;
  }
}

/* NEW: Mapping Quality Indicator Styles */
.mapping-quality-indicator {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
  overflow: hidden;
}

.quality-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.quality-score {
  font-size: 0.9rem;
  color: #2d3748;
  font-weight: 500;
  margin-bottom: 0.5rem;
  text-align: center;
}

.quality-score strong {
  color: #2d3748;
  font-size: 1.1rem;
  font-weight: 700;
  display: block;
  line-height: 1;
  margin: 0.25rem 0;
}

.quality-status {
  font-size: 0.85rem;
  color: #4a5568;
  font-weight: 500;
  text-align: center;
}

.quality-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.quality-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem;
  padding: 1rem;
  background: #f7fafc;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
}

.quality-panel:hover {
  background: #edf2f7;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.panel-label {
  font-weight: 600;
  color: #2d3748;
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.panel-quality {
  font-size: 0.7rem;
  color: #4a5568;
  font-weight: 500;
  text-align: center;
}

/* Quality score glow effects - subtle outlines only */
.mapping-quality-indicator.high {
  border-color: #48bb78;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(72, 187, 120, 0.2);
}

.mapping-quality-indicator.medium {
  border-color: #ed8936;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(237, 137, 54, 0.2);
}

.mapping-quality-indicator.low {
  border-color: #f56565;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(245, 101, 101, 0.2), 0 0 20px rgba(245, 101, 101, 0.1);
}

/* Subtle animations */
.quality-score.high {
  animation: pulse-success 3s infinite;
}

@keyframes pulse-success {
  0%, 100% { 
    transform: scale(1);
  }
  50% { 
    transform: scale(1.02);
  }
}

/* Required column missing indicators */
.mapping-toggle-button.required-missing {
  background-color: #fed7d7 !important;
  color: #c53030 !important;
  border: 2px solid #e53e3e !important;
  animation: pulse-missing 2s infinite;
}

@keyframes pulse-missing {
  0%, 100% { 
    background-color: #fed7d7; 
    border-color: #e53e3e;
  }
  50% { 
    background-color: #fbb6ce; 
    border-color: #d53f8c;
  }
}

.mapping-toggle-button.required-missing:hover {
  background-color: #fc8181 !important;
  transform: scale(1.05);
}