/* ============================================================
   ScienceEd AI Feedback Panel — Glass-panel styling
   ============================================================ */

/* ── Wrapper & panel container ────────────────────────────── */

#ai-feedback-wrapper {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}

#ai-feedback-wrapper * {
  pointer-events: auto;
}

/* ── Slide-in panel ──────────────────────────────────────── */

#ai-feedback-panel {
  width: 380px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(77, 166, 255, 0.2);
  border-radius: 16px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: #f1f5f9;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  transform: translateX(120%) translateY(0);
  opacity: 0;
  transition: transform 300ms cubic-bezier(0.25, 0.1, 0.25, 1),
              opacity 250ms ease-out;
  overflow: hidden;
}

#ai-feedback-panel.open {
  transform: translateX(0) translateY(0);
  opacity: 1;
}

/* ── Panel header ────────────────────────────────────────── */

#ai-feedback-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  flex-shrink: 0;
}

.ai-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4da6ff;
  box-shadow: 0 0 6px rgba(77, 166, 255, 0.5);
  flex-shrink: 0;
  animation: ai-pulse 2s infinite ease-in-out;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

#ai-feedback-header .ai-indicator-label {
  flex: 1;
  font-weight: 600;
  font-size: 0.8125rem;
  color: #e2e8f0;
  letter-spacing: 0.01em;
}

#ai-feedback-close {
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.125rem 0.375rem;
  border-radius: 6px;
  line-height: 1;
  transition: color 150ms, background 150ms;
}

#ai-feedback-close:hover {
  color: #f1f5f9;
  background: rgba(148, 163, 184, 0.15);
}

/* ── Panel body / scrollable content ─────────────────────── */

#ai-feedback-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 60px;
}

#ai-feedback-body::-webkit-scrollbar {
  width: 4px;
}

#ai-feedback-body::-webkit-scrollbar-track {
  background: transparent;
}

#ai-feedback-body::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 2px;
}

/* ── Feedback content ────────────────────────────────────── */

#ai-feedback-content {
  font-size: 0.875rem;
  line-height: 1.6;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Hint type badges */

.ai-hint-badge {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.ai-hint-badge.hint     { background: rgba(77, 166, 255, 0.2); color: #4da6ff; }
.ai-hint-badge.suggestion { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.ai-hint-badge.explanation { background: rgba(52, 211, 153, 0.2); color: #34d399; }
.ai-hint-badge.correction  { background: rgba(248, 113, 113, 0.2); color: #f87171; }
.ai-hint-badge.encouragement { background: rgba(129, 140, 248, 0.2); color: #818cf8; }

/* ── Source & latency meta ───────────────────────────────── */

#ai-feedback-meta {
  margin-top: 0.5rem;
  font-size: 0.6875rem;
  color: #64748b;
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ── Rating row ──────────────────────────────────────────── */

#ai-feedback-rating {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

#ai-feedback-rating.hidden {
  display: none;
}

#ai-feedback-rating .rating-label {
  font-size: 0.75rem;
  color: #64748b;
  margin-right: 0.25rem;
}

.rating-btn {
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 8px;
  padding: 0.375rem 0.625rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 150ms, border-color 150ms, transform 100ms;
  line-height: 1;
}

.rating-btn:hover {
  background: rgba(148, 163, 184, 0.2);
  border-color: rgba(148, 163, 184, 0.3);
  transform: scale(1.1);
}

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

.rating-btn.selected-up {
  background: rgba(52, 211, 153, 0.2);
  border-color: #34d399;
}

.rating-btn.selected-down {
  background: rgba(248, 113, 113, 0.2);
  border-color: #f87171;
}

.rating-thanks {
  font-size: 0.75rem;
  color: #34d399;
  animation: fade-in 200ms ease-out;
}

/* ── Loading state ───────────────────────────────────────── */

#ai-feedback-loading {
  display: none;
  align-items: center;
  gap: 0.625rem;
  color: #64748b;
  font-size: 0.8125rem;
}

#ai-feedback-loading.visible {
  display: flex;
}

.ai-loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(77, 166, 255, 0.2);
  border-top-color: #4da6ff;
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
}

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Empty / welcome state ───────────────────────────────── */

#ai-feedback-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0;
  color: #64748b;
  text-align: center;
}

#ai-feedback-welcome .welcome-icon {
  font-size: 1.5rem;
  opacity: 0.5;
}

#ai-feedback-welcome .welcome-text {
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* ── Floating toggle button ──────────────────────────────── */

#ai-feedback-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(77, 166, 255, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  color: #4da6ff;
  transition: transform 200ms, box-shadow 200ms;
}

#ai-feedback-toggle.visible {
  display: flex;
}

#ai-feedback-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(77, 166, 255, 0.2);
}

#ai-feedback-toggle:active {
  transform: scale(0.95);
}

#ai-feedback-toggle .ai-indicator-dot {
  width: 6px;
  height: 6px;
}

/* ── Toast notification for new feedback ─────────────────── */

#ai-feedback-toast {
  position: fixed;
  bottom: calc(1.5rem + 56px);
  right: 1.5rem;
  z-index: 9998;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(77, 166, 255, 0.2);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  color: #e2e8f0;
  font-size: 0.8125rem;
  max-width: 320px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transform: translateY(20px);
  opacity: 0;
  transition: transform 250ms ease-out, opacity 200ms ease-out;
  display: none;
}

#ai-feedback-toast.open {
  transform: translateY(0);
  opacity: 1;
  display: block;
  animation: toast-slide-in 300ms ease-out forwards;
}

@keyframes toast-slide-in {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#ai-feedback-toast .toast-header {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 600;
  font-size: 0.75rem;
  color: #4da6ff;
  margin-bottom: 0.25rem;
}

#ai-feedback-toast .toast-preview {
  color: #94a3b8;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ── Error state ─────────────────────────────────────────── */

#ai-feedback-error {
  display: none;
  padding: 0.75rem;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 0.8125rem;
}

#ai-feedback-error.visible {
  display: block;
}

/* ── Mobile responsive: full-width bottom sheet ──────────── */

@media (max-width: 640px) {
  #ai-feedback-wrapper {
    right: 0;
    bottom: 0;
    left: 0;
  }

  #ai-feedback-panel {
    width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    transform: translateY(100%);
    opacity: 1;
  }

  #ai-feedback-panel.open {
    transform: translateY(0);
  }

  #ai-feedback-toggle {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
  }

  #ai-feedback-toast {
    right: 1rem;
    left: 1rem;
    max-width: none;
  }
}
