:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --text: #1c2033;
  --muted: #6b7189;
  --accent: #4f5bd5;
  --accent-soft: #eceefe;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 50, .04), 0 4px 16px rgba(20, 24, 50, .06);
  --shadow-hover: 0 2px 4px rgba(20, 24, 50, .06), 0 10px 28px rgba(20, 24, 50, .10);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c; --surface: #1a1d28; --surface-2: #222634; --border: #2c3142;
    --text: #e8eaf2; --muted: #9298ad; --accent: #8790ff; --accent-soft: #262a48;
    --danger: #ff7272; --danger-soft: #3a2228;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --shadow-hover: 0 2px 4px rgba(0,0,0,.35), 0 10px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.loading { padding: 4rem; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- boutons & champs ---------- */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .5rem .9rem; border-radius: 10px; display: inline-flex; align-items: center; gap: .4rem;
  transition: background .15s, border-color .15s, transform .05s; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn-sm { padding: .3rem .6rem; font-size: 13px; border-radius: 8px; }

input, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 110px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 .35rem; }
.field { margin-bottom: 1rem; }
.error { color: var(--danger); font-size: 14px; min-height: 1.3em; margin: .2rem 0 .6rem; }

/* ---------- connexion ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 2.2rem 2rem; box-shadow: var(--shadow); }
.login-card .logo { font-size: 40px; }
.login-card h1 { font-size: 24px; margin: .4rem 0 .2rem; }
.login-card p { color: var(--muted); margin: 0 0 1.6rem; }
.login-card button { width: 100%; justify-content: center; padding: .7rem; }

/* ---------- structure ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: .7rem 1.25rem; display: flex; align-items: center; gap: 1rem; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: 14px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px;
  color: #fff; flex: none; }
main { max-width: 1120px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { font-size: 28px; }
.page-head p { margin: .3rem 0 0; color: var(--muted); }
.search { max-width: 280px; }

/* ---------- grille des sujets ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.topic-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem;
  box-shadow: var(--shadow); color: var(--text); display: flex; flex-direction: column; gap: .5rem; min-height: 170px;
  transition: box-shadow .2s, transform .2s, border-color .2s; }
.topic-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); text-decoration: none; border-color: var(--accent); }
.topic-icon { font-size: 30px; width: 52px; height: 52px; border-radius: 14px; background: var(--accent-soft); display: grid; place-items: center; }
.topic-card h3 { font-size: 17px; }
.topic-card .desc { color: var(--muted); font-size: 14px; flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { color: var(--muted); font-size: 13px; display: flex; gap: .9rem; flex-wrap: wrap; }
.new-card { border: 2px dashed var(--border); background: transparent; box-shadow: none; align-items: center; justify-content: center;
  color: var(--muted); font-weight: 600; cursor: pointer; font-size: 15px; }
.new-card .plus { font-size: 32px; line-height: 1; }
.new-card:hover { color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* ---------- page sujet ---------- */
.back { color: var(--muted); font-size: 14px; display: inline-block; margin-bottom: 1rem; }
.topic-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.8rem; flex-wrap: wrap; }
.topic-head .topic-icon { width: 64px; height: 64px; font-size: 36px; }
.topic-head h1 { font-size: 28px; }
.topic-head p { margin: .25rem 0 0; color: var(--muted); }
.topic-head .actions { margin-left: auto; display: flex; gap: .4rem; }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.4rem; }
.tab { border: none; background: none; border-radius: 0; padding: .7rem 1rem; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { background: none; color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.badge { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 0 .5rem; font-size: 12px; }
.tab.active .badge { background: var(--accent-soft); color: var(--accent); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* zone de dépôt */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.6rem; text-align: center; color: var(--muted);
  margin-bottom: 1.2rem; transition: border-color .15s, background .15s; cursor: pointer; background: var(--surface); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone strong { color: var(--accent); }
.uploads { margin-bottom: 1rem; display: grid; gap: .5rem; }
.upload-row { display: flex; align-items: center; gap: .8rem; font-size: 14px; }
.upload-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { width: 160px; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }

.file-list { list-style: none; margin: 0; padding: 0; }
.file-row { display: flex; align-items: center; gap: .9rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: none; }
.file-thumb { width: 46px; height: 46px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center;
  font-size: 22px; flex: none; overflow: hidden; cursor: pointer; }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; color: var(--text); cursor: pointer; }
.file-name:hover { color: var(--accent); }
.file-actions { display: flex; gap: .3rem; flex: none; }

/* notes */
.note-form { padding: 1.1rem; margin-bottom: 1.2rem; }
.note-form .row { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; }
.notes { display: grid; gap: 1rem; }
.note { padding: 1.1rem 1.2rem; }
.note-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.note-head .who { font-weight: 600; font-size: 14px; }
.note-head .when { color: var(--muted); font-size: 13px; }
.note-head .actions { margin-left: auto; display: flex; gap: .2rem; }
.note h3 { font-size: 16px; margin-bottom: .3rem; }
.note-body { white-space: pre-wrap; word-wrap: break-word; }

/* composer + pièces jointes */
.composer { padding: 1.1rem 1.2rem; margin-bottom: 1.4rem; display: grid; gap: .6rem; transition: border-color .15s, background .15s; }
.composer.over { border-color: var(--accent); background: var(--accent-soft); }
.composer .note-head { margin-bottom: 0; }
.composer .row { display: flex; align-items: center; gap: .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips:empty { display: none; }
.chip { position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: .35rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: .25rem .3rem .25rem .6rem; font-size: 13px; max-width: 100%; }
.chip small { color: var(--muted); }
.chip .bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; }
.chip .bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.note-head .who + .when, .note-head div > .when { font-size: 12.5px; }
.attach { margin-top: .8rem; display: grid; gap: .5rem; }
.attach-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.attach-img { position: relative; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.attach-img img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.attach-img button { position: absolute; top: 4px; right: 4px; background: var(--surface); }
.attach-file { display: flex; align-items: center; gap: .7rem; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.attach-file .file-thumb { width: 38px; height: 38px; font-size: 19px; background: var(--surface); }

/* fenêtres */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 25, .5); display: grid; place-items: center; padding: 1rem; z-index: 50;
  animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 460px; padding: 1.6rem; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { font-size: 20px; margin-bottom: 1.2rem; }
.modal .row { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.icons { display: flex; flex-wrap: wrap; gap: .3rem; }
.icons button { font-size: 20px; padding: .3rem .45rem; border-radius: 8px; }
.icons button.sel { border-color: var(--accent); background: var(--accent-soft); }
.viewer { max-width: min(1100px, 96vw); width: auto; padding: .8rem; }
.viewer-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.viewer-head .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer img, .viewer video { max-width: 100%; max-height: 80vh; display: block; margin: 0 auto; border-radius: 8px; }
.viewer iframe { width: min(1060px, 92vw); height: 80vh; border: none; border-radius: 8px; background: #fff; }

.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .65rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow-hover); z-index: 100; font-size: 14px; animation: fade .2s; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 640px) {
  main { padding: 1.2rem 1rem 3rem; }
  .page-head h1, .topic-head h1 { font-size: 23px; }
  .search { max-width: none; width: 100%; }
  .user-chip .uname { display: none; }
  .file-row { flex-wrap: wrap; }
  .file-actions { width: 100%; justify-content: flex-end; }
  .progress { width: 90px; }
  .topic-head .actions { margin-left: 0; }
}
