/* ═══════════════════════════════════════════════════════════════
   RAG Chatbot – Popup Widget CSS  v2.1
   Both #rag-launcher and #rag-popup-wrap are moved directly onto
   <body> by JS (portal pattern), bypassing any theme container
   that could break position:fixed.
   ═══════════════════════════════════════════════════════════════ */

/* ── Box-sizing reset scoped to widget only ──────────────────── */
#rag-popup-wrap,
#rag-popup-wrap *,
#rag-launcher,
#rag-launcher * {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ── Launcher – fixed bottom-right ───────────────────────────── */
#rag-launcher {
    position: fixed !important;
    bottom: 28px !important;
    left: 28px !important;
    top: auto !important;
    right: auto !important;
    z-index: 2147483646 !important; /* max z-index - 1 */
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-align: start;
    -ms-flex-align: start;
    align-items: flex-start;
    gap: 10px;
    /* Prevent theme from inheriting transforms */
    -webkit-transform: none !important;
    transform: none !important;
    -webkit-filter: none !important;
    filter: none !important;
    will-change: auto !important;
    contain: none !important;
    isolation: auto !important;
}

/* ── Teaser notification bubble ──────────────────────────────── */
#rag-teaser {
    background: #ffffff;
    border-radius: 14px;
    padding: 12px 30px 12px 14px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: start;
    -ms-flex-align: start;
    align-items: flex-start;
    gap: 10px;
    max-width: 260px;
    cursor: pointer;
    position: relative;
    -webkit-animation: rag-fadein 0.35s ease both;
    animation: rag-fadein 0.35s ease both;
}
#rag-teaser-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 8px;
    background: #91ac45;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
}
#rag-teaser-icon svg {
    width: 18px;
    height: 18px;
    fill: #ffffff;
    display: block;
}
#rag-teaser-title {
    font-size: 13px;
    font-weight: 600;
    color: #111111;
    line-height: 1.4;
}
#rag-teaser-sub {
    font-size: 11px;
    color: #999999;
    margin-top: 2px;
}
#rag-teaser-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: #bbbbbb;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    width: 20px;
    height: 20px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
}
#rag-teaser-close:hover { color: #555555; }

/* ── Launcher button ─────────────────────────────────────────── */
#rag-launcher-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: #90ac45;
    border: none;
    cursor: pointer;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-transition: -webkit-transform 0.2s ease, box-shadow 0.2s ease;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: visible;
    -webkit-transform: none;
    transform: none;
}
#rag-launcher-btn:hover {
    -webkit-transform: scale(1.07);
    transform: scale(1.07);
}
#rag-launcher-btn svg {
    width: 26px;
    height: 26px;
    fill: #ffffff;
    display: block;
}
#rag-launcher-btn .rag-icon-close { display: none; }

#rag-unread-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #ffffff;
    font-size: 10px;
    font-weight: 700;
    color: #ffffff;
    display: none;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    line-height: 1;
}
#rag-unread-badge.rag-visible {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
}

/* ── Popup window – fixed bottom-right ───────────────────────── */
#rag-popup-wrap {
    position: fixed !important;
    bottom: 96px !important;
    left: 28px !important;
    top: auto !important;
    right: auto !important;
    z-index: 2147483647 !important; /* max z-index */
    width: 360px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    overflow: hidden;
    /* Hidden by default — JS adds .rag-open */
    opacity: 0;
    visibility: hidden;
    -webkit-transform: translateY(16px) scale(0.97) !important;
    transform: translateY(16px) scale(0.97) !important;
    pointer-events: none;
    -webkit-transition: opacity 0.25s ease, visibility 0.25s ease, -webkit-transform 0.25s ease;
    transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
    /* Prevent theme interference */
    -webkit-filter: none !important;
    filter: none !important;
    will-change: opacity, transform;
    contain: none !important;
    isolation: isolate;
}
#rag-popup-wrap.rag-open {
    opacity: 1;
    visibility: visible;
    -webkit-transform: translateY(0) scale(1) !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────────── */
#rag-popup-header {
    background: #ffffff;
    padding: 14px 16px 12px;
    border-bottom: 1px solid #f0f0f0;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 10px;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}
.rag-avatars {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}
.rag-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    background: rgba(78, 76, 76, 1);
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
}
.rag-avatar img {
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
    object-fit: cover;
    display: block;
}
.rag-header-info {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    min-width: 0;
}
.rag-header-title {
    font-size: 15px;
    font-weight: 700;
    color: #111111;
    white-space: nowrap;
    overflow: hidden;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.rag-header-subtitle {
    font-size: 11px;
    color: #22c55e;
    margin-top: 2px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 4px;
}
.rag-online-dot {
    width: 7px;
    height: 7px;
    min-width: 7px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
}
.rag-header-actions {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 2px;
}
.rag-header-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #999999;
    padding: 6px;
    border-radius: 8px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-transition: background 0.15s, color 0.15s;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}
.rag-header-btn:hover {
    background: #f5f5f5;
    color: #333333;
}

/* ── Subheader banner ────────────────────────────────────────── */
#rag-popup-subheader {
    background: #f8f9ff;
    padding: 8px 16px;
    font-size: 12px;
    color: #666666;
    text-align: center;
    border-bottom: 1px solid #eeeeee;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}

/* ── Messages area ───────────────────────────────────────────── */
#rag-messages {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    gap: 8px;
    min-height: 240px;
    max-height: 340px;
    background: #f8f9fb;
}
#rag-messages::-webkit-scrollbar { width: 4px; }
#rag-messages::-webkit-scrollbar-track { background: transparent; }
#rag-messages::-webkit-scrollbar-thumb { background: #dddddd; border-radius: 2px; }

/* ── Message rows ────────────────────────────────────────────── */
.rag-msg-row {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: end;
    -ms-flex-align: end;
    align-items: flex-end;
    gap: 7px;
}
.rag-msg-row.rag-user {
    -webkit-box-orient: horizontal;
    -webkit-box-direction: reverse;
    -ms-flex-direction: row-reverse;
    flex-direction: row-reverse;
}
.rag-msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: rgba(78, 76, 76, 1);
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
}
.rag-msg-avatar img {
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
    object-fit: cover;
    display: block;
}
.rag-bubble {
    max-width: 76%;
    padding: 9px 12px !important;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    word-wrap: break-word;
}
.rag-msg-row.rag-bot .rag-bubble {
    background: #ffffff;
    color: #111111;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.rag-msg-row.rag-user .rag-bubble {
    background: #91ac45;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}
.rag-msg-meta {
    font-size: 10px;
    color: #bbbbbb;
    margin-top: 2px;
    padding-left: 35px;
    line-height: 1.3;
}
.rag-msg-row.rag-user + .rag-msg-meta {
    text-align: right;
    padding-left: 0;
    padding-right: 35px;
}

/* Cache badge */
.rag-cache-badge {
    display: inline-block;
    font-size: 10px;
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    border-radius: 4px;
    padding: 1px 6px;
    margin-bottom: 4px;
    font-weight: 500;
}

/* Typing dots */
.rag-typing {
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 5px;
    padding: 10px 14px !important;
    background: #ffffff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.rag-typing span {
    width: 7px;
    height: 7px;
    background: #cccccc;
    border-radius: 50%;
    display: block;
    -webkit-animation: rag-bounce 0.9s infinite;
    animation: rag-bounce 0.9s infinite;
}
.rag-typing span:nth-child(2) { -webkit-animation-delay: 0.15s; animation-delay: 0.15s; }
.rag-typing span:nth-child(3) { -webkit-animation-delay: 0.30s; animation-delay: 0.30s; }

/* Sources */
.rag-sources {
    font-size: 11px;
    color: #999999;
    margin-top: 4px;
    padding-left: 35px;
}
.rag-sources a { color: #91ac45; text-decoration: none; }
.rag-sources a:hover { text-decoration: underline; }

/* ── Input area ──────────────────────────────────────────────── */
#rag-input-area {
    border-top: 1px solid #eeeeee;
    background: #ffffff;
    padding: 10px 12px;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}
#rag-email-row {
    margin-bottom: 8px;
    display: none;
}
#rag-email-row.rag-visible { display: block; }
#rag-email-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid #eeeeee;
    padding: 6px 4px;
    font-size: 13px;
    color: #333333;
    outline: none;
    background: transparent;
    line-height: 1.4;
}
#rag-email-input::-webkit-input-placeholder { color: #cccccc; }
#rag-email-input:-ms-input-placeholder      { color: #cccccc; }
#rag-email-input::placeholder               { color: #cccccc; }
#rag-email-input:focus { border-bottom-color: #91ac45; }

#rag-msg-row {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: end;
    -ms-flex-align: end;
    align-items: flex-end;
    gap: 8px;
}
#rag-input {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    border: none;
    resize: none;
    font-size: 13.5px;
    font-family: inherit;
    color: #333333;
    outline: none;
    background: transparent;
    max-height: 100px;
    line-height: 1.5;
    padding: 4px;
    overflow-y: auto;
}
#rag-input::-webkit-input-placeholder { color: #cccccc; }
#rag-input:-ms-input-placeholder      { color: #cccccc; }
#rag-input::placeholder               { color: #cccccc; }

.rag-input-actions {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}
#rag-send-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    background: #91ac45;
    border: none;
    cursor: pointer;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-transition: background 0.2s, opacity 0.2s;
    transition: background 0.2s, opacity 0.2s;
}
#rag-send-btn:hover { background: #333; }
#rag-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#rag-send-btn svg { width: 16px; height: 16px; fill: #ffffff; display: block; }

/* ── Keyframes ───────────────────────────────────────────────── */
@-webkit-keyframes rag-fadein {
    from { opacity: 0; -webkit-transform: translateY(10px); transform: translateY(10px); }
    to   { opacity: 1; -webkit-transform: translateY(0);    transform: translateY(0); }
}
@keyframes rag-fadein {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@-webkit-keyframes rag-bounce {
    0%, 60%, 100% { -webkit-transform: translateY(0); transform: translateY(0); }
    30%           { -webkit-transform: translateY(-5px); transform: translateY(-5px); }
}
@keyframes rag-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-5px); }
}

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #rag-popup-wrap {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0;
        max-height: 88vh;
    }
    #rag-launcher {
        bottom: 16px !important;
        left: 16px !important;
    }
}

/* ── Contact Us button ───────────────────────────────────────── */
.rag-contact-btn-wrap {
    margin-top: 10px;
}
.rag-contact-btn {
    display: inline-block;
    padding: 7px 18px !important;
    background: #333;
    color: #fff !important;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    cursor: pointer;
    letter-spacing: 0.02em;
}
.rag-contact-btn:hover {
    background: #4f4f4f;
    transform: translateY(-1px);
    text-decoration: none;
    color: #fff !important;
}
