/* WebG AI v2.1 — Clean */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --c:    #0066cc;
  --cd:   #004fa3;
  --bg:   #ffffff;
  --sur:  #f4f7fb;
  --brd:  #e2e8f0;
  --txt:  #1a202c;
  --muted:#718096;
}

/* ── LAUNCHER ── */
#webg-launcher {
  position:fixed; bottom:24px; right:24px;
  width:60px; height:60px; border-radius:50%;
  background:var(--c); color:#fff; border:none; cursor:pointer;
  z-index:999998; display:flex; align-items:center; justify-content:center;
  box-shadow:0 4px 20px rgba(0,0,0,.3);
  transition:transform .2s,background .2s; outline:none; overflow:hidden;
}
#webg-launcher:hover { transform:scale(1.08); background:var(--cd); }
#webg-launcher svg { width:28px; height:28px; transition:opacity .2s,transform .2s; }
#webg-launcher .ico-chat  { opacity:1; transform:scale(1); position:absolute; }
#webg-launcher .ico-close { opacity:0; transform:scale(.6) rotate(-90deg); position:absolute; }
#webg-launcher.open .ico-chat  { opacity:0; transform:scale(.6) rotate(90deg); }
#webg-launcher.open .ico-close { opacity:1; transform:scale(1); }
.webg-badge {
  position:absolute; top:-2px; right:-2px;
  background:#e53e3e; color:#fff; font-size:10px; font-weight:700;
  width:18px; height:18px; border-radius:50%;
  display:flex; align-items:center; justify-content:center; border:2px solid #fff;
}

/* ── PANEL desktop ── */
#webg-panel {
  position:fixed; bottom:96px; right:24px;
  width:360px; max-width:calc(100vw - 32px);
  height:480px; max-height:calc(100vh - 120px);
  background:var(--bg); border-radius:18px;
  box-shadow:0 8px 40px rgba(0,0,0,.18);
  z-index:999997; display:flex; flex-direction:column;
  overflow:hidden; border:1px solid var(--brd);
  opacity:0; transform:translateY(16px) scale(.97); pointer-events:none;
  transition:opacity .25s,transform .25s;
}
#webg-panel.open { opacity:1; transform:translateY(0) scale(1); pointer-events:all; }

/* ── HEADER ── */
#webg-header {
  background:var(--c); color:#fff;
  padding:14px 16px; display:flex; align-items:center; gap:10px; flex-shrink:0;
}
.webg-avatar {
  width:40px; height:40px; border-radius:50%;
  background:rgba(255,255,255,.15); border:2px solid rgba(255,255,255,.3);
  display:flex; align-items:center; justify-content:center; flex-shrink:0; overflow:hidden;
}
.webg-avatar svg { width:38px; height:38px; }
.webg-header-info { flex:1; min-width:0; }
.webg-name { font-weight:700; font-size:14px; }
.webg-status { font-size:11px; opacity:.85; display:flex; align-items:center; gap:4px; margin-top:2px; }
.webg-dot { width:6px; height:6px; border-radius:50%; background:#48bb78; animation:blink 2s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── QUICK REPLIES ── */
#webg-quick {
  display:flex; flex-wrap:nowrap; gap:6px;
  padding:10px 12px 8px; border-bottom:1px solid var(--brd);
  flex-shrink:0; overflow-x:auto;
}
#webg-quick::-webkit-scrollbar { display:none; }
.webg-qr {
  font-size:12px; padding:6px 12px; border-radius:20px;
  border:1.5px solid var(--brd); color:var(--txt); background:var(--sur);
  cursor:pointer; white-space:nowrap; flex-shrink:0;
  transition:background .15s,color .15s,border-color .15s;
}
.webg-qr:hover { background:var(--c); color:#fff; border-color:var(--c); }

/* ── MESSAGES ── */
#webg-messages {
  flex:1; overflow-y:auto; overflow-x:hidden;
  padding:14px 12px; display:flex; flex-direction:column; gap:10px; width:100%;
}
#webg-messages::-webkit-scrollbar { width:4px; }
#webg-messages::-webkit-scrollbar-thumb { background:var(--brd); border-radius:4px; }

.webg-msg {
  display:flex; flex-direction:column;
  max-width:78%; width:fit-content;
  animation:msgin .2s ease-out;
}
@keyframes msgin { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }
.webg-msg.user { align-self:flex-end; align-items:flex-end; max-width:70%; }
.webg-msg.bot  { align-self:flex-start; align-items:flex-start; }

.webg-bubble {
  padding:10px 14px; border-radius:16px;
  font-size:13.5px; line-height:1.55;
  word-break:break-word; overflow-wrap:break-word; max-width:100%;
}
.webg-msg.user .webg-bubble { background:var(--c); color:#fff; border-bottom-right-radius:4px; }
.webg-msg.bot  .webg-bubble { background:#f0f4f8; color:var(--txt); border-bottom-left-radius:4px; }
.webg-time { font-size:10px; color:var(--muted); margin-top:3px; padding:0 4px; white-space:nowrap; }

.webg-typing .webg-bubble { display:flex; align-items:center; gap:4px; padding:12px 14px; }
.webg-typing .webg-bubble span { width:6px; height:6px; background:var(--muted); border-radius:50%; animation:dot 1.2s infinite; }
.webg-typing .webg-bubble span:nth-child(2){animation-delay:.2s}
.webg-typing .webg-bubble span:nth-child(3){animation-delay:.4s}
@keyframes dot { 0%,80%,100%{transform:scale(.7);opacity:.5} 40%{transform:scale(1);opacity:1} }

/* ── INPUT ── */
#webg-input-area { padding:10px 12px 12px; border-top:1px solid var(--brd); flex-shrink:0; }
.webg-input-wrap {
  display:flex; align-items:flex-end; gap:8px;
  background:var(--sur); border:1.5px solid var(--brd); border-radius:12px;
  padding:8px 8px 8px 12px; transition:border-color .2s;
}
.webg-input-wrap:focus-within { border-color:var(--c); }
#webg-input {
  flex:1; min-width:0; border:none; background:transparent; resize:none; outline:none;
  font-size:13.5px; line-height:1.5; color:var(--txt);
  max-height:90px; min-height:22px; font-family:inherit;
}
#webg-input::placeholder { color:var(--muted); }
#webg-send {
  width:34px; height:34px; border-radius:8px;
  background:var(--c); color:#fff; border:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
  transition:background .15s,transform .1s;
}
#webg-send:hover { background:var(--cd); }
#webg-send:active { transform:scale(.93); }
#webg-send:disabled { background:#a0aec0; cursor:not-allowed; }
#webg-send svg { width:16px; height:16px; }
.webg-powered { text-align:center; font-size:10px; color:var(--muted); padding:4px 0 0; opacity:.7; }
.webg-lead-ok { background:#f0fff4; border:1px solid #9ae6b4; color:#276749; font-size:12px; padding:8px 12px; border-radius:8px; }

/* ══════════════════════════════
   MOBILE
══════════════════════════════ */
@media (max-width: 600px) {

  /* launcher: piccolo, bottom-right, Z alto */
  #webg-launcher {
    width:50px !important; height:50px !important;
    bottom:20px !important; right:16px !important;
    z-index:999999 !important;
  }
  #webg-launcher svg { width:22px !important; height:22px !important; }

  /* panel: fullscreen, sotto la status bar */
  #webg-panel {
    position:fixed !important;
    top:0 !important; left:0 !important; right:0 !important; bottom:0 !important;
    width:100% !important; max-width:100% !important;
    height:100% !important; max-height:100% !important;
    border-radius:0 !important; border:none !important;
    z-index:999997 !important;
  }

  /* header: padding per status bar iOS */
  #webg-header {
    padding:14px 16px 14px !important;
    padding-top:max(14px, env(safe-area-inset-top, 14px)) !important;
    min-height:70px;
  }
  .webg-avatar { width:46px !important; height:46px !important; }
  .webg-name { font-size:17px !important; }
  .webg-status { font-size:13px !important; }

  /* quick: riga unica scorrevole, colori neutri NON verdi */
  #webg-quick {
    flex-wrap:nowrap !important; overflow-x:auto !important;
    padding:10px 14px 8px !important; gap:8px !important;
    background:var(--bg) !important;
  }
  .webg-qr {
    font-size:13px !important; padding:7px 14px !important;
    background:var(--sur) !important; color:var(--txt) !important;
    border-color:var(--brd) !important;
  }
  .webg-qr:hover, .webg-qr:active {
    background:var(--c) !important; color:#fff !important; border-color:var(--c) !important;
  }

  /* messages */
  #webg-messages {
    flex:1 !important; overflow-y:auto !important; overflow-x:hidden !important;
    padding:16px 14px !important; width:100% !important;
  }

  /* bolle: max-width stretto per non uscire mai */
  .webg-msg { max-width:75% !important; }
  .webg-msg.user { max-width:65% !important; align-self:flex-end !important; }
  .webg-msg.bot  { max-width:82% !important; align-self:flex-start !important; }
  .webg-bubble { font-size:15px !important; line-height:1.6 !important; padding:11px 14px !important; }
  .webg-time { font-size:11px !important; }

  /* input: fisso in basso */
  #webg-input-area {
    flex-shrink:0 !important;
    padding:10px 14px !important;
    padding-bottom:max(10px, env(safe-area-inset-bottom, 10px)) !important;
    background:var(--bg) !important;
    border-top:1px solid var(--brd) !important;
  }
  .webg-input-wrap {
    border-radius:24px !important; padding:10px 10px 10px 16px !important;
  }
  #webg-input { font-size:15px !important; }
  #webg-send {
    width:38px !important; height:38px !important; border-radius:50% !important;
  }
  #webg-send svg { width:17px !important; height:17px !important; }
  .webg-powered { padding:6px 0 4px !important; font-size:11px !important; }
}
