/* NeuroRAG Agent Chatbot Widget Styles */
#neurorag-bot-widget {
    position: fixed;
    z-index: 999999;
    --chatbot-primary: #10b981;
    --chatbot-accent: #3b82f6;
    --chatbot-gradient: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-accent) 100%);
    --chatbot-surface: #ffffff;
    --chatbot-surface-muted: #f7f8fa;
    --chatbot-bot-bubble: #ffffff;
    --chatbot-bot-text: #333333;
    --chatbot-border: #e5e7eb;
    --chatbot-input-bg: #ffffff;
    --chatbot-input-text: #111827;
    --chatbot-width: 380px;
    --chatbot-height: 560px;
    --chatbot-radius: 18px;
    --chatbot-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-family: var(--chatbot-font);
}

/* ── Position variants ───────────────────────────────────────────────────── */
.neurorag-bot-pos-bottom-right { bottom: 24px; right: 24px; }
.neurorag-bot-pos-bottom-left  { bottom: 24px; left: 24px; }
.neurorag-bot-pos-top-right    { top: 24px; right: 24px; }
.neurorag-bot-pos-top-left     { top: 24px; left: 24px; }

body.admin-bar .neurorag-bot-pos-top-right,
body.admin-bar .neurorag-bot-pos-top-left { top: 56px; }

@media screen and (min-width: 783px) {
    body.admin-bar .neurorag-bot-pos-top-right,
    body.admin-bar .neurorag-bot-pos-top-left { top: 56px; }
}

/* ── Launcher button ─────────────────────────────────────────────────────── */
#neurorag-bot-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(16, 185, 129, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    animation: launcherPulse 3s ease-in-out infinite;
}

@keyframes launcherPulse {
    0%   { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 0 rgba(16,185,129,0.4); }
    50%  { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 10px rgba(16,185,129,0); }
    100% { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 0 rgba(16,185,129,0); }
}

#neurorag-bot-button:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    animation: none;
}

#neurorag-bot-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
    pointer-events: none;
}

/* ── Chat container ──────────────────────────────────────────────────────── */
#neurorag-bot-container {
    position: absolute;
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    background: var(--chatbot-surface);
    border-radius: var(--chatbot-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: widgetOpen 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes widgetOpen {
    from { opacity: 0; transform: scale(0.9) translateY(16px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.neurorag-bot-pos-bottom-right #neurorag-bot-container { bottom: 80px; right: 0; }
.neurorag-bot-pos-bottom-left  #neurorag-bot-container { bottom: 80px; left: 0; }
.neurorag-bot-pos-top-right    #neurorag-bot-container { top: 80px; right: 0; }
.neurorag-bot-pos-top-left     #neurorag-bot-container { top: 80px; left: 0; }

.neurorag-bot-pos-top-right #neurorag-bot-container,
.neurorag-bot-pos-top-left  #neurorag-bot-container {
    animation: widgetOpenTop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes widgetOpenTop {
    from { opacity: 0; transform: scale(0.9) translateY(-16px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#neurorag-bot-header {
    background: var(--chatbot-gradient);
    color: white;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

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

.neurorag-bot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}

.neurorag-bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.neurorag-bot-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#neurorag-bot-title {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.neurorag-bot-status {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}

.neurorag-bot-status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

#neurorag-bot-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

#neurorag-bot-new {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #ffffff;
    font-size: 12px;
    cursor: pointer;
    line-height: 1;
    padding: 6px 12px;
    border-radius: 999px;
    transition: background 0.2s, border-color 0.2s;
}

#neurorag-bot-new:hover {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.6);
}

#neurorag-bot-close {
    background: none;
    border: none;
    color: white;
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

#neurorag-bot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ── Messages area ───────────────────────────────────────────────────────── */
#neurorag-bot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    background: var(--chatbot-surface-muted);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
#neurorag-bot-messages::-webkit-scrollbar { width: 4px; }
#neurorag-bot-messages::-webkit-scrollbar-track { background: transparent; }
#neurorag-bot-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
#neurorag-bot-messages::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.neurorag-bot-message {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    animation: messageIn 0.25s ease-out;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.neurorag-bot-message.user {
    align-items: flex-end;
}

.neurorag-bot-message-content {
    max-width: 78%;
    padding: 11px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
}

.neurorag-bot-message.bot .neurorag-bot-message-content {
    background: var(--chatbot-bot-bubble);
    color: var(--chatbot-bot-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.neurorag-bot-message.user .neurorag-bot-message-content {
    background: var(--chatbot-gradient);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.neurorag-bot-typing {
    display: flex;
    gap: 5px;
    padding: 13px 16px;
    background: var(--chatbot-bot-bubble);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.neurorag-bot-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    animation: typing 1.4s infinite ease-in-out;
}

.neurorag-bot-typing span:nth-child(2) { animation-delay: 0.2s; }
.neurorag-bot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-8px); opacity: 1; }
}

/* ── Suggestions area ────────────────────────────────────────────────────── */
#neurorag-bot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 16px 4px;
    background: var(--chatbot-surface);
    border-top: 1px solid var(--chatbot-border);
}

#neurorag-bot-suggestions:empty {
    display: none;
}

.neurorag-suggestion-chip {
    background: transparent;
    border: 1.5px solid var(--chatbot-primary);
    color: var(--chatbot-primary);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s;
    line-height: 1.3;
    text-align: left;
    animation: chipSlideUp 0.3s ease-out;
}

@keyframes chipSlideUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.neurorag-suggestion-chip:hover,
.neurorag-suggestion-chip:focus-visible {
    background: var(--chatbot-primary);
    color: #ffffff;
    transform: translateY(-1px);
}

/* ── Input area ──────────────────────────────────────────────────────────── */
#neurorag-bot-input-area {
    display: flex;
    padding: 12px 14px;
    background: var(--chatbot-surface);
    border-top: 1px solid var(--chatbot-border);
    gap: 8px;
    align-items: center;
}

#neurorag-bot-input {
    flex: 1;
    border: 1.5px solid var(--chatbot-border);
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--chatbot-input-bg);
    color: var(--chatbot-input-text);
}

#neurorag-bot-input:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

#neurorag-bot-send {
    background: var(--chatbot-gradient);
    color: white;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    min-width: 42px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.15s;
    padding: 0;
    flex-shrink: 0;
}

#neurorag-bot-send svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: white;
    pointer-events: none;
}

#neurorag-bot-send:hover {
    opacity: 0.9;
    transform: scale(1.06);
}

#neurorag-bot-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

/* ── Source chips ────────────────────────────────────────────────────────── */
.neurorag-source-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--chatbot-border);
}

.neurorag-source-label {
    font-size: 11px;
    color: #6b7280;
    flex-shrink: 0;
}

.neurorag-source-chip {
    display: inline-flex;
    align-items: center;
    background: var(--chatbot-surface-muted);
    border: 1px solid var(--chatbot-border);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11px;
    color: var(--chatbot-accent);
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.neurorag-source-chip:hover,
.neurorag-source-chip:focus-visible {
    background: var(--chatbot-border);
    border-color: var(--chatbot-accent);
    text-decoration: none;
    transform: translateY(-1px);
}

/* ── Feedback row ────────────────────────────────────────────────────────── */
.neurorag-feedback-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.neurorag-feedback-btn {
    background: none;
    border: 1px solid var(--chatbot-border);
    border-radius: 8px;
    padding: 3px 9px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    line-height: 1;
}

.neurorag-feedback-btn:hover:not(:disabled),
.neurorag-feedback-btn:focus-visible:not(:disabled) {
    background: var(--chatbot-surface-muted);
    border-color: var(--chatbot-primary);
    transform: scale(1.15);
}

.neurorag-feedback-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.neurorag-feedback-thanks {
    font-size: 11px;
    color: #6b7280;
    margin-left: 4px;
}

/* ── Dark theme ──────────────────────────────────────────────────────────── */
.neurorag-theme-dark,
#neurorag-bot-widget[data-theme="dark"] {
    --chatbot-surface: #1f2937;
    --chatbot-surface-muted: #111827;
    --chatbot-bot-bubble: #374151;
    --chatbot-bot-text: #f9fafb;
    --chatbot-border: #374151;
    --chatbot-input-bg: #374151;
    --chatbot-input-text: #f9fafb;
}

.neurorag-theme-dark #neurorag-bot-container,
#neurorag-bot-widget[data-theme="dark"] #neurorag-bot-container {
    background: #1f2937;
    color: #f9fafb;
}

.neurorag-theme-dark #neurorag-bot-messages,
#neurorag-bot-widget[data-theme="dark"] #neurorag-bot-messages {
    background: var(--chatbot-surface-muted);
}

.neurorag-theme-dark .neurorag-bot-message.bot .neurorag-bot-message-content,
#neurorag-bot-widget[data-theme="dark"] .neurorag-bot-message.bot .neurorag-bot-message-content {
    background: var(--chatbot-bot-bubble);
    color: var(--chatbot-bot-text);
}

.neurorag-theme-dark .neurorag-bot-typing,
#neurorag-bot-widget[data-theme="dark"] .neurorag-bot-typing {
    background: var(--chatbot-bot-bubble);
}

.neurorag-theme-dark #neurorag-bot-input-area,
#neurorag-bot-widget[data-theme="dark"] #neurorag-bot-input-area {
    background: var(--chatbot-surface);
    border-top-color: var(--chatbot-border);
}

.neurorag-theme-dark #neurorag-bot-input,
#neurorag-bot-widget[data-theme="dark"] #neurorag-bot-input {
    background: var(--chatbot-input-bg);
    border-color: var(--chatbot-border);
    color: var(--chatbot-input-text);
}

.neurorag-theme-dark #neurorag-bot-suggestions,
#neurorag-bot-widget[data-theme="dark"] #neurorag-bot-suggestions {
    background: var(--chatbot-surface);
    border-top-color: var(--chatbot-border);
}

.neurorag-theme-dark .neurorag-feedback-btn,
#neurorag-bot-widget[data-theme="dark"] .neurorag-feedback-btn {
    border-color: var(--chatbot-border);
    color: var(--chatbot-bot-text);
}

.neurorag-theme-dark .neurorag-source-chip,
#neurorag-bot-widget[data-theme="dark"] .neurorag-source-chip {
    background: var(--chatbot-surface);
    border-color: var(--chatbot-border);
}

/* ── Screen-reader only utility ──────────────────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Focus visible (WCAG 2.1 AA) ────────────────────────────────────────── */
#neurorag-bot-widget :focus-visible {
    outline: 3px solid var(--chatbot-accent);
    outline-offset: 2px;
}

/* ── Reduced motion (WCAG 2.1) ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #neurorag-bot-container,
    #neurorag-bot-button,
    .neurorag-bot-message,
    .neurorag-suggestion-chip,
    .neurorag-source-chip,
    .neurorag-feedback-btn,
    #neurorag-bot-send {
        animation: none !important;
        transition: none !important;
    }
    .neurorag-bot-typing span { animation: none !important; opacity: 1 !important; }
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #neurorag-bot-widget { bottom: 16px !important; right: 16px !important; left: auto !important; top: auto !important; }
    .neurorag-bot-pos-bottom-left { bottom: 16px !important; left: 16px !important; right: auto !important; }

    #neurorag-bot-container {
        width: calc(100vw - 32px);
        height: calc(100dvh - 90px);
        border-radius: 16px;
    }

    .neurorag-bot-pos-bottom-right #neurorag-bot-container,
    .neurorag-bot-pos-bottom-left  #neurorag-bot-container { bottom: 74px; }
}
