/* =========================================================
   extras.css — load AFTER style.css
   Skeleton loaders, Load More, lazy images, chatbot upgrades
========================================================= */

:root {
    --sk-base: #e8ecf1;
    --sk-shine: #f6f8fb;
}

.is-hidden { display: none !important; }

/* ---------- Initial page loader ---------- */
.page-loader {
    display: none;
}

.js .page-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    background: var(--light, #fff8f0);
    opacity: 1;
    visibility: visible;
    transition: opacity .3s ease, visibility .3s ease;
}

.js .page-loader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-loader-spinner {
    width: 46px;
    height: 46px;
    border: 4px solid rgba(217, 108, 63, .2);
    border-top-color: var(--primary, #d96c3f);
    border-radius: 50%;
    animation: page-spin .8s linear infinite;
}

@keyframes page-spin { to { transform: rotate(360deg); } }

/* ---------- Skeleton loader ---------- */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--sk-base);
    border-radius: 8px;
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--sk-shine), transparent);
    animation: sk-shimmer 1.4s ease-in-out infinite;
}

@keyframes sk-shimmer { 100% { transform: translateX(100%); } }

.sk-card {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 18px rgba(15, 23, 42, .08);
}

.sk-img { aspect-ratio: 16 / 10; border-radius: 0; }
.sk-body { padding: 20px; display: grid; gap: 12px; }
.sk-line { height: 12px; }
.sk-line.lg { height: 20px; width: 75%; }
.sk-line.sm { width: 40%; }
.sk-line.md { width: 90%; }
.sk-line.price { width: 90px; height: 22px; }
.sk-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.sk-btn { width: 118px; height: 36px; border-radius: 999px; }

/* Skeleton grid is only shown when JS is running */
.skeleton-grid { display: none; }
.js .skeleton-grid { display: grid; }
.js .card-grid.is-loading { display: none; }

/* ---------- Lazy image fade-in ---------- */
.itin-card-img { position: relative; overflow: hidden; }

.img-shimmer {
    display: none;
    position: absolute;
    inset: 0;
    border-radius: 0;
    z-index: 1;
}

.js .img-shimmer { display: block; }
.js .itin-card-img.is-loaded .img-shimmer { display: none; }

.js .itin-card-img img {
    opacity: 0;
    transition: opacity .5s ease;
}

.js .itin-card-img.is-loaded img { opacity: 1; }

/* ---------- Card reveal (after Load More) ---------- */
@keyframes cardIn {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: none; }
}

.itin-card.reveal { animation: cardIn .45s ease both; }

.filter-no-results { grid-column: 1 / -1; }

/* ---------- Load more ---------- */
.load-more-wrap { text-align: center; margin-top: 40px; }
.load-more-wrap[hidden] { display: none; }

.load-more-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 230px;
    justify-content: center;
}

.load-more-btn:disabled { opacity: .85; cursor: progress; }

.btn-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin .7s linear infinite;
}

.load-more-btn.is-loading .btn-spinner { display: inline-block; }

@keyframes btn-spin { to { transform: rotate(360deg); } }

.load-more-hint { margin-top: 12px; font-size: .9rem; opacity: .7; }

/* ---------- Active filter chips ---------- */
.active-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.active-filters:empty { display: none; }

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 0;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font: inherit;
    font-size: .85rem;
    cursor: pointer;
}

.filter-chip:hover { background: #e0e7ff; }

/* ---------- Skip painting far-below-the-fold sections ---------- */
.whatsapp-section,
.footer {
    content-visibility: auto;
    contain-intrinsic-size: 1px 420px;
}

/* =========================================================
   CHATBOT UPGRADES
========================================================= */
.chatbot-header-actions { display: flex; align-items: center; gap: 4px; }

.chatbot-messages { scroll-behavior: smooth; }

/* ---------- Responsive chatbot sizing ---------- */
.chatbot {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(78px, calc(14px + env(safe-area-inset-bottom)));
}

.chatbot-window {
    width: min(370px, calc(100vw - 24px));
    height: min(530px, calc(100dvh - 120px));
    max-height: calc(100dvh - 120px);
}

.chatbot-header,
.chatbot-input-area,
.chatbot-footer {
    flex: 0 0 auto;
}

.chatbot-messages {
    min-height: 0;
}

.message-content {
    min-width: 0;
    overflow-wrap: anywhere;
}

.quick-replies button {
    max-width: 100%;
    overflow-wrap: anywhere;
}

@media (max-width: 600px) {
    .chatbot {
        right: max(10px, env(safe-area-inset-right));
    }

    .chatbot-window {
        width: min(370px, calc(100vw - 20px));
        height: min(560px, calc(100dvh - 100px));
        max-height: calc(100dvh - 100px);
        border-radius: 18px;
    }

    .chatbot-input-area input {
        font-size: 16px;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    .chatbot {
        bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chatbot-window {
        height: min(440px, calc(100dvh - 128px));
        max-height: calc(100dvh - 128px);
    }
}

@media (max-height: 700px) and (orientation: portrait) {
    .chatbot {
        bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chatbot-window {
        height: min(560px, calc(100dvh - 128px));
        max-height: calc(100dvh - 128px);
    }
}

/* Suggested packages inside chat */
.chat-pkgs { display: grid; gap: 8px; margin: 10px 0 4px; }

.chat-pkg {
    display: grid;
    gap: 2px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    color: inherit;
    text-decoration: none;
    transition: border-color .2s, box-shadow .2s, transform .2s;
}

.chat-pkg:hover,
.chat-pkg:focus-visible {
    border-color: #6366f1;
    box-shadow: 0 4px 14px rgba(99, 102, 241, .15);
    outline: none;
}

.chat-pkg-title { font-weight: 600; font-size: .92rem; line-height: 1.3; }
.chat-pkg-meta { font-size: .8rem; opacity: .7; }
.chat-pkg-price { font-weight: 700; font-size: .95rem; color: #4f46e5; }

.chat-note { display: block; margin-top: 8px; font-size: .8rem; opacity: .7; }

.chat-whatsapp-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; }

/* Follow-up chips reuse .quick-replies from style.css; make sure they wrap */
.quick-replies { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.quick-replies button.is-used { opacity: .45; pointer-events: none; }

/* Message pop-in */
.chatbot-messages .bot-message,
.chatbot-messages .user-message {
    animation: cardIn .25s ease both;
}

/* Nudge bubble */
.chatbot-nudge {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: 230px;
    padding: 12px 30px 12px 14px;
    border-radius: 14px 14px 4px 14px;
    background: #fff;
    color: #1f2937;
    font-size: .88rem;
    line-height: 1.4;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
    animation: cardIn .35s ease both;
}

.chatbot-nudge[hidden] { display: none; }

.chatbot-nudge-close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: 0;
    background: none;
    color: #9ca3af;
    cursor: pointer;
}

.chatbot-notification[hidden] { display: none; }

@media (max-width: 480px) {
    .chatbot-nudge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton::after,
    .btn-spinner { animation: none; }
    .itin-card.reveal,
    .chatbot-messages .bot-message,
    .chatbot-messages .user-message,
    .chatbot-nudge { animation: none; }
    .chatbot-messages { scroll-behavior: auto; }
}