/* Chat Widget Styles */
.rag-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: var(--ragbot-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    font-size: var(--ragbot-base-font-size);
    --ragbot-scale: 1;
    --ragbot-base-font-size: 14px;
    --ragbot-primary: #007cba;
    --ragbot-primary-contrast: #ffffff;
    --ragbot-text: #1f2d3d;
    --ragbot-panel-bg: #ffffff;
    --ragbot-panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --ragbot-header-text: #ffffff;
    --ragbot-message-max-width: 80%;
    --ragbot-user-bubble-bg: #007cba;
    --ragbot-user-bubble-text: #ffffff;
    --ragbot-bot-bubble-bg: #f1f1f1;
    --ragbot-bot-bubble-text: #333333;
    --ragbot-input-bg: #ffffff;
    --ragbot-input-text: #1f2d3d;
    --ragbot-input-border: #dddddd;
    --ragbot-input-border-width: 1px;
    --ragbot-input-radius: 24px;
    --ragbot-input-padding-y: 12px;
    --ragbot-input-padding-x: 12px;
    --ragbot-input-font-size: 12px;
    --ragbot-input-focus: #007cba;
    --ragbot-send-btn-bg: #007cba;
    --ragbot-send-btn-text: #ffffff;
    --ragbot-send-btn-bg-hover: #005a87;
    --ragbot-send-btn-bg-disabled: #cccccc;
    --ragbot-launcher-bg: #007cba;
    --ragbot-launcher-bg-hover: #005a87;
    --ragbot-launcher-icon-color: #ffffff;
    --ragbot-muted: #666666;
    --ragbot-surface-muted: #f0f6ff;
    --ragbot-border-muted: #d6e6ff;
    --ragbot-success: #1d7f3c;
    --ragbot-danger: #b32d2e;
    --ragbot-widget-width: 350px;
    --ragbot-widget-height: 500px;
    --ragbot-header-height: auto;
    --ragbot-header-bg: #007cba;
    --ragbot-header-padding-y: 16px;
    --ragbot-header-padding-x: 16px;
    --ragbot-panel-radius: 12px;
    --ragbot-panel-border-width: 0px;
    --ragbot-panel-border-color: transparent;
    --ragbot-message-font-size: 12px;
    --ragbot-message-padding: 12px;
    --ragbot-message-radius: 12px;
    --ragbot-launcher-size: 60px;
    --ragbot-launcher-icon-size: 24px;
    --ragbot-send-btn-height: auto;
    --ragbot-send-btn-min-width: auto;
    --ragbot-send-btn-padding-y: 12px;
    --ragbot-send-btn-padding-x: 16px;
    --ragbot-send-btn-font-size: 12px;
    --ragbot-send-btn-radius: 24px;
    --ragbot-send-btn-icon-size: 16px;
    --ragbot-send-btn-icon-padding: 10px;
}

.rag-chat-widget.rag-chat-inline {
    position: relative;
    bottom: auto;
    right: auto;
    left: auto;
    width: 100%;
    max-width: 100%;
}

.rag-chat-button {
    width: calc(var(--ragbot-launcher-size) * var(--ragbot-scale));
    height: calc(var(--ragbot-launcher-size) * var(--ragbot-scale));
    border-radius: 50%;
    background: var(--ragbot-launcher-bg);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.rag-chat-button:hover {
    background: var(--ragbot-launcher-bg-hover);
    transform: scale(1.05);
}

.rag-chat-button svg {
    width: calc(var(--ragbot-launcher-icon-size) * var(--ragbot-scale));
    height: calc(var(--ragbot-launcher-icon-size) * var(--ragbot-scale));
    fill: var(--ragbot-launcher-icon-color);
}

.rag-chat-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: var(--ragbot-widget-width);
    height: var(--ragbot-widget-height);
    background: var(--ragbot-panel-bg);
    border-radius: calc(var(--ragbot-panel-radius) * var(--ragbot-scale));
    border: var(--ragbot-panel-border-width) solid var(--ragbot-panel-border-color);
    box-shadow: var(--ragbot-panel-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

.rag-chat-inline .rag-chat-button,
.rag-chat-inline .rag-chat-header .rag-chat-close {
    display: none;
}

.rag-chat-inline .rag-chat-panel {
    position: relative;
    bottom: auto;
    right: auto;
    width: 100%;
    height: 100%;
    min-height: 480px;
    display: flex;
}

.rag-chat-panel.open {
    display: flex;
}

.rag-chat-header {
    background: var(--ragbot-header-bg);
    color: var(--ragbot-header-text);
    padding: calc(var(--ragbot-header-padding-y) * var(--ragbot-scale)) calc(var(--ragbot-header-padding-x) * var(--ragbot-scale));
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--ragbot-header-height, auto);
    box-sizing: border-box;
}

.rag-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    width: 24px;
    height: 24px;
}

.rag-chat-messages {
    flex: 1;
    padding: calc(16px * var(--ragbot-scale));
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: calc(12px * var(--ragbot-scale));
    font-size: calc(var(--ragbot-message-font-size) * var(--ragbot-scale));
}

.rag-chat-message {
    max-width: var(--ragbot-message-max-width);
    padding: calc(var(--ragbot-message-padding) * var(--ragbot-scale));
    border-radius: calc(var(--ragbot-message-radius) * var(--ragbot-scale));
    word-wrap: break-word;
}

.rag-chat-message.user {
    background: var(--ragbot-user-bubble-bg);
    color: var(--ragbot-user-bubble-text);
    align-self: flex-end;
    margin-left: auto;
}

.rag-chat-message.bot {
    background: var(--ragbot-bot-bubble-bg);
    color: var(--ragbot-bot-bubble-text);
    align-self: flex-start;
}

.rag-chat-sources {
    margin-top: 8px;
    font-size: 10px;
    color: var(--ragbot-muted);
}

.rag-chat-sources a {
    color: var(--ragbot-primary);
    text-decoration: none;
    display: block;
    margin-top: 4px;
}

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

.rag-chat-input-area {
    padding: calc(16px * var(--ragbot-scale));
    border-top: 1px solid var(--ragbot-panel-border-color);
    display: flex;
    gap: 8px;
}

.rag-chat-input {
    flex: 1;
    padding: calc(var(--ragbot-input-padding-y) * var(--ragbot-scale)) calc(var(--ragbot-input-padding-x) * var(--ragbot-scale));
    border: var(--ragbot-input-border-width) solid var(--ragbot-input-border);
    border-radius: calc(var(--ragbot-input-radius) * var(--ragbot-scale));
    outline: none;
    font-size: calc(var(--ragbot-input-font-size) * var(--ragbot-scale));
    background: var(--ragbot-input-bg);
    color: var(--ragbot-input-text);
}

.rag-chat-input:focus {
    border-color: var(--ragbot-input-focus);
}

.rag-chat-send {
    padding: calc(var(--ragbot-send-btn-padding-y) * var(--ragbot-scale)) calc(var(--ragbot-send-btn-padding-x) * var(--ragbot-scale));
    background: var(--ragbot-send-btn-bg);
    color: var(--ragbot-send-btn-text);
    border: none;
    border-radius: calc(var(--ragbot-send-btn-radius) * var(--ragbot-scale));
    cursor: pointer;
    font-size: calc(var(--ragbot-send-btn-font-size) * var(--ragbot-scale));
    transition: background 0.2s;
    height: var(--ragbot-send-btn-height);
    min-width: var(--ragbot-send-btn-min-width);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    line-height: 1;
}

.rag-chat-send.is-icon {
    padding: calc(var(--ragbot-send-btn-icon-padding) * var(--ragbot-scale));
}

.rag-chat-send .rag-send-icon {
    width: calc(var(--ragbot-send-btn-icon-size) * var(--ragbot-scale));
    height: calc(var(--ragbot-send-btn-icon-size) * var(--ragbot-scale));
    fill: currentColor;
    display: none;
}

.rag-chat-send .rag-send-text {
    display: inline-block;
}

.rag-chat-send.is-icon .rag-send-icon {
    display: inline-block;
}

.rag-chat-send.is-icon .rag-send-text {
    display: none;
}

.rag-chat-send:hover:not(:disabled) {
    background: var(--ragbot-send-btn-bg-hover);
}

.rag-chat-send:disabled {
    background: var(--ragbot-send-btn-bg-disabled);
    cursor: not-allowed;
}

.rag-chat-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ragbot-muted);
    font-style: italic;
    background: transparent !important;
}

.rag-chat-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top: 2px solid var(--ragbot-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.ragbot-admin-loader {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top: 3px solid var(--ragbot-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.rag-prechat-form {
    padding: calc(20px * var(--ragbot-scale));
    display: flex;
    flex-direction: column;
    gap: calc(12px * var(--ragbot-scale));
}

.rag-prechat-form p {
    margin: 0 0 8px 0;
    font-weight: 600;
    color: var(--ragbot-text);
}

.rag-prechat-form input {
    padding: calc(var(--ragbot-input-padding-y) * var(--ragbot-scale)) calc(var(--ragbot-input-padding-x) * var(--ragbot-scale));
    border: var(--ragbot-input-border-width) solid var(--ragbot-input-border);
    border-radius: calc(var(--ragbot-input-radius) * var(--ragbot-scale));
    font-size: calc(var(--ragbot-input-font-size) * var(--ragbot-scale));
    background: var(--ragbot-input-bg);
    color: var(--ragbot-input-text);
}

.rag-prechat-form input:focus {
    outline: none;
    border-color: var(--ragbot-input-focus);
}

.rag-start-chat {
    padding: calc(var(--ragbot-send-btn-padding-y) * var(--ragbot-scale));
    background: var(--ragbot-send-btn-bg);
    color: var(--ragbot-send-btn-text);
    border: none;
    border-radius: calc(var(--ragbot-send-btn-radius) * var(--ragbot-scale));
    cursor: pointer;
    font-size: calc(var(--ragbot-send-btn-font-size) * var(--ragbot-scale));
    font-weight: 600;
}

.rag-start-chat:hover {
    background: var(--ragbot-send-btn-bg-hover);
}

.rag-follow-ups {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.rag-follow-ups small {
    color: var(--ragbot-muted);
    font-size: 11px;
}

.rag-follow-up-btn {
    background: white;
    border: 1px solid var(--ragbot-primary);
    color: var(--ragbot-primary);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    text-align: left;
    transition: all 0.2s;
}

.rag-follow-up-btn:hover {
    background: var(--ragbot-primary);
    color: var(--ragbot-primary-contrast);
}

.rag-lead-cta {
    background: var(--ragbot-surface-muted);
    border: 1px solid var(--ragbot-border-muted);
    color: var(--ragbot-text);
    max-width: 100%;
}

.rag-lead-cta-text {
    font-weight: 600;
    margin-bottom: 8px;
}

.rag-lead-cta-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rag-lead-cta-form input,
.rag-lead-cta-form textarea {
    padding: calc(var(--ragbot-input-padding-y) * var(--ragbot-scale)) calc(var(--ragbot-input-padding-x) * var(--ragbot-scale));
    border: var(--ragbot-input-border-width) solid var(--ragbot-input-border);
    border-radius: calc(var(--ragbot-input-radius) * var(--ragbot-scale));
    font-size: calc(var(--ragbot-input-font-size) * var(--ragbot-scale));
    background: var(--ragbot-input-bg);
    color: var(--ragbot-input-text);
}

.rag-lead-cta-form input:focus,
.rag-lead-cta-form textarea:focus {
    outline: none;
    border-color: var(--ragbot-input-focus);
}

.rag-lead-submit {
    padding: 10px 12px;
    background: var(--ragbot-send-btn-bg);
    color: var(--ragbot-send-btn-text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.rag-lead-submit:hover:not(:disabled) {
    background: var(--ragbot-send-btn-bg-hover);
}

.rag-lead-submit:disabled {
    background: var(--ragbot-send-btn-bg-disabled);
    cursor: not-allowed;
}

.rag-lead-status {
    font-size: 11px;
    color: var(--ragbot-danger);
}

.rag-lead-status.rag-lead-success {
    color: var(--ragbot-success);
}

.rag-chat-panel.theme-styled {
    font-family: inherit;
}

.rag-chat-panel.theme-styled .rag-chat-message {
    font-family: inherit;
}

.rag-chat-panel.theme-styled .rag-chat-input,
.rag-chat-panel.theme-styled .rag-prechat-form input {
    font-family: inherit;
}

/* Suggested Topics */
.rag-suggested-topics {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.rag-suggested-topics small {
    color: var(--ragbot-muted);
    font-size: 11px;
}

.rag-topic-btn {
    background: var(--ragbot-surface-muted);
    border: 1px solid var(--ragbot-border-muted);
    color: var(--ragbot-text);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 11px;
    text-align: left;
    transition: all 0.2s;
}

.rag-topic-btn:hover {
    background: var(--ragbot-panel-bg);
    border-color: var(--ragbot-primary);
}

/* Contact CTA */
.rag-contact-cta {
    margin-top: 8px;
    text-align: center;
}

.rag-contact-cta-btn {
    display: inline-block;
    padding: 8px 16px;
    background: var(--ragbot-primary);
    color: var(--ragbot-primary-contrast);
    border-radius: 8px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.2s;
}

.rag-contact-cta-btn:hover {
    background: var(--ragbot-send-btn-bg-hover);
    color: var(--ragbot-primary-contrast);
    text-decoration: none;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .rag-chat-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .rag-chat-panel {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
        right: 10px;
    }
}
