/* ============================================================
   INTERNATE V3 — Global Stylesheet
   ============================================================ */

@import url('theme.css');
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Texture de fond */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ---- SIDEBAR LAYOUT ---- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 14px;
  overflow-y: auto;
  z-index: 50;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.04em;
  background: var(--gen-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 4px 10px 20px;
  text-decoration: none;
  display: block;
}

body.filiere-techno .sidebar-logo {
  background: var(--tech-gradient);
  -webkit-background-clip: text;
  background-clip: text;
}

.sidebar-filiere-badge {
  margin: 0 10px 20px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

.badge-gen {
  background: rgba(108,99,255,0.15);
  color: var(--gen-primary);
  border: 1px solid rgba(108,99,255,0.25);
}

.badge-tech {
  background: rgba(255,107,53,0.15);
  color: var(--tech-primary);
  border: 1px solid rgba(255,107,53,0.25);
}

.nav-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 10px;
  margin: 20px 0 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.18s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: 'DM Sans', sans-serif;
}

.nav-item .ni { font-size: 1rem; width: 22px; text-align: center; flex-shrink: 0; }

.nav-item:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

.nav-item.active {
  color: var(--accent);
  background: rgba(108,99,255,0.1);
  font-weight: 600;
}

body.filiere-techno .nav-item.active {
  color: var(--tech-primary);
  background: rgba(255,107,53,0.1);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.user-tile:hover { background: rgba(255,255,255,0.04); }

.avatar {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--gen-gradient);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}

body.filiere-techno .avatar { background: var(--tech-gradient); }

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-name { font-size: 0.85rem; font-weight: 600; }
.user-role { font-size: 0.7rem; color: var(--muted); }

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.2s;
}
.btn-logout:hover { color: var(--red); background: rgba(255,71,87,0.08); }

/* ---- MAIN CONTENT ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 36px 44px;
  min-height: 100vh;
  animation: fadeUp 0.4s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- TOPBAR ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
}

.page-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1.9rem;
  letter-spacing: -0.04em;
}

.page-subtitle { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }

.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  width: 280px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
}
.search-input input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.87rem;
  width: 100%;
}
.search-input input::placeholder { color: var(--muted); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 9px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-btn-hover);
}

.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); border-color: var(--border2); }

body.filiere-techno .btn-primary {
  background: var(--tech-primary);
  box-shadow: var(--shadow-btn);
}
body.filiere-techno .btn-primary:hover { box-shadow: var(--shadow-btn-hover); }

/* ---- CARDS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition: all 0.22s;
}
.card:hover {
  border-color: var(--border2);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

/* ---- GRID LAYOUTS ---- */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* ---- SECTION HEADER ---- */
.section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-hd h2 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.see-all {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.2s;
}
.see-all:hover { opacity: 0.7; }

/* ---- FORM STYLES ---- */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

.form-input {
  width: 100%;
  padding: 13px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.92rem;
  outline: none;
  transition: all 0.22s;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.13);
  background: var(--surface3);
}
.form-input::placeholder { color: var(--muted); opacity: 0.7; }
.form-input.valid { border-color: var(--green); }
.form-input.invalid { border-color: var(--red); }

/* ---- CHIPS / TAGS ---- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.chip-gen { background: rgba(108,99,255,0.15); color: #a8a3ff; }
.chip-tech { background: rgba(255,107,53,0.15); color: #ffa07a; }
.chip-maths { background: rgba(84,160,255,0.15); color: #54a0ff; }
.chip-philo { background: rgba(167,139,250,0.15); color: #a78bfa; }
.chip-hist { background: rgba(255,169,77,0.15); color: #ffa94d; }
.chip-phys { background: rgba(0,212,170,0.15); color: #00d4aa; }
.chip-info { background: rgba(52,211,153,0.15); color: #34d399; }
.chip-anglais { background: rgba(244,114,182,0.15); color: #f472b6; }
.chip-esp { background: rgba(251,191,36,0.15); color: #fbbf24; }
.chip-eps { background: rgba(239,68,68,0.15); color: #ef4444; }
.chip-default { background: rgba(255,255,255,0.08); color: var(--text2); }

/* ---- ALERTS ---- */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 9px;
  font-size: 0.85rem;
  margin-top: 14px;
}
.alert-error { background: rgba(255,71,87,0.1); border: 1px solid rgba(255,71,87,0.2); color: var(--red); }
.alert-success { background: rgba(0,212,170,0.1); border: 1px solid rgba(0,212,170,0.2); color: var(--green); }
.alert-info { background: rgba(84,160,255,0.1); border: 1px solid rgba(84,160,255,0.2); color: var(--blue); }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ---- ANIMATIONS ---- */
@keyframes slideRight { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%,100% { opacity:1; transform:scale(1); } 50% { opacity:0.5; transform:scale(0.8); } }

.reveal { opacity: 0; transform: translateY(30px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.visible { opacity: 1; transform: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 20px; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ---- PAGE TRANSITIONS ---- */
@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pageSlide {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.main, .main-content { animation: pageIn 0.4s ease both; }

/* ---- PULL-TO-REFRESH ---- */
#ptrOverlay {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  height: 60px; z-index: 9999;
  align-items: flex-end; justify-content: center; padding-bottom: 8px;
}
#ptrOverlay.visible { display: flex; }
#ptrOverlay.loading .ptr-spinner { animation: spin 0.8s linear infinite; }
.ptr-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
}

/* ---- SKELETON LOADERS ---- */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-card { height: 160px; }
.skel-line { height: 14px; margin-bottom: 10px; width: 100%; }
.skel-line.w60 { width: 60%; }
.skel-line.w40 { width: 40%; }
.skel-avatar { width: 44px; height: 44px; border-radius: 50%; }
.skel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.skel-grid .skel-card { padding: 20px; }
.skel-grid .skel-card .skel-line:first-child { height: 80px; margin-bottom: 16px; }

/* ---- NOTIFICATION BELL ---- */
.notif-btn {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; text-decoration: none;
  color: var(--muted); font-size: 0.85rem; font-weight: 500;
  transition: all 0.18s; cursor: pointer; border: none;
  background: none; width: 100%; text-align: left; font-family: 'DM Sans', sans-serif;
}
.notif-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.notif-badge {
  display: none; position: absolute; top: 2px; right: 8px;
  min-width: 18px; height: 18px;
  background: var(--red); color: white; font-size: 0.6rem; font-weight: 700;
  border-radius: 100px; align-items: center; justify-content: center;
  padding: 0 4px; box-shadow: 0 0 0 2px var(--surface);
}

/* ---- NOTIFICATION PANEL ---- */
.notif-panel {
  display: none; position: fixed; top: 0; right: 0; bottom: 0;
  width: 360px; max-width: 92vw; background: var(--surface);
  border-left: 1px solid var(--border); z-index: 200;
  flex-direction: column; animation: slideIn 0.25s ease both;
  box-shadow: -10px 0 40px rgba(0,0,0,0.5);
}
.notif-panel.open { display: flex; }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.notif-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.notif-panel-header h3 { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 1.1rem; }
.notif-panel-close {
  width: 36px; height: 36px; border-radius: 8px; border: none;
  background: var(--surface3); color: var(--muted); font-size: 1.2rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.notif-panel-close:hover { background: var(--surface2); color: var(--text); }
.notif-list { flex: 1; overflow-y: auto; padding: 12px 16px; }
.notif-item {
  display: flex; gap: 12px; padding: 12px 14px; border-radius: 10px;
  margin-bottom: 6px; cursor: pointer; transition: background 0.2s;
}
.notif-item:hover { background: rgba(255,255,255,0.03); }
.notif-item.unread { background: rgba(108,99,255,0.06); border-left: 3px solid var(--accent); }
.notif-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.notif-icon.levelup { background: rgba(108,99,255,0.15); }
.notif-icon.comment { background: rgba(0,212,170,0.15); }
.notif-icon.class { background: rgba(255,169,77,0.15); }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.notif-body p { font-size: 0.75rem; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.notif-time { font-size: 0.65rem; color: var(--muted); margin-top: 4px; }
.notif-empty { text-align: center; padding: 60px 20px; color: var(--muted); font-size: 0.88rem; }
.notif-mark-read {
  padding: 10px 24px; text-align: center; border-top: 1px solid var(--border);
  font-size: 0.8rem; color: var(--accent); cursor: pointer; font-weight: 500;
}
.notif-mark-read:hover { background: rgba(108,99,255,0.05); }

/* ---- PWA INSTALL BTN ---- */
#installBtn { display: none; }

/* ---- COURSE COMPLETION ---- */
.course-complete-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; cursor: pointer; user-select: none;
}
.course-complete-toggle input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--accent2); cursor: pointer;
}
.course-complete-toggle label { font-size: 0.78rem; color: var(--muted); cursor: pointer; }
.cours-card.completed { opacity: 0.65; }
.cours-card.completed .cours-title { text-decoration: line-through; text-decoration-color: var(--muted); }

/* ---- PROGRESS BAR ---- */
.progress-bar {
  width: 100%; height: 6px; background: var(--surface2); border-radius: 100px; overflow: hidden; margin-top: 12px;
}
.progress-fill {
  height: 100%; background: var(--gen-gradient); border-radius: 100px; transition: width 0.5s ease;
}
.progress-text { font-size: 0.72rem; color: var(--muted); margin-top: 4px; text-align: right; }

/* ---- XP / GAMIFICATION ---- */
.xp-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 100px;
  background: rgba(108,99,255,0.12); color: var(--accent);
  font-size: 0.7rem; font-weight: 700;
}
.level-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--gen-gradient); color: white;
  font-size: 0.65rem; font-weight: 800;
}
.streak-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.75rem; color: var(--orange); font-weight: 600;
}

/* ---- AVATAR UPLOAD ---- */
.avatar-upload {
  position: relative; display: inline-block; cursor: pointer;
}
.avatar-upload .avatar-overlay {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s; font-size: 1.2rem;
}
.avatar-upload:hover .avatar-overlay { opacity: 1; }
.avatar-upload input[type="file"] { display: none; }

@media (max-width: 600px) {
  .grid-3, .grid-4, .grid-2 { grid-template-columns: 1fr; }
  .toast-container { top: 12px; right: 50%; transform: translateX(50%); }
  .toast { max-width: 90vw; }
  .notif-panel { width: 100vw; max-width: 100vw; }
}