/**
 * Estatify Chatbot UI — Premium Glassmorphic Design
 *
 * A stunning, modern chat widget with glassmorphism effects,
 * smooth animations, full-screen support, and property card rendering.
 */

/* ──────────────────────────────────────────────
   CSS Custom Properties (Admin-Configurable)
   ────────────────────────────────────────────── */

:root {
    --emls-chat-primary: #2563eb;
    --emls-chat-secondary: #1e40af;
    --emls-chat-bg: #ffffff;
    --emls-chat-text: #1f2937;
    --emls-chat-header-bg: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    --emls-chat-radius: 16px;
    --emls-chat-font: 'Inter', system-ui, -apple-system, sans-serif;
    --emls-chat-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.25);
    --emls-chat-shadow-hover: 0 30px 70px -12px rgba(0, 0, 0, 0.35);
    --emls-chat-glass: rgba(255, 255, 255, 0.08);
    --emls-chat-glass-border: rgba(255, 255, 255, 0.18);
    --emls-chat-width: 400px;
    --emls-chat-height: 600px;
}

/* ──────────────────────────────────────────────
   Font Import
   ────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ──────────────────────────────────────────────
   Chat Toggle Button (FAB)
   ────────────────────────────────────────────── */

.emls-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: var(--emls-chat-header-bg);
    color: #fff;
    cursor: pointer;
    z-index: 999998;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(37, 99, 235, 0.35);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.3s ease;
    animation: emls-fab-entrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.emls-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(37, 99, 235, 0.5);
}

.emls-chat-toggle:active {
    transform: scale(0.95);
}

.emls-chat-toggle svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.emls-chat-toggle .emls-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.emls-chat-toggle.active .emls-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.emls-chat-toggle.active .emls-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Hide FAB when chat is open – use header close only; remove from layout so no gap */
#emls-chatbot-container.emls-chat-open .emls-chat-toggle {
    display: none !important;
}

/* When chat is open, sit window at bottom/right edge so no empty space where FAB was */
#emls-chatbot-container.emls-chat-open .emls-chat-window {
    bottom: 24px;
    right: 24px;
}

#emls-chatbot-container.emls-chat-open .emls-chat-window.position-left {
    right: auto;
    left: 24px;
}

/* Position: Bottom Left */
.emls-chat-toggle.position-left {
    right: auto;
    left: 24px;
}

/* ──────────────────────────────────────────────
   Proactive Bubble
   ────────────────────────────────────────────── */

.emls-proactive-bubble {
    position: fixed;
    bottom: 100px;
    right: 24px;
    max-width: 280px;
    background: var(--emls-chat-bg);
    color: var(--emls-chat-text);
    padding: 14px 18px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    font-family: var(--emls-chat-font);
    font-size: 14px;
    line-height: 1.5;
    z-index: 999997;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
}

.emls-proactive-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.emls-proactive-bubble .emls-proactive-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f3f4f6;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #6b7280;
    transition: background 0.2s;
}

.emls-proactive-bubble .emls-proactive-close:hover {
    background: #e5e7eb;
}

.emls-proactive-bubble.position-left {
    right: auto;
    left: 24px;
    border-radius: 16px 16px 16px 4px;
}

/* ──────────────────────────────────────────────
   Chat Window
   ────────────────────────────────────────────── */

.emls-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: var(--emls-chat-width);
    height: var(--emls-chat-height);
    max-height: calc(100vh - 140px);
    border-radius: var(--emls-chat-radius);
    background: var(--emls-chat-bg);
    box-shadow: var(--emls-chat-shadow);
    font-family: var(--emls-chat-font);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s ease,
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        width 0.4s ease,
        height 0.4s ease,
        bottom 0.4s ease,
        right 0.4s ease,
        left 0.4s ease,
        border-radius 0.4s ease,
        max-height 0.4s ease;
}

.emls-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.emls-chat-window.position-left {
    right: auto;
    left: 24px;
}

/* ──────────────────────────────────────────────
   Full Screen Mode
   ────────────────────────────────────────────── */

.emls-chat-window.fullscreen {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    z-index: 1000000;
}

.emls-chat-window.fullscreen .emls-chat-header {
    border-radius: 0;
}

.emls-chat-window.fullscreen .emls-chat-messages {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.emls-chat-window.fullscreen .emls-chat-input-area {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* ──────────────────────────────────────────────
   Chat Header
   ────────────────────────────────────────────── */

.emls-chat-header {
    background: var(--emls-chat-header-bg);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Glassmorphic shimmer overlay */
.emls-chat-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg,
            transparent 30%,
            rgba(255, 255, 255, 0.06) 50%,
            transparent 70%);
    pointer-events: none;
}

.emls-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--emls-chat-glass);
    border: 2px solid var(--emls-chat-glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.emls-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.emls-chat-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
    flex-shrink: 0;
    display: block;
}

.emls-chat-header-info {
    flex: 1;
    min-width: 0;
}

.emls-chat-header-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emls-chat-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
}

.emls-chat-header-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    animation: emls-pulse 2s ease-in-out infinite;
}

.emls-chat-header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.emls-chat-header-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.emls-chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.05);
}

.emls-chat-header-actions button svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    display: block;
}

/* In fullscreen: show minimize, hide fullscreen expand */
.emls-chat-window.fullscreen .emls-chat-btn-fullscreen {
    display: none !important;
}

.emls-chat-window.fullscreen .emls-chat-btn-minimize {
    display: flex !important;
}

/* ──────────────────────────────────────────────
   Messages Area
   ────────────────────────────────────────────── */

.emls-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-width: 0;
}

/* Custom scrollbar */
.emls-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.emls-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.emls-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.emls-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ──────────────────────────────────────────────
   Message Bubbles
   ────────────────────────────────────────────── */

.emls-chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: emls-msg-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.emls-chat-msg.user {
    align-self: flex-end;
    background: var(--emls-chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.emls-chat-msg.assistant {
    align-self: flex-start;
    background: #f3f4f6;
    color: var(--emls-chat-text);
    border-bottom-left-radius: 4px;
}

.emls-chat-msg.assistant a {
    color: var(--emls-chat-primary);
    text-decoration: underline;
}

/* Typing indicator */
.emls-chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: #f3f4f6;
    border-radius: 16px 16px 16px 4px;
    animation: emls-msg-in 0.3s ease both;
}

.emls-chat-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: emls-typing-bounce 1.4s ease-in-out infinite;
}

.emls-chat-typing span:nth-child(2) {
    animation-delay: 0.16s;
}

.emls-chat-typing span:nth-child(3) {
    animation-delay: 0.32s;
}

/* ──────────────────────────────────────────────
   Quick Replies – compact, responsive, contained
   ────────────────────────────────────────────── */

.emls-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 2px 0 4px;
    animation: emls-msg-in 0.4s ease both;
    max-width: 100%;
    min-width: 0;
}

.emls-chat-quick-reply {
    padding: 4px 8px;
    border: 1px solid var(--emls-chat-primary);
    color: var(--emls-chat-primary);
    background: transparent;
    border-radius: 8px;
    font-size: 9px;
    font-family: var(--emls-chat-font);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s;
    white-space: normal;
    word-break: break-word;
    max-width: calc(50% - 3px);
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    line-height: 1.25;
    text-align: center;
    box-sizing: border-box;
}

.emls-chat-quick-reply:hover {
    background: var(--emls-chat-primary);
    color: #fff;
    transform: translateY(-1px);
}

.emls-chat-quick-reply:active {
    transform: scale(0.97);
}

.emls-chat-quick-reply,
.emls-chat-quick-reply * {
    font-size: 9px !important;
}

/* ──────────────────────────────────────────────
   Property Cards (Inside Chat)
   ────────────────────────────────────────────── */

.emls-chat-properties {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0 12px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    animation: emls-msg-in 0.4s ease both;
}

.emls-chat-properties::-webkit-scrollbar {
    height: 4px;
}

.emls-chat-properties::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

.emls-chat-property-card {
    flex: 0 0 260px;
    scroll-snap-align: start;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.emls-chat-property-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
}

.emls-chat-property-card-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    background: linear-gradient(135deg, #e5e7eb, #f3f4f6);
}

.emls-chat-property-card-body {
    padding: 12px;
}

.emls-chat-property-card-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--emls-chat-primary);
    margin-bottom: 4px;
}

.emls-chat-property-card-title {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.emls-chat-property-card-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: #9ca3af;
}

.emls-chat-property-card-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.emls-chat-property-card-location {
    font-size: 12px;
    color: #6b7280;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ──────────────────────────────────────────────
   Input Area
   ────────────────────────────────────────────── */

.emls-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--emls-chat-bg);
    flex-shrink: 0;
}

.emls-chat-input {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: 14px;
    font-family: var(--emls-chat-font);
    color: var(--emls-chat-text);
    background: #f9fafb;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    line-height: 1.4;
}

.emls-chat-input:focus {
    border-color: var(--emls-chat-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.emls-chat-input::placeholder {
    color: #9ca3af;
}

.emls-chat-send-btn {
    width: 40px !important;
    height: 40px !important;
    border: none !important;
    border-radius: 50% !important;
    background: var(--emls-chat-primary) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.2s, transform 0.15s !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
}

.emls-chat-send-btn:hover {
    background: var(--emls-chat-secondary);
    transform: scale(1.05);
}

.emls-chat-send-btn:active {
    transform: scale(0.95);
}

.emls-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.emls-chat-send-btn svg {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0 !important;
    stroke: currentColor !important;
    fill: none !important;
    display: block !important;
    margin: 0 !important;
}

/* Voice button */
.emls-chat-voice-btn {
    width: 40px !important;
    height: 40px !important;
    border: 1.5px solid #e5e7eb !important;
    border-radius: 50% !important;
    background: transparent !important;
    color: #6b7280 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.emls-chat-voice-btn:hover {
    border-color: var(--emls-chat-primary);
    color: var(--emls-chat-primary);
}

.emls-chat-voice-btn.recording {
    border-color: #ef4444;
    color: #ef4444;
    animation: emls-pulse-red 1.5s ease-in-out infinite;
}

.emls-chat-voice-btn svg {
    width: 18px !important;
    height: 18px !important;
    fill: none !important;
    stroke: currentColor !important;
    display: block !important;
}

/* ──────────────────────────────────────────────
   Lead Capture Notice
   ────────────────────────────────────────────── */

.emls-chat-lead-notice {
    background: linear-gradient(135deg, #ecfdf5, #f0fdf4);
    border: 1px solid #86efac;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 13px;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: emls-msg-in 0.4s ease both;
}

.emls-chat-lead-notice svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: #22c55e;
}

/* ──────────────────────────────────────────────
   Animations
   ────────────────────────────────────────────── */

@keyframes emls-fab-entrance {
    from {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }

    to {
        opacity: 1;
        transform: scale(1) rotate(0);
    }
}

@keyframes emls-msg-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes emls-typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

@keyframes emls-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes emls-pulse-red {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

/* ──────────────────────────────────────────────
   Mobile Responsive
   ────────────────────────────────────────────── */

@media (max-width: 480px) {
    .emls-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .emls-chat-window.position-left {
        left: 0;
        right: 0;
    }

    .emls-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .emls-chat-toggle.position-left {
        left: 16px;
    }

    .emls-proactive-bubble {
        right: 16px;
        bottom: 84px;
        max-width: 240px;
    }

    .emls-chat-property-card {
        flex: 0 0 220px;
    }
}

/* ──────────────────────────────────────────────
   Powered By footer
   ────────────────────────────────────────────── */

.emls-chat-powered {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: #9ca3af;
    background: var(--emls-chat-bg);
    flex-shrink: 0;
}

.emls-chat-powered a {
    color: #6b7280;
    text-decoration: none;
    font-weight: 500;
}

.emls-chat-powered a:hover {
    color: var(--emls-chat-primary);
}