/* DroboAI Training Coach — premium chat widget */
:root {
  --drobo-chat-bg: #070b14;
  --drobo-chat-panel: #0c1220;
  --drobo-chat-surface: rgba(22, 32, 52, 0.88);
  --drobo-chat-border: rgba(148, 163, 184, 0.12);
  --drobo-chat-blue: #3b82f6;
  --drobo-chat-blue-deep: #1d4ed8;
  --drobo-chat-text: #e8eef9;
  --drobo-chat-muted: #8b9bb8;
}

@keyframes drobo-chat-pop {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes drobo-msg-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes drobo-btn-pulse {
  0%,
  100% {
    box-shadow: 0 8px 28px rgba(37, 99, 235, 0.4), 0 0 0 0 rgba(59, 130, 246, 0.35);
  }
  50% {
    box-shadow: 0 10px 34px rgba(37, 99, 235, 0.55), 0 0 0 10px rgba(59, 130, 246, 0);
  }
}

@keyframes drobo-typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes drobo-shimmer {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

@keyframes drobo-live-dot {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.85);
  }
}

body.drobo-chat-open {
  overflow: hidden;
  touch-action: none;
}

#drobo-chat-btn {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  right: max(28px, env(safe-area-inset-right, 0px));
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(145deg, #60a5fa, #2563eb 45%, #1d4ed8);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s;
  animation: drobo-btn-pulse 2.8s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

#drobo-chat-btn:hover {
  transform: scale(1.08) translateY(-2px);
  animation: none;
}

#drobo-chat-btn.is-open {
  animation: none;
  background: linear-gradient(145deg, #1e293b, #0f172a);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

#drobo-chat-btn svg {
  width: 26px;
  height: 26px;
}

#drobo-chat-window {
  --noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  right: max(28px, env(safe-area-inset-right, 0px));
  width: min(400px, calc(100vw - 32px));
  height: min(600px, calc(100dvh - 110px));
  max-height: calc(100dvh - 110px);
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(37, 99, 235, 0.22), transparent 42%),
    radial-gradient(90% 60% at 0% 100%, rgba(14, 165, 233, 0.1), transparent 45%),
    linear-gradient(165deg, #101936 0%, var(--drobo-chat-bg) 48%, #060910 100%);
  border-radius: 22px;
  border: 1px solid rgba(96, 165, 250, 0.22);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  font-family: "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
  transform-origin: bottom right;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

#drobo-chat-window::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--noise);
  background-size: 180px 180px;
  opacity: 0.07;
  pointer-events: none;
  z-index: 0;
  mix-blend-mode: overlay;
}

#drobo-chat-window > * {
  position: relative;
  z-index: 1;
}

#drobo-chat-window.open {
  display: flex;
  animation: drobo-chat-pop 0.42s cubic-bezier(0.16, 1, 0.3, 1);
}

#drobo-chat-header {
  padding: 16px 16px 14px;
  padding-top: max(16px, env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
  background: linear-gradient(180deg, rgba(30, 58, 138, 0.45), rgba(15, 23, 42, 0.15));
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.drobo-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.drobo-chat-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
  color: #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.drobo-chat-icon-btn svg {
  width: 16px;
  height: 16px;
}

.drobo-chat-icon-btn:hover {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(96, 165, 250, 0.35);
  color: #eff6ff;
}

.drobo-chat-home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.drobo-chat-home-btn {
  appearance: none;
  border: 1px solid rgba(96, 165, 250, 0.28);
  background: rgba(59, 130, 246, 0.12);
  color: #bfdbfe;
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.drobo-chat-home-btn:hover {
  background: rgba(59, 130, 246, 0.22);
  transform: translateY(-1px);
}

.drobo-chat-home-btn--primary {
  background: linear-gradient(135deg, #60a5fa, #2563eb 50%, #1d4ed8);
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.drobo-chat-home-btn--primary:hover {
  color: #fff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.45);
}

.drobo-chat-prev-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  width: 100%;
}

.drobo-chat-prev-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font: inherit;
  transition: background 0.2s, border-color 0.2s;
}

.drobo-chat-prev-item:hover {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(96, 165, 250, 0.28);
}

.drobo-chat-prev-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.drobo-chat-prev-meta {
  font-size: 11px;
  color: #94a3b8;
}

#drobo-chat-header .drobo-chat-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

#drobo-chat-header .drobo-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #60a5fa, #2563eb 55%, #1e40af);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
  color: #fff;
}

#drobo-chat-header .drobo-chat-avatar svg {
  width: 20px;
  height: 20px;
}

#drobo-chat-header .title {
  color: #f8fafc;
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

#drobo-chat-header .subtitle {
  color: var(--drobo-chat-muted);
  font-size: 11px;
  margin-top: 3px;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 6px;
}

#drobo-chat-header .drobo-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
  animation: drobo-live-dot 1.8s ease-in-out infinite;
  flex-shrink: 0;
}

#drobo-close-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #c7d2fe;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  border-radius: 12px;
  transition: background 0.2s, color 0.2s, transform 0.2s;
  width: 40px;
  height: 40px;
  min-width: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

#drobo-close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  transform: rotate(90deg);
}

#drobo-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.55) transparent;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#drobo-messages::-webkit-scrollbar {
  width: 5px;
}

#drobo-messages::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.45);
  border-radius: 999px;
}

.drobo-msg {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
  animation: drobo-msg-in 0.38s cubic-bezier(0.16, 1, 0.3, 1);
}

.drobo-msg strong {
  font-weight: 700;
  color: inherit;
}

.drobo-msg em {
  font-style: italic;
  opacity: 0.95;
}

.drobo-msg.bot {
  background: var(--drobo-chat-surface);
  color: var(--drobo-chat-text);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  border: 1px solid var(--drobo-chat-border);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
}

.drobo-msg.bot strong {
  color: #f8fafc;
}

.drobo-msg a.drobo-chat-link {
  color: #93c5fd;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
  transition: color 0.15s;
}

.drobo-msg a.drobo-chat-link:hover {
  color: #dbeafe;
}

.drobo-chat-cta-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 2px;
  width: 100%;
}

.drobo-msg a.drobo-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  padding: 11px 16px;
  border-radius: 12px;
  text-decoration: none !important;
  font-weight: 650;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  line-height: 1.2;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease,
    border-color 0.18s ease;
  box-sizing: border-box;
}

.drobo-msg a.drobo-chat-btn--primary {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 55%, #1d4ed8 100%);
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.32);
}

.drobo-msg a.drobo-chat-btn--primary:hover {
  transform: translateY(-1px);
  color: #fff !important;
  box-shadow: 0 12px 22px rgba(37, 99, 235, 0.42);
}

.drobo-msg a.drobo-chat-btn--secondary {
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0 !important;
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.drobo-msg a.drobo-chat-btn--secondary:hover {
  transform: translateY(-1px);
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(96, 165, 250, 0.4);
  color: #f8fafc !important;
}

/* Legacy class names still style cleanly if any cached HTML remains */
.drobo-msg a.drobo-chat-link--cta {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 11px 16px;
  border-radius: 12px;
  text-decoration: none !important;
  font-weight: 650;
  font-size: 13.5px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.drobo-msg a.drobo-chat-link--soft {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 11px 16px;
  border-radius: 12px;
  text-decoration: none !important;
  font-weight: 650;
  font-size: 13.5px;
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0 !important;
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.drobo-msg.user {
  background: linear-gradient(145deg, #3b82f6, #2563eb 60%, #1d4ed8);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.32);
}

.drobo-msg.user a.drobo-chat-link {
  color: #dbeafe;
}

.drobo-msg.typing {
  background: var(--drobo-chat-surface);
  color: var(--drobo-chat-muted);
  align-self: flex-start;
  font-style: normal;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 72px;
  border: 1px solid var(--drobo-chat-border);
}

.drobo-typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.drobo-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7dd3fc;
  animation: drobo-typing-bounce 1.15s ease-in-out infinite;
}

.drobo-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.drobo-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

#drobo-input-area {
  padding: 12px 12px 8px;
  background: rgba(8, 12, 22, 0.72);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

#drobo-input {
  flex: 1;
  min-width: 0;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  color: #e8eef9;
  padding: 11px 13px;
  font-size: 16px;
  outline: none;
  resize: none;
  height: 46px;
  min-height: 46px;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
}

#drobo-input::placeholder {
  color: #64748b;
}

#drobo-input:focus {
  border-color: rgba(96, 165, 250, 0.55);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.14);
  background: rgba(15, 23, 42, 1);
}

#drobo-send-btn {
  background: linear-gradient(145deg, #60a5fa, #2563eb);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  width: 46px;
  height: 46px;
  min-width: 46px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.3);
  -webkit-tap-highlight-color: transparent;
}

#drobo-send-btn:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.4);
}

#drobo-send-btn:disabled {
  background: #1e293b;
  border-color: rgba(148, 163, 184, 0.12);
  cursor: not-allowed;
  opacity: 0.65;
  box-shadow: none;
}

#drobo-send-btn svg {
  width: 18px;
  height: 18px;
  color: #fff;
}

#drobo-powered {
  text-align: center;
  font-size: 10px;
  color: #64748b;
  padding: 2px 8px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  background: rgba(8, 12, 22, 0.72);
  flex-shrink: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

@media (max-width: 640px) {
  #drobo-chat-btn {
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
    width: 56px;
    height: 56px;
  }

  body.drobo-chat-open #drobo-chat-btn {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85);
  }

  #drobo-chat-window {
    inset: auto;
    top: 0;
    bottom: auto;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    height: 100dvh;
    height: 100svh;
    max-height: none;
    border-radius: 0;
    border: none;
    transform-origin: bottom center;
    /* JS pins top/height to visualViewport when the keyboard opens */
  }

  body.drobo-chat-open {
    overscroll-behavior: none;
  }

  #drobo-chat-header {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }

  #drobo-messages {
    padding: 14px;
  }

  .drobo-msg {
    max-width: 94%;
    font-size: 15px;
  }

  #drobo-input-area {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  #drobo-chat-btn,
  #drobo-chat-window.open,
  .drobo-msg,
  .drobo-typing-dots span,
  #drobo-chat-header .drobo-live,
  .drobo-msg a.drobo-chat-link--cta {
    animation: none !important;
  }

  #drobo-close-btn:hover {
    transform: none;
  }
}
