/* ============================================================
   Starline AI Chatbot — Frontend Widget CSS
   ============================================================ */

:root {
    --sl-primary:    #1a6ed8;
    --sl-primary-dk: #155bbf;
    --sl-radius:     16px;
    --sl-shadow:     0 8px 40px rgba(0,0,0,.18);
    --sl-font:       -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --sl-bg:         #ffffff;
    --sl-bg2:        #f4f7fb;
    --sl-text:       #1a1a2e;
    --sl-text-muted: #6b7280;
    --sl-border:     #e5e7eb;
    --sl-bot-bubble: #f0f4ff;
    --sl-user-bubble: var(--sl-primary);
    --sl-w:          370px;
    --sl-h:          540px;
}

/* ---- Toggle button ---- */
#starline-toggle {
    position:       fixed;
    bottom:         24px;
    right:          24px;
    width:          58px;
    height:         58px;
    border-radius:  50%;
    background:     var(--sl-primary);
    color:          #fff;
    border:         none;
    cursor:         pointer;
    display:        flex;
    align-items:    center;
    justify-content:center;
    box-shadow:     var(--sl-shadow);
    z-index:        999999;
    transition:     transform .2s, background .2s;
}
#starline-toggle:hover  { background: var(--sl-primary-dk); transform: scale(1.07); }
#starline-toggle:active { transform: scale(.95); }

#starline-unread-badge {
    position:    absolute;
    top: 2px; right: 2px;
    width: 18px; height: 18px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--sl-font);
}

/* ---- Chat box ---- */
#starline-chat-box {
    position:      fixed;
    bottom:        92px;
    right:         24px;
    width:         var(--sl-w);
    max-width:     calc(100vw - 32px);
    height:        var(--sl-h);
    max-height:    calc(100vh - 110px);
    background:    var(--sl-bg);
    border-radius: var(--sl-radius);
    box-shadow:    var(--sl-shadow);
    display:       flex;
    flex-direction:column;
    z-index:       999998;
    overflow:      hidden;
    font-family:   var(--sl-font);
    animation:     slSlideIn .25s ease;
}

@keyframes slSlideIn {
    from { opacity:0; transform: translateY(16px) scale(.97); }
    to   { opacity:1; transform: translateY(0) scale(1); }
}

/* ---- Header ---- */
#starline-header {
    background:    var(--sl-primary);
    color:         #fff;
    padding:       14px 16px;
    display:       flex;
    align-items:   center;
    gap:           10px;
    flex-shrink:   0;
}
#starline-header-avatar {
    width:  38px; height: 38px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
#starline-header-name   { font-size:15px; font-weight:600; }
#starline-header-status { font-size:11px; opacity:.85; margin-top:1px; }
#starline-close-btn {
    margin-left: auto;
    background: none; border: none; color: #fff;
    font-size: 18px; cursor: pointer; padding: 0;
    opacity: .8; line-height: 1;
}
#starline-close-btn:hover { opacity: 1; }

/* ---- Messages ---- */
#starline-messages {
    flex:       1;
    overflow-y: auto;
    padding:    16px 14px;
    display:    flex;
    flex-direction: column;
    gap:        10px;
    background: var(--sl-bg2);
    scroll-behavior: smooth;
}
#starline-messages::-webkit-scrollbar { width: 4px; }
#starline-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.sl-bubble-wrap {
    display:    flex;
    align-items:flex-end;
    gap:        7px;
    max-width:  88%;
}
.sl-bubble-wrap.sl-bot  { align-self: flex-start; }
.sl-bubble-wrap.sl-user { align-self: flex-end; flex-direction: row-reverse; }

.sl-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--sl-primary);
    color: #fff;
    font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.sl-bubble {
    padding:       10px 13px;
    border-radius: 14px;
    font-size:     14px;
    line-height:   1.55;
    color:         var(--sl-text);
    white-space:   pre-wrap;
    word-break:    break-word;
}
.sl-bot  .sl-bubble {
    background:    var(--sl-bot-bubble);
    border-bottom-left-radius: 4px;
}
.sl-user .sl-bubble {
    background:    var(--sl-user-bubble);
    color:         #fff;
    border-bottom-right-radius: 4px;
}

/* Typing animation */
.sl-typing {
    display: flex; align-items: center; gap: 5px;
    padding: 10px 14px;
    background: var(--sl-bot-bubble);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}
.sl-dot {
    width: 7px; height: 7px;
    background: var(--sl-primary);
    border-radius: 50%;
    animation: slBounce 1.2s infinite ease-in-out;
    opacity: .7;
}
.sl-dot:nth-child(2) { animation-delay: .2s; }
.sl-dot:nth-child(3) { animation-delay: .4s; }
@keyframes slBounce {
    0%,80%,100% { transform: translateY(0); }
    40%          { transform: translateY(-6px); }
}

/* ---- Lead form ---- */
#starline-lead-form {
    padding:    12px 14px;
    background: #fffbeb;
    border-top: 1px solid #fde68a;
    flex-shrink: 0;
}
#starline-lead-intro {
    font-size:   13px;
    color:       #92400e;
    margin:      0 0 10px;
    font-weight: 500;
}
#starline-lead-form input {
    width:         100%;
    padding:       8px 10px;
    margin-bottom: 7px;
    border:        1px solid #d1d5db;
    border-radius: 8px;
    font-size:     13px;
    font-family:   var(--sl-font);
    box-sizing:    border-box;
    outline:       none;
    transition:    border .15s;
}
#starline-lead-form input:focus { border-color: var(--sl-primary); }
.sl-btn-primary {
    padding: 8px 16px; background: var(--sl-primary); color: #fff;
    border: none; border-radius: 8px; font-size: 13px; cursor: pointer;
    font-family: var(--sl-font); transition: background .15s;
}
.sl-btn-primary:hover { background: var(--sl-primary-dk); }
.sl-btn-ghost {
    padding: 8px 12px; background: none; color: var(--sl-text-muted);
    border: 1px solid var(--sl-border); border-radius: 8px;
    font-size: 13px; cursor: pointer; font-family: var(--sl-font);
}
.sl-btn-ghost:hover { background: #f3f4f6; }

/* ---- Input row ---- */
#starline-input-row {
    display:    flex;
    align-items:flex-end;
    gap:        8px;
    padding:    10px 12px;
    border-top: 1px solid var(--sl-border);
    background: var(--sl-bg);
    flex-shrink:0;
}
#starline-input {
    flex:        1;
    border:      1px solid var(--sl-border);
    border-radius: 10px;
    padding:     9px 12px;
    font-size:   14px;
    font-family: var(--sl-font);
    resize:      none;
    outline:     none;
    max-height:  110px;
    overflow-y:  auto;
    line-height: 1.5;
    transition:  border .15s;
}
#starline-input:focus { border-color: var(--sl-primary); }
#starline-send {
    width:  38px; height: 38px;
    border-radius: 10px;
    background: var(--sl-primary);
    border: none; color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}
#starline-send:hover  { background: var(--sl-primary-dk); }
#starline-send:active { transform: scale(.93); }
#starline-send:disabled { background: #9ca3af; cursor: default; }

#starline-footer {
    text-align: center;
    font-size:  10px;
    color:      var(--sl-text-muted);
    padding:    4px 0 6px;
    background: var(--sl-bg);
    flex-shrink:0;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
    #starline-chat-box {
        bottom: 0; right: 0;
        width:  100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
    #starline-toggle {
        bottom: 16px; right: 16px;
        width: 52px; height: 52px;
    }
}

/* Required field asterisk color */
#starline-lead-form input:required {
    border-left: 3px solid var(--sl-primary);
}
#starline-lead-form input:required:valid {
    border-left: 3px solid #10b981;
}
#starline-lead-form input:invalid:not(:placeholder-shown) {
    border-left: 3px solid #ef4444;
}
