/**
 * Local Hero Chatbot — Frontend Styles
 *
 * All selectors are scoped under #lh-chatbot-widget or .lh-chatbot-embed
 * to prevent inheritance from the active theme (Astra, Divi, etc.).
 */

/* ── CSS Custom Properties ────────────────────────────────────────────────── */

:root {
    --lh-primary:   #2563eb;
    --lh-text:      #ffffff;
    --lh-bg:        #ffffff;
    --lh-user-msg:  #eff6ff;
    --lh-bot-msg:   #f9fafb;
    --lh-font-size: 14px;
    --lh-font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --lh-width:     380px;
    --lh-height:    520px;
    --lh-radius:    16px;
    --lh-shadow:    0 8px 32px rgba(0, 0, 0, 0.18);
    --lh-border:    #e5e7eb;
    --lh-bubble-sz: 56px;
}

/* ── Full isolation reset for everything inside the plugin ────────────────── */

#lh-chatbot-widget *,
#lh-chatbot-widget *::before,
#lh-chatbot-widget *::after,
.lh-chatbot-embed *,
.lh-chatbot-embed *::before,
.lh-chatbot-embed *::after {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

/* Buttons — Astra overrides padding, border, background, line-height */
#lh-chatbot-widget button,
.lh-chatbot-embed button {
    box-sizing:      border-box;
    background:      transparent;
    border:          none;
    border-radius:   0;
    padding:         0;
    margin:          0;
    font-family:     inherit;
    font-size:       inherit;
    font-weight:     inherit;
    line-height:     normal;
    color:           inherit;
    cursor:          pointer;
    outline:         none;
    text-align:      left;
    -webkit-appearance: none;
    appearance:      none;
    text-transform:  none;
    letter-spacing:  normal;
    box-shadow:      none;
}

/* Textarea — Astra overrides border, background, padding, box-shadow */
#lh-chatbot-widget textarea,
.lh-chatbot-embed textarea {
    box-sizing:      border-box;
    background:      transparent;
    border:          none;
    border-radius:   0;
    padding:         0;
    margin:          0;
    font-family:     inherit;
    font-size:       inherit;
    line-height:     normal;
    color:           inherit;
    outline:         none;
    resize:          none;
    box-shadow:      none;
    -webkit-appearance: none;
    appearance:      none;
    width:           100%;
}

/* Links — Astra overrides color, text-decoration, font-weight */
#lh-chatbot-widget a,
.lh-chatbot-embed a {
    color:           inherit;
    text-decoration: none;
    font-weight:     inherit;
    background:      transparent;
}

/* Paragraphs — Astra adds margin-bottom */
#lh-chatbot-widget p,
.lh-chatbot-embed p {
    margin:      0;
    padding:     0;
    font-size:   inherit;
    line-height: inherit;
    color:       inherit;
}

/* SVG — themes sometimes add display:inline or unwanted dimensions */
#lh-chatbot-widget svg,
.lh-chatbot-embed svg {
    display:        block;
    pointer-events: none;
    overflow:       visible;
    max-width:      none;
    height:         auto;
}

/* Images — themes add border, max-width, vertical-align */
#lh-chatbot-widget img,
.lh-chatbot-embed img {
    display:        block;
    max-width:      100%;
    height:         auto;
    border:         none;
    border-radius:  0;
    box-shadow:     none;
    vertical-align: top;
}

/* Spans — themes sometimes add display:block or line-height */
#lh-chatbot-widget span,
.lh-chatbot-embed span {
    font-size:   inherit;
    line-height: inherit;
    color:       inherit;
}

/* Lists */
#lh-chatbot-widget ul,
#lh-chatbot-widget ol,
.lh-chatbot-embed ul,
.lh-chatbot-embed ol {
    list-style: none;
    margin:     0;
    padding:    0;
}

/* ── Widget Container ─────────────────────────────────────────────────────── */

#lh-chatbot-widget {
    position:       fixed;
    z-index:        999999;
    display:        flex;
    flex-direction: column;
    align-items:    flex-end;
    font-family:    var(--lh-font);
    font-size:      var(--lh-font-size);
    line-height:    1.5;
}

#lh-chatbot-widget.lh-position-bottom-right {
    bottom: 24px;
    right:  24px;
}

#lh-chatbot-widget.lh-position-bottom-left {
    bottom:      24px;
    left:        24px;
    align-items: flex-start;
}

/* ── Floating Bubble ──────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-chatbot-bubble {
    width:           var(--lh-bubble-sz);
    height:          var(--lh-bubble-sz);
    border-radius:   50%;
    background:      var(--lh-primary);
    color:           var(--lh-text);
    display:         flex;
    align-items:     center;
    justify-content: center;
    box-shadow:      0 4px 16px rgba(0, 0, 0, 0.24);
    transition:      transform 0.2s ease, box-shadow 0.2s ease;
    position:        relative;
    flex-shrink:     0;
}

#lh-chatbot-widget .lh-chatbot-bubble:hover,
#lh-chatbot-widget .lh-chatbot-bubble:focus-visible {
    transform:  scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}

#lh-chatbot-widget .lh-chatbot-bubble:focus-visible {
    outline:        3px solid var(--lh-primary);
    outline-offset: 3px;
}

#lh-chatbot-widget .lh-bubble-icon,
#lh-chatbot-widget .lh-close-icon {
    width:      26px;
    height:     26px;
    position:   absolute;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#lh-chatbot-widget .lh-close-icon {
    opacity:   0;
    transform: rotate(-90deg) scale(0.7);
}

#lh-chatbot-widget .lh-chatbot-bubble.lh-bubble-open .lh-bubble-icon {
    opacity:   0;
    transform: rotate(90deg) scale(0.7);
}

#lh-chatbot-widget .lh-chatbot-bubble.lh-bubble-open .lh-close-icon {
    opacity:   1;
    transform: rotate(0deg) scale(1);
}

#lh-chatbot-widget .lh-bubble-avatar {
    width:         100%;
    height:        100%;
    border-radius: 50%;
    object-fit:    cover;
    position:      absolute;
    transition:    opacity 0.2s ease, transform 0.2s ease;
}

#lh-chatbot-widget .lh-chatbot-bubble.lh-bubble-open .lh-bubble-avatar {
    opacity:   0;
    transform: rotate(90deg) scale(0.7);
}

/* ── Chat Window ──────────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-chatbot-window {
    width:          var(--lh-width);
    max-width:      calc(100vw - 32px);
    background:     var(--lh-bg);
    border-radius:  var(--lh-radius);
    box-shadow:     var(--lh-shadow);
    display:        flex;
    flex-direction: column;
    overflow:       hidden;
    font-family:    var(--lh-font);
    font-size:      var(--lh-font-size);
    line-height:    1.5;
    margin-bottom:  12px;
    opacity:        0;
    transform:      translateY(16px) scale(0.97);
    pointer-events: none;
    transition:     opacity 0.25s ease, transform 0.25s ease;
    will-change:    transform, opacity;
    color:          #111827;
}

#lh-chatbot-widget .lh-chatbot-window.lh-open {
    opacity:        1;
    transform:      translateY(0) scale(1);
    pointer-events: all;
}

/* ── Shortcode Embed ──────────────────────────────────────────────────────── */

.lh-chatbot-embed {
    width:          var(--lh-width);
    max-width:      100%;
    background:     var(--lh-bg);
    border-radius:  var(--lh-radius);
    box-shadow:     var(--lh-shadow);
    display:        flex;
    flex-direction: column;
    overflow:       hidden;
    font-family:    var(--lh-font);
    font-size:      var(--lh-font-size);
    line-height:    1.5;
    border:         1px solid var(--lh-border);
    color:          #111827;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-chatbot-header,
.lh-chatbot-embed .lh-chatbot-header {
    background:   var(--lh-primary);
    color:        var(--lh-text);
    padding:      14px 16px;
    display:      flex;
    align-items:  center;
    gap:          10px;
    flex-shrink:  0;
    border:       none;
    border-radius: 0;
}

#lh-chatbot-widget .lh-header-avatar,
.lh-chatbot-embed .lh-header-avatar {
    width:         36px;
    height:        36px;
    border-radius: 50%;
    object-fit:    cover;
    flex-shrink:   0;
    border:        2px solid rgba(255, 255, 255, 0.4);
}

#lh-chatbot-widget .lh-header-title,
.lh-chatbot-embed .lh-header-title {
    flex:          1;
    font-weight:   600;
    font-size:     calc(var(--lh-font-size) + 1px);
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
    color:         var(--lh-text);
    line-height:   1.3;
}

#lh-chatbot-widget .lh-chatbot-close-btn {
    background:      transparent;
    border:          none;
    color:           var(--lh-text);
    padding:         4px;
    border-radius:   4px;
    display:         flex;
    align-items:     center;
    justify-content: center;
    opacity:         0.8;
    transition:      opacity 0.15s;
    flex-shrink:     0;
}

#lh-chatbot-widget .lh-chatbot-close-btn:hover,
#lh-chatbot-widget .lh-chatbot-close-btn:focus-visible {
    opacity: 1;
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

#lh-chatbot-widget .lh-chatbot-close-btn svg,
.lh-chatbot-embed .lh-chatbot-close-btn svg {
    width:  20px;
    height: 20px;
}

/* ── Messages Container ───────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-chatbot-messages,
.lh-chatbot-embed .lh-chatbot-messages {
    flex:            1;
    overflow-y:      auto;
    padding:         16px 14px;
    display:         flex;
    flex-direction:  column;
    gap:             10px;
    height:          calc(var(--lh-height) - 130px);
    min-height:      120px;
    scroll-behavior: smooth;
    background:      var(--lh-bg);
}

#lh-chatbot-widget .lh-chatbot-messages::-webkit-scrollbar,
.lh-chatbot-embed .lh-chatbot-messages::-webkit-scrollbar {
    width: 5px;
}
#lh-chatbot-widget .lh-chatbot-messages::-webkit-scrollbar-track,
.lh-chatbot-embed .lh-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}
#lh-chatbot-widget .lh-chatbot-messages::-webkit-scrollbar-thumb,
.lh-chatbot-embed .lh-chatbot-messages::-webkit-scrollbar-thumb {
    background:    #d1d5db;
    border-radius: 3px;
}
#lh-chatbot-widget .lh-chatbot-messages::-webkit-scrollbar-thumb:hover,
.lh-chatbot-embed .lh-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ── Message Bubbles ──────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-message,
.lh-chatbot-embed .lh-message {
    display:   flex;
    max-width: 85%;
    animation: lh-fade-in 0.2s ease forwards;
}

@keyframes lh-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

#lh-chatbot-widget .lh-bot-message,
.lh-chatbot-embed .lh-bot-message {
    align-self: flex-start;
}

#lh-chatbot-widget .lh-user-message,
.lh-chatbot-embed .lh-user-message {
    align-self:     flex-end;
    flex-direction: row-reverse;
}

#lh-chatbot-widget .lh-message-bubble,
.lh-chatbot-embed .lh-message-bubble {
    padding:       10px 14px;
    border-radius: 14px;
    line-height:   1.55;
    word-break:    break-word;
    overflow-wrap: anywhere;
    font-size:     var(--lh-font-size);
    font-family:   var(--lh-font);
}

#lh-chatbot-widget .lh-bot-message .lh-message-bubble,
.lh-chatbot-embed .lh-bot-message .lh-message-bubble {
    background:                var(--lh-bot-msg);
    color:                     #111827;
    border-bottom-left-radius: 4px;
    border:                    1px solid var(--lh-border);
}

#lh-chatbot-widget .lh-user-message .lh-message-bubble,
.lh-chatbot-embed .lh-user-message .lh-message-bubble {
    background:                 var(--lh-user-msg);
    color:                      #1e40af;
    border-bottom-right-radius: 4px;
    border:                     none;
}

/* Scoped element resets inside message bubbles */
#lh-chatbot-widget .lh-message-bubble p,
.lh-chatbot-embed .lh-message-bubble p {
    margin:      0 0 8px;
    font-size:   inherit;
    line-height: inherit;
    color:       inherit;
}

#lh-chatbot-widget .lh-message-bubble p:last-child,
.lh-chatbot-embed .lh-message-bubble p:last-child {
    margin-bottom: 0;
}

#lh-chatbot-widget .lh-message-bubble a,
.lh-chatbot-embed .lh-message-bubble a {
    color:           var(--lh-primary);
    text-decoration: underline;
    font-weight:     inherit;
}

/* ── CTA Block ────────────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-cta-block,
.lh-chatbot-embed .lh-cta-block {
    margin-top:     10px;
    display:        flex;
    flex-direction: column;
    gap:            8px;
}

#lh-chatbot-widget .lh-cta-button,
.lh-chatbot-embed .lh-cta-button {
    display:         inline-block;
    padding:         8px 18px;
    background:      var(--lh-primary);
    color:           var(--lh-text) !important;
    border-radius:   8px;
    text-decoration: none !important;
    font-weight:     600;
    font-size:       calc(var(--lh-font-size) - 1px);
    transition:      opacity 0.15s;
    text-align:      center;
    line-height:     1.4;
    border:          none;
    box-shadow:      none;
}

#lh-chatbot-widget .lh-cta-button:hover,
#lh-chatbot-widget .lh-cta-button:focus-visible,
.lh-chatbot-embed .lh-cta-button:hover,
.lh-chatbot-embed .lh-cta-button:focus-visible {
    opacity:        0.88;
    outline:        2px solid var(--lh-primary);
    outline-offset: 2px;
}

#lh-chatbot-widget .lh-fallback-text,
.lh-chatbot-embed .lh-fallback-text {
    margin: 0;
}

/* ── Typing Indicator ─────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-typing-indicator,
.lh-chatbot-embed .lh-typing-indicator {
    display:     flex;
    align-items: center;
    gap:         5px;
    padding:     10px 16px;
    min-width:   52px;
}

#lh-chatbot-widget .lh-typing-indicator span,
.lh-chatbot-embed .lh-typing-indicator span {
    display:       block;
    width:         8px;
    height:        8px;
    background:    #9ca3af;
    border-radius: 50%;
    animation:     lh-bounce 1.2s infinite ease-in-out;
    flex-shrink:   0;
}

#lh-chatbot-widget .lh-typing-indicator span:nth-child(1),
.lh-chatbot-embed .lh-typing-indicator span:nth-child(1) { animation-delay: 0s; }
#lh-chatbot-widget .lh-typing-indicator span:nth-child(2),
.lh-chatbot-embed .lh-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
#lh-chatbot-widget .lh-typing-indicator span:nth-child(3),
.lh-chatbot-embed .lh-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lh-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* ── Input Area ───────────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-chatbot-input-area,
.lh-chatbot-embed .lh-chatbot-input-area {
    display:      flex;
    align-items:  flex-end;
    padding:      10px 12px;
    border-top:   1px solid var(--lh-border);
    border-left:  none;
    border-right: none;
    border-bottom: none;
    background:   var(--lh-bg);
    gap:          8px;
    flex-shrink:  0;
    flex-wrap:    wrap;
}

#lh-chatbot-widget .lh-chatbot-input,
.lh-chatbot-embed .lh-chatbot-input {
    flex:          1;
    border:        1px solid var(--lh-border);
    border-radius: 10px;
    padding:       9px 13px;
    font-size:     var(--lh-font-size);
    font-family:   var(--lh-font);
    line-height:   1.4;
    resize:        none;
    outline:       none;
    background:    #f9fafb;
    color:         #111827;
    max-height:    120px;
    overflow-y:    auto;
    transition:    border-color 0.15s, box-shadow 0.15s;
    min-height:    0;
    height:        auto;
    width:         auto;
    display:       block;
    box-shadow:    none;
    -webkit-appearance: none;
    appearance:    none;
}

#lh-chatbot-widget .lh-chatbot-input:focus,
.lh-chatbot-embed .lh-chatbot-input:focus {
    border-color: var(--lh-primary);
    box-shadow:   0 0 0 3px rgba(37, 99, 235, 0.12);
    background:   #ffffff;
    outline:      none;
}

#lh-chatbot-widget .lh-chatbot-input:disabled,
.lh-chatbot-embed .lh-chatbot-input:disabled {
    opacity: 0.6;
    cursor:  not-allowed;
}

#lh-chatbot-widget .lh-chatbot-input::placeholder,
.lh-chatbot-embed .lh-chatbot-input::placeholder {
    color: #9ca3af;
}

#lh-chatbot-widget .lh-chatbot-send-btn,
.lh-chatbot-embed .lh-chatbot-send-btn {
    width:           38px;
    height:          38px;
    border-radius:   10px;
    background:      var(--lh-primary);
    color:           var(--lh-text);
    border:          none;
    display:         flex;
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
    transition:      opacity 0.15s, transform 0.15s;
    outline:         none;
    box-shadow:      none;
    padding:         0;
    margin:          0;
    line-height:     1;
}

#lh-chatbot-widget .lh-chatbot-send-btn:hover,
#lh-chatbot-widget .lh-chatbot-send-btn:focus-visible,
.lh-chatbot-embed .lh-chatbot-send-btn:hover,
.lh-chatbot-embed .lh-chatbot-send-btn:focus-visible {
    opacity:   0.88;
    transform: scale(1.05);
}

#lh-chatbot-widget .lh-chatbot-send-btn:focus-visible,
.lh-chatbot-embed .lh-chatbot-send-btn:focus-visible {
    outline:        3px solid var(--lh-primary);
    outline-offset: 2px;
}

#lh-chatbot-widget .lh-chatbot-send-btn:disabled,
.lh-chatbot-embed .lh-chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor:  not-allowed;
}

#lh-chatbot-widget .lh-chatbot-send-btn svg,
.lh-chatbot-embed .lh-chatbot-send-btn svg {
    width:  18px;
    height: 18px;
}

/* ── CAPTCHA ──────────────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-captcha-wrap,
.lh-chatbot-embed .lh-captcha-wrap {
    width:      100%;
    padding:    8px 0 4px;
    display:    flex;
    justify-content: center;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */

#lh-chatbot-widget .lh-chatbot-footer,
.lh-chatbot-embed .lh-chatbot-footer {
    padding:      6px 14px 8px;
    text-align:   center;
    flex-shrink:  0;
    background:   var(--lh-bg);
    border:       none;
}

#lh-chatbot-widget .lh-powered-by,
.lh-chatbot-embed .lh-powered-by {
    font-size:      10px;
    color:          #9ca3af;
    letter-spacing: 0.3px;
    line-height:    1.4;
}

/* ── Screen reader utility (scoped name to avoid Astra collision) ─────────── */

.lh-sr-only {
    position:   absolute !important;
    width:      1px;
    height:     1px;
    padding:    0;
    margin:     -1px;
    overflow:   hidden;
    clip:       rect(0, 0, 0, 0);
    white-space: nowrap;
    border:     0;
}

/* ── Dark theme ───────────────────────────────────────────────────────────── */

.lh-theme-dark .lh-chatbot-messages {
    background: #1f2937;
}

.lh-theme-dark .lh-bot-message .lh-message-bubble {
    background:   #374151;
    color:        #f3f4f6;
    border-color: #4b5563;
}

.lh-theme-dark .lh-user-message .lh-message-bubble {
    background: #1d4ed8;
    color:      #ffffff;
}

.lh-theme-dark .lh-chatbot-input-area,
.lh-theme-dark .lh-chatbot-footer {
    background:   #1f2937;
    border-color: #374151;
}

.lh-theme-dark .lh-chatbot-input {
    background:   #374151;
    color:        #f9fafb;
    border-color: #4b5563;
}

.lh-theme-dark .lh-chatbot-input:focus {
    border-color: var(--lh-primary);
    background:   #4b5563;
}

.lh-theme-dark .lh-chatbot-input::placeholder {
    color: #6b7280;
}

.lh-theme-dark .lh-powered-by {
    color: #6b7280;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    #lh-chatbot-widget .lh-chatbot-window {
        width:     calc(100vw - 16px);
        max-width: calc(100vw - 16px);
    }

    #lh-chatbot-widget.lh-position-bottom-right .lh-chatbot-window,
    #lh-chatbot-widget.lh-position-bottom-left .lh-chatbot-window {
        position: fixed;
        left:     8px;
        right:    8px;
        bottom:   80px;
        width:    auto;
    }

    #lh-chatbot-widget.lh-position-bottom-right {
        right: 16px;
    }

    #lh-chatbot-widget.lh-position-bottom-left {
        left: 16px;
    }

    #lh-chatbot-widget .lh-chatbot-messages,
    .lh-chatbot-embed .lh-chatbot-messages {
        height:     calc(80vh - 130px);
        min-height: 200px;
    }

    .lh-chatbot-embed {
        width: 100%;
    }

    #lh-chatbot-widget .lh-message,
    .lh-chatbot-embed .lh-message {
        max-width: 92%;
    }
}

@media (max-width: 360px) {
    #lh-chatbot-widget .lh-chatbot-bubble {
        width:  48px;
        height: 48px;
    }

    #lh-chatbot-widget .lh-chatbot-messages,
    .lh-chatbot-embed .lh-chatbot-messages {
        padding: 12px 10px;
    }
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    #lh-chatbot-widget .lh-chatbot-window,
    #lh-chatbot-widget .lh-chatbot-bubble,
    #lh-chatbot-widget .lh-message,
    #lh-chatbot-widget .lh-typing-indicator span,
    .lh-chatbot-embed .lh-message,
    .lh-chatbot-embed .lh-typing-indicator span {
        animation:  none;
        transition: none;
    }

    #lh-chatbot-widget .lh-chatbot-window {
        opacity:   1;
        transform: none;
    }
}
