/* ============================================
   POLARIS AI CHAT — Widget Styles
   Prefisso .pc- per isolamento
   ============================================ */

/* --- FAB Button --- */
.pc-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1730bc 0%, #2a4bff 100%);
  border: none;
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(23, 48, 188, 0.4), 0 0 0 0 rgba(23, 48, 188, 0.3);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
  animation: pc-pulse 2.5s ease-in-out infinite;
}

.pc-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(23, 48, 188, 0.5);
}

.pc-fab.pc-fab--open {
  animation: none;
  transform: rotate(0deg);
}

.pc-fab svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s ease, opacity 0.2s ease;
}

.pc-fab .pc-fab-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.pc-fab.pc-fab--open .pc-fab-chat { opacity: 0; transform: rotate(90deg) scale(0.5); }
.pc-fab.pc-fab--open .pc-fab-close { opacity: 1; transform: rotate(0deg) scale(1); }

@keyframes pc-pulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(23, 48, 188, 0.4), 0 0 0 0 rgba(23, 48, 188, 0.3); }
  50% { box-shadow: 0 4px 24px rgba(23, 48, 188, 0.4), 0 0 0 12px rgba(23, 48, 188, 0); }
}

/* --- Chat Panel --- */
.pc-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  max-height: min(600px, calc(100vh - 120px));
  border-radius: 16px;
  background: rgba(6, 12, 28, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(147, 197, 253, 0.15);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), 0 0 1px rgba(147, 197, 253, 0.2);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease;
}

.pc-panel.pc-panel--open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* --- Panel Header --- */
.pc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 12px 16px;
  border-bottom: 1px solid rgba(147, 197, 253, 0.1);
  flex-shrink: 0;
}

.pc-header-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  flex-shrink: 0;
}

.pc-header-title {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.pc-header-subtitle {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  margin-left: auto;
}

.pc-header-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.pc-header-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* --- Messages Area --- */
.pc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.pc-messages::-webkit-scrollbar { width: 4px; }
.pc-messages::-webkit-scrollbar-track { background: transparent; }
.pc-messages::-webkit-scrollbar-thumb { background: rgba(147, 197, 253, 0.2); border-radius: 2px; }

/* --- AI Message Row (avatar + bubble) --- */
.pc-row-ai {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  max-width: 90%;
  animation: pc-fadeIn 0.3s ease;
}

.pc-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1730bc 0%, #2a4bff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pc-avatar span {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

/* --- Message Bubbles --- */
.pc-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
  color: #fff;
  word-wrap: break-word;
  animation: pc-fadeIn 0.3s ease;
}

.pc-row-ai .pc-bubble {
  animation: none;
  max-width: none;
  flex: 1;
  min-width: 0;
}

.pc-bubble-ai {
  align-self: flex-start;
  background: rgba(147, 197, 253, 0.08);
  border: 1px solid rgba(147, 197, 253, 0.1);
  border-bottom-left-radius: 4px;
}

.pc-bubble-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1730bc 0%, #2a4bff 100%);
  border-bottom-right-radius: 4px;
}

.pc-bubble p { margin: 0 0 8px; }
.pc-bubble p:last-child { margin-bottom: 0; }
.pc-bubble strong { color: #93c5fd; font-weight: 600; }
.pc-bubble em { font-style: italic; color: rgba(255, 255, 255, 0.85); }
.pc-bubble ul, .pc-bubble ol { margin: 4px 0 8px 16px; }
.pc-bubble li { margin-bottom: 2px; }
.pc-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

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

/* --- Streaming Cursor --- */
.pc-streaming::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #93c5fd;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: pc-blink 0.8s step-end infinite;
}

@keyframes pc-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* --- Typing Indicator --- */
.pc-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
}

.pc-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(147, 197, 253, 0.5);
  animation: pc-typingBounce 1.4s ease-in-out infinite;
}

.pc-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.pc-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pc-typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Mode Selector --- */
.pc-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.pc-mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border-radius: 10px;
  background: rgba(147, 197, 253, 0.06);
  border: 1px solid rgba(147, 197, 253, 0.12);
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: 'Inter', sans-serif;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

.pc-mode-btn:hover {
  background: rgba(23, 48, 188, 0.2);
  border-color: rgba(147, 197, 253, 0.3);
  transform: translateY(-2px);
}

.pc-mode-icon {
  font-size: 22px;
  line-height: 1;
}

.pc-mode-label {
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
}

.pc-mode-desc {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  line-height: 1.3;
}

/* --- Rich Content Blocks --- */
.pc-rich-card {
  margin: 8px 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(147, 197, 253, 0.06);
  border: 1px solid rgba(147, 197, 253, 0.15);
  border-left: 3px solid #93c5fd;
}

.pc-rich-card-title {
  font-size: 13px;
  font-weight: 700;
  color: #93c5fd;
  margin-bottom: 6px;
}

.pc-rich-metric {
  margin: 8px 0;
  padding: 14px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(23, 48, 188, 0.15) 0%, rgba(249, 115, 22, 0.1) 100%);
  border: 1px solid rgba(249, 115, 22, 0.2);
  text-align: center;
}

.pc-rich-metric-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 700;
  color: #f97316;
  line-height: 1.2;
}

.pc-rich-metric-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pc-rich-demo {
  margin: 8px 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(147, 197, 253, 0.1);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.85);
  white-space: pre-wrap;
}

.pc-rich-demo::before {
  content: 'DEMO';
  display: inline-block;
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  font-weight: 700;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

/* --- Product Card (with image) --- */
.pc-rich-product {
  margin: 8px 0;
  border-radius: 10px;
  background: rgba(147, 197, 253, 0.06);
  border: 1px solid rgba(147, 197, 253, 0.15);
  overflow: hidden;
}

.pc-rich-product-img {
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
}

.pc-rich-product-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 10px 10px 0 0;
}

.pc-rich-product-name {
  padding: 10px 12px 2px;
  font-size: 13px;
  font-weight: 700;
  color: #93c5fd;
}

.pc-rich-product-desc {
  padding: 0 12px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.7);
}

/* --- Showcase / Simulation Block --- */
.pc-rich-showcase {
  margin: 8px 0;
  padding: 14px;
  border-radius: 10px;
  background: rgba(249, 115, 22, 0.06);
  border: 1px solid rgba(249, 115, 22, 0.2);
  border-left: 3px solid #f97316;
}

.pc-rich-showcase-title {
  font-size: 13px;
  font-weight: 700;
  color: #f97316;
  margin-bottom: 8px;
}

.pc-rich-showcase-title::before {
  content: 'LIVE';
  display: inline-block;
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  font-weight: 700;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 8px;
  letter-spacing: 1px;
  vertical-align: middle;
}

.pc-rich-showcase-body {
  font-size: 12.5px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.85);
}

.pc-rich-showcase-body p {
  margin: 0 0 4px;
}

.pc-rich-showcase-body p:last-child {
  margin-bottom: 0;
}

.pc-rich-cta {
  display: inline-block;
  margin: 8px 0;
  padding: 10px 20px;
  border-radius: 100px;
  background: linear-gradient(135deg, #1730bc 0%, #2a4bff 100%);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.25s ease;
  border: none;
}

.pc-rich-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(23, 48, 188, 0.4);
}

/* --- Lead Mini-Bar --- */
.pc-lead-bar {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(23, 48, 188, 0.12) 0%, rgba(249, 115, 22, 0.08) 100%);
  border: 1px solid rgba(249, 115, 22, 0.25);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  animation: pc-fadeIn 0.3s ease;
}

.pc-lead-bar-text {
  flex: 1;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  min-width: 120px;
}

.pc-lead-bar-cta {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 100px;
  background: #f97316;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.pc-lead-bar-cta:hover {
  background: #ea580c;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.pc-lead-bar-close {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.2s ease;
  padding: 0;
  line-height: 1;
}

.pc-lead-bar-close:hover { color: #fff; }

.pc-lead-bar-email {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: #93c5fd;
  text-decoration: none;
}

.pc-lead-bar-email:hover { text-decoration: underline; }

/* --- Lead Form (expanded from mini-bar) --- */
.pc-lead-bar--expanded {
  flex-direction: column;
  align-items: stretch;
}

.pc-lead-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pc-lead-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(147, 197, 253, 0.15);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

.pc-lead-input::placeholder { color: rgba(255, 255, 255, 0.35); }
.pc-lead-input:focus { border-color: rgba(147, 197, 253, 0.4); }

.pc-lead-submit {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: #f97316;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.25s ease;
}

.pc-lead-submit:hover { background: #ea580c; box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3); }
.pc-lead-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.pc-lead-alt {
  display: block;
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  margin-top: 2px;
}

.pc-lead-alt:hover { color: #93c5fd; text-decoration: underline; }

.pc-lead-thanks {
  text-align: center;
  font-size: 13px;
  color: #22c55e;
  padding: 8px 0;
}

/* --- Input Bar --- */
.pc-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgba(147, 197, 253, 0.1);
  flex-shrink: 0;
}

.pc-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(147, 197, 253, 0.12);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.2s ease;
}

.pc-input::placeholder { color: rgba(255, 255, 255, 0.35); }
.pc-input:focus { border-color: rgba(147, 197, 253, 0.35); }

.pc-send {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1730bc 0%, #2a4bff 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.pc-send:hover { transform: scale(1.05); }
.pc-send:disabled { opacity: 0.4; cursor: not-allowed; }

.pc-send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Fullpage Mode (ai-experience.html) --- */
.pc-fullpage .pc-panel {
  position: relative;
  bottom: auto;
  right: auto;
  width: 100%;
  max-width: 720px;
  max-height: 70vh;
  margin: 0 auto;
  transform: none;
  opacity: 1;
  pointer-events: auto;
  border-radius: 16px;
}

.pc-fullpage .pc-fab { display: none; }

/* --- Error Message --- */
.pc-error {
  align-self: center;
  font-size: 12px;
  color: #f97316;
  background: rgba(249, 115, 22, 0.1);
  padding: 8px 14px;
  border-radius: 8px;
  text-align: center;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
  .pc-fab {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }

  .pc-fab svg { width: 24px; height: 24px; }

  /* Hide FAB when chat is open on mobile */
  .pc-fab.pc-fab--open { display: none; }

  .pc-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
    opacity: 1;
  }

  .pc-panel.pc-panel--open {
    transform: translateY(0);
  }

  .pc-messages {
    padding: 12px;
    flex: 1;
    min-height: 0;
  }

  .pc-input-bar {
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }

  .pc-input {
    font-size: 16px; /* prevents iOS auto-zoom on focus */
  }

  .pc-modes { gap: 6px; }
  .pc-mode-btn { padding: 10px 6px; }

  .pc-avatar { width: 24px; height: 24px; min-width: 24px; }
  .pc-avatar span { font-size: 11px; }
  .pc-row-ai { gap: 6px; }

  .pc-rich-product-img { aspect-ratio: 16 / 9; }
  .pc-rich-product-name { padding: 8px 10px 2px; }
  .pc-rich-product-desc { padding: 0 10px 8px; }
  .pc-rich-showcase { padding: 10px; }

  .pc-fullpage .pc-panel {
    max-height: 60vh;
    border-radius: 16px;
    height: auto;
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
  }
}

/* --- Reveal Safety Net: show content if JS reveal fails --- */
.reveal:not(.is-visible) {
  animation: pc-reveal-safety 0s 1.5s forwards;
}

@keyframes pc-reveal-safety {
  to { opacity: 1; transform: translateY(0); }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  .pc-fab { animation: none; }
  .pc-typing-dot { animation: none; opacity: 0.5; }
  .pc-bubble { animation: none; }
  .pc-row-ai { animation: none; }
  .pc-streaming::after { animation: none; opacity: 1; }
  .pc-panel { transition: opacity 0.15s ease; transform: none; }
  .pc-panel:not(.pc-panel--open) { opacity: 0; pointer-events: none; }
  .pc-mode-btn:hover { transform: none; }
}
