/* ══════════════════════════════════════════════════════════════
   Vyakhya AI Reader Drawer & Floating Button Styles
   ══════════════════════════════════════════════════════════════ */

/* ── Floating "Explain with AI" Selection Button ── */
#vyakhya-floating-btn {
  position: absolute;
  z-index: 999999;
  display: none;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 30px;
  padding: 7px 16px;
  font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, filter 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  animation: vyakhyaPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

#vyakhya-floating-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 12px 30px rgba(139, 92, 246, 0.55), 0 4px 10px rgba(0, 0, 0, 0.3);
  filter: brightness(1.1);
}

#vyakhya-floating-btn:active {
  transform: translateY(0) scale(0.98);
}

#vyakhya-floating-btn .btn-sparkle {
  font-size: 14px;
  display: inline-block;
  animation: vyakhyaSpin 4s linear infinite;
}

@keyframes vyakhyaPop {
  from { opacity: 0; transform: scale(0.85) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes vyakhyaSpin {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(15deg); }
  75% { transform: rotate(-15deg); }
}

/* ── Backdrop Overlay ── */
#vyakhya-drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#vyakhya-drawer-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Sliding Side Drawer ── */
#vyakhya-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 440px;
  max-width: 94vw;
  height: 100vh;
  height: 100dvh;
  background: var(--t-bg-overlay, #0f172a);
  color: var(--t-text-primary, #f8fafc);
  border-left: 1px solid var(--t-border, rgba(255, 255, 255, 0.12));
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
  z-index: 1000001;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  box-sizing: border-box;
}

#vyakhya-drawer.open {
  transform: translateX(0);
}

/* ── Drawer Header ── */
.vyakhya-drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--t-border, rgba(255, 255, 255, 0.08));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.vyakhya-header-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.vyakhya-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(217, 70, 239, 0.25));
  border: 1px solid rgba(139, 92, 246, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.vyakhya-header-text {
  min-width: 0;
}

.vyakhya-header-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--t-accent, #a855f7);
  margin: 0;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.vyakhya-header-context {
  font-size: 11.5px;
  color: var(--t-text-muted, #94a3b8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.vyakhya-close-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--t-text-secondary, #94a3b8);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  line-height: 1;
}

.vyakhya-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

/* ── Selected Text Card ── */
.vyakhya-target-card {
  padding: 12px 18px;
  background: rgba(139, 92, 246, 0.06);
  border-bottom: 1px solid var(--t-border, rgba(255, 255, 255, 0.08));
  flex-shrink: 0;
}

.vyakhya-target-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.vyakhya-target-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #a855f7;
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.3);
  padding: 2px 7px;
  border-radius: 4px;
}

.vyakhya-copy-target-btn {
  background: none;
  border: none;
  color: var(--t-text-muted, #94a3b8);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s ease;
}

.vyakhya-copy-target-btn:hover {
  color: var(--t-accent, #a855f7);
}

.vyakhya-target-snippet {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--t-text-primary, #f1f5f9);
  max-height: 90px;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid var(--t-border, rgba(255, 255, 255, 0.06));
  font-style: italic;
}

/* ── Messages Chat Scroll Area ── */
.vyakhya-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  scroll-behavior: smooth;
}

/* Empty State Banner */
.vyakhya-empty-state {
  margin: auto;
  text-align: center;
  padding: 30px 20px;
  max-width: 320px;
}

.vyakhya-empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.85;
}

.vyakhya-empty-state-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--t-text-primary, #f8fafc);
  margin-bottom: 6px;
  font-family: 'Outfit', sans-serif;
}

.vyakhya-empty-state-desc {
  font-size: 13px;
  color: var(--t-text-muted, #94a3b8);
  line-height: 1.5;
}

/* Chat Messages */
.vyakhya-msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  animation: vyakhyaMsgFade 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes vyakhyaMsgFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.vyakhya-msg.user {
  align-self: flex-end;
  max-width: 85%;
}

.vyakhya-msg.user .vyakhya-bubble {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 16px 16px 2px 16px;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.25);
  word-break: break-word;
}

.vyakhya-msg.ai {
  align-self: flex-start;
  width: 100%;
}

.vyakhya-msg.ai .vyakhya-bubble {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--t-border, rgba(255, 255, 255, 0.08));
  color: var(--t-text-primary, #f8fafc);
  padding: 14px 16px;
  border-radius: 16px 16px 16px 2px;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  word-break: break-word;
}

/* Markdown styling inside AI bubble */
.vyakhya-bubble p {
  margin: 0 0 10px 0;
}
.vyakhya-bubble p:last-child {
  margin-bottom: 0;
}
.vyakhya-bubble strong {
  color: var(--t-accent, #a855f7);
  font-weight: 700;
}
.vyakhya-bubble em {
  font-style: italic;
  color: #cbd5e1;
}
.vyakhya-bubble h4, .vyakhya-bubble h3 {
  font-family: 'Outfit', sans-serif;
  color: var(--t-accent, #a855f7);
  font-size: 14px;
  font-weight: 700;
  margin: 12px 0 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 4px;
}
.vyakhya-bubble ul, .vyakhya-bubble ol {
  margin: 6px 0 10px 18px;
  padding: 0;
}
.vyakhya-bubble li {
  margin-bottom: 4px;
}
.vyakhya-bubble blockquote {
  border-left: 3px solid #8b5cf6;
  padding-left: 10px;
  margin: 8px 0;
  color: var(--t-text-secondary, #cbd5e1);
  font-style: italic;
}
.vyakhya-bubble code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
}

.vyakhya-msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--t-text-muted, #94a3b8);
}

.vyakhya-msg-actions {
  display: flex;
  gap: 8px;
}

.vyakhya-action-btn {
  background: none;
  border: none;
  color: var(--t-text-muted, #94a3b8);
  cursor: pointer;
  font-size: 11.5px;
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.vyakhya-action-btn:hover {
  color: var(--t-accent, #a855f7);
  background: rgba(255, 255, 255, 0.05);
}

/* Typing Indicator */
.vyakhya-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--t-border, rgba(255, 255, 255, 0.08));
  border-radius: 14px;
  width: fit-content;
}

.vyakhya-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a855f7;
  animation: vyakhyaBounce 1.4s infinite ease-in-out both;
}
.vyakhya-dot:nth-child(1) { animation-delay: -0.32s; }
.vyakhya-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes vyakhyaBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.vyakhya-typing-text {
  font-size: 12px;
  color: var(--t-text-muted, #94a3b8);
  margin-left: 4px;
}

/* ── Input Footer Area ── */
.vyakhya-drawer-footer {
  padding: 14px 18px 16px 18px;
  border-top: 1px solid var(--t-border, rgba(255, 255, 255, 0.08));
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.vyakhya-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--t-border, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  padding: 6px 10px 6px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.vyakhya-input-wrapper:focus-within {
  border-color: #a855f7;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}

.vyakhya-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--t-text-primary, #f8fafc);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  padding: 4px 0;
}

.vyakhya-textarea::placeholder {
  color: var(--t-text-muted, #64748b);
}

.vyakhya-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.vyakhya-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.vyakhya-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.vyakhya-send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.vyakhya-input-hint {
  font-size: 11px;
  color: var(--t-text-muted, #64748b);
  margin-top: 6px;
  text-align: right;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  #vyakhya-drawer {
    width: 100vw;
    max-width: 100vw;
    border-left: none;
  }
}
