/* Live support chat widget */
.live-chat-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 1060;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.45);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.live-chat-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 28px rgba(37, 99, 235, 0.55);
}
.live-chat-fab.has-unread::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
}

body.has-bottom-nav .live-chat-fab {
    bottom: 78px;
}

body.chat-fullscreen .live-chat-fab,
body.chat-fullscreen .live-chat-panel {
    display: none !important;
}

.live-chat-panel {
    position: fixed;
    bottom: 94px;
    left: 24px;
    z-index: 1059;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.92) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.live-chat-panel.open {
    transform: none;
    opacity: 1;
    pointer-events: auto;
}
body.has-bottom-nav .live-chat-panel {
    bottom: 148px;
}

#liveChatChatArea {
    display: none;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
#liveChatChatArea.is-visible {
    display: flex !important;
}

.live-chat-header {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.live-chat-header h6 {
    margin: 0;
    font-weight: 700;
    font-size: 0.95rem;
}
.live-chat-header small {
    opacity: 0.85;
    font-size: 0.72rem;
}

.live-chat-form {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}
.live-chat-form label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 2px;
}

.live-chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}
.live-chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
    word-wrap: break-word;
}
.live-chat-msg.guest {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-left-radius: 4px;
}
.live-chat-msg.staff {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-bottom-right-radius: 4px;
}
.live-chat-msg .msg-meta {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 4px;
}
.live-chat-msg .msg-sender {
    font-size: 0.68rem;
    font-weight: 700;
    margin-bottom: 2px;
    font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
}

.live-chat-input-bar {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}
.live-chat-input-bar form {
    display: flex;
    gap: 8px;
    align-items: center;
}
.live-chat-input-bar input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 16px; /* prevent iOS zoom */
    outline: none;
    min-width: 0;
}
.live-chat-input-bar input:focus {
    border-color: #2563eb;
}
.live-chat-input-bar button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    flex-shrink: 0;
}

.live-chat-status {
    text-align: center;
    font-size: 0.72rem;
    color: #64748b;
    padding: 4px;
    background: #f1f5f9;
    flex-shrink: 0;
}
.live-chat-status.offline { color: #ef4444; }

.live-chat-canned {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 12px;
    border-top: 1px solid #f1f5f9;
    max-height: 80px;
    overflow-y: auto;
}
.live-chat-canned button {
    font-size: 0.68rem;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    cursor: pointer;
}
.live-chat-canned button:hover {
    background: #dbeafe;
}

/* Full-screen on phones so panel is not clipped by bottom nav / viewport */
@media (max-width: 767.98px) {
    .live-chat-panel,
    body.has-bottom-nav .live-chat-panel {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        z-index: 3000 !important;
        transform: translateY(100%);
        box-shadow: none;
    }
    .live-chat-panel.open,
    body.has-bottom-nav .live-chat-panel.open {
        transform: none;
    }
    .live-chat-header {
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
    }
    body.livechat-open {
        overflow: hidden !important;
        touch-action: none;
    }
    body.livechat-open .live-chat-fab,
    body.livechat-open .mobile-bottom-nav,
    body.livechat-open .pwa-install-banner,
    body.livechat-open .site-navbar,
    body.livechat-open #buildingMobileDrawer,
    body.livechat-open #buildingDrawerBackdrop,
    body.livechat-open #buildingMenuToggle {
        visibility: hidden !important;
        pointer-events: none !important;
    }
}
