/* ============================================
   CHAT WIDGET
   ============================================ */

.chat-widget {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 95;
    font-family: var(--f-sans);
}

.chat-launcher {
    width: 60px;
    height: 60px;
    border-radius: var(--r-full);
    background: linear-gradient(135deg, var(--c-plum) 0%, var(--c-rose) 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(92, 61, 92, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s var(--ease), box-shadow 0.3s;
    position: relative;
}
.chat-launcher:hover { transform: scale(1.08); box-shadow: 0 12px 40px rgba(92, 61, 92, 0.5); }
.chat-launcher svg { width: 28px; height: 28px; }
.chat-launcher .badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--c-rose-deep);
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}
.chat-launcher.has-unread .badge { display: flex; }
.chat-launcher .pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--c-rose);
    animation: chat-pulse 2.5s infinite;
    z-index: -1;
}
@keyframes chat-pulse {
    0% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.5); opacity: 0; }
}

.chat-window {
    position: absolute;
    bottom: 76px;
    left: 0;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--c-white);
    border-radius: var(--r-xl);
    box-shadow: 0 20px 60px rgba(60, 30, 60, 0.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--c-line);
    animation: chat-slide-up 0.3s var(--ease);
}
.chat-window.is-open { display: flex; }
@keyframes chat-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-header {
    background: linear-gradient(135deg, var(--c-plum) 0%, var(--c-rose-deep) 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-rose) 0%, var(--c-lavender) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: var(--f-serif);
    color: white;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-info strong { display: block; font-size: 0.95rem; font-weight: 600; }
.chat-header-info small { font-size: 0.78rem; opacity: 0.85; display: flex; align-items: center; gap: 4px; }
.chat-header-info .dot {
    width: 8px;
    height: 8px;
    background: #6FA678;
    border-radius: 50%;
    display: inline-block;
}
.chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-close:hover { background: rgba(255, 255, 255, 0.25); }
.chat-close svg { width: 18px; height: 18px; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(180deg, var(--c-cream) 0%, var(--c-bg) 100%);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    padding: 6px 10px;
    border-radius: 12px;
    font-size: 0.86rem;
    line-height: 1.35;
    word-wrap: break-word;
    animation: chat-msg-in 0.25s var(--ease);
    white-space: pre-wrap;
    display: inline-block;
    width: fit-content;
    max-width: 85%;
    min-width: 0;
}
@keyframes chat-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg.bot {
    align-self: flex-start;
    background: white;
    color: var(--c-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(60, 30, 60, 0.06);
}
.chat-msg.customer {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--c-plum) 0%, var(--c-rose-deep) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}
.chat-msg.admin {
    align-self: flex-start;
    background: var(--c-info);
    color: white;
    border-bottom-left-radius: 4px;
}
.chat-msg.system {
    align-self: center;
    background: transparent;
    color: var(--c-muted);
    font-size: 0.78rem;
    font-style: italic;
    text-align: center;
    max-width: 100%;
}
.chat-msg strong { font-weight: 600; }

.chat-time {
    font-size: 0.7rem;
    color: var(--c-muted);
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}
.chat-msg.bot .chat-time { text-align: left; justify-content: flex-start; }

.chat-checks {
    display: inline-flex;
    align-items: center;
    color: rgba(255, 255, 255, 0.65);
}
.checks-read { color: #4FC3F7; }
.checks-sent, .checks-delivered { color: rgba(255, 255, 255, 0.7); }

.chat-typing {
    align-self: flex-start;
    background: white;
    padding: 12px 18px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
    box-shadow: 0 1px 3px rgba(60, 30, 60, 0.06);
}
.chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--c-rose);
    border-radius: 50%;
    animation: chat-typing 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-quick-replies {
    padding: 0 16px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: white;
    border-top: 1px solid var(--c-line);
}
.chat-qr-btn {
    background: var(--c-blush);
    color: var(--c-plum);
    border: 1px solid transparent;
    padding: 8px 14px;
    border-radius: var(--r-full);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-weight: 500;
}
.chat-qr-btn:hover { background: var(--c-rose); color: white; border-color: var(--c-rose); }

.chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid var(--c-line);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.chat-input {
    flex: 1;
    border: 1.5px solid var(--c-line);
    border-radius: 22px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    max-height: 100px;
    min-height: 42px;
    line-height: 1.4;
    transition: border-color 0.2s;
}
.chat-input:focus { outline: none; border-color: var(--c-rose); }
.chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--c-plum);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
}
.chat-send:hover { background: var(--c-rose-deep); transform: scale(1.05); }
.chat-send:disabled { background: var(--c-muted); cursor: not-allowed; transform: none; }
.chat-send svg { width: 18px; height: 18px; }

.chat-status-banner {
    background: var(--c-warning);
    color: white;
    padding: 8px 16px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

@media (max-width: 480px) {
    .chat-widget { left: 12px; bottom: 12px; }
    .chat-window {
        left: -12px;
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        max-height: none;
        border-radius: var(--r-lg);
    }
    .chat-launcher { width: 54px; height: 54px; }
    .chat-launcher svg { width: 24px; height: 24px; }
}
