/* ============================================
   Assistant Éducatif — TEAM-IFI
   Design premium dark, mobile-first
   ============================================ */

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

:root {
  --bg: #0a0d14;
  --surface: #111622;
  --surface-2: #1a2133;
  --border: rgba(255,255,255,0.08);
  --accent: #6c63ff;
  --accent-2: #a78bfa;
  --accent-3: #38bdf8;
  --success: #34d399;
  --danger: #f87171;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px rgba(0,0,0,0.5);
  --font: 'Inter', sans-serif;
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ========== PAGES ========== */
.page { display: none; min-height: 100vh; }
.page.active { display: flex; flex-direction: column; }

/* ========== LANDING ========== */
#landing {
  position: relative;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  overflow: hidden;
}

.landing-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  animation: float 8s ease-in-out infinite;
}
.orb-1 { width: 500px; height: 500px; background: radial-gradient(#6c63ff, transparent); top: -150px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: radial-gradient(#38bdf8, transparent); bottom: -100px; right: -80px; animation-delay: 3s; }
.orb-3 { width: 300px; height: 300px; background: radial-gradient(#a78bfa, transparent); top: 50%; left: 50%; transform: translate(-50%,-50%); animation-delay: 6s; }

@keyframes float {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-30px); }
}

.landing-content {
  position: relative;
  z-index: 1;
  max-width: 680px;
  width: 100%;
  text-align: center;
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(108,99,255,0.15);
  border: 1px solid rgba(108,99,255,0.3);
  border-radius: 100px;
  padding: 6px 16px;
  font-size: 0.8rem;
  color: var(--accent-2);
  margin-bottom: 28px;
  letter-spacing: 0.03em;
}
.logo-icon { font-size: 1rem; }

.hero-title {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}
.gradient-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 40px;
}

/* ========== ROLE CARDS ========== */
.role-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}
@media(max-width:520px) { .role-cards { grid-template-columns: 1fr; } }

.role-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
.role-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(108,99,255,0.05), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}
.role-card:hover { border-color: var(--accent); transform: translateY(-4px); box-shadow: 0 20px 40px rgba(108,99,255,0.2); }
.role-card:hover::before { opacity: 1; }
.role-icon { font-size: 2.5rem; margin-bottom: 10px; }
.role-card h3 { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.role-card p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.role-arrow { font-size: 1.2rem; color: var(--accent); opacity: 0; transition: opacity 0.3s; }
.role-card:hover .role-arrow { opacity: 1; }

/* ========== SESSION INPUT ========== */
.session-input-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
}
.session-input-wrap label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.session-row { display: flex; gap: 10px; }
.session-row input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  outline: none;
  transition: border-color 0.2s;
}
.session-row input:focus { border-color: var(--accent); }
.btn-generate-session {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-generate-session:hover { border-color: var(--accent); color: var(--accent); }

/* ========== TOPBAR ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(10,13,20,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.back-btn:hover { border-color: var(--accent); color: var(--text); }
.session-badge {
  background: rgba(108,99,255,0.15);
  border: 1px solid rgba(108,99,255,0.3);
  border-radius: 100px;
  padding: 4px 14px;
  font-size: 0.8rem;
  color: var(--accent-2);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ========== VIEW CONTAINER ========== */
.view-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  width: 100%;
}
.view-header { margin-bottom: 28px; }
.view-header h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.view-header p { color: var(--text-muted); font-size: 0.95rem; }

/* ========== UPLOAD ZONE ========== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  margin-bottom: 24px;
  background: var(--surface);
}
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,0.08);
}
.upload-icon { font-size: 3rem; margin-bottom: 12px; }
.upload-text { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; }
.upload-sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 16px; }
.file-preview {
  margin-top: 16px;
  background: rgba(52,211,153,0.1);
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9rem;
  color: var(--success);
  font-weight: 500;
}

/* ========== FORM ========== */
.upload-form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media(max-width:520px) { .form-row { grid-template-columns: 1fr; } }
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.form-group input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }

/* ========== BUTTONS ========== */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(108,99,255,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; }
.btn-danger {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.3);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 16px;
}
.btn-danger:hover { background: rgba(248,113,113,0.2); }

/* ========== RESULT BOX ========== */
.result-box {
  background: rgba(52,211,153,0.08);
  border: 1px solid rgba(52,211,153,0.25);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--success);
}
.result-box.error {
  background: rgba(248,113,113,0.08);
  border-color: rgba(248,113,113,0.25);
  color: var(--danger);
}

/* ========== DOCS LIST ========== */
.docs-section { margin-top: 40px; }
.docs-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; color: var(--text-muted); }
.docs-list { display: flex; flex-direction: column; gap: 10px; }
.doc-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.doc-name { font-weight: 600; font-size: 0.9rem; }
.doc-meta { font-size: 0.8rem; color: var(--text-muted); }
.doc-status { font-size: 0.75rem; color: var(--success); background: rgba(52,211,153,0.1); padding: 3px 10px; border-radius: 100px; }
.empty-state { color: var(--text-muted); font-size: 0.9rem; font-style: italic; }

/* ========== CHAT ========== */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  height: calc(100vh - 65px);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.chat-avatar {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}
.chat-header h2 { font-size: 1.1rem; font-weight: 700; }
.chat-status { font-size: 0.8rem; color: var(--success); }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.message { display: flex; }
.user-message { justify-content: flex-end; }
.bot-message { justify-content: flex-start; }

.message-bubble {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.65;
}
.user-message .message-bubble {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bot-message .message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.intro-message .message-bubble { border-color: rgba(108,99,255,0.3); background: rgba(108,99,255,0.08); }

.sources-list {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.source-chip {
  background: rgba(56,189,248,0.1);
  border: 1px solid rgba(56,189,248,0.3);
  border-radius: 100px;
  padding: 3px 12px;
  font-size: 0.75rem;
  color: var(--accent-3);
  white-space: nowrap;
}

.typing-indicator .message-bubble {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 20px;
}
.typing-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typing 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%,80%,100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ========== CHAT INPUT ========== */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: rgba(10,13,20,0.9);
  backdrop-filter: blur(16px);
}
.chat-input-area textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color 0.2s;
}
.chat-input-area textarea:focus { border-color: var(--accent); }
.send-btn {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border: none;
  border-radius: 14px;
  width: 50px; height: 50px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  flex-shrink: 0;
}
.send-btn:hover { transform: scale(1.08); box-shadow: 0 8px 24px rgba(108,99,255,0.45); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.send-btn svg { width: 20px; height: 20px; stroke: #fff; }

/* ========== SPINNER ========== */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== UTILITY ========== */
.hidden { display: none !important; }

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

/* ========== MOBILE ========== */
@media(max-width:640px) {
  .view-container { padding: 24px 16px 80px; }
  .messages-area { padding: 16px 14px; }
  .chat-input-area { padding: 12px 14px; }
  .message-bubble { max-width: 92%; }
  .chat-header { padding: 16px; }
}

/* ========== GLOBAL STATS ========== */
.global-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin-bottom: 32px;
}
@media(max-width:640px) {
  .global-stats { flex-direction: column; gap: 16px; padding: 16px; }
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-3);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
