/* ===================================================================
   CHATYLLO — Frontend Chat Widget
   Bulletproof styles — immune to WordPress themes, Elementor,
   Hello Elementor, WooCommerce, and any global CSS resets.
   =================================================================== */

/* ── Root Container & CSS Variables ─────────────────────────────── */
#chatyllo-root {
    --chy-primary:      #4F46E5;
    --chy-primary-dark:  #3730A3;
    --chy-primary-light: #EEF2FF;
    --chy-text:         #1E293B;
    --chy-text-light:   #64748B;
    --chy-bg:           #FFFFFF;
    --chy-bg-alt:       #F8FAFC;
    --chy-border:       #E2E8F0;
    --chy-green:        #10B981;
    --chy-red:          #EF4444;
    --chy-radius:       16px;
    --chy-shadow:       0 25px 50px -12px rgba(0,0,0,.18);
    --chy-bubble-size:  60px;
    --chy-panel-w:      380px;
    --chy-panel-h:      540px;

    position: fixed !important;
    bottom: 24px !important;
    z-index: 99999 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    color: var(--chy-text) !important;
    -webkit-font-smoothing: antialiased !important;
    letter-spacing: 0 !important;
    text-transform: none !important;
    direction: ltr !important;
}

/*
 * Global reset — uses #chatyllo-root for ID-level specificity to
 * defeat Hello Elementor, Elementor, WooCommerce and any theme globals.
 * Component styles use !important to override this reset where needed.
 */
#chatyllo-root *,
#chatyllo-root *::before,
#chatyllo-root *::after {
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    text-transform: none;
    text-decoration: none;
    letter-spacing: 0;
    float: none;
    list-style: none;
    box-sizing: border-box;
    box-shadow: none;
    text-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}

/* Form elements — ID specificity beats theme selectors like
   button, button:not(:disabled), [type="button"], input, textarea */
#chatyllo-root button,
#chatyllo-root textarea,
#chatyllo-root input,
#chatyllo-root select,
#chatyllo-root a {
    border: none;
    background: transparent;
    box-shadow: none;
    appearance: none;
    -webkit-appearance: none;
    text-indent: 0;
    min-height: 0;
    max-width: none;
    cursor: pointer;
}

/* SVG protection — prevent themes from collapsing inline SVGs */
#chatyllo-root svg {
    flex-shrink: 0;
    overflow: visible;
    vertical-align: middle;
}

/* ── Position Classes ───────────────────────────────────────────── */
.chatyllo-position-bottom-right { right: 24px !important; }
.chatyllo-position-bottom-left  { left: 24px !important; }


/* ═══════════════════════════════════════════════════════════════════
   BUBBLE TRIGGER
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-bubble {
    width: var(--chy-bubble-size) !important;
    height: var(--chy-bubble-size) !important;
    border-radius: 50% !important;
    background: var(--chy-primary) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 8px 25px color-mix(in srgb, var(--chy-primary) 35%, transparent) !important;
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), box-shadow .3s !important;
    position: relative !important;
}
.chatyllo-bubble:hover {
    transform: scale(1.1) !important;
    box-shadow: 0 12px 35px color-mix(in srgb, var(--chy-primary) 45%, transparent) !important;
}
.chatyllo-bubble:active { transform: scale(0.95) !important; }

/* Bubble SVG icons */
.chatyllo-bubble svg {
    width: 28px !important;
    min-width: 28px !important;
    height: 28px !important;
    fill: none !important;
    stroke: #fff !important;
    stroke-width: 2 !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
    transition: opacity .2s, transform .3s !important;
    display: block !important;
}
.chatyllo-bubble .chatyllo-icon-close {
    position: absolute !important;
    opacity: 0 !important;
    transform: rotate(-90deg) scale(0.5) !important;
}
.chatyllo-bubble--open .chatyllo-icon-chat {
    opacity: 0 !important;
    transform: rotate(90deg) scale(0.5) !important;
}
.chatyllo-bubble--open .chatyllo-icon-close {
    opacity: 1 !important;
    transform: rotate(0) scale(1) !important;
}

/* Pulse ring animation */
.chatyllo-bubble::after {
    content: '' !important;
    position: absolute !important;
    top: -4px !important;
    right: -4px !important;
    bottom: -4px !important;
    left: -4px !important;
    border-radius: 50% !important;
    border: 2px solid var(--chy-primary) !important;
    opacity: 0 !important;
    animation: chatyllo-ring 3s ease-out infinite !important;
}
.chatyllo-bubble--open::after { display: none !important; }

@keyframes chatyllo-ring {
    0%   { transform: scale(1);   opacity: .6; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* ── AI Status Dot on Bubble ────────────────────────────────────── */
.chatyllo-bubble__status {
    position: absolute !important;
    top: 2px !important;
    right: 2px !important;
    width: 14px !important;
    height: 14px !important;
    border-radius: 50% !important;
    border: 2px solid #fff !important;
    z-index: 1 !important;
}
.chatyllo-bubble__status--active   { background: var(--chy-green) !important; }
.chatyllo-bubble__status--inactive { background: var(--chy-red) !important; }


/* ═══════════════════════════════════════════════════════════════════
   CHAT PANEL
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-panel {
    position: absolute !important;
    bottom: calc(var(--chy-bubble-size) + 16px) !important;
    width: var(--chy-panel-w) !important;
    height: var(--chy-panel-h) !important;
    max-height: 80vh !important;
    background: var(--chy-bg) !important;
    border-radius: var(--chy-radius) !important;
    box-shadow: var(--chy-shadow) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    transform: scale(0.6) translateY(20px) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transform-origin: bottom right !important;
    transition: transform .35s cubic-bezier(.34,1.56,.64,1), opacity .25s !important;
    border: 1px solid rgba(0,0,0,.08) !important;
}
.chatyllo-position-bottom-left .chatyllo-panel {
    right: auto !important;
    left: 0 !important;
    transform-origin: bottom left !important;
}
.chatyllo-position-bottom-right .chatyllo-panel {
    right: 0 !important;
}

/* Panel OPEN state — must override the closed state above */
.chatyllo-panel--open {
    transform: scale(1) translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}


/* ═══════════════════════════════════════════════════════════════════
   PANEL HEADER
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-header {
    background: var(--chy-primary) !important;
    color: #fff !important;
    padding: 16px 18px !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    flex-shrink: 0 !important;
    min-height: 68px !important;
    border-radius: var(--chy-radius) var(--chy-radius) 0 0 !important;
}
.chatyllo-header__avatar {
    width: 42px !important;
    height: 42px !important;
    border-radius: 50% !important;
    background: rgba(255,255,255,.2) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 22px !important;
    flex-shrink: 0 !important;
    overflow: hidden !important;
    line-height: 1 !important;
}
.chatyllo-header__avatar img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 50% !important;
}
.chatyllo-header__info {
    flex: 1 !important;
    min-width: 0 !important;
}
.chatyllo-header__name {
    font-size: 16px !important;
    font-weight: 700 !important;
    line-height: 1.2 !important;
    color: #fff !important;
}
.chatyllo-header__status {
    font-size: 12px !important;
    opacity: .85 !important;
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    margin-top: 2px !important;
    color: #fff !important;
}
.chatyllo-header__status-dot {
    width: 8px !important;
    height: 8px !important;
    border-radius: 50% !important;
    display: inline-block !important;
    flex-shrink: 0 !important;
}
.chatyllo-header__status-dot--active   { background: #34D399 !important; }
.chatyllo-header__status-dot--inactive { background: #FCA5A5 !important; }

.chatyllo-header__actions {
    display: flex !important;
    gap: 6px !important;
}
.chatyllo-header__btn {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    background: rgba(255,255,255,.15) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background .2s !important;
}
.chatyllo-header__btn:hover { background: rgba(255,255,255,.3) !important; }
.chatyllo-header__btn svg {
    width: 16px !important;
    min-width: 16px !important;
    height: 16px !important;
    stroke: #fff !important;
    fill: none !important;
    stroke-width: 2 !important;
    display: block !important;
}


/* ═══════════════════════════════════════════════════════════════════
   MESSAGES AREA
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-messages {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 20px 16px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 14px !important;
    background: var(--chy-bg-alt) !important;
}
.chatyllo-messages::-webkit-scrollbar       { width: 5px !important; }
.chatyllo-messages::-webkit-scrollbar-track { background: transparent !important; }
.chatyllo-messages::-webkit-scrollbar-thumb { background: var(--chy-border) !important; border-radius: 4px !important; }


/* ═══════════════════════════════════════════════════════════════════
   MESSAGE BUBBLES
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-msg {
    max-width: 85% !important;
    display: flex !important;
    flex-direction: column !important;
    animation: chatyllo-msg-in .3s ease-out !important;
}
.chatyllo-msg--bot  { align-self: flex-start !important; }
.chatyllo-msg--user { align-self: flex-end !important; }

.chatyllo-msg__bubble {
    padding: 12px 16px !important;
    border-radius: 16px !important;
    font-size: 14px !important;
    line-height: 1.55 !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
}
.chatyllo-msg--bot .chatyllo-msg__bubble {
    background: var(--chy-bg) !important;
    color: var(--chy-text) !important;
    border: 1px solid var(--chy-border) !important;
    border-bottom-left-radius: 4px !important;
}
.chatyllo-msg--user .chatyllo-msg__bubble {
    background: var(--chy-primary) !important;
    color: #fff !important;
    border-bottom-right-radius: 4px !important;
}

/* Links and code inside message bubbles */
.chatyllo-msg__bubble a {
    color: inherit !important;
    text-decoration: underline !important;
}
.chatyllo-msg__bubble code {
    background: rgba(0,0,0,.06) !important;
    padding: 1px 5px !important;
    border-radius: 4px !important;
    font-size: 13px !important;
    font-family: "SF Mono", "Fira Code", Consolas, monospace !important;
}

.chatyllo-msg__time {
    font-size: 11px !important;
    color: var(--chy-text-light) !important;
    margin-top: 4px !important;
    padding: 0 4px !important;
}
.chatyllo-msg--user .chatyllo-msg__time { text-align: right !important; }

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


/* ═══════════════════════════════════════════════════════════════════
   TYPING INDICATOR
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-typing {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 12px 16px !important;
    background: var(--chy-bg) !important;
    border: 1px solid var(--chy-border) !important;
    border-radius: 14px !important;
    border-bottom-left-radius: 4px !important;
    align-self: flex-start !important;
    max-width: 80px !important;
}
.chatyllo-typing__dot {
    width: 7px !important;
    height: 7px !important;
    border-radius: 50% !important;
    background: var(--chy-text-light) !important;
    animation: chatyllo-typing-bounce .8s ease-in-out infinite !important;
}
.chatyllo-typing__dot:nth-child(2) { animation-delay: .15s !important; }
.chatyllo-typing__dot:nth-child(3) { animation-delay: .3s !important; }

@keyframes chatyllo-typing-bounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: .4; }
    40%           { transform: translateY(-5px);  opacity: 1; }
}


/* ═══════════════════════════════════════════════════════════════════
   INPUT AREA
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-input {
    display: flex !important;
    align-items: flex-end !important;
    gap: 10px !important;
    padding: 14px 16px !important;
    border-top: 1px solid var(--chy-border) !important;
    background: var(--chy-bg) !important;
    flex-shrink: 0 !important;
}
.chatyllo-input__field {
    flex: 1 !important;
    border: 1.5px solid var(--chy-border) !important;
    border-radius: 12px !important;
    padding: 10px 14px !important;
    font-size: 14px !important;
    resize: none !important;
    max-height: 80px !important;
    overflow: hidden !important;
    color: var(--chy-text) !important;
    line-height: 1.4 !important;
    background: var(--chy-bg-alt) !important;
    transition: border-color .2s, box-shadow .2s !important;
}
.chatyllo-input__field:focus {
    border-color: var(--chy-primary) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--chy-primary) 10%, transparent) !important;
}
.chatyllo-input__field::placeholder {
    color: var(--chy-text-light) !important;
    opacity: 1 !important;
}

.chatyllo-input__send {
    width: 42px !important;
    height: 42px !important;
    border-radius: 50% !important;
    background: var(--chy-primary) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    transition: background .2s, transform .15s !important;
}
.chatyllo-input__send:hover  { background: var(--chy-primary-dark) !important; }
.chatyllo-input__send:active { transform: scale(0.9) !important; }
.chatyllo-input__send:disabled { opacity: .5 !important; cursor: not-allowed !important; }
.chatyllo-input__send svg {
    width: 18px !important;
    min-width: 18px !important;
    height: 18px !important;
    fill: #fff !important;
    stroke: none !important;
    display: block !important;
}


/* ═══════════════════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════════════════ */
.chatyllo-footer {
    padding: 8px 16px 10px !important;
    text-align: center !important;
    font-size: 11px !important;
    color: var(--chy-text-light) !important;
    border-top: 1px solid var(--chy-border) !important;
    background: var(--chy-bg) !important;
    flex-shrink: 0 !important;
}
.chatyllo-footer a {
    color: var(--chy-primary) !important;
    font-weight: 600 !important;
}
.chatyllo-footer a:hover { text-decoration: underline !important; }


/* ═══════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    #chatyllo-root { bottom: 16px !important; }
    #chatyllo-root.chatyllo-position-bottom-right { right: 16px !important; }
    #chatyllo-root.chatyllo-position-bottom-left  { left: 16px !important; }

    .chatyllo-panel {
        width: calc(100vw - 32px) !important;
        height: calc(100vh - 120px) !important;
        max-height: calc(100vh - 120px) !important;
    }
    .chatyllo-position-bottom-right .chatyllo-panel { right: 0 !important; }
    .chatyllo-position-bottom-left .chatyllo-panel  { left: 0 !important; right: auto !important; }
}
