/* Widget de chat flotante (cuestionario de reformas): una pregunta por tarjeta */
.cw-root {
  position: fixed;
  right: 20px;
  bottom: 100px;
  bottom: calc(100px + env(safe-area-inset-bottom));
  /* z-index 10001: por encima del banner de cookies (9999) y del message-container (10000),
     pero por debajo del overlay modal de preferencias de cookies (.cc-overlay = 10000)
     cuando esté activo, para no bloquear el consentimiento. */
  z-index: 10001;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.cw-launcher {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #0f2f6b 0%, #0a2050 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(10, 32, 80, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cw-launcher::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.28) 0%, rgba(255, 255, 255, 0) 45%);
  pointer-events: none;
}

.cw-launcher:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 12px 28px rgba(10, 32, 80, 0.45);
}

.cw-launcher:active {
  transform: translateY(-1px) scale(0.98);
}

.cw-root.has-badge:not(.is-open) .cw-launcher {
  animation: cwLauncherBreathe 2.6s ease-in-out infinite;
}

@keyframes cwLauncherBreathe {
  0%, 100% { box-shadow: 0 8px 20px rgba(10, 32, 80, 0.4); }
  50% { box-shadow: 0 10px 26px rgba(10, 32, 80, 0.4), 0 0 0 7px rgba(232, 144, 26, 0.12); }
}

.cw-launcher-icon-chat {
  border-radius: 50%;
  object-fit: cover;
  object-position: center 20%;
}

.cw-launcher-icon-close {
  display: none;
}

.cw-root.is-open .cw-launcher-icon-chat {
  display: none;
}

.cw-root.is-open .cw-launcher-icon-close {
  display: block;
}

.cw-launcher-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #10b981;
  border: 2.5px solid #fff;
  display: none;
}

.cw-root.has-badge:not(.is-open) .cw-launcher-badge {
  display: block;
  animation: cwPulse 1.8s ease-in-out infinite;
}

@keyframes cwPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

.cw-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: 340px;
  max-width: calc(100vw - 32px);
  /* Altura por contenido: cada tarjeta decide cuánto ocupa el panel. Nada de max-height
     dependiente del viewport (vh/dvh): al hacer zoom, el viewport CSS se reduce pero el
     contenido crece en px CSS; si limitáramos con vh, el panel se estrecharía mientras
     el contenido crece → scroll interno. Dejando height:auto y sin max-height, panel y
     contenido escalan de forma proporcional al zoom y nunca aparece scroll dentro. */
  height: auto;
  min-height: 0;
  max-height: none;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.3, 0.64, 1);
}

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

.cw-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 22px;
  overflow: hidden;
}

.cw-header {
  background: linear-gradient(135deg, #0f2f6b 0%, #0a2050 100%);
  color: #fff;
  padding: 11px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.cw-header-info {
  display: flex;
  align-items: center;
  gap: 11px;
}

.cw-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(10, 32, 80, 0.3), 0 0 0 2px rgba(255, 255, 255, 0.18);
}

.cw-header-avatar img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.cw-header-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.cw-header-subtitle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: #d1d5db;
  margin-top: 1px;
}

.cw-header-subtitle::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
  flex-shrink: 0;
  animation: cwDotPulse 2.2s ease-in-out infinite;
}

@keyframes cwDotPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25); }
  50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12); }
}

.cw-close {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #fff;
  cursor: pointer;
  box-sizing: border-box;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.cw-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.16);
}

.cw-progress-track {
  height: 5px;
  background: #e9edf5;
  flex-shrink: 0;
}

.cw-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0f2f6b, #e8901a);
  box-shadow: 0 0 8px rgba(232, 144, 26, 0.5);
  border-radius: 0 3px 3px 0;
  transition: width 0.3s ease;
}

.cw-quickbar {
  display: none;
  gap: 8px;
  padding: 8px 14px 0;
  flex-shrink: 0;
}

.cw-quickbar.is-visible {
  display: flex;
}

.cw-quick-btn {
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 44px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

.cw-quick-btn:hover {
  color: #0f2f6b;
  background: rgba(15, 47, 107, 0.08);
}

.cw-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 14px 12px;
  background: linear-gradient(180deg, #eef2f9 0%, #f7f8fa 140px);
  /* Sin scroll interno: el panel crece con el contenido y escala proporcionalmente al
     zoom. Si el contenido excediese el viewport por arriba, es preferible a tener una
     barra de scroll dentro del propio chat. */
  overflow: visible;
}

.cw-card.cw-card-out-fwd,
.cw-card.cw-card-out-back {
  opacity: 0;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.cw-card.cw-card-out-fwd { transform: translateX(-10px); }
.cw-card.cw-card-out-back { transform: translateX(10px); }

.cw-card.cw-card-in-fwd { animation: cwCardInFwd 0.22s ease both; }
.cw-card.cw-card-in-back { animation: cwCardInBack 0.22s ease both; }

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

@keyframes cwCardInBack {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.cw-back {
  display: none;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 48px;
  padding: 4px 2px;
  flex-shrink: 0;
  transition: color 0.15s ease;
}

.cw-back.is-visible {
  display: flex;
}

.cw-back:hover {
  color: #0f2f6b;
}

.cw-question {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
  color: #0a2050;
  flex-shrink: 0;
  white-space: pre-line;
  animation: cwMsgIn 0.2s ease both;
  border-left: 3px solid #e8901a;
  padding: 2px 0 2px 10px;
}

@keyframes cwMsgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.cw-question-error {
  color: #b91c1c;
}

.cw-input-area {
  flex: 0 0 auto;
  min-height: 0;
  /* El scroll lo gestiona .cw-card (contenedor padre). El input-area ya no scroolea aparte,
     evitamos doble scroll anidado que ocultaba la pregunta del bot en tarjetas largas. */
}

.cw-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.cw-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
  background: rgba(255, 255, 255, 0.55);
  border: 1.5px solid rgba(15, 47, 107, 0.35);
  border-radius: 14px;
  padding: 8px;
}

.cw-choices:empty {
  display: none;
  padding: 0;
  border: none;
  background: none;
}

.cw-choice-btn {
  border: 1.5px solid #6f87b8;
  color: #0f2f6b;
  background: transparent;
  border-radius: 16px;
  padding: 5px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
  min-height: 32px;
  min-width: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.25;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
}

.cw-choice-btn:focus-visible,
.cw-send:focus-visible,
.cw-text-input:focus-visible,
.cw-launcher:focus-visible,
.cw-close:focus-visible {
  outline: 2px solid #e8901a;
  outline-offset: 2px;
}

.cw-choice-btn:hover {
  background: linear-gradient(135deg, #f0a93a 0%, #e8901a 100%);
  border-color: #e8901a;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(232, 144, 26, 0.3);
}

.cw-choice-btn--toggle.is-selected {
  background: linear-gradient(135deg, #0f2f6b 0%, #0a2050 100%);
  border-color: #0a2050;
  color: #fff;
  box-shadow: 0 2px 8px rgba(15, 47, 107, 0.35);
}

.cw-choice-btn--toggle.is-selected::before {
  content: "✓ ";
}

.cw-menu-btn {
  flex: 1 0 100%;
  justify-content: flex-start;
  padding: 13px 16px;
  font-size: 0.9375rem;
  border-radius: 14px;
}

.cw-continue-btn {
  flex: 1 0 100%;
  margin-top: 2px;
  border-color: transparent;
  background: linear-gradient(135deg, #f0a93a 0%, #e8901a 100%);
  color: #0a2050;
  padding: 7px 12px;
  min-height: 36px;
  font-size: 0.82rem;
  box-shadow: 0 2px 8px rgba(232, 144, 26, 0.32);
}

.cw-continue-btn::after {
  content: "→";
  display: inline-block;
  margin-left: 6px;
  transition: transform 0.18s ease;
}

.cw-continue-btn:hover {
  background: linear-gradient(135deg, #e8901a 0%, #c9760a 100%);
  border-color: transparent;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(201, 118, 10, 0.4);
}

.cw-continue-btn:hover::after {
  transform: translateX(3px);
}

.cw-text-row {
  display: none;
  gap: 8px;
}

.cw-text-row.is-active {
  display: flex;
}

.cw-text-input {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 20px;
  padding: 10px 15px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cw-text-input:focus {
  outline: none;
  border-color: #2f6fc4;
  box-shadow: 0 0 0 3px rgba(15, 47, 107, 0.15);
}

/* Autocomplete Nominatim dentro del chat: mb-addr-wrap mantiene el flex:1 del input;
   la lista ya es portal position:fixed (no necesita override de posicionamiento). */
.cw-text-row .mb-addr-wrap {
  flex: 1;
}

.cw-send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #f0a93a 0%, #e8901a 100%);
  color: #0a2050;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(232, 144, 26, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cw-send:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 5px 12px rgba(201, 118, 10, 0.4);
}

.cw-send:disabled,
.cw-choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@media (max-width: 480px) {
  /* Launcher subido para no solaparse con CTAs del flujo de página (p. ej. el botón
     naranja "Llamar Ahora" del final de muchas secciones). 86px lo separa de ese bloque
     y lo deja en una posición más natural dentro del alcance del pulgar. */
  .cw-root {
    right: 12px;
    bottom: 86px;
    bottom: calc(86px + env(safe-area-inset-bottom));
  }

  /* Launcher oculto mientras el chat está abierto: el usuario cierra con la X del header */
  .cw-root.is-open .cw-launcher {
    display: none;
  }

  /* El panel se ancla al fondo y crece hacia arriba según el contenido natural. Si una
     tarjeta es corta (2-3 líneas), el panel queda bajito; si es larga (multichoice con
     muchas opciones), crece hasta el max-height del viewport y aparece scroll interno
     en el card. Así nunca hay zona vacía por encima del texto. */
  .cw-root.is-open .cw-panel {
    position: fixed;
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    height: auto;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    max-height: calc(100svh - 24px);
    max-width: none;
  }

  /* Scroll interno del card solo si el contenido supera el max-height del panel. */
  .cw-root.is-open .cw-card {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  /* Botón X más discreto en móvil: 36x36 en vez de 48x48 para no robar protagonismo */
  .cw-close {
    min-width: 36px;
    min-height: 36px;
  }
}

@media (max-height: 480px) {
  .cw-panel {
    min-height: 0;
  }
}

/* Cabecera de sección dentro de un multichoice (OBRA / INSTALACIONES / EQUIPAMIENTO) */
.cw-section-header {
  flex: 1 0 100%;
  margin: 8px 0 2px;
  padding: 4px 2px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #0a2050;
  border-top: 1.5px solid rgba(15, 47, 107, 0.12);
  padding-top: 10px;
}

.cw-section-header:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 2px;
}

/* Inputs de medidas de la estancia (largo × ancho) */
.cw-dims {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 2px 8px;
}

.cw-dims-input {
  width: 92px;
  padding: 10px 12px;
  border: 1.5px solid #e5e7eb;
  border-radius: 14px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -moz-appearance: textfield;
}

.cw-dims-input::-webkit-outer-spin-button,
.cw-dims-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cw-dims-input:focus {
  outline: none;
  border-color: #2f6fc4;
  box-shadow: 0 0 0 3px rgba(15, 47, 107, 0.15);
}

.cw-dims-sep {
  font-weight: 700;
  color: #0a2050;
  font-size: 1.1rem;
}

.cw-dims-unit {
  font-size: 0.95rem;
  color: #4b5563;
  margin-left: 2px;
}

/* Textarea libre al final de cada estancia */
.cw-textarea {
  flex: 1 0 100%;
  width: 100%;
  min-height: 90px;
  resize: vertical;
  padding: 10px 14px;
  border: 1.5px solid #e5e7eb;
  border-radius: 14px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cw-textarea:focus {
  outline: none;
  border-color: #2f6fc4;
  box-shadow: 0 0 0 3px rgba(15, 47, 107, 0.15);
}

/* Lista de sugerencias Nominatim como portal (se añade al <body> por JS).
   Fondo blanco totalmente sólido + borde + sombra fuerte para que nunca se confunda
   con el texto que queda debajo. z-index altísimo para pasar por encima del chat. */
.mb-addr-sugg,
.mb-addr-sugg--portal {
  margin: 0;
  padding: 6px 0;
  background: #ffffff;
  border: 1px solid #c8cfdc;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(10, 32, 80, 0.28), 0 2px 6px rgba(10, 32, 80, 0.16);
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  z-index: 10050;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.92rem;
  /* Opaco también en navegadores con backdrop activo (Safari) */
  -webkit-backdrop-filter: none;
          backdrop-filter: none;
}
.mb-addr-sugg-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  color: #2a3246;
  line-height: 1.35;
  background: #ffffff;
}
.mb-addr-sugg-item + .mb-addr-sugg-item {
  border-top: 1px solid #eef0f5;
}
.mb-addr-sugg-item:hover,
.mb-addr-sugg-item.is-active {
  background: #f1f3f8;
  color: #0a2050;
}
.mb-addr-sugg-ic {
  flex-shrink: 0;
  margin-top: 1px;
}
.mb-addr-sugg-txt {
  flex: 1;
  word-break: break-word;
}
