/* ============================================================
   Site Chatbot Widget Styles
   Mobile-first, no external dependencies
   ============================================================ */

:root {
    --sc-primary:        #2563eb;
    --sc-primary-hover:  #1d4ed8;
    --sc-primary-light:  #eff6ff;
    --sc-bg:             #ffffff;
    --sc-header-bg:      #1e293b;
    --sc-text:           #1e293b;
    --sc-text-muted:     #64748b;
    --sc-border:         #e2e8f0;
    --sc-user-bubble:    #2563eb;
    --sc-user-text:      #ffffff;
    --sc-bot-bubble:     #f1f5f9;
    --sc-bot-text:       #1e293b;
    --sc-shadow:         0 20px 60px -12px rgba(0,0,0,.25), 0 4px 20px rgba(0,0,0,.12);
    --sc-radius:         18px;
    --sc-font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --sc-z:              999999;
    --sc-w:              380px;
    --sc-h:              560px;
    --sc-bottom:         24px;
    --sc-side:           24px;
    --sc-trigger-size:   60px;
}

/* ---- Reset ---- */
#site-chatbot-root *,
#site-chatbot-root *::before,
#site-chatbot-root *::after {
    box-sizing: border-box;
    margin:     0;
    padding:    0;
}

/* ---- Root ---- */
#site-chatbot-root {
    position:   fixed;
    bottom:     var(--sc-bottom);
    right:      var(--sc-side);
    z-index:    var(--sc-z);
    font-family: var(--sc-font);
}

#site-chatbot-root.sc-pos-left {
    right: auto;
    left:  var(--sc-side);
}

/* ============================================================
   Trigger Button
   ============================================================ */
#sc-trigger {
    position:      relative;
    width:         var(--sc-trigger-size);
    height:        var(--sc-trigger-size);
    border-radius: 50%;
    background:    var(--sc-primary);
    border:        none;
    cursor:        pointer;
    display:       flex;
    align-items:   center;
    justify-content: center;
    box-shadow:    0 4px 20px rgba(37,99,235,.45);
    transition:    transform .2s cubic-bezier(.34,1.56,.64,1), background .18s ease;
    outline-offset: 3px;
}

#sc-trigger:hover { transform: scale(1.08); background: var(--sc-primary-hover); }
#sc-trigger:focus-visible { outline: 2px solid var(--sc-primary); }
#sc-trigger:active { transform: scale(.96); }

#sc-trigger svg {
    width:  26px;
    height: 26px;
    color:  #fff;
    transition: opacity .15s, transform .2s;
}

.sc-icon-open  { display: flex; }
.sc-icon-close { display: none; }

#sc-trigger.sc-open .sc-icon-open  { display: none; }
#sc-trigger.sc-open .sc-icon-close { display: flex; }

/* Pulse ring animation */
#sc-trigger::after {
    content:    '';
    position:   absolute;
    inset:      -4px;
    border-radius: 50%;
    border:     2px solid var(--sc-primary);
    opacity:    0;
    animation:  sc-pulse 2.5s ease-out infinite;
}

@keyframes sc-pulse {
    0%   { transform: scale(.9); opacity: .7; }
    70%  { transform: scale(1.3); opacity: 0; }
    100% { opacity: 0; }
}

/* Unread badge */
.sc-unread-badge {
    position:      absolute;
    top:           0;
    right:         0;
    width:         20px;
    height:        20px;
    background:    #ef4444;
    color:         #fff;
    font-size:     11px;
    font-weight:   700;
    border-radius: 50%;
    display:       flex;
    align-items:   center;
    justify-content: center;
    border:        2px solid #fff;
}

/* ============================================================
   Chat Window
   ============================================================ */
#sc-window {
    position:      absolute;
    bottom:        calc(var(--sc-trigger-size) + 12px);
    right:         0;
    width:         var(--sc-w);
    height:        var(--sc-h);
    max-height:    calc(100vh - 120px);
    background:    var(--sc-bg);
    border-radius: var(--sc-radius);
    box-shadow:    var(--sc-shadow);
    display:       flex;
    flex-direction: column;
    overflow:      hidden;
    opacity:       0;
    transform:     translateY(16px) scale(.97);
    pointer-events: none;
    transition:    opacity .22s cubic-bezier(.4,0,.2,1), transform .22s cubic-bezier(.4,0,.2,1);
    border:        1px solid var(--sc-border);
}

#sc-window.sc-visible {
    opacity:        1;
    transform:      translateY(0) scale(1);
    pointer-events: all;
}

#sc-window.sc-minimized {
    height:         72px;
    min-height:     72px;
}

.sc-pos-left #sc-window {
    right: auto;
    left:  0;
}

/* ============================================================
   Header
   ============================================================ */
#sc-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         14px 16px;
    background:      var(--sc-header-bg);
    color:           #fff;
    flex-shrink:     0;
    gap:             10px;
}

.sc-header-info {
    display:     flex;
    align-items: center;
    gap:         10px;
    min-width:   0;
}

.sc-avatar {
    width:         38px;
    height:        38px;
    border-radius: 50%;
    background:    rgba(255,255,255,.15);
    display:       flex;
    align-items:   center;
    justify-content: center;
    flex-shrink:   0;
}

.sc-avatar svg { width: 22px; height: 22px; color: #fff; }

.sc-header-text {
    display:   flex;
    flex-direction: column;
    min-width: 0;
}

.sc-bot-name {
    font-size:   15px;
    font-weight: 600;
    white-space: nowrap;
    overflow:    hidden;
    text-overflow: ellipsis;
}

.sc-status {
    font-size:   11px;
    color:       rgba(255,255,255,.75);
    display:     flex;
    align-items: center;
    gap:         4px;
    margin-top:  2px;
}

.sc-online-dot {
    width:         6px;
    height:        6px;
    border-radius: 50%;
    background:    #22c55e;
    display:       inline-block;
    flex-shrink:   0;
}

.sc-header-actions {
    display:     flex;
    align-items: center;
    gap:         4px;
    flex-shrink: 0;
}

.sc-header-actions button {
    background:    transparent;
    border:        none;
    cursor:        pointer;
    color:         rgba(255,255,255,.75);
    width:         30px;
    height:        30px;
    border-radius: 6px;
    display:       flex;
    align-items:   center;
    justify-content: center;
    transition:    background .15s, color .15s;
}

.sc-header-actions button:hover  { background: rgba(255,255,255,.12); color: #fff; }
.sc-header-actions button svg    { width: 16px; height: 16px; }

/* ============================================================
   Messages Area
   ============================================================ */
#sc-messages {
    flex:         1;
    overflow-y:   auto;
    padding:      16px 12px;
    display:      flex;
    flex-direction: column;
    gap:          10px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Hide messages when minimized */
.sc-minimized #sc-messages,
.sc-minimized #sc-quick-replies,
.sc-minimized #sc-input-area,
.sc-minimized #sc-footer {
    display: none;
}

/* Scrollbar */
#sc-messages::-webkit-scrollbar { width: 4px; }
#sc-messages::-webkit-scrollbar-track { background: transparent; }
#sc-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ---- Message Row ---- */
.sc-msg {
    display:     flex;
    gap:         8px;
    align-items: flex-end;
    animation:   sc-msg-in .2s ease both;
}

@keyframes sc-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sc-msg.sc-msg-user  { flex-direction: row-reverse; }
.sc-msg.sc-msg-bot   { flex-direction: row; }

.sc-msg-avatar {
    width:         28px;
    height:        28px;
    border-radius: 50%;
    background:    var(--sc-header-bg);
    display:       flex;
    align-items:   center;
    justify-content: center;
    flex-shrink:   0;
}

.sc-msg-avatar svg { width: 16px; height: 16px; color: #fff; }

.sc-msg-user .sc-msg-avatar { display: none; }

.sc-bubble {
    max-width:     72%;
    padding:       10px 14px;
    border-radius: 18px;
    font-size:     14px;
    line-height:   1.55;
    word-wrap:     break-word;
    overflow-wrap: break-word;
}

.sc-msg-bot  .sc-bubble {
    background:         var(--sc-bot-bubble);
    color:              var(--sc-bot-text);
    border-bottom-left-radius: 4px;
}

.sc-msg-user .sc-bubble {
    background:          var(--sc-user-bubble);
    color:               var(--sc-user-text);
    border-bottom-right-radius: 4px;
}

.sc-bubble a {
    color:           var(--sc-primary);
    text-decoration: underline;
    word-break:      break-all;
}

.sc-msg-user .sc-bubble a { color: rgba(255,255,255,.9); }

.sc-timestamp {
    font-size:   10px;
    color:       var(--sc-text-muted);
    margin-top:  4px;
    text-align:  right;
}

.sc-msg-bot .sc-timestamp { text-align: left; padding-left: 36px; }

/* Typing indicator */
.sc-typing-indicator {
    display:     flex;
    gap:         4px;
    align-items: center;
    padding:     4px 2px;
}

.sc-typing-indicator span {
    width:         7px;
    height:        7px;
    border-radius: 50%;
    background:    var(--sc-text-muted);
    display:       inline-block;
    animation:     sc-bounce .9s ease infinite;
}

.sc-typing-indicator span:nth-child(1) { animation-delay: 0s; }
.sc-typing-indicator span:nth-child(2) { animation-delay: .15s; }
.sc-typing-indicator span:nth-child(3) { animation-delay: .3s; }

@keyframes sc-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Suggestions */
.sc-suggestions {
    display:    flex;
    flex-direction: column;
    gap:        4px;
    margin-top: 6px;
}

.sc-suggestion-label {
    font-size:   11px;
    font-weight: 600;
    color:       var(--sc-text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 2px;
}

.sc-suggestion-link {
    display:     inline-flex;
    align-items: center;
    gap:         4px;
    font-size:   13px;
    color:       var(--sc-primary);
    text-decoration: none;
    padding:     4px 8px;
    border-radius: 6px;
    transition:  background .15s;
}

.sc-suggestion-link:hover { background: var(--sc-primary-light); text-decoration: none; }

/* ============================================================
   Quick Replies
   ============================================================ */
#sc-quick-replies {
    padding:    0 12px 10px;
    display:    flex;
    flex-wrap:  wrap;
    gap:        6px;
    flex-shrink: 0;
}

.sc-quick-reply {
    background:    var(--sc-primary-light);
    color:         var(--sc-primary);
    border:        1.5px solid var(--sc-primary);
    border-radius: 20px;
    padding:       5px 13px;
    font-size:     13px;
    font-weight:   500;
    cursor:        pointer;
    transition:    background .15s, color .15s;
    white-space:   nowrap;
}

.sc-quick-reply:hover { background: var(--sc-primary); color: #fff; }

/* ============================================================
   Input Area
   ============================================================ */
#sc-input-area {
    display:      flex;
    align-items:  flex-end;
    gap:          8px;
    padding:      10px 12px;
    border-top:   1px solid var(--sc-border);
    background:   var(--sc-bg);
    flex-shrink:  0;
}

#sc-input {
    flex:          1;
    border:        1.5px solid var(--sc-border);
    border-radius: 12px;
    padding:       9px 12px;
    font-size:     14px;
    font-family:   var(--sc-font);
    resize:        none;
    outline:       none;
    line-height:   1.5;
    max-height:    120px;
    overflow-y:    auto;
    transition:    border-color .2s;
    color:         var(--sc-text);
    background:    #f8fafc;
}

#sc-input:focus { border-color: var(--sc-primary); background: #fff; }
#sc-input::placeholder { color: #94a3b8; }

#sc-send {
    width:         40px;
    height:        40px;
    flex-shrink:   0;
    border-radius: 50%;
    background:    var(--sc-primary);
    border:        none;
    cursor:        pointer;
    display:       flex;
    align-items:   center;
    justify-content: center;
    transition:    background .15s, transform .15s;
    outline-offset: 2px;
}

#sc-send:hover   { background: var(--sc-primary-hover); transform: scale(1.06); }
#sc-send:active  { transform: scale(.94); }
#sc-send:disabled { background: #cbd5e1; cursor: not-allowed; transform: none; }

#sc-send svg { width: 17px; height: 17px; color: #fff; }

/* ============================================================
   Footer
   ============================================================ */
#sc-footer {
    padding:     6px 12px 8px;
    text-align:  center;
    font-size:   10px;
    color:       #94a3b8;
    flex-shrink: 0;
    border-top:  1px solid var(--sc-border);
}

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 480px) {
    :root {
        --sc-w:      100vw;
        --sc-h:      calc(100vh - 90px);
        --sc-bottom: 0;
        --sc-side:   0;
        --sc-trigger-size: 56px;
    }

    #site-chatbot-root { bottom: 16px; right: 16px; }
    #sc-window {
        position:      fixed;
        bottom:        0;
        left:          0;
        right:         0;
        width:         100%;
        max-height:    85vh;
        border-radius: var(--sc-radius) var(--sc-radius) 0 0;
    }

    .sc-bubble { max-width: 85%; }
}
