*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #333;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  height: 100vh;
  position: relative;
}

/* Sidebar toggle – visible only on mobile */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #1e3a5f;
  border-radius: 8px;
  background: #1e3a5f;
  box-shadow: 0 2px 12px rgba(30, 58, 95, 0.35);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.sidebar-toggle:hover {
  background: #2c4a6f;
  border-color: #2c4a6f;
  box-shadow: 0 4px 16px rgba(30, 58, 95, 0.4);
}
.sidebar-toggle:active {
  box-shadow: 0 1px 6px rgba(30, 58, 95, 0.45);
}
.sidebar-toggle::before {
  content: '';
  display: block;
  width: 20px;
  height: 14px;
  margin: auto;
  border-top: 2px solid #fff;
  border-bottom: 2px solid #fff;
  box-shadow: 0 5px 0 0 #fff;
  flex-shrink: 0;
}
.sidebar-toggle[aria-expanded="false"]::before {
  width: 18px;
  height: 2px;
  border: none;
  box-shadow: none;
  background: #fff;
  border-radius: 1px;
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 280px;
  background: #f5f5f5;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.sidebar h1 {
  margin: 0;
  padding: 1.25rem 1.25rem 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1.3;
}

.instruction {
  margin: 0;
  padding: 0 1.25rem 1rem;
  font-size: 0.875rem;
  color: #555;
  line-height: 1.4;
}

.poi-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 1rem;
}

.poi-error {
  padding: 1rem 1.25rem;
  color: #b91c1c;
  font-size: 0.875rem;
  line-height: 1.4;
}

.poi-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.poi-list li {
  margin: 0;
  padding: 0;
  border-bottom: 1px solid #e8e8e8;
}

.poi-list a,
.poi-list .category-label {
  display: block;
  padding: 0.75rem 1.25rem;
  color: #333;
  text-decoration: none;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.poi-list a:hover {
  background: #ebebeb;
  color: #1a1a1a;
}

.poi-list a.active {
  background: #1e3a5f;
  color: #fff;
}

.poi-list .sub-category {
  padding-left: 1.5rem;
}

.poi-list .category-label {
  font-weight: 700;
  cursor: default;
  color: #333;
}

/* Map panel */
.map-panel {
  flex: 1;
  position: relative;
  min-width: 0;
}

.map {
  width: 100%;
  height: 100%;
  background: #e8e8e8;
}

/* Leaflet overrides for cleaner look */
.leaflet-popup-content-wrapper {
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 0.75rem 1rem;
  font-size: 0.875rem;
}

/* Location pin image - preserve aspect ratio, no stretch */
.location-pin-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
}

/* Tooltip / bubble with location name – professional style */
.leaflet-tooltip.poi-label {
  margin-bottom: 26px;
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: #111827;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.06),
    0 6px 16px rgba(0, 0, 0, 0.1);
  max-width: 320px;
  min-width: 200px;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: visible;
  text-align: left;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

/* Category icons in tooltip */
.leaflet-tooltip.poi-label .poi-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: 0;
  font-style: normal;
  line-height: 1;
  vertical-align: top;
}
.leaflet-tooltip.poi-label .poi-icon::before {
  font-size: 1.25em;
  line-height: 1;
}
.leaflet-tooltip.poi-label .poi-label-text {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
  word-break: normal;
  overflow-wrap: break-word;
}
.poi-icon-head-office::before { content: '🏢'; }
.poi-icon-layby::before { content: '🅿️'; }
.poi-icon-petrol-station::before { content: '⛽'; }
.poi-icon-reload-centre::before { content: '💳'; }
.poi-icon-points-of-interest::before { content: '📍'; }
.poi-icon-toll-plaza::before { content: '🛣️'; }
.poi-icon-pa-mosque::before { content: '🕌'; }
.poi-icon-pa-transport::before { content: '🚉'; }
.poi-icon-pa-parks::before { content: '🏞️'; }
.poi-icon-pa-schools::before { content: '🏫'; }
.poi-icon-pa-hospitals::before { content: '🏥'; }
.poi-icon-pa-emergency::before { content: '🚒'; }
.poi-icon-pa-default::before { content: '📍'; }

.leaflet-tooltip.poi-label::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -8px;
  margin-left: -8px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #fff;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.06));
}

.leaflet-tooltip-top.poi-label::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -7px;
  margin-left: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid #e5e7eb;
  z-index: -1;
}

/* ========== Responsive / Mobile ========== */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    width: min(320px, 100vw - 24px);
    min-width: 0;
    max-width: 100%;
    border-right: 1px solid #e0e0e0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.08);
  }

  .sidebar.is-hidden {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .map-panel {
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  .map {
    min-height: 300px;
  }

  /* Touch-friendly list items */
  .poi-list a,
  .poi-list .category-label {
    padding: 0.875rem 1.25rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .poi-list .sub-category a {
    padding-left: 1.5rem;
  }

  /* Tooltip fits small screens */
  .leaflet-tooltip.poi-label {
    max-width: min(320px, calc(100vw - 32px));
    min-width: 160px;
    padding: 12px 14px;
    font-size: 12px;
  }

  .leaflet-popup-content {
    font-size: 0.8125rem;
    margin: 0.5rem 0.75rem;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  .leaflet-tooltip.poi-label {
    max-width: calc(100vw - 24px);
    min-width: 140px;
  }

  .poi-list a,
  .poi-list .category-label {
    padding: 0.875rem 1rem;
    font-size: 0.9rem;
  }
}

/* Safe area for notched devices */
@supports (padding: env(safe-area-inset-left)) {
  .sidebar-toggle {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
  }

  @media (max-width: 768px) {
    .sidebar {
      padding-left: env(safe-area-inset-left);
    }
  }
}
