/* ==========================================================================
   Taxi Chatbot — Floating Widget · Tema Taxi Ride Barcelona
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
  --tcb-accent:        #f5c518;
  --tcb-accent-dark:   #d4a800;
  --tcb-accent-text:   #0a0a0a;
  --tcb-bg:            #111111;
  --tcb-bg-messages:   #0a0a0a;
  --tcb-bot-bubble:    #1c1c1c;
  --tcb-user-bubble:   #f5c518;
  --tcb-bot-text:      #e8e8e8;
  --tcb-user-text:     #0a0a0a;
  --tcb-header-bg:     #0a0a0a;
  --tcb-border:        #2a2a2a;
  --tcb-input-bg:      #1c1c1c;
  --tcb-font:          'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --tcb-width:         360px;
  --tcb-height:        500px;
  --tcb-bottom:        24px;
  --tcb-right:         24px;
}

/* ==========================================================================
   Launcher — burbuja flotante
   ========================================================================== */

.tcb-launcher {
  position: fixed;
  bottom: var(--tcb-bottom);
  right: var(--tcb-right);
  z-index: 99999;
  width: 58px;
  height: 58px;
  background: var(--tcb-accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(245, 197, 24, 0.45), 0 2px 8px rgba(0,0,0,0.4);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  outline: none;
  color: var(--tcb-accent-text);
}

.tcb-launcher:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(245, 197, 24, 0.6), 0 4px 12px rgba(0,0,0,0.4);
}

.tcb-launcher:active { transform: scale(0.95); }

.tcb-launcher__icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tcb-launcher__icon--chat  { opacity: 1; transform: scale(1) rotate(0deg); }
.tcb-launcher__icon--close { opacity: 0; transform: scale(0.6) rotate(-90deg); }

.tcb-launcher.is-open .tcb-launcher__icon--chat  { opacity: 0; transform: scale(0.6) rotate(90deg); }
.tcb-launcher.is-open .tcb-launcher__icon--close { opacity: 1; transform: scale(1) rotate(0deg); }

.tcb-launcher__badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: #ff3b30;
  border-radius: 50%;
  border: 2px solid #111;
  display: none;
}

.tcb-launcher__badge.is-visible { display: block; }

/* ==========================================================================
   Panel
   ========================================================================== */

.tcb-panel {
  position: fixed;
  bottom: calc(var(--tcb-bottom) + 58px + 12px);
  right: var(--tcb-right);
  z-index: 99998;
  width: var(--tcb-width);
  height: var(--tcb-height);
  background: var(--tcb-bg);
  border: 1px solid var(--tcb-border);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.7), 0 8px 24px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--tcb-font);
  font-size: 13px;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.tcb-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ==========================================================================
   Header
   ========================================================================== */

.tcb-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  background: var(--tcb-header-bg);
  color: #fff;
  flex-shrink: 0;
  border-bottom: 1px solid #1a1a1a;
  position: relative;
}

.tcb-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 56px;
  height: 2px;
  background: var(--tcb-accent);
}

.tcb-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--tcb-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--tcb-accent-text);
  flex-shrink: 0;
}

.tcb-header__info { flex: 1; min-width: 0; }

.tcb-header__name {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0.2px;
}

.tcb-header__status {
  font-size: 11px;
  color: #777;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.tcb-header__status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--tcb-accent);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 5px rgba(245, 197, 24, 0.6);
  animation: pcb-pulse 2s infinite;
}

.tcb-header__status.is-typing::before {
  background: #ff9f0a;
  animation: none;
}

@keyframes pcb-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.tcb-minimize {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.tcb-minimize:hover {
  color: var(--tcb-accent);
  background: rgba(245, 197, 24, 0.08);
}

/* ==========================================================================
   Mensajes
   ========================================================================== */

.tcb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--tcb-bg-messages);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.tcb-messages::-webkit-scrollbar { width: 3px; }
.tcb-messages::-webkit-scrollbar-track { background: transparent; }
.tcb-messages::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }
.tcb-messages::-webkit-scrollbar-thumb:hover { background: var(--tcb-accent); }

.tcb-message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: pcb-msg-in 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
  opacity: 0;
}

@keyframes pcb-msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tcb-message--bot  { align-self: flex-start; }
.tcb-message--user { align-self: flex-end; }

.tcb-message__bubble {
  padding: 10px 14px;
  border-radius: 12px;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 13px;
}

.tcb-message--bot .tcb-message__bubble {
  background: var(--tcb-bot-bubble);
  color: var(--tcb-bot-text);
  border: 1px solid #282828;
  border-bottom-left-radius: 3px;
}

.tcb-message--user .tcb-message__bubble {
  background: var(--tcb-user-bubble);
  color: var(--tcb-user-text);
  font-weight: 500;
  border-bottom-right-radius: 3px;
  box-shadow: 0 2px 10px rgba(245, 197, 24, 0.22);
}

.tcb-message__time {
  font-size: 10px;
  color: #444;
  margin-top: 4px;
  padding: 0 2px;
  font-weight: 500;
}

.tcb-message--user .tcb-message__time { text-align: right; color: #555; }

.tcb-message--typing .tcb-message__bubble { padding: 13px 16px; }

.tcb-typing-dots { display: flex; gap: 5px; align-items: center; }

.tcb-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--tcb-accent);
  border-radius: 50%;
  animation: pcb-typing 1.3s infinite ease-in-out;
  opacity: 0.4;
}

.tcb-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.tcb-typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes pcb-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-7px); opacity: 1; }
}

.tcb-message--error .tcb-message__bubble {
  background: #1a0a0a;
  color: #ff6b6b;
  border-color: #3a1515;
}

/* ==========================================================================
   Input area
   ========================================================================== */

.tcb-input-area {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 12px 14px;
  background: var(--tcb-bg);
  border-top: 1px solid var(--tcb-border);
  flex-shrink: 0;
}

.tcb-input {
  flex: 1;
  resize: none;
  border: 1px solid #2a2a2a;
  border-radius: 22px;
  padding: 9px 15px;
  font-family: var(--tcb-font);
  font-size: 13px;
  line-height: 1.4;
  color: #e8e8e8;
  background: var(--tcb-input-bg);
  outline: none;
  max-height: 90px;
  overflow-y: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
  scrollbar-width: none;
}

.tcb-input::-webkit-scrollbar { display: none; }
.tcb-input::-webkit-inner-spin-button,
.tcb-input::-webkit-outer-spin-button { display: none; }

.tcb-input:focus {
  border-color: var(--tcb-accent);
  box-shadow: 0 0 0 2px rgba(245, 197, 24, 0.1);
}

.tcb-input::placeholder { color: #444; }

/* Botón enviar — avión de papel clásico */
.tcb-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--tcb-accent);
  color: #0a0a0a;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}

.tcb-send svg {
  display: block;
  stroke: #0a0a0a;
  fill: none;
  flex-shrink: 0;
}

/* ==========================================================================
   HTML rico en burbujas del bot
   ========================================================================== */

.tcb-message__bubble--html {
  padding: 12px 15px;
}

.tcb-message__bubble--html p {
  margin: 0 0 8px;
  line-height: 1.6;
}

.tcb-message__bubble--html p:last-child { margin-bottom: 0; }

.tcb-message__bubble--html a {
  color: var(--tcb-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tcb-message__bubble--html a:hover { color: var(--tcb-accent-dark); }

.tcb-message__bubble--html img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin-top: 8px;
}

.tcb-message__bubble--html ul,
.tcb-message__bubble--html ol {
  padding-left: 18px;
  margin: 6px 0;
}

.tcb-message__bubble--html li { margin-bottom: 4px; }

.tcb-message__bubble--html strong { color: #fff; font-weight: 600; }

/* Formularios dentro del chat */
.tcb-message__bubble--html form {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tcb-message__bubble--html input,
.tcb-message__bubble--html select,
.tcb-message__bubble--html textarea {
  background: #0a0a0a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 8px 12px;
  color: #e8e8e8;
  font-size: 12px;
  font-family: var(--tcb-font);
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.tcb-message__bubble--html input:focus,
.tcb-message__bubble--html select:focus,
.tcb-message__bubble--html textarea:focus {
  border-color: var(--tcb-accent);
}

.tcb-message__bubble--html input::placeholder,
.tcb-message__bubble--html textarea::placeholder { color: #555; }

.tcb-message__bubble--html button[type="submit"],
.tcb-message__bubble--html input[type="submit"] {
  background: var(--tcb-accent);
  color: var(--tcb-accent-text);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--tcb-font);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  width: 100%;
}

.tcb-message__bubble--html button[type="submit"]:hover {
  background: var(--tcb-accent-dark);
  transform: translateY(-1px);
}

.tcb-message__bubble--html label {
  font-size: 11px;
  color: #888;
  font-weight: 500;
  margin-bottom: -4px;
}

/* Tablas */
.tcb-message__bubble--html table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 8px;
}

.tcb-message__bubble--html th {
  background: #0a0a0a;
  color: var(--tcb-accent);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
}

.tcb-message__bubble--html td {
  padding: 6px 10px;
  border-bottom: 1px solid #2a2a2a;
  color: #ccc;
}

.tcb-message__bubble--html tr:last-child td { border-bottom: none; }

/* ==========================================================================
   Botones de Acción desde n8n (Llamar, Enlaces, etc.)
   ========================================================================== */

/* Estilo del botón dentro de la burbuja */
.tcb-message__bubble--html a.tcb-btn-llamar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tcb-accent);
  color: var(--tcb-accent-text) !important;
  text-decoration: none !important;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-top: 10px;
  transition: all 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}

.tcb-message__bubble--html a.tcb-btn-llamar:hover {
  background: var(--tcb-accent-dark);
  transform: translateY(-2px);
}

/* MAGIA: Si n8n envía SOLO el botón (usando la clase tcb-solo-boton), le quitamos el fondo feo a la burbuja */
.tcb-message--bot:has(.tcb-solo-boton) .tcb-message__bubble {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  box-shadow: none !important;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 420px) {
  :root {
    --tcb-width:  calc(100vw - 20px);
    --tcb-right:  10px;
    --tcb-bottom: 16px;
  }

  .tcb-panel { border-radius: 14px; height: 70vh; }
  .tcb-launcher { width: 52px; height: 52px; }
}