/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --panel-width: 380px;
  --search-height: 48px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --cyan-600: #0891b2;
  --blue-600: #0284c7;
  --purple-500: #8b5cf6;
  --green-500: #22c55e;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: var(--font);
  color: var(--gray-800);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ===== Map ===== */
#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ===== Panel (Desktop) ===== */
#panel {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: var(--panel-width);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#panel-header {
  padding: 16px 16px 0;
  flex-shrink: 0;
}

#drag-handle {
  display: none;
}

/* ===== Search Bar ===== */
#search-bar {
  display: flex;
  align-items: center;
  height: var(--search-height);
  background: var(--gray-100);
  border-radius: 24px;
  padding: 0 8px 0 16px;
  gap: 8px;
}

#search-bar .search-icon {
  color: var(--gray-400);
  font-size: 22px;
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-800);
  outline: none;
  min-width: 0;
}

#search-input::placeholder {
  color: var(--gray-400);
}

#locate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  border-radius: 50%;
  color: var(--gray-500);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

#locate-btn:hover {
  background: var(--gray-200);
  color: var(--indigo-600);
}

/* ===== Search Clear Button ===== */
#search-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: 50%;
  color: var(--gray-400);
  cursor: pointer;
  flex-shrink: 0;
}

#search-clear:hover {
  background: var(--gray-200);
  color: var(--gray-600);
}

#search-clear .material-symbols-outlined {
  font-size: 18px;
}

#search-clear.hidden {
  display: none;
}

/* ===== Search Feedback ===== */
#search-feedback {
  font-size: 12px;
  color: var(--gray-500);
  padding: 4px 0;
}

#search-feedback.hidden {
  display: none;
}

#search-feedback.error {
  color: var(--red-500);
}

/* ===== Category Filters ===== */
#category-filters {
  display: flex;
  gap: 6px;
  padding: 12px 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

#category-filters::-webkit-scrollbar {
  display: none;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  border: 1.5px solid var(--chip-color);
  background: var(--chip-color);
  color: #fff;
  transition: all 0.15s;
  user-select: none;
}

.cat-chip.off {
  background: #fff;
  color: var(--chip-color);
}

.cat-chip .chip-count {
  font-size: 11px;
  opacity: 0.8;
}

/* ===== Results Summary ===== */
#results-summary {
  font-size: 12px;
  color: var(--gray-500);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}

/* ===== Card List ===== */
#card-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px;
  scroll-behavior: smooth;
}

#card-list::-webkit-scrollbar {
  width: 4px;
}

#card-list::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 4px;
}

/* ===== Outlet Card (simple list row) ===== */
.outlet-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background 0.1s;
}

.outlet-card:last-child {
  border-bottom: none;
}

.outlet-card:hover {
  background: var(--gray-50);
}

.outlet-card.selected {
  background: var(--gray-50);
}

.outlet-card.revoked {
  opacity: 0.55;
}

.card-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.card-icon .material-symbols-outlined {
  font-size: 16px;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-address {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.card-distance {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 500;
}

/* Expandable details — hidden by default, shown when card is selected */
.card-details {
  display: none;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--gray-100);
}

.outlet-card.selected .card-details {
  display: flex;
}

/* ===== Action Buttons (shared by card details + popup) ===== */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 16px;
  font-size: 12px !important;
  font-weight: 500;
  font-family: var(--font);
  color: var(--gray-700) !important;
  background: var(--gray-100);
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
  line-height: 1.2 !important;
}

.action-btn:hover {
  background: var(--gray-200);
}

.action-btn .material-symbols-outlined {
  font-size: 15px !important;
  color: var(--gray-700) !important;
}

.new-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: #15803d;
  background: #f0fdf4;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.revoked-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: var(--red-600);
  background: #fef2f2;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

/* ===== Map Popup ===== */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm) !important;
  font-family: var(--font) !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-popup-content {
  margin: 12px 16px !important;
  font-size: 13px !important;
  line-height: 1.4 !important;
  width: 240px !important;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.popup-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--gray-900);
}

.popup-address {
  color: var(--gray-500);
  font-size: 12px;
  margin-top: 4px;
}

.popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.popup-new {
  color: #15803d;
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}

.popup-revoked {
  color: var(--red-600);
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}

/* ===== Changes Badge & Panel ===== */
#changes-badge {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  background: #fff;
  border-radius: 24px;
  padding: 8px 16px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}

#changes-badge:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

#changes-badge.hidden {
  display: none;
}

#changes-panel {
  position: fixed;
  bottom: 72px;
  right: 24px;
  z-index: 1001;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 320px;
  max-height: 400px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#changes-panel.hidden {
  display: none;
}

#changes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
}

#changes-header h3 {
  font-size: 14px;
  font-weight: 600;
}

#changes-close {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--gray-400);
  display: flex;
  align-items: center;
}

#changes-list {
  overflow-y: auto;
  padding: 8px 16px;
  max-height: 340px;
}

.change-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
}

.change-item:last-child {
  border-bottom: none;
}

.change-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.change-dot.added { background: var(--green-500); }
.change-dot.removed { background: var(--gray-400); }
.change-dot.revoked { background: var(--red-500); }
.change-dot.unrevoked { background: var(--green-500); }

.change-info {
  flex: 1;
  min-width: 0;
}

.change-name {
  font-weight: 500;
  color: var(--gray-800);
}

.change-detail {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
}

/* ===== Panel Footer ===== */
#panel-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--gray-100);
  font-size: 11px;
  color: var(--gray-400);
  flex-shrink: 0;
  text-align: center;
}

#panel-footer:empty {
  display: none;
}

/* ===== Revoked Filter Chip ===== */
.revoked-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  border: 1.5px solid var(--gray-300);
  background: #fff;
  color: var(--gray-500);
  transition: all 0.15s;
  user-select: none;
}

.revoked-chip.active {
  border-color: var(--red-500);
  background: var(--red-500);
  color: #fff;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state .material-symbols-outlined {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.3s;
}

.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--indigo-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 14px;
  color: var(--gray-500);
  font-weight: 500;
}

/* ===== Mobile (Bottom Sheet) ===== */
@media (max-width: 768px) {
  #panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(calc(100% - 140px));
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    max-height: 85vh;
    will-change: transform;
  }

  #panel.sheet-half {
    transform: translateY(50%);
  }

  #panel.sheet-full {
    transform: translateY(0);
  }

  #panel.dragging {
    transition: none;
  }

  #drag-handle {
    display: flex;
    justify-content: center;
    padding: 8px 0 4px;
    cursor: grab;
  }

  #drag-handle::after {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--gray-300);
  }

  #panel-header {
    padding: 8px 16px 0;
  }

  /* Changes badge above the sheet */
  #changes-badge {
    bottom: 148px;
    right: 16px;
  }

  #changes-panel {
    bottom: 196px;
    right: 16px;
    left: 16px;
    width: auto;
  }
}

/* ===== Leaflet DivIcon (map markers) ===== */
.map-pin {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  position: relative;
  overflow: hidden;
}

.map-pin .material-symbols-outlined {
  font-size: 14px;
  color: #fff;
}

/* Revoked: grey with diagonal strikethrough */
.map-pin.revoked {
  background: #9ca3af !important;
}

.map-pin.revoked::after {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 1.5px),
    #fff calc(50% - 1.5px),
    #fff calc(50% + 1.5px),
    transparent calc(50% + 1.5px)
  );
}
