/* ==========================================================================
   CS AI Chat — Self-contained styles matching cs-theme design tokens.
   ========================================================================== */

@property --cs-glow-angle {
    syntax: "<angle>";
    initial-value: 45deg;
    inherits: false;
}

:root {
    --cs-chat-primary: #ffe800;
    --cs-chat-dark: #000000;
    --cs-chat-dark-100: #1a1a1a;
    --cs-chat-dark-200: #141414;
    --cs-chat-body: #777;
    --cs-chat-bg: #f4f4f4;
    --cs-chat-radius: 16px;
    --cs-chat-font: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ---------- Shared chat container ---------- */

.cs-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    font-family: var(--cs-chat-font);
    font-size: 14px;
    line-height: 1.5;
    color: #fff;
    background: var(--cs-chat-dark);
    border-radius: var(--cs-chat-radius);
    overflow: hidden;
}

.cs-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: var(--cs-chat-dark-200);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.cs-chat-header-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cs-chat-primary);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.cs-chat-header-icon svg {
    width: 18px;
    height: 18px;
    color: #000;
}

.cs-chat-header-title {
    font-weight: 700;
    font-size: 15px;
    color: #fff;
}

.cs-chat-header-subtitle {
    font-size: 12px;
    color: var(--cs-chat-body);
}

.cs-chat-header-close,
.cs-chat-header-expand,
.cs-chat-header-clear {
    background: none;
    border: none;
    color: var(--cs-chat-body);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.15s;
}

/* "Vaciar chat" is the first action button → pushes the group to the right */
.cs-chat-header-clear { margin-left: auto; }
.cs-chat-header-clear + .cs-chat-header-expand,
.cs-chat-header-clear + .cs-chat-header-close,
.cs-chat-header-expand + .cs-chat-header-close { margin-left: 4px; }

.cs-chat-header-close:hover,
.cs-chat-header-expand:hover,
.cs-chat-header-clear:hover {
    color: #fff;
}

.cs-chat-header-expand svg,
.cs-chat-header-clear svg {
    width: 18px;
    height: 18px;
}

/* ---------- Messages area ---------- */

.cs-chat-messages-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.cs-chat-messages {
    position: relative;
    z-index: 2;
    height: 100%;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.cs-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.cs-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

/* ---------- Glow orbs (thinking/streaming) ---------- */

.cs-chat-glow {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.25s ease-out;
    pointer-events: none;
}

.cs-chat-glow.is-active {
    opacity: 1;
    transition: opacity 0.2s ease-in;
}

.cs-chat-glow-orb {
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    filter: blur(70px);
    mix-blend-mode: screen;
    transform: translate3d(0,0,0);
    will-change: transform, opacity;
}

.cs-chat-glow-blue {
    background: radial-gradient(circle, rgba(26,115,232,0.8) 0%, transparent 70%);
    top: -40px;
    left: 5%;
    animation: csGlowBlue 2s ease infinite alternate;
}

.cs-chat-glow-purple {
    background: radial-gradient(circle, rgba(124,77,255,0.8) 0%, transparent 70%);
    bottom: -40px;
    right: 5%;
    animation: csGlowPurple 2.4s ease infinite alternate;
}

.cs-chat-glow-pink {
    background: radial-gradient(circle, rgba(255,64,129,0.7) 0%, transparent 70%);
    top: 30%;
    left: 25%;
    animation: csGlowPink 1.6s ease infinite alternate;
}

@keyframes csGlowBlue {
    0%   { transform: translate3d(0,0,0) scale(0.85); opacity: 0.4; }
    100% { transform: translate3d(150px,90px,0) scale(1.3); opacity: 0.9; }
}

@keyframes csGlowPurple {
    0%   { transform: translate3d(0,0,0) scale(1.3); opacity: 0.8; }
    100% { transform: translate3d(-130px,-110px,0) scale(0.75); opacity: 0.3; }
}

@keyframes csGlowPink {
    0%   { transform: translate3d(0,0,0) scale(0.9); opacity: 0.5; }
    100% { transform: translate3d(120px,-70px,0) scale(1.4); opacity: 0.95; }
}

/* ---------- Messages ---------- */

.cs-chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 14px;
    word-wrap: break-word;
    animation: csChatFadeIn 0.2s ease-out;
}

.cs-chat-msg-user {
    align-self: flex-end;
    background: var(--cs-chat-primary);
    color: #000;
    border-bottom-right-radius: 4px;
}

.cs-chat-msg-ai {
    align-self: flex-start;
    background: var(--cs-chat-dark-100);
    color: #e5e5e5;
    border-bottom-left-radius: 4px;
}

.cs-chat-msg-ai p {
    margin: 0 0 8px;
}

.cs-chat-msg-ai p:last-child {
    margin-bottom: 0;
}

.cs-chat-msg-ai strong,
.cs-chat-msg-ai b {
    color: #fff;
    font-weight: 600;
}

.cs-chat-msg-ai a {
    color: var(--cs-chat-primary);
    text-decoration: underline;
}

/* Inline "Ver producto" link rendered as a yellow pill */
.cs-chat-msg-ai a.cs-chat-link-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--cs-chat-primary);
    color: #000 !important;
    text-decoration: none !important;
    font-weight: 700;
    font-size: 12px;
    line-height: 1.2;
    padding: 3px 11px;
    border-radius: 999px;
    vertical-align: middle;
    white-space: nowrap;
    transition: background 0.15s, transform 0.1s;
}
.cs-chat-msg-ai a.cs-chat-link-pill:hover { background: #fff; }
.cs-chat-msg-ai a.cs-chat-link-pill:active { transform: scale(0.97); }

.cs-chat-msg-ai a.cs-chat-wa-pill {
    color: #000 !important;
    text-decoration: none !important;
    background: var(--cs-chat-primary) !important;
}

.cs-chat-msg-ai ul,
.cs-chat-msg-ai ol {
    margin: 4px 0 8px 20px;
    padding: 0;
}

.cs-chat-msg-ai li {
    margin-bottom: 4px;
}

/* Typing indicator */
.cs-chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--cs-chat-dark-100);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.cs-chat-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cs-chat-body);
    animation: csChatBounce 1.2s infinite;
}

.cs-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.cs-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

/* ---------- Quick-access suggestion pills (bar above the input) ---------- */

.cs-chat-suggest-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 16px 2px;
    flex-shrink: 0;
    scrollbar-width: none;
    animation: csChatFadeIn 0.2s ease-out;
}
.cs-chat-suggest-bar:empty { display: none; }
.cs-chat-suggest-bar::-webkit-scrollbar { display: none; }

.cs-chat-suggestion {
    flex-shrink: 0;
    white-space: nowrap;
    font-family: var(--cs-chat-font);
    font-size: 12.5px;
    font-weight: 600;
    color: #fff;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 999px;
    padding: 7px 14px;
    cursor: pointer;
    line-height: 1.2;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.cs-chat-suggestion:hover {
    background: var(--cs-chat-primary);
    color: #000;
    border-color: var(--cs-chat-primary);
}
.cs-chat-suggestion:active { transform: scale(0.97); }

/* Light theme (home box) */
.cs-chat-home-container .cs-chat-suggestion {
    color: #16181d;
    background: #fff;
    border-color: #e0e0e0;
}
.cs-chat-home-container .cs-chat-suggestion:hover {
    background: var(--cs-chat-primary);
    color: #000;
    border-color: var(--cs-chat-primary);
}

/* ---------- Product cards ---------- */

.cs-chat-products {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 0 8px;
    scrollbar-width: none;
    /* Constrain to the chat width so the inner cards scroll horizontally
       instead of overflowing and getting clipped in the narrow bubble panel. */
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-self: stretch;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

.cs-chat-products .cs-chat-product-card {
    scroll-snap-align: start;
}

.cs-chat-products::-webkit-scrollbar {
    display: none;
}

.cs-chat-product-card {
    display: flex;
    flex-direction: column;
    min-width: 160px;
    max-width: 180px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: #222;
    flex-shrink: 0;
    transition: box-shadow 0.2s, transform 0.2s;
}

.cs-chat-product-card:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

.cs-chat-product-link {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: #222;
}

.cs-chat-product-media {
    position: relative;
}

.cs-chat-product-card img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    background: #f8f8f8;
    padding: 8px;
    display: block;
}

.cs-chat-product-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #e74c3c;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 3px 8px;
    border-radius: 999px;
    z-index: 2;
}

/* Out-of-stock card: dim image */
.cs-chat-product-card.is-oos img {
    opacity: 0.55;
    filter: grayscale(0.35);
}

.cs-chat-product-info {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cs-chat-product-name {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #222;
}

.cs-chat-product-price {
    font-size: 14px;
    font-weight: 700;
    color: #000;
}

.cs-chat-product-sale {
    text-decoration: line-through;
    color: #999;
    font-size: 12px;
    font-weight: 400;
}

.cs-chat-product-cta {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #16181d;
    background: var(--cs-chat-primary);
    text-align: center;
    padding: 6px;
    margin: 0 12px 10px;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

/* Hover: yellow -> black bg, black -> white text */
.cs-chat-product-cta:hover {
    background: #16181d;
    color: #fff;
}

/* Out-of-stock CTA is neutral (overrides .is-oos rule above too) */
.cs-chat-product-card.is-oos .cs-chat-product-cta,
.cs-chat-product-card.is-oos .cs-chat-product-cta:hover,
.cs-chat-chip.is-oos .cs-chat-product-cta,
.cs-chat-chip.is-oos .cs-chat-product-cta:hover {
    background: #e5e5e5;
    color: #888;
}

/* Add-to-cart button (simple, in-stock products) */
.cs-chat-product-add {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: calc(100% - 24px);
    margin: 0 12px 10px;
    padding: 7px 6px;
    font-family: var(--cs-chat-font);
    font-size: 11px;
    font-weight: 700;
    color: #16181d;
    background: var(--cs-chat-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s, opacity 0.15s;
}

.cs-chat-product-add svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.cs-chat-product-add:hover { background: #16181d; color: #fff; }
.cs-chat-product-add:active { transform: scale(0.97); }
.cs-chat-product-add.is-loading { opacity: 0.7; cursor: default; }
.cs-chat-product-add.is-added { background: #25D366; color: #fff; }

/* ---------- Product cards vs compact chips (by container) ---------- */

/* Default = constrained containers (floating bubble + home box): use the
   compact chips, which are short and never clip. The full image cards are
   reserved for the full-page chat at /chat/, where there's vertical room. */
.cs-chat-products { display: none; }
.cs-chat-products-compact { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 8px; }

.cs-chat-fullpage .cs-chat-products { display: flex; }
.cs-chat-fullpage .cs-chat-products-compact { display: none; }

.cs-chat-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border-radius: 10px;
    padding: 9px 10px 9px 13px;
}
.cs-chat-chip.is-oos { opacity: 0.7; }
.cs-chat-chip-link {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}
.cs-chat-chip-link:hover .cs-chat-chip-name { text-decoration: underline; }
.cs-chat-chip-thumb {
    flex-shrink: 0;
    width: 46px; height: 46px;
    border-radius: 8px;
    background: #f4f4f5;
    overflow: hidden;
    display: grid;
    place-items: center;
}
.cs-chat-chip-thumb img { width: 100%; height: 100%; object-fit: contain; }
.cs-chat-chip-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.cs-chat-chip-name {
    font-size: 12px; font-weight: 600; color: #222; line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cs-chat-chip-price { font-size: 13px; font-weight: 700; color: #000; }

/* Action button/link inside a chip: compact, right-aligned, no card margins */
.cs-chat-chip-btn {
    flex-shrink: 0;
    width: auto !important;
    margin: 0 !important;
    padding: 8px 14px !important;
    border-radius: 8px !important;
    font-size: 11px;
    white-space: nowrap;
}

/* ---------- Order tracking cards (CS Seguimiento bridge) ---------- */

.cs-chat-orders {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 0 8px;
}

.cs-chat-order-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-left: 4px solid var(--cs-chat-primary);
    border-radius: 12px;
    padding: 12px 14px;
    color: #16181d;
    box-shadow: 0 2px 6px rgba(16, 24, 40, 0.06);
}
.cs-chat-order-card.is-done { border-left-color: #1a7f37; }

.cs-chat-order-head {
    display: flex;
    align-items: center;
    gap: 8px;
}
.cs-chat-order-pkg {
    flex-shrink: 0;
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: 7px;
    background: #16181d;
    color: var(--cs-chat-primary);
}
.cs-chat-order-pkg svg { width: 15px; height: 15px; }
.cs-chat-order-num {
    font-weight: 800;
    font-size: 13px;
    color: #16181d;
}
.cs-chat-order-badge {
    margin-left: auto;
    flex-shrink: 0;
    background: #16181d;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.cs-chat-order-card.is-done .cs-chat-order-badge { background: #1a7f37; }

.cs-chat-order-step {
    font-size: 12px;
    color: #374151;
    margin-top: 8px;
}
.cs-chat-order-step b { color: #16181d; font-weight: 700; }

.cs-chat-order-bar {
    height: 6px;
    border-radius: 999px;
    background: #ececef;
    overflow: hidden;
    margin-top: 6px;
}
.cs-chat-order-bar span {
    display: block;
    height: 100%;
    background: var(--cs-chat-primary);
    border-radius: 999px;
    transition: width 0.4s ease;
}
.cs-chat-order-card.is-done .cs-chat-order-bar span { background: #1a7f37; }

.cs-chat-order-meta {
    font-size: 11.5px;
    color: #6b7280;
    margin-top: 8px;
}
.cs-chat-order-carrier {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: #374151;
    margin-top: 6px;
}
.cs-chat-order-carrier svg { width: 14px; height: 14px; flex-shrink: 0; color: #6b7280; }
.cs-chat-order-shipment {
    font-size: 11px;
    color: #4b5563;
    margin: 3px 0 0 20px;
    line-height: 1.45;
}
.cs-chat-order-shipment a { color: #1565c0; text-decoration: underline; }

.cs-chat-order-btn {
    display: block;
    text-align: center;
    margin-top: 10px;
    padding: 8px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none !important;
    color: #16181d;
    background: var(--cs-chat-primary);
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
}
.cs-chat-order-btn:hover { background: #16181d; color: #fff; }

.cs-chat-order-notice {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
    font-size: 12.5px;
    line-height: 1.45;
    padding: 10px 12px;
    border-radius: 10px;
}

/* Neutral info notice (password resend / human escalation confirmation) */
.cs-chat-info-notice {
    align-self: flex-start;
    max-width: 90%;
    background: #eef6ff;
    border: 1px solid #cfe3ff;
    color: #1e40af;
    font-size: 12.5px;
    line-height: 1.45;
    padding: 10px 12px;
    border-radius: 10px;
}

/* ---------- WhatsApp pill (welcome message) ---------- */

.cs-chat-wa-pill {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    margin: 4px 2px;
    background: var(--cs-chat-primary) !important;
    color: #000 !important;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    border-radius: 20px;
    text-decoration: none !important;
    cursor: pointer;
    position: relative;
    z-index: 3;
    vertical-align: middle;
    transition: background 0.15s;
}

.cs-chat-wa-pill:hover {
    background: #fff !important;
    color: #000 !important;
}

.cs-chat-wa-pill svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    fill: #000;
}

/* ---------- WhatsApp button ---------- */

.cs-chat-wa-btn,
.cs-chat-mayorista-btn,
.cs-chat-seguimiento-btn,
.cs-chat-retiro-btn {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 8px;
    padding: 10px 20px;
    color: #fff;
    font-family: var(--cs-chat-font);
    font-size: 14px;
    font-weight: 600;
    border-radius: 24px;
    text-decoration: none;
    cursor: pointer;
    position: relative;
    z-index: 3;
    transition: background 0.15s, transform 0.15s;
    animation: csChatFadeIn 0.2s ease-out;
}

.cs-chat-wa-btn { background: #25D366; color: #fff !important; }
.cs-chat-wa-btn:hover { background: #1ebe57; color: #fff !important; transform: scale(1.03); }
.cs-chat-wa-btn:active { transform: scale(0.97); }

.cs-chat-mayorista-btn { background: var(--cs-chat-primary); color: #000; }
.cs-chat-mayorista-btn:hover { background: #e6d100; transform: scale(1.03); }
.cs-chat-mayorista-btn:active { transform: scale(0.97); }

.cs-chat-seguimiento-btn { background: #2271b1; color: #fff !important; }
.cs-chat-seguimiento-btn:hover { background: #1a5a8e; color: #fff !important; transform: scale(1.03); }
.cs-chat-seguimiento-btn:active { transform: scale(0.97); }

.cs-chat-retiro-btn { background: #e74c3c; color: #fff !important; }
.cs-chat-retiro-btn:hover { background: #c0392b; color: #fff !important; transform: scale(1.03); }
.cs-chat-retiro-btn:active { transform: scale(0.97); }

.cs-chat-wa-btn svg,
.cs-chat-mayorista-btn svg,
.cs-chat-seguimiento-btn svg,
.cs-chat-retiro-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* ---------- Input area ---------- */

.cs-chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px 12px 16px;
    background: var(--cs-chat-dark-200);
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.cs-chat-input-field {
    flex: 1;
    position: relative;
    min-width: 0;
}

.cs-chat-input-field::before,
.cs-chat-input-field::after {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: 25px;
    background: linear-gradient(var(--cs-glow-angle), #ffe800, #ffffff, #ffe800, #ffffff);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.cs-chat-input-field::before {
    z-index: 0;
}

.cs-chat-input-field::after {
    z-index: 0;
    filter: blur(10px);
}

.cs-chat-input-field.is-sent::before,
.cs-chat-input-field.is-sent::after {
    animation: csInputGlowRotate 0.6s linear, csInputGlowFade 0.6s ease forwards;
}

@keyframes csInputGlowRotate {
    from { --cs-glow-angle: 45deg; }
    to   { --cs-glow-angle: 405deg; }
}

@keyframes csInputGlowFade {
    0%   { opacity: 0; }
    20%  { opacity: 1; }
    60%  { opacity: 0.8; }
    100% { opacity: 0; }
}

.cs-chat-input {
    display: block;
    position: relative;
    z-index: 1;
    width: 100%;
    background: var(--cs-chat-dark-100);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 24px;
    padding: 10px 16px;
    color: #fff;
    font-family: var(--cs-chat-font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    line-height: 1.4;
    box-sizing: border-box;
}

.cs-chat-input::placeholder {
    color: var(--cs-chat-body);
}

.cs-chat-input:focus {
    border-color: var(--cs-chat-primary);
}

.cs-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--cs-chat-primary);
    color: #000;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
}

.cs-chat-send:hover {
    transform: scale(1.05);
}

.cs-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.cs-chat-send svg {
    width: 18px;
    height: 18px;
}

/* Honeypot */
.cs-chat-hp { position: absolute; left: -9999px; }

/* Disclaimer */
.cs-chat-disclaimer {
    text-align: center;
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    padding: 4px 16px 8px;
    background: var(--cs-chat-dark-200);
    flex-shrink: 0;
}

/* ---------- Floating bubble (trigger button) ---------- */

.cs-chat-bubble-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 51;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #000;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    display: grid;
    place-items: center;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.3s ease,
                border-color 0.3s ease,
                opacity 0.15s ease;
}

.cs-chat-bubble-btn:hover {
    box-shadow: 0 8px 32px rgba(255,232,0,0.25), 0 4px 16px rgba(0,0,0,0.3);
}

.cs-chat-bubble-btn:active {
    transform: scale(0.95);
}

.cs-chat-bubble-btn svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease, filter 0.3s ease;
}

/* AI glow on the spark itself — a soft white halo with a brighter
   highlight that orbits the icon. drop-shadow follows the spark shape. */
.cs-chat-bubble-btn:hover svg {
    transform: scale(1.08);
    animation: csSparkGlow 2s linear infinite;
}

@keyframes csSparkGlow {
    0%   { filter: drop-shadow(0 0 5px rgba(255,255,255,0.85)) drop-shadow(0 -4px 5px rgba(255,255,255,0.7)); }
    25%  { filter: drop-shadow(0 0 5px rgba(255,255,255,0.85)) drop-shadow(4px 0 5px rgba(255,255,255,0.7)); }
    50%  { filter: drop-shadow(0 0 5px rgba(255,255,255,0.85)) drop-shadow(0 4px 5px rgba(255,255,255,0.7)); }
    75%  { filter: drop-shadow(0 0 5px rgba(255,255,255,0.85)) drop-shadow(-4px 0 5px rgba(255,255,255,0.7)); }
    100% { filter: drop-shadow(0 0 5px rgba(255,255,255,0.85)) drop-shadow(0 -4px 5px rgba(255,255,255,0.7)); }
}

/* ---------- Bubble badge ---------- */

.cs-chat-bubble-badge {
    position: fixed;
    bottom: 96px;
    right: 25px;
    z-index: 51;
    background: #ffe800;
    color: #000;
    font-family: var(--cs-chat-font);
    font-size: 13px;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 10px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.18);
    /* El texto es contextual (ver CS_Chat_Frontend::bubble_badge_text), así que
       una frase con el nombre del producto no cabe en una línea. Antes era
       `nowrap`, que en móvil la sacaba de la pantalla: ahora envuelve dentro de
       un ancho acotado y nunca se pasa del viewport. */
    white-space: normal;
    max-width: min(240px, calc(100vw - 60px));
    line-height: 1.3;
    text-align: right;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cs-chat-bubble-badge::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 24px;
    width: 12px;
    height: 12px;
    background: #ffe800;
    border-radius: 2px;
    transform: rotate(45deg);
}

/* ---------- Burbuja en la esquina izquierda ----------
   Se usa cuando el popup del 10% de primera compra no está ocupando esa
   esquina (ver CS_Chat_Frontend::bubble_side). Estas reglas van después de
   las base a propósito: misma especificidad, ganan por orden, sin !important. */

.cs-chat-bubble-btn.is-left,
.cs-chat-bubble-badge.is-left {
    right: auto;
    left: 25px;
}

/* El texto se alinea hacia el lado donde está la burbuja. */
.cs-chat-bubble-badge.is-left {
    text-align: left;
}

/* La colita del globo apunta a la burbuja, así que también cambia de lado. */
.cs-chat-bubble-badge.is-left::after {
    right: auto;
    left: 24px;
}

.cs-chat-bubble-badge.is-hidden {
    opacity: 0 !important;
    transform: translateY(4px) !important;
    pointer-events: none;
    animation: none;
}

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

/* ---------- Off-canvas drawer (opens from the bubble) ---------- */

.cs-chat-drawer {
    position: fixed;
    inset: 0;
    z-index: 100000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.cs-chat-drawer.is-open {
    visibility: visible;
    opacity: 1;
}

.cs-chat-drawer__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.cs-chat-drawer__panel {
    position: absolute;
    right: 0;
    top: 34px;
    bottom: 30px;
    width: min(420px, 90vw);
    background: var(--cs-chat-dark);
    box-shadow: -8px 0 24px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    border-top-left-radius: 20px;
    border-bottom-left-radius: 20px;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.cs-chat-drawer.is-open .cs-chat-drawer__panel {
    transform: translateX(0);
}

/* The chat fills the drawer panel, flush to the edges */
.cs-chat-drawer__panel .cs-chat-container {
    height: 100%;
    flex: 1;
    border-radius: 0;
}

/* Lock background scroll while the drawer is open */
body.cs-chat-drawer-open {
    overflow: hidden;
}

/* ---------- Full page ---------- */

.cs-chat-fullpage {
    max-width: 800px;
    margin: 0 auto;
    height: calc(100vh - 200px);
    min-height: 500px;
}

.cs-chat-fullpage .cs-chat-container {
    height: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

/* ---------- /chat/ standalone page (no theme header/footer) ---------- */

/* Hide everything in the page wrapper except the chat content and the cart
   off-canvas (so add-to-cart still opens the cart drawer). */
body.cs-chat-fp #page > *:not(#cs-main):not([data-cs-cart-drawer]) {
    display: none !important;
}

body.cs-chat-fp #cs-main {
    margin: 0 !important;
    padding: 0 !important;
    min-height: 100vh;
}

body.cs-chat-fp .cs-chat-fullpage {
    max-width: 100%;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    margin: 0;
}

body.cs-chat-fp .cs-chat-fullpage .cs-chat-container {
    border-radius: 0;
    box-shadow: none;
}

/* "Volver al sitio" button in the chat header */
.cs-chat-header-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,0.08);
    border: none;
    color: #fff;
    font-family: var(--cs-chat-font);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    margin-right: 6px;
    transition: background 0.15s;
}
.cs-chat-header-back:hover { background: rgba(255,255,255,0.18); }
.cs-chat-header-back svg { width: 15px; height: 15px; }

/* ---------- Home embed (full-width section below promo banners) ---------- */

.cs-chat-home-wrap {
    width: 100%;
    background: #ffffff;
    padding: 44px 0;
    margin: 8px 0;
}

/* Desktop only — on mobile/tablet the floating bubble replaces the box. */
@media (max-width: 1023px) {
    .cs-chat-home-wrap { display: none !important; }
}

.cs-chat-home-inner {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px;
}

.cs-chat-home-head {
    text-align: center;
    margin-bottom: 22px;
}

.cs-chat-home-heading {
    font-family: var(--cs-chat-font);
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: #16181d;
    margin: 0;
}

.cs-chat-home-sub {
    font-family: var(--cs-chat-font);
    font-size: 14px;
    color: #6b7280;
    margin: 8px 0 0;
}

.cs-chat-home-container {
    height: 580px;
    border-radius: var(--cs-chat-radius);
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.12);
}

.cs-chat-home-container .cs-chat-container {
    height: 100%;
}

/* ---------- Home embed: LIGHT theme (consistent with the site) ---------- */
/* The floating bubble and /chat/ stay dark; only the home box is light. */
.cs-chat-home-container .cs-chat-container {
    --cs-chat-dark: #ffffff;
    --cs-chat-dark-100: #f3f4f6;
    --cs-chat-dark-200: #ffffff;
    color: #222529;
    border: 1px solid #ececec;
}

.cs-chat-home-container .cs-chat-header { border-bottom-color: #ededed; }
.cs-chat-home-container .cs-chat-header-title { color: #16181d; }
.cs-chat-home-container .cs-chat-header-subtitle { color: #8a8f98; }

.cs-chat-home-container .cs-chat-header-close,
.cs-chat-home-container .cs-chat-header-expand,
.cs-chat-home-container .cs-chat-header-clear { color: #8a8f98; }
.cs-chat-home-container .cs-chat-header-close:hover,
.cs-chat-home-container .cs-chat-header-expand:hover,
.cs-chat-home-container .cs-chat-header-clear:hover { color: #16181d; }

.cs-chat-home-container .cs-chat-msg-ai {
    background: #f3f4f6;
    color: #2b2f37;
}
.cs-chat-home-container .cs-chat-msg-ai strong,
.cs-chat-home-container .cs-chat-msg-ai b { color: #16181d; }

/* Inline category links in the white box: dark + bold (not the pills) */
.cs-chat-home-container .cs-chat-msg-ai a:not(.cs-chat-link-pill):not(.cs-chat-wa-pill) {
    color: #16181d;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cs-chat-home-container .cs-chat-input {
    background: #ffffff;
    border-color: #e0e0e0;
    color: #222529;
}
.cs-chat-home-container .cs-chat-input::placeholder { color: #9aa0aa; }
.cs-chat-home-container .cs-chat-input-wrap { border-top-color: #ededed; }
.cs-chat-home-container .cs-chat-disclaimer { color: #9aa0aa; }

/* Typing dots + scrollbar on light */
.cs-chat-home-container .cs-chat-typing { background: #f3f4f6; }
.cs-chat-home-container .cs-chat-messages { scrollbar-color: rgba(0,0,0,.18) transparent; }
.cs-chat-home-container .cs-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); }

/* Product cards/chips need contrast on the white background (else invisible) */
.cs-chat-home-container .cs-chat-product-card,
.cs-chat-home-container .cs-chat-chip {
    background: #fafbfc;
    border: 1px solid #e0e3e8;
    box-shadow: 0 2px 6px rgba(16,24,40,0.06);
}
.cs-chat-home-container .cs-chat-product-card:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

/* ---------- Skeleton loading state (home embed) ---------- */
@keyframes cs-chat-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.cs-chat-skeleton {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #ffffff;
    border-radius: var(--cs-chat-radius);
}
.cs-chat-skeleton__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid #ededed;
}
.cs-chat-skeleton__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 800px 100%;
    animation: cs-chat-shimmer 1.5s infinite linear;
}
.cs-chat-skeleton__header-lines {
    display: flex;
    flex-direction: column;
}
.cs-chat-skeleton__line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 800px 100%;
    animation: cs-chat-shimmer 1.5s infinite linear;
}
.cs-chat-skeleton__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 28px 20px;
}
.cs-chat-skeleton__pills {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
.cs-chat-skeleton__pill {
    width: 100px;
    height: 34px;
    border-radius: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 800px 100%;
    animation: cs-chat-shimmer 1.5s infinite linear;
}
.cs-chat-skeleton__input {
    padding: 18px 20px;
    border-top: 1px solid #ededed;
}

/* ---------- Confirm modal (matches CS Notifications popup style) ---------- */

.cs-chat-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.65);
    opacity: 0;
    transition: opacity 0.22s ease;
}
.cs-chat-confirm-overlay.is-open { opacity: 1; }

.cs-chat-confirm-box {
    position: relative;
    width: 100%;
    max-width: 360px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.30);
    padding: 28px 24px 22px;
    text-align: center;
    font-family: var(--cs-chat-font);
    transform: scale(0.85);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(.26,.53,.74,1.48), opacity 0.22s ease;
}
.cs-chat-confirm-overlay.is-open .cs-chat-confirm-box {
    transform: scale(1);
    opacity: 1;
}

.cs-chat-confirm-x {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: #eee;
    color: #555;
    font-size: 15px;
    line-height: 30px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.cs-chat-confirm-x:hover { background: #16181d; color: #fff; }

.cs-chat-confirm-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--cs-chat-primary);
    color: #16181d;
}
.cs-chat-confirm-icon svg { width: 24px; height: 24px; }

.cs-chat-confirm-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 800;
    color: #16181d;
    line-height: 1.25;
}
.cs-chat-confirm-text {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.5;
    color: #555;
}

.cs-chat-confirm-actions {
    display: flex;
    gap: 10px;
}
.cs-chat-confirm-actions button {
    flex: 1;
    padding: 11px 14px;
    font-family: var(--cs-chat-font);
    font-size: 14px;
    font-weight: 700;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, opacity 0.2s;
}
.cs-chat-confirm-cancel {
    background: #efefef;
    color: #16181d;
}
.cs-chat-confirm-cancel:hover { background: #e2e2e2; }
.cs-chat-confirm-ok {
    background: #16181d;
    color: #fff;
}
.cs-chat-confirm-ok:hover {
    background: var(--cs-chat-primary);
    color: #16181d;
}

body.cs-chat-confirm-lock { overflow: hidden !important; }

/* ---------- Animations ---------- */

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

@keyframes csChatBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-6px); }
}

/* ---------- Mobile ---------- */

@media (max-width: 767px) {
    .cs-chat-input {
        font-size: 16px;
    }

    .cs-chat-fullpage {
        height: calc(100vh - 140px);
        height: calc(100dvh - 140px);
    }

    .cs-chat-msg {
        max-width: 92%;
    }

    .cs-chat-product-card {
        min-width: 140px;
    }

    .cs-chat-home-container {
        height: 420px;
    }

    .cs-chat-home-wrap { padding: 30px 0; }
    .cs-chat-home-heading { font-size: 20px; }
    .cs-chat-home-sub { font-size: 13px; }
}
