/* TiendaPocket Chatbot Widget */

:root {
    --tpc-primary: #6C63FF;
    --tpc-primary-dark: #5a52d5;
    --tpc-bg: #ffffff;
    --tpc-bg-user: #f0eeff;
    --tpc-text: #1a1a2e;
    --tpc-text-light: #6b7280;
    --tpc-border: #e5e7eb;
    --tpc-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    --tpc-radius: 16px;
}

/* ── Bubble trigger ── */
.tpc-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tpc-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--tpc-shadow);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.tpc-bubble:hover {
    transform: scale(1.08);
    background: var(--tpc-primary-dark);
}

/* Entry animation */
.tpc-bubble--entrance {
    animation: tpc-bubble-entrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tpc-bubble-entrance {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

.tpc-bubble svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.tpc-bubble--close .tpc-bubble-icon-chat {
    display: none;
}

.tpc-bubble--close .tpc-bubble-icon-close {
    display: block;
}

.tpc-bubble-icon-close {
    display: none;
}

/* Online indicator dot on bubble */
.tpc-bubble-online {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: #25D366;
    border: 2px solid #fff;
    border-radius: 50%;
    pointer-events: none;
}

.tpc-bubble--close .tpc-bubble-online {
    display: none;
}

/* ── Chat window ── */
.tpc-chat {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-height: 600px;
    background: var(--tpc-bg);
    border-radius: var(--tpc-radius);
    box-shadow: var(--tpc-shadow);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--tpc-text);
}

.tpc-chat--open {
    display: flex;
}

/* ── Header ── */
.tpc-chat__header {
    background: var(--tpc-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.tpc-chat__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tpc-chat__avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

.tpc-chat__title {
    font-weight: 600;
    font-size: 15px;
}

.tpc-chat__subtitle {
    font-size: 12px;
    opacity: 0.8;
}

.tpc-chat__share-btn {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 13px;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    flex-shrink: 0;
}

.tpc-chat__share-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.28);
}

.tpc-chat__new-btn {
    margin-left: 0;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    padding: 4px 10px;
    font-size: 11px;
    opacity: 0.85;
    transition: opacity 0.2s, background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.tpc-chat__new-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.28);
}

/* ── Messages ── */
.tpc-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 250px;
    max-height: 420px;
}

.tpc-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    animation: tpc-msg-in 0.3s ease-out;
}

@keyframes tpc-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tpc-msg--bot {
    background: var(--tpc-border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.tpc-msg--user {
    background: var(--tpc-bg-user);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.tpc-msg--warning {
    background: #fff8e1;
    color: #7a5c00;
    border: 1px solid #ffe082;
    font-size: 13px;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.tpc-msg--typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
}

.tpc-msg--typing span:not(.tpc-typing-label):not(.tpc-sr-only) {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    background: var(--tpc-text-light);
    border-radius: 50%;
    animation: tpc-bounce 1.2s infinite;
}

.tpc-msg--typing span:not(.tpc-typing-label):not(.tpc-sr-only):nth-child(2) {
    animation-delay: 0.15s;
}

.tpc-msg--typing span:not(.tpc-typing-label):not(.tpc-sr-only):nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes tpc-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.tpc-typing-label {
    font-size: 11px;
    color: var(--tpc-text-light);
    margin-left: 4px;
    line-height: 1;
    animation: tpc-fade-in 0.3s ease;
}

@keyframes tpc-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Product cards (carousel) ── */
.tpc-products-wrap {
    position: relative;
    padding: 0 2px; /* prevent arrow clipping */
    min-height: 210px;
    overflow: visible;
}

.tpc-products {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    padding: 8px 2px 4px;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: stretch;
}

.tpc-products::-webkit-scrollbar {
    display: none;
}

.tpc-products-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tpc-bg);
    border: 1px solid var(--tpc-border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--tpc-text);
    z-index: 2;
    transition: background 0.2s, opacity 0.2s;
    opacity: 0;
    pointer-events: none;
}

.tpc-products-wrap:hover .tpc-products-arrow {
    opacity: 1;
    pointer-events: auto;
}

.tpc-products-arrow:hover {
    background: var(--tpc-border);
}

.tpc-products-arrow--left {
    left: 0;
}

.tpc-products-arrow--right {
    right: 0;
}

.tpc-product-card {
    flex: 0 0 150px !important;
    scroll-snap-align: start;
    border: 1px solid var(--tpc-border);
    border-radius: 10px;
    overflow: visible !important;
    text-decoration: none;
    color: var(--tpc-text);
    background: var(--tpc-bg);
    transition: box-shadow 0.2s;
    display: flex !important;
    flex-direction: column !important;
    min-height: unset !important;
    height: auto !important;
}

.tpc-product-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tpc-product-card__img-wrap {
    display: block;
    flex-shrink: 0;
    width: 100%;
    height: 90px;
    overflow: hidden;
    border-radius: 9px 9px 0 0;
    line-height: 0;
}

.tpc-product-card__img-wrap img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    max-width: 100% !important;
}

.tpc-product-card__info {
    padding: 8px;
    flex: 1;
}

.tpc-product-card__name {
    font-size: 12px;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tpc-product-card__price {
    font-size: 13px;
    font-weight: 700;
    color: var(--tpc-primary);
    margin-top: 4px;
}

.tpc-product-card__cart-btn {
    display: block;
    width: calc(100% - 16px);
    margin: 0 8px 8px;
    padding: 6px 0;
    border: 1px solid var(--tpc-primary);
    border-radius: 6px;
    background: transparent;
    color: var(--tpc-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.tpc-product-card__cart-btn:hover {
    background: var(--tpc-primary);
    color: #fff;
}

.tpc-product-card__cart-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Input area ── */
.tpc-chat__input {
    display: flex;
    padding: 12px;
    border-top: 1px solid var(--tpc-border);
    gap: 8px;
    flex-shrink: 0;
}

.tpc-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.tpc-char-count {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: var(--tpc-text-light);
    pointer-events: none;
    transition: color 0.2s;
}

.tpc-chat__input input {
    flex: 1;
    border: 1px solid var(--tpc-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.tpc-chat__input input:focus {
    border-color: var(--tpc-primary);
}

.tpc-chat__input input:disabled {
    background: #f3f4f6;
    color: var(--tpc-text-light);
    cursor: not-allowed;
    border-color: var(--tpc-border);
}

.tpc-chat__input button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--tpc-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.tpc-chat__input button:hover {
    background: var(--tpc-primary-dark);
}

.tpc-chat__input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tpc-chat__input button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ── WhatsApp link button ── */
.tpc-msg--whatsapp {
    background: transparent;
    padding: 4px 0;
    align-self: flex-start;
}

.tpc-whatsapp-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #25D366;
    color: #fff;
    text-decoration: none;
    padding: 10px 16px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.35);
}

.tpc-whatsapp-link:hover {
    background: #1ebe5d;
    transform: translateY(-1px);
    color: #fff;
    text-decoration: none;
}

.tpc-whatsapp-link svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    flex-shrink: 0;
}

/* ── Cart toast notification ── */
.tpc-cart-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: #2e7d32;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 999999;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    max-width: calc(100vw - 40px);
}

.tpc-cart-toast--visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.tpc-cart-toast svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    flex-shrink: 0;
}

/* ── Retry button ── */
.tpc-retry-btn {
    display: inline-block;
    margin-top: 4px;
    padding: 4px 12px;
    border: 1px solid #7a5c00;
    border-radius: 6px;
    background: transparent;
    color: #7a5c00;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.tpc-retry-btn:hover {
    background: #7a5c00;
    color: #fff;
}

/* ── Streaming cursor ── */
.tpc-msg--streaming::after {
    content: '\u258C';
    display: inline;
    animation: tpc-blink 0.7s steps(2) infinite;
    color: var(--tpc-primary);
    font-weight: 700;
}

/* ── Map card (Google Maps link preview) ── */
.tpc-map-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin: 6px 0;
    background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 100%);
    border: 1px solid #c8e6c9;
    border-radius: 10px;
    text-decoration: none !important;
    color: #2e7d32 !important;
    transition: transform 0.15s, box-shadow 0.15s;
    cursor: pointer;
}
.tpc-map-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(46,125,50,0.2);
}
.tpc-map-card__pin {
    font-size: 20px;
    flex-shrink: 0;
}
.tpc-map-card__label {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}
.tpc-map-card__arrow {
    font-size: 16px;
    font-weight: 700;
    opacity: 0.6;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.tpc-map-card:hover .tpc-map-card__arrow {
    transform: translateX(3px);
    opacity: 1;
}

/* ── Escalation banner (sentiment detection) ── */
.tpc-escalation-banner {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: #fff;
    padding: 14px 16px;
    border-radius: 12px;
    margin: 8px 40px 8px 8px;
    font-size: 14px;
    line-height: 1.5;
    animation: tpc-escalation-in 0.4s ease-out;
}
.tpc-escalation-banner p {
    margin: 0 0 10px 0;
}
.tpc-escalation-banner .tpc-escalation-icon {
    font-size: 20px;
    margin-right: 6px;
    vertical-align: middle;
}
.tpc-escalation-banner .tpc-escalation-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    color: #e65100;
    font-weight: 700;
    font-size: 14px;
    padding: 8px 18px;
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    border: none;
    cursor: pointer;
}
.tpc-escalation-banner .tpc-escalation-btn:hover {
    background: #fff3e0;
    transform: scale(1.03);
}
@keyframes tpc-escalation-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes tpc-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Screen-reader only (accessibility) ── */
.tpc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Reaction buttons (thumbs up/down) ── */
.tpc-reactions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    align-self: flex-start;
}

.tpc-reaction-btn {
    background: transparent;
    border: 1px solid var(--tpc-border);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 14px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s, border-color 0.2s;
    line-height: 1;
}

.tpc-reaction-btn:hover {
    opacity: 1;
    background: var(--tpc-bg-user);
}

.tpc-reaction-btn--selected {
    opacity: 1;
    border-color: var(--tpc-primary);
    background: var(--tpc-bg-user);
}

.tpc-reaction-btn--dimmed {
    opacity: 0.25;
    pointer-events: none;
}

/* ── Mobile responsive ── */
@media (max-width: 480px) {
    .tpc-chat {
        width: calc(100vw - 16px);
        right: 8px;
        bottom: 90px;
        max-height: calc(100vh - 110px);
    }

    .tpc-bubble {
        bottom: 16px;
        right: 16px;
    }
}

/* ── Read receipt (double check) ── */
.tpc-read-receipt {
    align-self: flex-end;
    font-size: 12px;
    color: var(--tpc-primary);
    margin-top: -8px;
    margin-bottom: -4px;
    letter-spacing: -2px;
    animation: tpc-fade-in 0.3s ease;
}

/* ── Proactive tooltip on bubble ── */
.tpc-bubble-tooltip {
    position: absolute;
    bottom: 70px;
    right: 0;
    background: var(--tpc-bg);
    color: var(--tpc-text);
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--tpc-shadow);
    animation: tpc-tooltip-in 0.4s ease-out;
    pointer-events: none;
}

.tpc-bubble-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 20px;
    width: 12px;
    height: 12px;
    background: var(--tpc-bg);
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.06);
}

@keyframes tpc-tooltip-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Smart cart summary bubble ── */
.tpc-msg--cart-summary {
    background: #f0f7ff;
    border: 1px solid #bbd4f0;
    font-size: 13px;
    line-height: 1.6;
}

/* ── Quick reply buttons ── */
.tpc-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 12px 8px;
}

.tpc-quick-reply {
    background: transparent;
    border: 1.5px solid var(--tpc-primary, #6C63FF);
    color: var(--tpc-primary, #6C63FF);
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-family: inherit;
    line-height: 1.3;
}

.tpc-quick-reply:hover {
    background: var(--tpc-primary, #6C63FF);
    color: #fff;
}
