/* ================================================================
   Chiaravalli × Tecnica Industriale — AI Chat Widget
   ENTERPRISE PREMIUM EDITION
   Palette: #003057 deep navy · #E8002D accent red · #00D4AA AI teal
   ================================================================ */

/* ── Variables ────────────────────────────────────────────────── */
.cv-chat-container {
  --cv-primary: #003057;
  --cv-primary-hover: #004a87;
  --cv-dark: #001a33;
  --cv-dark-light: #0a2540;
  --cv-bg: #F7F8FA;
  --cv-bg-alt: #EEF0F4;
  --cv-text: #1A1A2E;
  --cv-text-light: #6B7280;
  --cv-white: #FFFFFF;
  --cv-accent: #E8002D;
  --cv-ai: #00D4AA;
  --cv-ai-dark: #00B894;
  --cv-ai-glow: rgba(0, 212, 170, 0.35);
  --cv-shadow: 0 12px 48px rgba(0, 30, 60, 0.18), 0 2px 8px rgba(0,0,0,0.06);
  --cv-shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.08);
  --cv-radius: 16px;
  --cv-radius-sm: 10px;
  --cv-font-title: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --cv-font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --cv-z: 99999;
}

@media (prefers-color-scheme: dark) {
  .cv-chat-container {
    --cv-bg: #111827;
    --cv-bg-alt: #1F2937;
    --cv-text: #F3F4F6;
    --cv-text-light: #9CA3AF;
    --cv-white: #1F2937;
    --cv-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  }
}

/* ── Reset ────────────────────────────────────────────────────── */
.cv-chat-container,
.cv-chat-container * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.cv-chat-container {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: var(--cv-z);
  font-family: var(--cv-font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--cv-text);
}

/* ══════════════════════════════════════════════════════════════════
   LAUNCHER — AI Orb with pulse
   ══════════════════════════════════════════════════════════════════ */
.cv-chat-launcher {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--cv-primary) 0%, #001a33 60%, var(--cv-ai-dark) 100%);
  border: 2px solid rgba(0, 212, 170, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 48, 87, 0.35), 0 0 20px var(--cv-ai-glow);
  transition: transform 0.25s cubic-bezier(.4,0,.2,1), box-shadow 0.25s ease;
  position: relative;
  animation: cv-orbPulse 3s ease-in-out infinite;
}

.cv-chat-launcher:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 30px rgba(0, 48, 87, 0.45), 0 0 30px var(--cv-ai-glow);
}

.cv-chat-launcher svg {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 0 6px rgba(0, 212, 170, 0.5));
}

@keyframes cv-orbPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(0, 48, 87, 0.35), 0 0 16px var(--cv-ai-glow); }
  50% { box-shadow: 0 4px 20px rgba(0, 48, 87, 0.35), 0 0 32px var(--cv-ai-glow); }
}

/* AI badge on launcher */
.cv-chat-launcher-ai {
  position: absolute;
  bottom: -4px;
  right: -6px;
  background: linear-gradient(135deg, var(--cv-ai) 0%, var(--cv-ai-dark) 100%);
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 212, 170, 0.4);
  z-index: 2;
  pointer-events: none;
  text-transform: uppercase;
}

/* Unread badge */
.cv-chat-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: var(--cv-accent);
  border-radius: 10px;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  animation: cv-badgeBounce 0.4s cubic-bezier(.4,0,.2,1);
}

@keyframes cv-badgeBounce {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ══════════════════════════════════════════════════════════════════
   CHAT WINDOW
   ══════════════════════════════════════════════════════════════════ */
.cv-chat-window {
  width: 400px;
  height: 560px;
  background: var(--cv-bg);
  border-radius: var(--cv-radius);
  box-shadow: var(--cv-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  bottom: 78px;
  right: 0;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(.4,0,.2,1), transform 0.3s cubic-bezier(.4,0,.2,1);
  border: 1px solid rgba(0, 48, 87, 0.08);
}

.cv-chat-window.cv-chat-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header — gradient with AI glow ──────────────────────────── */
.cv-chat-header {
  background: linear-gradient(135deg, var(--cv-dark) 0%, var(--cv-primary) 50%, #00385f 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* Subtle animated AI accent line */
.cv-chat-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--cv-accent) 0%, var(--cv-ai) 50%, var(--cv-accent) 100%);
  background-size: 200% 100%;
  animation: cv-headerShimmer 4s linear infinite;
}

@keyframes cv-headerShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Header layout */
.cv-chat-header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cv-chat-header-title-main {
  font-family: var(--cv-font-title);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* AI indicator dot in title */
.cv-chat-header-title-main::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--cv-ai);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--cv-ai-glow);
  animation: cv-aiDot 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes cv-aiDot {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--cv-ai-glow); }
  50% { opacity: 0.6; box-shadow: 0 0 12px var(--cv-ai-glow); }
}

.cv-chat-header-title-sub {
  font-size: 11px;
  opacity: 0.65;
  letter-spacing: 0.02em;
  padding-left: 16px;
}

.cv-chat-header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Language selector */
.cv-chat-lang-selector {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 2px;
}

.cv-chat-lang-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  border: none;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--cv-font-body);
  padding: 3px 6px;
  border-radius: 4px;
  transition: all 0.15s;
  letter-spacing: 0.03em;
}

.cv-chat-lang-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
}

.cv-chat-lang-btn-active {
  background: rgba(0, 212, 170, 0.25);
  color: var(--cv-ai);
}

/* Close button */
.cv-chat-close-btn {
  background: rgba(255, 255, 255, 0.06);
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.6);
  font-size: 18px;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
}

.cv-chat-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

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

.cv-chat-messages::-webkit-scrollbar { width: 4px; }
.cv-chat-messages::-webkit-scrollbar-track { background: transparent; }
.cv-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 48, 87, 0.15);
  border-radius: 10px;
}

/* ── Chat bubbles ─────────────────────────────────────────────── */
.cv-chat-message {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: cv-msgIn 0.3s cubic-bezier(.4,0,.2,1) forwards;
}

@keyframes cv-msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cv-chat-message strong { font-weight: 700; }
.cv-chat-message em { font-style: italic; }
.cv-chat-message a {
  color: var(--cv-ai-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cv-chat-message-user {
  background: linear-gradient(135deg, var(--cv-primary) 0%, var(--cv-primary-hover) 100%);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 48, 87, 0.2);
}

.cv-chat-message-assistant {
  background: var(--cv-white);
  color: var(--cv-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: var(--cv-shadow-sm);
  border: 1px solid rgba(0, 48, 87, 0.06);
  position: relative;
}

/* Small AI indicator for assistant messages */
.cv-chat-message-assistant::before {
  content: 'AI';
  position: absolute;
  top: -8px;
  left: 10px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--cv-ai-dark);
  background: var(--cv-bg);
  padding: 0 4px;
  border-radius: 3px;
}

/* Product codes */
.cv-chat-product-code {
  background: rgba(0, 48, 87, 0.08);
  color: var(--cv-primary);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  font-weight: 600;
}

.cv-chat-belt-code {
  background: rgba(232, 0, 45, 0.08);
  color: var(--cv-accent);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  font-weight: 600;
}

/* ── Typing indicator ─────────────────────────────────────────── */
.cv-chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  align-self: flex-start;
}

.cv-chat-typing-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cv-ai-dark);
  text-transform: uppercase;
}

.cv-chat-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.cv-chat-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--cv-ai);
  border-radius: 50%;
  animation: cv-typingDot 1.4s infinite ease-in-out;
}
.cv-chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.cv-chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cv-typingDot {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* ── Suggested actions ────────────────────────────────────────── */
.cv-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 8px;
}

.cv-chat-suggestion-btn {
  background: var(--cv-white);
  color: var(--cv-primary);
  border: 1.5px solid rgba(0, 48, 87, 0.15);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--cv-font-body);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(.4,0,.2,1);
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.cv-chat-suggestion-btn:hover {
  background: var(--cv-primary);
  color: #fff;
  border-color: var(--cv-primary);
  box-shadow: 0 4px 12px rgba(0, 48, 87, 0.25);
  transform: translateY(-1px);
}

/* ── Lead form ────────────────────────────────────────────────── */
.cv-chat-lead-form {
  padding: 0 0 8px;
}

.cv-lead-form-inner {
  background: var(--cv-white);
  border: 1px solid rgba(0, 48, 87, 0.1);
  border-radius: var(--cv-radius-sm);
  padding: 16px;
  box-shadow: var(--cv-shadow-sm);
}

.cv-lead-title {
  font-family: var(--cv-font-title);
  font-size: 14px;
  font-weight: 700;
  color: var(--cv-dark);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cv-lead-title::before {
  content: '';
  width: 3px;
  height: 16px;
  background: linear-gradient(180deg, var(--cv-accent) 0%, var(--cv-ai) 100%);
  border-radius: 2px;
}

.cv-lead-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.cv-lead-input,
.cv-lead-select,
.cv-lead-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(0, 48, 87, 0.12);
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--cv-font-body);
  color: var(--cv-text);
  background: var(--cv-bg);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cv-lead-input:focus,
.cv-lead-select:focus,
.cv-lead-textarea:focus {
  border-color: var(--cv-ai-dark);
  box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.12);
}

.cv-lead-submit {
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, var(--cv-primary) 0%, var(--cv-primary-hover) 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--cv-font-body);
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}

.cv-lead-submit:hover {
  box-shadow: 0 4px 16px rgba(0, 48, 87, 0.3);
  transform: translateY(-1px);
}

.cv-lead-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.cv-lead-status {
  font-size: 12px;
  margin-top: 8px;
  text-align: center;
  min-height: 16px;
}

.cv-lead-consent-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--cv-text-light);
}

.cv-lead-consent-wrap input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--cv-ai-dark);
}

/* ── Input area ───────────────────────────────────────────────── */
.cv-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid rgba(0, 48, 87, 0.06);
  background: var(--cv-white);
}

.cv-chat-input {
  flex: 1;
  resize: none;
  border: 1.5px solid rgba(0, 48, 87, 0.1);
  border-radius: var(--cv-radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: var(--cv-font-body);
  color: var(--cv-text);
  background: var(--cv-bg);
  outline: none;
  min-height: 40px;
  max-height: 110px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cv-chat-input:focus {
  border-color: var(--cv-ai-dark);
  box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.1);
}

.cv-chat-input::placeholder {
  color: var(--cv-text-light);
}

.cv-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cv-primary) 0%, var(--cv-ai-dark) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(.4,0,.2,1);
  color: #fff;
  font-size: 16px;
  box-shadow: 0 2px 8px rgba(0, 48, 87, 0.25);
}

.cv-chat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(0, 48, 87, 0.35);
}

.cv-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Footer — AI powered branding ─────────────────────────────── */
.cv-chat-footer {
  text-align: center;
  padding: 8px 12px;
  font-size: 10px;
  color: var(--cv-text-light);
  background: var(--cv-white);
  letter-spacing: 0.04em;
  border-top: 1px solid rgba(0, 48, 87, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.cv-chat-footer::before {
  content: '';
  width: 5px;
  height: 5px;
  background: var(--cv-ai);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--cv-ai-glow);
  animation: cv-aiDot 2s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════════════════
   MOBILE — Fullscreen under 480px
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .cv-chat-container {
    bottom: 14px;
    right: 14px;
  }

  .cv-chat-launcher {
    width: 56px;
    height: 56px;
  }

  .cv-chat-launcher svg {
    width: 24px;
    height: 24px;
  }

  .cv-chat-window.cv-chat-open {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    z-index: calc(var(--cv-z) + 1);
  }
}

/* ══════════════════════════════════════════════════════════════════
   PRINT — hide
   ══════════════════════════════════════════════════════════════════ */
@media print {
  .cv-chat-container { display: none !important; }
}
