/* ===== Shelter Finder Qatar — Design System ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0a0f1a;
  --bg-secondary: #111827;
  --bg-card: #1a2234;
  --bg-card-hover: #1f2b42;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-red: #dc2626;
  --accent-red-glow: rgba(220, 38, 38, 0.3);
  --accent-green: #22c55e;
  --accent-green-glow: rgba(34, 197, 94, 0.2);
  --accent-blue: #3b82f6;
  --accent-blue-glow: rgba(59, 130, 246, 0.2);
  --accent-orange: #f59e0b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(59, 130, 246, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Alert Banner ===== */
.alert-banner {
  width: 100%;
  padding: 10px 16px;
  text-align: center;
  font-weight: 700;
  font-size: 0.85em;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.alert-banner.active {
  background: linear-gradient(90deg, #991b1b, #dc2626, #991b1b);
  color: #fff;
  animation: alertPulse 1.5s ease-in-out infinite;
}

.alert-banner.inactive {
  background: var(--bg-secondary);
  color: var(--accent-green);
  border-bottom: 1px solid var(--border-color);
}

@keyframes alertPulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.app-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header .logo-icon {
  font-size: 1.6em;
}

.app-header .logo-text h1 {
  font-size: 1.1em;
  font-weight: 800;
  color: var(--text-primary);
}

.app-header .logo-text p {
  font-size: 0.7em;
  color: var(--text-muted);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-sm {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.78em;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-sm:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* ===== Hero Button ===== */
.hero-section {
  padding: 16px;
}

.find-nearest-btn {
  width: 100%;
  padding: 18px 24px;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 1.15em;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.find-nearest-btn.default {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-green-glow);
}

.find-nearest-btn.default:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px var(--accent-green-glow);
}

.find-nearest-btn.alert {
  background: linear-gradient(135deg, #b91c1c, #dc2626);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-red-glow);
  animation: heroAlertPulse 1s ease-in-out infinite;
}

@keyframes heroAlertPulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.02);
  }
}

.find-nearest-btn:active {
  transform: scale(0.98);
}

.location-note {
  display: block;
  font-size: 0.78em;
  color: var(--text-muted);
  text-align: center;
  margin-top: 10px;
  font-style: italic;
  font-weight: 500;
}

.find-nearest-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  animation: none;
  transform: none;
}

/* ===== Route Info Bar ===== */
.route-info {
  display: none;
  margin: 0 16px 12px;
  padding: 16px 18px;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.14), transparent 40%),
    linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(59, 130, 246, 0.04));
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  gap: 14px;
  align-items: stretch;
  justify-content: space-between;
  flex-wrap: wrap;
  box-shadow: 0 10px 30px rgba(2, 8, 23, 0.24);
}

.route-info.visible {
  display: flex;
}

.route-info .route-stat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  min-width: 96px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.route-info .route-stat .value {
  order: 2;
  font-size: 1.55em;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #60a5fa;
  text-wrap: balance;
}

.route-info .route-stat .label {
  order: 1;
  font-size: 0.68em;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 700;
  opacity: 0.88;
}

.route-info .route-stat:nth-child(3) {
  order: -1;
  flex: 1.2 1 250px;
}

.route-info .route-stat:nth-child(3) .value {
  font-size: 1.08em;
  line-height: 1.3;
  color: var(--text-primary);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.route-info .route-stat:nth-child(1) .value,
.route-info .route-stat:nth-child(2) .value {
  text-shadow: 0 0 18px rgba(59, 130, 246, 0.16);
}

.route-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.route-info .gmaps-btn {
  padding: 10px 16px;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 0.82em;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font);
  transition: background 0.2s, transform 0.2s;
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.22);
}

.route-info .gmaps-btn:hover {
  background: #2563eb;
  transform: translateY(-1px);
}

.route-info .clear-btn {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.route-info .clear-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* ===== Map ===== */
.map-container {
  margin: 0 16px 16px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  position: relative;
}

#map {
  width: 100%;
  height: 380px;
}

.map-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 16px 16px;
}

.map-control-btn {
  padding: 11px 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.82em;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s ease;
}

.map-control-btn:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.14);
}

.map-control-btn:active {
  transform: scale(0.98);
}

/* Custom map markers */
.custom-marker {
  background: none !important;
  border: none !important;
}

.marker-shelter {
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  transition: transform 0.2s;
}

.marker-nearest {
  font-size: 36px;
  filter: drop-shadow(0 2px 6px rgba(220, 38, 38, 0.5));
  animation: markerBounce 1s ease-in-out infinite;
}

.marker-user {
  width: 14px;
  height: 14px;
  background: var(--accent-blue);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.8), 0 0 0 4px rgba(59, 130, 246, 0.3);
}

.true-compass {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  background: rgba(26, 34, 52, 0.85);
  /* semi-transparent card background */
  border: 2px solid var(--border-color);
  border-radius: 50%;
  z-index: 1000;
  /* Above Leaflet map */
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s linear;
  color: var(--text-primary);
  font-size: 10px;
  font-weight: 700;
  backdrop-filter: blur(4px);
}

.true-compass::after {
  /* North Needle */
  content: '';
  position: absolute;
  top: 6px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 12px solid var(--accent-red);
}

.c-n {
  position: absolute;
  top: 3px;
  color: var(--accent-red);
  font-size: 11px;
  z-index: 2;
  opacity: 0;
}

.c-e {
  position: absolute;
  right: 4px;
}

.c-s {
  position: absolute;
  bottom: 2px;
}

.c-w {
  position: absolute;
  left: 4px;
}

@keyframes markerBounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

/* Map popups */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
}

.popup-content {
  font-size: 0.88em;
  line-height: 1.8;
}

.popup-content strong {
  font-size: 1em;
  color: var(--text-primary);
}

.popup-type {
  color: var(--text-muted);
  font-size: 0.85em;
}

.popup-nav-link {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 12px;
  background: var(--accent-blue);
  color: #fff !important;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.85em;
  font-weight: 600;
}

/* ===== Shelter List ===== */
.shelter-list-section {
  padding: 0 16px 16px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 40px;
  background: var(--bg-card) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%2394a3b8" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/></svg>') no-repeat 14px center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95em;
  outline: none;
  transition: all 0.2s;
}

[dir="rtl"] .search-input {
  padding: 12px 40px 12px 16px;
  background-position: calc(100% - 14px) center;
}

.search-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.section-title {
  font-size: 1em;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.shelter-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shelter-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.shelter-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.12);
}

.shelter-card.active {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.08);
  box-shadow: 0 0 0 1px var(--accent-blue);
}

.shelter-card .card-icon {
  font-size: 2em;
  flex-shrink: 0;
}

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

.shelter-card .card-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.shelter-card .card-name {
  font-weight: 700;
  font-size: 0.92em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shelter-card .card-type {
  font-size: 0.78em;
  color: var(--text-muted);
}

.shelter-card .card-facilities {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
  max-width: 260px; /* Encourages wrapping into 2 lines */
}

.shelter-card .facility-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.16);
  color: var(--text-secondary);
  font-size: 0.64em; /* Slightly smaller to fit Better */
  font-weight: 600;
  line-height: 1.2;
}

.shelter-card .facility-chip-icon {
  font-size: 1em;
  line-height: 1;
}

.shelter-card .status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.72em;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.shelter-card .status-badge.status-verified {
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.22);
}

.shelter-card .status-badge.status-unverified {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.24);
}

.shelter-card .card-stats {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  font-size: 0.78em;
  color: var(--text-secondary);
}

.shelter-card .card-navigate {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.78em;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.2s;
  white-space: nowrap;
}

.shelter-card .card-navigate:hover {
  background: #2563eb;
}

/* ===== Emergency Contacts ===== */
.emergency-section {
  padding: 0 16px 24px;
}

.emergency-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.emergency-card {
  text-align: center;
  padding: 16px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s;
}

.emergency-card:hover {
  background: var(--bg-card-hover);
}

.emergency-card .emerg-icon {
  font-size: 1.8em;
  display: block;
  margin-bottom: 6px;
}

.emergency-card .emerg-label {
  font-size: 0.72em;
  color: var(--text-muted);
  display: block;
}

.emergency-card .emerg-number {
  font-size: 1.2em;
  font-weight: 800;
  color: var(--accent-red);
}

/* ===== Footer ===== */
.app-footer {
  padding: 16px;
  text-align: center;
  border-top: 1px solid var(--border-color);
}

.app-footer .disclaimer {
  font-size: 0.75em;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== Status Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 10px 20px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  font-size: 0.82em;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transition: transform 0.3s ease;
  white-space: normal;
  text-align: center;
  max-width: 320px;
  width: calc(100% - 32px);
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

.back-to-map-btn {
  position: fixed;
  right: 16px;
  bottom: 88px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(59, 130, 246, 0.24);
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.92);
  color: #bfdbfe;
  font-size: 1.05em;
  font-weight: 900;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
  z-index: 2100;
}

.back-to-map-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-map-btn:hover {
  background: rgba(31, 43, 66, 0.98);
}

/* ===== Location Overlay ===== */
.location-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 15, 26, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.location-overlay.hidden {
  display: none !important;
}

.location-card {
  background: var(--bg-card);
  padding: 30px 24px;
  border-radius: var(--radius-xl);
  text-align: center;
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-active);
  max-width: 400px;
  width: 100%;
}

.location-card .icon {
  font-size: 3.5em;
  margin-bottom: 12px;
  animation: markerBounce 2s ease-in-out infinite;
}

.location-card h3 {
  font-size: 1.3em;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.location-card p {
  color: var(--text-muted);
  font-size: 0.9em;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 1em;
  font-weight: 700;
  width: 100%;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-text {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 0.9em;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  transition: color 0.2s;
  font-family: var(--font);
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ===== Category Filters & Count ===== */
.category-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

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

.filter-btn {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  color: var(--text-muted);
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  transition: all 0.2s ease;
}

.filter-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

.list-count {
  font-size: 0.85em;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding: 0 4px;
}

/* ===== RTL Support ===== */
[dir="rtl"] .app-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .app-header .logo {
  flex-direction: row-reverse;
}

[dir="rtl"] .app-header .logo-text {
  text-align: right;
}

[dir="rtl"] .header-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .shelter-card {
  flex-direction: row-reverse;
}

[dir="rtl"] .shelter-card .card-info {
  text-align: right;
}

[dir="rtl"] .shelter-card .card-actions {
  align-items: flex-start;
}

[dir="rtl"] .shelter-card .card-stats {
  flex-direction: row-reverse;
}

[dir="rtl"] .shelter-card .card-facilities {
  flex-direction: row-reverse;
}

[dir="rtl"] .route-info {
  flex-direction: row-reverse;
}

[dir="rtl"] .section-title {
  text-align: right;
}

[dir="rtl"] .map-controls {
  direction: rtl;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  #map {
    height: 300px;
  }

  .map-controls {
    grid-template-columns: 1fr;
  }

  .emergency-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .shelter-card .card-navigate {
    padding: 6px 10px;
    font-size: 0.72em;
  }
}

@media (min-width: 768px) {
  body {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
  }

  #map {
    height: 450px;
  }
}

/* ===== Loading Spinner ===== */
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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