/*
 * ABV AI Chatbot – Frontend Styles
 *
 * Covers:
 *   – Inline shortcode chat widget  (.abv-chatbot-wrap)
 *   – Floating bottom-right widget  (.abv-chatbot-widget)
 *   – Shared message bubble styles
 *
 * No inline styles in HTML templates – all presentation lives here.
 *
 * @package ABV_Chatbot
 */

/* ============================================================
   CSS Custom Properties
   ============================================================ */

:root {
    --abv-primary:        #2271b1;
    --abv-primary-dark:   #135e96;
    --abv-primary-light:  #e8f0fa;
    --abv-bg:             #ffffff;
    --abv-surface:        #f6f7f7;
    --abv-border:         #dcdcde;
    --abv-text:           #1d2327;
    --abv-text-muted:     #646970;
    --abv-user-bg:        #2271b1;
    --abv-user-text:      #ffffff;
    --abv-bot-bg:         #f0f0f1;
    --abv-bot-text:       #1d2327;
    --abv-radius:         12px;
    --abv-radius-sm:      6px;
    --abv-shadow:         0 4px 24px rgba(0, 0, 0, 0.12);
    --abv-shadow-sm:      0 2px 8px rgba(0, 0, 0, 0.08);
    --abv-widget-size:    56px;
    --abv-chat-height:    480px;
    --abv-chat-width:     380px;
    --abv-z-index:        9999;
    --abv-transition:     0.25s ease;
}

/* ============================================================
   Shared: Chat window chrome
   ============================================================ */

.abv-chatbot-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--abv-primary);
    color: #fff;
    border-radius: var(--abv-radius) var(--abv-radius) 0 0;
    user-select: none;
}

.abv-chatbot-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    flex-shrink: 0;
}

.abv-chatbot-header-icon svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

.abv-chatbot-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    flex: 1;
}

.abv-chatbot-header-subtitle {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 1px;
}

/* Close/collapse button (widget only) */
.abv-chatbot-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--abv-radius-sm);
    transition: color var(--abv-transition), background var(--abv-transition);
    flex-shrink: 0;
}

.abv-chatbot-close-btn:hover,
.abv-chatbot-close-btn:focus {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    outline: 2px solid rgba(255, 255, 255, 0.4);
    outline-offset: 2px;
}

.abv-chatbot-close-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ============================================================
   Shared: Message area
   ============================================================ */

.abv-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--abv-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* Scrollbar (webkit) */
.abv-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.abv-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.abv-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--abv-border);
    border-radius: 3px;
}

/* ── Message rows ── */

.abv-chatbot-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.abv-chatbot-message.abv-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.abv-chatbot-message.abv-msg-bot {
    align-self: flex-start;
    align-items: flex-start;
}

/* ── Bubbles ── */

.abv-chatbot-bubble {
    padding: 10px 14px;
    border-radius: var(--abv-radius);
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.abv-msg-user .abv-chatbot-bubble {
    background: var(--abv-user-bg);
    color: var(--abv-user-text);
    border-bottom-right-radius: 3px;
}

.abv-msg-bot .abv-chatbot-bubble {
    background: var(--abv-bot-bg);
    color: var(--abv-bot-text);
    border-bottom-left-radius: 3px;
}

/* ── Sources list ── */

.abv-chatbot-sources {
    margin-top: 6px;
    padding: 8px 12px;
    background: var(--abv-primary-light);
    border-left: 3px solid var(--abv-primary);
    border-radius: 0 var(--abv-radius-sm) var(--abv-radius-sm) 0;
    font-size: 12px;
    color: var(--abv-text-muted);
}

.abv-chatbot-sources strong {
    display: block;
    margin-bottom: 4px;
    color: var(--abv-text);
}

.abv-chatbot-sources ul {
    margin: 0;
    padding: 0 0 0 16px;
    list-style: disc;
}

.abv-chatbot-sources ul li {
    margin-bottom: 2px;
}

.abv-chatbot-sources a {
    color: var(--abv-primary);
    text-decoration: none;
    word-break: break-all;
}

.abv-chatbot-sources a:hover,
.abv-chatbot-sources a:focus {
    text-decoration: underline;
}

/* ── Thinking / loading indicator ── */

.abv-chatbot-thinking .abv-chatbot-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
}

.abv-thinking-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--abv-text-muted);
    animation: abvDotPulse 1.4s infinite ease-in-out both;
    flex-shrink: 0;
}

.abv-thinking-dot:nth-child(1) { animation-delay: 0s; }
.abv-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.abv-thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes abvDotPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1;   }
}

/* ── Timestamp ── */

.abv-chatbot-time {
    font-size: 10px;
    color: var(--abv-text-muted);
    margin-top: 3px;
    padding: 0 4px;
}

/* ============================================================
   Shared: Input area
   ============================================================ */

.abv-chatbot-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--abv-border);
    background: var(--abv-bg);
    border-radius: 0 0 var(--abv-radius) var(--abv-radius);
}

.abv-chatbot-input {
    flex: 1;
    border: 1px solid var(--abv-border);
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--abv-text);
    background: var(--abv-surface);
    resize: none;
    outline: none;
    transition: border-color var(--abv-transition), box-shadow var(--abv-transition);
    max-height: 100px;
    overflow-y: auto;
    font-family: inherit;
}

.abv-chatbot-input:focus {
    border-color: var(--abv-primary);
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.15);
}

.abv-chatbot-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.abv-chatbot-send-btn {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--abv-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--abv-transition), transform var(--abv-transition);
}

.abv-chatbot-send-btn:hover:not(:disabled) {
    background: var(--abv-primary-dark);
    transform: scale(1.05);
}

.abv-chatbot-send-btn:focus {
    outline: 2px solid var(--abv-primary);
    outline-offset: 3px;
}

.abv-chatbot-send-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.abv-chatbot-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ============================================================
   Shortcode widget  (.abv-chatbot-wrap)
   ============================================================ */

.abv-chatbot-wrap {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--abv-border);
    border-radius: var(--abv-radius);
    overflow: hidden;
    box-shadow: var(--abv-shadow-sm);
    max-width: 680px;
    width: 100%;
    margin: 0 auto 24px;
    background: var(--abv-bg);
}

.abv-chatbot-wrap .abv-chatbot-messages {
    height: 360px;
}

/* ============================================================
   Floating widget  (.abv-chatbot-widget)
   ============================================================ */

.abv-chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--abv-z-index);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

/* ── Chat window panel ── */

.abv-chatbot-panel {
    display: flex;
    flex-direction: column;
    width: var(--abv-chat-width);
    max-height: var(--abv-chat-height);
    background: var(--abv-bg);
    border-radius: var(--abv-radius);
    box-shadow: var(--abv-shadow);
    overflow: hidden;
    /* Collapsed state */
    transform: translateY(16px) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition:
        transform var(--abv-transition),
        opacity var(--abv-transition);
}

.abv-chatbot-panel.abv-panel-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

.abv-chatbot-panel .abv-chatbot-messages {
    height: var(--abv-chat-height);
    max-height: calc(var(--abv-chat-height) - 120px);
}

/* ── Trigger button ── */

.abv-chatbot-trigger {
    width: var(--abv-widget-size);
    height: var(--abv-widget-size);
    border-radius: 50%;
    background: var(--abv-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--abv-shadow);
    transition:
        background var(--abv-transition),
        transform var(--abv-transition),
        box-shadow var(--abv-transition);
    position: relative;
    flex-shrink: 0;
}

.abv-chatbot-trigger:hover {
    background: var(--abv-primary-dark);
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.18);
}

.abv-chatbot-trigger:focus {
    outline: 3px solid var(--abv-primary);
    outline-offset: 3px;
}

.abv-chatbot-trigger svg {
    width: 26px;
    height: 26px;
    fill: #fff;
    transition: opacity var(--abv-transition), transform var(--abv-transition);
    position: absolute;
}

/* Icon swap: chat icon visible by default, close icon hidden */
.abv-trigger-icon-chat  { opacity: 1;  transform: scale(1)   rotate(0deg); }
.abv-trigger-icon-close { opacity: 0;  transform: scale(0.5) rotate(-90deg); }

/* When panel is open, swap icons */
.abv-chatbot-widget.abv-widget-open .abv-trigger-icon-chat  { opacity: 0;  transform: scale(0.5) rotate(90deg); }
.abv-chatbot-widget.abv-widget-open .abv-trigger-icon-close { opacity: 1;  transform: scale(1)   rotate(0deg); }

/* Unread badge */
.abv-chatbot-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #d63638;
    border: 2px solid #fff;
    display: none;
}

.abv-chatbot-badge.abv-badge-visible {
    display: block;
}

/* ============================================================
   Error / empty state
   ============================================================ */

.abv-chatbot-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 10px;
    padding: 32px 16px;
    color: var(--abv-text-muted);
    text-align: center;
}

.abv-chatbot-empty svg {
    width: 40px;
    height: 40px;
    fill: var(--abv-border);
}

.abv-chatbot-error-msg {
    font-size: 13px;
    color: #d63638;
    background: #fceded;
    border: 1px solid #f5c6cb;
    border-radius: var(--abv-radius-sm);
    padding: 8px 12px;
    margin: 0 16px 12px;
    text-align: center;
}

/* ============================================================
   Responsive
   ============================================================ */

@media screen and (max-width: 480px) {
    :root {
        --abv-chat-width:  calc(100vw - 32px);
        --abv-chat-height: 420px;
    }

    .abv-chatbot-widget {
        bottom: 16px;
        right: 16px;
    }

    .abv-chatbot-panel {
        width: var(--abv-chat-width);
    }

    .abv-chatbot-wrap {
        max-width: 100%;
    }
}

/* ============================================================
   Accessibility: reduced-motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .abv-chatbot-panel,
    .abv-chatbot-trigger,
    .abv-chatbot-send-btn,
    .abv-thinking-dot {
        transition: none;
        animation: none;
    }

    .abv-thinking-dot {
        opacity: 0.6;
        transform: none;
    }
}
