/* ==========================================================================
   CASA MODESTA - LUXURY CLIENT CONCIERGE LIVE CHAT WIDGET
   100% Glassmorphic, Draggable Bubble, Centered Modal & 4-Option Hub
   Synced with global.css Theme Variables (Dark & Light Mode)
   ========================================================================== */

#cm-chat-widget-root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    position: fixed;
    bottom: 104px;
    right: 16px;
    z-index: 9999998;
    touch-action: none;
}

body.woocommerce-checkout #cm-chat-widget-root {
    display: none !important;
}

/* 1. Fully Glossy Transparent Draggable Bubble (Icon Only) */
.cm-chat-trigger-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cm-surface);
    border: 1.5px solid var(--cm-border);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 0 20px var(--cm-matrix-glow);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
    position: relative;
}

.cm-chat-trigger-btn:hover {
    transform: scale(1.06);
    border-color: var(--cm-accent);
}

.cm-chat-trigger-btn.cm-is-dragging {
    cursor: grabbing !important;
    transform: scale(1.1) !important;
}

.cm-chat-trigger-icon {
    width: 24px;
    height: 24px;
    color: var(--cm-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.cm-chat-trigger-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.cm-chat-unread-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    background: #ff4d6d;
    color: #fff;
    font-size: 10px;
    font-weight: 900;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(255, 77, 109, 0.8);
    border: 2px solid var(--cm-bg, #15090d);
}

/* 2. Fullscreen Blur Backdrop */
.cm-chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 9999998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    display: none;
}

.cm-chat-backdrop.cm-active {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto;
}

/* 3. Centered Glassmorphic Chat Window */
.cm-chat-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    width: min(410px, calc(100vw - 28px));
    height: min(620px, calc(100dvh - 36px));
    max-height: 85vh;
    background: var(--cm-bg);
    border: 1px solid var(--cm-border);
    border-radius: 28px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), 0 0 35px var(--cm-matrix-glow);
    backdrop-filter: blur(35px);
    -webkit-backdrop-filter: blur(35px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999999;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
    box-sizing: border-box;
    color: var(--cm-text-static);
}

.cm-chat-window.cm-chat-open {
    display: flex !important;
    transform: translate(-50%, -50%) scale(1);
    opacity: 1 !important;
    pointer-events: auto;
}

/* 4. Luxury Header */
.cm-chat-header {
    padding: 14px 18px;
    background: var(--cm-surface);
    border-bottom: 1px solid var(--cm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.cm-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.cm-chat-avatar-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cm-card-glass);
    border: 1px solid var(--cm-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cm-accent);
    flex-shrink: 0;
}

.cm-chat-avatar-badge svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.cm-chat-header-text h4 {
    margin: 0;
    font-size: 14.5px;
    font-weight: 700;
    color: var(--cm-text-static, #fff7ec) !important;
    letter-spacing: 0.4px;
    line-height: 1.2;
}

.cm-chat-header-status {
    font-size: 10.5px;
    color: #22c55e;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    font-weight: 600;
}

.cm-chat-header-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 6px #22c55e;
}

.cm-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.cm-chat-back-btn,
.cm-chat-close-btn {
    background: transparent;
    border: none;
    color: var(--cm-accent);
    cursor: pointer;
    font-size: 18px;
    padding: 6px 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.cm-chat-back-btn {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    gap: 4px;
    padding: 4px 8px;
    background: var(--cm-card-glass);
}

.cm-chat-close-btn:hover,
.cm-chat-back-btn:hover {
    background: var(--cm-card-glass-hover);
}

/* 5. Window Body Views */
.cm-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    background: var(--cm-bg);
}

/* --- Options Hub --- */
.cm-hub-view {
    padding: 20px 16px 16px 16px;
    gap: 12px;
}

.cm-hub-banner {
    background: var(--cm-card-glass);
    border: 1px solid var(--cm-border);
    border-radius: 20px;
    padding: 14px 16px;
    margin-bottom: 4px;
    text-align: center;
}

.cm-hub-banner h3 {
    margin: 0 0 4px 0;
    font-family: 'Cinzel', serif;
    font-size: 16px;
    letter-spacing: 1.5px;
    color: var(--cm-text-static) !important;
    text-transform: uppercase;
}

.cm-hub-banner p {
    margin: 0;
    font-size: 11.5px;
    color: var(--cm-text-body) !important;
    line-height: 1.4;
}

.cm-hub-card {
    background: var(--cm-surface);
    border: 1px solid var(--cm-border);
    border-radius: 18px;
    padding: 13px 15px;
    display: flex;
    align-items: center;
    gap: 13px;
    cursor: pointer;
    text-decoration: none;
    color: var(--cm-text-static);
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    box-sizing: border-box;
}

.cm-hub-card:hover {
    transform: translateY(-2px);
    border-color: var(--cm-accent);
    background: var(--cm-card-glass-hover);
}

.cm-hub-card-primary {
    background: var(--cm-card-glass);
    border: 1.5px solid var(--cm-accent);
    box-shadow: 0 6px 20px var(--cm-matrix-glow);
}

.cm-hub-card-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--cm-glass-bg);
    border: 1px solid var(--cm-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cm-accent);
    font-size: 18px;
    flex-shrink: 0;
}

.cm-hub-card-icon.cm-icon-wa,
.cm-hub-card-icon.cm-icon-wa * {
    background: rgba(37, 211, 102, 0.12);
    border-color: rgba(37, 211, 102, 0.35);
    color: #25d366 !important;
}

.cm-hub-card-text {
    flex: 1;
    min-width: 0;
}

.cm-hub-card-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--cm-text-static) !important;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cm-hub-card-sub {
    font-size: 11px;
    color: var(--cm-text-body) !important;
    line-height: 1.35;
}

.cm-hub-badge-live {
    font-size: 9px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--cm-accent);
    color: var(--cm-btn-accent-color, #ffffff) !important;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.cm-hub-footer {
    margin-top: auto;
    padding: 12px 6px 4px 6px;
    text-align: center;
    font-size: 11px;
    color: var(--cm-text-body);
    line-height: 1.4;
}

.cm-hub-footer a {
    color: var(--cm-accent);
    text-decoration: underline;
    font-weight: 600;
}

/* --- Guest Intake Form --- */
.cm-intake-view {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
}

.cm-intake-title {
    text-align: center;
    margin-bottom: 6px;
}

.cm-intake-title h3 {
    font-family: 'Cinzel', serif;
    font-size: 18px;
    color: var(--cm-text-static) !important;
    margin-bottom: 4px;
}

.cm-intake-title p {
    font-size: 11.5px;
    color: var(--cm-text-body) !important;
}

.cm-intake-input {
    width: 100%;
    height: 46px;
    background: var(--cm-surface) !important;
    border: 1px solid var(--cm-border) !important;
    border-radius: 18px;
    padding: 0 16px;
    color: var(--cm-text-static) !important;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
}

.cm-intake-input:focus {
    border-color: var(--cm-accent) !important;
}

.cm-intake-submit {
    width: 100% !important;
    height: 48px !important;
    background: var(--cm-accent) !important;
    color: var(--cm-btn-accent-color, #ffffff) !important;
    border: none !important;
    border-radius: 24px !important;
    font-size: 12px !important;
    font-weight: 800 !important;
    letter-spacing: 1px !important;
    text-transform: uppercase !important;
    cursor: pointer !important;
    box-shadow: 0 6px 20px var(--cm-matrix-glow) !important;
    transition: transform 0.2s ease;
}

.cm-intake-submit:hover {
    transform: scale(1.02);
}

/* --- Live Chat Conversation View --- */
.cm-conv-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.cm-ticket-meta-bar {
    background: var(--cm-card-glass);
    border-bottom: 1px solid var(--cm-border);
    padding: 6px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--cm-text-body);
}

.cm-ticket-meta-bar strong {
    color: var(--cm-accent);
}

.cm-chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cm-chat-messages::-webkit-scrollbar { width: 4px; }
.cm-chat-messages::-webkit-scrollbar-thumb { background: var(--cm-border); border-radius: 4px; }

.cm-chat-msg {
    max-width: 82%;
    padding: 10px 14px;
    font-size: 12.5px;
    line-height: 1.45;
    word-break: break-word;
    animation: cmMsgIn 0.22s ease-out;
}

@keyframes cmMsgIn {
    0% { opacity: 0; transform: translateY(6px); }
    100% { opacity: 1; transform: translateY(0); }
}

.cm-chat-msg-user {
    align-self: flex-end;
    background: var(--cm-accent);
    color: var(--cm-btn-accent-color, #ffffff) !important;
    border-radius: 18px 18px 4px 18px;
    font-weight: 500;
}

.cm-chat-msg-admin {
    align-self: flex-start;
    background: var(--cm-card-glass);
    border: 1px solid var(--cm-border);
    color: var(--cm-text-static);
    border-radius: 18px 18px 18px 4px;
}

.cm-chat-msg-time {
    font-size: 9.5px;
    opacity: 0.75;
    margin-top: 3px;
    text-align: right;
    color: inherit;
}

.cm-chat-msg-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 12px;
    margin-top: 4px;
    cursor: pointer;
    display: block;
}

.cm-chat-quick-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 6px 12px;
    border-top: 1px solid var(--cm-border);
    scrollbar-width: none;
    background: var(--cm-surface);
}
.cm-chat-chip {
    background: var(--cm-card-glass) !important;
    border: 1px solid var(--cm-border) !important;
    color: var(--cm-text-static) !important;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

/* Resolution Banner */
.cm-resolved-banner {
    margin: 12px;
    padding: 16px;
    background: var(--cm-card-glass);
    border: 1px solid var(--cm-accent);
    border-radius: 20px;
    text-align: center;
}

.cm-resolved-banner h4 {
    font-size: 14px;
    color: var(--cm-accent);
    margin-bottom: 4px;
}

.cm-resolved-banner p {
    font-size: 11.5px;
    color: var(--cm-text-body);
    margin-bottom: 12px;
    line-height: 1.4;
}

.cm-new-chat-btn {
    padding: 10px 20px !important;
    background: var(--cm-accent) !important;
    color: var(--cm-btn-accent-color, #ffffff) !important;
    border: none !important;
    border-radius: 20px !important;
    font-size: 11.5px !important;
    font-weight: 900 !important;
    cursor: pointer !important;
    text-transform: uppercase !important;
    letter-spacing: 0.8px !important;
    box-shadow: 0 4px 15px var(--cm-matrix-glow) !important;
}

/* Input Bar */
.cm-chat-input-bar {
    padding: 10px 14px;
    background: var(--cm-surface);
    border-top: 1px solid var(--cm-border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.cm-chat-attach-btn {
    color: var(--cm-accent);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cm-chat-input-field {
    flex: 1;
    background: var(--cm-bg);
    border: 1px solid var(--cm-border);
    border-radius: 22px;
    padding: 10px 16px;
    color: var(--cm-text-static);
    font-size: 13px;
    outline: none;
}

.cm-chat-input-field:focus {
    border-color: var(--cm-accent);
}

.cm-chat-send-btn {
    background: var(--cm-accent) !important;
    color: var(--cm-btn-accent-color, #ffffff) !important;
    border: none !important;
    width: 38px !important;
    height: 38px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 900 !important;
    flex-shrink: 0 !important;
}

.cm-chat-send-btn svg {
    width: 17px !important;
    height: 17px !important;
    fill: var(--cm-btn-accent-color, #ffffff) !important;
    color: var(--cm-btn-accent-color, #ffffff) !important;
    margin-left: 2px !important;
}

.cm-chat-send-btn svg path {
    fill: var(--cm-btn-accent-color, #ffffff) !important;
}

/* --- FAQs View --- */
.cm-faq-view {
    padding: 16px;
    gap: 10px;
}

.cm-faq-item {
    background: var(--cm-card-glass);
    border: 1px solid var(--cm-border);
    border-radius: 16px;
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.cm-faq-question {
    padding: 12px 14px;
    font-size: 13px;
    font-weight: 700;
    color: var(--cm-text-static);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.cm-faq-arrow {
    color: var(--cm-accent);
    font-size: 12px;
    transition: transform 0.2s ease;
}

.cm-faq-item.cm-open .cm-faq-arrow {
    transform: rotate(180deg);
}

.cm-faq-answer {
    padding: 0 14px 12px 14px;
    font-size: 11.5px;
    color: var(--cm-text-body);
    line-height: 1.5;
    display: none;
}

.cm-faq-item.cm-open .cm-faq-answer {
    display: block;
}

/* Responsive Viewport */
@media (max-width: 480px) {
    .cm-chat-window {
        width: calc(100vw - 20px) !important;
        height: min(580px, calc(100dvh - 30px)) !important;
        border-radius: 24px;
    }
}

/* Business Inquiries Footer Note (Light & Dark Mode) */
.cm-hub-business-note {
    width: 100% !important;
    text-align: center !important;
    display: block !important;
    box-sizing: border-box !important;
    padding: 12px 14px 6px;
    font-size: 12px;
    color: var(--cm-text-body) !important;
    border-top: 1px solid var(--cm-border);
    margin: 4px auto 0 !important;
}
.cm-hub-business-note a {
    color: var(--cm-accent) !important;
    text-decoration: none;
    font-weight: 700;
}

/* 1-5 Star Post-Resolution Rating */
.cm-star-rating-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 10px 0 6px 0;
    font-size: 28px;
    cursor: pointer;
    user-select: none;
}
.cm-star-btn {
    color: var(--cm-border);
    transition: transform 0.15s ease, color 0.2s ease;
    display: inline-block;
}
.cm-star-btn:hover {
    transform: scale(1.22);
}

/* Live Chat In-App Notification Toast */
#cm-live-chat-notif-toast {
    position: fixed;
    top: 78px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100vw - 32px);
    max-width: 390px;
    background: var(--cm-surface);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--cm-border);
    border-radius: 20px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    z-index: 999999;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    box-sizing: border-box;
    color: var(--cm-text-static);
}

/* Dynamic Active Theme Adaptations for Light Mode */
html[data-theme="light"] .cm-chat-window,
body[data-theme="light"] .cm-chat-window {
    background: var(--cm-bg) !important;
    border-color: var(--cm-border) !important;
    color: var(--cm-text-static) !important;
}
html[data-theme="light"] .cm-chat-header,
body[data-theme="light"] .cm-chat-header {
    background: var(--cm-surface) !important;
    border-bottom-color: var(--cm-border) !important;
}
html[data-theme="light"] .cm-chat-view,
body[data-theme="light"] .cm-chat-view {
    background: var(--cm-bg) !important;
}
html[data-theme="light"] .cm-hub-banner,
html[data-theme="light"] .cm-hub-card,
html[data-theme="light"] .cm-faq-item,
body[data-theme="light"] .cm-hub-banner,
body[data-theme="light"] .cm-hub-card,
body[data-theme="light"] .cm-faq-item {
    background: var(--cm-card-glass) !important;
    border-color: var(--cm-border) !important;
}
html[data-theme="light"] .cm-hub-card:hover,
html[data-theme="light"] .cm-faq-item:hover,
body[data-theme="light"] .cm-hub-card:hover,
body[data-theme="light"] .cm-faq-item:hover {
    background: var(--cm-card-glass-hover) !important;
    border-color: var(--cm-accent) !important;
}
html[data-theme="light"] .cm-hub-card-title,
html[data-theme="light"] .cm-hub-banner h3,
html[data-theme="light"] .cm-chat-header-text h4,
html[data-theme="light"] .cm-faq-question,
html[data-theme="light"] .cm-chat-msg-admin,
body[data-theme="light"] .cm-hub-card-title,
body[data-theme="light"] .cm-hub-banner h3,
body[data-theme="light"] .cm-chat-header-text h4,
body[data-theme="light"] .cm-faq-question,
body[data-theme="light"] .cm-chat-msg-admin {
    color: var(--cm-text-heading) !important;
}
html[data-theme="light"] .cm-hub-card-sub,
html[data-theme="light"] .cm-hub-banner p,
html[data-theme="light"] .cm-faq-answer,
html[data-theme="light"] .cm-hub-business-note,
body[data-theme="light"] .cm-hub-card-sub,
body[data-theme="light"] .cm-hub-banner p,
body[data-theme="light"] .cm-faq-answer,
body[data-theme="light"] .cm-hub-business-note {
    color: var(--cm-text-body) !important;
}
html[data-theme="light"] .cm-chat-input-bar,
body[data-theme="light"] .cm-chat-input-bar {
    background: var(--cm-surface) !important;
    border-top-color: var(--cm-border) !important;
}
html[data-theme="light"] .cm-chat-input-field,
body[data-theme="light"] .cm-chat-input-field {
    background: var(--cm-bg) !important;
    border-color: var(--cm-border) !important;
    color: var(--cm-text-heading) !important;
}
html[data-theme="light"] #cm-live-chat-notif-toast button,
html[data-theme="light"] .cm-intake-submit,
html[data-theme="light"] .cm-new-chat-btn,
html[data-theme="light"] .cm-hub-badge-live,
html[data-theme="light"] .cm-chat-msg-user,
html[data-theme="light"] .cm-chat-send-btn svg,
html[data-theme="light"] .cm-chat-send-btn svg path {
    color: #000000 !important;
    fill: #000000 !important;
}

