/* ─── Live Sales Toaster ───────────────────────────────────────────── */
/* Refresh visual (mockup PR #222): icon verde soft + nome com badge de
   verificacao + linha de acao opcional "Ver produto". Card NAO eh link
   inteiro — so' o link de acao navega. Menos invasivo. */
.dmhub-sp-toaster {
    position: fixed;
    left: 20px;
    bottom: 20px;
    z-index: 99992;
    max-width: 340px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .04);
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .35s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.dmhub-sp-toaster.is-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}
.dmhub-sp-toaster__inner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 32px 12px 14px;
    color: #111827;
    position: relative;
}
.dmhub-sp-toaster__icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    /* Verde soft contextual — match com palette do plugin (cashback card) */
    background: #f0fdf4;
    color: #16a34a;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dmhub-sp-toaster__body {
    flex: 1;
    min-width: 0;
    line-height: 1.35;
}
.dmhub-sp-toaster__head {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}
.dmhub-sp-toaster__name {
    font-size: 13.5px;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.dmhub-sp-toaster__verified {
    flex-shrink: 0;
    color: #16a34a;
}
.dmhub-sp-toaster__product {
    font-size: 12px;
    color: #4b5563;
    margin-top: 2px;
    /* Uma linha apenas — corta o texto que excede sem ellipsis (user
       preferiu visual mais limpo, sem "..."). overflow:hidden +
       nowrap clipa no limite da box. */
    white-space: nowrap;
    overflow: hidden;
}
.dmhub-sp-toaster__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}
.dmhub-sp-toaster__meta {
    font-size: 11.5px;
    color: #9ca3af;
}
.dmhub-sp-toaster__action {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11.5px;
    font-weight: 600;
    color: #16a34a;
    text-decoration: none;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color .15s ease, background .15s ease;
}
.dmhub-sp-toaster__action[hidden] { display: none; }
.dmhub-sp-toaster__action:hover,
.dmhub-sp-toaster__action:focus-visible {
    color: #0d4620;
    background: #f0fdf4;
    text-decoration: none;
}
.dmhub-sp-toaster__close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: transparent;
    border: 0;
    font-size: 18px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
    /* Touch target 44x44px (WCAG 2.5.5). Padding 12px sobre font 18px =
       ~42px linha. width/height min garante o quadrado completo. */
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: color .15s ease, background .15s ease;
}
.dmhub-sp-toaster__close:hover {
    color: #374151;
    background: #f3f4f6;
}
.dmhub-sp-toaster__close:focus-visible {
    outline: 2px solid #16a34a;
    outline-offset: 1px;
    color: #16a34a;
}

/* Footer com APENAS o meta (sem url do produto) — esconde a row inteira.
   Evita "ha 2 dias" flutuando sozinho sem contexto. :has() OK pra
   browsers modernos (Safari 15.4+, FF 121+, Chrome 105+ ~98% BR). */
.dmhub-sp-toaster__foot:not(:has(.dmhub-sp-toaster__action:not([hidden]))) {
    display: none;
}

/* Respeita prefers-reduced-motion — usuarios com motion sickness nao
   recebem a animacao slide-up. Visibilidade muda instantaneamente. */
@media (prefers-reduced-motion: reduce) {
    .dmhub-sp-toaster {
        transition: none;
        transform: none;
    }
    .dmhub-sp-toaster:not(.is-visible) {
        opacity: 0;
    }
}
@media (max-width: 480px) {
    .dmhub-sp-toaster {
        left: 12px;
        right: 12px;
        bottom: 12px;
        max-width: none;
    }
    .dmhub-sp-toaster.has-stories {
        bottom: 96px;
    }
}

/* ─── Stories Bubble (fixa) ─────────────────────────────────────────── */
/* z-index acima do sidecart do checkout (que sobe a 99999/100000),
   mas o JS tambem esconde a bolinha via classe is-sidecart-hidden
   quando o drawer abre — evita conflito visual. */
.dmhub-sp-stories {
    position: fixed;
    bottom: 20px;
    z-index: 99994;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: opacity .25s, transform .25s;
}
.dmhub-sp-stories--right { right: 20px; }
.dmhub-sp-stories--left  { left:  20px; }

/* Esconder em sidecart-open + autohide threshold atingido */
.dmhub-sp-stories.is-sidecart-hidden,
.dmhub-sp-stories.is-autohidden {
    opacity: 0;
    transform: translateY(20px) scale(.9);
    pointer-events: none;
}

.dmhub-sp-stories__bubble {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 0;
    padding: 3px;
    background: linear-gradient(135deg, #ff3366, #8b5cf6);
    cursor: pointer;
    position: relative;
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
    overflow: hidden;
    animation: dmhub-sp-pulse 2.4s ease-in-out infinite;
    transition: transform .15s;
}
.dmhub-sp-stories__bubble:hover  { transform: scale(1.05); }
.dmhub-sp-stories__bubble:active { transform: scale(.95); }
.dmhub-sp-stories.is-seen .dmhub-sp-stories__bubble {
    background: #9ca3af;
    animation: none;
}
.dmhub-sp-stories__preview {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #000;
    display: block;
    pointer-events: none;
}
.dmhub-sp-stories__label {
    font-size: 11px;
    font-weight: 500;
    color: #1f2937;
    background: rgba(255,255,255,.95);
    padding: 2px 8px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@keyframes dmhub-sp-pulse {
    0%, 100% { box-shadow: 0 6px 18px rgba(0,0,0,.18), 0 0 0 0   rgba(255,51,102,.45); }
    50%      { box-shadow: 0 6px 18px rgba(0,0,0,.18), 0 0 0 10px rgba(255,51,102,0);    }
}
@media (prefers-reduced-motion: reduce) {
    .dmhub-sp-stories__bubble { animation: none; }
    .dmhub-sp-viewer          { animation: none; }
}

/* ─── Stories Carousel (shortcode) ─────────────────────────────────── */
.dmhub-sp-carousel {
    margin: 16px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.dmhub-sp-carousel__label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #1f2937;
}
.dmhub-sp-carousel__track {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 4px 12px;
    scrollbar-width: thin;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
}
.dmhub-sp-carousel__track.is-dragging { cursor: grabbing; user-select: none; }
.dmhub-sp-carousel__track::-webkit-scrollbar { height: 4px; }
.dmhub-sp-carousel__track::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.dmhub-sp-carousel__item {
    flex-shrink: 0;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    scroll-snap-align: start;
    width: 80px;
}
.dmhub-sp-carousel__bubble {
    display: block;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(135deg, #ff3366, #8b5cf6);
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    transition: transform .15s;
}
.dmhub-sp-carousel__item:hover .dmhub-sp-carousel__bubble { transform: scale(1.05); }
.dmhub-sp-carousel__preview {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #000;
    display: block;
    pointer-events: none;
}
.dmhub-sp-carousel__caption {
    font-size: 11px;
    color: #4b5563;
    text-align: center;
    line-height: 1.25;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ─── Stories Viewer ───────────────────────────────────────────────── */
body.dmhub-sp-viewer-open { overflow: hidden; }
/* Esconde UIs sociais quando viewer aberto: viewer foi posto em z-index
   baixo (9000) pra que QUALQUER sidecart de tema apareça por cima sem
   precisar adivinhar valor. Como FAB IA/toaster/bubble Stories tem
   z-index alto pra ficarem visiveis na pagina, precisam sumir agora. */
body.dmhub-sp-viewer-open .dmhub-sp-stories,
body.dmhub-sp-viewer-open .dmhub-sp-toaster,
body.dmhub-sp-viewer-open .dmhub-aibot-fab { display: none !important; }

.dmhub-sp-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.96);
    /* z-index baixo PROPOSITAL — sidecart de qualquer tema (varia entre
       1000 e 99999+) deve aparecer por cima sem precisar boost dinamico.
       Como o viewer fica abaixo de UI sociais (FAB IA 99996, toaster
       99992, bubble 99994), elas sao escondidas via display:none
       enquanto viewer aberto (regra logo abaixo). */
    z-index: 9000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    animation: dmhub-sp-fadein .2s ease-out;
}
@keyframes dmhub-sp-fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.dmhub-sp-viewer__progress {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    display: flex;
    gap: 4px;
    z-index: 3;
}
.dmhub-sp-viewer__bar {
    flex: 1;
    height: 2px;
    background: rgba(255,255,255,.25);
    border-radius: 2px;
    overflow: hidden;
}
.dmhub-sp-viewer__bar i {
    display: block;
    height: 100%;
    width: 0;
    background: #fff;
    transition: width .12s linear;
}
.dmhub-sp-viewer__close {
    position: absolute;
    top: 28px;
    right: 16px;
    background: rgba(255,255,255,.18);
    color: #fff;
    border: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    z-index: 4;
    transition: background .15s;
}
.dmhub-sp-viewer__close:hover { background: rgba(255,255,255,.28); }

.dmhub-sp-viewer__stage {
    position: relative;
    width: min(420px, 100vw);
    height: 100vh;
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dmhub-sp-viewer__video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}
.dmhub-sp-viewer__nav {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30%;
    background: transparent;
    border: 0;
    cursor: pointer;
    z-index: 2;
    /* Mobile: tap zone invisivel (lados esq/dir) */
    padding: 0;
}
.dmhub-sp-viewer__nav--prev { left:  0; }
.dmhub-sp-viewer__nav--next { right: 0; }

/* Desktop: setas visiveis nos lados (estilo Stories do Instagram).
   Mobile fica sem (swipe na tela inteira via tap zones acima). */
@media (min-width: 768px) {
    .dmhub-sp-viewer__nav {
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.55);
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0.85;
        transition: opacity .2s, background .2s, transform .15s;
    }
    /* -22px = metade do botao (44/2) — fica centrado na borda do video,
       metade dentro / metade fora. Tema 'Stories do Instagram' */
    .dmhub-sp-viewer__nav--prev { left:  -22px; }
    .dmhub-sp-viewer__nav--next { right: -22px; }
    .dmhub-sp-viewer__nav:hover {
        opacity: 1;
        background: rgba(0, 0, 0, 0.75);
    }
    .dmhub-sp-viewer__nav:active {
        transform: translateY(-50%) scale(0.94);
    }
    .dmhub-sp-viewer__nav::before {
        content: '';
        width: 12px;
        height: 12px;
        border-top: 2px solid #fff;
        border-right: 2px solid #fff;
        display: block;
    }
    .dmhub-sp-viewer__nav--prev::before {
        transform: rotate(-135deg);
        margin-left: 4px;
    }
    .dmhub-sp-viewer__nav--next::before {
        transform: rotate(45deg);
        margin-right: 4px;
    }
}

/* ─── CTA "Comprar agora" no viewer ────────────────────────────────── */
.dmhub-sp-viewer__cta {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: min(380px, calc(100vw - 32px));
    z-index: 5;
    pointer-events: none;
}
.dmhub-sp-viewer__cta .dmhub-sp-cta { pointer-events: auto; }

.dmhub-sp-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    background: rgba(255,255,255,.96);
    border: 0;
    border-radius: 14px;
    padding: 10px 12px 10px 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
    cursor: pointer;
    font-family: inherit;
    transition: transform .15s, background .2s;
}
.dmhub-sp-cta:hover { transform: scale(1.02); }
.dmhub-sp-cta:active { transform: scale(.98); }

.dmhub-sp-cta__product {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    line-height: 1.2;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.dmhub-sp-cta__price {
    font-size: 13px;
    font-weight: 600;
    color: #1f7a4d; /* verde brand (match checkout) — antes era #059669 emerald */
    flex-shrink: 0;
}
.dmhub-sp-cta__btn {
    /* Verde brand DigitalMart — match botoes Comprar do checkout/cashback
       card/orderbump. Antes: gradient roxo (#6366f1 → #8b5cf6) que destoava
       da palette do plugin. */
    background: #1f7a4d;
    color: #fff;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    transition: filter .2s, background .2s;
}
.dmhub-sp-cta:hover .dmhub-sp-cta__btn { background: #166639; /* hover escurece, igual --color-primary-dark */ }
.dmhub-sp-cta.is-loading .dmhub-sp-cta__btn { filter: brightness(.7); }
.dmhub-sp-cta.is-success .dmhub-sp-cta__btn { background: #10b981; }
.dmhub-sp-cta.is-error   .dmhub-sp-cta__btn { background: #ef4444; }

@media (max-width: 480px) {
    .dmhub-sp-stories__bubble { width: 64px; height: 64px; }
    .dmhub-sp-viewer__close   { top: 16px; right: 12px; }
    .dmhub-sp-cta__product    { max-width: 110px; font-size: 12px; }
}
