/* ===================== CHAT WIDGET ===================== */

/* Bubble trigger — pill with icon + label */
.chat-bubble-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px 12px 14px;
  border-radius: 100px;
  background: linear-gradient(135deg, #4B9B2B 0%, #6BC839 100%);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(75,155,43,0.45), 0 4px 12px rgba(0,0,0,0.18);
  z-index: 9998;
  transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
  font-family: inherit;
  isolation: isolate;
}
.chat-bubble-trigger:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 14px 36px rgba(75,155,43,0.55), 0 6px 16px rgba(0,0,0,0.22); }
.chat-bubble-trigger:active { transform: translateY(0) scale(0.98); }
.chat-bubble-trigger.hidden { display: none; }

/* Compact mode — collapse to icon-only (e.g. when footer in viewport) */
.chat-bubble-trigger.compact { padding: 10px; gap: 0; }
.chat-bubble-trigger.compact .ctb-text { display: none; }
.chat-bubble-trigger.compact .ctb-icon { background: transparent; width: 36px; height: 36px; }

.chat-bubble-trigger .ctb-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-bubble-trigger .ctb-text {
  display: inline-flex; flex-direction: column; align-items: flex-start;
  line-height: 1.15;
  text-align: left;
}
.chat-bubble-trigger .ctb-title {
  font-size: 14px; font-weight: 700; letter-spacing: 0.2px;
}
.chat-bubble-trigger .ctb-sub {
  font-size: 11px; font-weight: 500; opacity: 0.92;
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 2px;
}
.chat-bubble-trigger .ctb-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #A3FF6B;
  box-shadow: 0 0 0 0 rgba(163,255,107,0.7);
  animation: ctb-dot-pulse 2s ease-out infinite;
  display: inline-block;
}
@keyframes ctb-dot-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(163,255,107,0.7); }
  70%  { box-shadow: 0 0 0 8px rgba(163,255,107,0); }
  100% { box-shadow: 0 0 0 0 rgba(163,255,107,0); }
}

/* Halo — soft expanding ring around trigger */
.chat-bubble-trigger .ctb-halo {
  position: absolute;
  inset: -6px;
  border-radius: 100px;
  background: radial-gradient(closest-side, rgba(107,200,57,0.45), transparent 70%);
  z-index: -1;
  animation: ctb-halo 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes ctb-halo {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50%      { transform: scale(1.12); opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-bubble-trigger .ctb-dot,
  .chat-bubble-trigger .ctb-halo { animation: none; }
}

/* Widget panel */
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: min(720px, calc(100vw - 48px));
  height: min(720px, calc(100vh - 48px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat-widget.open { display: flex; }

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.chat-header-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.chat-header-title {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}
.chat-header-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
  transition: background 0.2s;
}
.chat-header-btn:hover { background: var(--darker); }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Bubbles — same style as site mockup */
.chat-msg { display: flex; gap: 8px; align-items: flex-end; }
.chat-msg.user { flex-direction: row-reverse; }
.chat-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.chat-msg.bot .chat-msg-avatar {
  background: linear-gradient(135deg, var(--green), var(--accent));
}
.chat-msg-text {
  max-width: 75%;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-msg.bot .chat-msg-text {
  background: var(--darker);
  border: 1px solid var(--border);
  border-radius: 4px 12px 12px 12px;
  color: var(--text);
}
.chat-msg.user .chat-msg-text {
  background: var(--green);
  color: var(--btn-text);
  font-weight: 600;
  border-radius: 12px 4px 12px 12px;
}

/* Loading dots */
.chat-msg-loading .chat-msg-text::after {
  content: '...';
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* Upload placeholder */
.chat-msg-upload .chat-msg-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-style: italic;
  color: var(--muted);
}
.upload-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Input bar */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.chat-input-bar input[type="text"] {
  flex: 1;
  background: var(--darker);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--input-text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input-bar input[type="text"]:focus { border-color: var(--green); }
.chat-input-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--muted);
  padding: 4px;
  transition: color 0.2s;
}
.chat-input-btn:hover { color: var(--green); }
.chat-input-btn.send {
  background: var(--green);
  color: var(--btn-text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.chat-input-btn.send:hover { opacity: 0.85; }

/* File input (hidden) */
.chat-file-input { display: none; }

/* Connection status */
.chat-status {
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--muted);
  background: var(--darker);
}
.chat-status.error { color: var(--red); }

/* Clickable offer-choose links — testo + dashed underline (no pill) */
.chat-msg .aef-choose {
  color: var(--green);
  font-weight: 600;
  text-decoration: underline dashed rgba(75,155,43,0.55);
  text-underline-offset: 2px;
  cursor: pointer;
  transition: color 0.15s, text-decoration-color 0.15s;
}
.chat-msg .aef-choose:hover {
  color: #2f6f1a;
  text-decoration-style: solid;
  text-decoration-color: var(--green);
}

/* ── Offerte chat: tag tipo prezzo, durata pill, prezzo 2 righe, reco box ── */
.aef-tag{display:inline-block;padding:1px 6px;border-radius:4px;font-size:9px;font-weight:700;letter-spacing:0.5px;margin-left:6px;vertical-align:middle;line-height:1.4}
.aef-tag-fix{background:#DBEAFE;color:#1E40AF}
.aef-tag-idx{background:#FEF3C7;color:#92400E}
.aef-dur{display:inline-block;padding:2px 8px;border-radius:100px;font-size:11px;font-weight:600;line-height:1.4;white-space:nowrap}
.aef-dur-12{background:#DCFCE7;color:#166534}
.aef-dur-24{background:#DBEAFE;color:#1E40AF}
.aef-dur-36{background:#EDE9FE;color:#5B21B6}
.aef-price-main{font-weight:700;color:#0F172A;display:block}
.aef-price-sub{font-size:10px;color:#64748B;margin-top:2px;display:block;font-weight:500}
.aef-reco-box{margin:14px 0 8px;background:rgba(255,255,255,0.95);color:#0F172A;border-radius:10px;padding:14px 16px;border-left:4px solid #FBBF24;box-shadow:0 2px 8px rgba(0,0,0,0.12)}
.aef-reco-box h3{font-size:12px;font-weight:800;letter-spacing:0.5px;text-transform:uppercase;color:#B45309;margin:0 0 8px;border:none}
.aef-reco-row{padding:6px 0;color:#0F172A;font-size:13px}
.aef-reco-row + .aef-reco-row{border-top:1px solid #F1F5F9}
.aef-reco-label{font-weight:700;color:#0F172A}
.aef-reco-name{color:#065F46;font-weight:600}

/* Markdown tables — variant A light: card neutra dentro bubble */
.chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 10px 0;
  background: #FFFFFF;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  font-variant-numeric: tabular-nums;
}
.chat-table thead {
  background: #0F2818;
}
.chat-table th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #A7F3A7;
  border: none;
}
.chat-table td {
  padding: 8px 12px;
  color: #1E293B;
  border-bottom: 1px solid #E2E8F0;
  font-size: 12px;
}
.chat-table tbody tr:last-child td {
  border-bottom: none;
}
.chat-table tbody tr:hover td {
  background: rgba(75,155,43,0.06);
}

/* List items */
.chat-list-item {
  padding: 2px 0 2px 16px;
  position: relative;
}
.chat-list-item::before {
  content: '•';
  position: absolute;
  left: 4px;
  color: var(--green);
}

/* Bot bubble wider for tables */
.chat-msg.bot .chat-msg-text {
  max-width: 90%;
}

/* ===================== FULLSCREEN PAGE ===================== */
#p-chat .chat-fullscreen {
  max-width: 700px;
  margin: 0 auto;
  height: calc(100vh - 57px);
  display: flex;
  flex-direction: column;
}
#p-chat .chat-header { border-bottom: 1px solid var(--border); }
#p-chat .chat-messages { flex: 1; padding: 24px; gap: 14px; }
#p-chat .chat-msg-text { font-size: 14px; }
#p-chat .chat-input-bar { padding: 16px 24px; }
#p-chat .chat-input-bar input[type="text"] { padding: 12px 16px; font-size: 14px; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .chat-widget {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 70vh;
    border-radius: 20px 20px 0 0;
  }
  .chat-bubble-trigger {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px 10px 12px;
    gap: 10px;
  }
  .chat-bubble-trigger .ctb-icon { width: 34px; height: 34px; }
  .chat-bubble-trigger .ctb-title { font-size: 13px; }
  .chat-bubble-trigger .ctb-sub { font-size: 10px; }
@media (max-width: 420px) {
  .chat-bubble-trigger .ctb-text { display: none; }
  .chat-bubble-trigger { padding: 12px; }
  .chat-bubble-trigger .ctb-icon { width: 36px; height: 36px; background: transparent; }
}
}
@media (max-width: 1024px) and (min-width: 769px) {
  .chat-widget { width: 400px; height: 560px; }
}
@media (max-width: 768px) {
  .chat-table { font-size: 11px; }
  .chat-table th, .chat-table td { padding: 4px 6px; }
}

/* ── Offerte chat: tag tipo prezzo, durata pill, prezzo 2 righe, reco box ── */
.chat-msg .aef-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-left: 6px;
  vertical-align: middle;
  line-height: 1.4;
}
.chat-msg .aef-tag-fix { background: #DBEAFE; color: #1E40AF; }
.chat-msg .aef-tag-idx { background: #FEF3C7; color: #92400E; }
.chat-msg .aef-dur {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}
.chat-msg .aef-dur-12 { background: #DCFCE7; color: #166534; }
.chat-msg .aef-dur-24 { background: #DBEAFE; color: #1E40AF; }
.chat-msg .aef-dur-36 { background: #EDE9FE; color: #5B21B6; }
.chat-msg .aef-price-main {
  display: block;
  font-weight: 700;
  color: #0F172A;
}
.chat-msg .aef-price-sub {
  display: block;
  font-size: 10px;
  color: #64748B;
  margin-top: 2px;
  font-weight: 500;
}
.chat-msg .aef-reco-box {
  margin: 14px 0 8px;
  background: rgba(255,255,255,0.95);
  color: #0F172A;
  border-radius: 10px;
  padding: 14px 16px;
  border-left: 4px solid #FBBF24;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.chat-msg .aef-reco-box h3 {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #B45309;
  margin: 0 0 8px;
}
.chat-msg .aef-reco-row {
  padding: 6px 0;
  font-size: 13px;
  color: #0F172A;
}
.chat-msg .aef-reco-row + .aef-reco-row { border-top: 1px solid #F1F5F9; }
.chat-msg .aef-reco-label { font-weight: 700; color: #0F172A; }
.chat-msg .aef-reco-name { color: #065F46; font-weight: 600; }
