/* ==========================================================================
   AVENUE METRO - MOBILE CHATBOT LAUNCHER
   Companion to js/chatbot-mobile.js.

   Phones only (narrow portrait OR short landscape):
     - Closed (default): floating round avatar bubble, bottom-right.
     - Open: compact bottom-sheet panel with header, close button,
       quick-reply chips and the existing input + voice controls.
   Tablets / desktop: nothing here applies; original chatbot is unchanged.

   Every rule is gated on body.am-chat-enhanced (added by the JS), so if the
   script is missing the page falls back to the original chatbot.
   Brand accent: #b50224
   ========================================================================== */

/* Injected elements are hidden everywhere by default (tablet/desktop) */
.am-chat-launcher,
.am-chat-teaser,
.am-chat-header,
.am-chat-chips {
    display: none;
}

/* Headshot crop of the full-body avatar PNG (415x600), tuned per floor */
.am-chat-face {
    display: block;
    flex: none;
    border-radius: 50%;
    background-color: #1c1c1c;
    background-repeat: no-repeat;
    background-size: var(--am-face-size, 160%);
    background-position: var(--am-face-pos, 42% 6%);
}

.page-shop {
    --am-face-size: 160%;
    --am-face-pos: 42% 6%;
}

.page-game-room {
    --am-face-size: 180%;
    --am-face-pos: 49% 0%;
}

.page-movie-lobby {
    --am-face-size: 138%;
    --am-face-pos: 55% 0%;
}

/* Keep in sync with MOBILE_QUERY in js/chatbot-mobile.js */
@media (max-width: 767px), (max-height: 500px) {

    /* ---------- Closed state: hide the full-body overlay entirely ---------- */
    body.am-chat-enhanced #chatbot-container {
        display: none !important;
    }

    body.am-chat-enhanced #chatbot-avatar {
        display: none !important;
    }

    /* Portrait menu no longer needs to clear a docked full-size chatbot */
    body.am-chat-enhanced .portrait-menu {
        bottom: 96px;
    }

    /* ---------- Launcher bubble ---------- */
    body.am-chat-enhanced .am-chat-launcher {
        display: block;
        position: fixed;
        right: calc(16px + env(safe-area-inset-right, 0px));
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        width: 64px;
        height: 64px;
        padding: 0;
        border: 3px solid #b50224;
        border-radius: 50%;
        background: #111;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(181, 2, 36, 0.6);
        cursor: pointer;
        z-index: 10001;
        animation: am-chat-pulse 2.4s ease-out 1s 3;
        -webkit-tap-highlight-color: transparent;
    }

    body.am-chat-enhanced .am-chat-launcher .am-chat-face {
        width: 100%;
        height: 100%;
    }

    body.am-chat-enhanced .am-chat-launcher:active {
        transform: scale(0.95);
    }

    body.am-chat-enhanced .am-chat-launcher:focus-visible {
        outline: 3px solid #fff;
        outline-offset: 3px;
    }

    .am-chat-launcher__dot {
        position: absolute;
        top: 1px;
        right: 1px;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background: #2ecc71;
        border: 2px solid #111;
    }

    body.am-chat-enhanced.am-chat-open .am-chat-launcher {
        display: none;
    }

    /* ---------- Teaser bubble ---------- */
    body.am-chat-enhanced .am-chat-teaser.is-visible {
        display: block;
        position: fixed;
        right: calc(92px + env(safe-area-inset-right, 0px));
        bottom: calc(26px + env(safe-area-inset-bottom, 0px));
        max-width: min(240px, calc(100vw - 120px));
        background: #fff;
        color: #111;
        border-radius: 16px 16px 4px 16px;
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
        z-index: 10001;
        animation: am-chat-in 0.25s ease-out;
    }

    .am-chat-teaser__text {
        display: block;
        width: 100%;
        margin: 0;
        padding: 12px 36px 12px 14px;
        border: 0;
        background: transparent;
        color: inherit;
        font-family: inherit;
        font-size: 14px;
        font-weight: 600;
        line-height: 1.35;
        text-align: left;
        cursor: pointer;
    }

    .am-chat-teaser__close {
        position: absolute;
        top: 4px;
        right: 4px;
        width: 28px;
        height: 28px;
        padding: 6px;
        border: 0;
        border-radius: 50%;
        background: transparent;
        color: #555;
        cursor: pointer;
    }

    /* ---------- Open state: bottom-sheet panel ---------- */
    body.am-chat-enhanced.am-chat-open #chatbot-container {
        display: flex !important;
        flex-direction: column;
        position: fixed !important;
        top: auto !important;
        left: calc(8px + env(safe-area-inset-left, 0px)) !important;
        right: calc(8px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(8px + env(safe-area-inset-bottom, 0px) + var(--am-kb, 0px)) !important;
        transform: none !important;
        width: auto !important;
        max-width: 480px;
        margin: 0 auto !important;
        max-height: min(78vh, calc(100vh - 16px - var(--am-kb, 0px)));
        max-height: min(78dvh, calc(100dvh - 16px - var(--am-kb, 0px)));
        background: rgba(12, 12, 12, 0.95);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-top: 3px solid #b50224;
        border-radius: 18px;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6);
        overflow: hidden;
        z-index: 10001 !important;
        animation: am-chat-in 0.22s ease-out;
    }

    /* Header */
    body.am-chat-enhanced .am-chat-header {
        display: flex;
        align-items: center;
        gap: 10px;
        flex: none;
        padding: 10px 10px 10px 14px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    body.am-chat-enhanced .am-chat-header .am-chat-face {
        width: 46px;
        height: 46px;
        border: 2px solid #b50224;
    }

    .am-chat-header__meta {
        display: flex;
        flex-direction: column;
        min-width: 0;
        line-height: 1.2;
    }

    .am-chat-header__name {
        color: #fff;
        font-size: 16px;
        font-weight: 800;
        letter-spacing: 0.02em;
    }

    .am-chat-header__role {
        display: flex;
        align-items: center;
        gap: 6px;
        color: rgba(255, 255, 255, 0.65);
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .am-chat-online {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #2ecc71;
        flex: none;
    }

    .am-chat-close {
        margin-left: auto;
        flex: none;
        width: 44px;
        height: 44px;
        padding: 11px;
        border: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.08);
        color: #fff;
        cursor: pointer;
    }

    .am-chat-close:active {
        background: rgba(255, 255, 255, 0.18);
    }

    .am-chat-close svg,
    .am-chat-teaser__close svg {
        display: block;
        width: 100%;
        height: 100%;
        fill: none;
        stroke: currentColor;
        stroke-width: 2.4;
        stroke-linecap: round;
    }

    /* Conversation */
    body.am-chat-enhanced #chatbot-container #chat-output {
        flex: 1 1 auto;
        min-height: 110px;
        height: auto;
        margin: 0;
        padding: 12px 14px;
        background: transparent;
        font-size: 15px;
        line-height: 1.45;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    body.am-chat-enhanced #chatbot-container #chat-output > p {
        margin: 0 0 8px;
        padding: 10px 12px;
        border-radius: 14px 14px 14px 4px;
        background: rgba(255, 255, 255, 0.08);
    }

    /* Quick replies */
    body.am-chat-enhanced .am-chat-chips {
        display: flex;
        flex: none;
        gap: 8px;
        padding: 8px 12px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    body.am-chat-enhanced .am-chat-chips::-webkit-scrollbar {
        display: none;
    }

    .am-chat-chip {
        flex: none;
        display: inline-flex;
        align-items: center;
        min-height: 38px;
        padding: 0 14px;
        border: 1px solid rgba(255, 255, 255, 0.28);
        border-radius: 999px;
        background: transparent;
        color: #fff;
        font: inherit;
        font-size: 13px;
        font-weight: 600;
        text-decoration: none;
        white-space: nowrap;
        cursor: pointer;
    }

    .am-chat-chip:active {
        background: #b50224;
        border-color: #b50224;
    }

    /* Input + voice controls */
    body.am-chat-enhanced #chatbot-container #chat-input-container {
        flex: none;
        margin: 0;
        padding: 10px 12px 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    body.am-chat-enhanced #chatbot-container #user-input {
        height: 44px;
        margin: 0;
        padding: 0 16px;
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 22px;
        background: #fff;
        color: #111;
        font-size: 16px; /* 16px+ prevents iOS zoom-on-focus */
    }

    body.am-chat-enhanced #chatbot-container #voice-controls {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-top: 8px;
    }

    body.am-chat-enhanced #chatbot-container #voice-controls button {
        min-height: 40px;
        margin: 0 !important; /* Send button has an inline margin-left */
        padding: 0 8px;
        border-radius: 12px;
        font-size: 14px;
        font-weight: 600;
        transform: none;
    }
}

/* Landscape phones: dock the panel to the right so the scene stays visible */
@media (max-height: 500px) and (orientation: landscape) {
    body.am-chat-enhanced.am-chat-open #chatbot-container {
        left: auto !important;
        width: min(400px, 62vw) !important;
        max-height: calc(100vh - 16px - var(--am-kb, 0px));
        max-height: calc(100dvh - 16px - var(--am-kb, 0px));
    }

    body.am-chat-enhanced #chatbot-container #chat-output {
        min-height: 60px;
    }
}

@keyframes am-chat-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

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

@keyframes am-chat-pulse {
    0% {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(181, 2, 36, 0.6);
    }

    70% {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 0 14px rgba(181, 2, 36, 0);
    }

    100% {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(181, 2, 36, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    body.am-chat-enhanced .am-chat-launcher,
    body.am-chat-enhanced .am-chat-teaser.is-visible,
    body.am-chat-enhanced.am-chat-open #chatbot-container {
        animation: none;
    }
}
