/* =============================================================
   AI ASISTENT — izgled widgeta (launcher, panel, poruke)
   Do sada je stajao kao inline <style> u partialu, dakle ~9 KB koji se
   ni jednom nisu keširali i parsirali su se pri svakoj navigaciji.
   ============================================================= */

/* ── Varijable ── */
:root {
    --ai-primary:       #2563eb;
    --ai-primary-hover: #1d4ed8;
    --ai-bot-bubble:    #f1f5f9;
    --ai-user-bubble:   #2563eb;
    --ai-panel-bg:      #ffffff;
    --ai-shadow:        0 8px 32px rgba(0,0,0,0.15);
    --ai-radius:        16px;
    --ai-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Tamna tema (prati globalni html.dark iz core.css) ──
   Preko tokena, a ne fiksnih boja: paleta je bila prepisana ručno, pa je
   posle produbljivanja tamne teme panel asistenta ostajao svetliji od
   stranice. Ovako prati paletu sam. */
html.dark {
    --ai-bot-bubble: var(--surface-hover);
    --ai-panel-bg:   var(--surface);
    --ai-shadow:     0 8px 32px rgba(0,0,0,0.55);
}
html.dark .ai-msg--bot .ai-msg__bubble { color: var(--text); }
html.dark .ai-msg--error .ai-msg__bubble { background: #7f1d1d; color: #fecaca; }
html.dark #ai-chat-input-area { border-top-color: var(--border); }
html.dark #ai-chat-input {
    background: var(--surface-subtle);
    color: var(--text);
    border-color: var(--border);
}
html.dark #ai-chat-input::placeholder { color: var(--text-faint); }
html.dark #ai-typing-indicator { color: var(--text-subtle); }

/* ── Gašenje uz otvoren dijalog / modal ──
   Launcher i panel stoje na z-index 9998/9999, iznad svakog overlay-a u
   aplikaciji (modali 1000–2000, potvrda 9998), pa su ostajali oštri i
   klikabilni dok je ostatak stranice zatamnjen — na uskim ekranima su čak
   prekrivali dugmad dijaloga. Uz otvoren dijalog widget prati sudbinu
   ostatka stranice: mutan je i ne prima klikove.
   `:has()` je namerno na <body> — nema centralnog mesta koje otvara sve
   modale (svaki ekran ih pali svojom klasom), pa se stanja nabrajaju. */
body:has(.confirm-overlay.is-open) #ai-chat-launcher,
body:has(.confirm-overlay.is-open) #ai-chat-panel,
body:has(.modal.active) #ai-chat-launcher,
body:has(.modal.active) #ai-chat-panel,
body:has(.primerci-modal.is-open) #ai-chat-launcher,
body:has(.primerci-modal.is-open) #ai-chat-panel,
body:has(.mobile-nav-drawer.open) #ai-chat-launcher,
body:has(.mobile-nav-drawer.open) #ai-chat-panel {
    /* Ispod svakog overlay-a (najniži je 1000), pa widget dobija i
       zatamnjenje same podloge dijaloga, a ne samo sopstveni blur. */
    z-index: 900;
    filter: blur(3px);
    opacity: 0.55;
    pointer-events: none;
    user-select: none;
}

/* ── Launcher container ── */
#ai-chat-launcher {
    position: fixed;
    bottom:   24px;
    right:    24px;
    z-index:  9998;
    display:  flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

/* ── Invite dugme (tekstualno) ── */
#ai-chat-invite {
    display:         flex;
    align-items:     center;
    gap:             8px;
    padding:         12px 18px;
    background:      var(--ai-primary);
    color:           white;
    border:          none;
    border-radius:   24px;
    cursor:          pointer;
    font-family:     var(--ai-font);
    font-size:       14px;
    font-weight:     500;
    box-shadow:      var(--ai-shadow);
    transition:      transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    white-space:     nowrap;
    max-width:       260px;
}
#ai-chat-invite:hover {
    background: var(--ai-primary-hover);
    transform:  translateY(-2px);
}
/* Animacija pojave invite dugmeta */
@keyframes ai-invite-in {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}
#ai-chat-invite {
    animation: ai-invite-in 0.4s ease 0.8s both; /* delay 0.8s da ne smeta odmah */
}

/* ── Chat panel ── */
#ai-chat-panel {
    position:        fixed;
    bottom:          24px;
    right:           24px;
    z-index:         9999;
    width:           370px;
    max-height:      560px;
    display:         flex;
    flex-direction:  column;
    background:      var(--ai-panel-bg);
    border-radius:   var(--ai-radius);
    box-shadow:      var(--ai-shadow);
    font-family:     var(--ai-font);
    font-size:       14px;
    overflow:        hidden;
    transform-origin: bottom right;
    animation:       ai-panel-in 0.25s ease;
}
#ai-chat-panel[hidden] { display: none; }

@keyframes ai-panel-in {
    from { opacity: 0; transform: scale(0.92) translateY(12px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* ── Responsive ── */
@media (max-width: 480px) {
    #ai-chat-launcher {
        bottom: 12px;
        right:  12px;
    }
    #ai-chat-panel {
        width:      calc(100vw - 24px);
        max-height: calc(100dvh - 100px); /* dvh = dynamic viewport height, ispravno na mobilnom */
        right:      12px;
        bottom:     16px;
        border-radius: 12px;
    }
    /* Na mobilnom je launcher MALO, okruglo dugme sa ikonicom — dovoljno
       veliko za dodir palcem (52px ≥ 44px preporučenog minimuma), a ne
       zauzima ekran kao tekstualna pilula. */
    #ai-chat-invite {
        width:           52px;
        height:          52px;
        padding:         0;
        border-radius:   50%;
        justify-content: center;
    }
    #ai-chat-invite svg {
        width:  24px;
        height: 24px;
    }
    #ai-invite-text { display: none; }
}

/* ── Header ── */
#ai-chat-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         14px 16px;
    background:      var(--ai-primary);
    color:           white;
    flex-shrink:     0;
}
#ai-chat-header-info { display: flex; align-items: center; gap: 10px; }
#ai-chat-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px;
}
#ai-chat-name   { font-weight: 600; font-size: 15px; }
#ai-chat-status { display: flex; align-items: center; gap: 5px; font-size: 12px; opacity: 0.85; }
#ai-status-dot  { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }
#ai-chat-close  { background: none; border: none; color: white; cursor: pointer; padding: 4px; opacity: 0.8; }
#ai-chat-close:hover { opacity: 1; }

/* ── Poruke ── */
#ai-chat-messages {
    flex:            1;
    overflow-y:      auto;
    padding:         16px;
    display:         flex;
    flex-direction:  column;
    gap:             12px;
    scroll-behavior: smooth;
}
.ai-msg       { display: flex; }
.ai-msg--user { justify-content: flex-end; }
.ai-msg--bot  { justify-content: flex-start; }
.ai-msg__bubble {
    max-width:     80%;
    padding:       10px 14px;
    border-radius: 18px;
    line-height:   1.5;
    word-break:    break-word;
}
.ai-msg--user .ai-msg__bubble {
    background:                 var(--ai-user-bubble);
    color:                      white;
    border-bottom-right-radius: 4px;
}
.ai-msg--bot .ai-msg__bubble {
    background:                var(--ai-bot-bubble);
    color:                     #1e293b;
    border-bottom-left-radius: 4px;
}
.ai-msg--error .ai-msg__bubble {
    background: #fee2e2;
    color:      #991b1b;
}

/* ── Typing indicator (tri tačke u mehuriću, kao u aplikacijama za poruke) ── */
#ai-typing-indicator {
    display:     flex;
    align-items: center;
    padding:     4px 16px 8px;
    flex-shrink: 0;
}
#ai-typing-indicator[hidden] { display: none; }

.ai-typing-bubble {
    display:                    inline-flex;
    align-items:                center;
    gap:                        4px;
    padding:                    10px 14px;
    background:                 var(--ai-bot-bubble);
    border-radius:              18px;
    border-bottom-left-radius:  4px;
}

.ai-typing-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #94a3b8;
    animation:  ai-bounce 1.2s infinite;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); }
}

/* ── Input area ── */
#ai-chat-input-area {
    display:     flex;
    align-items: flex-end;
    gap:         8px;
    padding:     12px 16px;
    border-top:  1px solid #e2e8f0;
    flex-shrink: 0;
}
#ai-chat-input {
    flex:          1;
    border:        1px solid #cbd5e1;
    border-radius: 12px;
    padding:       9px 12px;
    font-size:     14px;
    font-family:   inherit;
    resize:        none;
    outline:       none;
    max-height:    120px;
    overflow-y:    auto;
    line-height:   1.5;
    transition:    border-color 0.2s;
}
#ai-chat-input:focus { border-color: var(--ai-primary); }

#ai-chat-send {
    width:           38px;
    height:          38px;
    border-radius:   50%;
    background:      var(--ai-primary);
    color:           white;
    border:          none;
    cursor:          pointer;
    flex-shrink:     0;
    display:         flex;
    align-items:     center;
    justify-content: center;
    transition:      background 0.2s, opacity 0.2s;
}
#ai-chat-send:disabled            { opacity: 0.4; cursor: not-allowed; }
#ai-chat-send:not(:disabled):hover { background: var(--ai-primary-hover); }
