/* ==========================================================================
   AI Chat Widget — Stylesheet v2
   ========================================================================== */

#aicw-root {
    --aicw-primary:     #004280;
    --aicw-header-bg:   #004280;
    --aicw-header-tx:   #ffffff;
    --aicw-user-bg:     #004280;
    --aicw-user-tx:     #ffffff;
    --aicw-bot-bg:      #f0f0f9;
    --aicw-bot-tx:      #1a1b2e;
    --aicw-surface:     #ffffff;
    --aicw-surface-alt: #f5f5fb;
    --aicw-border:      #e2e3ef;
    --aicw-text:        #1a1b2e;
    --aicw-muted:       #5d6575;
    --aicw-shadow:      0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
    --aicw-radius:      16px;
    --aicw-z:           99999;
    --aicw-w:           360px;
    --aicw-h:           540px;
    --aicw-btn:         60px;

    font-family: 'Manrope', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--aicw-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;

    /* ✅ KEY FIX: root takes no space — only its visible children are clickable */
    width: fit-content;
    height: fit-content;
    pointer-events: none; /* ✅ root itself never blocks clicks */
}

/* ✅ Only interactive children receive pointer events */
#aicw-root > *,
#aicw-root .aicw-window,
#aicw-root .aicw-window * {
    pointer-events: auto;
}

/* Hidden window must NOT intercept clicks */
.aicw-window {
    pointer-events: none !important;
}
#aicw-root.aicw-open .aicw-window {
    pointer-events: auto !important;
}

/* Hidden teaser must NOT intercept clicks */
.aicw-window {
    visibility: hidden;
    pointer-events: none;
}

#aicw-root.aicw-open .aicw-window {
    visibility: visible;
    pointer-events: auto;
	z-index:9999;
}

/* ── Launcher ─────────────────────────────────────────────────────────────── */
#aicw-launcher {
    width:  var(--aicw-btn);
    height: var(--aicw-btn);
    border-radius: 50%;
    border: none;
    background: var(--aicw-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px rgba(0,0,0,.25);
    transition: transform .2s, box-shadow .2s;
    position: relative;
    flex-shrink: 0;
    order: 2;
    pointer-events: auto;
}

#aicw-launcher {z-index:9999;}
#aicw-launcher:hover  { transform: scale(1.08); box-shadow: 0 6px 24px rgba(0,0,0,.30); }
#aicw-launcher:active { transform: scale(.95); }
#aicw-launcher:focus-visible { outline: 3px solid var(--aicw-primary); outline-offset: 3px; }

/* Icon swap */
.aicw-icon-chat,
.aicw-icon-close {
    position: absolute;
    transition: opacity .18s, transform .2s;
}
.aicw-icon-chat  { width: 46px; height: 46px; opacity: 1; transform: scale(1) rotate(0deg); }
.aicw-icon-close { width: 26px; height: 26px;            opacity: 0; transform: scale(.5) rotate(-45deg); }

#aicw-root.aicw-open .aicw-icon-chat  { opacity: 0; transform: scale(.5) rotate(45deg); }
#aicw-root.aicw-open .aicw-icon-close { opacity: 1; transform: scale(1)  rotate(0deg); }

/* Badge */
.aicw-badge {
    position: absolute;
    top: -8px; right: 0;
    min-width: 20px; height: 20px;
    border-radius: 16px;
    background:#c81111;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    padding: 0 4px;
    border: 2px solid #fff;
    transition: opacity .2s, transform .2s;
    animation: aicw-pulse 2s ease-in-out infinite;
}
#aicw-root.aicw-open .aicw-badge { opacity: 0; transform: scale(0); pointer-events: none; }

@keyframes aicw-pulse {
    0%, 100% { box-shadow: 0 0 0 0   rgba(239,68,68,.5); }
    50%       { box-shadow: 0 0 0 5px rgba(239,68,68,0); }
}

/* ── Teaser ──────────────────────────────────────────────────────────────── */
.aicw-teaser {
    order: 1;
    display: none;
    position: relative;
    background: var(--aicw-surface);
    border: 1px solid var(--aicw-border);
    border-radius: 12px 12px 4px 12px;
    padding: 12px 36px 12px 14px;
    max-width: 460px;
    box-shadow: 0 4px 20px rgba(0,0,0,.13);
    cursor: pointer;
    color: var(--aicw-text);
    font-size: 13.5px;
    line-height: 1.5;
    opacity: 0;
    transform: translateY(10px) scale(.95);
    transition: opacity .3s ease, transform .3s ease;
}
.aicw-teaser::after {
    content: '';
    position: absolute;
    bottom: -8px; right: 18px;
    width: 14px; height: 14px;
    background: var(--aicw-surface);
    border-right: 1px solid var(--aicw-border);
    border-bottom: 1px solid var(--aicw-border);
    transform: rotate(45deg);
}
.aicw-teaser.aicw--visible {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.aicw-teaser-close {
    position: absolute;
    top: 6px; right: 7px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--aicw-muted);
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
}
.aicw-teaser-close:hover { color: var(--aicw-text); background: var(--aicw-surface-alt); }

#aicw-teaser-text { font-size: 1rem; margin-bottom:0.5rem; }
#aicw-teaser-link { font-size: 1rem; }

/* ── Chat window ─────────────────────────────────────────────────────────── */
.aicw-window {
    order: 0;
    width:  var(--aicw-w);
    height: var(--aicw-h);
    background: var(--aicw-surface);
    border-radius: var(--aicw-radius);
    border: 1px solid var(--aicw-border);
    box-shadow: var(--aicw-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.97);
    transform-origin: bottom right;
    transition: opacity .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
    /* pointer-events managed above */
}
#aicw-root.aicw-open .aicw-window {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.aicw-header {
    background: var(--aicw-header-bg);
    color: var(--aicw-header-tx);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.aicw-header-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.aicw-avatar svg {
    width: 14px;
    height: 14px;
    fill: var(--aicw-muted);
}


.aicw-header-avatar svg { width: 18px; height: 18px; fill: currentColor; }
.aicw-header-info  { flex: 1; display: flex; flex-direction: column; gap: 1px; overflow: hidden; }
.aicw-header-name  { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aicw-header-status { display: flex; align-items: center; gap: 5px; font-size: 11px; opacity: .85; }
.aicw-status-dot   { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; flex-shrink: 0; }

.aicw-header-btn {
    background: none; border: none;
    color: var(--aicw-header-tx);
    opacity: .75;
    cursor: pointer; padding: 4px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    transition: opacity .15s, background .15s;
    flex-shrink: 0;
}
.aicw-header-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.aicw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--aicw-surface-alt);
    scroll-behavior: smooth;
}
.aicw-messages::-webkit-scrollbar { width: 4px; }
.aicw-messages::-webkit-scrollbar-thumb { background: var(--aicw-border); border-radius: 4px; }

.aicw-messages .aicw-teaser-link {display:block;margin-top:6px;}

/* ── Bubble rows ─────────────────────────────────────────────────────────── */
.aicw-row { display: flex; gap: 7px; align-items: flex-end; animation: aicw-in .18s ease; }
.aicw-row.aicw-bot  { flex-direction: row; }
.aicw-row.aicw-user { flex-direction: row; justify-content: flex-end;}

@keyframes aicw-in {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

.aicw-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 13px;
}
.aicw-row.aicw-bot  .aicw-avatar { background: var(--aicw-primary); }
.aicw-row.aicw-bot  .aicw-avatar svg { width: 14px; height: 14px; fill: #fff; }
.aicw-row.aicw-user .aicw-avatar { background: var(--aicw-surface); border: 1px solid var(--aicw-border); }

.aicw-col { display: flex; flex-direction: column; max-width: 80%; }
.aicw-row.aicw-user .aicw-col { align-items: flex-end; }

.aicw-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 16px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
.aicw-bubble a { color: var(--aicw-primary) !important; text-decoration: underline; font-weight: 600; }
.aicw-bubble a:hover { opacity: .8; }

.aicw-row.aicw-bot  .aicw-bubble { background: var(--aicw-bot-bg); color: var(--aicw-bot-tx); border-bottom-left-radius:  3px; }
.aicw-row.aicw-user .aicw-bubble { background: var(--aicw-user-bg); color: var(--aicw-user-tx); border-bottom-right-radius: 3px; }

.aicw-ts { font-size: 14px; color: var(--aicw-muted); margin-top: 3px; padding: 0 2px; }

/* Typing dots */
.aicw-typing .aicw-bubble { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.aicw-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--aicw-muted); animation: aicw-bounce .9s infinite; }
.aicw-dot:nth-child(2) { animation-delay: .15s; }
.aicw-dot:nth-child(3) { animation-delay: .30s; }
@keyframes aicw-bounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: .5; }
    40%           { transform: translateY(-5px); opacity: 1; }
}


/* ── Overlay ──────────────────────────────────────────────────────────── */
#aicw-root::before {
    content: '';
    position: fixed;
    inset: 0;
background: rgba(0, 0, 0, 0.2);
backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 9998; /* под прозореца */
    pointer-events: none;
	
	
}

#aicw-root.aicw-open::before {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* клик върху overlay затваря чата */
}

/* Streaming cursor */
.aicw-streaming .aicw-bubble::after,
.aicw-row.aicw-streaming .aicw-bubble::after {
    content: '▋';
    display: inline-block;
    animation: aicw-blink .7s step-start infinite;
    margin-left: 1px;
    opacity: .8;
}
@keyframes aicw-blink {
    0%, 100% { opacity: .8; }
    50%       { opacity: 0; }
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.aicw-input-area {
    padding: 10px 12px 12px;
    border-top: 1px solid var(--aicw-border);
    background: var(--aicw-surface);
    flex-shrink: 0;
}
.aicw-textarea-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--aicw-surface-alt);
    border: 1.5px solid var(--aicw-border);
    border-radius: 12px;
    padding: 7px 7px 7px 12px;
    transition: border-color .2s, box-shadow .2s;
    font-size: 16px;
}
.aicw-textarea-wrap:focus-within {
    border-color: var(--aicw-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--aicw-primary) 15%, transparent);
}
.aicw-textarea {
    flex: 1; background: none; border: none; outline: none;
    resize: none; font-family: inherit; font-size: 16px;
    color: var(--aicw-text) !important; line-height: 1.5; 
	font-weight:500;
    max-height: 110px; overflow-y: auto; padding: 0;
}
.aicw-textarea::placeholder { color: var(--aicw-muted); font-size: 16px; }

.aicw-send-btn {
    width: 38px; height: 38px;
    border-radius: 50%; border: none;
    background: var(--aicw-primary); color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: filter .2s, transform .15s;
}
.aicw-send-btn svg    { width: 16px; height: 16px; }
.aicw-send-btn:hover  { filter: brightness(1.1); }
.aicw-send-btn:active { transform: scale(.9); }
.aicw-send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.aicw-hint {
    font-size: 14px;
    color: var(--aicw-muted);
    text-align: center;
    margin-top: 8px;
    margin-bottom: 2px;
}

.aicw-textarea,
.aicw-textarea::placeholder {
    font-size: 16px !important;
}

/* ── History separator ───────────────────────────────────────────────────── */
.aicw-separator {
    text-align: center;
    font-size: 10.5px;
    color: var(--aicw-muted);
    padding: 4px 10px;
    position: relative;
    margin: 4px 0;
}
.aicw-separator::before,
.aicw-separator::after {
    content: '';
    position: absolute;
    top: 50%; width: 18%; height: 1px;
    background: var(--aicw-border);
}
.aicw-separator::before { left: 0; }
.aicw-separator::after  { right: 0; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
      #aicw-root {
        bottom: 14px;
        right: 14px;
    }

    .aicw-window {
        width:  calc(100vw - 28px);
        /* ✅ max-height вместо height — не расте повече от viewport */
        max-height: calc(100dvh - 100px);
        height: 520px; /* default height — клавиатурата го свива автоматично */
        border-radius: 14px;
        /* ✅ Прозорецът не излиза извън екрана */
        overflow: hidden;
    }

    .aicw-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .aicw-input-area {
        position: sticky;
        bottom: 0;
        background: var(--aicw-surface);
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        /* ✅ Без blur/transparency */
        opacity: 1;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .aicw-teaser {
        max-width: calc(100vw - 90px);
    }
}