/* =========================================================
   TAGO Dhencio Chat Widget
   Floating chat button + window
   ========================================================= */

/* ---------- FLOATING BUTTON ---------- */
.dhencio-button {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 100px;
    height: 100px;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    cursor: pointer;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: visible;
}

.dhencio-button:hover {
    transform: scale(1.08);
    filter: drop-shadow(0 8px 28px rgba(0,0,0,0.45));
}

.dhencio-button:active {
    transform: scale(0.98);
}

.dhencio-button img {
    width: 80%;
    height: 80%;
    object-fit: contain;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.35));
}

.dhencio-button.active {
    /* When chat window is open, hide the button entirely */
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.dhencio-button {
    /* Smooth transition when hiding/showing */
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.dhencio-pulse {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #EF4444;
    border: 2px solid #1A2332;
    border-radius: 50%;
    display: none;
    animation: dhencioPulse 1.6s infinite;
}

@keyframes dhencioPulse {
    0%, 100% { transform: scale(1);   opacity: 1; }
    50%      { transform: scale(1.25); opacity: 0.7; }
}

/* ---------- CHAT WINDOW ---------- */
.dhencio-window {
    position: fixed;
    bottom: 148px;
    right: 16px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 180px);
    background: #FFFFFF;
    border-radius: 18px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.35);
    z-index: 9001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.dhencio-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---------- HEADER ---------- */
.dhencio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #1A2332;
    color: #FFFFFF;
    flex-shrink: 0;
}

.dhencio-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.dhencio-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid #1e293b;
    font-size: 20px;
}

.dhencio-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.dhencio-header-text {
    min-width: 0;
}

.dhencio-header-name {
    font-size: 15px;
    font-weight: 800;
    color: #F5B041;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.dhencio-header-tagline {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dhencio-close {
    background: transparent;
    border: none;
    color: #FFFFFF;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
    transition: background 0.15s;
    flex-shrink: 0;
}

.dhencio-close:hover {
    background: rgba(255,255,255,0.1);
}

/* ---------- MESSAGES ---------- */
.dhencio-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #F5F7FA;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.dhencio-messages::-webkit-scrollbar {
    width: 6px;
}

.dhencio-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

/* ---------- WELCOME SCREEN ---------- */
.dhencio-welcome {
    padding: 6px 0;
}

.dhencio-welcome-msg {
    background: #FFFFFF;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.6;
    color: #1A2332;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    margin-bottom: 16px;
}

.dhencio-openers-label {
    font-size: 11px;
    font-weight: 800;
    color: #6B7280;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 8px;
    padding: 0 4px;
}

.dhencio-openers {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dhencio-opener {
    background: #FFFFFF;
    border: 1.5px solid #E5E7EB;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #1A2332;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: all 0.15s;
}

.dhencio-opener:hover {
    border-color: #F5B041;
    background: #FFFBEB;
    color: #1A2332;
}

/* ---------- MESSAGE BUBBLES ---------- */
.dhencio-msg {
    display: flex;
    max-width: 90%;
}

.dhencio-msg-user {
    align-self: flex-end;
    justify-content: flex-end;
}

.dhencio-msg-bot {
    align-self: flex-start;
}

.dhencio-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.dhencio-msg-user .dhencio-bubble {
    background: #3B82F6;
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.dhencio-msg-bot .dhencio-bubble {
    background: #FFFFFF;
    color: #1A2332;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.dhencio-msg-bot .dhencio-bubble a {
    color: #3B82F6;
    text-decoration: underline;
    word-break: break-all;
}

/* ---------- RICH TEXT INSIDE BUBBLES ---------- */
.dhencio-bubble strong {
    font-weight: 800;
    color: #1A2332;
}

.dhencio-bubble em {
    font-style: italic;
}

.dhencio-bubble ul,
.dhencio-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}

.dhencio-bubble li {
    margin: 3px 0;
    line-height: 1.5;
}

.dhencio-bubble code {
    background: #F3F4F6;
    color: #1A2332;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.dhencio-bubble pre {
    background: #1A2332;
    color: #F5B041;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
    line-height: 1.5;
}

.dhencio-bubble pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: 12px;
}

/* User bubbles do not use light-theme bold */
.dhencio-msg-user .dhencio-bubble strong {
    color: #FFFFFF;
}

.dhencio-msg-user .dhencio-bubble code {
    background: rgba(255,255,255,0.2);
    color: #FFFFFF;
}

/* ---------- TABLES IN CHAT ---------- */
.dhencio-table-wrap {
    width: 100%;
    overflow-x: auto;
    margin: 8px 0;
    border-radius: 10px;
    border: 1px solid #E5E7EB;
    background: #FFFFFF;
}

.dhencio-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    min-width: 100%;
}

.dhencio-table th {
    background: #1A2332;
    color: #FFFFFF;
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 8px 10px;
    text-align: left;
    white-space: nowrap;
}

.dhencio-table td {
    padding: 8px 10px;
    border-top: 1px solid #F3F4F6;
    color: #374151;
    vertical-align: top;
    white-space: nowrap;
}

.dhencio-table tr:nth-child(even) td {
    background: #F9FAFB;
}

.dhencio-table strong {
    color: #1A2332;
    font-weight: 800;
}

/* ---------- THINKING INDICATOR ---------- */
.dhencio-bubble.dhencio-thinking {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
    min-width: 48px;
    justify-content: center;
}

.dhencio-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9CA3AF;
    display: inline-block;
    animation: dhencioDot 1.4s infinite ease-in-out;
}

.dhencio-dot:nth-child(1) { animation-delay: 0s;    }
.dhencio-dot:nth-child(2) { animation-delay: 0.2s;  }
.dhencio-dot:nth-child(3) { animation-delay: 0.4s;  }

@keyframes dhencioDot {
    0%, 80%, 100% {
        transform: scale(0.65);
        opacity: 0.35;
        background: #9CA3AF;
    }
    40% {
        transform: scale(1.05);
        opacity: 1;
        background: #F5B041;
    }
}

/* ---------- INPUT BAR ---------- */
.dhencio-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #FFFFFF;
    border-top: 1px solid #E5E7EB;
    flex-shrink: 0;
}

.dhencio-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #E5E7EB;
    border-radius: 24px;
    font-size: 13px;
    font-family: inherit;
    color: #1A2332;
    background: #F9FAFB;
    min-height: 40px;
    transition: border-color 0.15s, background 0.15s;
    outline: none;
}

.dhencio-input:focus {
    border-color: #F5B041;
    background: #FFFFFF;
}

.dhencio-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #F5B041;
    color: #1A2332;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.dhencio-send:hover {
    background: #D89420;
    transform: scale(1.05);
}

.dhencio-send:active {
    transform: scale(0.95);
}

.dhencio-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 480px) {
    .dhencio-window {
        bottom: 76px;
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        height: 70vh;
        max-height: 600px;
        border-radius: 16px;
    }

    .dhencio-button {
        bottom: 80px;
        right: 12px;
        width: 52px;
        height: 52px;
    }
}

/* =========================================================
   CART POPUP OVERRIDE
   When the cart is open, hide Dhencio so it does not block
   the Total amount or the Proceed to Checkout button.
   The body class .tago-cart-open is toggled by dhencio.js.
   ========================================================= */
body.tago-cart-open .dhencio-button,
body.tago-cart-open .dhencio-window {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

/* Also bump the cart popup above Dhencio just in case both are shown */
body.tago-cart-open .cart-popup,
body.tago-cart-open #cartPopup {
    z-index: 99999 !important;
}

/* =========================================================
   LONG-PRESS PREVIEW
   When the user holds the Dhencio button for ~600ms, show
   a large centered preview of the avatar.
   ========================================================= */
.dhencio-preview {
    position: fixed;
    inset: 0;
    background: rgba(26, 35, 50, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 24px;
    animation: dhencioPreviewIn 0.22s ease;
}

.dhencio-preview.show {
    display: flex;
}

@keyframes dhencioPreviewIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.dhencio-preview-img {
    max-width: min(70vw, 420px);
    max-height: min(70vh, 420px);
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 20px 60px rgba(0,0,0,0.5));
    animation: dhencioPreviewZoom 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dhencioPreviewZoom {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.dhencio-preview-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #FFFFFF;
    border: none;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.dhencio-preview-close:hover {
    background: rgba(255,255,255,0.25);
}

.dhencio-preview-hint {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
}