/* ==========================================================================
   ZD Agent — Chatbot Widget v3.1
   Premium chat interface with gradient theming.
   ========================================================================== */

/* ── CSS Custom Properties (overridden by inline vars from admin settings) ── */
.zd-agent-fab,
.zd-agent-chat {
    --zda-c1: #6C63FF;
    --zda-c2: #4ECDC4;
    --zda-gradient: linear-gradient(135deg, var(--zda-c1) 0%, var(--zda-c2) 100%);
}

/* ── FAB (Floating Action Button) ── */
.zd-agent-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    background: var(--zda-gradient);
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(108, 99, 255, 0.35);
    z-index: 10001;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.25s ease;
}

.zd-agent-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(108, 99, 255, 0.5);
}

.zd-agent-fab:active {
    transform: scale(0.98);
}

.zd-agent-fab--hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
}

/* Pulse ring */
.zd-agent-fab__pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(108, 99, 255, 0.4);
    animation: zdAgentPulse 3s ease-in-out infinite;
    pointer-events: none;
}

@keyframes zdAgentPulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50%      { transform: scale(1.2); opacity: 0; }
}

/* ── Chat Widget Container ── */
.zd-agent-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15), 0 2px 12px rgba(0, 0, 0, 0.06);
    z-index: 10002;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
}

.zd-agent-chat[hidden] {
    display: none;
}

.zd-agent-chat--open {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ── Header ── */
.zd-agent-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--zda-gradient);
    color: #fff;
    flex-shrink: 0;
}

.zd-agent-chat__header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.zd-agent-chat__header-left > i {
    font-size: 1.2rem;
    opacity: 0.9;
}

.zd-agent-chat__header-info {
    display: flex;
    flex-direction: column;
}

.zd-agent-chat__header-name {
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1.2;
}

.zd-agent-chat__header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    opacity: 0.8;
}

.zd-agent-chat__status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    box-shadow: 0 0 4px rgba(74, 222, 128, 0.6);
}

.zd-agent-chat__status-dot--offline {
    background: #94a3b8;
    box-shadow: none;
}

.zd-agent-chat__input--disabled {
    opacity: 0.5;
    pointer-events: none;
}

.zd-agent-chat__send--disabled {
    opacity: 0.5;
    pointer-events: none;
}

.zd-agent-chat__header-actions {
    display: flex;
    gap: 4px;
}

.zd-agent-chat__minimize,
.zd-agent-chat__close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    transition: background 0.15s ease;
}

.zd-agent-chat__minimize:hover,
.zd-agent-chat__close:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ── Messages Area ── */
.zd-agent-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

/* Slim scrollbar */
.zd-agent-chat__messages::-webkit-scrollbar {
    width: 4px;
}
.zd-agent-chat__messages::-webkit-scrollbar-track {
    background: transparent;
}
.zd-agent-chat__messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* ── Chat Bubbles ── */
.zd-agent-bubble {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}

.zd-agent-bubble--bot {
    align-self: flex-start;
}

.zd-agent-bubble--user {
    align-self: flex-end;
}

.zd-agent-bubble__content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.855rem;
    line-height: 1.6;
    word-break: break-word;
}

/* Bot bubble content rich text support */
.zd-agent-bubble__content strong {
    font-weight: 700;
}

.zd-agent-bubble--bot .zd-agent-bubble__content a {
    color: var(--zda-c1);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    transition: opacity 0.15s ease;
}

.zd-agent-bubble--bot .zd-agent-bubble__content a:hover {
    opacity: 0.75;
}

.zd-agent-bubble--user .zd-agent-bubble__content a {
    color: #fff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.zd-agent-bubble__content ul {
    margin: 6px 0 6px 16px;
    padding: 0;
    list-style: disc;
}

.zd-agent-bubble__content ul li {
    margin-bottom: 2px;
}

.zd-agent-bubble--bot .zd-agent-bubble__content {
    background: #fff;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.zd-agent-bubble--user .zd-agent-bubble__content {
    background: var(--zda-gradient);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(108, 99, 255, 0.2);
}

.zd-agent-bubble__admin-label {
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--zda-c1);
    margin-bottom: 2px;
    padding: 0 4px;
}

.zd-agent-bubble__time {
    font-size: 0.66rem;
    color: #94a3b8;
    margin-top: 3px;
    padding: 0 4px;
}

.zd-agent-bubble--user .zd-agent-bubble__time {
    text-align: right;
}

/* Bubble enter animation */
.zd-agent-bubble--anim {
    animation: zdBubbleIn 0.3s ease-out;
}

@keyframes zdBubbleIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Typing Indicator ── */
.zd-agent-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
    animation: zdBubbleIn 0.25s ease-out;
}

.zd-agent-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: zdTypingBounce 1.4s infinite;
}

.zd-agent-typing span:nth-child(2) { animation-delay: 0.16s; }
.zd-agent-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes zdTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Quick Replies (horizontal scroll) ── */
.zd-agent-chat__quick-replies {
    padding: 8px 14px;
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    min-width: 0;                   /* flex-item overflow fix */
    max-width: 100%;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* IE/Edge */
}

.zd-agent-chat__quick-replies::-webkit-scrollbar {
    display: none;                  /* Chrome/Safari */
}

.zd-agent-chat__quick-replies:empty {
    display: none;
}

.zd-agent-qr {
    padding: 6px 14px;
    border: 1.5px solid var(--zda-c1);
    border-radius: 20px;
    background: #fff;
    color: var(--zda-c1);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.zd-agent-qr:hover {
    background: var(--zda-c1);
    color: #fff;
    transform: translateY(-1px);
}

.zd-agent-qr:active {
    transform: translateY(0);
}

/* ── Input Area ── */
.zd-agent-chat__input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}

.zd-agent-chat__input {
    flex: 1;
    min-width: 0;
    padding: 9px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 24px;
    font-size: 0.855rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #f8fafc;
}

.zd-agent-chat__input:focus {
    border-color: var(--zda-c1);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.08);
    background: #fff;
}

.zd-agent-chat__send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--zda-gradient);
    color: #fff;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.2);
}

.zd-agent-chat__send:hover {
    transform: scale(1.06);
    box-shadow: 0 3px 12px rgba(108, 99, 255, 0.3);
}

.zd-agent-chat__send:active {
    transform: scale(0.94);
}

/* ── Footer ── */
.zd-agent-chat__footer {
    text-align: center;
    padding: 5px 14px;
    font-size: 0.66rem;
    color: #a0aec0;
    border-top: 1px solid #f1f5f9;
    flex-shrink: 0;
    letter-spacing: 0.01em;
}

/* ── Disclaimer ── */
.zd-agent-chat__disclaimer {
    display: block;
    font-size: 0.6rem;
    color: #94a3b8;
    margin-top: 2px;
    font-style: italic;
}

/* ── Lead Capture Form (inline in chat) ── */
.zd-agent-lead-form {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    padding: 14px;
    align-self: flex-start;
    max-width: 85%;
    animation: zdBubbleIn 0.3s ease-out;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.zd-agent-lead-form__title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #334155;
    margin: 0 0 10px;
}

.zd-agent-lead-form__field {
    margin-bottom: 8px;
}

.zd-agent-lead-form__field input {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.zd-agent-lead-form__field input:focus {
    border-color: var(--zda-c1);
}

.zd-agent-lead-form__submit {
    width: 100%;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: var(--zda-gradient);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.zd-agent-lead-form__submit:hover {
    opacity: 0.9;
}

.zd-agent-lead-form__submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.zd-agent-lead-form__error {
    color: #dc2626;
    font-size: 0.72rem;
    margin-top: 4px;
}

/* ── Pre-chat Intro Form ── */
.zd-agent-prechat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 28px 20px 20px;
    height: 100%;
    box-sizing: border-box;
}

.zd-agent-prechat__icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--zda-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.zd-agent-prechat__icon i {
    font-size: 1.3rem;
    color: #fff;
}

.zd-agent-prechat__title {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 4px;
}

.zd-agent-prechat__sub {
    font-size: 0.78rem;
    color: #64748b;
    line-height: 1.5;
    margin-bottom: 20px;
}

.zd-agent-prechat__field {
    width: 100%;
    margin-bottom: 10px;
}

.zd-agent-prechat__field input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.86rem;
    font-family: inherit;
    outline: none;
    background: #f8fafc;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.zd-agent-prechat__field input:focus {
    border-color: var(--zda-c1);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
    background: #fff;
}

.zd-agent-prechat__btn {
    width: 100%;
    padding: 11px 20px;
    border: none;
    border-radius: 10px;
    background: var(--zda-gradient);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 4px;
    transition: opacity 0.15s ease, transform 0.15s ease;
    box-shadow: 0 4px 14px rgba(108, 99, 255, 0.25);
}

.zd-agent-prechat__btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

.zd-agent-prechat__btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.zd-agent-prechat__error {
    color: #dc2626;
    font-size: 0.72rem;
    margin-top: 8px;
    min-height: 1em;
}

/* ── FAB "Hi!!" Badge ── */
.zd-agent-fab__hi {
    position: absolute;
    top: -6px;
    right: -8px;
    background: #ff6b6b;
    color: #fff;
    font-size: 0.58rem;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 10px;
    line-height: 1.2;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.4);
    pointer-events: none;
    animation: zdHiBounce 2s ease-in-out infinite;
}

@keyframes zdHiBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1) rotate(-3deg); }
}

.zd-agent-fab--hidden .zd-agent-fab__hi { display: none; }

/* ── Left-positioned variant ── */
.zd-agent-fab.zd-agent--left {
    right: auto;
    left: 24px;
}

.zd-agent-chat.zd-agent--left {
    right: auto;
    left: 24px;
}

/* ── Responsive: Mobile (full-screen bottom sheet) ── */
@media (max-width: 480px) {
    .zd-agent-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.1rem;
    }

    .zd-agent-fab.zd-agent--left {
        right: auto;
        left: 16px;
    }

    .zd-agent-chat {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .zd-agent-bubble { max-width: 90%; }
}

/* ── Responsive: Tablet ── */
@media (min-width: 481px) and (max-width: 768px) {
    .zd-agent-chat {
        width: 350px;
        height: 520px;
        bottom: 20px;
        right: 20px;
    }
}
