/* ─── WP RAG Chatbot Widget ───────────────────────────────── */

:root {
    --wprag-primary: #6C63FF;
    --wprag-primary-dark: #5A52E0;
    --wprag-bg: #ffffff;
    --wprag-bg-alt: #f7f7f8;
    --wprag-text: #1a1a2e;
    --wprag-text-muted: #6b7280;
    --wprag-header-text: #ffffff;
    --wprag-user-text: #ffffff;
    --wprag-footer-text: #6b7280;
    --wprag-typing-dot: #9ca3af;
    --wprag-border: #e5e7eb;
    --wprag-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    --wprag-radius: 16px;
}

/* ── Bubble toggle ─────────────────────────────────────────── */

#wprag-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wprag-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(108, 99, 255, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 99999;
}

#wprag-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(108, 99, 255, 0.5);
}

#wprag-bubble.wprag-no-accent,
#wprag-bubble.wprag-no-accent:hover {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

#wprag-bubble svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}

#wprag-bubble.wprag-open svg {
    transform: rotate(90deg);
}

/* Position variants */
#wprag-bubble.wprag-bottom-left {
    right: auto;
    left: 24px;
}

/* ── Chat window ───────────────────────────────────────────── */

#wprag-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--wprag-bg);
    border-radius: var(--wprag-radius);
    box-shadow: var(--wprag-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99998;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#wprag-chat-window.wprag-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#wprag-chat-window.wprag-bottom-left {
    right: auto;
    left: 24px;
}

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

.wprag-header {
    background: var(--wprag-primary);
    color: var(--wprag-header-text);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.wprag-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wprag-header-avatar svg {
    width: 20px;
    height: 20px;
}

.wprag-header-info {
    flex: 1;
    min-width: 0;
}

.wprag-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.wprag-header-subtitle {
    font-size: 12px;
    opacity: 0.8;
    line-height: 1.3;
}

.wprag-header-close {
    background: none;
    border: none;
    color: var(--wprag-header-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.wprag-header-close:hover {
    opacity: 1;
}

/* ── Messages area ─────────────────────────────────────────── */

.wprag-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.wprag-messages::-webkit-scrollbar {
    width: 6px;
}

.wprag-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.wprag-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: wprag-fade-in 0.3s ease;
}

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

.wprag-msg-user {
    align-self: flex-end;
    background: var(--wprag-primary);
    color: var(--wprag-user-text);
    border-bottom-right-radius: 4px;
}

.wprag-msg-assistant {
    align-self: flex-start;
    background: var(--wprag-bg-alt);
    color: var(--wprag-text);
    border-bottom-left-radius: 4px;
}

.wprag-msg-assistant p {
    margin: 0 0 8px 0;
}

.wprag-msg-assistant p:last-child {
    margin-bottom: 0;
}

.wprag-msg-assistant h1,
.wprag-msg-assistant h2,
.wprag-msg-assistant h3 {
    margin: 10px 0 8px;
    line-height: 1.3;
    color: var(--wprag-text);
}

.wprag-msg-assistant h1 { font-size: 18px; }
.wprag-msg-assistant h2 { font-size: 16px; }
.wprag-msg-assistant h3 { font-size: 15px; }

.wprag-msg-assistant ul,
.wprag-msg-assistant ol {
    margin: 8px 0 10px 20px;
    padding: 0;
}

.wprag-msg-assistant li {
    margin: 4px 0;
}

.wprag-msg-assistant blockquote {
    margin: 10px 0;
    padding: 8px 12px;
    border-left: 3px solid var(--wprag-primary);
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
}

.wprag-msg-assistant blockquote p {
    margin: 0;
}

.wprag-msg-assistant hr {
    border: 0;
    border-top: 1px solid var(--wprag-border);
    margin: 12px 0;
}

.wprag-msg-assistant code {
    background: #e5e7eb;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}

.wprag-msg-assistant pre {
    background: #1a1a2e;
    color: #e5e7eb;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}

.wprag-msg-assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.wprag-table-wrap {
    margin: 10px 0;
    overflow-x: auto;
}

.wprag-msg-assistant table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 260px;
}

.wprag-msg-assistant th,
.wprag-msg-assistant td {
    border: 1px solid var(--wprag-border);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}

.wprag-msg-assistant th {
    background: #f3f4f6;
    font-weight: 600;
}

/* Sources */
.wprag-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--wprag-border);
    font-size: 12px;
    color: var(--wprag-text-muted);
}

.wprag-sources a {
    color: var(--wprag-primary);
    text-decoration: none;
}

.wprag-sources a:hover {
    text-decoration: underline;
}

.wprag-sources ul {
    margin: 6px 0 0 18px;
    padding: 0;
}

.wprag-sources li {
    margin: 0 0 6px;
}

/* Typing indicator */
.wprag-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--wprag-bg-alt);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.wprag-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--wprag-typing-dot);
    border-radius: 50%;
    animation: wprag-bounce 1.4s ease-in-out infinite;
}

.wprag-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.wprag-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* ── Input area ────────────────────────────────────────────── */

.wprag-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--wprag-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.wprag-input-area textarea {
    flex: 1;
    border: 1px solid var(--wprag-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 40px;
    transition: border-color 0.2s;
    background: var(--wprag-bg);
    color: var(--wprag-text);
}

.wprag-input-area textarea:focus {
    border-color: var(--wprag-primary);
}

.wprag-input-area textarea::placeholder {
    color: var(--wprag-text-muted);
}

.wprag-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--wprag-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

.wprag-send-btn:hover {
    background: var(--wprag-primary-dark);
}

.wprag-send-btn:active {
    transform: scale(0.95);
}

.wprag-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wprag-send-btn svg {
    width: 18px;
    height: 18px;
}

/* ── Powered-by footer ─────────────────────────────────────── */

.wprag-powered {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--wprag-footer-text);
    background: var(--wprag-bg-alt);
    flex-shrink: 0;
}

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

@media (max-width: 480px) {
    #wprag-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 100px);
        bottom: 90px;
        right: 8px;
        border-radius: 12px;
    }

    #wprag-chat-window.wprag-bottom-left {
        left: 8px;
    }

    #wprag-bubble {
        width: 52px;
        height: 52px;
        bottom: 20px;
        right: 16px;
    }

    #wprag-bubble.wprag-bottom-left {
        right: auto;
        left: 16px;
    }
}
