* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

  :root {
    --wa-green: #25D366;
    --wa-green-dark: #128C7E;
    --wa-green-light: #DCF8C6;
    --wa-bg: #ECE5DD;
    --wa-header: #075E54;
    --wa-bubble-out: #DCF8C6;
    --wa-bubble-in: #FFFFFF;
    --wa-text: #111B21;
    --wa-text-secondary: #667781;
    --wa-input-bg: #FFFFFF;
    --wa-footer-bg: #F0F2F5;
    --wa-shadow: rgba(0,0,0,0.13);
    --wa-btn: #25D366;
    --wa-btn-text: #fff;
    --radius-bubble: 7.5px;
  }

  html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--wa-header);
    overflow: hidden;
  }

  #app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    background: var(--wa-bg);
    box-shadow: 0 0 40px rgba(0,0,0,0.3);
  }

  /* HEADER */
  .chat-header {
    background: var(--wa-header);
    padding: 10px 16px 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
    flex-shrink: 0;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .header-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #25D366, #128C7E);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
  .header-info { flex: 1; min-width: 0; }
  .header-name {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .header-status {
    color: rgba(255,255,255,0.75);
    font-size: 12px;
    display: flex; align-items: center; gap: 4px;
  }
  .status-dot {
    width: 7px; height: 7px;
    background: var(--wa-green);
    border-radius: 50%;
    animation: pulse 2s infinite;
  }
  @keyframes pulse {
    0%,100% { opacity: 1; }
    50% { opacity: 0.4; }
  }
  .header-icons { display: flex; gap: 18px; }
  .header-icons svg { fill: rgba(255,255,255,0.8); width: 22px; height: 22px; }

  /* BACKGROUND PATTERN */
  .chat-bg {
    position: absolute;
    inset: 0;
    background-color: #ECE5DD;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='88' height='88'%3E%3Cg fill='none' stroke='%23d4ccc4' stroke-width='0.8' opacity='0.5'%3E%3Cpath d='M44 2c11.6 0 22 4.7 29.6 12.4C81.3 22 86 32.4 86 44s-4.7 22-12.4 29.6C66 81.3 55.6 86 44 86s-22-4.7-29.6-12.4C6.7 66 2 55.6 2 44s4.7-22 12.4-29.6C22 6.7 32.4 2 44 2z'/%3E%3Cpath d='M44 14c8.3 0 15.8 3.4 21.2 8.8C70.6 28.2 74 35.7 74 44s-3.4 15.8-8.8 21.2C59.8 70.6 52.3 74 44 74s-15.8-3.4-21.2-8.8C17.4 59.8 14 52.3 14 44s3.4-15.8 8.8-21.2C28.2 17.4 35.7 14 44 14z'/%3E%3C/g%3E%3C/svg%3E");
    z-index: 0;
  }

  /* MESSAGES AREA */
  .chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;   /* hidden (não clip) permite que filhos usem margens negativas */
    padding: 12px 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    position: relative;
    z-index: 1;
    scroll-behavior: smooth;
  }
  .chat-messages::-webkit-scrollbar { width: 4px; }
  .chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }

  /* DATE DIVIDER */
  .date-divider {
    display: flex; align-items: center; justify-content: center;
    margin: 8px 0;
  }
  .date-divider span {
    background: rgba(225,245,254,0.92);
    color: #54656F;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 7px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
    font-weight: 500;
  }

  /* BUBBLES */
  .message {
    display: flex;
    max-width: 78%;
    animation: msgIn 0.2s ease-out;
  }
  @keyframes msgIn {
    from { opacity: 0; transform: translateY(6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }
  .message.bot { align-self: flex-start; }
  .message.user { align-self: flex-end; }

  .bubble {
    padding: 7px 10px 6px;
    border-radius: var(--radius-bubble);
    position: relative;
    box-shadow: 0 1px 2px var(--wa-shadow);
    word-break: break-word;
    line-height: 1.45;
    font-size: 14.5px;
  }
  .message.bot .bubble {
    background: var(--wa-bubble-in);
    color: var(--wa-text);
    border-top-left-radius: 2px;
    margin-left: 2px;
  }
  .message.bot .bubble::before {
    content: '';
    position: absolute;
    top: 0; left: -8px;
    border: 8px solid transparent;
    border-top-color: var(--wa-bubble-in);
    border-right: none;
  }
  .message.user .bubble {
    background: var(--wa-bubble-out);
    color: var(--wa-text);
    border-top-right-radius: 2px;
    margin-right: 2px;
  }
  .message.user .bubble::after {
    content: '';
    position: absolute;
    top: 0; right: -8px;
    border: 8px solid transparent;
    border-top-color: var(--wa-bubble-out);
    border-left: none;
  }

  .bubble-time {
    font-size: 11px;
    color: var(--wa-text-secondary);
    float: right;
    margin-left: 10px;
    margin-top: 2px;
    display: flex; align-items: center; gap: 2px;
  }
  .check-icon { color: #53BDEB; font-size: 13px; }

  /* TYPING INDICATOR */
  .typing-bubble {
    background: var(--wa-bubble-in);
    border-radius: var(--radius-bubble);
    border-top-left-radius: 2px;
    padding: 12px 14px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 1px 2px var(--wa-shadow);
    margin-left: 2px;
    animation: msgIn 0.2s ease-out;
  }
  .typing-bubble::before {
    content: '';
    position: absolute;
    top: 0; left: -8px;
    border: 8px solid transparent;
    border-top-color: var(--wa-bubble-in);
    border-right: none;
  }
  .dot {
    width: 8px; height: 8px;
    background: #90A4AE;
    border-radius: 50%;
    animation: bounce 1.3s infinite;
  }
  .dot:nth-child(2) { animation-delay: 0.15s; }
  .dot:nth-child(3) { animation-delay: 0.3s; }
  @keyframes bounce {
    0%,60%,100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
  }

  /* QUICK REPLY BUTTONS */
  .quick-replies {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    align-self: flex-start;
    width: 100%;
    max-width: 260px;
    animation: msgIn 0.25s ease-out;
  }
  .qr-btn {
    background: #fff;
    border: 1.5px solid var(--wa-green);
    color: var(--wa-green-dark);
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, color 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    -webkit-user-select: none; user-select: none;
  }
  .qr-btn:active, .qr-btn:hover { background: var(--wa-green); color: #fff; }

  /* IMAGE PREVIEW IN BUBBLE */
  .img-preview {
    max-width: 200px;
    border-radius: 6px;
    display: block;
    margin-bottom: 4px;
  }

  /* FOOTER */
  .chat-footer {
    background: var(--wa-footer-bg);
    padding: 8px 10px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    z-index: 10;
    flex-shrink: 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    position: relative;
  }
  .footer-actions { display: flex; align-items: center; gap: 6px; }
  .icon-btn {
    background: none; border: none; cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
  }
  .icon-btn:active { background: rgba(0,0,0,0.07); }
  .icon-btn svg { width: 24px; height: 24px; fill: var(--wa-text-secondary); }

  .input-wrap {
    flex: 1;
    background: var(--wa-input-bg);
    border-radius: 22px;
    display: flex;
    align-items: flex-end;
    padding: 6px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    min-height: 44px;
    max-height: 120px;
  }
  #msg-input {
    flex: 1;
    border: none; outline: none;
    background: transparent;
    font-size: 15px;
    color: var(--wa-text);
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    font-family: inherit;
    padding: 2px 0;
  }
  #msg-input::placeholder { color: #8696A0; }
  #msg-input:disabled { opacity: 0.5; cursor: not-allowed; }

  .send-btn {
    width: 44px; height: 44px;
    background: var(--wa-green);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
    box-shadow: 0 2px 6px rgba(37,211,102,0.4);
  }
  .send-btn:active { transform: scale(0.93); background: var(--wa-green-dark); }
  .send-btn svg { fill: #fff; width: 22px; height: 22px; }
  .send-btn:disabled { background: #c5e8d0; box-shadow: none; cursor: not-allowed; }

  /* Upload label */
  #upload-label {
    display: none;
  }

  /* Final summary card */
  .summary-card {
    background: #fff;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.7;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    margin-bottom: 2px;
  }
  .summary-card .summary-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--wa-header);
    margin-bottom: 6px;
  }

  /* WA button */
  .wa-open-btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--wa-green);
    color: #fff;
    border: none;
    border-radius: 22px;
    padding: 11px 20px;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(37,211,102,0.4);
    transition: background 0.15s;
  }
  .wa-open-btn:active { background: var(--wa-green-dark); }

  /* Hidden file input */
  #file-input { display: none; }

  /* ── CARROSSEL ──────────────────────────────────────────────── */
  /*
     IMPORTANTE: o wrapper precisa escapar do fluxo normal das
     mensagens (max-width: 78%) para ocupar a largura toda da tela.
     Fazemos isso com margens negativas + largura explícita.
  */
  .carousel-wrapper {
    /* ocupa toda a largura do chat, ignorando o max-width das bubbles */
    width: calc(100vw - 0px);
    max-width: 480px;          /* mesma max-width do #app */
    margin-left: calc(-8px);   /* compensa o padding do chat-messages */
    margin-top: 6px;
    /* NÃO usar overflow:hidden aqui — bloqueia o scroll horizontal */
    overflow: visible;
    animation: msgIn 0.25s ease-out;
    align-self: stretch;       /* estica no flex column */
  }
  .carousel-track {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: visible;
    padding: 4px 12px 12px;
    scroll-snap-type: x mandatory;
    /* essencial para scroll suave em iOS */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* evita que o pai corte o scroll */
    touch-action: pan-x;
  }
  .carousel-track::-webkit-scrollbar { display: none; }
  .carousel-card {
    /* 42vw garante ~2 cards visíveis em qualquer celular */
    flex: 0 0 42vw;
    max-width: 160px;
    min-width: 130px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    overflow: hidden;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    transition: transform 0.15s;
    border: 2px solid transparent;
    /* impede que o card encolha */
    flex-shrink: 0;
  }
  .carousel-card:active { transform: scale(0.97); }
  .carousel-img-placeholder {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    flex-shrink: 0;
  }
  .carousel-img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
  }
  .carousel-body {
    padding: 8px 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }
  .carousel-title {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--wa-header);
    text-align: center;
  }
  .carousel-desc {
    font-size: 11px;
    color: var(--wa-text-secondary);
    text-align: center;
    line-height: 1.35;
    flex: 1;
  }
  .carousel-btn {
    margin-top: 6px;
    background: var(--wa-green);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 7px 10px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
    /* área de toque mínima para mobile */
    min-height: 36px;
    touch-action: manipulation;
  }
  .carousel-btn:active { background: var(--wa-green-dark); }
  .carousel-hint {
    font-size: 11px;
    color: var(--wa-text-secondary);
    text-align: center;
    padding: 2px 8px 5px;
  }