/**
 * Energy Chat Widget — CSS Scoped Stylesheet
 * Ecosistema Portali Verticali Energy — ConsulentiWeb.com S.r.l.
 * Versione: 1.0.0
 */

:root {
  --ecw-primary: #00875a;
  --ecw-primary-dark: #006644;
  --ecw-primary-light: #e3fcef;
  --ecw-accent: #00b8d9;
  --ecw-text-main: #172b4d;
  --ecw-text-muted: #6b778c;
  --ecw-bg-surface: #ffffff;
  --ecw-bg-light: #f4f5f7;
  --ecw-border-color: #ebecf0;
  --ecw-shadow-floating: 0 12px 36px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
  --ecw-shadow-bubble: 0 4px 14px rgba(0, 0, 0, 0.12);
  --ecw-radius-lg: 18px;
  --ecw-radius-md: 12px;
  --ecw-radius-sm: 8px;
  --ecw-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ecw-zindex: 999999;
}

/* Base Wrapper Reset */
#energy-chat-widget-root {
  font-family: var(--ecw-font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ecw-text-main);
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--ecw-zindex);
}

#energy-chat-widget-root * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Floating Trigger Button */
.ecw-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ecw-primary), var(--ecw-primary-dark));
  color: #ffffff;
  box-shadow: var(--ecw-shadow-floating);
  cursor: pointer;
  border: none;
  outline: none;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
  user-select: none;
}

.ecw-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

.ecw-launcher:active {
  transform: scale(0.95);
}

.ecw-launcher-icon {
  width: 30px;
  height: 30px;
  fill: currentColor;
  transition: transform 0.3s ease, opacity 0.2s ease;
}

.ecw-launcher-close {
  display: none;
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.ecw-launcher.ecw-is-open .ecw-launcher-icon {
  display: none;
}

.ecw-launcher.ecw-is-open .ecw-launcher-close {
  display: block;
}

/* Pulsing Online Ping */
.ecw-pulse-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--ecw-primary);
  animation: ecwPulse 2.4s infinite cubic-bezier(0.25, 0.8, 0.25, 1);
  pointer-events: none;
  opacity: 0.6;
}

@keyframes ecwPulse {
  0% { transform: scale(1); opacity: 0.8; }
  70% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* Teaser Bubble (Callout) */
.ecw-teaser {
  position: absolute;
  right: 76px;
  bottom: 10px;
  background: #ffffff;
  color: var(--ecw-text-main);
  padding: 10px 14px;
  border-radius: var(--ecw-radius-md);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  white-space: nowrap;
  font-weight: 500;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--ecw-border-color);
  animation: ecwFadeSlide 0.4s ease forwards;
  cursor: pointer;
  max-width: 280px;
}

.ecw-teaser::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 18px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 1px solid var(--ecw-border-color);
  border-top: 1px solid var(--ecw-border-color);
  transform: rotate(45deg);
}

.ecw-teaser-badge {
  background: var(--ecw-primary-light);
  color: var(--ecw-primary-dark);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ecw-teaser-close {
  color: var(--ecw-text-muted);
  font-size: 16px;
  line-height: 1;
  margin-left: 4px;
  cursor: pointer;
}

.ecw-teaser-close:hover {
  color: #ff5630;
}

@keyframes ecwFadeSlide {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Chat Window Container */
.ecw-window {
  display: none;
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 390px;
  height: 620px;
  max-height: calc(100vh - 120px);
  background: var(--ecw-bg-surface);
  border-radius: var(--ecw-radius-lg);
  box-shadow: var(--ecw-shadow-floating);
  border: 1px solid var(--ecw-border-color);
  flex-direction: column;
  overflow: hidden;
  animation: ecwWindowOpen 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transform-origin: bottom right;
}

.ecw-window.ecw-active {
  display: flex;
}

@keyframes ecwWindowOpen {
  0% { opacity: 0; transform: scale(0.92) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Header */
.ecw-header {
  background: linear-gradient(135deg, var(--ecw-primary), var(--ecw-primary-dark));
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: var(--ecw-radius-lg);
  border-top-right-radius: var(--ecw-radius-lg);
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ecw-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ecw-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.ecw-avatar-icon {
  width: 22px;
  height: 22px;
  fill: #ffffff;
}

.ecw-status-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #36b37e;
  border: 2px solid #ffffff;
}

.ecw-header-text h3 {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: #ffffff;
}

.ecw-header-text p {
  font-size: 11px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.9);
}

.ecw-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ecw-btn-icon {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.ecw-btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.ecw-btn-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Context Banner (Portal identity) */
.ecw-context-banner {
  background: var(--ecw-bg-light);
  border-bottom: 1px solid var(--ecw-border-color);
  padding: 6px 14px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ecw-text-muted);
}

.ecw-portal-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--ecw-primary-dark);
}

.ecw-portal-tag svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.ecw-incentive-pill {
  background: #e3fcef;
  color: #006644;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 10px;
}

/* Messages Area */
.ecw-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fafbfc;
  scroll-behavior: smooth;
}

.ecw-messages::-webkit-scrollbar {
  width: 5px;
}

.ecw-messages::-webkit-scrollbar-thumb {
  background: #dcdfe4;
  border-radius: 10px;
}

/* Message Bubble */
.ecw-msg-row {
  display: flex;
  gap: 8px;
  max-width: 88%;
}

.ecw-msg-row.ecw-msg-assistant {
  align-self: flex-start;
}

.ecw-msg-row.ecw-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ecw-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ecw-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
}

.ecw-msg-avatar svg {
  width: 14px;
  height: 14px;
  fill: #ffffff;
}

.ecw-msg-bubble {
  padding: 12px 14px;
  border-radius: var(--ecw-radius-md);
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  word-break: break-word;
}

.ecw-msg-assistant .ecw-msg-bubble {
  background: #ffffff;
  color: var(--ecw-text-main);
  border: 1px solid var(--ecw-border-color);
  border-top-left-radius: 4px;
}

.ecw-msg-user .ecw-msg-bubble {
  background: var(--ecw-primary);
  color: #ffffff;
  border-top-right-radius: 4px;
}

.ecw-msg-time {
  font-size: 10px;
  color: var(--ecw-text-muted);
  margin-top: 4px;
  text-align: right;
}

.ecw-msg-user .ecw-msg-time {
  color: rgba(255, 255, 255, 0.8);
}

/* Markdown styling inside assistant bubble */
.ecw-msg-bubble p {
  margin-bottom: 8px;
}
.ecw-msg-bubble p:last-child {
  margin-bottom: 0;
}
.ecw-msg-bubble ul, .ecw-msg-bubble ol {
  padding-left: 18px;
  margin: 6px 0;
}
.ecw-msg-bubble li {
  margin-bottom: 4px;
}
.ecw-msg-bubble strong {
  font-weight: 700;
  color: inherit;
}
.ecw-msg-bubble a {
  color: var(--ecw-primary);
  text-decoration: underline;
}

/* Typing Indicator */
.ecw-typing {
  display: none;
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid var(--ecw-border-color);
  padding: 10px 14px;
  border-radius: var(--ecw-radius-md);
  border-top-left-radius: 4px;
  gap: 5px;
  align-items: center;
}

.ecw-typing.ecw-active {
  display: inline-flex;
}

.ecw-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a5b2c6;
  animation: ecwTypingBounce 1.2s infinite ease-in-out;
}

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

@keyframes ecwTypingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Quick Suggestion Chips */
.ecw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ecw-chip {
  background: #ffffff;
  color: var(--ecw-primary-dark);
  border: 1px solid var(--ecw-primary);
  padding: 6px 11px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ecw-chip:hover {
  background: var(--ecw-primary);
  color: #ffffff;
  transform: translateY(-1px);
}

/* In-Chat Lead Capture Form Card */
.ecw-lead-card {
  background: #ffffff;
  border: 1.5px solid var(--ecw-primary);
  border-radius: var(--ecw-radius-md);
  padding: 14px;
  margin-top: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  animation: ecwFadeSlide 0.3s ease;
}

.ecw-lead-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ecw-border-color);
}

.ecw-lead-badge {
  background: var(--ecw-primary-light);
  color: var(--ecw-primary-dark);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 6px;
  text-transform: uppercase;
}

.ecw-lead-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ecw-text-main);
}

.ecw-lead-desc {
  font-size: 11.5px;
  color: var(--ecw-text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.ecw-form-group {
  margin-bottom: 10px;
}

.ecw-form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--ecw-text-main);
  margin-bottom: 4px;
}

.ecw-form-label span.ecw-req {
  color: #de350b;
}

.ecw-input, .ecw-select, .ecw-textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--ecw-radius-sm);
  border: 1px solid #c1c7d0;
  font-size: 13px;
  font-family: inherit;
  color: var(--ecw-text-main);
  background: #fafbfc;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ecw-input:focus, .ecw-select:focus, .ecw-textarea:focus {
  outline: none;
  border-color: var(--ecw-primary);
  background: #ffffff;
  box-shadow: 0 0 0 2px var(--ecw-primary-light);
}

.ecw-form-row {
  display: flex;
  gap: 8px;
}

.ecw-form-row .ecw-form-group {
  flex: 1;
}

.ecw-privacy-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 10px 0 12px 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--ecw-text-muted);
}

.ecw-privacy-check input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--ecw-primary);
  cursor: pointer;
}

.ecw-privacy-check a {
  color: var(--ecw-primary);
  text-decoration: underline;
}

.ecw-btn-submit {
  width: 100%;
  padding: 10px;
  border-radius: var(--ecw-radius-sm);
  background: var(--ecw-primary);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s, transform 0.1s;
}

.ecw-btn-submit:hover {
  background: var(--ecw-primary-dark);
}

.ecw-btn-submit:active {
  transform: scale(0.99);
}

.ecw-btn-submit.ecw-loading {
  opacity: 0.8;
  cursor: not-allowed;
}

/* Success Card */
.ecw-success-card {
  background: #e3fcef;
  border: 1px solid #abf5d1;
  color: #006644;
  padding: 14px;
  border-radius: var(--ecw-radius-md);
  text-align: center;
  margin-top: 10px;
  animation: ecwFadeSlide 0.3s ease;
}

.ecw-success-icon {
  width: 36px;
  height: 36px;
  background: #36b37e;
  border-radius: 50%;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.ecw-success-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.ecw-success-desc {
  font-size: 12px;
  line-height: 1.4;
  color: #005230;
}

/* Input Area */
.ecw-input-area {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid var(--ecw-border-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ecw-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fafbfc;
  border: 1px solid #dfe1e6;
  border-radius: 20px;
  padding: 6px 12px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.ecw-input-box:focus-within {
  border-color: var(--ecw-primary);
  background: #ffffff;
  box-shadow: 0 0 0 2px var(--ecw-primary-light);
}

.ecw-textarea-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ecw-text-main);
  outline: none;
  max-height: 90px;
  min-height: 22px;
  line-height: 20px;
  padding: 2px 0;
}

.ecw-textarea-input::placeholder {
  color: #97a0af;
}

.ecw-btn-send {
  background: var(--ecw-primary);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.ecw-btn-send:hover {
  background: var(--ecw-primary-dark);
}

.ecw-btn-send:disabled {
  background: #ebecf0;
  color: #a5b2c6;
  cursor: not-allowed;
}

.ecw-btn-send svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  transform: translateX(1px);
}

/* Micro Legal Footer */
.ecw-footer-legal {
  font-size: 10px;
  color: var(--ecw-text-muted);
  text-align: center;
  padding-top: 2px;
  letter-spacing: -0.1px;
}

.ecw-footer-legal a {
  color: inherit;
  text-decoration: none;
}

.ecw-footer-legal a:hover {
  text-decoration: underline;
}

/* Responsive Mobile Rules */
@media (max-width: 480px) {
  #energy-chat-widget-root {
    bottom: 16px;
    right: 16px;
  }

  .ecw-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    bottom: 74px;
    right: 0;
  }

  .ecw-teaser {
    display: none; /* Hide teaser on small screens to avoid clutter */
  }
}
