/* ============================================================
   Reefy Chatbot v1.2 — Stylesheet
   RTL-first, Arabic typography
   Includes: floating bubble, inline embed, suggestion chips,
             loan button, typing indicator, streaming cursor
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700&display=swap');

:root {
    --reefy-brand:       #1a6b4a;
    --reefy-brand-dark:  #145538;
    --reefy-brand-light: #e8f5ef;
    --reefy-bg:          #ffffff;
    --reefy-surface:     #f7f9f8;
    --reefy-border:      #dde8e3;
    --reefy-text:        #1c2b26;
    --reefy-muted:       #7a9b8e;
    --reefy-user-bg:     var(--reefy-brand);
    --reefy-user-text:   #ffffff;
    --reefy-bot-bg:      #eef5f1;
    --reefy-bot-text:    var(--reefy-text);
    --reefy-shadow:      0 8px 32px rgba(26,107,74,.18), 0 2px 8px rgba(0,0,0,.08);
    --reefy-radius:      18px;
    --reefy-bubble-size: 58px;
    --reefy-font:        'Tajawal', 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    --reefy-w:           390px;
    --reefy-h:           560px;
    --reefy-z:           99999;
}

.reefy-chat-wrap *,
.reefy-chat-embed * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── FLOATING BUBBLE ── */
#reefy-float-btn {
    position: fixed;
    width:  var(--reefy-bubble-size);
    height: var(--reefy-bubble-size);
    border-radius: 50%;
    background: var(--reefy-brand);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--reefy-shadow);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1), background .2s;
    z-index: var(--reefy-z);
    outline: none;
}
#reefy-float-btn:hover { background: var(--reefy-brand-dark); transform: scale(1.08); }
#reefy-float-btn.bottom-right { bottom: 24px; right: 24px; }
#reefy-float-btn.bottom-left  { bottom: 24px; left: 24px; }
#reefy-float-btn svg { width: 26px; height: 26px; }
#reefy-float-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--reefy-brand);
    opacity: 0;
    animation: reefy-ping 2.4s ease-out infinite;
}
@keyframes reefy-ping {
    0%  { transform: scale(1);   opacity: .6; }
    80% { transform: scale(1.5); opacity: 0; }
}

/* ── CHAT PANEL ── */
.reefy-chat-wrap {
    display: flex;
    flex-direction: column;
    background: var(--reefy-bg);
    border-radius: var(--reefy-radius);
    overflow: hidden;
    font-family: var(--reefy-font);
    direction: rtl;
    text-align: right;
}

.reefy-chat-wrap.is-floating {
    position: fixed;
    width: var(--reefy-w);
    height: var(--reefy-h);
    box-shadow: var(--reefy-shadow);
    border: 1px solid var(--reefy-border);
    z-index: var(--reefy-z);
    transform-origin: bottom right;
    transform: scale(.85) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform .3s cubic-bezier(.34,1.4,.64,1), opacity .25s ease;
}
.reefy-chat-wrap.is-floating.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}
.reefy-chat-wrap.is-floating.bottom-right { bottom: 94px; right: 24px; }
.reefy-chat-wrap.is-floating.bottom-left  { bottom: 94px; left: 24px; }

.reefy-chat-embed {
    width: 100%;
    border-radius: var(--reefy-radius);
    overflow: hidden;
    border: 1px solid var(--reefy-border);
    box-shadow: 0 4px 18px rgba(26,107,74,.10);
}
.reefy-chat-embed .reefy-chat-wrap { height: 100%; border-radius: 0; }

/* ── HEADER ── */
.reefy-header {
    background: var(--reefy-brand);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 10px;
}
.reefy-header-info { display: flex; align-items: center; gap: 10px; }
.reefy-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.22);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.reefy-avatar svg { width: 20px; height: 20px; }
.reefy-title   { font-size: 15px; font-weight: 700; line-height: 1.2; }
.reefy-subtitle { font-size: 11px; opacity: .78; margin-top: 1px; }
.reefy-close-btn {
    background: transparent; border: none; cursor: pointer;
    color: #fff; opacity: .75; padding: 4px; border-radius: 6px;
    transition: opacity .15s, background .15s; display: none;
    align-items: center;
}
.reefy-close-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
.is-floating .reefy-close-btn { display: flex; }
.reefy-close-btn svg { width: 18px; height: 18px; }

/* ── MESSAGES ── */
.reefy-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--reefy-surface);
    scroll-behavior: smooth;
}
.reefy-messages::-webkit-scrollbar { width: 5px; }
.reefy-messages::-webkit-scrollbar-thumb { background: var(--reefy-border); border-radius: 3px; }

.reefy-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.7;
    animation: reefy-pop .22s ease both;
    word-break: break-word;
    white-space: pre-wrap;
}
@keyframes reefy-pop {
    from { transform: scale(.94) translateY(4px); opacity: 0; }
    to   { transform: scale(1)   translateY(0);   opacity: 1; }
}
.reefy-msg.user {
    background: var(--reefy-user-bg);
    color: var(--reefy-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.reefy-msg.bot {
    background: var(--reefy-bot-bg);
    color: var(--reefy-bot-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.reefy-msg.bot.streaming::after {
    content: '▌';
    opacity: .7;
    animation: reefy-blink .6s step-end infinite;
}
@keyframes reefy-blink { 0%,100% { opacity:.7; } 50% { opacity:0; } }

/* typing dots */
.reefy-msg.typing {
    background: var(--reefy-bot-bg);
    align-self: flex-start;
    display: flex; align-items: center; gap: 5px;
    padding: 12px 16px; min-width: 56px;
}
.reefy-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--reefy-muted);
    animation: reefy-bounce .9s ease infinite;
}
.reefy-dot:nth-child(2) { animation-delay: .15s; }
.reefy-dot:nth-child(3) { animation-delay: .30s; }
@keyframes reefy-bounce {
    0%,60%,100% { transform: translateY(0); }
    30%          { transform: translateY(-6px); }
}

/* ── SUGGESTION CHIPS ── */
.reefy-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 4px 2px 6px;
    align-self: flex-start;
    width: 100%;
    animation: reefy-pop .25s ease both;
}
.reefy-chip {
    padding: 6px 13px;
    background: var(--reefy-brand-light);
    color: var(--reefy-brand-dark);
    border: 1.5px solid #b3d4c4;
    border-radius: 20px;
    font-size: 13px;
    font-family: var(--reefy-font);
    cursor: pointer;
    transition: background .15s, transform .1s;
    line-height: 1.4;
    direction: rtl;
}
.reefy-chip:hover {
    background: #c8e6d4;
    transform: translateY(-1px);
}

/* ── LOAN BUTTON ── */
.reefy-loan-wrap {
    align-self: flex-start;
    animation: reefy-pop .25s ease both;
    margin: 2px 0;
}
.reefy-loan-btn {
    background: var(--reefy-brand);
    color: #fff;
    padding: 9px 20px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-family: var(--reefy-font);
    font-weight: 600;
    transition: background .18s, transform .15s;
    direction: rtl;
    display: flex; align-items: center; gap: 7px;
}
.reefy-loan-btn:hover { background: var(--reefy-brand-dark); transform: translateY(-1px); }
.reefy-loan-btn svg { width: 16px; height: 16px; }

/* ── INPUT BAR ── */
.reefy-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--reefy-border);
    background: var(--reefy-bg);
    flex-shrink: 0;
}
.reefy-input {
    flex: 1;
    border: 1.5px solid var(--reefy-border);
    border-radius: 24px;
    padding: 9px 16px;
    font-family: var(--reefy-font);
    font-size: 14px;
    direction: rtl; text-align: right;
    background: var(--reefy-surface);
    color: var(--reefy-text);
    outline: none;
    transition: border-color .18s, box-shadow .18s;
    resize: none; line-height: 1.5;
    max-height: 120px; overflow-y: auto;
}
.reefy-input::placeholder { color: var(--reefy-muted); }
.reefy-input:focus {
    border-color: var(--reefy-brand);
    box-shadow: 0 0 0 3px rgba(26,107,74,.12);
    background: #fff;
}
.reefy-send-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--reefy-brand);
    color: #fff; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .18s, transform .15s;
}
.reefy-send-btn:hover:not(:disabled) { background: var(--reefy-brand-dark); transform: scale(1.07); }
.reefy-send-btn:disabled { opacity: .45; cursor: not-allowed; }
.reefy-send-btn svg { width: 18px; height: 18px; }

/* ── POPUP CLOUD BUBBLE ── */
#reefy-bubble-popup {
    position: fixed;
    z-index: calc(var(--reefy-z) + 1);
    background: #fff;
    color: var(--reefy-text);
    font-family: var(--reefy-font);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    padding: 10px 16px;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 4px 20px rgba(0,0,0,.13), 0 1px 4px rgba(0,0,0,.08);
    white-space: nowrap;
    direction: rtl;
    cursor: pointer;
    border: 1px solid var(--reefy-border);

    /* entry animation */
    opacity: 0;
    transform: translateY(8px) scale(.95);
    animation: reefy-bubble-in .4s cubic-bezier(.34,1.4,.64,1) .8s forwards;
}

/* tail pointing down toward button */
#reefy-bubble-popup::after {
    content: '';
    position: absolute;
    bottom: -8px;
    width: 14px; height: 14px;
    background: #fff;
    border-right: 1px solid var(--reefy-border);
    border-bottom: 1px solid var(--reefy-border);
    clip-path: polygon(0 0, 100% 100%, 100% 0);
}

/* position tail per button placement */
#reefy-bubble-popup.bottom-right::after { right: 20px; }
#reefy-bubble-popup.bottom-left::after  { left: 20px; clip-path: polygon(0 0, 100% 0, 0 100%); }

#reefy-bubble-popup.bottom-right { right: 14px; }
#reefy-bubble-popup.bottom-left  { left: 14px; }

/* dismiss X button */
#reefy-bubble-popup .reefy-bubble-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: #eee;
    border: none;
    cursor: pointer;
    font-size: 11px;
    color: #666;
    vertical-align: middle;
    flex-shrink: 0;
    transition: background .15s;
}
#reefy-bubble-popup .reefy-bubble-close:hover { background: #ddd; }

#reefy-bubble-popup.hiding {
    animation: reefy-bubble-out .25s ease forwards;
}

@keyframes reefy-bubble-in {
    from { opacity: 0; transform: translateY(8px) scale(.95); }
    to   { opacity: 1; transform: translateY(0)   scale(1);   }
}
@keyframes reefy-bubble-out {
    from { opacity: 1; transform: translateY(0)  scale(1);   }
    to   { opacity: 0; transform: translateY(4px) scale(.95); }
}

/* ── RESPONSIVE ── */
@media (max-width: 460px) {
    .reefy-chat-wrap.is-floating {
        width: calc(100vw - 24px);
        right: 12px; left: 12px;
    }
    #reefy-float-btn.bottom-right { right: 16px; bottom: 16px; }
    #reefy-float-btn.bottom-left  { left: 16px;  bottom: 16px; }
}
