/* DfElettro AI Chat — styles isolated under .ai-chat-* */
#ai-chat-root {
  --ai-chat-primary: var(--primary, #2563eb);
  --ai-chat-primary-dark: var(--primary-dark, #1d4ed8);
  --ai-chat-bg: var(--surface, #ffffff);
  --ai-chat-bg-soft: var(--surface2, #f8fafc);
  --ai-chat-text: var(--text, #1e293b);
  --ai-chat-muted: var(--text2, #64748b);
  --ai-chat-border: var(--border, #e2e8f0);
  --ai-chat-shadow: 0 18px 55px rgba(15, 23, 42, .22);
  font-family: 'Source Sans 3', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.ai-chat-launcher {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 9990;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(145deg, var(--ai-chat-primary), var(--ai-chat-primary-dark));
  box-shadow: 0 8px 24px rgba(37, 99, 235, .34);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.ai-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 11px 30px rgba(37, 99, 235, .4); }
.ai-chat-launcher:active { transform: translateY(0) scale(.98); }
.ai-chat-launcher:focus-visible,
.ai-chat-panel button:focus-visible,
.ai-chat-panel textarea:focus-visible {
  outline: 3px solid rgba(59, 130, 246, .35);
  outline-offset: 3px;
}
.ai-chat-launcher i { font-size: 23px; }
.ai-chat-launcher-label { display: none; }

.ai-chat-panel {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 76px);
  z-index: 9991;
  display: flex;
  flex-direction: column;
  width: min(410px, calc(100vw - 32px));
  height: min(640px, calc(100dvh - 125px));
  min-height: 340px;
  overflow: hidden;
  color: var(--ai-chat-text);
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  border-radius: 18px;
  box-shadow: var(--ai-chat-shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px) scale(.985);
  transform-origin: bottom right;
  transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
}
.ai-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 0 0 auto;
  padding: 15px 15px 14px;
  color: #fff;
  background: linear-gradient(115deg, var(--ai-chat-primary-dark), var(--ai-chat-primary));
}
.ai-chat-header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 12px;
  background: rgba(255,255,255,.14);
  font-size: 18px;
}
.ai-chat-heading { min-width: 0; flex: 1; }
.ai-chat-title { margin: 0; color: #fff; font-size: 16px; font-weight: 700; line-height: 1.25; }
.ai-chat-subtitle { margin-top: 3px; color: rgba(255,255,255,.82); font-size: 12px; line-height: 1.3; }
.ai-chat-header-actions { display: flex; align-items: center; gap: 5px; }
.ai-chat-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #fff;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}
.ai-chat-icon-button:hover { border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.13); }
.ai-chat-icon-button i { font-size: 14px; }

.ai-chat-notice {
  flex: 0 0 auto;
  padding: 8px 13px;
  color: var(--ai-chat-muted);
  background: var(--ai-chat-bg-soft);
  border-bottom: 1px solid var(--ai-chat-border);
  font-size: 11px;
  line-height: 1.4;
}
.ai-chat-messages {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 16px 13px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--ai-chat-bg);
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.ai-chat-message-row { display: flex; width: 100%; }
.ai-chat-message-row.is-user { justify-content: flex-end; }
.ai-chat-message-row.is-assistant,
.ai-chat-message-row.is-error { justify-content: flex-start; }
.ai-chat-bubble {
  max-width: 88%;
  padding: 10px 12px;
  border: 1px solid var(--ai-chat-border);
  border-radius: 14px 14px 14px 5px;
  color: var(--ai-chat-text);
  background: var(--ai-chat-bg-soft);
  font-size: 13.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-chat-message-row.is-user .ai-chat-bubble {
  color: #fff;
  background: var(--ai-chat-primary);
  border-color: var(--ai-chat-primary);
  border-radius: 14px 14px 5px 14px;
}
.ai-chat-message-row.is-error .ai-chat-bubble {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}
.ai-chat-message-meta { margin-top: 5px; color: var(--ai-chat-muted); font-size: 10px; }
.ai-chat-message-row.is-user .ai-chat-message-meta { text-align: right; }
.ai-chat-welcome {
  align-self: flex-start;
  max-width: 95%;
  padding: 13px 14px;
  border: 1px solid var(--ai-chat-border);
  border-radius: 14px;
  background: var(--ai-chat-bg-soft);
  font-size: 13px;
  line-height: 1.5;
}
.ai-chat-welcome strong { display: block; margin-bottom: 4px; font-size: 14px; }
.ai-chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.ai-chat-suggestion {
  padding: 6px 9px;
  color: var(--ai-chat-primary-dark);
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
}
.ai-chat-suggestion:hover { background: var(--ai-chat-primary); color: #fff; border-color: var(--ai-chat-primary); }

.ai-chat-typing { display: inline-flex; align-items: center; gap: 4px; min-width: 54px; }
.ai-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai-chat-muted);
  animation: ai-chat-pulse 1s infinite ease-in-out;
}
.ai-chat-typing span:nth-child(2) { animation-delay: .12s; }
.ai-chat-typing span:nth-child(3) { animation-delay: .24s; }
@keyframes ai-chat-pulse { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.ai-chat-compose {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 12px max(12px, env(safe-area-inset-bottom));
  background: var(--ai-chat-bg);
  border-top: 1px solid var(--ai-chat-border);
}
.ai-chat-input-wrap { flex: 1 1 auto; min-width: 0; }
.ai-chat-input {
  display: block;
  width: 100%;
  min-height: 42px;
  max-height: 125px;
  padding: 11px 12px;
  resize: none;
  overflow-y: auto;
  color: var(--ai-chat-text);
  background: var(--ai-chat-bg-soft);
  border: 1px solid var(--ai-chat-border);
  border-radius: 12px;
  outline: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
}
.ai-chat-input:focus { border-color: var(--ai-chat-primary); box-shadow: 0 0 0 3px rgba(37,99,235,.09); }
.ai-chat-input:disabled { opacity: .7; cursor: wait; }
.ai-chat-input::placeholder { color: var(--ai-chat-muted); }
.ai-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  padding: 0;
  color: #fff;
  background: var(--ai-chat-primary);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.ai-chat-send:hover:not(:disabled) { background: var(--ai-chat-primary-dark); }
.ai-chat-send:active:not(:disabled) { transform: scale(.97); }
.ai-chat-send:disabled { opacity: .45; cursor: not-allowed; }
.ai-chat-footer {
  flex: 0 0 auto;
  padding: 0 13px 9px;
  margin-top: -3px;
  color: var(--ai-chat-muted);
  background: var(--ai-chat-bg);
  font-size: 10px;
  text-align: center;
}

@media (max-width: 520px) {
  .ai-chat-launcher {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
  }
  .ai-chat-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(82dvh, 720px);
    min-height: 320px;
    border-radius: 18px 18px 0 0;
    transform-origin: bottom center;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .ai-chat-panel.is-open { transform: translateY(0) scale(1); }
  .ai-chat-panel:not(.is-open) { transform: translateY(12px) scale(.99); }
  .ai-chat-messages { padding: 14px 12px; }
  .ai-chat-bubble { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-launcher, .ai-chat-panel, .ai-chat-send { transition: none; }
  .ai-chat-typing span { animation: none; opacity: .7; }
}
