/* ==========================================================================
   Alter Mirror AI Guide , Realistic Robot Companion Design System
   ========================================================================== */

/* Full-Screen Walking Guide Container (Pure GPU Hardware-Accelerated) */
.chatbot-companion-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 130px;
    height: 102px;
    z-index: 10000;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    transition: opacity 0.25s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: none;
    pointer-events: all;
    will-change: transform;
    transform: translate3d(0, 0, 0);
}

.chatbot-companion-wrapper.dragging {
    cursor: grabbing !important;
    transition: none !important;
}

/* Lottie Robot Character Container (Attached Bodymovin JSON 500x394) */
.companion-character {
    width: 130px;
    height: 102px;
    position: relative;
    cursor: inherit;
    transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1);
    filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.85)) drop-shadow(0 0 16px rgba(209, 158, 81, 0.25));
    will-change: transform;
    transform: translateZ(0);
}

.companion-character:hover {
    transform: translateY(-4px) scale(1.05);
    filter: drop-shadow(0 14px 34px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 24px rgba(209, 158, 81, 0.5));
}

/* Mirror Glass Fracture Realistic Overlay */
.mirror-crack-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 8; /* On top surface of mirror glass substrate */
    transition: opacity 1.2s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Robot Physics & Interaction States */
.companion-character.held {
    animation: robotPickedUp 0.5s ease-in-out infinite alternate;
}
@keyframes robotPickedUp {
    0% { transform: scale(0.94, 1.08) rotate(-3deg); }
    50% { transform: scale(1.02, 0.98) rotate(0deg); }
    100% { transform: scale(0.92, 1.1) rotate(3deg); }
}

.companion-character.flying {
    filter: drop-shadow(0 15px 35px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 25px rgba(209, 158, 81, 0.45));
}

.companion-character.falling {
    animation: robotFallingFlail 0.2s ease-in-out infinite alternate;
}
@keyframes robotFallingFlail {
    0% { transform: scale(0.86, 1.16) translateY(-2px) rotate(-4deg); }
    100% { transform: scale(0.92, 1.1) translateY(2px) rotate(4deg); }
}

.companion-character.landing-squish {
    animation: robotLandSquish 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
@keyframes robotLandSquish {
    0% { transform: scale(1, 1); }
    25% { transform: scale(1.28, 0.72) translateY(5px); }
    55% { transform: scale(0.88, 1.12) translateY(-4px); }
    80% { transform: scale(1.05, 0.95) translateY(1px); }
    100% { transform: scale(1, 1) translateY(0); }
}

.companion-character.wall-impact {
    animation: robotWallImpact 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes robotWallImpact {
    0% { transform: scale(0.72, 1.3); }
    50% { transform: scale(1.15, 0.9); }
    100% { transform: scale(1, 1); }
}

.companion-character.mirror-impact {
    animation: robotMirrorImpact 0.45s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes robotMirrorImpact {
    0% { transform: scale(1.38, 0.62) translateY(4px); }
    40% { transform: scale(0.85, 1.2) translateY(-6px); }
    75% { transform: scale(1.08, 0.95) translateY(1px); }
    100% { transform: scale(1, 1) translateY(0); }
}

.companion-character.power-impact {
    animation: robotPowerImpact 0.45s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes robotPowerImpact {
    0% { transform: scale(1, 1); }
    30% { transform: scale(1.32, 0.68) translateY(4px); }
    60% { transform: scale(0.86, 1.18) translateY(-8px); }
    100% { transform: scale(1, 1) translateY(0); }
}

.lottie-robot-box {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lottie-robot-box svg {
    width: 100% !important;
    height: 100% !important;
    overflow: visible;
}

/* Robot React & Interaction State */
.companion-character.reacting {
    animation: robotAcknowledge 0.45s ease-in-out;
}
@keyframes robotAcknowledge {
    0% { transform: scale(1); }
    40% { transform: scale(1.16) translateY(-6px); }
    100% { transform: scale(1); }
}

/* Floating Luxury Speech Bubble (Direction-Neutral, Edge-Safe) */
.companion-speech-bubble {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: rgba(14, 10, 7, 0.96);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(209, 158, 81, 0.45);
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.85);
    padding: 0.55rem 1rem;
    border-radius: 18px;
    color: #F6E6CD;
    font-size: 0.76rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    white-space: normal;
    word-break: break-word;
    text-align: center;
    max-width: min(290px, calc(100vw - 2.5rem));
    width: max-content;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 1001;
    box-sizing: border-box;
}
.companion-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: rgba(14, 10, 7, 0.96) transparent transparent;
}
.companion-speech-bubble.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* AI Concierge Chat Window (Base Desktop) */
.chatbot-window {
    position: fixed;
    bottom: 5rem;
    right: 2.5rem;
    width: 410px;
    max-width: calc(100vw - 3rem);
    height: min(640px, calc(100dvh - 6.5rem));
    max-height: 85vh;
    background: rgba(10, 7, 5, 0.97);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(209, 158, 81, 0.3);
    border-radius: 18px;
    z-index: 10005;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85), 0 0 35px rgba(209, 158, 81, 0.12);
    overflow: hidden;
    font-family: 'Montserrat', sans-serif;
    transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), visibility 0.3s;
    transform-origin: bottom right;
    box-sizing: border-box;
}

.chatbot-window.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transform: scale(0.94) translateY(12px);
}

.chatbot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid rgba(209, 158, 81, 0.2);
    background: rgba(14, 10, 7, 0.95);
    flex-shrink: 0;
    box-sizing: border-box;
}
.chatbot-header-title {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}
.chatbot-status-dot {
    width: 8px;
    height: 8px;
    background: var(--gold);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--gold);
    flex-shrink: 0;
}
.chatbot-logo {
    height: 22px;
    width: auto;
    flex-shrink: 0;
}
.chatbot-header-text {
    font-size: 0.78rem;
    font-weight: 600;
    color: #FFFFFF;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chatbot-close {
    background: transparent;
    border: none;
    color: rgba(246, 230, 205, 0.7);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.25s, transform 0.25s;
    padding: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.chatbot-close:hover {
    color: var(--gold);
    transform: rotate(90deg);
}

.chatbot-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 1.2rem 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
    box-sizing: border-box;
}
.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}
.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(209, 158, 81, 0.25);
    border-radius: 4px;
}

.msg {
    max-width: 88%;
    padding: 0.85rem 1.1rem;
    border-radius: 14px;
    font-size: 0.86rem;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-sizing: border-box;
}
.msg.bot {
    align-self: flex-start;
    background: rgba(246, 230, 205, 0.04);
    color: #FFFFFF;
    border: 1px solid rgba(209, 158, 81, 0.22);
    border-left: 3px solid var(--gold);
    border-bottom-left-radius: 4px;
}
.msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #D19E51 0%, #b8853b 100%);
    color: #000000;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border-bottom-right-radius: 4px;
}

/* Typing Streaming Cursor */
.typing-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--gold);
    vertical-align: middle;
    margin-left: 3px;
    animation: cursorBlink 0.7s infinite;
}
@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Interactive Quick Reply Chips */
.chatbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.5rem;
    width: 100%;
    box-sizing: border-box;
}
.quick-reply-btn {
    background: rgba(215, 165, 244, 0.1);
    border: 1px solid rgba(215, 165, 244, 0.4);
    color: var(--color-lavender);
    padding: 0.45rem 0.85rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: normal;
    text-align: left;
    line-height: 1.35;
    touch-action: manipulation;
    max-width: 100%;
    box-sizing: border-box;
}
.quick-reply-btn:hover {
    background: var(--gold);
    color: #000000;
    border-color: var(--gold);
    box-shadow: 0 4px 15px rgba(209, 158, 81, 0.35);
}

.chatbot-input-area {
    display: flex;
    padding: 0.9rem 1.2rem;
    border-top: 1px solid rgba(209, 158, 81, 0.2);
    background: rgba(14, 10, 7, 0.95);
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
    box-sizing: border-box;
}
.chatbot-input-area input {
    flex: 1;
    min-width: 0;
    background: rgba(246, 230, 205, 0.04);
    border: 1px solid rgba(209, 158, 81, 0.25);
    border-radius: 24px;
    padding: 0.65rem 1rem;
    color: #ffffff;
    font-family: inherit;
    font-size: 16px; /* Prevents auto-zoom on iOS Safari */
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
    box-sizing: border-box;
}
.chatbot-input-area input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(209, 158, 81, 0.25);
}
.chatbot-input-area input::placeholder {
    color: rgba(246, 230, 205, 0.45);
}
.chatbot-input-area button {
    background: var(--gold);
    border: none;
    color: #000000;
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.chatbot-input-area button:hover {
    background: var(--color-champagne);
    transform: scale(1.05);
}

/* Inline Lead Form */
.chatbot-lead-form {
    background: rgba(14, 10, 7, 0.85);
    padding: 1.1rem;
    border-radius: 12px;
    border: 1px solid rgba(209, 158, 81, 0.25);
    margin-top: 0.6rem;
    width: 100%;
    box-sizing: border-box;
}
.chatbot-lead-form input, .chatbot-lead-form select, .chatbot-lead-form textarea {
    width: 100%;
    background: rgba(246, 230, 205, 0.04);
    border: 1px solid rgba(209, 158, 81, 0.22);
    color: #ffffff;
    padding: 0.7rem;
    margin-bottom: 0.7rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    outline: none;
    box-sizing: border-box;
}
.chatbot-lead-form input:focus, .chatbot-lead-form select:focus, .chatbot-lead-form textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(209, 158, 81, 0.25);
}
.chatbot-lead-form select option {
    background: #0a0705;
    color: #ffffff;
}
.chatbot-lead-form button {
    width: 100%;
    padding: 0.8rem;
    background: linear-gradient(135deg, #D19E51 0%, #b8853b 100%);
    color: #000000;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    transition: all 0.25s;
    min-height: 42px;
    box-sizing: border-box;
}
.chatbot-lead-form button:hover {
    background: var(--color-champagne);
    box-shadow: 0 4px 18px rgba(209, 158, 81, 0.45);
}

/* ==========================================================================
   Responsive Breakpoints for All Devices (320px to 1920px+)
   ========================================================================== */

/* Tablets / Medium Screens (769px to 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .chatbot-window {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 390px;
        max-width: calc(100vw - 3rem);
        height: min(620px, calc(100dvh - 3.5rem));
        border-radius: 18px;
    }
    .chatbot-companion-wrapper {
        width: 110px;
        height: 86px;
    }
    .companion-character {
        width: 110px;
        height: 86px;
    }
}

/* Mobile Phones (<= 768px Portrait) */
@media (max-width: 768px) {
    .chatbot-companion-wrapper {
        position: fixed !important;
        bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px)) !important;
        right: 0.65rem !important;
        left: auto !important;
        top: auto !important;
        width: 66px !important;
        height: 52px !important;
        z-index: 9999 !important;
    }
    .companion-character {
        width: 66px !important;
        height: 52px !important;
    }
    .companion-speech-bubble {
        position: absolute !important;
        bottom: calc(100% + 5px) !important;
        right: 0 !important;
        left: auto !important;
        transform: none !important;
        max-width: clamp(170px, 60vw, 220px) !important;
        font-size: 0.66rem !important;
        padding: 0.38rem 0.65rem !important;
        line-height: 1.35 !important;
        border-radius: 12px !important;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.9) !important;
    }
    .companion-speech-bubble::after {
        left: auto !important;
        right: 20px !important;
        transform: none !important;
    }
    .companion-speech-bubble.visible {
        transform: translateY(-2px) !important;
    }

    /* Native App Modal Experience on Mobile */
    .chatbot-window {
        position: fixed;
        inset: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        box-shadow: none;
        z-index: 10005;
        transform-origin: center bottom;
    }
    .chatbot-window.hidden {
        transform: translateY(100%);
    }

    .chatbot-header {
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-left: max(1.2rem, env(safe-area-inset-left));
        padding-right: max(1.2rem, env(safe-area-inset-right));
        padding-bottom: 0.85rem;
    }
    .chatbot-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 1.8rem;
    }

    .chatbot-messages {
        padding-top: 1rem;
        padding-left: max(1.1rem, env(safe-area-inset-left));
        padding-right: max(1.1rem, env(safe-area-inset-right));
        padding-bottom: 1rem;
        gap: 0.85rem;
    }
    .msg {
        max-width: 90%;
        font-size: 0.85rem;
        padding: 0.75rem 0.95rem;
    }

    .chatbot-input-area {
        padding-top: 0.75rem;
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
    }
    .chatbot-input-area button {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
    }
}

/* Small / Compact Phones (320px to 375px) */
@media (max-width: 375px) {
    .chatbot-header-text {
        font-size: 0.72rem;
        letter-spacing: 0.5px;
    }
    .chatbot-messages {
        padding: 0.85rem 0.9rem;
        gap: 0.75rem;
    }
    .msg {
        max-width: 94%;
        font-size: 0.82rem;
        padding: 0.65rem 0.85rem;
    }
    .quick-reply-btn {
        font-size: 0.68rem;
        padding: 0.38rem 0.7rem;
    }
    .chatbot-input-area {
        padding: 0.65rem 0.85rem max(0.75rem, env(safe-area-inset-bottom)) 0.85rem;
        gap: 0.4rem;
    }
}

/* Mobile Landscape (< 540px height) */
@media (max-height: 540px) and (orientation: landscape) {
    .chatbot-window {
        position: fixed;
        inset: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
    .chatbot-header {
        padding: max(0.4rem, env(safe-area-inset-top)) 1.2rem 0.4rem 1.2rem;
    }
    .chatbot-messages {
        padding: 0.55rem 1.2rem;
        gap: 0.5rem;
    }
    .msg {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
    .chatbot-input-area {
        padding: 0.4rem 1.2rem max(0.4rem, env(safe-area-inset-bottom)) 1.2rem;
    }
    .chatbot-lead-form {
        padding: 0.7rem;
        margin-top: 0.4rem;
    }
    .chatbot-lead-form input, .chatbot-lead-form select, .chatbot-lead-form textarea {
        padding: 0.45rem;
        margin-bottom: 0.45rem;
        font-size: 14px;
    }
}
