/* Maia v1.2 — Disevidenze */

/* ── STYLE ISOLATION: blocca l'ereditarietà dal tema del sito (Elementor ecc.) ── */
#maya-panel, #maya-panel *, #maya-panel *::before, #maya-panel *::after,
#maya-launcher, #maya-launcher *, #maya-launcher *::before, #maya-launcher *::after,
#maya-hint {
  box-sizing: border-box !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  font-style: normal !important;
  text-shadow: none !important;
}
#maya-panel button, #maya-launcher button {
  -webkit-appearance: none !important; appearance: none !important;
  margin: 0 !important; min-width: 0 !important; max-width: none !important;
  box-shadow: none !important;
  font-weight: 400;
  line-height: normal;
}

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

/* ── LAUNCHER ── */
#maya-launcher {
  position:fixed; bottom:20px; right:20px;
  width:64px; height:64px; border-radius:50%;
  background:#ffffff; border:none; cursor:pointer;
  z-index:999998; display:flex; align-items:center; justify-content:center;
  box-shadow:0 4px 20px rgba(0,0,0,.25);
  transition:transform .2s; outline:none; overflow:visible;
  padding:0;
}
#maya-launcher:hover { transform:scale(1.08); }
#maya-launcher svg { width:28px; height:28px; transition:opacity .2s,transform .2s; }
#maya-launcher img.ico-chat { width:64px; height:64px; border-radius:50%; object-fit:cover; transition:opacity .2s,transform .2s; }
#maya-launcher .ico-chat  { opacity:1; transform:scale(1); position:absolute; }
#maya-launcher .ico-close { opacity:0; transform:scale(.6) rotate(-90deg); position:absolute; background:rgba(0,0,0,0.5); border-radius:50%; padding:4px; }
#maya-launcher.open .ico-chat  { opacity:0; transform:scale(.6) rotate(90deg); }
#maya-launcher.open .ico-close { opacity:1; transform:scale(1); }
.maya-badge {
  position:absolute; top:0px; right:0px;
  background:#e53e3e; color:#fff; font-size:9px; font-weight:700;
  width:18px; height:18px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  border:2px solid #fff; z-index:2;
  pointer-events:none;
}

/* ── PANEL desktop ── */
#maya-panel {
  position:fixed; bottom:96px; right:24px;
  width:360px; max-width:calc(100vw - 32px);
  height:480px; max-height:calc(100vh - 120px);
  background:#ffffff; 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;
}
#maya-panel.open { opacity:1; transform:translateY(0) scale(1); pointer-events:all; }

/* ── LAYOUT ORDER: saluto in alto, azioni rapide sopra al campo di scrittura ── */
#maya-header      { order:0; }
#maya-messages    { order:1; }
#maya-quick       { order:2; }
#maya-input-area  { order:3; }
#maya-quick:empty { display:none !important; padding:0 !important; border:none !important; }

/* ── HEADER ── */
#maya-header {
  background:var(--c); color:#fff;
  padding:14px 16px; display:flex; align-items:center; gap:10px; flex-shrink:0;
}
.maya-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;
}
.maya-avatar svg { width:38px; height:38px; }
.maya-header-info { flex:1; min-width:0; }
.maya-name { font-weight:700; font-size:14px; }
.maya-status { font-size:11px; opacity:.85; display:flex; align-items:center; gap:4px; margin-top:2px; }
.maya-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 ── */
#maya-quick {
  display:flex; flex-direction:column; gap:7px;
  padding:12px 14px 10px; border-top:1px solid var(--brd);
  flex-shrink:0; width:100%; overflow:hidden;
}
.maya-qr {
  display:flex !important; align-items:center; gap:9px;
  width:100% !important;
  font-size:13px !important; font-weight:500 !important;
  padding:10px 14px !important; border-radius:12px !important;
  border:1.5px solid var(--brd) !important; color:var(--txt); background:var(--sur);
  cursor:pointer; text-align:left; line-height:1.3;
  white-space:normal; word-break:break-word;
  transition:background .15s, color .15s, border-color .15s, transform .1s;
}
.maya-qr:hover { background:var(--c); color:#fff; border-color:var(--c); transform:translateY(-1px); }
.maya-qr:active { transform:translateY(0); }

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

.maya-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)} }
.maya-msg.user { align-self:flex-end; align-items:flex-end; max-width:70%; }
.maya-msg.bot  { align-self:flex-start; align-items:flex-start; }

.maya-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%;
}
.maya-msg.user .maya-bubble { background:var(--c); color:#fff; border-bottom-right-radius:4px; }
.maya-msg.bot  .maya-bubble { background:#f0f4f8; color:var(--txt); border-bottom-left-radius:4px; }
.maya-time { font-size:10px; color:var(--muted); margin-top:3px; padding:0 4px; white-space:nowrap; }

.maya-typing .maya-bubble { display:flex; align-items:center; gap:4px; padding:12px 14px; }
.maya-typing .maya-bubble span { width:6px; height:6px; background:var(--muted); border-radius:50%; animation:dot 1.2s infinite; }
.maya-typing .maya-bubble span:nth-child(2){animation-delay:.2s}
.maya-typing .maya-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 ── */
#maya-input-area { padding:10px 12px 12px; border-top:1px solid var(--brd); flex-shrink:0; }
.maya-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;
}
.maya-input-wrap:focus-within { border-color:var(--c); }
#maya-input {
  flex:1; min-width:0; border:none; background:#ffffff; resize:none; outline:none;
  font-size:13.5px; line-height:1.5; color:var(--txt);
  max-height:90px; min-height:22px; font-family:inherit;
}
#maya-input::placeholder { color:var(--muted); }
#maya-send {
  width:38px !important; height:38px !important; border-radius:50% !important;
  padding:0 !important; flex-shrink:0 !important;
  background:var(--c); color:#fff; border:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  transition:background .15s,transform .1s;
}
#maya-send:hover:not(:disabled) { background:var(--cd); }
#maya-send:active:not(:disabled) { transform:scale(.93); }
#maya-send:disabled { background:var(--c); opacity:.4; cursor:not-allowed; }
#maya-send svg { width:17px; height:17px; }
.maya-powered { text-align:center; font-size:10px; color:var(--muted); padding:4px 0 0; opacity:.7; }
.maya-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 */
  #maya-launcher {
    width:64px !important; height:64px !important;
    bottom:20px !important; right:16px !important;
    z-index:999999 !important;
  }
  #maya-launcher svg { width:22px !important; height:22px !important; }

  /* panel: fullscreen, sotto la status bar */
  #maya-panel {
    position:fixed !important;
    top:0 !important; left:0 !important; right:0 !important; bottom:0 !important;
    width:100vw !important; max-width:100vw !important;
    height:100% !important; max-height:100% !important;
    border-radius:0 !important; border:none !important;
    z-index:999997 !important;
    background:#ffffff !important;
    -webkit-overflow-scrolling: touch !important;
  }

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

  /* quick: riga unica scorrevole, colori neutri NON verdi */
  #maya-quick {
    flex-direction:column !important;
    overflow-x:hidden !important;
    padding:12px 14px 10px !important;
    gap:8px !important;
    background:#ffffff !important;
    border-top:1px solid var(--brd) !important;
    border-bottom:none !important;
  }
  .maya-qr {
    font-size:14px !important;
    padding:12px 14px !important;
    background:var(--sur) !important;
    color:var(--txt) !important;
    border-color:var(--brd) !important;
    width:100% !important;
    text-align:left !important;
    white-space:normal !important;
  }
  .maya-qr:hover, .maya-qr:active {
    background:var(--c) !important; color:#fff !important; border-color:var(--c) !important;
  }

  /* messages */
  #maya-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 */
  .maya-msg { max-width:75% !important; }
  .maya-msg.user {
    max-width:62% !important;
    align-self:flex-end !important;
    margin-right:0 !important;
    overflow:hidden !important;
    word-break:break-word !important;
  }
  .maya-msg.bot  { max-width:82% !important; align-self:flex-start !important; }
  .maya-bubble { font-size:15px !important; line-height:1.6 !important; padding:11px 14px !important; }
  .maya-time { font-size:11px !important; }

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

/* Close button in header (mobile) */
#maya-close-btn {
  flex-shrink: 0;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  margin-left: auto;
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  width: 34px; height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
  transition: background .15s;
}
#maya-close-btn:hover { background: rgba(255,255,255,.35); }

@media (max-width: 600px) {
  /* bolla utente - fix overflow definitivo */
  #maya-messages {
    padding-right: 16px !important;
  }
  .maya-msg.user .maya-bubble {
    margin-right: 0 !important;
  }
  /* send button sempre blu */
  #maya-send {
    background: var(--c) !important;
  }
  #maya-send:not(:disabled) {
    background: var(--c) !important;
    opacity: 1 !important;
  }
  #maya-send:disabled {
    background: var(--c) !important;
    opacity: 0.45 !important;
  }
}

@media (max-width: 600px) {
  /* panel chiuso su mobile: nascosto completamente */
  #maya-panel:not(.open) {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }
  /* panel aperto su mobile: visibile e solido */
  #maya-panel.open {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: all !important;
    background: #ffffff !important;
  }
  /* launcher più grande */
  #maya-launcher {
    width: 58px !important;
    height: 58px !important;
    bottom: 24px !important;
    right: 20px !important;
  }
  #maya-launcher svg { width: 26px !important; height: 26px !important; }
}
