/* Chat Drawer - Desktop Mode Side Panel */

/* Drawer container (hidden on mobile) */
.chat-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-sheet-content);
  pointer-events: none;
  display: none;
  /* Hidden on mobile by default */
}

/* Show drawer only on desktop (1024px+) */
@media (min-width: 1024px) {
  .chat-drawer {
    display: block;
  }
}

.chat-drawer.open {
  pointer-events: all;
}

/* Overlay (darker background) */
.chat-drawer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.chat-drawer.open .chat-drawer-overlay {
  opacity: 1;
  pointer-events: all;
}

/* Drawer panel (slides in from right) */
.chat-drawer-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: 624px;
  max-width: 90vw;
  height: calc(100% / var(--zoom-factor, 0.9) - 32px);
  background: var(--brokerly-secondary-background);
  border: 1px solid var(--brokerly-border-medium);
  border-radius: 24px;
  box-shadow: -8px 8px 32px rgba(0, 0, 0, 0.12), 0 0 16px rgba(0, 0, 0, 0.05);
  transform: translateX(calc(100% + 20px));
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  overflow: visible; /* Allowed visible to let the halo behind the left edge glow outwards */
}

/* Force overflow: visible to override sheets.css overflow: hidden !important */
#chat-drawer.chat-drawer.right-side-panel .chat-drawer-panel {
  overflow: visible !important;
}

/* Inherit standard floating maximized layout from sheets.css */
.chat-drawer-panel::before {
  content: '';
  position: absolute;
  inset: -12px; /* Expand wider on all 4 sides to wrap the entire panel */
  background: linear-gradient(135deg,
    rgba(255, 111, 97, 0.7) 0%,
    rgba(255, 215, 0, 0.7) 20%,
    rgba(80, 200, 120, 0.7) 40%,
    rgba(0, 158, 217, 0.7) 60%,
    rgba(26, 127, 230, 0.7) 80%,
    rgba(255, 111, 97, 0.7) 100%
  );
  background-size: 200% 200%;
  opacity: 0;
  transition: opacity 0.5s ease, filter 0.5s ease;
  animation: gradient-flow-rect 15s ease infinite alternate, morph-halo 10s ease-in-out infinite alternate;
  box-shadow: 
    -12px -12px 30px rgba(255, 111, 97, 0.04),
    12px -12px 30px rgba(80, 200, 120, 0.04),
    12px 12px 30px rgba(0, 158, 217, 0.04),
    -12px 12px 30px rgba(255, 215, 0, 0.04);
  filter: blur(10px);
  z-index: -1; /* Placed beneath/behind the solid drawer background */
  pointer-events: none; /* Prevent interception of hover events */
  border-radius: 36px; /* Perfect contour matching: 24px panel border-radius + 12px inset */
}

.chat-drawer.open .chat-drawer-panel::before {
  opacity: 0.45; /* Much more transparent overall glow */
  filter: blur(14px); /* Higher blur to make the edges beautifully transparent */
  animation: gradient-flow-rect 12s ease infinite alternate, morph-halo-active 8s ease-in-out infinite alternate;
}

@keyframes gradient-flow-rect {
  0% {
    background-position: 0% 0%;
  }
  50% {
    background-position: 100% 100%;
  }
  100% {
    background-position: 0% 100%;
  }
}

@keyframes morph-halo {
  0% {
    transform: scale(1) translate(0, 0);
  }
  33% {
    transform: scale(1.002) translate(-0.3px, 0.2px);
  }
  66% {
    transform: scale(0.998) translate(0.3px, -0.2px);
  }
  100% {
    transform: scale(1.001) translate(0, 0);
  }
}

@keyframes morph-halo-active {
  0% {
    transform: scale(1.002) translate(0, 0);
  }
  33% {
    transform: scale(1.006) translate(-0.5px, 0.3px);
  }
  66% {
    transform: scale(0.996) translate(0.5px, -0.3px);
  }
  100% {
    transform: scale(1.003) translate(0, 0);
  }
}

@keyframes gradient-glow {
  0%, 100% {
    box-shadow:
      -15px -15px 35px rgba(255, 111, 97, 0.06),
      15px -15px 35px rgba(80, 200, 120, 0.06),
      15px 15px 35px rgba(0, 158, 217, 0.06),
      -15px 15px 35px rgba(255, 215, 0, 0.06);
  }
  50% {
    box-shadow:
      -15px 15px 35px rgba(255, 111, 97, 0.06),
      -15px -15px 35px rgba(80, 200, 120, 0.06),
      15px -15px 35px rgba(0, 158, 217, 0.06),
      15px 15px 35px rgba(255, 215, 0, 0.06);
  }
}

.chat-drawer.open .chat-drawer-panel {
  transform: translateX(0);
}

/* Drawer Header */
.chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  background: var(--brokerly-secondary-background);
  border-top-left-radius: 23px;
  border-top-right-radius: 23px;
}

.chat-drawer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-drawer-action-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--brokerly-text-secondary);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.chat-drawer-action-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--brokerly-text-primary);
}

.chat-drawer-action-btn.help-btn-prominent {
  background: rgba(var(--brokerly-primary-rgb), 0.1) !important;
  color: var(--brokerly-primary) !important;
  border: 1px solid rgba(var(--brokerly-primary-rgb), 0.25) !important;
  box-shadow: 0 2px 8px rgba(var(--brokerly-primary-rgb), 0.1) !important;
  width: auto !important;
  height: 34px !important;
  padding: 0 14px !important;
  border-radius: 17px !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  gap: 6px !important;
}

.chat-drawer-action-btn.help-btn-prominent:hover {
  background: var(--brokerly-primary) !important;
  color: white !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--brokerly-primary-rgb), 0.25) !important;
}

.chat-drawer-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-broker-avatar-small {
  position: relative;
  width: 52px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  padding: 2px;
  background: linear-gradient(135deg,
      #FF6B6B 0%,
      #FFD93D 12.5%,
      #6BCF7F 25%,
      #4D96FF 37.5%,
      #9D4EDD 50%,
      #FF6B9D 62.5%,
      #FFB347 75%,
      #7B68EE 87.5%,
      #FF6B6B 100%);
}

.avatar-circle-32 {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brokerly-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-circle-32 .avatar-initial {
  font-size: 16px;
  font-weight: 500;
  color: white;
}

.drawer-title-info {
  display: flex;
  flex-direction: column;
}

.drawer-title-info h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg,
    var(--sheet-title-color-1, #FF6B6B) 0%,
    var(--sheet-title-color-2, #FFD93D) 40%,
    var(--sheet-title-color-3, #4D96FF) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  background-size: 200% 200%;
  animation: sheet-title-shimmer 6s ease-in-out infinite alternate;
}

.drawer-subtitle {
  font-size: 13px;
  color: var(--brokerly-text-secondary);
  font-weight: 500;
}

/* Drawer Messages Area */
.chat-drawer-messages {
  flex: 1;
  overflow-y: auto;
  background: var(--brokerly-section-background);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Reuse message styles from chat-ios.css */
.chat-drawer-messages .message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

.chat-drawer-messages .user-message {
  flex-direction: row-reverse;
  margin-left: 40px;
}

.chat-drawer-messages .ai-message {
  flex-direction: column;
  align-items: flex-start;
  margin-right: 40px;
}

/* Comparison cards need the full panel width — remove the 40px margin */
.chat-drawer-messages .ai-message:has(.comparison-embedded) {
  margin-right: 0;
  max-width: 100%;
  width: fit-content;
}

.chat-drawer-messages .ai-message:has(.comparison-embedded) .message-bubble {
  max-width: 100% !important;
  width: fit-content !important;
  padding: 5px !important;
}

/* Allow message bubbles to expand more in the maximized state */
body .right-side-panel.maximized .chat-drawer-messages .message-bubble {
  width: fit-content;
  max-width: 85% !important;
  /* Fit content but cap at 85% for better readability */
}

/* Align User messages to the right in maximized mode */
body .right-side-panel.maximized .chat-drawer-messages .user-message {
  align-self: flex-end;
  margin-left: 100px;
  /* More breathing room on left */
  margin-right: 0;
}

/* Align AI messages to the left in maximized mode */
body .right-side-panel.maximized .chat-drawer-messages .ai-message {
  align-self: flex-start;
  margin-right: 100px;
  /* More breathing room on right */
  margin-left: 0;
}

/* Larger Avatars in Maximized Mode (48px) */
body .right-side-panel.maximized .user-avatar-small,
body .right-side-panel.maximized .ai-avatar-small {
  width: 48px !important;
  height: 48px !important;
}

body .right-side-panel.maximized .ai-broker-avatar-small {
  width: 64px !important;
  height: 44px !important;
  border-radius: 22px !important;
}

body .right-side-panel.maximized .avatar-circle-32 {
  width: 44px !important;
  height: 44px !important;
}

body .right-side-panel.maximized .avatar-circle-32 .avatar-initial {
  font-size: 20px !important;
}

body .right-side-panel.maximized .chat-drawer .user-avatar-small img,
body .right-side-panel.maximized .chat-drawer .ai-avatar-small img,
body .right-side-panel.maximized .chat-drawer .ai-message-avatar-img {
  width: 48px !important;
  height: 48px !important;
}

/* Ensure AI Charts expand naturally inside the wider panel */
body .right-side-panel.maximized .ai-chart-container {
  max-width: 100%;
  width: 100%;
}

/* Drawer Input Area */
.chat-drawer-input {
  background: var(--brokerly-secondary-background);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom-left-radius: 23px;
  border-bottom-right-radius: 23px;
}

.chat-drawer-input .input-divider {
  height: 0.5px;
  background: rgba(60, 60, 67, 0.29);
}

.chat-drawer-input .input-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.chat-drawer-input .text-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  height: 44px;
  background: var(--brokerly-input-background);
  border: 1px solid var(--brokerly-border-subtle);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chat-drawer-input .chat-text-input {
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 400;
  color: var(--brokerly-text-primary);
  outline: none;
  position: relative;
  z-index: 2;
}

.chat-drawer-input .chat-text-input::placeholder {
  color: var(--brokerly-text-tertiary);
}

/* Waveform Container - 24 bars (for voice input) */
.chat-drawer-input .waveform-container {
  position: absolute;
  left: 16px;
  right: 48px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  z-index: 1;
  pointer-events: none;
}

.chat-drawer-input .waveform-bar {
  flex: 1;
  background: var(--brokerly-primary);
  border-radius: 2px;
  min-height: 2px;
  transition: height 0.05s ease-out;
}

/* Clear Button - X icon */
.chat-drawer-input .clear-button {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--brokerly-text-tertiary);
  cursor: pointer;
  padding: 0;
  display: none;
  z-index: 2;
}

.chat-drawer-input .clear-button:hover {
  color: var(--brokerly-text-secondary);
}

/* Voice and Send Buttons */
.chat-drawer-input .voice-button,
.chat-drawer-input .send-button-ios {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  border: none;
  background: var(--brokerly-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-drawer-input .voice-button:hover,
.chat-drawer-input .send-button-ios:hover:not(:disabled) {
  background: var(--brokerly-primary-dark);
  transform: scale(1.05);
}

.chat-drawer-input .send-button-ios:disabled {
  background: var(--brokerly-text-tertiary);
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-drawer-input .voice-button.recording {
  background: #FF3B30;
  animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.05);
    opacity: 0.9;
  }
}

/* Smaller screens (tablets) */
@media (max-width: 1280px) and (min-width: 1024px) {
  .chat-drawer-panel {
    width: 520px !important;
  }
}

/* Very small desktop */
@media (max-width: 1024px) {
  .chat-drawer-panel {
    width: 468px !important;
  }
}

/* Mobile: Hide drawer completely */
@media (max-width: 1023px) {
  .chat-drawer {
    display: none !important;
  }
}

/* Smooth animations */
@media (prefers-reduced-motion: reduce) {

  .chat-drawer-panel,
  .chat-drawer-overlay {
    transition: none;
  }
}