/**
 * iLogist — Live Chat Widget
 *
 * Плаваюча модалка над усім сайтом. Drag на desktop, fixed на mobile.
 * Стиль — мобільний месенджер (bubble messages, iLogist brand).
 */

/* ============================================================
   КОНТЕЙНЕР МОДАЛКИ
============================================================ */
.ilg-chat {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 360px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    font-family: 'Poppins', sans-serif;
}

.ilg-chat.is-open {
    display: flex;
    animation: ilg-chat-slide-in 0.25s ease-out;
}

@keyframes ilg-chat-slide-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   ЗАГОЛОВОК (drag handle)
============================================================ */
.ilg-chat__header {
    background: linear-gradient(135deg, #14213d 0%, #1e3a5f 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
}

.ilg-chat__header:active { cursor: grabbing; }

/* Indicator що це drag handle (тільки desktop) */
@media (min-width: 768px) {
    .ilg-chat__header::before {
        content: "⋮⋮";
        color: rgba(255, 255, 255, 0.4);
        font-size: 16px;
        letter-spacing: -2px;
        margin-right: 4px;
    }
}

.ilg-chat__avatar {
    width: 36px;
    height: 36px;
    background: #fca311;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    flex-shrink: 0;
}

.ilg-chat__title {
    flex: 1;
    line-height: 1.3;
}

.ilg-chat__title strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
}

.ilg-chat__title small {
    font-size: 11px;
    opacity: 0.7;
}

/* Online indicator */
.ilg-chat__title small::before {
    content: "●";
    color: #10b981;
    margin-right: 4px;
    font-size: 9px;
    vertical-align: middle;
}

/* Buttons */
.ilg-chat__btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 18px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    line-height: 1;
}

.ilg-chat__btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* ============================================================
   MESSAGES AREA
============================================================ */
.ilg-chat__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

.ilg-chat__body::-webkit-scrollbar { width: 6px; }
.ilg-chat__body::-webkit-scrollbar-track { background: transparent; }
.ilg-chat__body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* Message bubble */
.ilg-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.ilg-msg--system {
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.ilg-msg--user {
    background: linear-gradient(135deg, #14213d, #1e3a5f);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ilg-msg__time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 4px;
    display: block;
}

.ilg-msg a {
    color: #fca311;
    text-decoration: underline;
    font-weight: 600;
}

.ilg-msg--user a { color: #fcd34d; }

/* Typing indicator (3 dots) */
.ilg-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    align-items: center;
}

.ilg-typing span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: ilg-typing-bounce 1.2s infinite;
}

.ilg-typing span:nth-child(2) { animation-delay: 0.15s; }
.ilg-typing span:nth-child(3) { animation-delay: 0.30s; }

@keyframes ilg-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   QUICK REPLIES (pills після greeting у новій сесії)
============================================================ */
.ilg-chat__quick {
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0 8px;
    max-width: 90%;
}
.ilg-chat__quick-hint {
    font-size: 11px;
    color: #9ca3af;
    padding-left: 4px;
    margin-bottom: 2px;
}
.ilg-chat__quick-btn {
    background: #fff;
    color: #14213d;
    border: 1px solid #fca311;
    padding: 8px 14px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    font-family: inherit;
}
.ilg-chat__quick-btn:hover {
    background: #fca311;
    color: #fff;
    transform: translateX(2px);
}

/* ============================================================
   INPUT AREA
============================================================ */
.ilg-chat__footer {
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 12px;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.ilg-chat__input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    font-family: inherit;
    line-height: 1.4;
}

.ilg-chat__input:focus {
    border-color: #fca311;
    box-shadow: 0 0 0 3px rgba(252, 163, 17, 0.1);
}

.ilg-chat__send {
    width: 40px;
    height: 40px;
    background: #fca311;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ilg-chat__send:hover { background: #d97706; transform: scale(1.05); }
.ilg-chat__send:disabled { background: #d1d5db; cursor: not-allowed; transform: none; }

/* ============================================================
   MINIMIZED BUBBLE (згорнутий стан)
============================================================ */
.ilg-chat-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #14213d, #1e3a5f);
    border-radius: 50%;
    box-shadow: 0 6px 20px rgba(20, 33, 61, 0.4);
    z-index: 99999;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    border: 2px solid #fca311;
    transition: transform 0.15s;
}

.ilg-chat-bubble:hover { transform: scale(1.1); }

.ilg-chat-bubble.is-visible { display: flex; }

/* Badge: кількість нових повідомлень */
.ilg-chat-bubble__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ============================================================
   MOBILE — fixed bottom (no drag)
============================================================ */
@media (max-width: 767.98px) {
    .ilg-chat {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: auto !important;
        width: 100% !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        border: none;
    }
    .ilg-chat__header {
        cursor: default;  /* немає drag на mobile */
        padding-top: max(14px, env(safe-area-inset-top));
    }
    .ilg-chat__footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    .ilg-chat-bubble {
        bottom: 16px;
        right: 16px;
    }
}
