/* premium styling tokens for chat widget */
:root {
    --chat-bg-glass: rgba(17, 24, 39, 0.82);
    --chat-border: rgba(255, 255, 255, 0.08);
    --chat-header-grad: linear-gradient(135deg, #111827, #1f2937);
    
    --accent-teal: #14b8a6;
    --accent-teal-dark: #0f766e;
    --accent-gold: #d4af37;
    --accent-gold-dark: #b89114;
    
    --text-light: #f3f4f6;
    --text-muted: #9ca3af;
    --shadow-premium: 0 16px 40px rgba(0, 0, 0, 0.5);
}

/* Launcher Button */
.chat-launcher-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 1px solid var(--chat-border);
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-teal));
    color: #000;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(20, 184, 166, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 99999;
}

.chat-launcher-btn:hover {
    transform: scale(1.08) rotate(5deg);
    box-shadow: 0 15px 35px rgba(20, 184, 166, 0.5);
}

.chat-launcher-btn:active {
    transform: scale(0.95);
}

.chat-icon-svg {
    width: 28px;
    height: 28px;
    color: #ffffff;
    transition: transform 0.3s;
}

.chat-launcher-btn:hover .chat-icon-svg {
    transform: scale(1.05);
}

/* Chat Window Container */
.chat-window-container {
    position: fixed;
    bottom: 105px;
    right: 30px;
    width: 380px;
    height: 580px;
    max-height: 80vh;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-premium);
    border: 1px solid var(--chat-border);
    background: var(--chat-bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 99998;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease-in-out, width 0.25s ease, height 0.25s ease;
    transform-origin: bottom right;
}

/* Visibility toggling with smooth animation */
.chat-window-container.hidden {
    opacity: 0;
    transform: translateY(40px) scale(0.8);
    pointer-events: none;
}

/* Header */
.chat-header {
    background: var(--chat-header-grad);
    border-bottom: 1px solid var(--chat-border);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.agent-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.agent-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-teal));
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-avatar::after {
    content: "VV";
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
}

.active-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background-color: #10b981;
    border: 2px solid #1f2937;
    border-radius: 50%;
}

.agent-name {
    color: var(--text-light);
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
}

.agent-status {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.chat-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-close-btn:hover {
    color: var(--text-light);
    transform: scale(1.1);
}

.chat-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-related-content {
    max-height: 42%;
    padding: 0.85rem 0.85rem 0;
    position: relative;
    overflow: hidden;
}

.chat-related-content.hidden {
    display: none;
}

.related-carousel {
    position: relative;
    height: 100%;
    min-height: 0;
}

.related-carousel-track {
    height: 100%;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    gap: 0.85rem;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    outline: none;
}

.related-carousel-track::-webkit-scrollbar {
    display: none;
}

.related-carousel-arrow {
    position: absolute;
    top: 50%;
    z-index: 3;
    width: 38px;
    height: 46px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(10, 15, 24, 0.66);
    color: #ffffff;
    cursor: pointer;
    font-size: 2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-50%);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
    transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.related-carousel-arrow.previous {
    left: 0.45rem;
}

.related-carousel-arrow.next {
    right: 0.45rem;
}

.related-carousel-arrow:hover:not(:disabled) {
    border-color: rgba(212, 175, 55, 0.62);
    transform: translateY(-50%) scale(1.04);
}

.related-carousel-arrow:disabled {
    cursor: default;
    opacity: 0.26;
}

.related-carousel-arrow.hidden {
    display: none;
}

.related-card {
    flex: 0 0 100%;
    min-width: 0;
    scroll-snap-align: center;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.025)),
        rgba(10, 15, 24, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.9rem;
    color: var(--text-light);
    opacity: 0.54;
    transform: scale(0.965);
    transition: opacity 0.38s ease, transform 0.38s ease, border-color 0.38s ease, box-shadow 0.38s ease;
}

.related-card.has-image {
    padding: 0;
    overflow: hidden;
}

.related-card.is-active {
    opacity: 1;
    transform: scale(1);
    border-color: rgba(212, 175, 55, 0.3);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}

.related-card-image {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    background: transparent;
}

.related-card.has-image .related-card-image {
    border-radius: 0;
    margin-bottom: 0;
}

.related-card.is-floor-plan .related-card-image {
    object-fit: contain;
    background:
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.07), transparent 68%),
        rgba(255, 255, 255, 0.015);
}

.related-card-body {
    padding: 0;
}

.related-card.has-image .related-card-body {
    padding: 0.9rem;
}

.related-card-title {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 0.98rem;
    line-height: 1.25;
    color: #ffffff;
}

.related-card-subtitle {
    margin: 0.3rem 0 0;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.35;
}

.related-card-bullets {
    margin: 0.65rem 0 0;
    padding-left: 1rem;
    color: var(--text-light);
    font-size: 0.78rem;
    line-height: 1.35;
}

.related-card-bullets li {
    margin: 0.25rem 0;
}

.related-card-resources {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.7rem;
}

.related-resource-link,
.related-cta {
    min-height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(212, 175, 55, 0.45);
    background: rgba(212, 175, 55, 0.1);
    color: #f8e8a0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.42rem 0.65rem;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.15;
    text-decoration: none;
    cursor: pointer;
}

.related-cta {
    width: 100%;
    margin-top: 0.7rem;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-dark));
    border: none;
    color: #0a0f18;
}

/* Chat Messages Box */
.chat-messages-box {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

.chat-window-container.has-related .chat-messages-box {
    padding-top: 0.85rem;
}

/* Custom Scrollbar for Messages */
.chat-messages-box::-webkit-scrollbar {
    width: 5px;
}
.chat-messages-box::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages-box::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.chat-messages-box::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Message Bubble */
.message-bubble {
    max-width: 80%;
    padding: 0.85rem 1.1rem;
    border-radius: 18px;
    font-size: 0.92rem;
    line-height: 1.45;
    animation: msgFadeIn 0.3s ease-out;
}

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

.message-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent-teal-dark), var(--accent-teal));
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(20, 184, 166, 0.15);
}

.message-bubble.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-light);
    border: 1px solid var(--chat-border);
    border-top-left-radius: 4px;
}

.message-bubble p {
    margin: 0 0 0.55rem;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble ul {
    margin: 0.35rem 0 0.7rem;
    padding-left: 1.1rem;
}

.message-bubble li {
    margin: 0.25rem 0;
}

.message-bubble strong {
    font-weight: 700;
    color: #ffffff;
}

/* Input Area */
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--chat-border);
    background: rgba(10, 15, 24, 0.4);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-input-area input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--chat-border);
    border-radius: 50px;
    padding: 0.75rem 1.25rem;
    color: var(--text-light);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.2s, background-color 0.2s;
}

.chat-input-area input:focus {
    border-color: var(--accent-teal);
    background: rgba(255, 255, 255, 0.08);
}

.chat-input-area input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.chat-input-area button {
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-dark));
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #000000;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-input-area button:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.chat-input-area button:active {
    transform: scale(0.95);
}

.send-icon-svg {
    width: 18px;
    height: 18px;
}

/* Loading Dots */
.loading-bubble {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--chat-border);
    padding: 0.85rem 1.25rem;
    border-radius: 18px;
    border-top-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--accent-teal);
    animation: dotBounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Responsive adjustment for Mobile screens */
@media (max-width: 480px) {
    .chat-window-container {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }
    .chat-launcher-btn {
        bottom: 20px;
        right: 20px;
    }
}

@media (max-width: 719px) {
    .chat-window-container.has-related.has-visual-related .chat-related-content {
        max-height: 62vh;
        padding: 0.7rem 0.7rem 0;
    }

    .chat-window-container.has-related.has-visual-related .related-card {
        flex-basis: 94%;
    }

    .chat-window-container.has-related.has-visual-related .related-card-image {
        aspect-ratio: 16 / 10;
        object-fit: cover;
    }

    .chat-window-container.has-related.has-visual-related .related-card.is-floor-plan .related-card-image {
        object-fit: contain;
    }

    .chat-window-container.has-related.has-visual-related .chat-messages-box {
        padding: 0.75rem 1rem;
    }
}

@media (min-width: 720px) {
    .chat-window-container.has-related {
        width: min(760px, calc(100vw - 60px));
    }

    .chat-window-container.has-related .chat-body {
        flex-direction: row;
    }

    .chat-window-container.has-related .chat-related-content {
        width: 330px;
        max-height: none;
        padding: 1rem;
        border-right: 1px solid var(--chat-border);
    }

    .chat-window-container.has-related .related-card {
        width: 100%;
    }

    .chat-window-container.has-related .chat-messages-box {
        min-width: 0;
    }

    .chat-window-container.has-related.has-visual-related {
        width: min(1180px, calc(100vw - 60px));
        height: min(760px, calc(100vh - 60px));
        max-height: calc(100vh - 60px);
    }

    .chat-window-container.has-related.has-visual-related .chat-related-content {
        flex: 1;
        width: auto;
        padding: 1rem;
    }

    .chat-window-container.has-related.has-visual-related .related-card {
        display: flex;
        min-height: 0;
        flex-direction: column;
    }

    .chat-window-container.has-related.has-visual-related .related-card.has-image {
        min-height: 420px;
    }

    .chat-window-container.has-related.has-visual-related .related-card-image {
        flex: 1;
        min-height: 310px;
        aspect-ratio: auto;
    }

    .chat-window-container.has-related.has-visual-related .related-card-body {
        flex: 0 0 auto;
    }

    .chat-window-container.has-related.has-visual-related .chat-messages-box {
        flex: 0 0 340px;
        border-left: 1px solid var(--chat-border);
    }
}

@media (min-width: 1040px) {
    .chat-window-container.has-related.has-visual-related .chat-messages-box {
        flex-basis: 360px;
    }

    .chat-window-container.has-related.has-visual-related .related-card-image {
        min-height: 390px;
    }
}
