/* Site-wide feedback widget: floating launcher + native <dialog> chat, plus the
   admin inbox at /admin/feedback. Page-scoped plain CSS (NOT in app.bundle.css),
   linked site-wide from base.html — so no Tailwind rebuild is needed. Self-
   contained custom classes only (no new Tailwind utilities). The chat body
   mirrors 22-chatbot.css; the shell is a native <dialog> (free focus-trap / Esc /
   backdrop, like the account modal). Accent is violet to stay distinct from the
   cyan English-chat and the site's own surfaces. */

:root { --fb-accent: 139, 92, 246; }  /* violet-500 */

/* ── Floating launcher (fixed, icon-only, deliberately understated) ─────────── */
.feedback-launcher {
  position: fixed;
  right: calc(1rem + env(safe-area-inset-right, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));   /* clear the home indicator */
  z-index: 60;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  border: 1px solid rgba(var(--fb-accent), 0.35);
  background: rgba(15, 23, 42, 0.78);
  color: #c4b5fd;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(6px);
  opacity: 0.78;
  transition: opacity 0.18s, transform 0.18s, background 0.18s, color 0.18s, box-shadow 0.18s;
}
.feedback-launcher:hover,
.feedback-launcher:focus-visible {
  opacity: 1;
  transform: translateY(-2px);
  background: rgba(var(--fb-accent), 0.92);
  color: #fff;
  box-shadow: 0 12px 30px rgba(var(--fb-accent), 0.35);
  outline: none;
}
.feedback-launcher svg { width: 1.4rem; height: 1.4rem; }
/* Drop the launcher a little on very short/tall mobile so it clears thumb-bars. */
@media (max-width: 640px) {
  .feedback-launcher {
    width: 2.85rem; height: 2.85rem;
    right: calc(0.85rem + env(safe-area-inset-right, 0px));
    bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }
}
@media (prefers-reduced-motion: reduce) {
  .feedback-launcher { transition: opacity 0.18s, background 0.18s, color 0.18s; }
  .feedback-launcher:hover, .feedback-launcher:focus-visible { transform: none; }
}

/* ── Dialog shell (native <dialog>; anchored bottom-right on desktop) ────────── */
.feedback-dialog {
  position: fixed;
  margin: 0;
  inset: auto 1rem 1rem auto;           /* bottom-right, near the launcher */
  width: min(400px, calc(100vw - 2rem));
  height: min(560px, calc(100dvh - 5rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 1rem;
  background: #0b1120;
  color: #e2e8f0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.feedback-dialog::backdrop {
  background: rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(2px);
}
.feedback-dialog:not([open]) { display: none; }

/* Inner layout: head / scrolling log / pinned input bar. */
.feedback-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.feedback-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.6rem 0.7rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.feedback-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #f1f5f9;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.feedback-title svg { width: 1.05rem; height: 1.05rem; color: rgb(var(--fb-accent)); }
.feedback-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  color: #94a3b8;
  background: transparent;
  border: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.feedback-close svg { width: 1.1rem; height: 1.1rem; }
.feedback-close:hover { background: rgba(255, 255, 255, 0.08); color: #e2e8f0; }

.feedback-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
}
.feedback-bubble {
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.9rem;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.feedback-user {
  align-self: flex-end;
  background: rgba(var(--fb-accent), 0.18);
  color: #ede9fe;
  border-bottom-right-radius: 0.25rem;
}
.feedback-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  border-bottom-left-radius: 0.25rem;
}
.feedback-typing { color: #94a3b8; animation: fb-pulse 1.2s ease-in-out infinite; }
@keyframes fb-pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

.feedback-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.feedback-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.8rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0f172a;
  color: #e2e8f0;
  resize: none;
}
.feedback-input:focus { outline: none; border-color: rgba(var(--fb-accent), 0.55); }
.feedback-input:disabled { opacity: 0.6; }
.feedback-send {
  flex-shrink: 0;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.55rem 1.1rem;
  border-radius: 0.6rem;
  border: 0;
  background: rgba(var(--fb-accent), 0.92);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}
.feedback-send:hover { background: rgb(var(--fb-accent)); }
.feedback-send:disabled { opacity: 0.5; cursor: not-allowed; }

.feedback-privacy {
  margin: 0;
  padding: 0 0.75rem 0.6rem;
  font-size: 0.7rem;
  color: #64748b;
  text-align: center;
  flex-shrink: 0;
}

/* Mobile: full-screen sheet; dvh keeps the input above the on-screen keyboard. */
@media (max-width: 640px) {
  .feedback-dialog {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
    /* Safe area: header clears the notch, the send row clears the home indicator. */
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .feedback-close, .feedback-send { transition: none; }
  .feedback-typing { animation: none; opacity: 0.7; }
}

/* ── Admin inbox (/admin/feedback) — uses the bundle's utilities for the page
      frame; these classes own the feedback-specific cards. ───────────────────── */
.fb-admin { max-width: 70rem; margin: 0 auto; }
.fb-panel { width: 100%; }
.fb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-bottom: 1.1rem;
}
.fb-counts { font-size: 0.85rem; color: #94a3b8; }
.fb-hide-cb { accent-color: rgb(var(--fb-accent)); width: 0.95rem; height: 0.95rem; cursor: pointer; margin-left: 0.4rem; }
.fb-hide-label { font-size: 0.82rem; color: #cbd5e1; cursor: pointer; user-select: none; }
/* "Hide resolved" — pure CSS via :has(); degrades to showing all if unsupported. */
.fb-panel:has(.fb-hide-cb:checked) .fb-card.is-resolved { display: none; }
.fb-card {
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 0.9rem;
  background: rgba(15, 23, 42, 0.55);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.fb-card.is-resolved { opacity: 0.62; }
.fb-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.9rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: #94a3b8;
}
.fb-who { font-weight: 600; color: #e2e8f0; }
.fb-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}
.fb-badge.new      { background: rgba(var(--fb-accent), 0.22); color: #ddd6fe; }
.fb-badge.resolved { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
.fb-url { color: #93c5fd; text-decoration: none; overflow-wrap: anywhere; }
.fb-url:hover { text-decoration: underline; }
.fb-body { display: grid; grid-template-columns: 1fr; gap: 0.9rem; }
@media (min-width: 720px) { .fb-body.has-shot { grid-template-columns: 1fr 13rem; } }
.fb-thread { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.fb-msg {
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 0.3rem 0.7rem;
  border-radius: 0.85rem;
  max-width: 80%;
  width: fit-content;
}
/* Chat layout: the student's messages sit on the right, the AI's on the left
   (align-self overrides the thread's default stretch so each bubble hugs its text). */
.fb-msg.user {
  align-self: flex-end;
  background: rgba(var(--fb-accent), 0.14);
  color: #ede9fe;
  border-bottom-right-radius: 0.2rem;
}
.fb-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  border-bottom-left-radius: 0.2rem;
}
.fb-shot { min-width: 0; }
.fb-shot a { display: block; }
.fb-shot img {
  width: 100%;
  height: auto;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.fb-ua { font-size: 0.7rem; color: #64748b; overflow-wrap: anywhere; }
.fb-actions { margin-top: 0.75rem; }
.fb-resolve {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.3rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: #cbd5e1;
  cursor: pointer;
}
.fb-resolve:hover { background: rgba(255, 255, 255, 0.10); }
.fb-empty { color: #94a3b8; padding: 2rem 0; text-align: center; }
