/* Ask Diecast — Rule-based Chatbot */

#ask-diecast-bubble {
    position: fixed;
    bottom: 28px;
    right: 28px;
    height: 56px;
    min-width: 56px;
    padding: 0;
    background: #cb1313;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 0;
    cursor: pointer;
    z-index: 99990;
    box-shadow: 0 0 18px 4px rgba(203,19,19,0.55), 0 4px 14px rgba(0,0,0,0.35);
    transition: transform 0.2s, box-shadow 0.2s, padding 1.1s cubic-bezier(0.65, 0, 0.35, 1);
    border: none;
    outline: none;
    user-select: none;
    /* Pops in as a circle, then keeps the existing slow glow. */
    animation: dz-bubble-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both,
               dz-bubble-breathe 2.8s ease-in-out 0.5s infinite;
}
@keyframes dz-bubble-pop {
    0%   { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
/* Circle -> "ASK DIECAST" pill. JS adds .is-expanded on a timer; hover and
   keyboard focus open it too. */
#ask-diecast-bubble.is-expanded,
#ask-diecast-bubble:hover,
#ask-diecast-bubble:focus-visible {
    padding-right: 22px;
}
#ask-diecast-bubble:focus-visible {
    outline: 3px solid rgba(203, 19, 19, 0.35);
    outline-offset: 3px;
}
#ask-diecast-bubble::before,
#ask-diecast-bubble::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50px;
    background: rgba(203, 19, 19, 0.45);
    animation: dz-bubble-ripple 2.8s ease-out infinite;
    pointer-events: none;
    z-index: -1;
}
#ask-diecast-bubble::after {
    animation-delay: 1s;
    background: rgba(203, 19, 19, 0.3);
}
@keyframes dz-bubble-ripple {
    0%   { transform: scale(1);    opacity: 0.7; }
    100% { transform: scale(1.75); opacity: 0; }
}
@keyframes dz-bubble-breathe {
    0%, 100% { box-shadow: 0 0 18px 4px rgba(203,19,19,0.55), 0 4px 14px rgba(0,0,0,0.35); }
    50%       { box-shadow: 0 0 30px 8px rgba(203,19,19,0.75), 0 6px 18px rgba(0,0,0,0.4); }
}
#ask-diecast-bubble:hover {
    transform: scale(1.05);
    animation: none;
    box-shadow: 0 0 30px 8px rgba(203,19,19,0.7), 0 6px 18px rgba(0,0,0,0.4);
}
#ask-diecast-bubble .dz-bubble-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
#ask-diecast-bubble .dz-bubble-icon svg {
    width: 32px;
    height: 32px;
    overflow: visible;
    animation: dz-bot-bob 2.8s ease-in-out infinite;
}
#ask-diecast-bubble .dz-bot-head,
#ask-diecast-bubble .dz-bot-ear,
#ask-diecast-bubble .dz-bot-antenna-dot { fill: #fff; }
#ask-diecast-bubble .dz-bot-antenna { stroke: #fff; stroke-width: 2; stroke-linecap: round; }
#ask-diecast-bubble .dz-bot-eye,
#ask-diecast-bubble .dz-bot-mouth { fill: #cb1313; }
#ask-diecast-bubble .dz-bot-eye {
    transform-box: fill-box;
    transform-origin: center;
    animation: dz-bot-blink 4s ease-in-out infinite;
}
#ask-diecast-bubble .dz-bot-antenna-dot {
    transform-box: fill-box;
    transform-origin: center;
    animation: dz-bot-signal 1.4s ease-in-out infinite;
}
@keyframes dz-bot-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-1.5px); }
}
@keyframes dz-bot-blink {
    0%, 44%, 52%, 100% { transform: scaleY(1); }
    48%                { transform: scaleY(0.1); }
}
@keyframes dz-bot-signal {
    0%, 100% { transform: scale(1);   opacity: 1; }
    50%      { transform: scale(1.5); opacity: 0.55; }
}
#ask-diecast-bubble .dz-bubble-label {
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    display: inline-block;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    /* Closing: the text fades out first, then the pill narrows. */
    transition: max-width 0.8s cubic-bezier(0.65, 0, 0.35, 1) 0.15s, opacity 0.35s ease;
}
#ask-diecast-bubble.is-expanded .dz-bubble-label,
#ask-diecast-bubble:hover .dz-bubble-label,
#ask-diecast-bubble:focus-visible .dz-bubble-label {
    /* chatbot.js measures the real text width, so the animation runs for its
       full length instead of finishing early inside a wider max-width. */
    max-width: var(--dz-label-w, 110px);
    opacity: 1;
    /* Opening: the pill widens slowly and the text fades in as it settles. */
    transition: max-width 1.1s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.7s ease 0.4s;
}
@media (prefers-reduced-motion: reduce) {
    #ask-diecast-bubble,
    #ask-diecast-bubble::before,
    #ask-diecast-bubble::after,
    #ask-diecast-bubble .dz-bubble-icon svg,
    #ask-diecast-bubble .dz-bot-eye,
    #ask-diecast-bubble .dz-bot-antenna-dot { animation: none; }
}

/* ==========================================================================
   Chat window - laid out like the support widgets shoppers already know
   (Intercom / Tidio style): a home screen with a brand header, a message
   card and help topics; a plain conversation view with a bottom message bar.
   Flat colours only - no gradients or glows.
   ========================================================================== */
#ask-diecast-window {
    --dz-brand: #b10e0e;
    --dz-brand-hover: #990000;
    --dz-ink: #1f2933;
    --dz-muted: #6b7280;
    --dz-line: #e6e8eb;
    --dz-bg: #f4f5f7;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: min(620px, calc(100vh - 48px));
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    z-index: 99991;
    overflow: hidden;
    font-family: "Lato", system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--dz-ink);
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.2s ease;
}
#ask-diecast-window.dz-chat-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}
body.dz-chat-active #ask-diecast-bubble {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
}
#ask-diecast-window button { font-family: inherit; }
#ask-diecast-window a { text-decoration: none; }

.dz-logo {
    border-radius: 50%;
    background: #fff;
    object-fit: contain;
    flex-shrink: 0;
}
.dz-icon-btn {
    width: 32px;
    height: 32px;
    border: none !important;
    border-radius: 8px !important;
    background: transparent !important;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0 !important;
    flex-shrink: 0;
    transition: background 0.15s;
}
.dz-icon-btn:hover { background: rgba(255, 255, 255, 0.15) !important; }
.dz-icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- home view ---------- */
.dz-home {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--dz-bg);
}
.dz-home-hero {
    background: var(--dz-brand);
    color: #fff;
    padding: 20px 20px 64px;
}
.dz-home-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 26px;
}
.dz-home-top .dz-logo { width: 40px; height: 40px; padding: 3px; }
.dz-home-hero h2 {
    margin: 0 0 4px;
    color: #fff;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.2;
}
.dz-home-hero p {
    margin: 0;
    color: rgba(255, 255, 255, 0.85);
    font-size: 15px;
}
.dz-home-cards {
    margin-top: -44px;
    padding: 0 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.dz-home-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--dz-line);
}
.dz-start {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    text-align: left;
    cursor: pointer;
    border: 1px solid var(--dz-line) !important;
    background: #fff !important;
    color: var(--dz-ink) !important;
    transition: border-color 0.15s;
}
.dz-start:hover { border-color: #c9ccd1 !important; }
.dz-start-text { flex: 1; min-width: 0; }
.dz-start-text strong { display: block; font-size: 14.5px; font-weight: 700; color: var(--dz-ink); }
.dz-start-text span { font-size: 13px; color: var(--dz-muted); }
.dz-start > svg { width: 20px; height: 20px; fill: none; stroke: var(--dz-brand); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.dz-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
}
.dz-search svg { width: 17px; height: 17px; fill: none; stroke: var(--dz-muted); stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.dz-search input {
    flex: 1;
    min-width: 0;
    height: 46px;
    border: none !important;
    background: transparent !important;
    outline: none;
    font-size: 14px;
    color: var(--dz-ink);
    padding: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
}
.dz-search input::placeholder { color: #9aa0a6; }

.dz-topics-title {
    padding: 14px 16px 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--dz-ink);
}
.dz-topic {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 16px;
    border: none !important;
    border-top: 1px solid var(--dz-line) !important;
    border-radius: 0 !important;
    background: #fff !important;
    color: var(--dz-ink) !important;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}
.dz-topic:last-child { border-radius: 0 0 12px 12px !important; }
.dz-topic:hover { background: #fafafa !important; color: var(--dz-brand) !important; }
.dz-topic svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.6; }

/* ---------- conversation view ---------- */
.dz-convo {
    flex: 1;
    min-height: 0;
    display: none;
    flex-direction: column;
}
#ask-diecast-window.is-chatting .dz-home { display: none; }
#ask-diecast-window.is-chatting .dz-convo { display: flex; }

.dz-convo-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 10px;
    background: var(--dz-brand);
    color: #fff;
    flex-shrink: 0;
}
.dz-convo-header .dz-logo { width: 34px; height: 34px; padding: 2px; }
.dz-convo-title { flex: 1; min-width: 0; line-height: 1.25; }
.dz-convo-title strong { display: block; font-size: 15px; font-weight: 700; color: #fff; }
.dz-convo-title span { font-size: 12.5px; color: rgba(255, 255, 255, 0.82); }

.dz-chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: #fff;
}
.dz-chat-body::-webkit-scrollbar { width: 6px; }
.dz-chat-body::-webkit-scrollbar-thumb { background: #dadce0; border-radius: 6px; }
.dz-chat-messages {
    padding: 16px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.dz-msg { display: flex; gap: 8px; align-items: flex-end; }
.dz-msg-user { justify-content: flex-end; }
.dz-msg-avatar { width: 26px; height: 26px; flex-shrink: 0; }
.dz-msg-avatar .dz-logo { width: 26px; height: 26px; border: 1px solid var(--dz-line); padding: 1px; }
.dz-msg-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    max-width: 80%;
}
.dz-msg-user .dz-msg-col { align-items: flex-end; }
.dz-msg-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.dz-msg-bot .dz-msg-bubble {
    background: var(--dz-bg);
    color: var(--dz-ink);
    border-bottom-left-radius: 4px;
}
.dz-msg-bot .dz-msg-bubble a { color: var(--dz-brand) !important; font-weight: 700; }
.dz-msg-bot .dz-msg-bubble a:hover { text-decoration: underline; }
.dz-msg-user .dz-msg-bubble {
    background: var(--dz-brand);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.dz-quick-replies { display: flex; flex-wrap: wrap; gap: 6px; }
.dz-quick-reply {
    background: #fff !important;
    border: 1px solid var(--dz-brand) !important;
    color: var(--dz-brand) !important;
    border-radius: 16px !important;
    padding: 5px 12px !important;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.dz-quick-reply:hover { background: var(--dz-brand) !important; color: #fff !important; }

/* product cards */
.dz-cards {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
    max-width: 100%;
}
.dz-cards::-webkit-scrollbar { height: 5px; }
.dz-cards::-webkit-scrollbar-thumb { background: #dadce0; border-radius: 5px; }
.dz-card {
    flex: 0 0 140px;
    scroll-snap-align: start;
    border: 1px solid var(--dz-line);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
    color: var(--dz-ink) !important;
    display: flex;
    flex-direction: column;
}
.dz-card:hover { border-color: #c9ccd1; }
.dz-card-img {
    height: 96px;
    background: #fafafa;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--dz-line);
}
.dz-card-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.dz-card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.dz-card-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.dz-card-price { font-size: 13.5px; font-weight: 700; color: var(--dz-ink); }
.dz-card-stock { font-size: 12px; color: #15803d; }
.dz-card-stock.is-out { color: var(--dz-muted); }
.dz-card-cta { margin-top: auto; padding-top: 4px; font-size: 12.5px; font-weight: 700; color: var(--dz-brand); }

/* order cards */
.dz-order {
    border: 1px solid var(--dz-line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 13px;
}
.dz-order-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dz-order-status { font-size: 12px; font-weight: 700; color: var(--dz-brand); }
.dz-order-items { color: var(--dz-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dz-order-links { display: flex; gap: 14px; margin-top: 2px; }
.dz-order-links a { color: var(--dz-brand) !important; font-weight: 700; }

/* typing */
.dz-typing { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.dz-typing span {
    width: 6px;
    height: 6px;
    background: #9aa0a6;
    border-radius: 50%;
    animation: dz-type-bounce 1.2s infinite ease-in-out;
}
.dz-typing span:nth-child(2) { animation-delay: 0.15s; }
.dz-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dz-type-bounce {
    0%, 80%, 100% { opacity: 0.35; }
    40% { opacity: 1; }
}

/* message bar */
.dz-composer {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px 6px 16px;
    border-top: 1px solid var(--dz-line);
    background: #fff;
    flex-shrink: 0;
}
.dz-composer input {
    flex: 1;
    min-width: 0;
    height: 46px;
    border: none !important;
    background: transparent !important;
    outline: none;
    font-size: 14px;
    color: var(--dz-ink);
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}
.dz-composer input::placeholder { color: #9aa0a6; }
#ask-diecast-window .dz-composer .dz-chat-send {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 8px !important;
    background: transparent !important;
    color: var(--dz-brand);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1 !important;
    font-size: 0 !important;
    transition: background 0.15s, opacity 0.15s;
}
#ask-diecast-window .dz-composer .dz-chat-send:hover:not(:disabled) { background: var(--dz-bg) !important; }
#ask-diecast-window .dz-composer .dz-chat-send:disabled { opacity: 0.35; cursor: default; }
#ask-diecast-window .dz-composer .dz-chat-send svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }

@media (prefers-reduced-motion: reduce) {
    #ask-diecast-window,
    .dz-typing span { animation: none !important; transition: none !important; }
}

/* ---------- phones: full-screen ---------- */
@media (max-width: 480px) {
    #ask-diecast-window {
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
    }
    .dz-composer { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
    #ask-diecast-bubble { right: 16px; bottom: 20px; height: 52px; min-width: 52px; }
    #ask-diecast-bubble .dz-bubble-icon { width: 52px; height: 52px; }
    #ask-diecast-bubble .dz-bubble-icon svg { width: 30px; height: 30px; }
    #ask-diecast-bubble.is-expanded,
    #ask-diecast-bubble:hover { padding-right: 18px; }
    #ask-diecast-bubble .dz-bubble-label { font-size: 12px; }
}
