/**
 * ==============================================================================
 * 03_COMPONENTS — DYNAMIC ISLAND MOBILE SEARCH (Apple Style Capsule)
 * ==============================================================================
 * Experiencia inmersiva e interactiva de búsqueda mobile estilo Dynamic Island /
 * cápsula fluida de Apple. Reemplaza el modal tosco de pantalla completa por una
 * burbuja reactiva con física de resorte (spring cubic-bezier), glassmorphism
 * de alta densidad y microinteracciones de precisión.
 * ==============================================================================
 */

/* ── Fondo Atenuado Suave (Backdrop) ── */
.km-dynamic-island-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2400;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.3s ease;
}

.km-dynamic-island-backdrop.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ── Cápsula Principal (Dynamic Island Pill) ── */
.km-dynamic-island {
    position: fixed;
    top: 10px;
    left: 12px;
    right: 12px;
    z-index: 2500;
    height: 48px;
    border-radius: 9999px;
    background: rgba(18, 18, 18, 0.94);
    backdrop-filter: blur(28px) saturate(190%);
    -webkit-backdrop-filter: blur(28px) saturate(190%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    padding: 0 14px;
    gap: 10px;
    transform: translateY(-80px) scale(0.92);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.42s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                opacity 0.25s ease,
                visibility 0.42s ease,
                border-radius 0.3s ease;
    font-family: var(--km-font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
}

.km-dynamic-island.is-expanded {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ── Icono de Lupa con Microanimación ── */
.km-dynamic-island__icon {
    flex-shrink: 0;
    color: #c084fc;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, color 0.25s ease;
}

.km-dynamic-island.is-expanded .km-dynamic-island__icon {
    animation: kmIslandPulse 2s infinite ease-in-out;
}

@keyframes kmIslandPulse {
    0%, 100% {
        transform: scale(1);
        color: #c084fc;
    }
    50% {
        transform: scale(1.12);
        color: #e9d5ff;
    }
}

/* ── Formulario e Input ── */
.km-dynamic-island__form {
    flex: 1;
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
}

.km-dynamic-island__input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: #ffffff;
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.2;
    padding: 0;
    margin: 0;
    font-family: inherit;
}

.km-dynamic-island__input::placeholder {
    color: rgba(255, 255, 255, 0.55);
    font-weight: 400;
}

/* ── Botones de Acción (Limpiar y Cerrar) ── */
.km-dynamic-island__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.km-dynamic-island__btn-clear {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: none;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.km-dynamic-island__btn-clear.is-visible {
    display: flex;
}

.km-dynamic-island__btn-clear:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.km-dynamic-island__btn-close {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 9999px;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.km-dynamic-island__btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.km-dynamic-island__btn-close:active {
    transform: scale(0.95);
}

/* ── Tarjeta Desplegable de Sugerencias / Resultados ── */
.km-dynamic-island__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(24, 24, 27, 0.96);
    backdrop-filter: blur(28px) saturate(190%);
    -webkit-backdrop-filter: blur(28px) saturate(190%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
    padding: 12px 14px;
    max-height: 60vh;
    overflow-y: auto;
    display: none;
    flex-direction: column;
    gap: 8px;
    animation: kmIslandFadeIn 0.25s ease;
}

.km-dynamic-island__dropdown.is-active {
    display: flex;
}

@keyframes kmIslandFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.km-dynamic-island__quick-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.km-dynamic-island__tag {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 9999px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.km-dynamic-island__tag:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.3);
}

/* ── Contenedor de Resultados en Vivo de la Dynamic Island ── */
.km-dynamic-island__results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.km-dynamic-island__dropdown .km-sug-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #c084fc;
    padding: 6px 2px 2px 2px;
}

.km-dynamic-island__dropdown .km-sug-tiendas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}

.km-dynamic-island__dropdown .km-sug-tienda-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    text-decoration: none;
    color: #ffffff;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.km-dynamic-island__dropdown .km-sug-tienda-item:hover,
.km-dynamic-island__dropdown .km-sug-tienda-item.km-sug-active {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(192, 132, 252, 0.4);
}

.km-dynamic-island__dropdown .km-sug-tienda-img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.km-dynamic-island__dropdown .km-sug-tienda-placeholder {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

.km-dynamic-island__dropdown .km-sug-tienda-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.km-dynamic-island__dropdown .km-sug-tienda-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.km-dynamic-island__dropdown .km-sug-tienda-badge {
    font-size: 0.65rem;
    color: #a78bfa;
    font-weight: 500;
}

.km-dynamic-island__dropdown .km-sug-chips-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.km-dynamic-island__dropdown .km-sug-chip {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 5px 11px;
    border-radius: 9999px;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.km-dynamic-island__dropdown .km-sug-chip:hover,
.km-dynamic-island__dropdown .km-sug-chip.km-sug-active {
    background: rgba(192, 132, 252, 0.25);
    border-color: rgba(192, 132, 252, 0.5);
    color: #ffffff;
}

.km-dynamic-island__dropdown .km-sug-productos-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.km-dynamic-island__dropdown .km-sug-producto-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.km-dynamic-island__dropdown .km-sug-producto-item:hover,
.km-dynamic-island__dropdown .km-sug-producto-item.km-sug-active {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.km-dynamic-island__dropdown .km-sug-prod-img {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    object-fit: cover;
    background: #27272a;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.km-dynamic-island__dropdown .km-sug-prod-info {
    flex: 1;
    min-width: 0;
}

.km-dynamic-island__dropdown .km-sug-prod-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.km-dynamic-island__dropdown .km-sug-prod-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    margin-top: 2px;
}

.km-dynamic-island__dropdown .km-sug-prod-price {
    font-weight: 700;
    color: #34d399;
}

.km-dynamic-island__dropdown .km-sug-prod-store {
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.km-dynamic-island__dropdown .km-sug-footer {
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.km-dynamic-island__dropdown .km-sug-all-link {
    display: block;
    color: #c084fc;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    padding: 6px 0;
    transition: color 0.2s ease;
}

.km-dynamic-island__dropdown .km-sug-all-link:hover {
    color: #e9d5ff;
    text-decoration: underline;
}

.km-dynamic-island__dropdown .km-sug-loading,
.km-dynamic-island__dropdown .km-sug-empty {
    padding: 18px 12px;
    text-align: center;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.8rem;
}

.km-dynamic-island__dropdown .km-sug-empty i {
    color: rgba(255, 255, 255, 0.4);
}

.km-dynamic-island__dropdown .km-match-hl {
    color: #facc15;
    font-weight: 700;
}

/* Solo visible en viewports menores a desktop */
@media (min-width: 992px) {
    .km-dynamic-island,
    .km-dynamic-island-backdrop {
        display: none !important;
    }
}
