/* ================================================
   REPÈRE ACADÉMIQUE — CSS Application PWA
   Palette : Bleu Royal #1e3a8a, Or #d4a017, Blanc
================================================ */

:root {
  --primary: #1e3a8a;
  --primary-light: #2d4fa3;
  --primary-dark: #162d6e;
  --gold: #d4a017;
  --gold-light: #f0c040;
  --success: #0d9488;
  --warning: #d97706;
  --danger: #dc2626;
  --purple: #7c3aed;
  --bg: #f0f4ff;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --topbar-h: 64px;
  --bottom-nav-h: 72px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(30,58,138,0.10);
  --shadow-lg: 0 8px 32px rgba(30,58,138,0.18);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  height: 100%;
}

/* ════════ TOPBAR ════════ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

.topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.topbar-center { display: flex; align-items: center; justify-content: center; }
.topbar-right { display: flex; align-items: center; }

.app-logo { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.logo-icon-img { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; }
.logo-text { color: white; font-family: 'Space Grotesk', sans-serif; font-size: 13px; display: none; }
.logo-text strong { color: var(--gold-light); }

@media (min-width: 400px) { .logo-text { display: block; } }

/* Sélecteur établissement */
.etab-switcher { position: relative; }

.etab-current {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  color: white;
  font-size: 13px;
  font-weight: 500;
  max-width: 180px;
  transition: background 0.2s;
}
.etab-current:hover { background: rgba(255,255,255,0.25); }
.etab-color-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); flex-shrink: 0; }
.etab-current span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { width: 14px; height: 14px; flex-shrink: 0; transition: transform 0.2s; }
.etab-current.open .chevron { transform: rotate(180deg); }

.etab-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 200;
  overflow: hidden;
}
.etab-dropdown.open { display: block; animation: slideDown 0.15s ease; }

.etab-dropdown-header {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.etab-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}
.etab-dropdown-item:hover { background: var(--bg); }
.etab-dropdown-item.active { background: #eff6ff; font-weight: 600; color: var(--primary); }
.etab-dropdown-item .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.etab-add-btn {
  padding: 10px 14px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-top: 1px solid var(--border);
}
.etab-add-btn:hover { background: var(--bg); }

/* Témoin réseau */
.network-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(255,255,255,0.12);
  color: white;
  transition: all 0.3s;
}
.network-indicator svg { width: 14px; height: 14px; }
.network-indicator.offline { background: rgba(234,88,12,0.3); }
.network-indicator.offline svg { stroke: #fb923c; }

/* Avatar */
.user-avatar { cursor: pointer; position: relative; }
.avatar-circle {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  font-family: 'Space Grotesk', sans-serif;
  border: 2px solid rgba(255,255,255,0.4);
  transition: transform 0.2s;
}
.avatar-circle:hover { transform: scale(1.05); }

/* Menu profil */
.profile-menu {
  position: absolute;
  top: calc(var(--topbar-h) + 4px);
  right: 8px;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 200;
  overflow: hidden;
}
.profile-menu.open { display: block; animation: slideDown 0.15s ease; }

.profile-menu-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
}
.pm-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.pm-name { font-weight: 600; font-size: 13px; }
.pm-email { font-size: 11px; opacity: 0.8; }

.pm-divider { height: 1px; background: var(--border); }

.pm-item {
  padding: 11px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pm-item:hover { background: var(--bg); }
.pm-admin { color: var(--text-muted); font-size: 12px; }
.pm-version { color: var(--text-light); font-size: 11px; justify-content: flex-end; cursor: default; }

/* ════════ BOTTOM NAV ════════ */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-light);
  font-size: 10px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s;
  min-width: 48px;
}
.nav-item svg { width: 22px; height: 22px; transition: all 0.2s; }
.nav-item:hover, .nav-item.active { color: var(--primary); }
.nav-item.active svg { stroke: var(--primary); }

.nav-add {
  width: 52px; height: 52px;
  background: var(--primary);
  border-radius: 50%;
  color: white !important;
  box-shadow: 0 4px 12px rgba(30,58,138,0.4);
  font-size: 0;
}
.nav-add svg { width: 26px; height: 26px; stroke: white !important; }

/* ════════ VIEWS ════════ */
.view {
  display: none;
  padding: calc(var(--topbar-h) + 16px) 16px calc(var(--bottom-nav-h) + 16px);
  min-height: 100vh;
}
.view.active { display: block; animation: fadeIn 0.2s ease; }

/* ════════ PAGE HEADER ════════ */
.page-header { margin-bottom: 20px; }
.page-greeting { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.page-title { font-family: 'Space Grotesk', sans-serif; font-size: 24px; font-weight: 700; color: var(--text); }
.page-sub { font-size: 13px; color: var(--primary); font-weight: 500; margin-top: 2px; }

/* ════════ STATS GRID ════════ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border-left: 4px solid var(--card-accent, var(--primary));
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-icon { font-size: 22px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; font-family: 'Space Grotesk', sans-serif; color: var(--text); line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ════════ CARDS ════════ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* ════════ SÉANCES LIST ════════ */
.section-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.seances-list { display: flex; flex-direction: column; gap: 10px; }

.seance-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  cursor: pointer;
  transition: all 0.2s;
}
.seance-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.seance-card.offline { border-left-color: var(--warning); }

.seance-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.seance-matiere {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: #eff6ff;
  color: var(--primary);
}
.seance-matiere.pc { background: #f0fdf4; color: #166534; }
.seance-date { font-size: 11px; color: var(--text-muted); }
.seance-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.seance-resume { font-size: 12px; color: var(--text-muted); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.seance-footer { display: flex; justify-content: space-between; margin-top: 8px; }
.seance-classe { font-size: 11px; font-weight: 500; color: var(--primary); }
.seance-duree { font-size: 11px; color: var(--text-muted); }
.sync-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--warning); margin-right: 4px; }

/* ════════ FILTER ROW ════════ */
.filter-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.filter-row select {
  flex: 1;
  min-width: 140px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
}

/* ════════ SEARCH ════════ */
.search-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.search-tab {
  flex: 1;
  min-width: 140px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
  position: relative;
}
.search-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

.online-badge {
  display: inline-block;
  font-size: 9px;
  background: rgba(255,255,255,0.2);
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: 4px;
}

.search-panel { display: none; }
.search-panel.active { display: block; animation: fadeIn 0.2s; }

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}
.search-box:focus-within { border-color: var(--primary); }
.search-box svg { width: 18px; height: 18px; stroke: var(--text-muted); flex-shrink: 0; }
.search-box input { flex: 1; border: none; outline: none; font-size: 14px; background: transparent; }

.ai-options { display: flex; gap: 8px; margin-bottom: 16px; }
.ai-options select { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; }

.formules-grid { display: flex; flex-direction: column; gap: 10px; }

.formule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.formule-title { font-weight: 700; font-size: 14px; color: var(--primary); margin-bottom: 8px; }
.formule-main {
  font-family: 'Space Grotesk', monospace;
  font-size: 16px;
  font-weight: 600;
  background: #f8faff;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  margin-bottom: 10px;
  overflow-x: auto;
}
.formule-vars { font-size: 12px; color: var(--text-muted); line-height: 1.8; }
.formule-astuce {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fffbeb;
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  font-size: 12px;
  color: #78350f;
}
.formule-badge { display: inline-block; font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; margin-bottom: 8px; background: #eff6ff; color: var(--primary); }

.ai-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.ai-result-header { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--purple); margin-bottom: 12px; }
.ai-result-text { font-size: 14px; line-height: 1.7; color: var(--text); }
.ai-astuce {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fffbeb;
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  color: #78350f;
}
.ai-loading { text-align: center; padding: 24px; color: var(--text-muted); }
.ai-loading .spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 12px; }

/* ════════ EXPORTS ════════ */
.export-form { margin-bottom: 0; }
.btn-large { width: 100%; margin-top: 8px; }

.export-preview-placeholder {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.export-preview-placeholder .empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ════════ MODALS ════════ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.6);
  backdrop-filter: blur(4px);
  z-index: 300;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s; }

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}
.modal-large { max-height: 92vh; }

@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); margin: 16px; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; font-family: 'Space Grotesk', sans-serif; }
.modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--bg);
  border-radius: 50%; cursor: pointer;
  font-size: 16px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
}

.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ════════ FORMS ════════ */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.3px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ════════ BUTTONS ════════ */
.btn-primary {
  padding: 11px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); }
.btn-primary:active { transform: none; }

.btn-secondary {
  padding: 11px 20px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

/* ════════ ADMIN TABS ════════ */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--bg); padding: 4px; border-radius: 8px; }
.admin-tab { flex: 1; padding: 8px; border: none; background: transparent; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text-muted); }
.admin-tab.active { background: white; color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* ════════ EMPTY STATE ════════ */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.7; }

/* ════════ TOAST ════════ */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 400;
  opacity: 0;
  transition: all 0.3s;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #0d9488; }
.toast.error { background: var(--danger); }

/* ════════ ANIMATIONS ════════ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
