/* ==========================================================================
   Cours GenAI — feuille de style
   Palette : indigo/violet sur fond neutre, accent clair pour les statuts
   (succès, avertissement 25 Mo). Deux thèmes via [data-theme].
   ========================================================================== */

:root {
  --bg: #f6f7fb;
  --bg-elevated: #ffffff;
  --bg-sidebar: #ffffff;
  --border: #e2e4ef;
  --text: #1a1b2e;
  --text-muted: #5b5e78;
  --accent: #5b4bf5;
  --accent-2: #8a5cf6;
  --accent-contrast: #ffffff;
  --success: #16a37a;
  --warning: #c2790a;
  --danger: #d63a4b;
  --focus-ring: #5b4bf5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(24, 24, 55, 0.06), 0 8px 24px rgba(24, 24, 55, 0.06);
  --font-body: "Source Sans Pro", "Segoe UI", system-ui, sans-serif;
  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #10111d;
  --bg-elevated: #171929;
  --bg-sidebar: #14151f;
  --border: #2a2c42;
  --text: #eef0fb;
  --text-muted: #9498b8;
  --accent: #8a7bff;
  --accent-2: #b58cff;
  --accent-contrast: #10111d;
  --success: #37d6a3;
  --warning: #f0a63a;
  --danger: #ff6b7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.55rem 0.9rem;
  transition: border-color 0.15s ease, transform 0.05s ease;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast);
  border: none;
  font-weight: 600;
}
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-quiet { border-color: transparent; background: transparent; }

input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}

/* ---------------------------------------------------------------- layout */

#app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
}

header.site-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.profil-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.profil-header-text { line-height: 1.2; }
.profil-header-text .nom { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.profil-header-text .accroche { color: var(--text-muted); font-size: 0.85rem; }

header.site-header .spacer { flex: 1; }

aside.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem;
}

main.viewer-area {
  grid-area: main;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------------------------------------------------------------- sidebar */

.matiere-group { margin-bottom: 0.4rem; }

.matiere-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.55rem 0.5rem;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 600;
}
.matiere-toggle:hover { background: var(--bg); }
.matiere-toggle .chevron { transition: transform 0.15s ease; color: var(--text-muted); }
.matiere-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.matiere-progress-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  margin: 0.15rem 0.4rem 0.4rem;
}
.matiere-progress-bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
}

.section-list { padding-left: 1.4rem; }
.section-title {
  font-size: 0.75rem; text-transform: none; color: var(--text-muted);
  margin: 0.5rem 0 0.15rem;
}

.contenu-item {
  display: flex; align-items: center; gap: 0.5rem;
  width: 100%; text-align: left; border: none; background: transparent;
  padding: 0.4rem 0.5rem; border-radius: var(--radius);
  color: var(--text); font-size: 0.9rem;
}
.contenu-item:hover { background: var(--bg); }
.contenu-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.contenu-item .check { color: var(--success); width: 1rem; flex-shrink: 0; }
.contenu-item .titre { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- viewer */

.viewer-toolbar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.viewer-toolbar h2 { font-family: var(--font-display); font-size: 1rem; margin: 0; flex: 1; font-weight: 600; }

.viewer-frame-wrap { flex: 1; overflow: auto; position: relative; }
.viewer-frame-wrap iframe, .viewer-frame-wrap embed {
  width: 100%; height: 100%; border: none; background: #fff;
}
.viewer-html, .viewer-docx {
  max-width: 900px; margin: 0 auto; padding: 2rem;
  background: var(--bg-elevated); min-height: 100%;
}

.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 0.5rem; padding: 2rem; text-align: center;
}

/* ---------------------------------------------------------------- search modal */

.search-overlay {
  position: fixed; inset: 0; background: rgba(10, 10, 25, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 10vh; z-index: 60;
}
.search-overlay[hidden] { display: none; }
.search-box {
  width: min(560px, 92vw); background: var(--bg-elevated);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  border: 1px solid var(--border);
}
.search-box input {
  border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  padding: 1rem; font-size: 1.05rem;
}
.search-results { max-height: 50vh; overflow-y: auto; }
.search-results .result {
  display: flex; flex-direction: column; gap: 0.15rem;
  width: 100%; text-align: left; border: none; background: transparent;
  padding: 0.7rem 1rem; border-radius: 0;
}
.search-results .result:hover, .search-results .result.selected { background: var(--bg); }
.search-results .result .path { font-size: 0.75rem; color: var(--text-muted); }
.search-empty { padding: 1.25rem; color: var(--text-muted); text-align: center; }

/* ---------------------------------------------------------------- modal (confirmation, forms) */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 10, 25, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 70;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: min(480px, 92vw); background: var(--bg-elevated);
  border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); padding: 1.25rem;
}
.modal h3 { margin-top: 0; font-family: var(--font-display); }
.modal .actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.modal.modal-wide { width: min(680px, 94vw); }

.field { margin-bottom: 0.85rem; }
.field label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }
.hint.warning { color: var(--warning); }
.hint.danger { color: var(--danger); }

/* ---------------------------------------------------------------- misc */

.badge {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.72rem; background: var(--bg); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.teacher { color: var(--accent); border-color: var(--accent); }

.icon-btn {
  border: none; background: transparent; padding: 0.35rem; border-radius: var(--radius);
  color: var(--text-muted); display: inline-flex;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

.email-list { list-style: none; margin: 0; padding: 0; }
.email-list li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}
.email-list li .addr { flex: 1; }

#toast-region {
  position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column;
  gap: 0.5rem; z-index: 90;
}
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: var(--radius); padding: 0.7rem 1rem; font-size: 0.9rem;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

/* ---------------------------------------------------------------- login */

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--accent) 16%, var(--bg)), var(--bg) 60%);
}
.login-card {
  width: min(380px, 92vw); background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem;
}
.login-card h1 { font-family: var(--font-display); font-size: 1.4rem; margin-top: 0; }
.login-card p.lede { color: var(--text-muted); margin-top: -0.5rem; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  #app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "sidebar"
      "main";
    height: auto;
    min-height: 100vh;
  }
  aside.sidebar { max-height: 40vh; }
  main.viewer-area { min-height: 60vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
