<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { businessService } from '@/services/businessService'
import { couponsService } from '@/services/couponsService'
import type { Business, Coupon } from '@/types'
import FavoriteButton from '@/components/FavoriteButton.vue'
import { getImageUrl as utilGetImageUrl } from '@/utils/imageUrl'
import { analyticsService } from '@/services/analyticsService'
import LoadingBranded from '@/components/common/LoadingBranded.vue'

import { useI18n } from 'vue-i18n'

const { t } = useI18n()
const route = useRoute()
const router = useRouter()
const business = ref<Business | null>(null)
const coupons = ref<Coupon[]>([])
const isLoading = ref(true)
const fetchError = ref(false)
const carouselIndex = ref(0)

// Gallery: mezcla imagen principal + gallery_images
const galleryImages = computed(() => {
  if (!business.value) return []
  const imgs: string[] = []
  if (business.value.image_url) imgs.push(business.value.image_url)
  if (business.value.gallery_images?.length) imgs.push(...business.value.gallery_images)
  return imgs
})

const CATEGORY_EMOJI: Record<string, string> = {
  'Restaurante': '🍽️', 'Hotel': '🏨', 'Café': '☕',
  'Comercio': '🏪', 'Turismo': '🌄', 'Bebidas': '🍹',
}

function catEmoji(cat?: string | null) {
  return cat ? (CATEGORY_EMOJI[cat] ?? '📍') : '📍'
}

async function fetchData() {
  const id = route.params.id as string
  if (!id) return
  isLoading.value = true
  fetchError.value = false
  try {
    const [bizData, allCoupons] = await Promise.all([
      businessService.getBusiness(id),
      couponsService.getAllCoupons({ active_only: true })
    ])
    business.value = bizData
    coupons.value = allCoupons.filter(c => c.business_id === id)
    analyticsService.logEvent({
      event_name: 'view_details',
      entity_type: 'business',
      entity_id: bizData.id,
      entity_name: bizData.name,
      properties: { business_id: id }
    })
  } catch (e) {
    console.error('Failed to load business details', e)
    fetchError.value = true
  } finally {
    isLoading.value = false
  }
}

onMounted(fetchData)

function getImageUrl(path: string | null | undefined) {
  return utilGetImageUrl(path, 'business')
}

const goBack = () => router.back()

function openMaps() {
  if (!business.value) return
  analyticsService.logEvent({ event_name: 'location_click', entity_type: 'business', entity_id: business.value.id, entity_name: business.value.name })
  if (business.value.latitude && business.value.longitude) {
    window.open(`https://www.google.com/maps/dir/?api=1&destination=${business.value.latitude},${business.value.longitude}`, '_blank')
  } else if (business.value.address) {
    window.open(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(business.value.address + ' ' + (business.value.area || ''))}`, '_blank')
  }
}

function callPhone() {
  if (business.value?.phone) {
    analyticsService.logEvent({ event_name: 'contact_click', entity_type: 'business', entity_id: business.value.id, entity_name: business.value.name, properties: { channel: 'phone' } })
    window.location.href = `tel:${business.value.phone}`
  }
}

function openWhatsApp() {
  if (!business.value?.whatsapp) return
  const num = business.value.whatsapp.replace(/\D/g, '')
  analyticsService.logEvent({ event_name: 'social_click', entity_type: 'business', entity_id: business.value.id, entity_name: business.value.name, properties: { platform: 'whatsapp' } })
  window.open(`https://wa.me/${num}`, '_blank')
}

function openInstagram() {
  if (!business.value?.instagram) return
  const handle = business.value.instagram.replace('@', '')
  analyticsService.logEvent({ event_name: 'social_click', entity_type: 'business', entity_id: business.value.id, entity_name: business.value.name, properties: { platform: 'instagram' } })
  window.open(`https://instagram.com/${handle}`, '_blank')
}

function openFacebook() {
  if (!business.value?.facebook) return
  analyticsService.logEvent({ event_name: 'social_click', entity_type: 'business', entity_id: business.value.id, entity_name: business.value.name, properties: { platform: 'facebook' } })
  const fb = business.value.facebook
  window.open(fb.startsWith('http') ? fb : `https://facebook.com/${fb}`, '_blank')
}

function prevSlide() {
  carouselIndex.value = (carouselIndex.value - 1 + galleryImages.value.length) % galleryImages.value.length
}
function nextSlide() {
  carouselIndex.value = (carouselIndex.value + 1) % galleryImages.value.length
}

// Quick info pills computed
const quickInfoPills = computed(() => {
  if (!business.value) return []
  const pills = []
  if (business.value.area)     pills.push({ icon: 'location_on', text: business.value.area })
  if (business.value.schedule) pills.push({ icon: 'schedule',    text: business.value.schedule })
  if (business.value.phone)    pills.push({ icon: 'phone',       text: business.value.phone })
  if (business.value.website)  pills.push({ icon: 'language',    text: t('business.website'), href: business.value.website })
  return pills
})

// Social networks available
const hasSocials = computed(() =>
  !!(business.value?.whatsapp || business.value?.instagram || business.value?.facebook || business.value?.latitude)
)
</script>

<template>
  <!-- ── LOADING ── -->
  <div v-if="isLoading" class="state-full">
    <LoadingBranded :message="t('business.loading')" icon="storefront" />
  </div>

  <!-- ── ERROR ── -->
  <div v-else-if="fetchError" class="state-full">
    <span class="material-icons state-icon">wifi_off</span>
    <h3 class="state-title">{{ t('business.offlineTitle') }}</h3>
    <p class="state-sub">{{ t('business.offlineDesc') }}</p>
    <button class="btn-retry" @click="fetchData">
      <span class="material-icons">refresh</span>
      {{ t('common.retry') }}
    </button>
  </div>

  <!-- ── MAIN CONTENT ── -->
  <div v-else-if="business" class="biz-page">

    <!-- ══════════════════════════════════════════ -->
    <!-- SECTION 1 · HERO                          -->
    <!-- ══════════════════════════════════════════ -->
    <section class="hero">
      <img
        :src="getImageUrl(business.image_url)"
        :alt="business.name"
        class="hero-img"
      />
      <!-- Gradient overlay -->
      <div class="hero-gradient"></div>

      <!-- Top controls -->
      <button class="hero-btn hero-back" @click="goBack" :aria-label="t('common.back')">
        <span class="material-icons">arrow_back</span>
      </button>
      <div class="hero-fav">
        <FavoriteButton
          item-type="business"
          :item-id="business.id"
          :item-name="business.name"
          :item-image="business.image_url || undefined"
        />
      </div>

      <!-- Centered name + badge -->
      <div class="hero-body">
        <span class="hero-cat">{{ catEmoji(business.category) }} {{ business.category }}</span>
        <h1 class="hero-name">{{ business.name }}</h1>
      </div>

      <!-- Gold rule at bottom -->
      <div class="hero-rule"></div>
    </section>

    <!-- ══════════════════════════════════════════ -->
    <!-- SECTION 2 · QUICK INFO PILLS              -->
    <!-- ══════════════════════════════════════════ -->
    <div class="pills-scroll-wrap">
      <div class="pills-row">
        <a
          v-for="(pill, i) in quickInfoPills"
          :key="i"
          class="pill"
          :href="pill.href || undefined"
          :target="pill.href ? '_blank' : undefined"
          :rel="pill.href ? 'noopener noreferrer' : undefined"
        >
          <span class="material-icons pill-icon">{{ pill.icon }}</span>
          <span class="pill-text">{{ pill.text }}</span>
        </a>
      </div>
    </div>

    <!-- ══════════════════════════════════════════ -->
    <!-- SECTION 3 · IMAGE CAROUSEL                -->
    <!-- ══════════════════════════════════════════ -->
    <section v-if="galleryImages.length > 0" class="biz-section">
      <div class="section-header">
        <span class="section-accent"></span>
        <h2 class="section-title">{{ t('business.gallery') }}</h2>
      </div>

      <div class="carousel-wrap">
        <!-- Slides -->
        <div class="carousel-track">
          <div
            v-for="(img, idx) in galleryImages"
            :key="idx"
            class="carousel-slide"
            :class="{ 'slide-active': idx === carouselIndex, 'slide-prev': idx < carouselIndex, 'slide-next': idx > carouselIndex }"
          >
            <img
              :src="getImageUrl(img)"
              :alt="`Foto ${idx + 1} de ${business.name}`"
              class="carousel-img"
              loading="lazy"
            />
          </div>
        </div>

        <!-- Nav arrows (only if >1 image) -->
        <template v-if="galleryImages.length > 1">
          <button class="car-arrow car-arrow-left" @click="prevSlide" :aria-label="t('business.previous')">
            <span class="material-icons">chevron_left</span>
          </button>
          <button class="car-arrow car-arrow-right" @click="nextSlide" :aria-label="t('business.next')">
            <span class="material-icons">chevron_right</span>
          </button>

          <!-- Dots -->
          <div class="car-dots">
            <span
              v-for="(_, dotIdx) in galleryImages"
              :key="dotIdx"
              class="car-dot"
              :class="{ 'car-dot-active': dotIdx === carouselIndex }"
              @click="carouselIndex = dotIdx"
            ></span>
          </div>
        </template>
      </div>
    </section>

    <!-- ══════════════════════════════════════════ -->
    <!-- SECTION 4 · ABOUT                         -->
    <!-- ══════════════════════════════════════════ -->
    <section v-if="business.description" class="biz-section">
      <div class="section-header">
        <span class="section-accent"></span>
        <h2 class="section-title">{{ t('business.about') }}</h2>
      </div>
      <p class="about-text">{{ business.description }}</p>
    </section>

    <!-- ══════════════════════════════════════════ -->
    <!-- SECTION 5 · SOCIALS & CONTACT             -->
    <!-- ══════════════════════════════════════════ -->
    <section v-if="hasSocials" class="biz-section">
      <div class="section-header">
        <span class="section-accent"></span>
        <h2 class="section-title">{{ t('business.contactUs') }}</h2>
      </div>
      <div class="socials-grid">

        <!-- WhatsApp -->
        <button
          v-if="business.whatsapp"
          class="social-btn social-wa"
          @click="openWhatsApp"
        >
          <svg class="social-svg" viewBox="0 0 24 24" fill="currentColor">
            <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
          </svg>
          <span class="social-label">WhatsApp</span>
        </button>

        <!-- Instagram -->
        <button
          v-if="business.instagram"
          class="social-btn social-ig"
          @click="openInstagram"
        >
          <svg class="social-svg" viewBox="0 0 24 24" fill="currentColor">
            <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/>
          </svg>
          <span class="social-label">Instagram</span>
        </button>

        <!-- Facebook -->
        <button
          v-if="business.facebook"
          class="social-btn social-fb"
          @click="openFacebook"
        >
          <svg class="social-svg" viewBox="0 0 24 24" fill="currentColor">
            <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
          </svg>
          <span class="social-label">Facebook</span>
        </button>

        <!-- Google Maps -->
        <button
          v-if="business.latitude || business.address"
          class="social-btn social-maps"
          @click="openMaps"
        >
          <span class="material-icons social-maps-icon">place</span>
          <span class="social-label">Google Maps</span>
        </button>

      </div>
    </section>

    <!-- ══════════════════════════════════════════ -->
    <!-- SECTION 6 · COUPONS / OFFERS              -->
    <!-- ══════════════════════════════════════════ -->
    <section v-if="coupons.length > 0" class="biz-section">
      <div class="section-header">
        <span class="section-accent"></span>
        <h2 class="section-title">{{ t('business.offers') }}</h2>
      </div>
      <div class="coupons-grid">
        <div v-for="coupon in coupons" :key="coupon.id" class="coupon-card">
          <div class="coupon-top">
            <span class="coupon-pct">{{ coupon.discount_percentage }}<sup>%</sup></span>
            <FavoriteButton
              item-type="coupon"
              :item-id="coupon.id"
              :item-name="coupon.title"
              :item-image="coupon.image_url || undefined"
            />
          </div>
          <div class="coupon-divider"></div>
          <h3 class="coupon-title">{{ coupon.title }}</h3>
          <p class="coupon-desc">{{ coupon.description }}</p>
          <span class="coupon-off">{{ t('coupons.off') }}</span>
        </div>
      </div>
    </section>

    <!-- Bottom spacer for sticky bar -->
    <div style="height: 96px;"></div>

    <!-- ══════════════════════════════════════════ -->
    <!-- STICKY CTA BAR                            -->
    <!-- ══════════════════════════════════════════ -->
    <div class="cta-bar">
      <button
        v-if="business.latitude || business.address"
        class="cta-map"
        @click="openMaps"
      >
        <span class="material-icons">near_me</span>
        {{ t('business.viewMap') }}
      </button>
      <button
        v-if="business.phone"
        class="cta-call"
        @click="callPhone"
      >
        <span class="material-icons">phone</span>
        {{ t('business.call') }}
      </button>
    </div>

  </div>
</template>

<style scoped>
/* ═══════════════════════════════════════════════
   BASE
═══════════════════════════════════════════════ */
.biz-page {
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Space Grotesk', system-ui, sans-serif;
}

/* ═══════════════════════════════════════════════
   HERO
═══════════════════════════════════════════════ */
.hero {
  position: relative;
  height: 300px;
  overflow: hidden;
  flex-shrink: 0;
}

.hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.03);
  transition: transform 10s ease;
}

.hero:hover .hero-img { transform: scale(1); }

.hero-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.25) 0%,
    rgba(0, 0, 0, 0.1) 30%,
    rgba(0, 0, 0, 0.6) 70%,
    rgba(0, 0, 0, 0.88) 100%
  );
}

.hero-btn {
  position: absolute;
  top: 20px;
  z-index: 10;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.hero-btn:hover { background: rgba(0,0,0,0.65); }
.hero-back { left: 18px; }
.hero-back:hover { transform: translateX(-2px); }

.hero-fav {
  position: absolute;
  top: 20px;
  right: 18px;
  z-index: 10;
}

/* Centered name block */
.hero-body {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 24px 28px;
  color: #fff;
}

.hero-cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fee715;
  color: #101820;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 14px;
  border-radius: 100px;
  margin-bottom: 10px;
}

.hero-name {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 900;
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.hero-rule {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #fee715 40%, transparent);
  opacity: 0.8;
}

/* ═══════════════════════════════════════════════
   PILLS ROW
═══════════════════════════════════════════════ */
.pills-scroll-wrap {
  overflow-x: auto;
  scrollbar-width: none;
  padding: 18px 18px 4px;
}
.pills-scroll-wrap::-webkit-scrollbar { display: none; }

.pills-row {
  display: flex;
  gap: 10px;
  width: max-content;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 100px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
}

.pill:hover { border-color: #fee715; color: var(--text-primary); }

.pill-icon {
  font-size: 1rem;
  color: #fee715;
}

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

/* ═══════════════════════════════════════════════
   SECTION COMMON
═══════════════════════════════════════════════ */
.biz-section {
  padding: 24px 18px;
  border-bottom: 1px solid var(--border-color);
}
.biz-section:last-of-type { border-bottom: none; }

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.section-accent {
  display: block;
  width: 4px;
  height: 22px;
  background: #fee715;
  border-radius: 4px;
  flex-shrink: 0;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 900;
  margin: 0;
  letter-spacing: -0.01em;
}

/* ═══════════════════════════════════════════════
   CAROUSEL
═══════════════════════════════════════════════ */
.carousel-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  aspect-ratio: 16/9;
  background: var(--bg-secondary);
}

.carousel-track {
  width: 100%;
  height: 100%;
  position: relative;
}

.carousel-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
}

.carousel-slide.slide-active {
  opacity: 1;
  pointer-events: auto;
}

.carousel-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.car-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: background 0.2s, transform 0.2s;
}

.car-arrow:hover { background: rgba(0,0,0,0.75); }
.car-arrow-left  { left: 10px; }
.car-arrow-right { right: 10px; }

.car-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 5;
}

.car-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.car-dot-active {
  background: #fee715;
  transform: scale(1.3);
}

/* ═══════════════════════════════════════════════
   ABOUT
═══════════════════════════════════════════════ */
.about-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-secondary);
  margin: 0;
}

/* ═══════════════════════════════════════════════
   SOCIALS GRID
═══════════════════════════════════════════════ */
.socials-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.social-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 12px;
  border-radius: 18px;
  border: 1.5px solid var(--border-color);
  background: var(--bg-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), border-color 0.2s, box-shadow 0.2s;
}

.social-btn:hover { transform: scale(1.04); }

.social-svg {
  width: 32px;
  height: 32px;
}

.social-maps-icon {
  font-size: 2rem;
}

.social-label {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Brand colors */
.social-wa {
  border-color: rgba(37, 211, 102, 0.3);
  color: #25D366;
}
.social-wa:hover { box-shadow: 0 4px 20px rgba(37, 211, 102, 0.25); border-color: #25D366; }

.social-ig {
  border-color: rgba(228, 64, 95, 0.3);
  color: #E4405F;
}
.social-ig:hover { box-shadow: 0 4px 20px rgba(228, 64, 95, 0.25); border-color: #E4405F; }

.social-fb {
  border-color: rgba(24, 119, 242, 0.3);
  color: #1877F2;
}
.social-fb:hover { box-shadow: 0 4px 20px rgba(24, 119, 242, 0.25); border-color: #1877F2; }

.social-maps {
  border-color: rgba(234, 67, 53, 0.3);
  color: #EA4335;
}
.social-maps:hover { box-shadow: 0 4px 20px rgba(234, 67, 53, 0.25); border-color: #EA4335; }

/* ═══════════════════════════════════════════════
   COUPONS
═══════════════════════════════════════════════ */
.coupons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.coupon-card {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 22px;
  overflow: hidden;
  transition: transform 0.25s, box-shadow 0.25s;
}

.coupon-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: #fee715;
}

.coupon-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}

.coupon-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.coupon-pct {
  font-size: 2.8rem;
  font-weight: 900;
  line-height: 1;
  color: #fee715;
}

.coupon-pct sup { font-size: 1.2rem; font-weight: 700; }

.coupon-divider { height: 1px; background: var(--border-color); margin-bottom: 14px; }

.coupon-title {
  font-size: 1rem;
  font-weight: 800;
  margin: 0 0 6px;
}

.coupon-desc {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
}

.coupon-off {
  position: absolute;
  bottom: 14px;
  right: 16px;
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: #fee715;
  opacity: 0.4;
}

/* ═══════════════════════════════════════════════
   STICKY CTA BAR
═══════════════════════════════════════════════ */
.cta-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 500;
}

.cta-map {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 0;
  background: #fee715;
  color: #101820;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  transition: filter 0.2s, transform 0.2s;
  box-shadow: 0 4px 20px rgba(254, 231, 21, 0.3);
}

.cta-map:hover { filter: brightness(1.08); transform: translateY(-1px); }
.cta-map:active { transform: scale(0.97); }

.cta-call {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.cta-call:hover { border-color: var(--active-color); background: rgba(254,231,21,0.05); }

/* ═══════════════════════════════════════════════
   STATES
═══════════════════════════════════════════════ */
.state-full {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  text-align: center;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border-color);
  border-top-color: #fee715;
  border-radius: 50%;
  animation: spin 0.75s infinite linear;
}

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

.state-icon { font-size: 3rem; color: var(--text-secondary); opacity: 0.35; }
.state-msg  { font-size: 0.95rem; color: var(--text-secondary); margin: 0; }
.state-title { font-size: 1.4rem; font-weight: 900; margin: 0; }
.state-sub  { font-size: 0.9rem; color: var(--text-secondary); max-width: 300px; margin: 0; }

.btn-retry {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: #fee715;
  color: #101820;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition: filter 0.2s;
  margin-top: 8px;
}

.btn-retry:hover { filter: brightness(1.08); }

/* ═══════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════ */
@media (min-width: 600px) {
  .hero { height: 380px; }
  .hero-name { font-size: 2.6rem; }
  .socials-grid { grid-template-columns: repeat(4, 1fr); }
  .biz-section { padding: 28px 24px; }
  .cta-bar { max-width: 600px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; }
}
</style>
