/* ============================================================
   bot-bubble.css
   Estrategia: El botón flotante se pinta con CSS puro (FCP inmediato).
   La lógica pesada se inyecta solo después del click via import().
   @layer bot — aislado para evitar colisión con global.css
   ============================================================ */

@layer bot {

  /* ---- Trigger button ---- */
  .bot-trigger {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: var(--z-bot, 400);

    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--color-midnight, #1a237e);
    box-shadow:
      0 4px 24px rgba(26,35,126,0.35),
      0 0 0 4px rgba(179,155,114,0.15);
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    /* Contain paint to avoid repaints propagating */
    contain: layout style;
    will-change: transform;

    transition:
      transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
      box-shadow 220ms ease;
  }

  .bot-trigger:hover {
    transform: scale(1.1);
    box-shadow:
      0 8px 36px rgba(26,35,126,0.45),
      0 0 0 6px rgba(179,155,114,0.2);
  }

  .bot-trigger:active { transform: scale(0.95); }

  .bot-trigger svg {
    width: 26px;
    height: 26px;
    stroke: var(--color-champagne, #b39b72);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
  }

  /* Pulse ring animation — CSS only, no JS */
  .bot-trigger::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(179,155,114,0.4);
    animation: bot-pulse 2.4s cubic-bezier(0, 0, 0.2, 1) infinite;
    pointer-events: none;
  }

  @keyframes bot-pulse {
    0%   { opacity: 1; transform: scale(1); }
    70%  { opacity: 0; transform: scale(1.5); }
    100% { opacity: 0; transform: scale(1.5); }
  }

  /* Badge notification dot */
  .bot-trigger__badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: var(--color-champagne, #b39b72);
    border: 2px solid var(--color-white, #fff);
    border-radius: 50%;
    font-size: 0;
  }

  /* Icons — chat open / close states */
  .bot-trigger__icon-chat { display: block; }
  .bot-trigger__icon-close { display: none; }

  .bot-trigger[aria-expanded="true"] .bot-trigger__icon-chat { display: none; }
  .bot-trigger[aria-expanded="true"] .bot-trigger__icon-close { display: block; }

  /* ---- Widget shell (injected by shell.js) ---- */
  .bot-widget {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: var(--z-bot, 400);
    width: 360px;
    max-width: calc(100vw - 40px);
    border-radius: var(--radius-lg, 24px);
    background: var(--color-white, #fff);
    box-shadow: 0 24px 80px rgba(26,35,126,0.22);
    border: 1px solid rgba(26,35,126,0.08);
    overflow: hidden;

    /* Animate in/out with transform + opacity */
    transform-origin: bottom right;
    transition:
      transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1),
      opacity 220ms ease;
  }

  .bot-widget[hidden] {
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    /* hidden attr removes from flow — use visibility trick for animation */
    visibility: hidden;
  }

  /* Override hidden to allow CSS transition */
  .bot-widget.is-closing {
    display: block !important;
    visibility: visible;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
  }

  .bot-widget.is-open {
    visibility: visible;
    transform: scale(1) translateY(0);
    opacity: 1;
  }

  /* Widget header */
  .bot-widget__header {
    background: var(--color-midnight, #1a237e);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .bot-widget__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--color-champagne, #b39b72);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-midnight, #1a237e);
  }

  .bot-widget__info { flex: 1; }
  .bot-widget__name {
    font-family: var(--font-serif, serif);
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-white, #fff);
    line-height: 1.2;
  }
  .bot-widget__status {
    font-size: 0.6875rem;
    color: rgba(255,255,255,0.55);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
  }
  .bot-widget__status::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #68d391; /* green dot */
    flex-shrink: 0;
  }

  /* Widget body — messages area */
  .bot-widget__body {
    height: 300px;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;

    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(26,35,126,0.15) transparent;
  }

  .bot-widget__body::-webkit-scrollbar { width: 4px; }
  .bot-widget__body::-webkit-scrollbar-track { background: transparent; }
  .bot-widget__body::-webkit-scrollbar-thumb { background: rgba(26,35,126,0.15); border-radius: 4px; }

  /* Messages */
  .bot-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.55;
    animation: bot-msg-in 240ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

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

  .bot-msg--bot {
    background: var(--color-off-white, #f8f9fa);
    color: var(--color-text-primary, #0d1757);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
  }

  .bot-msg--user {
    background: var(--color-midnight, #1a237e);
    color: var(--color-white, #fff);
    border-bottom-right-radius: 4px;
    align-self: flex-end;
  }

  /* Typing indicator */
  .bot-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
    background: var(--color-off-white, #f8f9fa);
    border-radius: 16px 16px 16px 4px;
    align-self: flex-start;
    max-width: 64px;
  }
  .bot-typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: rgba(26,35,126,0.3);
    animation: bot-blink 1.2s infinite ease-in-out;
  }
  .bot-typing span:nth-child(2) { animation-delay: 0.2s; }
  .bot-typing span:nth-child(3) { animation-delay: 0.4s; }

  @keyframes bot-blink {
    0%, 80%, 100% { transform: scale(1); opacity: 0.4; }
    40%           { transform: scale(1.3); opacity: 1; }
  }

  /* Quick replies */
  .bot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 8px;
  }
  .bot-quick-reply {
    padding: 6px 14px;
    background: transparent;
    border: 1.5px solid rgba(26,35,126,0.2);
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-midnight, #1a237e);
    cursor: pointer;
    transition: background 160ms, border-color 160ms, color 160ms;
  }
  .bot-quick-reply:hover {
    background: var(--color-midnight, #1a237e);
    border-color: var(--color-midnight, #1a237e);
    color: var(--color-white, #fff);
  }

  /* Widget footer — input area */
  .bot-widget__footer {
    border-top: 1px solid rgba(26,35,126,0.07);
    padding: 12px 14px;
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .bot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid rgba(26,35,126,0.15);
    border-radius: 100px;
    font-family: var(--font-sans, sans-serif);
    font-size: 0.875rem;
    color: var(--color-text-primary, #0d1757);
    background: var(--color-off-white, #f8f9fa);
    transition: border-color 160ms, box-shadow 160ms;
  }
  .bot-input:focus {
    outline: none;
    border-color: var(--color-midnight, #1a237e);
    box-shadow: 0 0 0 3px rgba(26,35,126,0.08);
  }
  .bot-input::placeholder { color: var(--color-text-muted, #718096); }

  .bot-send {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--color-champagne, #b39b72);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 160ms, transform 160ms;
  }
  .bot-send:hover { background: var(--color-champagne-lt, #c9b48e); transform: scale(1.08); }
  .bot-send svg { width: 16px; height: 16px; stroke: var(--color-midnight, #1a237e); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

  /* Loading skeleton inside widget body */
  .bot-skeleton {
    display: flex; flex-direction: column; gap: 12px; padding: 20px 16px;
  }
  .bot-skeleton__line {
    height: 12px;
    border-radius: 100px;
    background: linear-gradient(90deg, #e8edf5 25%, #f4f6fc 50%, #e8edf5 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s infinite linear;
  }
  .bot-skeleton__line:nth-child(1) { width: 70%; }
  .bot-skeleton__line:nth-child(2) { width: 55%; margin-left: auto; }
  .bot-skeleton__line:nth-child(3) { width: 80%; }

  @keyframes skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }

  /* Reduced motion overrides */
  @media (prefers-reduced-motion: reduce) {
    .bot-trigger::before { animation: none; }
    .bot-typing span     { animation: none; opacity: 0.5; }
    .bot-skeleton__line  { animation: none; }
    .bot-msg             { animation: none; }
  }

  /* Mobile adjustments */
  @media (max-width: 480px) {
    .bot-trigger { bottom: 16px; right: 16px; }
    .bot-widget  { bottom: 88px; right: 12px; left: 12px; width: auto; max-width: none; }
  }
}
