/* MJLM Chat Widget - Slide-in Sidebar */

/* Theme-aware variables - monochrome */
:root {
  --mjlm-accent: #6B6B6B;
  --mjlm-accent-hover: #4A4A4A;
}

.dark .mjlm-sidebar,
.dark .mjlm-toggle {
  --mjlm-accent: #8A8A8A;
  --mjlm-accent-hover: #A0A0A0;
}

/* Light mode (default) */
.mjlm-sidebar,
.mjlm-toggle {
  --mjlm-bg: #FDFBF7;
  --mjlm-bg-secondary: #F0EEEB;
  --mjlm-text: #1A1A1A;
  --mjlm-text-muted: #6B6B6B;
  --mjlm-border: #E0DCD6;
  --mjlm-user-bg: #E8E6E3;
  --mjlm-assistant-bg: #FDFBF7;
}

/* Dark mode */
.dark .mjlm-sidebar,
.dark .mjlm-toggle {
  --mjlm-bg: #121212;
  --mjlm-bg-secondary: #1A1A1A;
  --mjlm-text: #E8E6E3;
  --mjlm-text-muted: #8A8A8A;
  --mjlm-border: #2A2A2A;
  --mjlm-user-bg: #2A2A2A;
  --mjlm-assistant-bg: #1A1A1A;
}

/* ============================================
   MICRO ANIMATIONS
   ============================================ */

/* Message entrance animation */
@keyframes mjlm-message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Slide in from right for sidebar */
@keyframes mjlm-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* Fade in animation */
@keyframes mjlm-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Staggered entrance */
@keyframes mjlm-stagger-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Loading dots bounce */
@keyframes mjlm-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Send button press effect */
@keyframes mjlm-press {
  0% { transform: scale(1); }
  50% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* ============================================
   TOGGLE BUTTON
   ============================================ */

.mjlm-toggle {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--mjlm-bg);
  border: 1px solid var(--mjlm-border);
  border-radius: 0;
  color: var(--mjlm-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease;
  font-family: inherit;
}

.mjlm-toggle:hover {
  border-color: var(--mjlm-text);
}

.mjlm-toggle:active {
  transform: scale(0.98);
}

.mjlm-toggle-icon {
  color: var(--mjlm-text-muted);
  font-size: 14px;
}

/* ============================================
   SIDEBAR PANEL
   ============================================ */

.mjlm-sidebar {
  position: fixed;
  top: 0;
  right: -400px;
  width: 380px;
  max-width: 100vw;
  height: 100vh;
  background: var(--mjlm-bg);
  border-left: 1px solid var(--mjlm-border);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: right 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.mjlm-sidebar.open {
  right: 0;
}

/* ============================================
   HEADER
   ============================================ */

.mjlm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--mjlm-border);
  background: var(--mjlm-bg);
}

.mjlm-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--mjlm-text);
}

.mjlm-title span {
  color: var(--mjlm-text-muted);
}

.mjlm-header-actions {
  display: flex;
  gap: 4px;
}

.mjlm-header-btn {
  background: none;
  border: none;
  color: var(--mjlm-text-muted);
  cursor: pointer;
  padding: 6px;
  font-size: 18px;
  transition: color 0.2s ease;
  border-radius: 0;
}

.mjlm-header-btn:hover {
  color: var(--mjlm-text);
}

.mjlm-header-btn:active {
  transform: scale(0.95);
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */

.mjlm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ============================================
   WELCOME STATE
   ============================================ */

.mjlm-welcome {
  padding: 20px 0;
  animation: mjlm-fade-in 0.4s ease-out;
}

.mjlm-welcome h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--mjlm-text);
  margin: 0 0 16px 0;
}

/* ============================================
   SUGGESTED QUESTIONS
   ============================================ */

.mjlm-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mjlm-suggestion {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  background: transparent;
  border: 1px solid var(--mjlm-border);
  border-radius: 0;
  color: var(--mjlm-text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease;
  animation: mjlm-stagger-in 0.4s ease-out backwards;
}

.mjlm-suggestion:nth-child(1) { animation-delay: 0.1s; }
.mjlm-suggestion:nth-child(2) { animation-delay: 0.2s; }
.mjlm-suggestion:nth-child(3) { animation-delay: 0.3s; }

.mjlm-suggestion:hover {
  border-color: var(--mjlm-text);
}

.mjlm-suggestion:active {
  transform: scale(0.99);
}

.mjlm-suggestion-icon {
  color: var(--mjlm-text-muted);
  flex-shrink: 0;
  font-size: 12px;
  margin-top: 2px;
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */

.mjlm-message {
  max-width: 90%;
  padding: 12px 16px;
  border-radius: 0;
  font-size: 14px;
  line-height: 1.6;
  animation: mjlm-message-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mjlm-message.user {
  align-self: flex-end;
  background: var(--mjlm-user-bg);
  color: var(--mjlm-text);
}

.mjlm-message.assistant {
  align-self: flex-start;
  background: var(--mjlm-assistant-bg);
  color: var(--mjlm-text);
  border: 1px solid var(--mjlm-border);
}

/* Markdown formatting in assistant messages */
.mjlm-message.assistant p {
  margin: 0 0 10px 0;
}

.mjlm-message.assistant p:last-child {
  margin-bottom: 0;
}

.mjlm-message.assistant strong {
  font-weight: 600;
}

.mjlm-message.assistant em {
  font-style: italic;
}

.mjlm-message.assistant ul,
.mjlm-message.assistant ol {
  margin: 8px 0;
  padding-left: 20px;
}

.mjlm-message.assistant li {
  margin: 4px 0;
}

.mjlm-message.assistant code {
  background: var(--mjlm-bg-secondary);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
}

/* ============================================
   SOURCES
   ============================================ */

.mjlm-sources {
  padding: 12px 16px;
  font-size: 12px;
  animation: mjlm-fade-in 0.4s ease-out 0.2s backwards;
}

.mjlm-sources-title {
  color: var(--mjlm-text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.mjlm-source-link {
  color: var(--mjlm-text);
  text-decoration: underline;
  text-decoration-color: var(--mjlm-text-muted);
  font-size: 13px;
  transition: text-decoration-color 0.2s ease;
}

.mjlm-source-link:hover {
  text-decoration-color: var(--mjlm-text);
}

/* ============================================
   LOADING STATE
   ============================================ */

.mjlm-loading {
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  align-self: flex-start;
  animation: mjlm-fade-in 0.3s ease-out;
}

.mjlm-loading-dot {
  width: 8px;
  height: 8px;
  background: var(--mjlm-text-muted);
  border-radius: 50%;
  animation: mjlm-bounce 1.2s infinite ease-in-out;
}

.mjlm-loading-dot:nth-child(1) { animation-delay: 0s; }
.mjlm-loading-dot:nth-child(2) { animation-delay: 0.15s; }
.mjlm-loading-dot:nth-child(3) { animation-delay: 0.3s; }

/* ============================================
   INPUT AREA
   ============================================ */

.mjlm-input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--mjlm-border);
  background: var(--mjlm-bg);
}

.mjlm-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
  position: relative;
}

.mjlm-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--mjlm-bg-secondary);
  border: 1px solid var(--mjlm-border);
  border-radius: 0;
  color: var(--mjlm-text);
  font-size: 14px;
  resize: none;
  font-family: inherit;
  max-height: 120px;
  transition: border-color 0.2s ease;
  caret-color: transparent;
}

.mjlm-input:focus {
  outline: none;
  border-color: var(--mjlm-text);
  background: var(--mjlm-bg);
}

.mjlm-input::placeholder {
  color: var(--mjlm-text-muted);
  transition: opacity 0.2s ease;
}

.mjlm-input:focus::placeholder {
  opacity: 0.6;
}

/* ============================================
   FANCY CARET
   ============================================ */

.mjlm-caret {
  position: absolute;
  width: 2px;
  height: 16px;
  background: var(--mjlm-text);
  border-radius: 1px;
  pointer-events: none;
  opacity: 0;
  transition: left 0.06s ease-out, opacity 0.15s ease;
  z-index: 5;
  top: 50%;
  transform: translateY(-50%);
}

.mjlm-caret.visible {
  opacity: 1;
  animation: mjlm-caret-blink 1s ease-in-out infinite;
}

.mjlm-caret-glow {
  display: none;
}

@keyframes mjlm-caret-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Mirror element for text measurement - must be invisible */
.mjlm-input-mirror {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  white-space: pre;
  font-size: 14px;
  pointer-events: none;
  height: 0;
  overflow: hidden;
}

/* ============================================
   SEND BUTTON
   ============================================ */

.mjlm-send {
  width: 36px;
  height: 36px;
  background: var(--mjlm-border);
  border: none;
  border-radius: 0;
  color: var(--mjlm-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  font-size: 16px;
}

/* When there's text - activate the button */
.mjlm-send.has-text {
  background: var(--mjlm-text);
  color: var(--mjlm-bg);
}

.mjlm-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mjlm-send.has-text:hover:not(:disabled) {
  opacity: 0.8;
}

.mjlm-send:active:not(:disabled) {
  animation: mjlm-press 0.15s ease-out;
}

/* ============================================
   FOLLOW-UP QUESTIONS
   ============================================ */

.mjlm-followups {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 4px;
}

.mjlm-followup {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  background: transparent;
  border: none;
  color: var(--mjlm-text-muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: color 0.2s ease;
  animation: mjlm-stagger-in 0.35s ease-out backwards;
}

.mjlm-followup:nth-child(1) { animation-delay: 0.15s; }
.mjlm-followup:nth-child(2) { animation-delay: 0.25s; }
.mjlm-followup:nth-child(3) { animation-delay: 0.35s; }

.mjlm-followup:hover {
  color: var(--mjlm-text);
}

.mjlm-followup::before {
  content: '\2192';
  color: var(--mjlm-text-muted);
  font-size: 12px;
  transition: color 0.2s ease;
}

.mjlm-followup:hover::before {
  color: var(--mjlm-text);
}

/* ============================================
   PUSH CONTENT WHEN SIDEBAR OPEN
   ============================================ */

/* Prevent horizontal scroll when sidebar open */
body.mjlm-open {
  overflow-x: hidden;
}

/* Target main content areas - PaperMod specific */
body.mjlm-open .main,
body.mjlm-open .header,
body.mjlm-open .footer {
  transform: translateX(-190px);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Ensure content has transition even when closing */
.main,
.header,
.footer {
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Hide toggle button when sidebar is open */
body.mjlm-open .mjlm-toggle {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-20px);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  /* Don't push content on tablets and below - overlay instead */
  body.mjlm-open .main,
  body.mjlm-open .header,
  body.mjlm-open .footer {
    transform: none;
  }

  /* Show toggle on mobile even when open */
  body.mjlm-open .mjlm-toggle {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
}

@media (max-width: 480px) {
  .mjlm-sidebar {
    width: 100vw;
    right: -100vw;
  }

  .mjlm-toggle {
    top: auto;
    bottom: 20px;
    right: 20px;
    padding: 10px 16px;
  }

  /* Mobile input area - prevent zoom and ensure visibility */
  .mjlm-input {
    font-size: 16px; /* Prevents iOS auto-zoom on focus */
    touch-action: manipulation; /* Prevents double-tap zoom */
  }

  .mjlm-input-area {
    position: sticky;
    bottom: 0;
    padding: 12px 12px 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom)); /* Handle iPhone notch */
    background: var(--mjlm-bg);
  }

  /* Ensure messages area shrinks properly when keyboard opens */
  .mjlm-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Larger touch targets on mobile */
  .mjlm-send {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .mjlm-header-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

.mjlm-messages::-webkit-scrollbar {
  width: 6px;
}

.mjlm-messages::-webkit-scrollbar-track {
  background: transparent;
}

.mjlm-messages::-webkit-scrollbar-thumb {
  background: var(--mjlm-border);
  border-radius: 3px;
  transition: background 0.2s ease;
}

.mjlm-messages::-webkit-scrollbar-thumb:hover {
  background: var(--mjlm-text-muted);
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .mjlm-toggle,
  .mjlm-toggle-icon,
  .mjlm-sidebar,
  .mjlm-message,
  .mjlm-suggestion,
  .mjlm-followup,
  .mjlm-loading-dot,
  .mjlm-send,
  .mjlm-header-btn {
    animation: none !important;
    transition: none !important;
  }
}
