/* ============================================================
   Smart Derivador — Página Pública
   Diseño Liquid Glass / Glassmorphism
   Compatible: Chrome 76+, Safari 9+, Firefox 103+
   ============================================================ */

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

:root {
    --theme-color:     #1a1a2e;
    --glass-bg:        rgba(255, 255, 255, 0.055);
    --glass-border:    rgba(255, 255, 255, 0.14);
    --glass-shadow:    rgba(0, 0, 0, 0.20);
    --glass-highlight: rgba(255, 255, 255, 0.22);
    --text-primary:    #ffffff;
    --text-secondary:  rgba(255, 255, 255, 0.75);
    --blur-amount:     32px;
    --radius-card:     28px;
    --radius-btn:      16px;
    --transition:      0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

html, body {
    width: 100%;
    height: 100vh;                  /* fallback base */
    height: -webkit-fill-available; /* Safari móvil (excluye chrome del browser) */
    height: 100dvh;                 /* Chrome/Firefox/Safari 15.4+ */
    max-height: 100vh;
    max-height: -webkit-fill-available;
    max-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden !important;
    overscroll-behavior: none;
}

/* ---------- Background ---------- */
body {
    background-color: var(--theme-color);
    position: relative;
}

.bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
}

.bg-layer::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        160deg,
        rgba(0,0,0,0.35) 0%,
        rgba(0,0,0,0.20) 50%,
        rgba(0,0,0,0.45) 100%
    );
}

/* Fondo por defecto (sin banner) — gradiente generado dinámicamente desde PHP con el color elegido */
.bg-layer.no-banner {
    background: var(--theme-color); /* fallback si PHP no cargó */
}

/* ---------- Layout Principal ---------- */
.page-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
    max-height: 100vh;
    max-height: -webkit-fill-available;
    max-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;                          /* Safari fallback */
    padding: clamp(0.5rem, 2dvh, 1.25rem) 1rem;
    overflow: hidden;
}

/* ---------- Contenedor Glass Principal ---------- */
.glass-container {
    width: 100%;
    max-width: 420px;
    height: 100%;
    /* padding simétrico: mismo valor arriba y abajo */
    padding: 1.25rem 1.5rem;                         /* Safari fallback */
    padding: clamp(0.75rem, 2dvh, 1.75rem) 1.5rem;
    border-radius: var(--radius-card);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 100%;
}

@supports (backdrop-filter: blur(1px)) {
    .glass-container {
        background: var(--glass-bg);
        backdrop-filter: blur(var(--blur-amount)) saturate(200%);
        -webkit-backdrop-filter: blur(var(--blur-amount)) saturate(200%);
        border: 1px solid var(--glass-border);
        box-shadow:
            0 8px 48px var(--glass-shadow),
            inset 0 1px 0 var(--glass-highlight),
            inset 0 -1px 0 rgba(0,0,0,0.08);
    }
}

/* Fallback sin backdrop-filter */
@supports not (backdrop-filter: blur(1px)) {
    .glass-container {
        background: rgba(15, 15, 30, 0.72);
        border: 1px solid rgba(255,255,255,0.10);
        box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    }
}

/* Efecto de luz interna (liquid glass highlight) */
.glass-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255,255,255,0.4) 30%,
        rgba(255,255,255,0.6) 50%,
        rgba(255,255,255,0.4) 70%,
        transparent
    );
    pointer-events: none;
}

/* ---------- Header ---------- */
.site-header {
    text-align: center;
    margin-bottom: 0.75rem;                     /* Safari fallback */
    margin-bottom: clamp(0.5rem, 1.5dvh, 1rem);
    flex-shrink: 1;
    min-height: 0;
    pointer-events: none;
    user-select: none;
}

.site-logo-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.2rem;
}

.site-logo {
    /*
     * --logo-sz viene del inline style de PHP (ej: --logo-sz:120px)
     * min() anidado para compatibilidad Safari 14 (3 args no soportado)
     * Fallbacks: 120px → vh → dvh (progresivo)
     */
    width:  120px;                                           /* último fallback */
    width:  min(var(--logo-sz, 120px), 22vh);               /* Safari sin dvh */
    width:  min(min(var(--logo-sz, 120px), 22dvh), 75vw);
    height: 120px;
    height: min(var(--logo-sz, 120px), 22vh);
    height: min(min(var(--logo-sz, 120px), 22dvh), 75vw);
    object-fit: contain;
    filter: drop-shadow(0 4px 16px rgba(0,0,0,0.25));
    pointer-events: none;
    /* Sin transition ni transform — completamente estático */
}

.site-subtitle {
    font-size: 0.8rem;                           /* Safari fallback */
    font-size: clamp(0.7rem, 1.8dvh, 0.875rem);
    color: var(--text-secondary);
    margin-top: 0.2rem;
    font-weight: 400;
}

/* ---------- Grid de Botones ---------- */
.buttons-grid {
    display: grid;
    grid-template-columns: 1fr;         /* portrait/vertical: 1 columna */
    grid-auto-rows: 1fr;                /* filas de igual altura */
    gap: 0.4rem;                        /* Safari fallback */
    gap: clamp(0.25rem, 1dvh, 0.6rem);
    flex: 1;       /* llena todo el espacio que deja el header */
    min-height: 0;
    align-content: stretch;
}

/* ---------- Botón Individual ---------- */
.action-btn {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0 1.1rem;
    border-radius: var(--radius-btn);
    text-decoration: none;
    cursor: pointer;
    border: none;
    width: 100%;
    /* La altura la controla el grid-auto-rows del padre */
    min-height: 2.5rem;
    max-height: 5rem;
    background: var(--btn-color, rgba(255,255,255,0.09));
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
    -webkit-tap-highlight-color: transparent; /* elimina flash azul en iOS */
}

@supports (backdrop-filter: blur(1px)) {
    .action-btn {
        backdrop-filter: blur(12px) saturate(160%);
        -webkit-backdrop-filter: blur(12px) saturate(160%);
        border: 1px solid rgba(255,255,255,0.2);
        box-shadow:
            0 4px 16px rgba(0,0,0,0.2),
            inset 0 1px 0 rgba(255,255,255,0.25),
            inset 0 -1px 0 rgba(0,0,0,0.08);
    }
}

@supports not (backdrop-filter: blur(1px)) {
    .action-btn {
        border: 1px solid rgba(255,255,255,0.15);
        box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    }
}

/* Highlight superior en botones */
.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
    pointer-events: none;
}

/* Hover */
.action-btn:hover {
    transform: translateY(-2px) scale(1.012);
    box-shadow:
        0 8px 28px rgba(0,0,0,0.28),
        inset 0 1px 0 rgba(255,255,255,0.3);
    filter: brightness(1.08);
}

/* Active */
.action-btn:active {
    transform: translateY(0) scale(0.98);
    filter: brightness(0.95);
}

/* Ícono del botón */
.btn-icon {
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
    color: rgba(255,255,255,0.92);
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.btn-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Texto del botón */
.btn-label {
    font-size: 0.875rem;                        /* Safari fallback */
    font-size: clamp(0.8rem, 1.6dvh, 1rem);
    font-weight: 600;
    color: rgba(255,255,255,0.95);
    letter-spacing: 0.01em;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    flex: 1;
}

/* Flecha derecha */
.btn-arrow {
    color: rgba(255,255,255,0.5);
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    transition: transform var(--transition), color 0.2s;
}

.action-btn:hover .btn-arrow {
    color: rgba(255,255,255,0.85);
    transform: translateX(3px);
}

/* ---------- Estado vacío ---------- */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ---------- Responsive: Landscape / pantalla ancha → 2 columnas ---------- */
@media (orientation: landscape) and (min-width: 540px) {
    .glass-container {
        max-width: 640px;   /* más ancho para alojar 2 columnas */
    }
    .buttons-grid {
        grid-template-columns: repeat(2, 1fr);  /* 2 columnas en landscape */
    }
}

/* ---------- Responsive: Large Desktop ---------- */
@media (min-width: 1024px) and (orientation: portrait) {
    .glass-container {
        max-width: 480px;
    }
}

/* ---------- Animación de entrada ---------- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.glass-container {
    animation: fadeInUp 0.5s ease-out both;
}

.action-btn {
    animation: fadeInUp 0.4s ease-out both;
}

.action-btn:nth-child(1)  { animation-delay: 0.05s; }
.action-btn:nth-child(2)  { animation-delay: 0.10s; }
.action-btn:nth-child(3)  { animation-delay: 0.15s; }
.action-btn:nth-child(4)  { animation-delay: 0.20s; }
.action-btn:nth-child(5)  { animation-delay: 0.25s; }
.action-btn:nth-child(6)  { animation-delay: 0.30s; }
.action-btn:nth-child(7)  { animation-delay: 0.35s; }
.action-btn:nth-child(8)  { animation-delay: 0.40s; }

/* ---------- Popup de ubicación Maps ---------- */
.maps-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeInUp 0.22s ease-out both;
}

.maps-popup {
    position: relative;
    width: 100%;
    max-width: 380px;
    background: rgba(15, 20, 40, 0.88);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.12);
    padding: 1.5rem 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.maps-popup-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2rem;
    height: 2rem;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 50%;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}
.maps-popup-close svg { width: 0.875rem; height: 0.875rem; }
.maps-popup-close:hover { background: rgba(255,255,255,0.15); color: #fff; }

.maps-popup-address {
    font-size: 1rem;
    font-weight: 600;
    color: #f1f5f9;
    padding-right: 2rem;
    line-height: 1.4;
}

.maps-popup-map {
    width: 100%;
    height: 200px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}

.maps-popup-map iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.maps-popup-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: rgba(99,102,241,0.85);
    border: 1px solid rgba(99,102,241,0.5);
    border-radius: 12px;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
}
.maps-popup-btn:hover { background: rgba(99,102,241,1); transform: translateY(-1px); }
.maps-popup-btn:active { transform: scale(0.98); }

/* ---------- Reducir movimiento (accesibilidad) ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
