/* ==========================================================================
   AGENTE INTELIGENTE "BRY" — LYZBRI LEGAL
   Estilos de interfaz conversacional (Protocolo 3, Nivel U3)
   Aprobado según diseño de referencia: interfaz.jpeg + Kit de Marca v2
   ========================================================================== */

:root {
  --bry-primary: #102A4C;        /* Azul Lyzbri institucional */
  --bry-turquoise: #18B8B1;      /* Turquesa secundario / iconos / acentos */
  --bry-pink: #E96AAE;           /* Rosa colibrí acento */
  --bry-bubble-agent: #F7A84B;   /* Naranja cálido aprobado para Bry */
  --bry-bubble-user: #BBD4F0;    /* Azul claro aprobado para Usuario */
  --bry-text-main: #18273B;      /* Texto oscuro de alta legibilidad */
  --bry-text-muted: #5A6D82;     /* Texto secundario / metadatos */
  --bry-bg-app: #FFFFFF;         /* Fondo blanco */
  --bry-bg-input: #EFF3F6;       /* Barra inferior redondeada */
  --bry-border: #E2E8F0;         /* Bordes suaves */
  --bry-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bry-shadow-soft: 0 4px 20px rgba(16, 42, 76, 0.08);
  --bry-shadow-card: 0 8px 30px rgba(16, 42, 76, 0.12);
}

/* Reset y caja base con alcance cerrado para no afectar el resto del sitio */
.bry-container,
.bry-container * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--bry-font-family);
  -webkit-font-smoothing: antialiased;
}

/* Contenedor principal de la experiencia Bry */
.bry-container {
  width: 100%;
  max-width: 490px;
  margin: 0 auto;
  background: var(--bry-bg-app);
  display: flex;
  flex-direction: column;
  height: 590px; /* Altura ergonómica para que el visor no crezca indefinidamente */
  max-height: 85vh;
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  box-shadow: var(--bry-shadow-card);
  border: 1px solid var(--bry-border);
}

/* Encabezado con marca Lyzbri */
.bry-header {
  padding: 18px 20px 14px;
  background: #FFFFFF;
  text-align: center;
  border-bottom: 1px solid rgba(226, 232, 240, 0.6);
  position: relative;
  z-index: 10;
}

.bry-brand-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.bry-header-logo {
  height: 52px;
  width: auto;
  max-width: 170px;
  object-fit: contain;
  margin-bottom: 4px;
}

.bry-brand-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--bry-primary);
  letter-spacing: -0.4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bry-brand-subtitle {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--bry-text-muted);
  letter-spacing: 0.3px;
  margin-top: 1px;
}

.bry-agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 3px 10px;
  background: #F0F8F8;
  border: 1px solid rgba(24, 184, 177, 0.25);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--bry-primary);
}

.bry-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10B981;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Área de conversación con scroll */
.bry-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  background: #FFFFFF;
}

/* Escenario de paso a paso con reemplazo de turno (Flujo Anti-Gravity) */
.bry-stage-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: bryStageEnter 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.18s ease-out, transform 0.18s ease-out;
}

.bry-stage-container.bry-stage-exit {
  opacity: 0;
  transform: translateY(-12px);
  pointer-events: none;
}

@keyframes bryStageEnter {
  0% {
    opacity: 0;
    transform: translateY(14px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.bry-stage-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(226, 232, 240, 0.8);
}

.bry-btn-back-step {
  background: none;
  border: none;
  color: var(--bry-text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.bry-btn-back-step:hover {
  background: #F0F4F8;
  color: var(--bry-primary);
}

.bry-prev-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--bry-turquoise);
  background: #F0F8F8;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid rgba(24, 184, 177, 0.2);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bry-bold-name {
  font-weight: 800;
  color: #102A4C;
  letter-spacing: 0.3px;
  display: inline;
}

/* Fila de mensaje */
.bry-message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  animation: bryFadeSlideUp 0.25s ease-out forwards;
}

.bry-message-row.bry-agent {
  justify-content: flex-start;
}

.bry-message-row.bry-user {
  justify-content: flex-end;
}

/* Avatares */
.bry-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(16, 42, 76, 0.1);
  background: #FFFFFF;
  border: 1.5px solid #FFFFFF;
}

.bry-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bry-avatar.bry-user-avatar {
  background: #E8F2FD;
  border: 1.5px solid #BBD4F0;
  color: var(--bry-primary);
}

/* Burbujas de chat */
.bry-bubble {
  max-width: 82%;
  padding: 14px 17px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--bry-text-main);
  position: relative;
  word-break: break-word;
}

/* Burbuja del Agente (Naranja Cálido) */
.bry-message-row.bry-agent .bry-bubble {
  background-color: var(--bry-bubble-agent);
  color: var(--bry-text-main);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 2px 10px rgba(247, 168, 75, 0.22);
}

/* Burbuja del Usuario (Azul Claro) */
.bry-message-row.bry-user .bry-bubble {
  background-color: var(--bry-bubble-user);
  color: var(--bry-text-main);
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 2px 10px rgba(187, 212, 240, 0.25);
}

/* Opciones interactivas rápidas (Chips / Quick Replies) */
.bry-quick-replies {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding-left: 0;
  width: 100%;
  animation: bryFadeSlideUp 0.3s ease-out;
  transition: opacity 0.25s ease, max-height 0.25s ease, margin 0.25s ease, padding 0.25s ease;
}

/* Compactación automática para evitar "muros de botones" (Experiencia Anti-Gravity) */
.bry-quick-replies.bry-replies-hidden {
  opacity: 0;
  max-height: 0;
  margin: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.bry-chip-btn {
  background: #FFFFFF;
  border: 1.5px solid rgba(24, 184, 177, 0.4);
  color: var(--bry-primary);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: left;
  min-height: 42px;
  display: flex;
  align-items: center;
  width: 100%;
  box-shadow: 0 2px 6px rgba(16, 42, 76, 0.04);
}

.bry-chip-btn:hover {
  background: #18B8B1;
  color: #FFFFFF;
  border-color: #18B8B1;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(24, 184, 177, 0.25);
}

.bry-chip-btn:focus-visible {
  outline: 2px solid var(--bry-turquoise);
  outline-offset: 2px;
}

.bry-chip-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Botón flotante / destacado de Apertura Limpia: "Empezar orientación" */
.bry-start-action-container {
  display: flex;
  justify-content: flex-start;
  padding-left: 44px;
  margin-top: 8px;
  animation: bryFadeSlideUp 0.35s ease-out;
  transition: opacity 0.25s ease, max-height 0.25s ease;
}

.bry-start-action-container.bry-start-hidden {
  opacity: 0;
  max-height: 0;
  margin: 0;
  overflow: hidden;
  pointer-events: none;
}

.bry-btn-start {
  background: linear-gradient(135deg, #102A4C 0%, #173B6B 100%);
  color: #FFFFFF;
  border: 1.5px solid rgba(24, 184, 177, 0.5);
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(16, 42, 76, 0.16), 0 0 0 3px rgba(24, 184, 177, 0.12);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 48px;
}

.bry-btn-start:hover {
  background: #18B8B1;
  color: #FFFFFF;
  border-color: #18B8B1;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(24, 184, 177, 0.35);
}

.bry-btn-start svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  transition: transform 0.2s;
}

.bry-btn-start:hover svg {
  transform: translateX(3px);
}

/* Indicador de escritura "Bry está escribiendo..." */
.bry-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: #FBEBD9;
  border-radius: 18px 18px 18px 4px;
  width: fit-content;
}

.bry-typing-dot {
  width: 7px;
  height: 7px;
  background-color: #E2872A;
  border-radius: 50%;
  animation: bryBouncingDot 1.4s infinite ease-in-out both;
}

.bry-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.bry-typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* Tarjetas especiales dentro del chat (Resultado / Alerta / Contacto) */
.bry-card {
  background: #FFFFFF;
  border: 1.5px solid var(--bry-border);
  border-radius: 18px;
  padding: 18px;
  margin-top: 8px;
  margin-bottom: 4px;
  box-shadow: var(--bry-shadow-soft);
  max-width: 95%;
}

.bry-card-result {
  border-color: var(--bry-turquoise);
  background: linear-gradient(180deg, #FAFEFE 0%, #FFFFFF 100%);
}

.bry-badge-legal {
  display: inline-block;
  background: #18B8B1;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.bry-card-title {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--bry-primary);
  margin-bottom: 8px;
  line-height: 1.35;
}

.bry-card-desc {
  font-size: 14px;
  line-height: 1.5;
  color: var(--bry-text-main);
  margin-bottom: 14px;
}

.bry-price-box {
  background: #F0F8F8;
  border-left: 4px solid var(--bry-turquoise);
  padding: 10px 14px;
  border-radius: 4px 10px 10px 4px;
  margin-bottom: 14px;
}

.bry-price-label {
  font-size: 11.5px;
  color: var(--bry-text-muted);
  font-weight: 500;
}

.bry-price-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--bry-primary);
}

/* Alerta por Temeridad */
.bry-alert-temerity {
  background: #FFF8E6;
  border: 1.5px solid #F59E0B;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  color: #854D0E;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.bry-alert-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* Formulario embebido de contacto */
.bry-contact-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.bry-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bry-input-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--bry-primary);
}

.bry-input-control {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--bry-border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 15px; /* Evita zoom automático en Safari iOS */
  color: var(--bry-text-main);
  background: #FFFFFF;
  transition: border-color 0.2s;
}

.bry-input-control:focus {
  outline: none;
  border-color: var(--bry-turquoise);
  box-shadow: 0 0 0 3px rgba(24, 184, 177, 0.15);
}

.bry-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--bry-text-muted);
  line-height: 1.4;
  cursor: pointer;
  margin-top: 4px;
}

.bry-consent-checkbox {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--bry-turquoise);
  cursor: pointer;
}

.bry-btn-primary {
  width: 100%;
  min-height: 48px;
  background: var(--bry-primary);
  color: #FFFFFF;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 4px 14px rgba(16, 42, 76, 0.2);
  margin-top: 6px;
}

.bry-btn-primary:hover {
  background: #173B6B;
}

.bry-btn-primary:active {
  transform: scale(0.99);
}

/* Botón secundario para fallbacks */
.bry-btn-secondary {
  width: 100%;
  min-height: 44px;
  background: #FFFFFF;
  color: var(--bry-primary);
  border: 1.5px solid var(--bry-border);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: all 0.2s;
}

.bry-btn-secondary:hover {
  background: #F6F8FA;
  border-color: var(--bry-primary);
}

/* Barra inferior de entrada (Idéntica al mockup interfaz.jpeg) */
.bry-chat-input-bar {
  padding: 12px 16px 16px;
  background: #FFFFFF;
  border-top: 1px solid rgba(226, 232, 240, 0.7);
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 10;
}

.bry-pill-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bry-bg-input);
  border-radius: 999px;
  padding: 4px 10px 4px 18px;
  border: 1.5px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.bry-pill-input-wrapper:focus-within {
  border-color: var(--bry-turquoise);
  background: #FFFFFF;
  box-shadow: 0 0 0 3px rgba(24, 184, 177, 0.12);
}

.bry-input-text {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  color: var(--bry-text-main);
  outline: none;
  padding: 8px 4px 8px 0;
}

.bry-input-text::placeholder {
  color: #8C9CAE;
}

/* Iconos de la barra inferior */
.bry-icon-btn {
  background: none;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--bry-turquoise);
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
}

.bry-icon-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.bry-icon-btn:hover:not(:disabled) {
  background: rgba(24, 184, 177, 0.12);
  transform: scale(1.05);
}

.bry-icon-btn.bry-icon-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  position: relative;
}

.bry-icon-btn.bry-icon-send {
  color: var(--bry-turquoise);
}

.bry-icon-btn.bry-icon-send:hover {
  background: rgba(24, 184, 177, 0.15);
}

/* Tooltip accesible para iconos desactivados (Voz y Adjuntos en v1) */
.bry-tooltip {
  position: absolute;
  bottom: 56px;
  background: var(--bry-primary);
  color: #FFFFFF;
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 4px 12px rgba(16, 42, 76, 0.2);
}

.bry-tooltip.bry-tooltip-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Animaciones */
@keyframes bryFadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bryBouncingDot {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Adaptabilidad Mobile-First y Responsiva */
@media (max-width: 480px) {
  .bry-container {
    border-radius: 0;
    border: none;
    box-shadow: none;
    min-height: 100vh;
    height: 100vh;
  }
  
  .bry-header {
    padding: 12px 14px 10px;
  }

  .bry-header-logo {
    height: 44px;
  }

  .bry-chat-messages {
    padding: 14px 12px;
  }

  .bry-bubble {
    max-width: 88%;
    font-size: 14.5px;
    padding: 12px 15px;
  }

  .bry-quick-replies {
    padding-left: 0;
  }

  .bry-chip-btn {
    font-size: 13.5px;
    padding: 8px 13px;
  }
}
