/* ============================================
   Teacher IA - Full UI Redesign
   ============================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --c-bg: #fafbfc;
  --c-surface: #ffffff;
  --c-surface-2: #f3f4f8;
  --c-border: #e2e5ec;
  --c-border-light: #eef0f4;
  --c-text: #1a1d26;
  --c-text-2: #5f6577;
  --c-text-3: #9298a8;
  --c-primary: #5b4cff;
  --c-primary-soft: #eeeaff;
  --c-primary-dark: #4338ca;
  --c-accent: #f472b6;
  --c-accent-soft: #fce7f3;
  --c-success: #10b981;
  --c-success-soft: #d1fae5;
  --c-warning: #f59e0b;
  --c-warning-soft: #fef3c7;
  --c-danger: #ef4444;
  --c-danger-soft: #fee2e2;
  --sidebar-w: 272px;
  --topbar-h: 56px;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 50;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--c-primary);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-label {
  font-weight: 700;
  font-size: 17px;
  color: var(--c-text);
}

.logo-label span {
  color: var(--c-primary);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--c-text-3);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}
.sidebar-close:hover { background: var(--c-surface-2); }

.sidebar-section {
  padding: 0 16px 20px;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--c-text-3);
  margin-bottom: 8px;
  padding: 0 4px;
}

/* User card */
.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--c-primary-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info { min-width: 0; }
.user-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-level { font-size: 12px; color: var(--c-primary-dark); font-weight: 600; }

/* XP bar */
.xp-bar-container { margin-bottom: 12px; }

.xp-bar-track {
  height: 6px;
  background: var(--c-surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-primary), var(--c-accent));
  border-radius: 3px;
  transition: width .5s ease;
}

.xp-bar-label {
  text-align: right;
  font-size: 11px;
  color: var(--c-text-3);
  margin-top: 4px;
}

/* Mini stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.mini-stat {
  background: var(--c-surface-2);
  border-radius: var(--radius-xs);
  padding: 8px 4px;
  text-align: center;
}

.mini-stat-val {
  font-size: 16px;
  font-weight: 800;
  color: var(--c-primary);
}

.mini-stat-lbl {
  font-size: 10px;
  color: var(--c-text-3);
  margin-top: 2px;
}

/* Subject list */
.subject-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.subject-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--c-text-2);
  padding: 9px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background .12s, color .12s;
}

.subject-btn:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}

.subject-btn.active {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 600;
}

.subject-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  background: var(--c-surface-2);
  color: var(--c-text-2);
  flex-shrink: 0;
}

.subject-btn.active .subject-ico {
  background: var(--c-primary);
  color: #fff;
}

/* Level select */
#levelSelect {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 13px;
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  appearance: auto;
}

#levelSelect:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

/* Sidebar bottom */
.sidebar-bottom {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--c-border-light);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text-2);
  padding: 9px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background .12s;
  width: 100%;
  text-align: left;
}

.sidebar-action:hover { background: var(--c-surface-2); }

.sidebar-action--danger { color: var(--c-danger); }
.sidebar-action--danger:hover { background: var(--c-danger-soft); }

.action-ico { font-size: 15px; }

/* ---- MAIN AREA ---- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--c-bg);
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  gap: 12px;
}

.menu-btn {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}
.menu-btn:hover { background: var(--c-surface-2); }
.menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--c-text);
  border-radius: 1px;
}

.topbar-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--c-text);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-stats {
  display: flex;
  gap: 14px;
}

.topbar-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
}

.ts-icon { font-size: 14px; }

.btn-login {
  background: var(--c-primary);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-login:hover { background: var(--c-primary-dark); transform: translateY(-1px); }

/* ---- WELCOME SCREEN ---- */
#welcomeScreen {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.welcome-wrapper {
  max-width: 680px;
  width: 100%;
}

.welcome-hero {
  text-align: center;
  margin-bottom: 48px;
}

.hero-badge {
  display: inline-block;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 20px;
  margin-bottom: 20px;
}

.welcome-hero h1 {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 16px;
  letter-spacing: -0.5px;
}

.text-gradient {
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-desc {
  font-size: 16px;
  color: var(--c-text-2);
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto 28px;
}

.btn-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  padding: 14px 32px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
}

.btn-cta:hover {
  background: var(--c-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(91,76,255,.25);
}

.btn-cta--sm {
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 10px;
}

.hero-sub {
  margin-top: 12px;
  font-size: 12px;
  color: var(--c-text-3);
}

/* Features */
.features {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.feat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  transition: transform .2s, box-shadow .2s;
}
.feat:hover { transform: translateY(-4px); box-shadow: var(--shadow); }

.feat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 12px;
  font-weight: 700;
}

.feat-icon--1 { background: var(--c-primary-soft); color: var(--c-primary); }
.feat-icon--2 { background: var(--c-warning-soft); color: var(--c-warning); }
.feat-icon--3 { background: var(--c-accent-soft); color: var(--c-accent); }
.feat-icon--4 { background: var(--c-success-soft); color: var(--c-success); }

.feat h3 { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.feat p { font-size: 12px; color: var(--c-text-2); line-height: 1.5; }

/* ---- CHAT SCREEN ---- */
#chatScreen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Quick bar */
.quick-bar {
  display: flex;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--c-border-light);
  flex-shrink: 0;
}

.qbtn {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--c-text-2);
  padding: 6px 14px;
  cursor: pointer;
  transition: all .12s;
}
.qbtn:hover { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-primary-soft); }

/* Messages */
#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  animation: msgIn .3s ease;
}

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

.msg--user {
  align-self: flex-end;
}

.msg--user .msg-bubble {
  background: var(--c-primary);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.msg--user .msg-bubble strong { color: #fff; }

.msg-bubble {
  background: var(--c-surface);
  border: 1px solid var(--c-border-light);
  padding: 16px 20px;
  border-radius: 18px 18px 18px 4px;
  font-size: 14px;
  line-height: 1.7;
  box-shadow: var(--shadow-sm);
}

.msg--user .msg-bubble {
  border: none;
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble strong { color: var(--c-primary); font-weight: 600; }

.msg-bubble pre {
  background: var(--c-surface-2);
  padding: 14px;
  border-radius: var(--radius-xs);
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  border: 1px solid var(--c-border-light);
}

.msg-bubble code {
  background: var(--c-surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.msg-bubble ul, .msg-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.msg-bubble li { margin-bottom: 4px; }

/* XP notification */
.xp-notif {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--c-success-soft);
  color: var(--c-success);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 10px;
  animation: popIn .4s cubic-bezier(.18,.89,.32,1.27);
}

@keyframes popIn {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* Quiz */
.quiz-container { margin-top: 14px; }

.quiz-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  padding: 11px 16px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 6px;
  transition: all .12s;
}

.quiz-option:hover:not(:disabled) {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
}

.quiz-option.correct {
  border-color: var(--c-success);
  background: var(--c-success-soft);
  color: #065f46;
}

.quiz-option.wrong {
  border-color: var(--c-danger);
  background: var(--c-danger-soft);
  color: #991b1b;
}

.quiz-option:disabled { cursor: default; opacity: 0.7; }

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: 6px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--c-text-3);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -.32s; }
.typing-dots span:nth-child(2) { animation-delay: -.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Chat input */
.chat-input-area {
  padding: 12px 24px 20px;
  flex-shrink: 0;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: 16px;
  padding: 6px 6px 6px 18px;
  transition: border-color .15s, box-shadow .15s;
}

.chat-input-wrap:focus-within {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

#messageInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--c-text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  outline: none;
  line-height: 1.5;
  padding: 8px 0;
}

#messageInput::placeholder { color: var(--c-text-3); }

#sendBtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--c-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

#sendBtn:hover { background: var(--c-primary-dark); transform: scale(1.05); }
#sendBtn:disabled { opacity: .4; cursor: default; transform: none; }

/* ---- OVERLAYS / MODALS ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
  animation: fadeOverlay .2s ease;
}

@keyframes fadeOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--c-surface);
  border-radius: 20px;
  padding: 36px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: modalIn .3s cubic-bezier(.18,.89,.32,1.27);
}

@keyframes modalIn {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text-2);
  margin: 20px 0 10px;
  text-align: left;
}

.modal-x {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--c-text-3);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-x:hover { background: var(--c-surface-2); }

/* Level up */
.modal--levelup {
  overflow: hidden;
}

.levelup-glow {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(91,76,255,.2) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.levelup-icon {
  font-size: 56px;
  margin-bottom: 8px;
  position: relative;
}

.modal--levelup h2 {
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 28px;
}

.badge-unlocked-label {
  font-size: 13px;
  color: var(--c-text-2);
  margin-top: 12px;
}

.badge-showcase {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--c-primary-soft);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-primary);
  margin-top: 6px;
}

/* Profile */
.modal--profile {
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
}

.modal--profile h2 { text-align: center; }

.profile-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 16px 0 20px;
}

.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
}

.profile-name { font-size: 17px; font-weight: 700; }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.pg-item {
  background: var(--c-surface-2);
  border-radius: var(--radius-xs);
  padding: 14px 8px;
  text-align: center;
}

.pg-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--c-primary);
}

.pg-lbl {
  font-size: 11px;
  color: var(--c-text-3);
  margin-top: 2px;
}

.badges-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge-item {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border-light);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.badge-item.locked { opacity: .3; }

.subjects-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.subject-tag {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
}

/* ---- SIDEBAR OVERLAY (mobile) ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 40;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-text-3); }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

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

  .sidebar.open ~ .sidebar-overlay,
  .sidebar-overlay.show {
    display: block;
  }

  .sidebar-close { display: flex; align-items: center; justify-content: center; }
  .menu-btn { display: flex; }

  .features { grid-template-columns: repeat(2, 1fr); }
  .welcome-hero h1 { font-size: 30px; }
  .profile-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-bar { padding: 8px 16px; }
  #chatMessages { padding: 16px; }
  .chat-input-area { padding: 10px 16px 16px; }
}

@media (max-width: 420px) {
  .features { grid-template-columns: 1fr 1fr; gap: 8px; }
  .feat { padding: 16px 12px; }
  .welcome-hero h1 { font-size: 26px; }
}
