/* ============================================================
   RH Gemini Chat Widget — Production CSS v1.4.0
   Professional-grade chat experience
   ============================================================ */

/* ──────────────────────────────────────────────
   1. WRAPPER
   ────────────────────────────────────────────── */
.rh-gemini-chat-wrapper {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    font-family: inherit;
}

/* ──────────────────────────────────────────────
   2. TOGGLE BUTTON
   ────────────────────────────────────────────── */
.rh-gemini-chat-toggle {
    width: var(--rh-gemini-size, 60px);
    height: var(--rh-gemini-size, 60px);
    border-radius: var(--rh-gemini-radius, 50%);
    background-color: var(--rh-gemini-primary, #0052cc);
    color: white;
    border: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                box-shadow 0.3s ease;
}
.rh-gemini-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.rh-gemini-chat-toggle:active {
    transform: scale(0.95);
}

/* ──────────────────────────────────────────────
   3. CHAT BOX — desktop
   ────────────────────────────────────────────── */
.rh-gemini-chat-box {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 100px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12),
                0 0 0 1px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.rh-gemini-chat-box.rh-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9) translateY(12px);
}

/* ──────────────────────────────────────────────
   4. HEADER
   ────────────────────────────────────────────── */
.rh-gemini-chat-header {
    background: var(--rh-gemini-primary, #0052cc);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 56px;
    box-sizing: border-box;
}
.rh-gemini-chat-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: white;
    letter-spacing: 0.2px;
}
#rh-gemini-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s;
}
#rh-gemini-chat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ──────────────────────────────────────────────
   5. MESSAGES
   ────────────────────────────────────────────── */
.rh-gemini-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 20px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: #f8f9fb;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ──────────────────────────────────────────────
   6. BUBBLES
   ────────────────────────────────────────────── */
.rh-chat-message {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.65;
    word-wrap: break-word;
    animation: rhFadeIn 0.3s ease;
}
@keyframes rhFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.rh-chat-message p {
    margin: 0 0 6px 0;
}
.rh-chat-message p:last-child {
    margin: 0;
}
.rh-chat-message.model {
    background: #ffffff;
    color: #2d3748;
    align-self: flex-start;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: 1px solid #eef1f6;
}
.rh-chat-message.user {
    background: var(--rh-gemini-primary, #0052cc);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 82, 204, 0.25);
}

/* ──────────────────────────────────────────────
   7. INPUT AREA
   ────────────────────────────────────────────── */
.rh-gemini-chat-input-area {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid #eef1f6;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
#rh-gemini-chat-input {
    flex: 1;
    border: 1.5px solid #e2e6ed;
    background: #f8f9fb;
    border-radius: 22px;
    padding: 10px 16px;
    font-family: inherit;
    /* 16px prevents iOS zoom on focus */
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 80px;
    min-height: 42px;
    height: 42px;
    overflow-y: auto;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    line-height: 1.4;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}
#rh-gemini-chat-input:focus {
    border-color: var(--rh-gemini-primary, #0052cc);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.08);
}
#rh-gemini-chat-input::placeholder {
    color: #9ca3af;
    font-size: 14px;
}
#rh-gemini-chat-send {
    background: var(--rh-gemini-primary, #0052cc);
    color: white;
    border: none;
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.2s, transform 0.15s, background-color 0.2s;
    flex-shrink: 0;
}
#rh-gemini-chat-send:not(:disabled):hover {
    filter: brightness(1.1);
    transform: scale(1.05);
}
#rh-gemini-chat-send:not(:disabled):active {
    transform: scale(0.95);
}
#rh-gemini-chat-send:disabled {
    background: #e4e9f2;
    color: #8f9bb3;
    cursor: not-allowed;
}

/* ──────────────────────────────────────────────
   8. TYPING INDICATOR
   ────────────────────────────────────────────── */
.rh-typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 16px;
    background: #ffffff;
    border-radius: 16px;
    align-self: flex-start;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: 1px solid #eef1f6;
    animation: rhFadeIn 0.3s ease;
}
.rh-typing-indicator span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: rhBlink 1.4s infinite both;
}
.rh-typing-indicator span:nth-child(1) { animation-delay: 0s; }
.rh-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.rh-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes rhBlink {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40%            { opacity: 1;   transform: scale(1.15); }
}

/* ──────────────────────────────────────────────
   9. BODY SCROLL LOCK (toggled by JS)
   ────────────────────────────────────────────── */
body.rh-chat-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    touch-action: none !important;
}

/* ──────────────────────────────────────────────
   10. PROACTIVE NOTIFICATIONS & READ RECEIPTS
   ────────────────────────────────────────────── */
.rh-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #FF3B30;
    color: white;
    font-size: 11px;
    font-weight: bold;
    height: 20px;
    min-width: 20px;
    padding: 0 6px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    box-sizing: border-box;
    animation: rhPopIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes rhPopIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.rh-msg-status {
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: -6px;
    margin-bottom: 10px;
    padding-right: 14px;
    gap: 4px;
    align-self: flex-end;
    width: 100%;
}
.rh-msg-status.rh-sent { color: #9ca3af; }
.rh-msg-status.rh-read { color: #34b7f1; } /* WhatsApp Blue */

.rh-msg-status svg {
    width: 14px;
    height: 14px;
}

/* ══════════════════════════════════════════════
   11. MOBILE — fullscreen takeover (≤ 768px)
   ══════════════════════════════════════════════ */
@media (max-width: 768px) {
    .rh-gemini-chat-box {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        transform: none !important;
        z-index: 2147483647 !important;
        box-shadow: none !important;
        transition: none !important;
        overflow: hidden !important;
    }
    .rh-gemini-chat-box.rh-hidden {
        display: none !important;
    }

    /* iOS Safari viewport fix */
    @supports (-webkit-touch-callout: none) {
        .rh-gemini-chat-box {
            height: -webkit-fill-available !important;
        }
    }

    /* Adjust padding for mobile */
    .rh-gemini-chat-messages {
        padding: 16px 12px;
    }
    .rh-gemini-chat-input-area {
        padding: 10px 12px;
        /* Safe area for phones with notch/home indicator */
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .rh-gemini-chat-box:not(.rh-hidden) ~ .rh-gemini-chat-toggle {
        display: none !important;
    }
}
