/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-900: #0a0f1e;
  --blue-800: #0d1526;
  --blue-700: #111d35;
  --indigo:   #4f46e5;
  --indigo-light: #6366f1;
  --violet:   #7c3aed;
  --cyan:     #06b6d4;
  --green:    #10b981;
  --white:    #ffffff;
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;

  --grad: linear-gradient(135deg, var(--indigo), var(--violet));
  --radius: 12px;
  --sidebar-w: 280px;
  --header-h: 68px;
  --input-h: 80px;
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

html { height: 100%; overflow: hidden; }
body { height: 100%; overflow: hidden; font-family: 'Inter', sans-serif; -webkit-font-smoothing: antialiased; max-width: 100vw; }
body { background: var(--blue-900); color: var(--white); }

.accent { background: linear-gradient(135deg, #818cf8, #a78bfa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 24px; border-radius: var(--radius); font-weight: 600; font-size: 15px; text-decoration: none; border: none; cursor: pointer; transition: all var(--transition); }
.btn-primary { background: var(--grad); color: white; box-shadow: 0 4px 20px rgba(79,70,229,.35); width: 100%; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(79,70,229,.5); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ===== ONBOARDING OVERLAY ===== */
.onboarding-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--blue-900);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}

.onboarding-card {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 24px;
  padding: 40px;
  width: 100%; max-width: 520px;
  box-shadow: 0 24px 64px rgba(0,0,0,.4);
}

.ob-step { display: none; flex-direction: column; gap: 16px; }
.ob-step.active { display: flex; }

.ob-avatar { font-size: 64px; text-align: center; }
.ob-step h1 { font-size: 28px; font-weight: 800; text-align: center; }
.ob-step h2 { font-size: 22px; font-weight: 700; }
.ob-step p { color: rgba(255,255,255,.55); font-size: 15px; line-height: 1.6; }
.ob-step-num { font-size: 12px; font-weight: 700; color: rgba(255,255,255,.35); text-transform: uppercase; letter-spacing: .1em; }

.ob-input {
  width: 100%; padding: 14px 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  color: white; font-size: 16px;
  outline: none; transition: border-color var(--transition);
}
.ob-input:focus { border-color: var(--indigo); }
.ob-input::placeholder { color: rgba(255,255,255,.3); }

.ob-options { display: flex; flex-direction: column; gap: 10px; }
.ob-option {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  cursor: pointer; color: white;
  text-align: left; transition: all var(--transition);
  width: 100%;
}
.ob-option:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); }
.ob-option.selected { background: rgba(79,70,229,.2); border-color: rgba(79,70,229,.5); }
.ob-option .opt-icon { font-size: 24px; flex-shrink: 0; }
.ob-option strong { display: block; font-size: 15px; font-weight: 600; }
.ob-option small { color: rgba(255,255,255,.45); font-size: 12px; }

/* ===== CHAT APP LAYOUT ===== */
.chat-app {
  display: flex;
  height: 100vh;
  width: 100vw;
  max-width: 100vw;
  overflow: hidden;
  position: relative;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--blue-800);
  border-right: 1px solid rgba(255,255,255,.06);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: white;
  font-size: 18px; font-weight: 700;
}
.logo span:first-child { font-size: 22px; }

.student-card {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.student-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.student-name { display: block; font-size: 14px; font-weight: 600; }
.student-meta { font-size: 12px; color: rgba(255,255,255,.4); }

.sidebar-nav { flex: 1; padding: 20px; overflow-y: auto; }
.nav-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: rgba(255,255,255,.35); margin-bottom: 10px; }

.goal-badge {
  display: inline-block;
  background: rgba(79,70,229,.25);
  border: 1px solid rgba(79,70,229,.4);
  color: #a5b4fc;
  padding: 5px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}

.progress-bar-wrap { margin-top: 6px; }
.progress-bar-label { display: flex; justify-content: space-between; font-size: 12px; color: rgba(255,255,255,.4); margin-bottom: 6px; }
.progress-bar { background: rgba(255,255,255,.08); border-radius: 999px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--grad); border-radius: 999px; transition: width .4s ease; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.stat-item { background: rgba(255,255,255,.05); border-radius: 10px; padding: 10px 8px; text-align: center; }
.stat-value { display: block; font-size: 18px; font-weight: 700; color: #fff; line-height: 1.2; }
.stat-label { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: rgba(255,255,255,.35); margin-top: 2px; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.06); display: flex; flex-direction: column; gap: 8px; }
.btn-upgrade {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--grad); color: white;
  font-size: 13px; font-weight: 700; text-decoration: none;
  box-shadow: 0 4px 16px rgba(79,70,229,.3);
  transition: all var(--transition);
}
.btn-upgrade:hover { transform: translateY(-1px); }
.btn-reset { background: none; border: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.4); padding: 8px; border-radius: var(--radius); cursor: pointer; font-size: 12px; transition: all var(--transition); }
.btn-reset:hover { border-color: rgba(255,255,255,.25); color: rgba(255,255,255,.7); }

/* ===== CHAT MAIN ===== */
.chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
}

.chat-header {
  height: var(--header-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--blue-900);
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.menu-toggle { display: none; background: none; border: none; color: white; font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.menu-toggle:hover { background: rgba(255,255,255,.08); }

.header-teacher { display: flex; align-items: center; gap: 12px; flex: 1; }
.teacher-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; position: relative; flex-shrink: 0;
}
.online-badge {
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--blue-900);
}
.teacher-name { font-size: 15px; font-weight: 700; }
.teacher-status { font-size: 12px; color: rgba(255,255,255,.45); }

.header-actions { display: flex; gap: 8px; }
.icon-btn { background: rgba(255,255,255,.06); border: none; color: rgba(255,255,255,.6); width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 16px; text-decoration: none; transition: all var(--transition); }
.icon-btn:hover { background: rgba(255,255,255,.12); color: white; }

/* ===== MESSAGES ===== */
.messages-area {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px 0;
  scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.messages-inner {
  max-width: 800px; margin: 0 auto;
  padding: 0 24px;
  display: flex; flex-direction: column; gap: 20px;
}

/* Message bubbles */
.msg-row { display: flex; gap: 12px; animation: fadeInUp .25s ease; }
.msg-row.user { flex-direction: row-reverse; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.msg-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
  align-self: flex-end;
}
.msg-row.bot .msg-avatar { background: var(--grad); }
.msg-row.user .msg-avatar { background: rgba(255,255,255,.12); }

.msg-bubble {
  width: max-content;
  min-width: 56px;
  max-width: min(72%, calc(100vw - 120px));
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 15px; line-height: 1.65;
  position: relative;
  overflow-wrap: break-word;
  word-break: break-word;
}
.msg-row.bot .msg-bubble {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-bottom-left-radius: 4px;
  color: rgba(255,255,255,.9);
}
.msg-row.user .msg-bubble {
  background: var(--grad);
  border-bottom-right-radius: 4px;
  color: white;
}

/* Markdown inside bot messages */
.msg-bubble p { margin-bottom: 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: white; font-weight: 700; }
.msg-bubble em { font-style: italic; color: rgba(255,255,255,.8); }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 8px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble blockquote {
  border-left: 3px solid var(--indigo-light);
  padding-left: 12px; margin: 10px 0;
  color: rgba(255,255,255,.65); font-style: italic;
}
.msg-bubble code {
  background: rgba(255,255,255,.1);
  padding: 2px 6px; border-radius: 4px;
  font-family: monospace; font-size: 13px;
}
.msg-bubble pre {
  background: rgba(0,0,0,.3); padding: 12px;
  border-radius: 8px; overflow-x: auto; margin: 10px 0;
}
.msg-bubble pre code { background: none; padding: 0; }

.msg-time { font-size: 11px; color: rgba(255,255,255,.3); margin-top: 6px; text-align: right; }
.msg-row.bot .msg-time { text-align: left; }

/* Typing indicator */
.typing-row { display: flex; gap: 12px; align-items: flex-end; }
.typing-bubble {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px; border-bottom-left-radius: 4px;
  padding: 14px 18px;
  display: flex; gap: 5px; align-items: center;
}
.typing-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,.4);
  animation: bounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

/* System / date messages */
.msg-system {
  text-align: center; font-size: 12px;
  color: rgba(255,255,255,.3);
  padding: 4px 0;
}

/* Welcome card */
.welcome-card {
  background: rgba(79,70,229,.1);
  border: 1px solid rgba(79,70,229,.25);
  border-radius: 16px; padding: 24px;
  text-align: center; margin-bottom: 8px;
}
.welcome-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.welcome-card p { color: rgba(255,255,255,.55); font-size: 14px; line-height: 1.6; }
.welcome-card .welcome-emoji { font-size: 36px; margin-bottom: 12px; display: block; }

/* Suggestion chips */
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.suggestion-chip {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: rgba(255,255,255,.7);
  cursor: pointer; transition: all var(--transition);
}
.suggestion-chip:hover { background: rgba(79,70,229,.2); border-color: rgba(79,70,229,.4); color: white; }

/* ===== LIMIT BAR ===== */
.limit-bar {
  background: rgba(239,68,68,.1);
  border-top: 1px solid rgba(239,68,68,.2);
  flex-shrink: 0;
}
.limit-bar-inner {
  max-width: 800px; margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; font-size: 14px; color: rgba(255,255,255,.7);
}
.btn-upgrade-inline {
  background: rgba(239,68,68,.2);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5; padding: 6px 14px;
  border-radius: 999px; font-size: 13px; font-weight: 600;
  text-decoration: none; white-space: nowrap;
  transition: all var(--transition);
}
.btn-upgrade-inline:hover { background: rgba(239,68,68,.3); }

/* ===== INPUT AREA ===== */
.input-area {
  padding: 12px 24px 16px;
  background: var(--blue-900);
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
  max-width: 100%;
  overflow: hidden;
}
.input-wrap {
  display: flex; gap: 12px; align-items: flex-end;
  max-width: 800px; margin: 0 auto;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px; padding: 4px 4px 4px 16px;
  transition: border-color var(--transition);
}
.input-wrap:focus-within { border-color: rgba(79,70,229,.5); }

.message-input {
  flex: 1; background: none; border: none; outline: none;
  color: white; font-size: 15px; font-family: inherit;
  resize: none; min-height: 40px; max-height: 160px;
  padding: 10px 0; line-height: 1.5;
  scrollbar-width: thin;
}
.message-input::placeholder { color: rgba(255,255,255,.3); }

.send-btn {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  background: var(--grad); border: none; cursor: pointer; color: white;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.input-hint {
  display: flex; justify-content: space-between;
  max-width: 800px; margin: 6px auto 0;
  font-size: 11px; color: rgba(255,255,255,.2);
}
.char-count { color: rgba(255,255,255,.2); }
.char-count.warn { color: #f59e0b; }

/* ===== RESPONSIVE ===== */
/* ===== MOBILE ===== */
@media (max-width: 768px) {
  :root { --header-h: 60px; }
  /* Sidebar desliza SOBRE o conteúdo (não empurra) */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    transform: translateX(-100%);
    width: min(var(--sidebar-w), 85vw);
  }
  .sidebar.open { transform: none; box-shadow: 8px 0 32px rgba(0,0,0,.5); }
  /* Chat principal ocupa 100% da tela — sidebar não empurra */
  .chat-main { width: 100vw; max-width: 100vw; flex: none; }
  .menu-toggle { display: flex; }

  /* Header compacto: reduz padding e gap */
  .chat-header { padding: 0 12px; gap: 8px; height: 60px; }

  /* Info do professor: esconde status, trunca nome */
  .header-teacher { gap: 8px; min-width: 0; }
  .teacher-avatar { width: 34px; height: 34px; font-size: 14px; }
  .teacher-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .teacher-status { display: none; }

  /* Nome do usuário logado: esconde no mobile (já está no sidebar) */
  #user-info { display: none !important; }

  /* Botões do header: menores */
  .header-actions { gap: 6px; flex-shrink: 0; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; border-radius: 8px; }
  /* Botão "Sair": vira ícone pequeno */
  #auth-btn { padding: 0 8px; font-size: 12px; height: 32px; min-width: 44px; }

  .msg-bubble { max-width: min(88%, calc(100vw - 96px)); }

  /* Mensagens: menos padding lateral */
  .messages-inner { padding: 0 12px; gap: 14px; }
  .messages-area { padding: 16px 0; }

  /* Área de input */
  .input-area { padding: 8px 12px 12px; }
  .input-wrapper { border-radius: 16px; }
  #messageInput { font-size: 15px; padding: 10px 14px; }
  .send-btn { width: 40px; height: 40px; }

  /* Onboarding */
  .onboarding-card { padding: 24px 18px; }
  .onboarding-card h2 { font-size: 20px; }
}

@media (max-width: 480px) {
  /* Header ainda mais compacto em telas muito pequenas */
  .chat-header { padding: 0 10px; gap: 6px; }
  .teacher-name { max-width: 110px; }

  /* Esconde ícone 📊 no header — já está no sidebar */
  .header-actions a.icon-btn[href="dashboard.html"] { display: none; }

  /* Limite de mensagens */
  .limit-bar-inner { flex-direction: column; gap: 8px; text-align: center; }

  .msg-bubble { max-width: min(88%, calc(100vw - 96px)); font-size: 14px; }

  /* Input */
  .input-area { padding: 6px 10px 10px; }
}
