/**
 * Quadra Business Directory - UI/UX Refactor Phase 2
 * Implements "Quadra Ferry UI_UX_Business.txt" Requirements
 */

/* 1. VARIABLES & RESET */
:root {
  /* Brand Core */
  --primary-blue: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --accent-color: #3b82f6;

  /* Modern Palette */
  --bg-page: #f1f5f9;
  /* Slightly darker than white for glassmorphism contrast */
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --border-color: #e2e8f0;

  /* Safe Area Insets */
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);

  /* Transitions */
  --ease-spring: cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  margin: 0;
  padding: 0;
}

/* 2. HEADER */
.header {
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  padding-top: calc(1rem + var(--safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  /* Kept flex for header layout */
  align-items: center;
  justify-content: space-between;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
}

.site-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Enhanced CTA from Phase 1 (Kept as it aligns with new requirements) */
.back-button {
  position: relative;
  padding: 10px 24px;
  font-size: 15px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  border: none;
  border-radius: 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s var(--ease-spring);
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
}

.back-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.4);
}

/* 3. HERO */
.hero {
  text-align: center;
  padding: 80px 24px 64px;
  /* Increased padding slightly for better framing */
  background:
    linear-gradient(to bottom, rgba(239, 246, 255, 0.85), rgba(241, 245, 249, 0.9)),
    url('../assets/images/treasure-map-bg.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  /* Optional: Blend mode for "faded" look if simple opacity isn't enough */
  background-blend-mode: overlay;
}

.hero h1 {
  font-size: 3rem;
  font-weight: 800;
  color: #1e293b;
  margin-bottom: 24px;
  letter-spacing: -0.02em;
  /* Stronger halo for readability */
  text-shadow:
    0 2px 4px rgba(255, 255, 255, 1),
    0 0 20px rgba(255, 255, 255, 0.8);
  /* Glass card effect */
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(8px);
  padding: 16px 32px;
  border-radius: 16px;
  display: inline-block;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.hero p {
  font-size: 1.25rem;
  color: #334155;
  /* Slightly darker for contrast */
  max-width: 640px;
  margin: 0 auto;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(8px);
  padding: 12px 24px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* 4. SEARCH & FILTERS (REFACTORED) */
.search-section {
  padding: 0 20px;
  margin: -32px auto 0;
  max-width: 1280px;
  position: relative;
  z-index: 10;
}

.filter-container {
  background: rgba(255, 255, 255, 0.8);
  /* Glassmorphism base */
  backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.05),
    0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

/* Search Wrapper with Floating Label Support */
.search-wrapper {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: nowrap;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  padding: 18px 18px 10px;
  /* Adjusted padding for floating label */
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.8);
  border: 2px solid transparent;
  color: var(--text-primary);
  font-size: 15px;
  transition: all 0.25s;
  box-sizing: border-box;
  /* Critical */
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.search-input:focus {
  outline: none;
  background: white;
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.search-label {
  position: absolute;
  left: 18px;
  top: 16px;
  color: #94a3b8;
  font-size: 15px;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Float label when focused or has content (using placeholder-shown hack) */
.search-input:focus+.search-label,
.search-input:not(:placeholder-shown)+.search-label {
  top: 6px;
  font-size: 11px;
  color: #3b82f6;
  font-weight: 600;
}

/* Enhanced Search Button (ISSUE #1) */
.search-btn {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  padding: 0 32px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 12px;
  border: none;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
  transition: all 0.3s var(--ease-spring);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  /* Prevent shrinking */
}

/* Shimmer Effect */
.search-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.5s;
}

.search-btn:hover::before {
  left: 100%;
}

.search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.5);
}

.search-btn:active {
  transform: translateY(0);
}

/* Filter Chips Grid (ISSUE #4) */
.filter-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  /* Removed overflow-x: scroll */
}

.filter-button {
  padding: 10px 16px;
  border-radius: 12px;
  /* Slight tweak to match aesthetic */
  border: 1px solid rgba(226, 232, 240, 0.8);
  background: rgba(255, 255, 255, 0.6);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease-spring);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  /* Touch target size */
  position: relative;
  overflow: hidden;
}

/* Ripple effect container */
.filter-button::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.2);
  transform: translate(-50%, -50%);
  transition: width 0.4s, height 0.4s;
}

.filter-button:active::after {
  width: 200px;
  height: 200px;
}

.filter-button:hover {
  border-color: #93c5fd;
  background: white;
  transform: translateY(-1px);
}

.filter-button.active {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border-color: #2563eb;
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* 5. MAP SECTION */
.map-section {
  max-width: 1280px;
  margin: 32px auto;
  padding: 0 24px;
}

.map-container {
  background: white;
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: max-height 0.4s var(--ease-spring), opacity 0.3s ease;
  max-height: 600px;
  opacity: 1;
  border: 1px solid var(--border-color);
}

.map-container.map-collapsed {
  max-height: 0;
  opacity: 0;
  border: none;
}

.map-header {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}

.map-wrapper {
  height: 500px;
  width: 100%;
}

/* 6. BUSINESS LISTINGS */
.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 80px;
  padding-bottom: calc(80px + var(--safe-area-inset-bottom));
}

.category-section {
  margin-top: 48px;
  margin-bottom: 24px;
}

/* Sticky Category Headers (ISSUE #3) */
.category-header {
  margin-bottom: 20px;
  padding: 16px 24px;
  position: sticky;
  top: 72px;
  /* Below main header */
  background: rgba(241, 245, 249, 0.95);
  /* Matches bg-page */
  backdrop-filter: blur(12px);
  z-index: 90;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  margin-left: -24px;
  margin-right: -24px;
  /* Bleed to edges */
  border-radius: 0 0 12px 12px;
}

.category-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.category-count {
  background: white;
  color: var(--primary-blue);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Grid Layout (ISSUE #6) */
.business-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
}

/* Elevated Business Card (ISSUE #2) */
.business-card {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid rgba(226, 232, 240, 0.6);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.05),
    0 8px 24px rgba(0, 0, 0, 0.04);
  transition: all 0.3s var(--ease-spring);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

/* Accent Border */
.business-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  opacity: 0;
  transition: opacity 0.3s;
}

.business-card:hover {
  transform: translateY(-4px);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.08),
    0 4px 8px rgba(0, 0, 0, 0.04);
  border-color: rgba(96, 165, 250, 0.3);
  background: white;
}

.business-card:hover::before {
  opacity: 1;
}

.card-header-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.business-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.3;
}

.location-row {
  font-size: 14px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.business-desc {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  flex: 1;
  /* Pushes content down */
  margin-bottom: 12px;
}

.service-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.service-tag {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.contact-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.contact-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
  background: #f8fafc;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.contact-button:hover {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
  transform: translateY(-1px);
}

/* 7. LOADING ANIMATIONS */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.business-card {
  animation: fadeInUp 0.5s var(--ease-spring) backwards;
}

/* Using loop would be cleaner in SCSS, but hardcoding for standard CSS */
.business-card:nth-child(1) {
  animation-delay: 0.05s;
}

.business-card:nth-child(2) {
  animation-delay: 0.1s;
}

.business-card:nth-child(3) {
  animation-delay: 0.15s;
}

.business-card:nth-child(4) {
  animation-delay: 0.2s;
}

.business-card:nth-child(5) {
  animation-delay: 0.25s;
}

.business-card:nth-child(n+6) {
  animation-delay: 0.3s;
}

/* 8. MOBILE OPTIMIZATIONS */
.floating-action-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 200;
  transition: all 0.3s;
  /* Respect safe area */
  bottom: calc(24px + var(--safe-area-inset-bottom));
}

.floating-action-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.5);
}

@media (min-width: 768px) {
  .floating-action-btn {
    display: none;
  }
}

@media (max-width: 640px) {
  .search-wrapper {
    flex-direction: column;
  }

  .search-btn {
    width: 100%;
  }

  .business-grid {
    grid-template-columns: 1fr;
  }

  .category-header {
    top: 60px;
    padding: 12px 24px;
  }
}

/* 9. DARK MODE SUPPORT */
/* Media query removed to prevent conflict with manual toggle.
   Theme is now controlled via body.dark-mode class. */

body.dark-mode {
  --bg-page: #0f172a;
  --bg-card: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  --border-color: #334155;
}

body.dark-mode .header,
body.dark-mode .category-header {
  background: rgba(15, 23, 42, 0.9);
}

body.dark-mode .filter-container {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .search-input {
  background: rgba(15, 23, 42, 0.6);
  color: white;
}

body.dark-mode .filter-button {
  background: rgba(51, 65, 85, 0.5);
  color: #e2e8f0;
  border-color: #475569;
}

body.dark-mode .filter-button:hover {
  background: #334155;
}

body.dark-mode .business-card {
  background: rgba(30, 41, 59, 0.6);
  border-color: #334155;
}

body.dark-mode .business-card:hover {
  background: #1e293b;
  border-color: #3b82f6;
}

body.dark-mode .category-count {
  background: #334155;
  color: #60a5fa;
}

body.dark-mode .contact-button {
  background: rgba(30, 41, 59, 0.5);
  border-color: #475569;
  color: #94a3b8;
}

body.dark-mode .contact-button:hover {
  background: #334155;
  color: #60a5fa;
}