/* DataTrade Chat Widget — v1.1 */

:root {
    --dt-primary:   #0088CC;
    --dt-primary-d: #006fa3;
    --dt-primary-l: #e8f4fb;
    --dt-bg:        #ffffff;
    --dt-bubble-in: #f0f4f8;
    --dt-text:      #1a2332;
    --dt-muted:     #6b7a8d;
    --dt-radius:    14px;
    --dt-shadow:    0 8px 32px rgba(0,136,204,0.18), 0 2px 8px rgba(0,0,0,0.10);
    --dt-font:      'DM Sans', 'Segoe UI', system-ui, sans-serif;
    /* Offset per la sticky bar WooCommerce su mobile — cambia se la tua barra è diversa */
    --dt-sticky-bar-height: 60px;
}

/* ── BUBBLE ─────────────────────────────────────────────────── */
#dt-chat-bubble {
    position: fixed;
    bottom: 78px;
    right: 18px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--dt-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 99999;
    box-shadow: 0 4px 20px rgba(0,136,204,0.40);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
}
#dt-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0,136,204,0.55);
}
#dt-chat-bubble:active { transform: scale(0.95); }

#dt-chat-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: #e53935;
    border-radius: 50%;
    color: white;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    font-family: var(--dt-font);
}

/* ── PANEL ──────────────────────────────────────────────────── */
#dt-chat-panel {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 640px;
    max-height: calc(100vh - 120px);
    background: var(--dt-bg);
    border-radius: var(--dt-radius);
    box-shadow: var(--dt-shadow);
    display: none;
    flex-direction: column;
    z-index: 99998;
    overflow: hidden;
    font-family: var(--dt-font);
    animation: dtSlideUp 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
#dt-chat-panel.open { display: flex; }

@keyframes dtSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ── HEADER ─────────────────────────────────────────────────── */
#dt-chat-header {
    background: var(--dt-primary);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#dt-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
#dt-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
#dt-chat-header-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: white;
}
#dt-chat-header-status {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.80);
    margin-top: 1px;
}
#dt-chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.85);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s;
}
#dt-chat-close:hover { background: rgba(255,255,255,0.15); color: white; }

/* ── MESSAGES ───────────────────────────────────────────────── */
#dt-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f7f9fc;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
#dt-chat-messages::-webkit-scrollbar { width: 4px; }
#dt-chat-messages::-webkit-scrollbar-thumb { background: #cdd6e0; border-radius: 4px; }

.dt-msg {
    max-width: 82%;
    padding: 10px 13px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    animation: dtFadeIn 0.2s ease;
}
@keyframes dtFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.dt-msg-bot {
    background: white;
    color: var(--dt-text);
    margin-right: auto;
    border-bottom-left-radius: 3px;
    border: 1px solid #e8edf2;
}
.dt-msg-user {
    background: var(--dt-primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 3px;
}
.dt-msg-time {
    font-size: 0.65rem;
    opacity: 0.55;
    margin-top: 4px;
    text-align: right;
}
.dt-msg-bot .dt-msg-time { text-align: left; }

/* Link nei messaggi bot */
.dt-msg-bot a {
    color: var(--dt-primary);
    text-decoration: underline;
    word-break: break-all;
}

/* Welcome card */
.dt-welcome {
    background: white;
    border: 1px solid #e8edf2;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    margin-bottom: 4px;
}
.dt-welcome-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--dt-primary-l);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
}
.dt-welcome h3 { font-size: 0.95rem; font-weight: 700; color: var(--dt-text); margin: 0 0 4px; }
.dt-welcome p  { font-size: 0.8rem; color: var(--dt-muted); margin: 0; line-height: 1.4; }

/* Quick replies */
.dt-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.dt-quick-reply {
    background: white;
    border: 1.5px solid var(--dt-primary);
    color: var(--dt-primary);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--dt-font);
}
.dt-quick-reply:hover { background: var(--dt-primary); color: white; }

/* Typing indicator */
#dt-chat-typing {
    padding: 10px 14px;
    background: #f7f9fc;
    flex-shrink: 0;
}
#dt-chat-typing span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dt-primary);
    margin: 0 2px;
    animation: dtBounce 1.2s infinite;
    opacity: 0.7;
}
#dt-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
#dt-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dtBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-5px); }
}

/* ── INPUT ──────────────────────────────────────────────────── */
#dt-chat-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    border-top: 1px solid #eaeff4;
    flex-shrink: 0;
}
#dt-chat-input {
    flex: 1;
    border: 1.5px solid #dde3ea;
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 0.875rem;
    font-family: var(--dt-font);
    outline: none;
    color: var(--dt-text);
    background: #f7f9fc;
    transition: border-color 0.15s, background 0.15s;
}
#dt-chat-input:focus {
    border-color: var(--dt-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(0,136,204,0.10);
}
#dt-chat-input::placeholder { color: #a0aab4; }
#dt-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--dt-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}
#dt-chat-send:hover  { background: var(--dt-primary-d); }
#dt-chat-send:active { transform: scale(0.92); }
#dt-chat-send:disabled { background: #b0c4d4; cursor: default; }
#dt-chat-send svg,
#dt-chat-send svg path {
    fill: white !important;
    color: white !important;
    display: block;
    pointer-events: none;
}
/* Carattere unicode freccia invio */
#dt-chat-send {
    color: white !important;
    font-size: 18px !important;
    line-height: 1 !important;
    text-align: center !important;
}

/* ── FOOTER ─────────────────────────────────────────────────── */
#dt-chat-footer {
    text-align: center;
    font-size: 0.68rem;
    color: #b0b8c1;
    padding: 5px 0 7px;
    background: white;
    flex-shrink: 0;
}
#dt-chat-footer strong { color: var(--dt-primary); }

/* ── ESCALATION CARD ─────────────────────────────────────────── */
.dt-escalation-card {
    background: #e8f4fb;
    border: 1.5px solid var(--dt-primary);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.82rem;
    color: var(--dt-text);
    line-height: 1.5;
}
.dt-escalation-card strong { color: var(--dt-primary); }

/* ── MOBILE ─────────────────────────────────────────────────── */
@media (max-width: 480px) {

    /* Bubble: sopra la sticky bar del carrello WooCommerce */
    #dt-chat-bubble {
        bottom: calc(var(--dt-sticky-bar-height) + 60px);
        right: 16px;
        width: 52px;
        height: 52px;
    }

    /* Panel: occupa tutto lo schermo sopra la sticky bar */
    #dt-chat-panel {
        bottom: var(--dt-sticky-bar-height);
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        /* Altezza = tutto lo spazio disponibile sopra la sticky bar */
        height: calc(100dvh - var(--dt-sticky-bar-height));
        max-height: calc(100dvh - var(--dt-sticky-bar-height));
        border-radius: var(--dt-radius) var(--dt-radius) 0 0;
    }

    /* Header leggermente più alto su mobile */
    #dt-chat-header {
        padding: 16px;
    }

    /* Input 16px per evitare zoom automatico su iOS */
    #dt-chat-input {
        font-size: 16px;
        padding: 11px 16px;
    }

    /* Messaggio a tutta larghezza su schermi piccoli */
    .dt-msg {
        max-width: 88%;
        font-size: 0.925rem;
    }

    /* Offset simbolo iubenda (lucchetto privacy) — di solito 30px */
    #dt-chat-footer {
        padding-bottom: 36px;
    }
}

/* Supporto per telefoni con notch/Dynamic Island */
@supports (height: 100dvh) {
    @media (max-width: 480px) {
        #dt-chat-panel {
            height: calc(100dvh - var(--dt-sticky-bar-height));
            max-height: calc(100dvh - var(--dt-sticky-bar-height));
        }
    }
}
