/* ==========================================================================
   Unilever Duplicate Coordinates Detection Tool - Stylesheet
   ========================================================================== */

:root {
  --primary: #1f36c7;
  --primary-hover: #15269b;
  --primary-light: #e0e7ff;
  --primary-dark: #121e7b;
  --secondary: #475569;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --danger-dark: #991b1b;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --success: #16a34a;
  --success-light: #dcfce7;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Layout & Header ---------------- */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  color: #fff;
  padding: 0.85rem 1.5rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 2px solid #312e81;
}

.header-container {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-logo-img {
  height: 42px;
  width: auto;
  max-width: 130px;
  object-fit: contain;
  display: block;
  background: white;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.025em;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: #38bdf8;
  font-weight: 500;
  letter-spacing: 0.015em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ---------------- Main Container ---------------- */
.main-content {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---------------- Upload & Stats Section ---------------- */
.stats-and-upload-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.25rem;
}

@media (max-width: 1024px) {
  .stats-and-upload-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: white;
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}

/* Upload Dropzone */
.dropzone {
  border: 2px dashed #3b82f6;
  background: #f8fafc;
  border-radius: var(--radius-md);
  padding: 1.75rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.dropzone:hover, .dropzone.dragover {
  background: #eff6ff;
  border-color: #1d4ed8;
  transform: translateY(-1px);
}

.dropzone-icon {
  font-size: 2.5rem;
  color: #2563eb;
}

.dropzone-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray-800);
}

.dropzone-subtitle {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.file-input-hidden {
  display: none;
}

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.stat-box {
  background: white;
  border-radius: var(--radius-md);
  padding: 1rem;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  transition: transform 0.2s;
}

.stat-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon-blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon-red { background: #fee2e2; color: #dc2626; }
.stat-icon-amber { background: #fef3c7; color: #d97706; }
.stat-icon-purple { background: #f3e8ff; color: #7e22ce; }
.stat-icon-green { background: #dcfce7; color: #15803d; }

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
}

.stat-subtext {
  font-size: 0.7rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ---------------- Tabs & Controls ---------------- */
.view-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-bottom: 2px solid var(--gray-200);
  padding-bottom: 0.5rem;
}

.tabs-group {
  display: flex;
  gap: 0.5rem;
}

.tab-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: white;
  color: var(--gray-600);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.tab-button:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

.tab-button.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(31, 54, 199, 0.35);
}

.badge-tab {
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 6px;
  border-radius: 9999px;
  font-size: 0.75rem;
}

.tab-button:not(.active) .badge-tab {
  background: var(--gray-200);
  color: var(--gray-700);
}

/* ---------------- Filter Bar ---------------- */
.filter-toolbar {
  background: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-input-wrapper input {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-300);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 54, 199, 0.15);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 0.9rem;
}

.filter-select {
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-300);
  font-size: 0.875rem;
  background: white;
  color: var(--gray-700);
  outline: none;
  cursor: pointer;
}

.filter-select:focus {
  border-color: var(--primary);
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover {
  background: var(--danger-dark);
}

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover {
  background: #15803d;
}

.btn-secondary {
  background: white;
  border-color: var(--gray-300);
  color: var(--gray-700);
}
.btn-secondary:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

.btn-outline {
  background: transparent;
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline:hover {
  background: var(--primary-light);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
}

/* ---------------- Map Section ---------------- */
.map-view-container {
  display: flex;
  flex-direction: column;
  height: 680px;
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-md);
}

.map-header-bar {
  padding: 0.6rem 1rem;
  background: var(--gray-900);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  z-index: 500;
}

#map {
  flex: 1;
  width: 100%;
  height: 100%;
  z-index: 10;
}

.map-legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-200);
  z-index: 800;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot-red { background: #ef4444; border: 2px solid #b91c1c; }
.dot-amber { background: #f59e0b; border: 2px solid #b45309; }
.dot-purple { background: #8b5cf6; border: 2px solid #6d28d9; }

/* ---------------- Side-by-Side Comparison UI ---------------- */
.comparison-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.comparison-card {
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.comparison-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--gray-300);
}

.comparison-card-header {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.group-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--danger-light);
  color: var(--danger-dark);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  border: 1px solid #fca5a5;
}

.coord-pill {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  background: var(--gray-200);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--gray-800);
  font-weight: 600;
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  divide-x: 1px solid var(--gray-200);
}

@media (max-width: 900px) {
  .comparison-grid {
    grid-template-columns: 1fr;
  }
}

.original-panel {
  padding: 1rem;
  background: #fcfdfe;
  border-right: 1px solid var(--gray-200);
}

.duplicate-panel {
  padding: 1rem;
  background: #fffafa;
}

.panel-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title-primary {
  color: var(--primary);
}

.title-duplicate {
  color: var(--danger);
}

.outlet-record-box {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.outlet-record-box.duplicate-item {
  border-left: 4px solid var(--danger);
}

.outlet-record-box.primary-item {
  border-left: 4px solid var(--primary);
}

.record-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.825rem;
  margin-bottom: 0.35rem;
}

.record-label {
  color: var(--gray-500);
  font-weight: 500;
}

.record-val {
  font-weight: 600;
  color: var(--gray-900);
  text-align: right;
  word-break: break-word;
}

.dt-badge {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.dt-mismatch-badge {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #f87171;
  font-size: 0.7rem;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 700;
}

/* ---------------- Table View ---------------- */
.table-wrapper {
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.data-table th {
  background: var(--gray-50);
  color: var(--gray-700);
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

.data-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  color: var(--gray-800);
}

.data-table tr:hover td {
  background: #f8fafc;
}

.data-table tr.row-duplicate-cluster {
  background: #fffbfb;
}

/* ---------------- Map Popups ---------------- */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-xl) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
  min-width: 290px;
  max-width: 380px;
}

.popup-container {
  padding: 0.85rem;
}

.popup-header {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: white;
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.popup-title {
  font-weight: 700;
  font-size: 0.85rem;
}

.popup-badge {
  background: #ef4444;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 9999px;
}

.popup-outlets-list {
  max-height: 240px;
  overflow-y: auto;
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.popup-outlet-item {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  font-size: 0.78rem;
}

.popup-outlet-item:first-child {
  border-left: 3px solid var(--primary);
}

.popup-outlet-item:not(:first-child) {
  border-left: 3px solid var(--danger);
}

.popup-actions {
  margin-top: 0.5rem;
  border-top: 1px solid var(--gray-200);
  padding-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

/* ---------------- Modals ---------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  padding: 1rem;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.2s;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-overlay.active .modal-box {
  transform: translateY(0);
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--gray-50);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  background: var(--gray-50);
}

/* ---------------- Loading Overlay ---------------- */
.loading-indicator {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
  gap: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.loading-indicator.active {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------------- Pagination ---------------- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  font-size: 0.85rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ---------------- Custom Leaflet Marker Badges ---------------- */
.custom-map-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #dc2626;
  color: white;
  font-weight: 700;
  font-size: 11px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.custom-map-marker:hover {
  transform: scale(1.18);
}

.custom-map-marker.cluster-sm { width: 26px; height: 26px; background: #ea580c; }
.custom-map-marker.cluster-md { width: 32px; height: 32px; background: #dc2626; font-size: 12px; }
.custom-map-marker.cluster-lg { width: 38px; height: 38px; background: #991b1b; font-size: 13px; border-width: 3px; }

/* ---------------- Utilities ---------------- */
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.font-mono { font-family: ui-monospace, monospace; }
.hidden { display: none !important; }
