:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1c1b22;
  --muted: #6b6975;
  --border: #e4e1d8;
  --accent: #4b45d6;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfd;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --warn: #9a5a06;
  --warn-soft: #fdf1dc;
  --error: #c0392b;
  --error-soft: #fbe6e3;
  --rec: #e5383b;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 18 40 / 6%), 0 4px 16px rgb(20 18 40 / 5%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141417;
    --surface: #1d1d22;
    --surface-2: #26262c;
    --text: #ececf1;
    --muted: #9a98a6;
    --border: #303038;
    --accent: #8f8afc;
    --accent-ink: #14131f;
    --accent-soft: #2a2850;
    --ok: #4cc382;
    --ok-soft: #183526;
    --warn: #f0b45a;
    --warn-soft: #3a2c14;
    --error: #ff7b6e;
    --error-soft: #3d1c19;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
body.modal-open { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px max(16px, env(safe-area-inset-left));
  min-height: 58px;
}
.topbar .logo { border-radius: 8px; flex: none; }
.titles { flex: 1; min-width: 0; }
.titles h1 { margin: 0; font-size: 1.08rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 4px; align-items: center; }

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-left)) 96px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
section > .section-head, .card > .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 { margin: 0; font-size: 1.05rem; font-weight: 650; }

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

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; flex-wrap: wrap; }
.row.center { justify-content: center; }
.row-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .row-2 { grid-template-columns: 1fr 1fr; } }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.center { text-align: center; }
.center-block { display: flex; justify-content: center; padding: 8px 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 10px 0 0; }
.lead { margin: 0 0 4px; color: var(--muted); }
.ok-text { color: var(--ok); display: inline-flex; vertical-align: -2px; }
.warn-text { color: var(--warn); }
.error-text { color: var(--error); }
.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--surface-2);
  margin-right: 6px;
}
.footer-actions { margin-top: 8px; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--error); }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 0.88rem; }
.btn.block { width: 100%; }
.btn.big { min-height: 52px; padding: 10px 22px; font-size: 1.05rem; border-radius: 14px; }
.btn.round { width: 52px; height: 52px; border-radius: 50%; padding: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover, .icon-btn.active { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--error); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon { flex: none; }

/* ---------- Formulaires ---------- */

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* évite le zoom automatique d'iOS */
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.5; }
textarea.editor { min-height: 50vh; font-family: var(--mono); font-size: 14px; }

/* ---------- Listes ---------- */

.grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }
.course-card { display: flex; align-items: center; gap: 12px; color: var(--text); padding: 14px; }
.course-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.course-card > .icon:last-child { color: var(--muted); }
.course-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}
.course-name { font-weight: 650; }

.list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row > .icon { color: var(--muted); }
.row-title { font-weight: 600; }

.chip {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.error { background: var(--error-soft); color: var(--error); }
.chip.busy { background: var(--accent-soft); color: var(--accent); }

/* ---------- Bannières, états ---------- */

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.92rem;
  margin-bottom: 12px;
}
.banner.stack { flex-direction: column; align-items: stretch; }
.banner.info { background: var(--accent-soft); }
.banner.warn { background: var(--warn-soft); }
.banner.error { background: var(--error-soft); color: var(--error); }
.banner.top { border-radius: 0; margin: 0; justify-content: center; text-align: center; }
.page > .banner { margin-bottom: 0; }
.pending-rec { display: flex; align-items: center; gap: 6px; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty p { margin: 0; }
.loading { display: grid; place-items: center; padding: 32px; }
.loading.full { min-height: 100vh; }

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  display: inline-block;
  flex: none;
}
.spinner.small { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s; }

/* ---------- Séance ---------- */

.seance-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.title-input {
  flex: 1 1 240px;
  font-size: 1.45rem;
  font-weight: 700;
  border-color: transparent;
  background: transparent;
  padding: 6px 8px;
  margin-left: -8px;
}
.title-input:hover { border-color: var(--border); }
.date-input { width: auto; flex: none; background: var(--surface); }

.add-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.btn.add {
  flex-direction: column;
  gap: 4px;
  min-height: 72px;
  font-size: 0.88rem;
  background: var(--surface-2);
  border-color: transparent;
}
.btn.add:hover { background: var(--accent-soft); color: var(--accent); }

.sources { display: flex; flex-direction: column; gap: 6px; }
.source {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 10px 10px 12px;
  display: flex;
  flex-direction: column;
}
.source:not(:has(.source-main)) { flex-direction: row; align-items: center; gap: 10px; }
.source.error { border-color: color-mix(in srgb, var(--error) 35%, var(--border)); }
.source-main { display: flex; align-items: center; gap: 10px; }
.source-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  flex: none;
}
.source-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.source-content {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  max-height: 60vh;
  overflow: auto;
}

.dropzone {
  position: fixed;
  inset: 12px;
  z-index: 50;
  border: 3px dashed var(--accent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--accent-soft) 85%, transparent);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 650;
  color: var(--accent);
  pointer-events: none;
}

/* ---------- Notes ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.toolbar-icons { display: flex; gap: 2px; margin-left: auto; }
@media (max-width: 559px) {
  .toolbar .btn.primary { flex: 1 1 100%; }
  .toolbar .btn:not(.primary) { flex: 1 1 auto; }
}
.generating { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.md.streaming { opacity: 0.85; }
.md.streaming > :last-child::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1 { font-size: 1.45rem; margin: 1.2em 0 0.4em; }
.md h2 { font-size: 1.2rem; margin: 1.5em 0 0.4em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.05rem; margin: 1.3em 0 0.3em; }
.md h4 { font-size: 1rem; margin: 1.1em 0 0.3em; }
.md p { margin: 0.5em 0; }
.md ul, .md ol { padding-left: 1.4em; margin: 0.4em 0; }
.md li { margin: 0.2em 0; }
.md li > ul, .md li > ol { margin: 0.1em 0; }
.md em:only-child { color: var(--muted); }
.md code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0.6em 0; padding: 0.2em 0 0.2em 1em; border-left: 3px solid var(--accent); color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0.8em 0; font-size: 0.92rem; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md img { max-width: 100%; }

/* ---------- Transcription ---------- */

.transcript { border: 1px solid var(--border); border-radius: 12px; margin-top: 8px; }
.transcript summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  cursor: pointer;
  list-style: none;
  font-weight: 550;
}
.transcript summary::-webkit-details-marker { display: none; }
.transcript summary > .icon { transition: transform 0.2s; transform: rotate(-90deg); color: var(--muted); }
.transcript[open] summary > .icon { transform: none; }
.transcript-bar {
  position: sticky;
  top: calc(59px + env(safe-area-inset-top));
  z-index: 5;
  background: var(--surface);
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.transcript-bar audio { width: 100%; height: 40px; }
.transcript-body { padding: 4px 12px 12px; max-height: 70vh; overflow: auto; }
.transcript-body p { margin: 0; padding: 8px 6px; border-radius: 8px; line-height: 1.6; }
.transcript-body p.active { background: var(--accent-soft); }
.ts {
  font: 600 0.78rem var(--mono);
  color: var(--accent);
  background: var(--accent-soft);
  border: 0;
  border-radius: 6px;
  padding: 1px 6px;
  margin-right: 6px;
  cursor: pointer;
  vertical-align: 1px;
}
.ts:disabled { cursor: default; }
.speaker {
  font-size: 0.74rem;
  font-weight: 650;
  border-radius: 6px;
  padding: 1px 6px;
  margin-right: 6px;
  vertical-align: 1px;
  background: var(--surface-2);
  color: var(--muted);
}
.speaker.eleve { background: var(--warn-soft); color: var(--warn); }
.transcript-body p.eleve { margin-left: 18px; border-left: 3px solid var(--warn-soft); border-radius: 0 8px 8px 0; }

/* ---------- Fenêtres ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgb(10 10 20 / 45%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease-out;
}
@media (min-width: 640px) { .overlay { align-items: center; padding: 24px; } }
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.2s ease-out;
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.grow-field textarea { min-height: 45vh; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

/* ---------- Enregistreur ---------- */

.recorder .rec-time {
  font: 700 3.4rem/1 var(--mono);
  text-align: center;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.recorder .rec-time.paused { color: var(--muted); animation: blink 1.2s steps(2) infinite; }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter > div { height: 100%; background: linear-gradient(90deg, var(--ok), var(--accent)); transform-origin: left; transition: transform 0.08s linear; }
.rec-controls { display: flex; justify-content: center; align-items: center; gap: 16px; min-height: 84px; }
.rec-btn {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 4px solid var(--rec);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.rec-btn span { width: 56px; height: 56px; border-radius: 50%; background: var(--rec); transition: transform 0.1s; }
.rec-btn:active span { transform: scale(0.92); }
.rec-pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 99px;
  border: 0;
  background: var(--text);
  color: var(--bg);
  font: 600 0.92rem var(--font);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
  cursor: pointer;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); flex: none; }
.rec-dot.recording { animation: blink 1s steps(2) infinite; }
.rec-dot.paused { background: var(--muted); }

/* ---------- Notifications ---------- */

.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.92rem;
  max-width: 520px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 20%);
  animation: rise 0.2s ease-out;
}
.toast.error { background: var(--error); color: #fff; }
.upload-dock {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font: 600 0.88rem var(--font);
  cursor: pointer;
}

/* ---------- Connexion ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; align-items: center; text-align: center; }
.login h1 { margin: 0; font-size: 1.3rem; }
.login .field { width: 100%; text-align: left; }
.pin { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); font-weight: 600; }
.pin-box { position: relative; padding: 6px 4px; }
/* Champ invisible posé sur les pastilles : il reçoit la frappe et ouvre le pavé numérique. */
.pin-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  border: 0;
  padding: 0;
  caret-color: transparent;
  cursor: pointer;
}
.pin-input:focus { box-shadow: none; }
.pin-dots { display: flex; gap: 16px; pointer-events: none; }
.pin-dots span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: background 0.1s, border-color 0.1s;
}
.pin-dots span.filled { background: var(--accent); border-color: var(--accent); }
.pin-box:focus-within .pin-dots span:not(.filled) { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.pin-dots.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
