/* ================================
   AIVOKA ÉTUDIANT — Design System
   ================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ── Variables ── */
:root {
  --green: #00C93C;
  --green-d: #00a832;
  --blue: #1349FB;
  --blue-d: #0F3AC9;
  --red: #FF004F;
  --red-d: #d9003f;
  --white: #ffffff;
  --bg: #F4F6FA;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-full: 999px;
  --font: 'Nunito', sans-serif;
}

.logo-img {
  height: 32px;
  width: auto;
  vertical-align: middle;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

button {
  cursor: pointer;
  font-family: var(--font);
  border: none;
  outline: none;
}

input,
textarea {
  font-family: var(--font);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: var(--radius-full);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  transition: all .2s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border: 3px solid var(--green);
  box-shadow: 0 4px 0 var(--green-d);
}

.btn-primary:hover {
  background: var(--green-d);
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--green-d);
}

.btn-secondary {
  background: #fff;
  color: var(--blue);
  border: 3px solid var(--blue);
  box-shadow: 0 4px 0 var(--blue-d);
}

.btn-secondary:hover {
  background: #eef6ff;
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--blue-d);
}

.btn-danger {
  background: var(--red);
  color: #fff;
  border: 3px solid var(--red);
  box-shadow: 0 4px 0 var(--red-d);
}

.btn-danger:hover {
  background: var(--red-d);
  transform: translateY(2px);
}

.btn-forum {
  background: #6C5CE7;
  color: #fff;
  border: 3px solid #6C5CE7;
  box-shadow: 0 4px 0 #5A4BD1;
}

.btn-forum:hover {
  background: #5A4BD1;
  transform: translateY(2px);
}

.btn-sm {
  padding: 8px 18px;
  font-size: .875rem;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
  position: relative;
  transition: all .2s ease;
  box-shadow: var(--shadow);
}

.btn-icon:hover {
  background: var(--bg);
  transform: scale(1.07);
}

.btn-icon.btn-admin:hover {
  background: #5A4BD1 !important;
  border-color: #5A4BD1 !important;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  padding: 20px;
  transition: transform .2s, box-shadow .2s;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--red);
  color: #fff;
  font-size: .7rem;
  font-weight: 900;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  padding: 0 5px;
  position: absolute;
  top: -4px;
  right: -4px;
  animation: pulse 1.5s infinite;
}

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: .75rem;
  font-weight: 700;
}

.tag-green {
  background: #d4f7e0;
  color: var(--green-d);
}

.tag-blue {
  background: #daeeff;
  color: var(--blue-d);
}

.tag-red {
  background: #ffdde9;
  color: var(--red-d);
}

.tag-new {
  background: var(--red);
  color: #fff;
}

/* ── Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 68px;
  gap: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--text);
  flex-shrink: 0;
}

.navbar-brand span {
  color: var(--green);
}

.navbar-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border-radius: var(--radius-full);
  padding: 5px;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 22px;
  border-radius: var(--radius-full);
  font-size: .95rem;
  font-weight: 800;
  color: var(--muted);
  background: transparent;
  border: none;
  transition: all .2s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: #fff;
}

.tab-btn.active {
  background: var(--white);
  color: var(--text);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.tab-btn.active.tab-biblio {
  color: var(--blue);
}

.tab-btn.active.tab-chatbot {
  color: var(--green);
}

.tab-btn.active.tab-forum {
  color: #6C5CE7;
}

.tab-btn .tab-icon {
  font-size: 1.2rem;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Tab Panels ── */
.tab-panel {
  display: none;
  animation: fadeIn .3s ease;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

.main-area {
  flex: 1;
  overflow: hidden;
}

/* ── Chat Bubbles ── */
.messages-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  overflow-y: auto;
}

.bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.bubble-wrap.user {
  flex-direction: row-reverse;
}

.bubble-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: var(--bg);
  border: 2px solid var(--border);
}

.bubble {
  max-width: 75%;
  /* Augmenté légèrement pour mobile */
  padding: 12px 20px;
  border-radius: 20px;
  font-size: .95rem;
  line-height: 1.5;
  word-wrap: break-word;
  /* FIX Overflow */
  overflow-wrap: break-word;
  word-break: break-word;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

.bubble-ai {
  background: #fdfdfd;
  /* Fond blanchâtre */
  color: var(--text);
  border: 1.5px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble-user {
  background: linear-gradient(135deg, var(--blue) 0%, #6C5CE7 100%);
  /* Dégradé bleu → violet */
  color: #fff;
  border: none;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(19, 73, 251, 0.2);
}

.chat-input-bar {
  padding: 16px 24px;
  border-top: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-input {
  flex: 1;
  padding: 13px 20px;
  border-radius: var(--radius-full);
  border: 2px solid var(--border);
  font-size: .95rem;
  background: var(--bg);
  transition: border .2s;
}

.chat-input:focus {
  outline: none;
  border-color: var(--green);
  background: #fff;
}

/* ── Sidebar ── */
.chat-layout {
  display: flex;
  height: calc(100vh - 68px);
  height: calc(100dvh - 68px);
  overflow: hidden;
}

.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width .3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.sidebar.collapsed {
  width: 0 !important;
  border-right: none;
}

.sidebar-header {
  padding: 18px 20px;
  border-bottom: 1.5px solid var(--border);
  font-weight: 900;
  font-size: .9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.conv-item {
  padding: 13px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
  font-size: .9rem;
}

.conv-item:hover {
  background: var(--bg);
}

.conv-item.active {
  background: #f0fdf4;
  border-left: 3px solid var(--green);
}

.conv-title {
  font-weight: 700;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview {
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Library ── */
.library-panel {
  height: calc(100vh - 68px);
  overflow-y: auto;
  padding: 28px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
  background: var(--surface);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: .8rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.filter-select {
  padding: 7px 14px;
  border-radius: var(--radius-full);
  border: 2px solid var(--border);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 700;
  background: var(--bg);
  cursor: pointer;
  transition: border .2s;
}

.filter-select:focus {
  outline: none;
  border-color: var(--blue);
}

.courses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.course-card {
  cursor: pointer;
  transition: all 0.25s ease;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: white;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Style hover des cartes - tout en bleu */
.course-card:hover {
  border-color: var(--blue);
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(19, 73, 251, 0.15);
}

.course-thumbnail {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.course-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 0.3s ease;
}

.course-card:hover .course-thumbnail img {
  transform: scale(1.03);
}

.course-thumbnail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
}

.course-thumbnail-placeholder i {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.course-thumbnail-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  display: flex;
  gap: 6px;
}

.course-content {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.course-title {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.4;
  color: var(--text);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.course-info {
  flex: 1;
  margin-bottom: 12px;
}

.course-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--green);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.course-name i {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.course-teacher {
  font-size: 0.78rem;
  color: var(--blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.course-teacher i {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.course-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.course-pages {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.course-pages i {
  width: 12px;
  height: 12px;
}

/* Extrait de recherche sémantique */
.course-extrait {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 10px;
  padding: 10px;
  background: linear-gradient(135deg, #f0f7ff 0%, #e8f4f8 100%);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--blue);
}

.course-extrait i {
  color: var(--blue);
  opacity: 0.6;
  margin-top: 2px;
}

.course-extrait span {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Badge de page pour résultats de recherche */
.tag-page {
  background: var(--blue);
  color: white;
  font-weight: 700;
}

/* ── Barre de recherche hero ── */
.search-hero {
  background: linear-gradient(135deg, #1349FB 0%, #0F3AC9 100%);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.search-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  pointer-events: none;
}

.search-hero-inner {
  position: relative;
  z-index: 1;
}

.search-main {
  display: flex;
  align-items: center;
  background: white;
  border-radius: var(--radius-full);
  padding: 6px 6px 6px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}

.search-main:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}

.search-main-icon {
  width: 22px;
  height: 22px;
  color: var(--muted);
  flex-shrink: 0;
}

.search-main-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: transparent;
}

.search-main-input::placeholder {
  color: var(--muted);
  font-weight: 500;
}

.search-mode-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--green) 0%, #00a832 100%);
  color: white;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 800;
  animation: pulse-glow 2s infinite;
}

.search-mode-indicator.active {
  display: flex;
}

.search-mode-indicator i {
  width: 16px;
  height: 16px;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 201, 60, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(0, 201, 60, 0); }
}

.search-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
  font-weight: 500;
}

.search-hint.active {
  color: rgba(255,255,255,1);
}

.search-hint i {
  flex-shrink: 0;
}

/* ── Barre de filtres ── */
.filters-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filters-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
}

.filters-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Pills de catégorie */
.filter-pills {
  display: flex;
  gap: 6px;
}

.filter-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  background: white;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-pill:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.filter-pill.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.filter-pill i {
  width: 16px;
  height: 16px;
}

.filter-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

/* Dropdowns de filtres */
.filter-dropdown-group {
  display: flex;
  gap: 8px;
}

.filter-dropdown {
  position: relative;
}

.filter-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  max-width: 200px;
}

.filter-dropdown-btn:hover {
  border-color: var(--blue);
}

.filter-dropdown-btn.active {
  background: rgba(19, 73, 251, 0.1);
  border-color: var(--blue);
  color: var(--blue);
}

.filter-dropdown-btn i:first-child {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.6;
}

.filter-dropdown-btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.dropdown-arrow {
  width: 14px !important;
  height: 14px !important;
  opacity: 0.5;
  transition: transform 0.2s;
}

.filter-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.filter-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 250px;
  max-height: 300px;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s;
  z-index: 100;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.filter-dropdown.open .filter-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.dropdown-search i {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.dropdown-search input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.85rem;
  color: var(--text);
}

.dropdown-options {
  overflow-y: auto;
  max-height: 220px;
  padding: 6px;
}

.dropdown-option {
  display: block;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-option:hover {
  background: var(--bg);
}

.dropdown-option.active {
  background: rgba(19, 73, 251, 0.1);
  color: var(--blue);
  font-weight: 700;
}

.dropdown-option.hidden {
  display: none;
}

/* Badge résultats */
.results-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--muted);
}

.results-badge i {
  width: 16px;
  height: 16px;
}

.results-badge strong {
  color: var(--text);
}

/* Bouton reset */
.btn-reset {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset:hover {
  background: var(--red);
  color: white;
}

.btn-reset i {
  width: 16px;
  height: 16px;
}

/* Responsive */
@media (max-width: 768px) {
  .search-hero {
    padding: 20px;
  }

  .filters-bar {
    padding: 12px;
  }

  .filters-bar-left {
    width: 100%;
  }

  .filter-pills {
    width: 100%;
    justify-content: space-between;
  }

  .filter-pill {
    flex: 1;
    justify-content: center;
    padding: 8px 10px;
  }

  .filter-divider {
    display: none;
  }

  .filter-dropdown-group {
    width: 100%;
  }

  .filter-dropdown {
    flex: 1;
  }

  .filter-dropdown-btn {
    width: 100%;
    max-width: none;
  }

  .filters-bar-right {
    width: 100%;
    justify-content: space-between;
  }
}

.filters-summary {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.results-count {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.results-count strong {
  color: var(--text);
}

.btn-reset-filters {
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset-filters:hover {
  background: white;
  border-color: var(--blue);
  color: var(--blue);
}

/* ── Forum ── */
.forum-layout {
  display: flex;
  height: calc(100vh - 68px);
  height: calc(100dvh - 68px);
  overflow: hidden;
}

.channels-list {
  width: 300px;
  border-right: 2px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  flex-shrink: 0;
}

.channels-header {
  padding: 18px 20px;
  border-bottom: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.channels-header h3 {
  font-size: .9rem;
  font-weight: 900;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
  position: relative;
}

.channel-item:hover {
  background: var(--bg);
}

.channel-item.active {
  background: #f0eeff;
  border-left: 3px solid #6C5CE7;
}

.channel-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.channel-info {
  flex: 1;
  min-width: 0;
}

.channel-name {
  font-weight: 800;
  font-size: .92rem;
}

.channel-preview {
  font-size: .78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.channel-time {
  font-size: .72rem;
  color: var(--muted);
}

.forum-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mobile-only {
  display: none !important;
}

.forum-header {
  padding: 16px 24px;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.forum-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.forum-header-info {
  min-width: 0;
}

.forum-header-info h2 {
  font-size: 1.1rem;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.forum-header-info p {
  font-size: .8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.forum-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.forum-search-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.forum-search-mobile {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}


/* ── Mascot SVG ── */
.mascot-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mascot-svg {
  animation: float 3.5s ease-in-out infinite;
}

.mascot-svg-read {
  animation: float-slow 4s ease-in-out infinite;
}

.mascot-svg-robot {
  animation: bob 2.5s ease-in-out infinite;
}

.mascot-svg-group {
  animation: fadeIn 1s ease;
}

/* ── Animations ── */
@keyframes float {

  0%,
  100% {
    transform: translateY(0px) rotate(-2deg);
  }

  50% {
    transform: translateY(-18px) rotate(2deg);
  }
}

@keyframes float-slow {

  0%,
  100% {
    transform: translateY(0px) rotate(-1deg);
  }

  50% {
    transform: translateY(-10px) rotate(1deg);
  }
}

@keyframes bob {

  0%,
  100% {
    transform: translateY(0) scaleX(1);
  }

  25% {
    transform: translateY(-8px) scaleX(1.03);
  }

  75% {
    transform: translateY(4px) scaleX(.98);
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.typing-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  margin: 0 2px;
  animation: float 1.2s ease-in-out infinite;
}

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

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

/* ── Utility ── */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-8 {
  gap: 8px;
}

.gap-12 {
  gap: 12px;
}

.gap-16 {
  gap: 16px;
}

.gap-24 {
  gap: 24px;
}

.mt-8 {
  margin-top: 8px;
}

.mt-16 {
  margin-top: 16px;
}

.mb-8 {
  margin-bottom: 8px;
}

.w-full {
  width: 100%;
}

.text-center {
  text-align: center;
}

.text-sm {
  font-size: .85rem;
}

.text-muted {
  color: var(--muted);
}

.font-bold {
  font-weight: 700;
}

.font-black {
  font-weight: 900;
}

.hidden {
  display: none !important;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ══════════════════════════════════════
   RESPONSIVE — Tablet (≤900px)
   ══════════════════════════════════════ */
@media (max-width: 900px) {

  /* Navbar: réduire les paddings */
  .navbar {
    padding: 0 16px;
    gap: 10px;
  }

  .navbar-brand {
    font-size: 1.1rem;
  }

  .navbar-brand span {
    display: none;
  }

  /* Masquer "Étudiant" */

  /* Tabs: labels masqués, icônes seules */
  .tab-btn {
    padding: 9px 14px;
    font-size: 0;
    gap: 0;
  }

  .tab-btn .tab-icon {
    font-size: 1.3rem;
  }

  /* Sidebar chat: rétrécir */
  .sidebar {
    width: 220px;
  }

  /* Forum: rétrécir la liste des canaux */
  .channels-list {
    width: 220px;
  }

  .channel-name {
    font-size: .82rem;
  }

  .channel-preview {
    display: none;
  }

  .channel-meta {
    display: none;
  }

  /* Library: 2 colonnes */
  .courses-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }

  .library-panel {
    padding: 20px;
  }

  /* Filtres: 2 colonnes sur tablette */
  .filters-row {
    gap: 12px;
  }

  .filter-group {
    min-width: 140px;
  }

  .filter-group.search-group {
    flex: 100%;
    min-width: 100%;
  }

  /* Filter bar: wrap */
  .filter-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-group[style*="margin-left:auto"] {
    margin-left: 0 !important;
  }

  .filter-group input {
    min-width: 0 !important;
    width: 100%;
  }
}

/* ══════════════════════════════════════
   RESPONSIVE — Mobile (≤640px)
   ══════════════════════════════════════ */
@media (max-width: 640px) {

  /* ── Navbar ── */
  .navbar {
    height: auto;
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .navbar-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
    padding: 4px;
    gap: 4px;
  }

  .tab-btn {
    flex: 1;
    justify-content: center;
    padding: 8px 6px;
  }

  .navbar-brand {
    font-size: 1rem;
  }

  .navbar-brand span {
    display: none;
  }

  .navbar-actions {
    margin-left: auto;
  }

  /* ── Chat layout: sidebar en drawer ── */
  .chat-layout {
    flex-direction: row;
    /* Force vertical even on mobile */
    height: calc(100vh - 68px);
  }

  .sidebar {
    width: 260px !important;
    max-height: none !important;
    border-right: 2px solid var(--border) !important;
    border-bottom: none !important;
    flex-direction: column !important;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
  }

  .sidebar-header {
    display: flex !important;
  }

  #convList {
    flex-direction: column !important;
  }

  #convList .conv-item {
    min-width: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border) !important;
  }

  .conv-preview {
    display: block !important;
  }

  .chat-main {
    margin-left: 0;
    transition: margin-left .3s;
  }

  /* ── Chat: hauteur adaptée ── */
  #chatMessages {
    max-height: calc(100vh - 240px);
  }

  /* ── Bulles: largeur max plus grande sur mobile ── */
  .bubble {
    max-width: 85%;
    font-size: .88rem;
  }

  /* ── Forum: WhatsApp Style Mobile ── */
  .forum-layout {
    flex-direction: row;
    position: relative;
    overflow: hidden;
  }

  .channels-list {
    width: 100% !important;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    transition: transform .3s;
  }

  .forum-main {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform .3s;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .forum-layout.viewing-channel .channels-list {
    transform: translateX(-100%);
  }

  .forum-layout.viewing-channel .forum-main {
    transform: translateX(0);
    z-index: 30;
  }

  .channel-preview,
  .channel-meta {
    display: block !important;
  }

  /* Header fixe en haut, input fixe en bas, messages scrollent au milieu */
  .forum-header {
    flex-shrink: 0 !important;
  }

  .forum-search-mobile {
    flex-shrink: 0 !important;
  }

  #forumMessages {
    flex: 1 !important;
    overflow-y: auto !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  .forum-input-bar {
    flex-shrink: 0 !important;
  }

  /* ── Library ── */
  .library-panel {
    padding: 14px;
    height: auto;
  }

  .courses-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .course-thumbnail {
    aspect-ratio: 4 / 5;
  }

  .course-content {
    padding: 12px;
  }

  .course-title {
    font-size: 0.85rem;
  }

  .course-name, .course-teacher {
    font-size: 0.75rem;
  }

  .filters-container {
    padding: 14px;
  }

  .filters-row {
    flex-direction: column;
    gap: 12px;
  }

  .filter-group {
    min-width: 100%;
    width: 100%;
  }

  .filter-group.search-group {
    min-width: 100%;
  }

  .filters-summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .filter-bar {
    padding: 12px;
    gap: 8px;
  }

  .biblio-mascot-banner {
    flex-direction: column;
    text-align: center;
    padding: 16px;
    gap: 10px;
  }

  /* ── Buttons ── */
  .btn {
    padding: 12px 20px;
    font-size: .9rem;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
  }

  /* ══════════════════════════════════════
     CHAT MOBILE - Layout complet repensé
     ══════════════════════════════════════ */
  .chat-layout {
    height: calc(100vh - 110px) !important;
    height: calc(100dvh - 110px) !important;
    position: relative;
  }

  .chat-main {
    display: flex;
    flex-direction: column;
    height: 100% !important;
    position: relative;
  }

  /* Zone des messages - prend tout l'espace disponible */
  #chatMessages {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 16px !important;
    padding-bottom: 20px !important;
    max-height: none !important;
    height: auto !important;
  }

  /* État vide - centré verticalement */
  .chat-empty {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 20px;
    padding-bottom: 20px;
  }

  /* Mascotte chat plus petite sur mobile */
  .chat-avo-icon {
    width: 100px !important;
    height: 115px !important;
  }

  .chat-empty h3 {
    font-size: 1rem;
    margin-top: 12px;
  }

  .chat-empty p {
    font-size: 0.8rem;
    padding: 0 10px;
    margin-bottom: 16px;
  }

  .suggestion-pills {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding: 0 10px;
  }

  .suggestion-pills .pill {
    font-size: 0.72rem;
    padding: 8px 10px;
  }

  /* Barre de saisie - en bas mais pas fixed pour éviter les problèmes */
  .chat-input-bar {
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    padding: 10px 12px;
    background: var(--surface);
    border-top: 2px solid var(--border);
    gap: 8px;
    flex-shrink: 0;
  }

  .chat-input {
    padding: 11px 14px;
    font-size: 0.88rem;
    min-width: 0;
  }

  .chat-input-bar .btn {
    padding: 10px 14px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .chat-input-bar .btn-icon,
  .chat-input-bar .record-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  .record-btn {
    padding: 0 !important;
  }

  /* Recording UI compact */
  .recording-indicator {
    font-size: 0.8rem;
  }

  /* ══════════════════════════════════════
     RECHERCHE HERO MOBILE
     ══════════════════════════════════════ */
  .search-hero {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: var(--radius-sm);
  }

  .search-main {
    padding: 4px 4px 4px 14px;
    border-radius: var(--radius-sm);
  }

  .search-main-input {
    padding: 10px 8px;
    font-size: 0.9rem;
  }

  .search-main-icon {
    width: 18px;
    height: 18px;
  }

  .search-mode-indicator {
    padding: 8px 12px;
    font-size: 0.75rem;
  }

  .search-hint {
    font-size: 0.7rem;
    margin-top: 8px;
  }

  /* ══════════════════════════════════════
     FILTRES MOBILE
     ══════════════════════════════════════ */
  .filters-bar {
    padding: 10px;
    gap: 10px;
    flex-direction: column;
    align-items: stretch;
  }

  .filters-bar-left {
    flex-direction: column;
    gap: 10px;
  }

  .filter-pills {
    width: 100%;
    justify-content: space-between;
  }

  .filter-pill {
    flex: 1;
    justify-content: center;
    padding: 8px 6px;
    font-size: 0.8rem;
  }

  .filter-pill i {
    display: none;
  }

  .filter-divider {
    display: none;
  }

  .filter-dropdown-group {
    width: 100%;
    flex-direction: column;
    gap: 8px;
  }

  .filter-dropdown {
    width: 100%;
  }

  .filter-dropdown-btn {
    width: 100%;
    max-width: none;
    justify-content: space-between;
    padding: 10px 14px;
  }

  .filter-dropdown-btn span {
    max-width: none;
  }

  .filter-dropdown-menu {
    width: 100%;
    left: 0;
    right: 0;
  }

  .filters-bar-right {
    width: 100%;
    justify-content: space-between;
  }

  .results-badge {
    flex: 1;
  }

  /* ══════════════════════════════════════
     FORUM MOBILE
     ══════════════════════════════════════ */

  .mobile-only {
    display: inline-flex !important;
  }

  .desktop-only {
    display: none !important;
  }

  .forum-header {
    padding: 10px 14px;
    gap: 10px;
  }

  .forum-header-info h2 {
    font-size: .95rem !important;
  }

  #followBtn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 6px 14px !important;
    font-size: .8rem !important;
  }

  .forum-mascot-banner {
    padding: 12px;
    gap: 10px;
    flex-direction: column;
    text-align: center;
  }

  .forum-mascot-text h2 {
    font-size: 0.9rem;
  }

  .forum-mascot-text p {
    font-size: 0.75rem;
  }

  .channels-header .btn {
    padding: 6px 12px !important;
    font-size: .75rem !important;
  }

  /* Forum layout: pleine hauteur */
  .forum-layout {
    height: calc(100vh - 110px) !important;
    height: calc(100dvh - 110px) !important;
  }

  #forumMessages {
    flex: 1 !important;
    overflow-y: auto !important;
    max-height: none !important;
    padding: 12px !important;
  }

  .forum-input-bar {
    flex-shrink: 0;
  }

  /* Bulles forum: largeur adaptée */
  .forum-bubble {
    max-width: 85% !important;
  }
}

/* ══════════════════════════════════════
   FORUM SOCIAL & INTERACTIONS (EXTRACTED)
   ══════════════════════════════════════ */

/* ── Context Menu (Forum Reactions/Actions) ── */
.context-menu {
  position: fixed;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: none;
  flex-direction: column;
  padding: 8px;
  min-width: 180px;
}

.context-menu-item {
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.2s;
}

.context-menu-item:hover {
  background: var(--bg);
}

.reaction-picker {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 8px;
  justify-content: space-between;
}

.reaction-emoji {
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.2s;
}

.reaction-emoji:hover {
  transform: scale(1.3);
}

/* ── Reaction Bubbles under messages ── */
.reactions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.reaction-tag {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.reaction-tag.mine {
  background: rgba(19, 73, 251, 0.1);
  border-color: var(--blue);
}

/* ── Reply Preview UI ── */
.reply-preview-container {
  display: none;
  background: #f8fafc;
  border-left: 4px solid var(--blue);
  padding: 8px 16px;
  border-top: 2px solid var(--border);
  position: relative;
}

.reply-preview-text {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cancel-reply {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  font-weight: 900;
  color: var(--muted);
}

/* ── Media Upload Previews ── */
.file-preview-area {
  display: none;
  padding: 10px 24px;
  background: white;
  border-top: 1.5px solid var(--border);
  gap: 12px;
  overflow-x: auto;
}

.preview-item {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1.5px solid var(--border);
  position: relative;
  flex-shrink: 0;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.remove-preview {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: pointer;
  border: 2px solid white;
}

/* ── Forum & Chat UI Fixes ── */
.chat-input-bar,
.forum-input-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  padding: 12px 18px;
  border-top: 2px solid var(--border);
}

.bubble audio {
  max-width: 100%;
  height: 36px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
  border-radius: var(--radius-full);
}

.bubble-user audio {
  filter: invert(1) hue-rotate(180deg) brightness(1.5);
  /* Adapter les contrôles sur fond bleu */
}

.record-btn.recording {
  background: var(--red);
  border-color: var(--red-d);
  color: white;
  animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 0, 79, 0.4);
  }

  70% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(255, 0, 79, 0);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 0, 79, 0);
  }
}

.recording-indicator {
  display: none;
  /* Masqué par défaut */
  align-items: center;
  gap: 8px;
  color: var(--red);
  font-weight: 700;
  font-size: 0.9rem;
  margin-right: 10px;
  white-space: nowrap;
}

.recording-indicator .dot {
  width: 8px;
  height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: blink 1s infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.bubble-wrap {
  transition: transform .2s;
  will-change: transform;
}

/* ── Indicateur de page dans le viewer PDF ── */
.page-indicator-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-radius: var(--radius-full);
  color: white;
  font-size: 1.05rem;
  font-weight: 800;
  font-family: var(--font);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.page-indicator-dot {
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}