/* ============================================
   chat.css — Component Styles
   Math Tutor | Glassmorphism UI
   ============================================ */

/* ─── Background Orbs ───────────────────────── */
.orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(1px);
}

.orb-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(124, 111, 255, 0.15), transparent 70%);
  top: -200px;
  left: -200px;
  animation: float 8s ease-in-out infinite;
}

.orb-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(0, 217, 255, 0.10), transparent 70%);
  bottom: -150px;
  right: -150px;
  animation: float 10s ease-in-out infinite reverse;
}

.orb-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(124, 111, 255, 0.08), transparent 70%);
  top: 40%;
  left: 40%;
  animation: float 12s ease-in-out infinite;
  animation-delay: -4s;
}

/* ─── App Shell ─────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ─── Header ────────────────────────────────── */
#header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-base);
}

#hamburger:hover {
  background: var(--glass-hover);
}

#hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: transform var(--transition-base), opacity var(--transition-base);
}

#hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#hamburger.open span:nth-child(2) { opacity: 0; }
#hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.logo {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Question Counter */
#question-counter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 5px 12px;
  border-radius: 20px;
  transition: color var(--transition-base), border-color var(--transition-base);
}

#question-counter.warning {
  color: var(--warning);
  border-color: rgba(255, 170, 0, 0.3);
}

#question-counter.danger {
  color: var(--error);
  border-color: rgba(255, 68, 102, 0.3);
}

.counter-icon { font-size: 0.9rem; }

/* Session Timer */
#session-timer {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  transition: color var(--transition-base);
}

#session-timer.warning { color: var(--warning); }
#session-timer.danger  {
  color: var(--error);
  animation: pulse 1.2s ease-in-out infinite;
}

/* ─── Body Layout ───────────────────────────── */
#body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ─── Sidebar ───────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  height: 100%;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: rgba(10, 10, 26, 0.6);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform var(--transition-slow), opacity var(--transition-slow);
  z-index: 50;
}

.sidebar-top {
  padding: 16px;
  border-bottom: 1px solid var(--glass-border);
}

#new-chat-btn {
  width: 100%;
  padding: 11px 16px;
  background: var(--accent-gradient);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
  box-shadow: 0 4px 16px rgba(124, 111, 255, 0.25);
}

#new-chat-btn:hover {
  opacity: 0.9;
  transform: scale(1.02);
  box-shadow: 0 6px 24px rgba(124, 111, 255, 0.4);
}

#new-chat-btn:active {
  transform: scale(0.98);
}

.sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.history-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 16px 6px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition-fast);
  border-left: 3px solid transparent;
  position: relative;
}

.history-item:hover {
  background: var(--glass-hover);
}

.history-item:hover .delete-btn {
  opacity: 1;
}

.history-item.active {
  border-left-color: var(--accent-primary);
  background: rgba(124, 111, 255, 0.08);
}

.history-item-text {
  flex: 1;
  min-width: 0;
}

.history-item-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.history-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.delete-btn {
  opacity: 0;
  padding: 4px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
  font-size: 0.8rem;
}

.delete-btn:hover {
  color: var(--error);
  background: rgba(255, 68, 102, 0.1);
}

/* Sidebar overlay (mobile) */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 49;
  backdrop-filter: blur(4px);
}

/* ─── Chat Area ─────────────────────────────── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ─── Messages Container ─────────────────────── */
#messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* ─── Welcome Card ───────────────────────────── */
#welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: 40px 24px;
}

.welcome-inner {
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
}

.welcome-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  display: block;
}

.welcome-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-sub {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 28px;
  line-height: 1.5;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.chip {
  padding: 8px 16px;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  background: var(--glass-bg);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
}

.chip:hover {
  background: rgba(124, 111, 255, 0.15);
  border-color: rgba(124, 111, 255, 0.4);
  transform: scale(1.02);
}

.chip:active {
  transform: scale(0.98);
}

/* ─── Message Bubbles ───────────────────────── */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: slideUp 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.message-row.user  { justify-content: flex-end; }
.message-row.ai    { justify-content: flex-start; }

.emotion-avatar {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-bottom: 4px;
  order: 1;
}

.message-row.user .emotion-avatar { order: 2; }

.bubble {
  max-width: 70%;
  padding: 14px 18px;
  position: relative;
}

/* User bubble */
.bubble.user-bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(124, 111, 255, 0.3);
  border-radius: 16px 4px 16px 16px;
  max-width: 70%;
  text-align: right;
}

/* AI bubble */
.bubble.ai-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--glass-border);
  border-radius: 4px 16px 16px 16px;
  max-width: 80%;
}

.bubble-sender {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-primary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bubble-text {
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.bubble-text code,
.bubble-text .math-inline {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  background: rgba(124, 111, 255, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--accent-secondary);
}

.bubble-text .math-block {
  font-family: var(--font-mono);
  display: block;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 10px 0;
  overflow-x: auto;
  font-size: 0.9rem;
  color: var(--accent-secondary);
  text-align: left;
}

.bubble-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 6px;
  display: block;
}

.bubble.user-bubble .bubble-time { text-align: right; }

/* ─── Skeleton Loader ───────────────────────── */
.skeleton-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: fadeIn 200ms 200ms ease both;
}

.skeleton-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.05) 25%,
    rgba(255,255,255,0.12) 50%,
    rgba(255,255,255,0.05) 75%
  );
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite linear;
  flex-shrink: 0;
}

.skeleton-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--glass-border);
  border-radius: 4px 16px 16px 16px;
  padding: 16px 18px;
  width: min(380px, 70vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.05) 25%,
    rgba(255,255,255,0.12) 50%,
    rgba(255,255,255,0.05) 75%
  );
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite linear;
}

.skeleton-line:nth-child(1) { width: 85%; }
.skeleton-line:nth-child(2) { width: 100%; animation-delay: 0.1s; }
.skeleton-line:nth-child(3) { width: 60%; animation-delay: 0.2s; }

/* ─── Typing Indicator ───────────────────────── */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: pulse 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ─── Input Section ─────────────────────────── */
#input-section {
  flex-shrink: 0;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--glass-border);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: rgba(10, 10, 26, 0.5);
}

/* Emotion Selector */
#emotion-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.emotion-pill {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  gap: 5px;
}

.emotion-pill:hover {
  background: var(--glass-hover);
  color: var(--text-primary);
}

.emotion-pill.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 12px rgba(124, 111, 255, 0.3);
}

/* Input Row */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.input-row:focus-within {
  border-color: rgba(124, 111, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 111, 255, 0.1);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.5;
  resize: none;
  min-height: 22px;
  max-height: 110px;
  overflow-y: auto;
  padding: 0;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

/* PDF Upload */
#pdf-btn {
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-base), background var(--transition-base);
  flex-shrink: 0;
}

#pdf-btn:hover {
  color: var(--text-primary);
  background: var(--glass-hover);
}

#pdf-input { display: none; }

.pdf-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(124, 111, 255, 0.12);
  border: 1px solid rgba(124, 111, 255, 0.25);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--accent-primary);
  margin-bottom: 8px;
  animation: slideUp 200ms ease forwards;
}

.pdf-chip-remove {
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.pdf-chip-remove:hover {
  color: var(--error);
}

/* Send Button */
#send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: transform var(--transition-base), box-shadow var(--transition-base), opacity var(--transition-base);
  box-shadow: 0 4px 16px rgba(124, 111, 255, 0.3);
}

#send-btn:hover:not(:disabled) {
  transform: scale(1.07);
  box-shadow: 0 6px 24px rgba(124, 111, 255, 0.5);
  animation: glowPulse 1.5s ease-in-out infinite;
}

#send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  animation: none;
}

#send-btn .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Modals ─────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 300ms ease forwards;
}

.modal-overlay.hidden { display: none; }

.modal-card {
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: rgba(15, 15, 45, 0.9);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  animation: bounceIn 400ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-icon { font-size: 3rem; margin-bottom: 16px; display: block; }
.modal-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.modal-body {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 28px;
  line-height: 1.6;
}

.modal-btn {
  padding: 12px 28px;
  background: var(--accent-gradient);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
  box-shadow: 0 4px 20px rgba(124, 111, 255, 0.35);
}

.modal-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 28px rgba(124, 111, 255, 0.5);
}

/* ─── Toast Notifications ───────────────────── */
#toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(15, 15, 45, 0.95);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-size: 0.85rem;
  color: var(--text-primary);
  white-space: nowrap;
  animation: toastIn 300ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success { border-color: rgba(0, 255, 136, 0.3); }
.toast.warning { border-color: rgba(255, 170, 0, 0.3); }
.toast.error   { border-color: rgba(255, 68, 102, 0.3); }
.toast.exit    { animation: toastOut 300ms ease forwards; }

/* ─── Limit Reached Banner ───────────────────── */
#limit-banner {
  display: none;
  background: rgba(255, 68, 102, 0.08);
  border: 1px solid rgba(255, 68, 102, 0.25);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin: 0 24px 8px;
  font-size: 0.85rem;
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: slideUp 250ms ease forwards;
}

#limit-banner.hidden { display: none !important; }

#limit-banner-btn {
  padding: 6px 14px;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-base);
}

#limit-banner-btn:hover { opacity: 0.85; }

/* ─── KaTeX Overrides ───────────────────────── */
.katex {
  font-size: 1em;
  color: var(--text-primary);
}

.katex-display {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 10px 0;
  overflow-x: auto;
}

/* ─── Responsive — Tablet ───────────────────── */
@media (max-width: 1024px) {
  #hamburger { display: flex; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
    z-index: 50;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-overlay { display: block; }
  #sidebar-overlay.hidden { display: none; }

  .bubble.user-bubble { max-width: 80%; }
}

/* ─── Responsive — Mobile ───────────────────── */
@media (max-width: 768px) {
  #messages-wrap { padding: 16px 16px 8px; }
  #input-section { padding: 10px 16px 14px; }

  #emotion-selector {
    flex-wrap: wrap;
    gap: 6px;
  }

  .bubble.user-bubble,
  .bubble.ai-bubble { max-width: 90%; }

  .bubble { padding: 12px 14px; }

  .header-right .counter-label { display: none; }

  .welcome-inner { padding: 32px 24px; }
  .welcome-title { font-size: 1.25rem; }

  .modal-card { padding: 36px 24px; }
}

@media (max-width: 480px) {
  .logo-text { display: none; }
  #send-btn { width: 34px; height: 34px; }
}
