/* ================================================================
   CUPONES — toast flotante de Trofi, módulo del carrito y aviso de
   precio con descuento en la ficha de producto.

   Portado de cupones_ejemplos/. Las clases van con prefijo `cpn-`
   para no chocar con las del sitio (.chip, .hidden, etc.).
   El azul sale de --primary de style.css, que es el mismo #3072E8
   del diseño; el resto de los tonos son propios del componente.
   ================================================================ */

:root {
  --cpn-blue: var(--primary, #3072E8);
  --cpn-blue-strong: #1B5FD4;
  --cpn-blue-soft: #EBF2FE;
  --cpn-ink: #1A1A2E;
  --cpn-muted: #6B7280;
  --cpn-muted-2: #9CA3AF;
  --cpn-line: #E5E7EB;
  --cpn-card: #FFFFFF;
  --cpn-green: #22C55E;
  --cpn-green-dark: #15803D;
  --cpn-green-soft: #DCFCE7;
  --cpn-amber: #F5B632;
  --cpn-red: #EF4444;
  --cpn-red-dark: #B91C1C;
  --cpn-red-soft: #FEE2E2;
}

.cpn-hidden { display: none !important; }

/* ══════════════════════════════
   MINI TOAST — Trofi hablando
══════════════════════════════ */
.cpn-mini-toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  display: flex; flex-direction: column; align-items: flex-end; gap: 0;
  cursor: pointer;
  animation: cpn-mini-pop .4s cubic-bezier(.16,1,.3,1) both;
}
@keyframes cpn-mini-pop { from { transform: scale(0) translateY(20px); opacity: 0 } to { transform: scale(1) translateY(0); opacity: 1 } }
.cpn-mini-toast:hover .cpn-mini-trofi { animation-play-state: paused; transform: scale(1.08) }

.cpn-mini-trofi {
  width: 68px; height: 68px; border-radius: 50%;
  object-fit: cover; border: 3px solid #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  flex-shrink: 0; z-index: 2;
  background: #fff;
  animation: cpn-trofi-talk 2.5s ease-in-out infinite;
}
@keyframes cpn-trofi-talk {
  0%,50%,100% { transform: rotate(0) scale(1) }
  10% { transform: rotate(-4deg) scale(1.04) }
  20% { transform: rotate(3deg) scale(1) }
  30% { transform: rotate(-2deg) scale(1.03) }
  40% { transform: rotate(1deg) scale(1) }
}

/* Globo de diálogo */
.cpn-speech-card {
  position: relative;
  background: var(--cpn-card); border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1), 0 1px 4px rgba(0,0,0,.06);
  padding: 14px 20px;
  margin-bottom: 10px;
  min-width: 210px;
  opacity: 0; transform: translateY(10px) scale(.95);
  animation: cpn-card-in .5s cubic-bezier(.16,1,.3,1) .3s forwards;
  transition: box-shadow .2s;
}
.cpn-speech-card:hover { box-shadow: 0 8px 32px rgba(48,114,232,.18) }
@keyframes cpn-card-in { to { opacity: 1; transform: translateY(0) scale(1) } }

/* Puntita abajo apuntando a Trofi */
.cpn-speech-card::after {
  content: ''; position: absolute;
  bottom: -10px; right: 20px;
  width: 0; height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 12px solid var(--cpn-card);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.05));
}

/* Animación de mensajes */
.cpn-speech-stage { position: relative; height: 22px; overflow: hidden }
.cpn-speech-msg {
  position: absolute; left: 0; right: 0;
  white-space: nowrap; line-height: 22px;
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 700; color: var(--cpn-ink);
}
.cpn-speech-msg svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--cpn-blue) }

.cpn-speech-msg-1 { opacity: 0; animation: cpn-msg1 5s ease-in-out infinite }
@keyframes cpn-msg1 {
  0% { opacity: 0; transform: translateY(12px) }
  8% { opacity: 1; transform: translateY(0) }
  42% { opacity: 1; transform: translateY(0) }
  50% { opacity: 0; transform: translateY(-12px) }
  100% { opacity: 0; transform: translateY(12px) }
}

.cpn-speech-msg-2 { opacity: 0; animation: cpn-msg2 5s ease-in-out infinite }
@keyframes cpn-msg2 {
  0%,42% { opacity: 0; transform: translateY(12px) }
  50% { opacity: 0; transform: translateY(12px) }
  58% { opacity: 1; transform: translateY(0) }
  92% { opacity: 1; transform: translateY(0) }
  100% { opacity: 0; transform: translateY(-12px) }
}

/* Typing dots */
.cpn-speech-typing {
  position: absolute; left: 0; top: 0; height: 20px;
  display: flex; gap: 4px; align-items: center;
  animation: cpn-typing-vis 5s ease-in-out infinite;
}
@keyframes cpn-typing-vis {
  0% { opacity: 1 } 6% { opacity: 1 } 8% { opacity: 0 }
  42% { opacity: 0 } 48% { opacity: 1 } 50% { opacity: 1 }
  56% { opacity: 0 } 100% { opacity: 0 }
}
.cpn-typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cpn-muted-2);
  animation: cpn-dot-bounce .9s ease-in-out infinite;
}
.cpn-typing-dot:nth-child(2) { animation-delay: .12s }
.cpn-typing-dot:nth-child(3) { animation-delay: .24s }
@keyframes cpn-dot-bounce { 0%,60%,100% { transform: translateY(0) } 30% { transform: translateY(-4px) } }

/* ══════════════════════════════
   FULL TOAST — Expandido
══════════════════════════════ */
.cpn-full-toast {
  position: fixed; bottom: 28px; right: 28px; z-index: 1000;
  max-width: 520px; width: calc(100% - 40px);
  background: var(--cpn-card); border: 1px solid var(--cpn-line);
  border-top: 4px solid var(--cpn-amber); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(27,37,89,.16), 0 4px 12px rgba(27,37,89,.08);
  padding: 24px; overflow: visible;
  transform: translateY(140%); opacity: 0;
  transition: transform .45s cubic-bezier(.16,1,.3,1), opacity .3s;
  pointer-events: none;
}
.cpn-full-toast.cpn-visible { transform: translateY(0); opacity: 1; pointer-events: auto }

.cpn-full-toast-trofi {
  position: absolute; left: -20px; bottom: -12px;
  width: 210px; height: auto; z-index: 2;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,.2));
  animation: cpn-trofi-slide .5s cubic-bezier(.16,1,.3,1) .25s both;
  pointer-events: none;
}
@keyframes cpn-trofi-slide { from { transform: translateY(30px) scale(.85); opacity: 0 } to { transform: translateY(0) scale(1); opacity: 1 } }

.cpn-full-toast-content { margin-left: 178px }
.cpn-full-toast-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px }
.cpn-full-toast-title { font-size: 20px; font-weight: 800; color: var(--cpn-ink) }
.cpn-full-toast-x { background: none; border: none; color: var(--cpn-muted-2); cursor: pointer; font-size: 22px; line-height: 1; padding: 0 }
.cpn-full-toast-x:hover { color: var(--cpn-ink) }
.cpn-full-toast-body { font-size: 14px; color: var(--cpn-muted); line-height: 1.5; margin-bottom: 14px }

.cpn-input-col { display: flex; flex-direction: column; gap: 10px }
.cpn-input-col input { width: 100%; padding: 13px 16px; border: 2px solid var(--cpn-line); border-radius: 10px; font-family: inherit; font-size: 15px; font-weight: 600; color: var(--cpn-ink); outline: none; background: #fff; text-transform: uppercase }
.cpn-input-col input:focus { border-color: var(--cpn-blue); box-shadow: 0 0 0 3px rgba(48,114,232,.12) }
.cpn-input-col input::placeholder { color: var(--cpn-muted-2); font-weight: 500; text-transform: none }
.cpn-input-col button { width: 100%; padding: 13px; background: var(--cpn-blue); color: #fff; border: none; border-radius: 10px; font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer; text-align: center }
.cpn-input-col button:hover { background: var(--cpn-blue-strong) }
.cpn-input-col button:disabled { opacity: .6; cursor: default }

.cpn-applied { display: flex; align-items: center; gap: 8px; padding: 12px 14px; background: var(--cpn-green-soft); border-radius: 10px }
.cpn-applied svg { width: 20px; height: 20px; color: var(--cpn-green); flex-shrink: 0 }
.cpn-applied span { font-size: 13px; font-weight: 700; color: var(--cpn-green-dark) }

/* Mensaje de error dentro del toast y del carrito */
.cpn-error {
  display: flex; align-items: flex-start; gap: 8px;
  margin-top: 10px; padding: 10px 12px;
  background: var(--cpn-red-soft); border-radius: 10px;
  font-size: 12.5px; font-weight: 600; color: var(--cpn-red-dark); line-height: 1.4;
}
.cpn-error svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px }

/* En el carrito la barra fija del total tapa el toast en mobile */
.cpn-mini-toast.cpn-sube, .cpn-full-toast.cpn-sube { bottom: 110px }
@media (min-width: 1200px) {
  .cpn-mini-toast.cpn-sube { bottom: 24px }
  .cpn-full-toast.cpn-sube { bottom: 28px }
}

@media (max-width: 575.98px) {
  .cpn-full-toast { right: 12px; left: 12px; width: auto; padding: 18px }
  .cpn-full-toast-trofi { width: 130px; left: -14px; bottom: -8px }
  .cpn-full-toast-content { margin-left: 112px }
  .cpn-full-toast-title { font-size: 17px }
  .cpn-mini-toast { right: 14px }
}

/* ══ Con el chip del productor (PAS) en pantalla ══
   El chip de components/header_productor_mobile.php es fijo abajo a la derecha,
   la misma esquina que el toast. Cuando entran los dos, el toast se pasa a la
   esquina izquierda (y la puntita del globo cambia de lado para seguir
   apuntando a Trofi). */
.cpn-mini-toast.cpn-con-pas { right: auto; left: 24px; align-items: flex-start }
.cpn-mini-toast.cpn-con-pas .cpn-speech-card::after { right: auto; left: 20px }
.cpn-full-toast.cpn-con-pas { right: auto; left: 28px }

/* Abajo de 992px el toast expandido (520px de ancho) llega hasta donde está el
   chip estirado: ahí sube justo por encima del chip (26px de base + 62px de
   alto). El mini no hace falta subirlo, es angosto y además desaparece al
   expandir. */
@media (max-width: 991.98px) {
  .cpn-full-toast.cpn-con-pas { bottom: 100px }
}

/* En mobile el toast queda abajo del todo, en la esquina opuesta al chip */
@media (max-width: 575.98px) {
  .cpn-mini-toast.cpn-con-pas { left: 14px; bottom: 10px }
  .cpn-full-toast.cpn-con-pas { left: 12px; right: 12px; bottom: 10px }
}

/* Con el panel del PAS abierto el toast se esconde: el panel ocupa media
   pantalla en mobile y el toast, que se dibuja después, le quedaría encima. */
body.cpn-pas-panel-abierto .cpn-mini-toast,
body.cpn-pas-panel-abierto .cpn-full-toast {
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .2s, visibility .2s;
}

/* ══════════════════════════════
   MÓDULO DEL CARRITO
══════════════════════════════ */
.cpn-module {
  position: relative;
  background: var(--cpn-card);
  border-radius: 16px;
  padding: 24px 24px 0 24px;
  margin: 16px auto 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  overflow: visible;
  display: flex; align-items: flex-end; gap: 16px;
}
.cpn-module-trofi {
  width: 130px; height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.14));
  margin-bottom: -4px;
  margin-top: -40px;
}
.cpn-module-right { flex: 1; min-width: 0; padding-bottom: 24px }
.cpn-module-label { font-size: 15px; font-weight: 700; color: var(--cpn-blue); margin-bottom: 14px; display: flex; align-items: center; justify-content: flex-start; gap: 8px }
.cpn-module-label svg { width: 18px; height: 18px; flex-shrink: 0 }
.cpn-input-stack { display: flex; gap: 10px }
.cpn-input-stack input { flex: 1; min-width: 0; padding: 12px 16px; border: 1.5px solid var(--cpn-line); border-radius: 10px; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--cpn-ink); outline: none; background: #fff; text-transform: uppercase }
.cpn-input-stack input:focus { border-color: var(--cpn-blue) }
.cpn-input-stack input::placeholder { color: var(--cpn-muted-2); font-weight: 500; text-transform: none }
.cpn-input-stack button { padding: 12px 24px; background: transparent; color: var(--cpn-blue); border: 1.5px solid var(--cpn-blue); border-radius: 10px; font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap; display: none }
.cpn-input-stack button.cpn-show { display: block }
.cpn-input-stack button:hover { background: var(--cpn-blue-soft) }
.cpn-input-stack button:disabled { opacity: .6; cursor: default }

.cpn-ok { background: var(--cpn-green-soft); border: 1.5px solid var(--cpn-green); border-radius: 12px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 400px; margin: 0 auto }
.cpn-ok-left { display: flex; align-items: center; gap: 8px }
.cpn-ok-left svg { width: 20px; height: 20px; color: var(--cpn-green); flex-shrink: 0 }
.cpn-ok-text { font-size: 14px; font-weight: 700; color: var(--cpn-green-dark) }
.cpn-ok-rm { font-size: 12px; font-weight: 600; color: var(--cpn-muted); text-decoration: underline; cursor: pointer; background: none; border: none; font-family: inherit }

@media (max-width: 575.98px) {
  .cpn-module { padding: 18px 16px 0 16px; gap: 10px }
  .cpn-module-trofi { width: 92px; margin-top: -26px }
  .cpn-module-right { padding-bottom: 18px }
  .cpn-input-stack { flex-direction: column }
  .cpn-input-stack button { width: 100% }
}

/* ══════════════════════════════
   AVISO EN LA FICHA DE PRODUCTO
══════════════════════════════ */
.cpn-inline {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--cpn-green-soft); color: var(--cpn-green-dark);
  font-size: 12px; font-weight: 700;
  padding: 5px 12px; border-radius: 5px;
  margin-bottom: 8px;
}
.cpn-inline svg { width: 14px; height: 14px; flex-shrink: 0 }

/* Precio anterior tachado cuando el descuento lo pone el cupón */
.cpn-precio-old { font-size: 16px; font-weight: 600; color: var(--cpn-muted-2); text-decoration: line-through }
