/* ============================================================
   DigitalKiddo™ Maths — Kiddo Coach Chat
   ------------------------------------------------------------
   Two concerns live here:
   1. The floating "Kiddo Coach" button (.kiddo-coach-fab) — this
      file is included on every auth-gated page purely for the FAB.
      All .chat-* rules are scoped to chat.html and are inert
      elsewhere because those elements do not exist on other pages.
   2. The full-screen chat page layout (body.chat-page + .chat-*).
   ============================================================ */

/* ── FLOATING ACTION BUTTON (all auth-gated pages) ───────────── */
.kiddo-coach-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary, #6c63ff);
  color: #fff;
  border-radius: 50px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}
.kiddo-coach-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(108, 99, 255, 0.45);
}
/* On phones, show a larger round icon button — a big, easy-to-tap target
   that won't overlap game UI the way the full pill would. */
@media (max-width: 480px) {
  .kiddo-coach-fab {
    gap: 0;
    width: 64px;
    height: 64px;
    padding: 0;
    justify-content: center;
    font-size: 1.85rem;          /* bigger 🤖 icon */
    line-height: 1;
    bottom: 20px;
    right: 20px;
    box-shadow: 0 6px 22px rgba(108, 99, 255, 0.45);
  }
  .kiddo-coach-fab span { display: none; }
}

/* ── CHAT PAGE LAYOUT ─────────────────────────────────────────── */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;         /* fallback */
  height: 100dvh;        /* dynamic viewport height — fills phone screen */
  background: var(--bg, #f8f9ff);
  overflow: hidden;
}

/* ── TOP BAR ──────────────────────────────────────────────────── */
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
  z-index: 10;
}
.chat-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #f1f3f5;
  color: #333;
  text-decoration: none;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background 0.2s;
}
.chat-back-btn:hover { background: #e2e6ea; }
.chat-topbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.chat-avatar-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}
.chat-topbar-name {
  font-weight: 700;
  font-size: 1rem;
  color: #1a1a2e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-topbar-status {
  font-size: 0.75rem;
  color: #40c057;
  font-weight: 500;
}
.chat-topbar-user {
  font-size: 0.8rem;
  font-weight: 600;
  color: #6c63ff;
  background: #f0eeff;
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── CHAT WINDOW ──────────────────────────────────────────────── */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* ── BUBBLES ──────────────────────────────────────────────────── */
.chat-bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: chatFadeUp 0.25s ease;
}
@keyframes chatFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ai-row   { justify-content: flex-start; }
.user-row { justify-content: flex-end;   }
.chat-bubble-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: #f1f3f5;
}
.user-avatar {
  background: #6c63ff;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}
.chat-bubble {
  max-width: min(75%, 540px);
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.55;
  word-break: break-word;
}
.ai-bubble {
  background: #fff;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
}
.user-bubble {
  background: #6c63ff;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble strong { font-weight: 700; }
.chat-bubble em { font-style: italic; }

/* ── TYPING INDICATOR ─────────────────────────────────────────── */
.typing-bubble {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
}
.dot {
  width: 8px;
  height: 8px;
  background: #adb5bd;
  border-radius: 50%;
  animation: chatBounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatBounce {
  0%, 80%, 100% { transform: scale(0.85); opacity: 0.5; }
  40%           { transform: scale(1.15); opacity: 1;   }
}

/* ── QUICK PROMPT CHIPS ───────────────────────────────────────── */
.chat-chips-bar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid #f1f3f5;
}
/* Friendly guiding label for kids & parents */
.chat-chips-hint {
  font-size: 0.72rem;
  font-weight: 700;
  color: #8a93a3;
  letter-spacing: 0.2px;
  padding-left: 2px;
}
/* Horizontal scroller (chips live here) */
.chat-chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  padding: 2px 30px 4px 0; /* right room so the last chip clears the fade */
}
.chat-chips-row::-webkit-scrollbar { display: none; }
/* Right-edge fade — a clear "swipe for more →" affordance */
.chat-chips-bar::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 8px;
  width: 38px;
  height: 46px;
  pointer-events: none;
  background: linear-gradient(to right, rgba(255, 255, 255, 0), #fff);
}
.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 22px;
  border: 2px solid #c9c4ff;
  background: #f0eeff;
  color: #5a52d5;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.18s, filter 0.18s;
  flex-shrink: 0;
  scroll-snap-align: start;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.chat-chip:hover  { filter: brightness(0.97); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10); transform: translateY(-1px); }
.chat-chip:active { transform: scale(0.93); }
.chat-chip:focus-visible { outline: 3px solid #6c63ff; outline-offset: 2px; }

/* Playful category colours — fun for kids, easy to tell apart for parents */
.chip-help      { background: #e7f0ff; border-color: #9cc2ff; color: #2563eb; }
.chip-practice  { background: #e6f9ee; border-color: #86e0aa; color: #15924e; }
.chip-fractions { background: #ffe9f0; border-color: #ffa6c4; color: #d6336c; }
.chip-challenge { background: #fff4e0; border-color: #ffce85; color: #d98200; }
.chip-easier    { background: #e4faf7; border-color: #8ce0d4; color: #0f9b8a; }
.chip-fun       { background: #f0eaff; border-color: #c3a6ff; color: #7a3ff0; }
.chip-test      { background: #e6f6ff; border-color: #8ad4f5; color: #0b86c2; }
.chip-confused  { background: #fff0e6; border-color: #ffb98a; color: #e8590c; }

/* ── INPUT ROW ────────────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px 14px;
  background: #fff;
  border-top: 1px solid #e9ecef;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1.5px solid #dee2e6;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  font-family: inherit;
  outline: none;
  background: #f8f9ff;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s;
}
.chat-input:focus { border-color: #6c63ff; background: #fff; }
.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #6c63ff;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}
.chat-send-btn:hover  { background: #5a52d5; transform: scale(1.08); }
.chat-send-btn:active { transform: scale(0.95); }
.chat-send-btn:disabled { background: #adb5bd; cursor: not-allowed; transform: none; }

/* ── RESPONSIVE ───────────────────────────────────────────────── */
/* Tablet (≥ 600px) */
@media (min-width: 600px) {
  .chat-window    { padding: 20px 24px; }
  .chat-input-row { padding: 12px 24px 16px; }
  .chat-chips-bar { padding: 10px 24px; }
  .chat-topbar    { padding: 14px 24px; }
}
/* Desktop (≥ 960px) — constrain to a chat-column */
@media (min-width: 960px) {
  .chat-page { align-items: center; background: #eef0ff; }
  .chat-topbar,
  .chat-window,
  .chat-chips-bar,
  .chat-input-row {
    width: 100%;
    max-width: 720px;
  }
  .chat-topbar {
    border-radius: 16px 16px 0 0;
    margin-top: 24px;
  }
  .chat-input-row {
    border-radius: 0 0 16px 16px;
    margin-bottom: 24px;
  }
  .chat-window {
    background: #fff;
    min-height: 0;
  }
  .chat-chips-bar { background: #fafafa; }
  /* Keep the swipe fade matching the desktop chips background */
  .chat-chips-bar::after { background: linear-gradient(to right, rgba(250, 250, 250, 0), #fafafa); }
}
