/* ========================
   TABIREX CHAT AGENT WIDGET
   Self-contained floating chat. Uses Font Awesome icons (already loaded site-wide).
   ======================== */

.chat-launcher {
    position: fixed;
    left: 24px;
    bottom: 24px;
    z-index: 9990;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #0e7490, #06b6d4);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(6, 182, 212, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
}
.chat-launcher:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(6, 182, 212, 0.5);
}
.chat-launcher .chat-close-icon { display: none; }
.chat-launcher.is-open .chat-open-icon { display: none; }
.chat-launcher.is-open .chat-close-icon { display: inline; }

/* Gentle pulse ring on the launcher until first opened */
@keyframes chat-launcher-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.45); }
    70%  { box-shadow: 0 0 0 14px rgba(6, 182, 212, 0); }
    100% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
}
.chat-launcher:not(.is-open) {
    animation: chat-launcher-pulse 2.6s ease-out infinite;
}

.chat-widget {
    position: fixed;
    left: 24px;
    bottom: 96px;
    z-index: 9991;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 130px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(6, 14, 26, 0.35);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

.chat-widget.is-open { display: flex; }

.chat-header {
    background: linear-gradient(135deg, #060e1a, #0e7490);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #06b6d4;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title {
    font-weight: 600;
    font-size: 15px;
    margin: 0;
}
.chat-header-status {
    font-size: 12px;
    color: #a7f3d0;
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0;
}
.chat-header-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34d399;
    display: inline-block;
}
.chat-header-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
}
.chat-header-close:hover { background: rgba(255,255,255,0.15); }

/* --- Message area --- */
.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 12px;
    background: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-row.bot { justify-content: flex-start; }
.chat-row.user { justify-content: flex-end; }
.chat-row.grouped { margin-top: -5px; }
.chat-row.grouped .chat-bubble-meta { display: none; }

.chat-avatar-sm {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #0e7490;
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-msg-wrap {
    max-width: 78%;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-msg {
    position: relative;
    padding: 9px 12px 20px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-line;
    word-wrap: break-word;
    animation: chat-in .25s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.chat-msg a { color: inherit; }
.chat-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}
.chat-msg.bot a {
    color: #0e7490;
    font-weight: 600;
    text-decoration: underline;
}
.chat-msg.user {
    align-self: flex-end;
    background: #0e7490;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* In-bubble meta: time + read ticks (WhatsApp style) */
.chat-bubble-meta {
    position: absolute;
    right: 8px;
    bottom: 4px;
    font-size: 10px;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: none;
    white-space: nowrap;
}
.chat-msg.bot .chat-bubble-meta { color: #9ca3af; }
.chat-msg.user .chat-bubble-meta { color: rgba(255, 255, 255, 0.85); }
.chat-msg.user .tick-dbl { display: none; }
.chat-row.seen .chat-msg.user .tick-dbl { display: inline-block; color: #a5f3fc; }

/* --- Typing indicator (animated dots + avatar, WhatsApp-style) --- */
@keyframes chat-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30%           { transform: translateY(-4px); opacity: 1; }
}
.chat-msg.typing-dots {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 54px;
}
.chat-msg.typing-dots i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    display: inline-block;
    animation: chat-dot-bounce 1.2s ease-in-out infinite;
}
.chat-msg.typing-dots i:nth-child(2) { animation-delay: .18s; }
.chat-msg.typing-dots i:nth-child(3) { animation-delay: .36s; }

.chat-quick-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    background: #fff;
    border-top: 1px solid #eef0f3;
    flex-shrink: 0;
}
.chat-chip {
    background: #ecfeff;
    color: #0e7490;
    border: 1px solid #a5f3fc;
    border-radius: 999px;
    padding: 6px 13px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s ease;
}
.chat-chip:hover { background: #cffafe; }

.chat-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eef0f3;
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s ease;
}
.chat-input:focus { border-color: #06b6d4; }
.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: #0e7490;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}
.chat-send-btn:hover { background: #0c5a72; }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-footer-note {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    padding: 6px;
    background: #f9fafb;
    flex-shrink: 0;
}

/* --- Teaser bubble (shown once, before first open) --- */
.chat-teaser {
    position: fixed;
    left: 24px;
    bottom: 96px;
    z-index: 9989;
    width: 234px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(6, 14, 26, 0.18);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.45;
    color: #1f2937;
    text-align: left;
    cursor: pointer;
    display: none;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}
.chat-teaser.show {
    display: block;
    animation: chat-teaser-in .3s ease;
}
.chat-teaser .chat-teaser-title { font-weight: 600; margin-bottom: 2px; }
.chat-teaser .chat-teaser-body { color: #4b5563; }
.chat-teaser .chat-teaser-tail {
    position: absolute;
    left: 26px;
    bottom: -7px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    transform: rotate(45deg);
}
.chat-teaser .chat-teaser-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 12px;
    padding: 4px;
}
.chat-teaser .chat-teaser-close:hover { color: #1f2937; }
@keyframes chat-teaser-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

/* Scrollbar */
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .chat-launcher:not(.is-open),
    .chat-msg,
    .chat-teaser.show {
        animation: none !important;
    }
    .chat-msg.typing-dots i { animation: none; opacity: 1; }
}

@media (max-width: 480px) {
    .chat-launcher { left: 16px; bottom: 16px; }
    .chat-widget { left: 8px; right: 8px; bottom: 84px; width: auto; }
    .chat-teaser { left: 16px; bottom: 84px; }
}