/* ===== TPFW AI CHAT WIDGET — PREMIUM v3 ===== */

.tpfw-chat-widget {
    position: fixed !important;
    left: 20px !important;
    bottom: 20px !important;
    right: auto !important;
    top: auto !important;
    z-index: 999999 !important;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Toggle button ── */
.tpfw-chat-toggle {
    order: 2;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(145deg, #0b1120 0%, #1a2744 100%);
    border: 2px solid rgba(184,146,74,.4);
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(0,0,0,.45), 0 2px 8px rgba(184,146,74,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s;
    position: relative;
    flex-shrink: 0;
    outline: none;
}
.tpfw-chat-toggle:hover {
    transform: scale(1.12);
    box-shadow: 0 14px 44px rgba(0,0,0,.5), 0 0 0 4px rgba(184,146,74,.38);
}
.tpfw-chat-toggle svg {
    width: 26px; height: 26px;
    stroke: #fff; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tpfw-icon-close { display: none; }
.tpfw-chat-widget.is-open .tpfw-icon-open  { display: none; }
.tpfw-chat-widget.is-open .tpfw-icon-close { display: block; }

/* Badge */
.tpfw-chat-badge {
    position: absolute;
    top: -4px; right: -4px;
    min-width: 22px; height: 22px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    border-radius: 11px;
    font-size: .58rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
    padding: 0 4px;
    animation: tpfw-badge-pulse 2s ease-in-out infinite;
    box-shadow: 0 2px 10px rgba(239,68,68,.5);
}
.tpfw-chat-widget.is-open .tpfw-chat-badge { display: none; }
@keyframes tpfw-badge-pulse {
    0%,100% { transform:scale(1); }
    50%      { transform:scale(1.2); }
}

/* ── Panel ── */
.tpfw-chat-panel {
    order: 1;
    width: 370px;
    background: #edf0f4;
    border-radius: 22px;
    box-shadow:
        0 40px 100px rgba(0,0,0,.22),
        0 12px 32px rgba(0,0,0,.12),
        inset 0 0 0 1px rgba(255,255,255,.65);
    overflow: hidden;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    max-height: 570px;
    /* collapsed state */
    opacity: 0;
    transform: translateY(24px) scale(.93);
    pointer-events: none;
    transition: opacity .3s cubic-bezier(.4,0,.2,1), transform .35s cubic-bezier(.34,1.56,.64,1);
    transform-origin: bottom left;
}
.tpfw-chat-widget.is-open .tpfw-chat-panel {
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
}

/* ── Header ── */
.tpfw-chat-header {
    background: linear-gradient(135deg, #0b1120 0%, #162036 60%, #1a2744 100%);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(184,146,74,.22);
}
.tpfw-chat-avatar-wrap { position: relative; flex-shrink: 0; }
.tpfw-chat-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7a5e24 0%, #b8924a 60%, #d4aa6a 100%);
    color: #fff;
    font-weight: 800; font-size: .8rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 2.5px rgba(184,146,74,.45), 0 4px 14px rgba(0,0,0,.3);
    letter-spacing: .5px;
}
.tpfw-online-dot {
    position: absolute; bottom: 1px; right: 1px;
    width: 13px; height: 13px;
    background: #22c55e;
    border-radius: 50%;
    border: 2.5px solid #0b1120;
    animation: tpfw-glow 3s ease-in-out infinite;
}
@keyframes tpfw-glow {
    0%,100% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); }
    50%      { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}
.tpfw-chat-info { flex: 1; min-width: 0; }
.tpfw-chat-info strong {
    display: block;
    font-size: .92rem; font-weight: 700; color: #fff;
    letter-spacing: .2px; margin-bottom: 3px;
}
.tpfw-status-row {
    display: flex; align-items: center; gap: 5px;
    font-size: .7rem; color: rgba(255,255,255,.5);
}
.tpfw-status-dot {
    width: 6px; height: 6px;
    background: #22c55e;
    border-radius: 50%;
    animation: tpfw-glow 3s ease-in-out infinite;
    flex-shrink: 0;
}
.tpfw-chat-close {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14);
    color: rgba(255,255,255,.65);
    width: 32px; height: 32px;
    border-radius: 50%;
    cursor: pointer; font-size: 1.2rem; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: background .2s, color .2s, transform .15s;
    flex-shrink: 0; padding: 0; outline: none;
}
.tpfw-chat-close:hover {
    background: rgba(239,68,68,.28);
    border-color: rgba(239,68,68,.45);
    color: #fff; transform: scale(1.12);
}

/* ── Message list ── */
.tpfw-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    scroll-behavior: smooth;
    background:
        radial-gradient(ellipse at top left, rgba(184,146,74,.05) 0%, transparent 55%),
        linear-gradient(180deg, #e5e8ed 0%, #edf0f4 100%);
}
.tpfw-chat-messages::-webkit-scrollbar { width: 3px; }
.tpfw-chat-messages::-webkit-scrollbar-thumb { background: #c4cad4; border-radius: 3px; }

/* ── Message rows ── */
.tpfw-msg {
    display: flex; align-items: flex-end; gap: 8px;
    animation: tpfw-slide-in .28s cubic-bezier(.4,0,.2,1) both;
}
.tpfw-msg--user { flex-direction: row-reverse; }
@keyframes tpfw-slide-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tpfw-msg-av {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0b1120, #182238);
    color: #b8924a;
    font-size: .58rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    border: 1px solid rgba(184,146,74,.22);
}

.tpfw-msg-bubble {
    max-width: 82%;
    padding: 11px 15px;
    border-radius: 18px;
    font-size: .855rem;
    line-height: 1.6;
    word-wrap: break-word;
}
.tpfw-msg--bot .tpfw-msg-bubble {
    background: #fff;
    color: #1e293b;
    border-radius: 4px 18px 18px 18px;
    box-shadow: 0 2px 14px rgba(0,0,0,.07), 0 0 0 1px rgba(0,0,0,.04);
}
.tpfw-msg--user .tpfw-msg-bubble {
    background: linear-gradient(135deg, #7a5e24 0%, #b8924a 100%);
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 4px 18px rgba(184,146,74,.4);
}
.tpfw-bubble-success {
    background: linear-gradient(135deg, #059669, #047857) !important;
    color: #fff !important;
    box-shadow: 0 4px 18px rgba(5,150,105,.38) !important;
}

/* ── Step fields ── */
.tpfw-step-field {
    margin: 3px 0 3px 38px;
    background: #fff;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 2px 18px rgba(0,0,0,.09), 0 0 0 1px rgba(0,0,0,.04);
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: tpfw-slide-in .3s cubic-bezier(.4,0,.2,1) both;
}
.tpfw-step-field input[type="tel"],
.tpfw-step-field input[type="email"],
.tpfw-step-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: .875rem;
    font-family: inherit;
    color: #1e293b;
    background: #f8fafc;
    outline: none;
    transition: border-color .2s, box-shadow .2s, background .2s;
    -webkit-appearance: none;
    resize: none;
}
.tpfw-step-field input:focus,
.tpfw-step-field textarea:focus {
    border-color: #b8924a;
    box-shadow: 0 0 0 3px rgba(184,146,74,.14);
    background: #fff;
}
.tpfw-step-field input::placeholder,
.tpfw-step-field textarea::placeholder { color: #94a3b8; font-size: .82rem; }

.tpfw-next-btn {
    width: 100%;
    padding: 12px 18px;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    gap: 7px;
    transition: background .2s, transform .15s, box-shadow .2s;
    letter-spacing: .4px;
    font-family: inherit;
    outline: none;
}
.tpfw-next-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #1e293b 0%, #2d3f5e 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(0,0,0,.28);
}
.tpfw-next-btn:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
.tpfw-next-btn:disabled { opacity: .55; cursor: not-allowed; }
.tpfw-send-btn {
    background: linear-gradient(135deg, #7a5e24 0%, #b8924a 100%) !important;
    box-shadow: 0 3px 14px rgba(184,146,74,.38);
}
.tpfw-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #5e4718 0%, #96742e 100%) !important;
    box-shadow: 0 6px 24px rgba(184,146,74,.52) !important;
}

/* ── Referral chips ── */
.tpfw-chips {
    margin: 3px 0 3px 38px;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    animation: tpfw-slide-in .3s cubic-bezier(.4,0,.2,1) both;
}
.tpfw-chip {
    padding: 8px 14px;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 22px;
    font-size: .78rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: all .18s cubic-bezier(.34,1.56,.64,1);
    box-shadow: 0 1px 5px rgba(0,0,0,.06);
    font-family: inherit;
    outline: none;
    white-space: nowrap;
}
.tpfw-chip:hover {
    background: linear-gradient(135deg, #7a5e24, #b8924a);
    border-color: #b8924a;
    color: #fff;
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 6px 18px rgba(184,146,74,.4);
}
.tpfw-chip.selected {
    background: linear-gradient(135deg, #7a5e24, #b8924a);
    border-color: #b8924a;
    color: #fff;
    box-shadow: 0 4px 14px rgba(184,146,74,.42);
}

/* ── Typing indicator ── */
.tpfw-typing {
    display: flex; align-items: center; gap: 5px;
    background: #fff;
    padding: 13px 16px;
    border-radius: 4px 18px 18px 18px;
    box-shadow: 0 2px 14px rgba(0,0,0,.07);
    max-width: 74px;
}
.tpfw-typing span {
    width: 7px; height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    display: inline-block;
    animation: tpfw-dot 1.3s ease-in-out infinite;
}
.tpfw-typing span:nth-child(2) { animation-delay: .2s; }
.tpfw-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes tpfw-dot {
    0%,80%,100% { transform:scale(.65); opacity:.45; }
    40%         { transform:scale(1);   opacity:1; }
}

/* ── Mobile ── */
@media (max-width: 480px) {
    .tpfw-chat-widget {
        left: 0 !important; right: 0 !important;
        bottom: 0 !important; width: 100% !important;
        align-items: stretch !important;
    }
    .tpfw-chat-panel {
        width: 100% !important;
        border-radius: 22px 22px 0 0;
        margin-bottom: 0;
        max-height: 88vh;
    }
    .tpfw-chat-toggle {
        position: fixed !important;
        left: 16px !important; bottom: 16px !important;
        order: unset;
    }
    .tpfw-chat-widget.is-open .tpfw-chat-toggle { display: none; }
    .tpfw-chips { gap: 6px; }
    .tpfw-chip  { font-size: .76rem; padding: 7px 12px; }
}
