/* Tornobot — Asistente Virtual de Torno Cisneros
 * Componente flotante de prediagnóstico industrial
 * Tokens heredados del sistema de diseño del sitio
 */

:root {
  --tbot-paper: #0E1525;
  --tbot-paper-2: #151E30;
  --tbot-paper-3: #1C2840;
  --tbot-border: rgba(42,58,85,.6);
  --tbot-border-hover: rgba(30,111,255,.5);
  --tbot-accent: #1E6FFF;
  --tbot-accent-dim: #155ACC;
  --tbot-accent-glow: rgba(30,111,255,.25);
  --tbot-text: #E8F0F8;
  --tbot-text-secondary: #6B7E99;
  --tbot-text-body: #B8C8DC;
  --tbot-success: #25D366;
  --tbot-warning: #F59E0B;
  --tbot-danger: #EF4444;
  --tbot-radius: 8px;
  --tbot-radius-sm: 4px;
  --tbot-radius-xl: 12px;
  --tbot-font-heading: 'Barlow Condensed', sans-serif;
  --tbot-font-body: 'Barlow', sans-serif;
  --tbot-font-mono: 'Share Tech Mono', monospace;
  --tbot-shadow: 0 8px 40px rgba(0,0,0,.6);
  --tbot-ease: cubic-bezier(.4,0,.2,1);
  --tbot-z-fab: 9998;
  --tbot-z-invite: 9997;
  --tbot-z-panel: 9995;
  --tbot-z-overlay: 9990;
}

/* ====== FAB (Floating Action Button) ====== */
#tbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--tbot-z-fab);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .3s var(--tbot-ease);
}

#tbot-fab:hover { transform: scale(1.05); }
#tbot-fab:active { transform: scale(.95); }

#tbot-fab:focus-visible .tbot-fab-circle {
  outline: 2px solid var(--tbot-accent);
  outline-offset: 4px;
}

.tbot-fab-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tbot-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(30,111,255,.4);
  transition: background .25s, box-shadow .25s;
  flex-shrink: 0;
}

#tbot-fab:hover .tbot-fab-circle {
  background: var(--tbot-accent-dim);
  box-shadow: 0 6px 28px rgba(30,111,255,.55);
}

.tbot-fab-circle svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tbot-fab-label {
  font-family: var(--tbot-font-heading);
  font-weight: 700;
  font-size: .82rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--tbot-text);
  background: var(--tbot-paper-2);
  padding: 8px 14px;
  border-radius: var(--tbot-radius);
  border: 1px solid var(--tbot-border);
  white-space: nowrap;
  display: none;
}

@media (min-width: 768px) {
  .tbot-fab-label { display: block; }
  #tbot-fab { right: 32px; bottom: 32px; }
}

/* ====== INVITATION BUBBLE ====== */
#tbot-invite {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: var(--tbot-z-invite);
  width: min(340px, calc(100vw - 48px));
  background: var(--tbot-paper-2);
  border: 1px solid var(--tbot-border);
  border-radius: var(--tbot-radius-xl);
  padding: 20px 20px 16px;
  box-shadow: var(--tbot-shadow);
  animation: tbot-slide-up .35s var(--tbot-ease) forwards;
  display: none;
}

#tbot-invite.tbot-visible { display: block; }

#tbot-invite::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 32px;
  width: 14px;
  height: 14px;
  background: var(--tbot-paper-2);
  border-right: 1px solid var(--tbot-border);
  border-bottom: 1px solid var(--tbot-border);
  transform: rotate(45deg);
}

.tbot-invite-text {
  font-family: var(--tbot-font-body);
  font-size: .88rem;
  line-height: 1.5;
  color: var(--tbot-text-body);
  margin: 0 0 14px;
}

.tbot-invite-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tbot-invite-start {
  font-family: var(--tbot-font-heading);
  font-weight: 700;
  font-size: .78rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  padding: 10px 18px;
  border: none;
  border-radius: var(--tbot-radius);
  background: var(--tbot-accent);
  color: #fff;
  cursor: pointer;
  transition: background .25s, transform .2s;
  flex: 1;
  min-width: 140px;
}

.tbot-invite-start:hover { background: var(--tbot-accent-dim); }
.tbot-invite-start:active { transform: scale(.97); }

.tbot-invite-later {
  font-family: var(--tbot-font-body);
  font-size: .82rem;
  color: var(--tbot-text-secondary);
  background: transparent;
  border: 1px solid var(--tbot-border);
  border-radius: var(--tbot-radius);
  padding: 10px 16px;
  cursor: pointer;
  transition: color .25s, border-color .25s;
  flex: 1;
  min-width: 100px;
}

.tbot-invite-later:hover { color: var(--tbot-text); border-color: var(--tbot-text-secondary); }

.tbot-invite-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--tbot-text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, background .2s;
}

.tbot-invite-close:hover { color: var(--tbot-text); background: rgba(255,255,255,.08); }

/* ====== OVERLAY ====== */
#tbot-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--tbot-z-overlay);
  background: rgba(0,0,0,.6);
  opacity: 0;
  transition: opacity .3s var(--tbot-ease);
  pointer-events: none;
  display: none;
}

#tbot-overlay.tbot-active { display: block; opacity: 1; pointer-events: auto; }

/* ====== PANEL ====== */
#tbot-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: var(--tbot-z-panel);
  width: 100%;
  max-height: 90vh;
  height: 100%;
  background: var(--tbot-paper);
  border: 1px solid var(--tbot-border);
  display: none;
  flex-direction: column;
  box-shadow: var(--tbot-shadow);
  animation: tbot-slide-up .35s var(--tbot-ease) forwards;
}

#tbot-panel.tbot-active { display: flex; }

@media (min-width: 768px) {
  #tbot-panel {
    bottom: 96px;
    right: 24px;
    width: 400px;
    height: min(600px, calc(100vh - 128px));
    border-radius: var(--tbot-radius-xl);
    max-height: calc(100vh - 128px);
  }
}

@media (min-width: 768px) and (max-height: 700px) {
  #tbot-panel { height: min(480px, calc(100vh - 128px)); }
}

/* ====== HEADER ====== */
.tbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--tbot-border);
  flex-shrink: 0;
}

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

.tbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tbot-accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tbot-avatar svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--tbot-accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tbot-header-title {
  font-family: var(--tbot-font-heading);
  font-weight: 700;
  font-size: .95rem;
  color: var(--tbot-text);
  line-height: 1.2;
}

.tbot-header-status {
  font-family: var(--tbot-font-mono);
  font-size: .68rem;
  color: var(--tbot-success);
  letter-spacing: .05em;
}

.tbot-header-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--tbot-text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, background .2s;
}

.tbot-header-close:hover { color: var(--tbot-text); background: rgba(255,255,255,.08); }

/* ====== PROGRESS BAR ====== */
.tbot-progress {
  height: 3px;
  background: var(--tbot-paper-3);
  flex-shrink: 0;
}

.tbot-progress-fill {
  height: 100%;
  background: var(--tbot-accent);
  transition: width .45s var(--tbot-ease);
  width: 0%;
}

/* ====== MESSAGES AREA ====== */
.tbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.tbot-messages::-webkit-scrollbar { width: 4px; }
.tbot-messages::-webkit-scrollbar-track { background: transparent; }
.tbot-messages::-webkit-scrollbar-thumb { background: var(--tbot-paper-3); border-radius: 2px; }

/* ====== BOT MESSAGE ====== */
.tbot-msg-bot {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: tbot-fade-in .35s var(--tbot-ease) forwards;
}

.tbot-msg-bot-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--tbot-accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.tbot-msg-bot-avatar svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--tbot-accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tbot-msg-bubble {
  background: var(--tbot-paper-2);
  border: 1px solid var(--tbot-border);
  border-radius: 0 var(--tbot-radius-xl) var(--tbot-radius-xl) var(--tbot-radius-xl);
  padding: 12px 16px;
}

.tbot-msg-text {
  font-family: var(--tbot-font-body);
  font-size: .85rem;
  line-height: 1.55;
  color: var(--tbot-text-body);
  margin: 0;
}

.tbot-msg-text strong { color: var(--tbot-text); font-weight: 600; }

/* ====== USER MESSAGE ====== */
.tbot-msg-user {
  display: flex;
  justify-content: flex-end;
  max-width: 80%;
  margin-left: auto;
  animation: tbot-fade-in .3s var(--tbot-ease) forwards;
}

.tbot-msg-user .tbot-msg-bubble {
  background: var(--tbot-accent);
  border-color: var(--tbot-accent);
  border-radius: var(--tbot-radius-xl) 0 var(--tbot-radius-xl) var(--tbot-radius-xl);
}

.tbot-msg-user .tbot-msg-text { color: #fff; }

/* ====== TYPING INDICATOR ====== */
.tbot-typing {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: tbot-fade-in .25s var(--tbot-ease) forwards;
}

.tbot-typing-bubble {
  background: var(--tbot-paper-2);
  border: 1px solid var(--tbot-border);
  border-radius: 0 var(--tbot-radius-xl) var(--tbot-radius-xl) var(--tbot-radius-xl);
  padding: 14px 18px;
  display: flex;
  gap: 4px;
}

.tbot-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tbot-text-secondary);
  animation: tbot-bounce 1.2s infinite;
}

.tbot-typing-dot:nth-child(2) { animation-delay: .2s; }
.tbot-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes tbot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ====== OPTIONS ====== */
.tbot-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 0;
  animation: tbot-fade-in .35s var(--tbot-ease) forwards;
}

.tbot-option {
  font-family: var(--tbot-font-body);
  font-size: .82rem;
  font-weight: 500;
  color: var(--tbot-text);
  background: var(--tbot-paper-2);
  border: 1px solid var(--tbot-border);
  border-radius: var(--tbot-radius);
  padding: 10px 18px;
  cursor: pointer;
  transition: all .2s var(--tbot-ease);
  text-align: left;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  min-height: 44px;
}

.tbot-option:hover {
  border-color: var(--tbot-accent);
  background: rgba(30,111,255,.08);
}

.tbot-option:active { transform: scale(.97); }

.tbot-option:focus-visible {
  outline: 2px solid var(--tbot-accent);
  outline-offset: 2px;
}

.tbot-option.tbot-selected {
  background: rgba(30,111,255,.15);
  border-color: var(--tbot-accent);
  color: #fff;
}

/* ====== INPUT AREA (text inputs at end) ====== */
.tbot-input-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
  animation: tbot-fade-in .35s var(--tbot-ease) forwards;
}

.tbot-input {
  font-family: var(--tbot-font-body);
  font-size: .85rem;
  color: var(--tbot-text);
  background: var(--tbot-paper-2);
  border: 1px solid var(--tbot-border);
  border-radius: var(--tbot-radius);
  padding: 12px 14px;
  outline: none;
  transition: border-color .25s;
  width: 100%;
  min-height: 44px;
}

.tbot-input::placeholder { color: var(--tbot-text-secondary); }
.tbot-input:focus { border-color: var(--tbot-accent); }

.tbot-input-submit {
  font-family: var(--tbot-font-heading);
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  padding: 12px 20px;
  border: none;
  border-radius: var(--tbot-radius);
  background: var(--tbot-accent);
  color: #fff;
  cursor: pointer;
  transition: background .25s, transform .2s;
  min-height: 44px;
}

.tbot-input-submit:hover { background: var(--tbot-accent-dim); }
.tbot-input-submit:active { transform: scale(.97); }
.tbot-input-submit:disabled { opacity: .4; cursor: not-allowed; }

/* Checkbox */
.tbot-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-family: var(--tbot-font-body);
  font-size: .82rem;
  color: var(--tbot-text-body);
  line-height: 1.4;
  padding: 4px 0;
}

.tbot-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--tbot-accent);
  cursor: pointer;
}

/* ====== RESULT CARD ====== */
.tbot-result {
  background: var(--tbot-paper-2);
  border: 1px solid var(--tbot-accent-glow);
  border-radius: var(--tbot-radius-xl);
  padding: 20px;
  animation: tbot-fade-in .4s var(--tbot-ease) forwards;
  margin: 4px 0;
}

.tbot-result-title {
  font-family: var(--tbot-font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--tbot-accent);
  margin: 0 0 16px;
  letter-spacing: .05em;
}

.tbot-result-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(42,58,85,.3);
}

.tbot-result-row:last-child { border-bottom: none; }

.tbot-result-label {
  font-family: var(--tbot-font-mono);
  font-size: .68rem;
  color: var(--tbot-text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  flex-shrink: 0;
}

.tbot-result-value {
  font-family: var(--tbot-font-body);
  font-size: .82rem;
  color: var(--tbot-text);
  text-align: right;
}

.tbot-result-note {
  font-family: var(--tbot-font-body);
  font-size: .75rem;
  color: var(--tbot-text-secondary);
  font-style: italic;
  margin: 14px 0 0;
  line-height: 1.4;
}

/* ====== WHATSAPP BUTTON ====== */
.tbot-wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--tbot-font-heading);
  font-weight: 700;
  font-size: .88rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 14px 24px;
  border: none;
  border-radius: var(--tbot-radius);
  background: var(--tbot-success);
  color: #0A0A0A;
  cursor: pointer;
  transition: background .25s, transform .2s;
  min-height: 48px;
  width: 100%;
}

.tbot-wa-btn:hover { background: #20b859; }
.tbot-wa-btn:active { transform: scale(.98); }
.tbot-wa-btn:focus-visible { outline: 2px solid var(--tbot-success); outline-offset: 2px; }

.tbot-wa-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ====== SECONDARY BUTTON ====== */
.tbot-secondary-btn {
  font-family: var(--tbot-font-body);
  font-size: .82rem;
  color: var(--tbot-text-secondary);
  background: transparent;
  border: 1px solid var(--tbot-border);
  border-radius: var(--tbot-radius);
  padding: 10px 16px;
  cursor: pointer;
  transition: all .25s;
  min-height: 44px;
}

.tbot-secondary-btn:hover { color: var(--tbot-text); border-color: var(--tbot-text-secondary); }

/* ====== FOOTER ACTIONS ====== */
.tbot-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--tbot-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tbot-back-btn {
  font-family: var(--tbot-font-body);
  font-size: .78rem;
  color: var(--tbot-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color .2s;
}

.tbot-back-btn:hover { color: var(--tbot-text); }
.tbot-back-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

.tbot-restart-btn {
  font-family: var(--tbot-font-mono);
  font-size: .68rem;
  color: var(--tbot-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  margin-left: auto;
  transition: color .2s;
}

.tbot-restart-btn:hover { color: var(--tbot-danger); }

/* ====== WHATSAPP SENT NOTE ====== */
.tbot-wa-note {
  font-family: var(--tbot-font-body);
  font-size: .78rem;
  color: var(--tbot-text-secondary);
  text-align: center;
  padding: 8px 0 0;
  line-height: 1.4;
}

/* ====== ANIMATIONS ====== */
@keyframes tbot-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tbot-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ====== REDUCED MOTION ====== */
@media (prefers-reduced-motion: reduce) {
  #tbot-invite,
  #tbot-panel,
  .tbot-msg-bot,
  .tbot-msg-user,
  .tbot-typing,
  .tbot-options,
  .tbot-input-area,
  .tbot-result,
  .tbot-progress-fill {
    animation: none !important;
    transition: none !important;
  }

  #tbot-fab { transition: none !important; }
  .tbot-typing-dot { animation: none !important; opacity: .6; }
}

/* ====== SAFE AREA (mobile notched devices) ====== */
@supports (padding: max(0px)) {
  #tbot-panel {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }

  #tbot-fab {
    bottom: max(24px, env(safe-area-inset-bottom, 24px));
    right: max(24px, env(safe-area-inset-right, 24px));
  }

  #tbot-invite {
    bottom: max(92px, calc(env(safe-area-inset-bottom, 0px) + 92px));
    right: max(24px, env(safe-area-inset-right, 24px));
  }
}
