/* ============================================
   CHAT WIDGET CONFIGURATION
   All colors, sizes, and styling in one place
   ============================================ */

/* Global scrollbar styling for consistency */
/* Webkit browsers (Chrome, Edge, Safari) */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: #f5f5f5;
  border-radius: 6px;
}

::-webkit-scrollbar-thumb {
  background-color: #c0c0c0;
  border-radius: 6px;
  border: 2px solid #f5f5f5;
  min-height: 40px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: #a0a0a0;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #c0c0c0 #f5f5f5;
}

/* Dark mode scrollbar (applies to page scrollbar when chat sidebar has dark theme) */
.chat-sidebar[data-chat-theme="dark"] ~ * ::-webkit-scrollbar-track,
body:has(.chat-sidebar[data-chat-theme="dark"]) ::-webkit-scrollbar-track {
  background: #2a2a2a;
}

.chat-sidebar[data-chat-theme="dark"] ~ * ::-webkit-scrollbar-thumb,
body:has(.chat-sidebar[data-chat-theme="dark"]) ::-webkit-scrollbar-thumb {
  background-color: #505050;
  border-color: #2a2a2a;
}

.chat-sidebar[data-chat-theme="dark"] ~ * ::-webkit-scrollbar-thumb:hover,
body:has(.chat-sidebar[data-chat-theme="dark"]) ::-webkit-scrollbar-thumb:hover {
  background-color: #707070;
}

/* Light Mode (default) */
.chat-wrapper,
.chat-sidebar {
  /* Brand Colors */
  --chat-primary-color: #854fff;
  --chat-secondary-color: #6b3fd4;
  --chat-accent-hover: #5a32b3;

  /* Background Colors */
  --chat-bg-color: #ffffff;
  --chat-input-bg: #ffffff;

  /* Text Colors */
  --chat-text-color: #333333;
  --chat-intro-text: #333333;

  /* Border Colors */
  --chat-border-color: #e5e7eb;
  --chat-input-border: color-mix(in srgb, var(--chat-primary-color) 50%, #e5e7eb);
  --chat-input-focus-border: var(--chat-primary-color);
  --chat-input-placeholder-opacity: 0.5;

  /* Message Bubble Colors */
  --chat-bubble-user-bg: #854fff;
  --chat-bubble-user-text: #ffffff;
  --chat-bubble-ai-bg: #ffffff;
  /* --chat-bubble-ai-border: #e5e7eb; */
  /* Derive AI border from primary color with subtle opacity */
  --chat-bubble-ai-border: color-mix(in srgb, var(--chat-primary-color) 40%, transparent);
  --chat-bubble-ai-text: #333333;

  /* Code Styling */
  --chat-code-bg: #2d2d2d;
  --chat-code-border: #404040;
  --chat-code-text: #e0e0e0;
  --chat-inline-code-bg: #f5f5f5;
  --chat-inline-code-border: #e0e0e0;
  --chat-inline-code-text: #d73a49;

  /* Link Colors */
  --chat-link-color: #854fff;
  --chat-link-hover: #6b3fd4;

  /* Scrollbar Colors */
  --chat-scrollbar-thumb: #c0c0c0;
  --chat-scrollbar-thumb-hover: #a0a0a0;
  --chat-scrollbar-track: #f5f5f5;

  /* Send Button Colors */
  --chat-send-btn-bg: #854fff;
  --chat-send-btn-icon: #ffffff;
  --chat-send-btn-disabled-bg: rgba(132, 79, 255, 0.846);
  --chat-send-btn-disabled-icon: rgb(204, 183, 255);

  /* Shadows */
  --chat-shadow: rgba(0, 0, 0, 0.1);
  --chat-sidebar-shadow: rgba(0, 0, 0, 0.1);

  /* Sizing */
  --chat-header-height: 2.4rem;
  --chat-border-radius: 10px;
  --chat-bubble-radius: 12px;
  --chat-input-radius: 8px;

  /* Font Sizes */
  --chat-font-size-base: 14px;
  --chat-font-size-intro-title: 24px;
  --chat-font-size-button: 16px;
  --chat-font-size-input: 14px;

  /* Spacing */
  --chat-bubble-padding: 12px 16px;
  --chat-input-padding: 8px 12px;
  --chat-button-padding: 14px 28px;
}

/* Dark Mode Variables */
.chat-wrapper[data-chat-theme="dark"],
.chat-sidebar[data-chat-theme="dark"] {
  /* Brand Colors */
  --chat-primary-color: #9d6fff;
  --chat-secondary-color: #7d4fd4;
  --chat-accent-hover: #8d5fe8;

  /* Background Colors */
  --chat-bg-color: #1e1e1e;
  --chat-input-bg: #2a2a2a;

  /* Text Colors */
  --chat-text-color: #ffffff;
  --chat-intro-text: #e0e0e0;

  /* Border Colors */
  --chat-border-color: #3a3a3a;
  --chat-input-border: color-mix(in srgb, var(--chat-primary-color) 50%, #3a3a3a);
  --chat-input-focus-border: var(--chat-primary-color);
  --chat-input-placeholder-opacity: 0.25;

  /* Message Bubble Colors */
  --chat-bubble-user-bg: #9d6fff;
  --chat-bubble-user-text: #ffffff;
  --chat-bubble-ai-bg: #2a2a2a;
  /* --chat-bubble-ai-border: #3a3a3a; */
  /* Derive AI border from primary color with subtle opacity */
  --chat-bubble-ai-border: color-mix(in srgb, var(--chat-primary-color) 50%, transparent);

  --chat-bubble-ai-text: #e0e0e0;

  /* Code Styling */
  --chat-code-bg: #1a1a1a;
  --chat-code-border: #404040;
  --chat-code-text: #e0e0e0;
  --chat-inline-code-bg: #2a2a2a;
  --chat-inline-code-border: #404040;
  --chat-inline-code-text: #ff6b9d;

  /* Link Colors */
  --chat-link-color: #9d6fff;
  --chat-link-hover: #b58fff;

  /* Scrollbar Colors */
  --chat-scrollbar-thumb: #505050;
  --chat-scrollbar-thumb-hover: #707070;
  --chat-scrollbar-track: #2a2a2a;

  /* Send Button Colors */
  --chat-send-btn-bg: #9d6fff;
  --chat-send-btn-icon: #ffffff;
  --chat-send-btn-disabled-bg: rgba(157, 111, 255, 0.85);
  --chat-send-btn-disabled-icon: rgb(195, 167, 255);

  /* Shadows */
  --chat-shadow: rgba(0, 0, 0, 0.3);
  --chat-sidebar-shadow: rgba(0, 0, 0, 0.3);
}

/* Chat header styles */
.chat-header {
  display: flex;
  align-items: center;
  height: var(--chat-header-height);
  padding: 0 0.8rem;
  background: linear-gradient(135deg, var(--chat-primary-color) 0%, var(--chat-secondary-color) 100%);
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.chat-header-logo {
  width: 1.6rem;
  height: 1.6rem;
  margin-right: 0.6rem;
  border-radius: 3px;
}

.chat-header-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
}

.chat-close-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  padding: 4px;
  margin-left: 12px; /* More space from theme toggle */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.theme-toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 28px;
  margin: 0 4px 0 0;
  cursor: pointer;
}

.theme-toggle-switch input[type="checkbox"] {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle-switch .theme-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.25);
  border-radius: 28px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 0;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

.theme-toggle-switch .theme-slider:before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  top: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  z-index: 1;
}

.theme-toggle-switch .theme-icon-light,
.theme-toggle-switch .theme-icon-dark {
  position: absolute;
  width: 16px;
  height: 16px;
  top: 6px;
  z-index: 2;
  transition: all 0.3s ease;
}

.theme-toggle-switch .theme-icon-light {
  left: 6px;
  color: #854fff;
  filter: drop-shadow(0 0 1px rgba(255,255,255,0.5));
}

.theme-toggle-switch .theme-icon-dark {
  right: 6px;
  color: rgba(255, 255, 255, 0.95);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}

.theme-toggle-switch input:checked + .theme-slider {
  background-color: rgba(255, 255, 255, 0.35);
}

.theme-toggle-switch input:checked + .theme-slider:before {
  transform: translateX(32px);
}

.theme-toggle-switch input:checked + .theme-slider .theme-icon-light {
  color: rgba(255, 255, 255, 0.95);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}

.theme-toggle-switch input:checked + .theme-slider .theme-icon-dark {
  color: #854fff;
  filter: drop-shadow(0 0 1px rgba(255,255,255,0.5));
}

.theme-toggle-switch:hover .theme-slider {
  background-color: rgba(255, 255, 255, 0.3);
}

.theme-toggle-switch input:checked + .theme-slider:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

/* Chat wrapper */
.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--chat-bg-color);
  transition: background 0.3s ease;
}

.chat-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--chat-bg-color);
}

/* Intro panel - positioned OUTSIDE shadow DOM as overlay */
.intro-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  box-sizing: border-box;
  background: var(--chat-bg-color);
  z-index: 10;
  pointer-events: all;
  transition: background 0.3s ease, opacity 0.3s ease;
}

.intro-panel h2 {
  margin: 0 0 20px 0;
  color: var(--chat-intro-text);
  font-size: var(--chat-font-size-intro-title);
  font-weight: 500;
  line-height: 1.4;
}

.intro-panel .start-chat-btn {
  background: var(--chat-primary-color);
  color: white;
  border: none;
  padding: var(--chat-button-padding);
  border-radius: var(--chat-border-radius);
  font-size: var(--chat-font-size-button);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px var(--chat-shadow);
}

.intro-panel .start-chat-btn:hover {
  background: var(--chat-secondary-color);
  box-shadow: 0 4px 12px var(--chat-shadow);
  transform: translateY(-1px);
}

.intro-panel .start-chat-btn:active {
  background: var(--chat-accent-hover);
  box-shadow: 0 2px 4px var(--chat-shadow);
  transform: translateY(0);
}

/* Floating button */
.chat-float-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #9d6fff;
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

/* Only apply hover effect on devices with hover capability (not touch screens) */
@media (hover: hover) and (pointer: fine) {
  .chat-float-btn:hover {
    background: #b58fff;
    transform: scale(1.1);
  }
}

/* Mobile chat popup */
.chat-mobile-popup {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 90vw;
  max-width: 400px;
  height: 500px;
  border-radius: 10px;
  box-shadow: 0 4px 12px var(--chat-shadow);
  z-index: 1000;
  display: none;
  overflow: hidden;
  background: var(--chat-bg-color);
}

/* Chat sidebar styles for desktop */
.chat-sidebar {
  position: fixed;
  top: var(--header-height, 64px); /* Dynamically set by JS */
  left: calc(-1 * var(--chat-sidebar-width, 400px)); /* Hidden off-screen */
  bottom: 0;
  width: 400px;
  background: var(--chat-bg-color);
  box-shadow: 2px 0 8px var(--chat-sidebar-shadow);
  z-index: 50; /* Below header (z-index: 100) */
  transition: left 0.3s ease, background 0.3s ease;
  display: none; /* Hidden by default, shown on desktop by JS */
}

.chat-sidebar.open {
  left: 0;
}

.chat-sidebar-resize-handle {
  position: absolute;
  right: -4px; /* Position mostly outside the sidebar, 1px overlap inside */
  top: 0;
  bottom: 0;
  width: 5px; /* Thin resize handle extending outside */
  cursor: ew-resize;
  background: transparent;
  transition: background 0.2s;
  z-index: 20; /* Above intro panel (z-index: 10) */
  pointer-events: all; /* Ensure it captures mouse events */
}

.chat-sidebar-resize-handle:hover,
.chat-sidebar-resize-handle.resizing {
  background: rgba(157, 111, 255, 0.5); /* Purple indicator on hover */
}

#chat-sidebar-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* Ensure Deep Chat wrapper takes full height */
#chat-sidebar-container > .chat-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Make main content adjust when sidebar is open */
.md-container {
  margin-left: 0;
}

body.chat-sidebar-open .md-container {
  margin-left: var(--chat-sidebar-width, 400px);
}

/* Smooth transition when toggling sidebar (not when resizing) */
body.chat-sidebar-transitioning .md-container {
  transition: margin-left 0.3s ease;
}

/* DokyAI Chat toggle button - flat design */
.chat-toggle-button-new {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 39px; /* Match search input height exactly */
  padding: 0 16px !important;
  margin-right: 8px;

  /* Flat solid color */
  background: #9d6fff;
  color: white !important;

  /* Subtle border */
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.1rem;

  /* Match search input font style */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17.5px;

  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;

  /* Minimal flat shadow */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-toggle-button-new:hover {
  background: #b58fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.chat-toggle-button-new:active {
  background: #854fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  transform: translateY(0);
}

.chat-toggle-button-new.active {
  background: #854fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.chat-toggle-button-new svg {
  width: 20px;  /* Bigger sparkle icon */
  height: 20px;
  flex-shrink: 0;
}

.chat-button-text {
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Old chat toggle button (deprecated) */
.chat-toggle-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.chat-toggle-button.active {
  background: rgba(0,0,0,0.05);
}

/* Mobile: hide sidebar and header button, use floating button */
@media screen and (max-width: 76.1875em) {
  .chat-sidebar {
    display: none !important;
  }

  body.chat-sidebar-open .md-container {
    margin-left: 0;
  }

  .chat-toggle-button-new {
    display: none !important;
  }
}
