/* ============================================================
   Derek AI Floating Chat Widget
   Global assistant — Intercom/ChatGPT-style floating chat bubble

   Design: 3-color discipline: cream (#fffef2) / dark (#191918) / gold (#FFB923)
   ============================================================ */

/* ============================================================
   1. FLOATING ACTION BUTTON (FAB)
   ============================================================ */

.dk-ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--df-accent, #FFB923);
  color: var(--dk-text-on-dark, #fffef2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(25, 25, 24, 0.25), 0 2px 6px rgba(25, 25, 24, 0.15);
  z-index: 400;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dk-ai-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(25, 25, 24, 0.3), 0 4px 12px rgba(25, 25, 24, 0.2);
}

.dk-ai-fab:active {
  transform: scale(0.98);
}

.dk-ai-fab i {
  line-height: 1;
}

/* Pulse animation on first load */
.dk-ai-fab--pulse {
  animation: dk-fab-pulse 2s ease-out 1;
}

@keyframes dk-fab-pulse {
  0% {
    box-shadow: 0 4px 16px rgba(25, 25, 24, 0.25), 0 2px 6px rgba(25, 25, 24, 0.15), 0 0 0 0 rgba(255, 185, 35, 0.4);
  }
  50% {
    box-shadow: 0 4px 16px rgba(25, 25, 24, 0.25), 0 2px 6px rgba(25, 25, 24, 0.15), 0 0 0 20px rgba(255, 185, 35, 0);
  }
  100% {
    box-shadow: 0 4px 16px rgba(25, 25, 24, 0.25), 0 2px 6px rgba(25, 25, 24, 0.15), 0 0 0 0 rgba(255, 185, 35, 0);
  }
}

/* Notification badge */
.dk-ai-fab-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dk-dark-1, #191918);
  border: 2px solid var(--df-accent, #FFB923);
  display: none;
}

.dk-ai-fab-badge--visible {
  display: block;
  animation: dk-badge-pop 0.3s ease-out;
}

@keyframes dk-badge-pop {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* Hide FAB when panel is open */
.dk-ai-fab--hidden {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

/* ============================================================
   2. FLOATING CHAT PANEL
   ============================================================ */

.dk-ai-float {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  max-height: min(600px, 70vh);
  background: var(--dk-bg-card, #ffffff);
  border: 1px solid var(--df-border, #e5e3d8);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(25, 25, 24, 0.15), 0 4px 16px rgba(25, 25, 24, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 401;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

/* Hidden state */
.dk-ai-float--hidden {
  opacity: 0;
  transform: scale(0.95) translateY(10px);
  pointer-events: none;
}

/* Visible state */
.dk-ai-float--visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ============================================================
   3. PANEL HEADER
   ============================================================ */

.dk-ai-float-header {
  background: var(--dk-dark-1, #191918);
  color: var(--dk-text-on-dark, #fffef2);
  padding: 16px 20px;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.dk-ai-float-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dk-ai-float-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--dk-text-on-dark, #fffef2);
}

.dk-ai-float-title i {
  color: var(--df-accent-text);
  font-size: 0.875rem;
}

.dk-ai-float-context {
  font-size: 0.6875rem;
  color: var(--dk-text-on-dark-muted, rgba(255, 254, 242, 0.6));
  font-weight: 500;
}

.dk-ai-float-close {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 254, 242, 0.1);
  color: var(--dk-text-on-dark, #fffef2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.15s ease;
  font-size: 14px;
}

.dk-ai-float-close:hover {
  background: rgba(255, 254, 242, 0.2);
}

/* ============================================================
   4. CHAT MESSAGES
   ============================================================ */

.dk-ai-float-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  min-height: 200px;
}

.dk-ai-float-messages::-webkit-scrollbar {
  width: 4px;
}

.dk-ai-float-messages::-webkit-scrollbar-track {
  background: transparent;
}

.dk-ai-float-messages::-webkit-scrollbar-thumb {
  background: var(--df-border, #e5e3d8);
  border-radius: 2px;
}

.dk-ai-float-messages::-webkit-scrollbar-thumb:hover {
  background: var(--df-border-3, #c9c7b8);
}

/* Message base */
.dk-ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  animation: dk-ai-msg-in 0.25s ease-out;
}

@keyframes dk-ai-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User message — right-aligned, dark */
.dk-ai-msg--user {
  align-self: flex-end;
  background: var(--dk-dark-1, #191918);
  color: var(--dk-text-on-dark, #fffef2);
  border-radius: 12px 12px 4px 12px;
}

/* AI message — left-aligned, light bg */
.dk-ai-msg--ai {
  align-self: flex-start;
  background: var(--df-bg-surface-2, #f8f7ee);
  color: var(--df-text-secondary, #4a4a47);
  border-radius: 12px 12px 12px 4px;
}

/* AI message label */
.dk-ai-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--df-accent-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.dk-ai-label i {
  font-size: 11px;
}

/* AI message content formatting */
.dk-ai-msg--ai strong {
  color: var(--df-text-primary, #191918);
  font-weight: 600;
}

.dk-ai-msg--ai p {
  margin: 0 0 8px;
}

.dk-ai-msg--ai p:last-child {
  margin-bottom: 0;
}

.dk-ai-msg--ai ul,
.dk-ai-msg--ai ol {
  margin: 8px 0;
  padding-left: 18px;
}

.dk-ai-msg--ai li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.dk-ai-msg--ai li:last-child {
  margin-bottom: 0;
}

.dk-ai-msg--ai code {
  font-family: var(--df-font-mono, 'JetBrains Mono', monospace);
  font-size: 0.75rem;
  background: var(--df-bg-elevated, #EFF0E5);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--df-text-primary, #191918);
  font-weight: 500;
}

/* Tables in AI responses */
.dk-ai-msg--ai table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 0.75rem;
}

.dk-ai-msg--ai td,
.dk-ai-msg--ai th {
  padding: 4px 8px;
  border: 1px solid var(--df-border-2, #dbd9ce);
}

.dk-ai-msg--ai th {
  background: var(--df-bg-elevated, #EFF0E5);
  font-weight: 600;
  color: var(--df-text-primary, #191918);
  text-align: left;
}

/* ============================================================
   5. TYPING INDICATOR
   ============================================================ */

.dk-ai-msg--typing {
  align-self: flex-start;
  background: var(--df-bg-surface-2, #f8f7ee);
  padding: 10px 14px;
  border-radius: 12px 12px 12px 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.dk-ai-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--df-accent, #FFB923);
  animation: dk-ai-pulse 1.2s ease-in-out infinite;
}

.dk-ai-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dk-ai-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dk-ai-pulse {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.9);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================
   6. SUGGESTED CHIPS
   ============================================================ */

.dk-ai-float-chips {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-top: 1px solid var(--df-border-2, #dbd9ce);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.dk-ai-float-chips::-webkit-scrollbar {
  display: none;
}

.dk-ai-chip {
  padding: 5px 12px;
  background: var(--df-bg-surface, #ffffff);
  border: 1px solid var(--df-border, #e5e3d8);
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
  color: var(--df-text-secondary, #4a4a47);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}

.dk-ai-chip:hover {
  background: var(--df-accent-subtle, rgba(255, 185, 35, 0.08));
  border-color: var(--df-accent, #FFB923);
  color: var(--df-accent-text);
}

.dk-ai-chip:active {
  transform: scale(0.97);
}

/* ============================================================
   7. INPUT AREA
   ============================================================ */

.dk-ai-float-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--df-border-2, #dbd9ce);
  background: var(--dk-bg-card, #ffffff);
  flex-shrink: 0;
}

.dk-ai-input {
  flex: 1;
  min-height: 36px;
  padding: 8px 12px;
  background: var(--df-bg-elevated, #EFF0E5);
  border: 1px solid var(--df-border, #e5e3d8);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--df-text-primary, #191918);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.dk-ai-input::placeholder {
  color: var(--df-text-muted, #8a8984);
}

.dk-ai-input:focus {
  border-color: var(--df-accent, #FFB923);
  box-shadow: 0 0 0 3px rgba(255, 185, 35, 0.15);
  background: var(--dk-bg-card, #ffffff);
}

.dk-ai-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--df-accent, #FFB923);
  color: var(--dk-text-on-dark, #fffef2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.dk-ai-send i {
  font-size: 14px;
}

.dk-ai-send:hover {
  background: var(--df-accent-dim, #E8A41C);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 185, 35, 0.3);
}

.dk-ai-send:active {
  transform: translateY(0);
}

.dk-ai-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ============================================================
   8. RESPONSIVE: MOBILE FULL-WIDTH
   ============================================================ */

@media (max-width: 768px) {
  .dk-ai-float {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 80vh;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
  }

  .dk-ai-float-header {
    border-radius: 12px 12px 0 0;
  }

  .dk-ai-float--hidden {
    transform: translateY(100%);
  }

  .dk-ai-float--visible {
    transform: translateY(0);
  }

  .dk-ai-fab {
    bottom: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    font-size: 20px;
  }
}

/* ============================================================
   9. PRINT STYLES
   ============================================================ */

@media print {
  .dk-ai-fab,
  .dk-ai-float {
    display: none !important;
  }
}

/* ============================================================
   10. REDUCED MOTION
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .dk-ai-fab,
  .dk-ai-float,
  .dk-ai-msg,
  .dk-ai-chip {
    animation: none;
    transition: none;
  }

  .dk-ai-typing-dot {
    animation: none;
    opacity: 0.6;
  }

  .dk-ai-fab--pulse {
    animation: none;
  }

  .dk-ai-fab-badge--visible {
    animation: none;
  }
}

/* ============================================================
   END OF FILE
   ============================================================ */
