/* ==========================================================================
   1. RESET & ROOT CONTAINER
   ========================================================================== */
#lcfw-chat-root-container *,
#lcfw-chat-root-container *::before,
#lcfw-chat-root-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    line-height: inherit;
    border: 0;
    vertical-align: baseline;
    background: transparent;
    list-style: none;
    text-decoration: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    outline: none;
}

#lcfw-chat-root-container {
    font-family: 'Arial', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ==========================================================================
   2. ICON FONTS (Dashicons & FontAwesome)
   ========================================================================== */
#lcfw-chat-root-container .dashicons {
    font-family: "dashicons", sans-serif !important;
    font-weight: normal !important;
    font-style: normal !important;
    text-rendering: auto;
    display: inline-block;
}

#lcfw-chat-root-container .fa-solid {
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
    font-style: normal !important;
    color: var(--lcfw-bubble-color);
    text-rendering: auto;
    display: var(--fa-display, inline-block);
}

#lcfw-chat-root-container .fa-brands {
    font-family: "Font Awesome 6 Brands" !important;
    font-weight: 400 !important;
    font-style: normal !important;
    text-rendering: auto;
    display: var(--fa-display, inline-block);
}

#lcfw-chat-root-container .fa {
    font-family: "Font Awesome 6 Free" !important;
    font-weight: normal !important;
    font-style: normal !important;
    text-rendering: auto;
    display: var(--fa-display, inline-block);
}

/* ==========================================================================
   3. CHAT BUBBLE
   ========================================================================== */
#lcfw-chat-root-container #lcfw-chat-bubble {
    position: fixed;
    background-color: var(--lcfw-bubble-color);
    color: #fff;
    border-radius: 50%;
    width: var(--lcfw-bubble-size);
    height: var(--lcfw-bubble-size);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, background-color 0.3s ease;
    pointer-events: auto !important;
}

#lcfw-chat-root-container #lcfw-chat-bubble:hover {
    transform: scale(1.05);
}

#lcfw-chat-root-container #lcfw-chat-bubble span.dashicons {
    font-size: calc(var(--lcfw-bubble-size) * 0.6);
    line-height: 1;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#lcfw-chat-root-container #lcfw-chat-bubble img {
    max-width: 60%;
    max-height: 60%;
    border-radius: 50%;
    object-fit: contain;
}

/* Bubble Positions */
#lcfw-chat-root-container .lcfw-bubble-bottom_right { bottom: 20px; right: 20px; }
#lcfw-chat-root-container .lcfw-bubble-bottom_left { bottom: 20px; left: 20px; }
#lcfw-chat-root-container .lcfw-bubble-middle_right { top: 50%; right: 20px; transform: translateY(-50%); }
#lcfw-chat-root-container .lcfw-bubble-middle_left { top: 50%; left: 20px; right: auto; transform: translateY(-50%); }

/* ==========================================================================
   4. CHAT WIDGET (Main Structure)
   ========================================================================== */
#lcfw-chat-root-container #lcfw-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    height: 450px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    display: none; /* Hidden by default */
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto !important;
}

/* Widget Positions */
#lcfw-chat-root-container #lcfw-chat-widget.lcfw-position-bottom_left { left: 20px; right: auto; }
#lcfw-chat-root-container #lcfw-chat-widget.lcfw-position-middle_right { top: 50%; transform: translateY(-50%); }
#lcfw-chat-root-container #lcfw-chat-widget.lcfw-position-middle_left { top: 50%; left: 20px; right: auto; transform: translateY(-50%); }

/* Header */
#lcfw-chat-root-container #lcfw-chat-header {
    background-color: var(--lcfw-header-color);
    color: var(--lcfw-header-font-color);
    font-family: var(--lcfw-header-font-family);
    font-size: var(--lcfw-header-font-size);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    flex-shrink: 0;
    height: 65px;
    overflow: hidden;
}

#lcfw-chat-root-container .lcfw-admin-info { display: flex; align-items: center; }
#lcfw-chat-root-container #lcfw-chat-header-photo {
    width: 35px; height: 35px; border-radius: 50%; margin-right: 10px; object-fit: cover;
    border: 2px solid rgba(255,255,255,0.8);
}
#lcfw-chat-root-container #lcfw-chat-header-name { font-weight: bold; }
#lcfw-chat-root-container #lcfw-chat-close-button { font-size: 1.5em; cursor: pointer; }

/* Body */
#lcfw-chat-root-container #lcfw-chat-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: #fdfdfd;
    min-height: 0;
    height: calc(100% - var(--lcfw-header-height) - var(--lcfw-footer-height));
    transition: height 0.2s ease-out;
    position: relative;
}

/* Footer */
#lcfw-chat-root-container #lcfw-chat-footer {
    flex-shrink: 0;
    border-top: 1px solid #eee;
    padding: 15px;
    display: flex;
    background-color: #f7f7f7;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    min-height: 65px;
}

/* ==========================================================================
   5. CHAT MESSAGES
   ========================================================================== */
#lcfw-chat-root-container #lcfw-chat-messages {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

#lcfw-chat-root-container .lcfw-message-wrapper { display: flex; margin-bottom: 10px; }
#lcfw-chat-root-container .lcfw-message-wrapper.admin { justify-content: flex-start; }
#lcfw-chat-root-container .lcfw-message-wrapper.visitor { justify-content: flex-end; }

#lcfw-chat-root-container .lcfw-message-content {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.4;
    position: relative;
    /* Formatting Fixes for Container */
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Apply pre-wrap ONLY to text messages */
#lcfw-chat-root-container .lcfw-message-text {
    white-space: pre-wrap;
}

#lcfw-chat-root-container .lcfw-message-content a {
    word-break: break-all;
    display: inline-block;
}

/* Admin/Visitor Specifics */
#lcfw-chat-root-container .lcfw-message-content.admin {
    background-color: #e6e6e6;
    border-bottom-left-radius: 2px;
}

#lcfw-chat-root-container .lcfw-message-content.visitor {
    background-color: var(--lcfw-bubble-color);
    border-bottom-right-radius: 2px;
}

/* Sender Name */
#lcfw-chat-root-container .lcfw-message-sender-name {
    font-weight: bold;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
}

#lcfw-chat-root-container .lcfw-message-sender-name .dashicons {
    font-size: 1.2em; margin-right: 5px; line-height: 1;
    display: flex; justify-content: center; align-items: center;
    height: 1em; width: 1em; flex-shrink: 0;
}

/* Message Fonts/Colors */
#lcfw-chat-root-container .lcfw-message-content.admin .lcfw-message-sender-name {
    color: var(--lcfw-admin-name-font-color);
    font-family: var(--lcfw-admin-name-font-family);
    font-size: var(--lcfw-admin-name-font-size);
}
#lcfw-chat-root-container .lcfw-message-content.visitor .lcfw-message-sender-name {
    color: var(--lcfw-visitor-name-font-color);
    font-family: var(--lcfw-visitor-name-font-family);
    font-size: var(--lcfw-visitor-name-font-size);
}
#lcfw-chat-root-container .lcfw-message-content.admin .lcfw-message-text {
    color: var(--lcfw-admin-message-font-color);
    font-family: var(--lcfw-admin-message-font-family);
    font-size: var(--lcfw-admin-message-font-size);
}
#lcfw-chat-root-container .lcfw-message-content.visitor .lcfw-message-text {
    color: var(--lcfw-visitor-message-font-color);
    font-family: var(--lcfw-visitor-message-font-family);
    font-size: var(--lcfw-visitor-message-font-size);
}

/* Timestamp */
#lcfw-chat-root-container .lcfw-message-timestamp-public {
    font-size: 0.7em; color: #888; margin-top: 5px; display: block; text-align: right; opacity: 0.7;
}
#lcfw-chat-root-container .lcfw-message-content.visitor .lcfw-message-timestamp-public {
    color: rgba(255,255,255,0.8);
}

/* ==========================================================================
   6. INPUT AREA & MISC
   ========================================================================== */
#lcfw-chat-root-container #lcfw-chat-input-area {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 10px;
}

#lcfw-chat-root-container #lcfw-visitor-message-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
}

#lcfw-chat-root-container #lcfw-visitor-send-button {
    background-color: var(--lcfw-bubble-color);
    color: #fff;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.3s ease;
    flex-shrink: 0;
}

#lcfw-chat-root-container #lcfw-visitor-send-button:hover {
    background-color: color-mix(in srgb, var(--lcfw-bubble-color) 80%, black);
}

#lcfw-chat-root-container .lcfw-full-width-button {
    width: 100%;
    padding: 12px 0;
    text-align: center;
    box-sizing: border-box;
    color: var(--lcfw-bubble-color);
}

/* No results / Loading helpers */
#lcfw-chat-root-container .lcfw-no-products-found,
#lcfw-chat-root-container .lcfw-no-orders-found,
#lcfw-chat-root-container .lcfw-loading-indicator,
#lcfw-chat-root-container .lcfw-error-loading-products,
#lcfw-chat-root-container .lcfw-error-loading-orders {
    text-align: center;
    padding: 10px;
    color: #777;
    font-style: italic;
}

#lcfw-typing-indicator {
    padding: 5px 15px;
    font-size: 12px;
    color: #888;
    font-style: italic;
    background: rgba(255,255,255,0.8);
    border-top: 1px solid #eee;
}
.lcfw-typing-dots span {
    animation: lcfw-blink 1s infinite;
}
.lcfw-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.lcfw-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lcfw-blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}