
/* ── Trigger ── */
.chat-trigger {
    position: fixed; bottom: 28px; right: 28px;
    width: 58px; height: 58px; border-radius: 50%;
    background: #bd191f;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 24px rgba(189, 25, 31, 0.5);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 60; animation: pulse-ring 2.6s ease-out infinite;
}
.chat-trigger:hover { transform: scale(1.07); box-shadow: 0 8px 32px rgba(189, 25, 31, 0.6); }
.chat-trigger svg { width: 24px; height: 24px; fill: white; flex-shrink: 0; }
.chat-trigger .icon-close { display: none; }
.chat-trigger.open .icon-chat  { display: none; }
.chat-trigger.open .icon-close { display: block; }
@keyframes pulse-ring {
    0%   { box-shadow: 0 4px 24px rgba(189, 25, 31, 0.5), 0 0 0 0   rgba(189, 25, 31, 0.5); }
    70%  { box-shadow: 0 4px 24px rgba(189, 25, 31, 0.5), 0 0 0 16px rgba(189, 25, 31, 0);   }
    100% { box-shadow: 0 4px 24px rgba(189, 25, 31, 0.5), 0 0 0 0   rgba(189, 25, 31, 0);   }
}

/* ── Modal shell ── */
.chat-modal {
    position: fixed; bottom: 98px; right: 28px;
    width: 390px;
    border-radius: 22px;
    background: #14141a;
    border: 1px solid rgba(255,255,255,0.07);
    box-shadow: 0 32px 80px rgba(0,0,0,0.65), 0 0 0 1px rgba(255,255,255,0.03) inset;
    display: flex; flex-direction: column; overflow: hidden;
    z-index: 59;
    transform-origin: bottom right;
    transform: scale(0.84) translateY(18px);
    opacity: 0; pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.22s ease;
    max-height: 620px;
}
.chat-modal.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }
/* inner wrapper below header so overlays don't cover it */
.modal-body {
    position: relative; flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* ── Header ── */
.modal-header {
    padding: 16px 18px 13px;
    background: #1a1a22;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; gap: 11px; flex-shrink: 0;
}
.agent-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: #bd191f;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 600; color: white;
    flex-shrink: 0; position: relative;
}
.agent-avatar::after {
    content: ''; position: absolute; bottom: 1px; right: 1px;
    width: 9px; height: 9px; border-radius: 50%;
    background: #22c55e; border: 2px solid #1a1a22;
}
.agent-info { flex: 1; }
.agent-name   { font-size: 13.5px; font-weight: 600; color: #f1f1f5; line-height: 1.2; }
.agent-status { font-size: 11px; color: #6b7280; margin-top: 2px; }
.header-actions { display: flex; gap: 3px; }
.header-btn {
    width: 30px; height: 30px; border-radius: 8px;
    background: transparent; border: none; cursor: pointer;
    color: #6b7280; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.header-btn:hover { background: rgba(255,255,255,0.06); color: #a3a3b3; }
.header-btn svg { width: 15px; height: 15px; }

/* ── Panels ── */
.panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; transition: opacity 0.25s ease, transform 0.25s ease; }
.panel.hidden { display: none; }

/* ── Pre-chat Form ── */
.prechat-panel { overflow-y: auto; padding: 24px 22px 22px; gap: 0; background: #14141a; }
.prechat-panel::-webkit-scrollbar { width: 4px; }
.prechat-panel::-webkit-scrollbar-thumb { background: #2d2d3a; border-radius: 4px; }

.prechat-intro { margin-bottom: 22px; }
.prechat-intro h2 { font-size: 17px; font-weight: 600; color: #f0f0f5; margin-bottom: 6px; }
.prechat-intro p  { font-size: 12.5px; color: #6b7280; line-height: 1.6; }

.form-group { margin-bottom: 14px; }
.form-label {
    display: block; font-size: 11.5px; font-weight: 500;
    color: #9ca3af; margin-bottom: 6px; letter-spacing: 0.02em;
}
.form-label span { color: #ef4444; margin-left: 2px; }
.form-control {
    width: 100%; background: #1e1e28;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 11px; padding: 10px 13px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px; color: #e0e0e8; outline: none;
    transition: border-color 0.18s, background 0.18s;
}
.form-control::placeholder { color: #cfc8c8; }
.form-control:focus { border-color: rgba(189, 25, 31, 0.5); background: #21212e; }
.form-control.err { border-color: rgba(189, 25, 31, 0.55); }
textarea.form-control { resize: none; height: 88px; line-height: 1.5; }

.form-error {
    font-size: 11px; color: #f87171; margin-top: 5px;
    display: none; align-items: center; gap: 4px;
}
.form-error.show { display: flex; }

.submit-btn {
    width: 100%; padding: 12px 0; border-radius: 12px;
    background: #bd191f;
    border: none; cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px; font-weight: 600; color: white;
    transition: opacity 0.15s, transform 0.12s;
    margin-top: 6px;
}
.submit-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.submit-btn:active { transform: translateY(0); opacity: 1; }

/* ── Chat Panel ── */
.chat-panel { background: #14141a; min-height: 440px; height: 560px; }

.flow-bar {
    padding: 9px 18px;
    background: #111118;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex; align-items: center; gap: 0;
    flex-shrink: 0; overflow-x: auto; scrollbar-width: none;
}
.flow-bar::-webkit-scrollbar { display: none; }
.flow-step {
    display: flex; align-items: center; gap: 5px;
    font-size: 10.5px; color: #b8a9a9; white-space: nowrap;
    font-weight: 500; cursor: default; transition: color 0.2s;
}
.step-dot {
    width: 17px; height: 17px; border-radius: 50%;
    background: #bfabab; border: 1.5px solid #cab8b8;
    display: flex; align-items: center; justify-content: center;
    font-size: 8.5px; font-weight: 700; color: #685b5b;
    flex-shrink: 0; transition: all 0.25s;
}
.flow-step.active .step-dot { background: #bd191f; border-color: transparent; color: white; box-shadow: 0 0 8px rgba(189, 25, 31, 0.45); }
.flow-step.done   .step-dot { background: #16a34a; border-color: transparent; color: white; }
.flow-step.active { color: #fff1f3; }
.flow-step.done   { color: #4ade80; }
.step-conn { width: 18px; height: 1px; background: #252530; flex-shrink: 0; margin: 0 2px; }
.step-conn.done { background: #4ade80; }

.messages-area {
    flex: 1; overflow-y: auto;
    padding: 16px 14px; display: flex; flex-direction: column; gap: 10px;
}
.messages-area::-webkit-scrollbar { width: 3px; }
.messages-area::-webkit-scrollbar-thumb { background: #2d2d3a; border-radius: 4px; }

.msg { display: flex; gap: 8px; animation: msg-in 0.22s ease; }
@keyframes msg-in { from { opacity:0; transform:translateY(7px); } to { opacity:1; transform:translateY(0); } }
.msg.user { flex-direction: row-reverse; }
.msg-av {
    width: 27px; height: 27px; border-radius: 50%;
    background: #bd191f;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 10.5px; font-weight: 600; color: white;
    align-self: flex-end;
}
.msg.user .msg-av { background: #252535; }
.msg-content { max-width: 80%; display: flex; flex-direction: column; }
.msg-bubble { padding: 9px 13px; font-size: 13.5px; line-height: 1.55; color: #dde0ea; }
.msg.bot  .msg-bubble { background: #202030; border-radius: 4px 14px 14px 14px; }
.msg.user .msg-bubble { background: #bd191f; color: #ffc8ca; border-radius: 14px 4px 14px 14px; }
.msg-time { font-size: 10px; color: #c5b1b2; margin-top: 3px; padding: 0 3px; }
.msg.user .msg-time { text-align: right; }

/* Image bubbles */
.msg-img-wrap {
    max-width: 210px; border-radius: 12px; overflow: hidden;
    cursor: pointer; margin-bottom: 4px;
}
.msg-img-wrap img { width: 100%; display: block; border-radius: 12px; transition: opacity 0.15s; }
.msg-img-wrap:hover img { opacity: 0.88; }
.msg-img-name { font-size: 10.5px; color: #fff0f0; padding: 0 3px; margin-bottom: 2px; }

/* Quick replies */
.quick-replies { display: flex; flex-wrap: wrap; gap: 6px; padding: 3px 0 5px 35px; }
.qr-btn {
    padding: 6px 12px; border-radius: 20px;
    border: 1px solid rgba(189, 25, 31, 0.35);
    background: rgba(99,102,241,0.08);
    color: #fff0f0; font-size: 12px; cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.qr-btn:hover { background: rgba(189, 25, 31, 0.2); border-color: rgba(189, 25, 31, 0.6); transform: translateY(-1px); }

/* Typing */
.typing-indicator { display: flex; gap: 8px; align-items: flex-end; }
.typing-bubble { background: #202030; border-radius: 4px 14px 14px 14px; padding: 11px 14px; display: flex; gap: 4px; align-items: center; }
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: #bd191f; animation: tb 1.2s ease-in-out infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes tb { 0%,60%,100% { transform:translateY(0); opacity:0.4; } 30% { transform:translateY(-5px); opacity:1; } }

/* ── Input area ── */
.input-area {
    padding: 10px 13px 12px;
    background: #1a1a22;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

/* Preview strip */
.img-preview-strip { display: none; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.img-preview-strip.active { display: flex; }
.preview-item {
    position: relative; width: 54px; height: 54px;
    border-radius: 9px; overflow: hidden;
    border: 1.5px solid rgba(189, 25, 31, 0.45);
    animation: msg-in 0.18s ease;
}
.preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-remove {
    position: absolute; top: 2px; right: 2px;
    width: 16px; height: 16px; border-radius: 50%;
    background: rgba(0,0,0,0.75); border: none; cursor: pointer;
    color: #fff; font-size: 9px; display: flex; align-items: center; justify-content: center;
    line-height: 1;
}

.input-row {
    display: flex; align-items: flex-end; gap: 7px;
    background: #0e0e16;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 13px; padding: 7px 7px 7px 13px;
    transition: border-color 0.2s;
}
.input-row:focus-within { border-color: rgba(189, 25, 31, 0.42); }
.msg-input {
    flex: 1; background: transparent; border: none; outline: none;
    resize: none; font-family: 'DM Sans', sans-serif;
    font-size: 13.5px; color: #e0e0e8; line-height: 1.5;
    max-height: 96px; min-height: 22px;
}
.msg-input::placeholder { color: #402f2f; }
.msg-input:disabled { opacity: 0.35; }

.input-btns { display: flex; align-items: center; gap: 5px; }
.attach-btn {
    width: 32px; height: 32px; border-radius: 9px;
    background: rgba(255,255,255,0.05); border: none; cursor: pointer;
    color: #6a595a; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.attach-btn:hover { background: rgba(243, 112, 117, 0.15); color: #fda4a8; }
.attach-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.attach-btn svg { width: 16px; height: 16px; }

.send-btn {
    width: 33px; height: 33px; border-radius: 10px;
    background: #bd191f;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.15s, transform 0.15s;
}
.send-btn:hover { opacity: 0.88; transform: scale(0.96); }
.send-btn:disabled { opacity: 0.28; cursor: not-allowed; transform: none; }
.send-btn svg { width: 14px; height: 14px; fill: white; }

.input-footer {
    display: flex; justify-content: space-between; align-items: center; padding-top: 7px;
}
.img-count { font-size: 10.5px; color: #ffa1a4; background: rgba(99,102,241,0.15); padding: 2px 8px; border-radius: 10px; display: none; }
.img-count.show { display: block; }
.powered { font-size: 10px; color: #452e2f; }
.powered strong { color: #5a3334; }

/* ── Header menu dropdown ── */
.header-menu-wrap { position: relative; }
.header-menu {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: #1e1e2a; border: 1px solid rgba(255,255,255,0.09);
    border-radius: 11px; padding: 5px;
    min-width: 170px; z-index: 80;
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
    opacity: 0; transform: translateY(-6px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}
.header-menu.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }
.menu-item {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 11px; border-radius: 8px;
    font-size: 12.5px; cursor: pointer; border: none;
    background: transparent; color: #9ca3af; width: 100%;
    font-family: 'DM Sans', sans-serif;
    transition: background 0.12s, color 0.12s;
    text-align: left;
}
.menu-item:hover { background: rgba(255,255,255,0.06); color: #e0e0e8; }
.menu-item.danger:hover { background: rgba(239,68,68,0.1); color: #f87171; }
.menu-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.menu-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 4px 0; }

/* ── End-chat confirmation overlay ── */
.end-confirm-overlay {
    position: absolute; inset: 0;
    background: rgba(10,10,16,0.88);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 40; border-radius: 0 0 20px 20px;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
}
.end-confirm-overlay.open { opacity: 1; pointer-events: all; }
.end-confirm-box {
    background: #1e1e2a; border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px; padding: 26px 24px 22px;
    width: 300px; text-align: center;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    animation: pop-in 0.22s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes pop-in { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.end-confirm-icon {
    width: 46px; height: 46px; border-radius: 50%;
    background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.25);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 14px;
}
.end-confirm-icon svg { width: 22px; height: 22px; color: #f87171; }
.end-confirm-box h3 { font-size: 15px; font-weight: 600; color: #f1f1f5; margin-bottom: 7px; }
.end-confirm-box p  { font-size: 12.5px; color: #6a5b5b; line-height: 1.6; margin-bottom: 20px; }
.end-confirm-actions { display: flex; gap: 9px; }
.btn-cancel {
    flex: 1; padding: 10px 0; border-radius: 10px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    color: #9ca3af; font-size: 13px; font-weight: 500;
    cursor: pointer; font-family: 'DM Sans', sans-serif;
    transition: background 0.15s, color 0.15s;
}
.btn-cancel:hover { background: rgba(255,255,255,0.09); color: #e0e0e8; }
.btn-end {
    flex: 1; padding: 10px 0; border-radius: 10px;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    border: none; color: white; font-size: 13px; font-weight: 600;
    cursor: pointer; font-family: 'DM Sans', sans-serif;
    transition: opacity 0.15s, transform 0.12s;
}
.btn-end:hover { opacity: 0.88; transform: translateY(-1px); }

/* ── Ended state screen ── */
.ended-screen {
    position: absolute; inset: 0;
    background: #14141a;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 35; border-radius: 0 0 20px 20px;
    padding: 28px 24px;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
}
.ended-screen.open { opacity: 1; pointer-events: all; }
.ended-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: rgba(243, 101, 106, 0.1); border: 1px solid rgba(237, 97, 102, 0.2);
    display: flex; align-items: center; justify-content: center; margin-bottom: 18px;
}
.ended-icon svg { width: 26px; height: 26px; color: #bd191f; }
.ended-screen h3 { font-size: 16px; font-weight: 600; color: #f1f1f5; margin-bottom: 8px; text-align: center; }
.ended-screen p  { font-size: 12.5px; color: #7e6a6a; line-height: 1.65; text-align: center; margin-bottom: 24px; max-width: 240px; }
.btn-new-chat {
    padding: 11px 28px; border-radius: 11px;
    background: #bd191f;
    border: none; color: white; font-size: 13.5px; font-weight: 600;
    cursor: pointer; font-family: 'DM Sans', sans-serif;
    transition: opacity 0.15s, transform 0.12s;
}
.btn-new-chat:hover { opacity: 0.88; transform: translateY(-1px); }

/* ── Lightbox ── */
.lightbox {
    position: fixed; inset: 0; background: rgba(0,0,0,0.9);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.lightbox.open { opacity: 1; pointer-events: all; }
.lightbox-img { max-width: 92vw; max-height: 88vh; border-radius: 14px; display: block; }
.lightbox-close {
    position: absolute; top: 18px; right: 22px;
    background: rgba(255,255,255,0.1); border: none; cursor: pointer;
    color: white; width: 36px; height: 36px; border-radius: 50%;
    font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.lightbox-fname {
    position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
    font-size: 12px; color: rgba(255,255,255,0.5); font-family: 'DM Mono', monospace;
    background: rgba(0,0,0,0.5); padding: 4px 12px; border-radius: 8px;
    white-space: nowrap; max-width: 80vw; overflow: hidden; text-overflow: ellipsis;
}

/* ── Toast ── */
.toast {
    position: fixed; bottom: 108px; right: 28px;
    background: #2e1d1e; border: 1px solid rgba(239,68,68,0.3);
    color: #fca5a5; font-size: 12px; padding: 10px 15px;
    border-radius: 10px; z-index: 70; pointer-events: none;
    opacity: 0; transform: translateY(5px);
    transition: opacity 0.2s, transform 0.2s;
    max-width: 290px; line-height: 1.4;
}
.toast.show { opacity: 1; transform: translateY(0); }

.demo-hint {
    position: fixed; top: 22px; left: 50%; transform: translateX(-50%);
    font-size: 11px; color: #372627; letter-spacing: 0.08em;
    text-transform: uppercase; font-family: 'DM Mono', monospace;
}
