/* ═══════════════════════════════════
   EduAI v6 — Clean Light Design
   ═══════════════════════════════════ */

:root {
  --primary: #4361ee;
  --primary-light: #eef2ff;
  --primary-dark: #3451d1;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --sidebar-w: 300px;
  --topbar-h: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
.page { height: 100vh; }

/* ═══ LOGIN ═══ */
.login-wrapper { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #eff6ff 100%); padding: 1rem; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.5rem; }
.login-logo { font-size: 3rem; text-align: center; margin-bottom: 0.5rem; }
.login-card h1 { text-align: center; font-size: 1.75rem; font-weight: 700; color: var(--text); }
.login-sub { text-align: center; color: var(--text-secondary); margin-bottom: 2rem; font-size: 0.95rem; }
.input-group { margin-bottom: 1rem; }
.input-group label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.375rem; }
.input-group input { width: 100%; padding: 0.75rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 0.95rem; font-family: inherit; transition: border-color 0.2s, box-shadow 0.2s; background: var(--bg); }
.input-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67,97,238,0.1); }
.btn-login { width: 100%; padding: 0.875rem; background: var(--primary); color: white; border: none; border-radius: var(--radius); font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s, transform 0.1s; margin-top: 0.5rem; }
.btn-login:hover { background: var(--primary-dark); }
.btn-login:active { transform: scale(0.98); }
.error-msg { color: var(--danger); text-align: center; margin-top: 1rem; font-size: 0.875rem; min-height: 1.25rem; }
.demo-accounts { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.demo-accounts > p { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; text-align: center; }
.demo-chips { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.demo-chips span { padding: 0.375rem 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; font-size: 0.8rem; cursor: pointer; transition: all 0.2s; user-select: none; }
.demo-chips span:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* ═══ MAIN LAYOUT ═══ */
#mainApp { display: flex; height: 100vh; }

/* ═══ SIDEBAR ═══ */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; z-index: 100; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1rem; }
.sidebar-brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-icon { font-size: 1.5rem; }
.brand-text { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.sidebar-close { display: none; background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-muted); padding: 4px; }
.btn-new-chat { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin: 0 1rem 0.75rem; padding: 0.75rem; background: var(--primary); color: white; border: none; border-radius: var(--radius); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-new-chat:hover { background: var(--primary-dark); }
.session-list { flex: 1; overflow-y: auto; padding: 0 0.5rem; }
.session-item { padding: 0.75rem 1rem; border-radius: 10px; cursor: pointer; font-size: 0.875rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: all 0.15s; margin-bottom: 2px; display: flex; align-items: center; gap: 0.5rem; }
.session-item:hover { background: var(--bg); color: var(--text); }
.session-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.session-item .session-icon { flex-shrink: 0; opacity: 0.5; }
.session-item.active .session-icon { opacity: 1; }
.sidebar-bottom { padding: 1rem; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1rem; font-weight: 600; }
.user-avatar.student { background: #dbeafe; color: #2563eb; }
.user-avatar.teacher { background: #dcfce7; color: #16a34a; }
.user-avatar.parent { background: #fef3c7; color: #d97706; }
.user-avatar.admin { background: #f3e8ff; color: #9333ea; }
.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 0.875rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.75rem; color: var(--text-muted); }
.sidebar-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.sidebar-link { display: block; padding: 0.5rem 0.75rem; font-size: 0.85rem; color: var(--text-secondary); text-decoration: none; border-radius: 8px; transition: all 0.15s; }
.sidebar-link:hover { background: var(--bg); color: var(--primary); }
.btn-logout { padding: 0.5rem 0.75rem; background: none; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--text-muted); font-size: 0.85rem; transition: all 0.15s; text-align: left; }
.btn-logout:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }

/* ═══ MAIN CONTENT ═══ */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Topbar */
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: 0.75rem; padding: 0 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.hamburger { display: none; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; }
.topbar-title { font-size: 0.95rem; font-weight: 600; color: var(--text); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-badge { font-size: 0.75rem; padding: 0.25rem 0.75rem; border-radius: 20px; font-weight: 500; }
.topbar-badge.student { background: #dbeafe; color: #2563eb; }
.topbar-badge.teacher { background: #dcfce7; color: #16a34a; }
.topbar-badge.parent { background: #fef3c7; color: #d97706; }
.topbar-badge.admin { background: #f3e8ff; color: #9333ea; }

/* ═══ MESSAGES ═══ */
.messages-container { flex: 1; overflow-y: auto; }
.messages { max-width: 800px; margin: 0 auto; padding: 1.5rem 1rem; }

/* Welcome */
.welcome-screen { text-align: center; padding: 4rem 1rem 2rem; }
.welcome-icon { font-size: 4rem; margin-bottom: 1rem; }
.welcome-screen h2 { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: 0.5rem; }
.welcome-screen p { color: var(--text-secondary); font-size: 1rem; margin-bottom: 2rem; }
.quick-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }
.quick-action { padding: 0.75rem 1.25rem; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 0.875rem; cursor: pointer; transition: all 0.2s; color: var(--text-secondary); }
.quick-action:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* Message bubbles */
.msg { margin-bottom: 1.25rem; display: flex; gap: 0.75rem; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; flex-shrink: 0; margin-top: 2px; }
.msg.user .msg-avatar { background: var(--primary); color: white; }
.msg.assistant .msg-avatar { background: var(--primary-light); color: var(--primary); }
.msg-bubble { flex: 1; min-width: 0; }
.msg.user { flex-direction: row-reverse; }
.msg.user .msg-bubble { text-align: right; }
.msg-sender { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.25rem; }
.msg-text { padding: 0.875rem 1.125rem; border-radius: var(--radius-lg); line-height: 1.6; font-size: 0.925rem; white-space: pre-wrap; word-break: break-word; }
.msg.user .msg-text { background: var(--primary); color: white; border-bottom-right-radius: 4px; display: inline-block; }
.msg.assistant .msg-text { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant .msg-text strong { color: var(--primary); }
.msg.assistant .msg-text code { background: var(--bg); padding: 0.125rem 0.375rem; border-radius: 4px; font-size: 0.85em; }

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; padding: 1rem 1.125rem; }
.typing-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); animation: typingBounce 1.4s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }

/* ═══ INPUT ═══ */
.input-container { padding: 0.75rem 1rem 1rem; border-top: 1px solid var(--border); background: var(--surface); }
.input-wrapper { max-width: 800px; margin: 0 auto; display: flex; align-items: flex-end; gap: 0.5rem; background: var(--bg); border: 1.5px solid var(--border); border-radius: var(--radius-lg); padding: 0.5rem 0.5rem 0.5rem 1rem; transition: border-color 0.2s, box-shadow 0.2s; }
.input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67,97,238,0.1); }
.input-wrapper textarea { flex: 1; border: none; background: transparent; font-size: 0.95rem; font-family: inherit; resize: none; max-height: 150px; line-height: 1.5; padding: 0.375rem 0; color: var(--text); }
.input-wrapper textarea:focus { outline: none; }
.input-wrapper textarea::placeholder { color: var(--text-muted); }
.btn-send { width: 40px; height: 40px; border-radius: 10px; border: none; background: var(--primary); color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0; }
.btn-send:hover { background: var(--primary-dark); }
.btn-send:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
.input-hint { text-align: center; font-size: 0.7rem; color: var(--text-muted); margin-top: 0.5rem; max-width: 800px; margin-left: auto; margin-right: auto; }

/* ═══ MOBILE ═══ */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 99; }

@media (max-width: 768px) {
  .sidebar { position: fixed; left: -100%; top: 0; bottom: 0; width: 85%; max-width: 320px; transition: left 0.3s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { left: 0; }
  .sidebar-close { display: block; }
  .sidebar-overlay.open { display: block; }
  .hamburger { display: flex; }
  .messages { padding: 1rem 0.75rem; }
  .welcome-screen { padding: 2rem 0.5rem 1rem; }
  .quick-actions { flex-direction: column; align-items: center; }
}

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

/* ═══ ANIMATIONS ═══ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg { animation: fadeIn 0.3s ease; }
