/* ======================================================================= thème */
:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f2f8;
  --panel-3: #e8ebf4;
  --border: #e1e4ee;
  --text: #1d2433;
  --muted: #6b7385;
  --accent: #5b5bd6;
  --accent-2: #8b5cf6;
  --accent-soft: #ecebff;
  --accent-text: #ffffff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --mark: #fef08a;
  --code-bg: #f1f3f8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px rgba(16, 24, 40, .07);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "SFMono-Regular", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016;
    --panel: #161922;
    --panel-2: #1c202b;
    --panel-3: #252a38;
    --border: #2a3040;
    --text: #e5e8f0;
    --muted: #9099ad;
    --accent: #8b8cf6;
    --accent-2: #a78bfa;
    --accent-soft: #24264a;
    --accent-text: #0e1016;
    --success: #4ade80;
    --success-soft: #11301f;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --warning: #fbbf24;
    --warning-soft: #3a2c0c;
    --mark: #6b5b12;
    --code-bg: #1f2431;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.grow { flex: 1; }

/* ======================================================================= mise en page */
.layout {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr) 364px;
  height: 100vh;
  overflow: hidden;
}
.layout.no-ai { grid-template-columns: 256px minmax(0, 1fr) 0; }
.layout.no-ai #ai-panel { display: none; }
.layout.wide { grid-template-columns: 256px minmax(0, 1fr) 0; }
.layout.wide #ai-panel { display: none; }
.layout.focus { grid-template-columns: 0 minmax(0, 1fr) 0; }
.layout.focus #sidebar, .layout.focus #ai-panel { display: none; }

#sidebar, #ai-panel {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#sidebar { border-right: 1px solid var(--border); padding: 14px 12px 8px; gap: 10px; }
#ai-panel { border-left: 1px solid var(--border); }
#main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { overflow: auto; }

@media (max-width: 1180px) {
  .layout, .layout.no-ai { grid-template-columns: 240px minmax(0, 1fr) 0; }
  #ai-panel {
    position: fixed; right: 0; top: 0; bottom: 0; width: min(400px, 92vw); z-index: 40;
    box-shadow: var(--shadow);
  }
}
/* Téléphone : bibliothèque en tiroir (☰), assistant IA en plein écran, barre du haut. */
.mobile-bar, .drawer-backdrop, .only-phone { display: none; }
@media (max-width: 760px) {
  .layout, .layout.no-ai, .layout.wide, .layout.focus {
    grid-template-columns: minmax(0, 1fr);
    height: 100vh;
    height: 100dvh; /* hauteur visible réelle (barres du navigateur) */
  }
  #sidebar, .layout.focus #sidebar {
    display: flex; position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; width: min(330px, 86vw);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); border-right: none;
    padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .layout.nav-open #sidebar { transform: none; }
  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55; background: rgba(10, 12, 20, .45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .layout.nav-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  #ai-panel {
    position: fixed; inset: 0; width: 100%; z-index: 58; border-left: none; box-shadow: none;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-bar {
    display: flex; align-items: center; gap: 4px; flex: none; background: var(--panel);
    border-bottom: 1px solid var(--border); padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  }
  .mobile-bar .icon-btn { width: 40px; height: 40px; font-size: 19px; color: var(--text); }
  .m-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-size: 15px; }
  .m-brand .brand-logo { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }
  .m-review { position: relative; }
  .m-review b {
    position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
    background: var(--danger); color: #fff; font-size: 10.5px; line-height: 17px; text-align: center;
  }
  .layout.focus .mobile-bar { display: none; }
  .only-desktop { display: none; }
  .only-phone { display: inline; }
}

/* ======================================================================= boutons & champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.small { padding: 5px 9px; font-size: 12.5px; }
.btn.full { width: 100%; }
.btn.danger { color: var(--danger); }
.icon-btn {
  border: none; background: transparent; cursor: pointer; border-radius: 7px;
  width: 30px; height: 30px; display: inline-grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.link { border: none; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }

input:not([type=checkbox]):not([type=range]), select, textarea {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
.select.small { padding: 4px 8px; font-size: 12.5px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row > input { flex: 1; }

.seg { display: inline-flex; background: var(--panel-2); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button {
  border: none; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--muted);
}
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg.small button { padding: 3px 9px; font-size: 12.5px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-select {
  background: var(--accent-soft) !important; color: var(--accent); border-color: transparent !important;
  border-radius: 999px !important; font-weight: 600; font-size: 12px !important; padding: 3px 6px 3px 9px !important;
  cursor: pointer;
}
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--panel-2);
  font-size: 11.5px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.dot.ko { background: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, .18); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 10px; }
.tabs button {
  border: none; background: none; padding: 9px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

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

/* ======================================================================= barre latérale */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); padding: 2px 4px 6px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11.5px; }
.side-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.search-box { position: relative; }
.search-box input { width: 100%; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; max-height: 360px; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.search-results button {
  display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-results button:hover { background: var(--panel-2); }
.search-results small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.search-results mark { background: var(--mark); color: inherit; border-radius: 2px; }

.side-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.nav-pill {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 9px; padding: 7px 9px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.nav-pill:hover { border-color: var(--accent); }
.nav-pill.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.nav-pill b { background: var(--muted); color: var(--panel); border-radius: 999px; padding: 0 7px; font-size: 11.5px; }
.review-pill.has b { background: var(--accent); color: var(--accent-text); }
#next-exam.soon { background: var(--danger); color: white; }
#next-exam.near { background: var(--warning); color: white; }

.library { flex: 1; overflow: auto; margin: 0 -6px; padding: 0 6px; }
.semester { margin-bottom: 8px; }
.semester-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px; border-radius: 7px; cursor: pointer;
  font-weight: 700; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  user-select: none; position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.semester-head:hover { color: var(--text); }
.semester-head .caret { width: 12px; transition: transform .15s; font-size: 10px; }
.semester.collapsed .semester-head .caret { transform: rotate(-90deg); }
.semester.collapsed .semester-body { display: none; }
.semester-head .chip.now { background: var(--accent-soft); color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 600; }
.semester-head .count { font-weight: 500; }
.subject { margin-bottom: 1px; }
.subject-head {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 7px; cursor: pointer;
  font-weight: 600; font-size: 13px; color: var(--text); user-select: none;
}
.subject-head:hover { background: var(--panel-2); }
.subject-head .caret { width: 12px; transition: transform .15s; font-size: 10px; color: var(--muted); }
.subject.collapsed .subject-head .caret { transform: rotate(-90deg); }
.subject.collapsed .subject-docs { display: none; }
.subject.no-docs .subject-head { font-weight: 500; color: var(--muted); }
.subject.no-docs .subject-head .caret { visibility: hidden; }
.subject-head { position: relative; }
.subject-head .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-head .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.subject-head .count { font-weight: 500; color: var(--muted); font-size: 12px; }
.subject-head .exam-chip { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: var(--warning-soft); color: var(--warning); white-space: nowrap; }
.subject-head .exam-chip.soon { background: var(--danger-soft); color: var(--danger); }
.subject-head .icon-btn {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; opacity: 0; background: var(--panel-3);
}
.subject-head:hover .icon-btn { opacity: 1; }
.subject-head:hover .exam-chip { visibility: hidden; }
.subject-head.drop-target { background: var(--accent-soft); outline: 2px dashed var(--accent); }
.subject-docs { padding-left: 10px; }
.cat-label {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px 1px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.cat-label .n { font-weight: 500; letter-spacing: 0; }
.cat-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.doc-item {
  display: flex; align-items: center; gap: 7px; width: 100%; text-align: left; border: none; background: none;
  padding: 5px 8px; border-radius: 7px; cursor: pointer; color: var(--text); font-size: 13.5px;
}
.doc-item:hover { background: var(--panel-2); }
.doc-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.doc-item .ico { flex: none; width: 18px; text-align: center; }
.doc-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .multi {
  flex: none; margin-left: auto; font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--panel-2); border-radius: 999px; padding: 1px 6px;
}
.doc-item.child { padding-left: 26px; font-size: 13px; }
.doc-item.child .name { color: var(--muted); }
.doc-item.child.active .name { color: var(--accent); }
.library .empty { color: var(--muted); font-size: 12.5px; padding: 6px 8px; }

.side-footer {
  display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding: 8px 4px 2px; font-size: 12.5px;
}
.side-footer #ollama-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chip {
  display: flex; align-items: center; gap: 8px; width: 100%; border: none; background: none; cursor: pointer;
  padding: 6px 4px 2px; border-radius: 8px; color: var(--text); font-size: 13px; text-align: left;
}
.account-chip:hover { background: var(--panel-2); }
.account-chip .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 12px;
  font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

/* ------------------------------------------------------------------ connexion & comptes */
.login-screen {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, var(--accent-soft), var(--bg) 60%);
}
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.login-card #login-step-auth, .login-card #login-step-change { display: flex; flex-direction: column; gap: 12px; }
.login-card [hidden] { display: none !important; }
.login-card input { width: 100%; }
.login-error { margin: 0; color: var(--danger); font-size: 13px; }
.wide-dialog { width: min(640px, 94vw); }
.acc-section { display: flex; flex-direction: column; gap: 8px; }
.acc-section h4 { margin: 6px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.acc-grid { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; align-items: center; }
.acc-grid.new-user { grid-template-columns: 1fr auto auto; }
.acc-grid input { min-width: 0; }
.public-url {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border-radius: 8px;
  background: var(--panel-2); font-size: 13px;
}
.public-url code { font-size: 13px; word-break: break-all; }
.user-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow: auto; }
.user-list li { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.user-list li:last-child { border-bottom: none; }
.user-list .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.user-list .who b { overflow: hidden; text-overflow: ellipsis; }
.user-list .who small { color: var(--muted); }
.user-list li.off .who b { color: var(--muted); text-decoration: line-through; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warning-soft); color: var(--warning); }
.secret-box {
  padding: 10px 12px; border-radius: 8px; border: 1px dashed var(--accent); background: var(--accent-soft); font-size: 13px;
  display: flex; flex-direction: column; gap: 6px;
}
.secret-box code { font-size: 15px; font-weight: 700; letter-spacing: .04em; user-select: all; }
@media (max-width: 640px) {
  .acc-grid, .acc-grid.new-user { grid-template-columns: 1fr; }
}

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 200px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 4px;
}
.menu button {
  display: block; width: 100%; text-align: left; border: none; background: none; padding: 7px 10px;
  border-radius: 6px; cursor: pointer;
}
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
.floating-menu { position: fixed; }

/* ======================================================================= accueil */
.home { overflow: auto; }
.home-inner { max-width: 960px; margin: 0 auto; padding: 36px 32px 60px; width: 100%; }
.home h1 { margin: 0 0 6px; font-size: 28px; }
.lead { color: var(--muted); font-size: 15px; margin: 0 0 22px; max-width: 720px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 22px; text-align: center; color: var(--muted);
  background: var(--panel); transition: border-color .15s, background .15s;
}
.dropzone b { color: var(--text); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.big { padding: 34px; }
.dz-icon { font-size: 34px; margin-bottom: 6px; }
.dropzone small { display: block; margin-top: 6px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 22px 0; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12.5px; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--accent); }
.home-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
@media (max-width: 900px) { .home-cols { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.how ol { margin: 0; padding-left: 20px; color: var(--muted); }
.how li { margin: 4px 0; }
.how b { color: var(--text); }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.plain-list li:last-child { border-bottom: none; }
.plain-list a { text-decoration: none; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.plain-list a:hover { color: var(--accent); }
.plain-list .empty { color: var(--muted); }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.score.good { color: var(--success); }
.score.mid { color: var(--warning); }
.score.bad { color: var(--danger); }
.warn-card { border-color: var(--warning); background: var(--warning-soft); }

/* ======================================================================= document */
.doc-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex-wrap: wrap;
}
.doc-title {
  font-size: 17px; font-weight: 700; border-color: transparent !important; background: transparent !important;
  flex: 1 1 140px; min-width: 120px; padding: 5px 8px !important; text-overflow: ellipsis;
}
#doc-subject { max-width: 170px; }
.doc-header .spacer { flex: 0 1 0; }
.doc-title:hover { background: var(--panel-2) !important; }
.doc-title:focus { background: var(--panel) !important; border-color: var(--accent) !important; }
.doc-tabs { background: var(--panel); }
.banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--warning-soft);
  border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap;
}
.banner.info { background: var(--accent-soft); }
.update-banner {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--danger-soft);
  color: var(--danger); border-bottom: 1px solid var(--danger); font-size: 13.5px; flex-wrap: wrap;
}
.update-banner span { flex: 1; min-width: 260px; }
#doc-parent { max-width: 260px; }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.toolbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex-wrap: wrap;
}
.toolbar button {
  border: none; background: none; min-width: 30px; height: 28px; padding: 0 7px; border-radius: 6px; cursor: pointer;
  color: var(--text); font-size: 13px;
}
.toolbar button:hover { background: var(--panel-2); }
.toolbar button.on { background: var(--accent-soft); color: var(--accent); }
.toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.toolbar mark { background: var(--mark); color: inherit; padding: 0 2px; }
.find-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border);
  background: var(--panel-2); flex-wrap: wrap;
}
.find-bar input:not([type=checkbox]) { width: 170px; padding: 4px 8px; }
.editor-split { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.editor-split.mode-edit { grid-template-columns: minmax(0, 1fr); }
.editor-split.mode-edit #preview { display: none; }
.editor-split.mode-preview { grid-template-columns: minmax(0, 1fr); }
.editor-split.mode-preview #editor { display: none; }
#editor {
  border: none; border-radius: 0; resize: none; padding: 22px 26px; font: 14px/1.7 var(--mono);
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
  background: var(--panel); border-right: 1px solid var(--border); height: 100%; overflow: auto; tab-size: 4;
}
#editor:focus { box-shadow: none; }
#preview { overflow: auto; padding: 22px 32px 80px; height: 100%; }
.editor-split.mode-edit #editor, .editor-split.mode-preview #preview { padding-left: max(32px, calc(50% - 400px)); padding-right: max(32px, calc(50% - 400px)); }
.statusbar {
  display: flex; align-items: center; gap: 14px; padding: 5px 14px; border-top: 1px solid var(--border);
  background: var(--panel); font-size: 12px; color: var(--muted);
}
.readonly .toolbar, .readonly #mode-switch, .readonly #find-bar { display: none !important; }

/* ======================================================================= rendu markdown */
.markdown { line-height: 1.7; font-size: 15px; word-wrap: break-word; }
.markdown.small { font-size: 13.5px; line-height: 1.6; }
.markdown > :first-child { margin-top: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { line-height: 1.3; margin: 1.4em 0 .5em; }
.markdown h1 { font-size: 1.75em; padding-bottom: .3em; border-bottom: 3px solid var(--accent); }
.markdown h2 { font-size: 1.35em; padding-bottom: .2em; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 1.15em; }
.markdown h4 { font-size: 1em; }
.markdown.small h1 { font-size: 1.35em; }
.markdown.small h2 { font-size: 1.15em; }
.markdown.small h3 { font-size: 1.05em; }
.markdown p, .markdown ul, .markdown ol, .markdown table, .markdown blockquote, .markdown pre { margin: .6em 0; }
.markdown ul, .markdown ol { padding-left: 1.5em; }
.markdown li { margin: .2em 0; }
.markdown li > ul, .markdown li > ol { margin: .1em 0; }
.markdown blockquote {
  margin-left: 0; padding: .5em 1em; border-left: 4px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}
.markdown blockquote > :first-child { margin-top: 0; }
.markdown blockquote > :last-child { margin-bottom: 0; }
.markdown code { font-family: var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.markdown pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; vertical-align: top; text-align: left; }
.markdown th { background: var(--panel-2); }
.markdown mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 2px; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 1.6em 0; }
.markdown img { max-width: 100%; }
.markdown .task-list-item { list-style: none; margin-left: -1.3em; }
.markdown .arithmatex { overflow-x: auto; }
.markdown details { background: var(--panel-2); border-radius: 8px; padding: 6px 12px; }

/* ======================================================================= panneau IA */
.ai-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; }
.ai-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ai-empty { padding: 30px 20px; color: var(--muted); text-align: center; }
.task-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.task {
  display: flex; flex-direction: column; gap: 1px; text-align: left; border: 1px solid var(--border);
  background: var(--panel); border-radius: 9px; padding: 8px 10px; cursor: pointer; min-height: 56px;
}
.task:hover { border-color: var(--accent); }
.task.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.task .t { font-weight: 600; font-size: 13px; }
.task .d { color: var(--muted); font-size: 11.5px; line-height: 1.3; }
.scope-row { display: flex; flex-direction: column; gap: 6px; }
.scope-row .seg { display: flex; }
.scope-row .seg button { flex: 1; }
.scope-pick summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.scope-list {
  display: flex; flex-direction: column; gap: 5px; margin-top: 6px; max-height: 190px; overflow: auto;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); font-size: 12.5px;
}
.scope-list .check { min-width: 0; }
.scope-list .check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-options { display: flex; flex-direction: column; gap: 8px; }
.ai-options .row label { width: 72px; color: var(--muted); font-size: 12.5px; }
.ai-options input[type=number] { width: 80px; flex: none !important; }
.ai-options textarea { width: 100%; }
.ai-output {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel-2);
  display: flex; flex-direction: column; gap: 8px;
}
.ai-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.ai-output.finished .spinner { display: none; }
.thinking summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.thinking pre { white-space: pre-wrap; font-size: 11.5px; color: var(--muted); max-height: 180px; overflow: auto; margin: 6px 0 0; }
.done-card {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--success-soft); color: var(--success); font-weight: 600; font-size: 13px;
}
.done-card.warn { background: var(--warning-soft); color: var(--warning); }
.done-card span { flex: 1; }
.json-progress { font-size: 13px; color: var(--muted); }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.tool-grid button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 7px 6px; cursor: pointer;
  font-size: 12.5px;
}
.tool-grid button:hover { border-color: var(--accent); background: var(--accent-soft); }

.chat { gap: 8px; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.msg { max-width: 92%; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.assistant.pending:empty::after { content: "…"; animation: blink 1s infinite; }
.msg.error { background: var(--danger-soft); color: var(--danger); }
@keyframes blink { 50% { opacity: .3; } }
.chat-empty { color: var(--muted); text-align: center; margin: auto 10px; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 4px 10px;
  font-size: 12px; cursor: pointer; color: var(--muted);
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.chat-form { display: flex; flex-direction: column; gap: 6px; }
.chat-form textarea { width: 100%; resize: none; }

/* ======================================================================= QCM */
.quiz { max-width: 760px; margin: 0 auto; padding: 28px 24px 60px; width: 100%; }
.quiz-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.progress { flex: 1; height: 8px; background: var(--panel-3); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; }
.quiz-q { font-size: 18px; font-weight: 650; margin: 10px 0 16px; line-height: 1.45; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; border: 1.5px solid var(--border);
  background: var(--panel); border-radius: 10px; padding: 11px 14px; cursor: pointer; font-size: 14.5px;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .letter {
  flex: none; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: var(--panel-2); font-weight: 700; font-size: 13px;
}
.choice.correct { border-color: var(--success); background: var(--success-soft); }
.choice.correct .letter { background: var(--success); color: white; }
.choice.wrong { border-color: var(--danger); background: var(--danger-soft); }
.choice.wrong .letter { background: var(--danger); color: white; }
.choice:disabled { cursor: default; }
.explanation { margin-top: 14px; padding: 10px 14px; border-radius: 10px; background: var(--panel-2); border-left: 4px solid var(--accent); }
.quiz-nav { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.quiz-result { text-align: center; padding: 20px 0; }
.quiz-result .big { font-size: 52px; font-weight: 800; }
.mistakes { text-align: left; margin-top: 18px; }
.mistake { padding: 10px 0; border-bottom: 1px solid var(--border); }
.mistake .q { font-weight: 600; }
.mistake .a { color: var(--success); margin-top: 3px; }
.mistake .y { color: var(--danger); margin-top: 3px; }

/* ======================================================================= flashcards */
.review-page { max-width: 820px; margin: 0 auto; padding: 24px; width: 100%; }
.review-page-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.review-page-head h2 { margin: 0; }
.review { max-width: 720px; margin: 0 auto; padding: 24px 20px 50px; width: 100%; }
.review-top { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.flashcard {
  min-height: 260px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 28px 30px; display: flex; flex-direction: column; justify-content: center;
  cursor: pointer; user-select: text;
}
.flashcard .face-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.flashcard .front { font-size: 20px; font-weight: 650; text-align: center; }
.flashcard .back { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--border); font-size: 16px; text-align: center; }
.flashcard code, .quiz code { font-family: var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.flashcard mark, .quiz mark { background: var(--mark); color: inherit; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.grade { border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 9px; cursor: pointer; font-weight: 600; }
.grade small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.grade.g0:hover { border-color: var(--danger); background: var(--danger-soft); }
.grade.g1:hover { border-color: var(--warning); background: var(--warning-soft); }
.grade.g2:hover { border-color: var(--success); background: var(--success-soft); }
.grade.g3:hover { border-color: var(--accent); background: var(--accent-soft); }
.reveal { width: 100%; margin-top: 16px; padding: 11px; }
.kbd-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 10px; }
.kbd-hint kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .e-icon { font-size: 44px; }
.empty-state h3 { color: var(--text); }
.cards-editor { max-width: 900px; margin: 0 auto; padding: 22px 24px 60px; width: 100%; }
.card-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: start; margin-bottom: 8px; }
.card-row textarea { width: 100%; min-height: 44px; resize: vertical; font-size: 13.5px; }
.card-row .meta { grid-column: 1 / 3; font-size: 11px; color: var(--muted); margin-top: -4px; }
.card-new { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ======================================================================= original */
.original-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex-wrap: wrap;
}
.original-frame { flex: 1; min-height: 0; position: relative; background: var(--panel-3); display: flex; }
.original-frame iframe { flex: 1; border: none; width: 100%; height: 100%; background: #525659; }
.original-frame .empty-state { margin: auto; }
.original-frame .empty-state.error { color: var(--danger); }

/* ======================================================================= calendrier */
.cal-page { max-width: 1280px; margin: 0 auto; padding: 22px 24px 50px; width: 100%; }
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-head h2 { margin: 0; font-size: 22px; }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .cal-layout { grid-template-columns: minmax(0, 1fr); } }
.cal-main { padding: 12px; margin: 0; }
.cal-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-nav b { font-size: 16px; min-width: 150px; text-align: center; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-dow { padding: 6px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; text-align: center; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--panel-2); }
.cal-day {
  min-height: 96px; padding: 4px 5px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; transition: background .1s;
}
.cal-day:hover { background: var(--panel-2); }
.cal-day.other { background: var(--bg); }
.cal-day.other .num { opacity: .45; }
.cal-day.weekend { background: color-mix(in srgb, var(--panel-2) 55%, transparent); }
.cal-day .num { font-size: 12px; font-weight: 600; color: var(--muted); align-self: flex-end; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { background: var(--accent); color: var(--accent-text); }
.cal-ev {
  font-size: 11.5px; line-height: 1.3; padding: 2px 6px; border-radius: 5px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; border-left: 3px solid var(--ev, var(--accent));
  background: color-mix(in srgb, var(--ev, var(--accent)) 16%, var(--panel));
}
.cal-ev:hover { filter: brightness(1.08); }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.cal-side { margin: 0; }
.upcoming { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.upcoming li {
  display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); border-left: 4px solid var(--ev, var(--accent)); background: var(--panel);
}
.upcoming li:hover { background: var(--panel-2); }
.upcoming li.empty { border: 1px dashed var(--border); color: var(--muted); cursor: default; justify-content: center; }
.upcoming .date { flex: none; width: 44px; text-align: center; line-height: 1.1; }
.upcoming .date b { display: block; font-size: 19px; }
.upcoming .date small { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.upcoming .info { flex: 1; min-width: 0; }
.upcoming .info .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming .info .m { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.countdown { flex: none; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.countdown.soon { background: var(--danger-soft); color: var(--danger); }
.countdown.near { background: var(--warning-soft); color: var(--warning); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 26px; height: 26px; border-radius: 7px; border: 2px solid transparent; cursor: pointer; }
.swatches button.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }

/* ======================================================================= fenêtres */
.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text);
  width: min(560px, 94vw); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
.dialog form { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog h3 { margin: 0; font-size: 17px; }
.dialog footer { display: flex; align-items: center; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.field small { font-weight: 400; }
.field.check { flex-direction: row; font-weight: 400; }
.imp-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; }
.imp-list li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.imp-list li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.imp-list li small { display: block; color: var(--warning); }
.imp-list li.err small { color: var(--danger); }

.drop-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; pointer-events: none;
  background: rgba(91, 91, 214, .12); border: 4px dashed var(--accent);
}
.drop-overlay div { background: var(--panel); padding: 18px 28px; border-radius: 14px; box-shadow: var(--shadow); font-size: 18px; font-weight: 600; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13.5px; max-width: 420px; display: flex; gap: 10px; align-items: center; animation: pop .2s ease-out;
}
.toast.error { background: var(--danger); color: white; }
.toast button { border: none; background: rgba(255,255,255,.18); color: inherit; border-radius: 6px; padding: 3px 8px; cursor: pointer; font-weight: 600; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ======================================================================= écrans tactiles */
@media (pointer: coarse) {
  .kbd-hint { display: none; } /* raccourcis clavier : inutiles sans clavier */
  .icon-btn { width: 38px; height: 38px; }
  .doc-item { padding: 9px 8px; }
  .tabs button { padding: 11px 12px; }
  .toolbar button { min-width: 38px; height: 36px; }
  .seg button { padding: 7px 12px; }
  .menu button { padding: 11px 12px; }
}

/* ======================================================================= téléphone (détails) */
@media (max-width: 760px) {
  /* Pas de zoom automatique d'iOS sur les champs (police < 16 px). */
  input:not([type=checkbox]):not([type=range]), select, textarea { font-size: 16px; }
  .select.small { font-size: 14px; padding: 6px 8px; }

  /* Accueil */
  .home-inner { padding: 18px 14px 40px; }
  .home h1 { font-size: 23px; }
  .lead { font-size: 14px; margin-bottom: 16px; }
  .dropzone.big { padding: 20px 14px; }
  .dz-icon { font-size: 28px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
  .stat { padding: 10px 12px; }
  .stat .num { font-size: 22px; }
  .card { padding: 12px; }

  /* En-tête du document : titre sur toute la largeur, puis les commandes */
  .doc-header { padding: 8px 10px; gap: 6px; }
  .doc-title { order: -1; flex: 1 1 100%; font-size: 16px; }
  #doc-subject { flex: 1 1 70px; min-width: 0; max-width: none; } /* rétrécit pour garder les boutons sur la ligne */
  #doc-parent { max-width: 100%; }
  .doc-header .icon-btn { width: 34px; }
  #mode-switch button { padding: 6px 10px; }
  /* En lecture seule (aperçu), la barre d'outils d'édition ne sert à rien. */
  .editor-pane:has(.editor-split.mode-preview) .toolbar { display: none; }
  #btn-toggle-ai { display: none; } /* déjà dans la barre du haut */
  #mode-switch [data-mode="split"] { display: none; } /* pas de place pour deux colonnes */
  .doc-tabs, .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs button { white-space: nowrap; }
  .banner { padding: 8px 10px; }

  /* Éditeur : barre d'outils qui défile, une seule colonne */
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 4px 6px; }
  .toolbar::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  .toolbar button { flex: none; }
  .find-bar input:not([type=checkbox]) { width: auto; flex: 1 1 120px; }
  /* 16 px : en dessous, l'iPhone zoome en touchant le texte et la page se met à glisser sur le côté. */
  #editor { padding: 14px; font-size: 16px; border-right: none; }
  #preview { padding: 16px 14px 60px; }
  .editor-split.mode-edit #editor, .editor-split.mode-preview #preview { padding-left: 14px; padding-right: 14px; }
  .markdown { font-size: 15.5px; }
  .markdown h1 { font-size: 1.5em; }

  /* Défilement de haut en bas uniquement : tout revient à la ligne plutôt que de dépasser à droite. */
  #editor, #preview { overflow-x: hidden; overscroll-behavior-x: none; }
  #editor { white-space: pre-wrap; overflow-wrap: anywhere; }
  .markdown { overflow-wrap: anywhere; }                 /* longues URL, `code`, mots composés */
  .markdown pre { white-space: pre-wrap; overflow-x: hidden; }
  .markdown table { display: table; width: 100%; overflow: visible; font-size: 13.5px; }
  .markdown th, .markdown td { padding: .35em .45em; overflow-wrap: break-word; hyphens: auto; } /* coupe aux syllabes : « Enso-leillement » */
  .markdown table.squeeze th, .markdown table.squeeze td { overflow-wrap: anywhere; } /* dernier recours (fitToWidth) */
  .markdown .arithmatex, .markdown .katex-display { overflow-x: clip; max-width: 100%; } /* formules réduites à la largeur (fitFormulas) */
  .statusbar { gap: 8px; padding: 5px 10px; flex-wrap: wrap; }
  #doc-source { display: none; }
  .original-bar { padding: 6px 10px; }
  .original-bar .only-phone { flex-basis: 100%; }

  /* Assistant IA */
  .ai-head { padding: 10px 10px 6px; }
  .ai-head .icon-btn { width: 40px; height: 40px; font-size: 18px; }
  .ai-body { padding: 10px 12px 16px; }
  .task { min-height: 52px; }

  /* QCM, flashcards */
  .quiz { padding: 16px 14px 40px; }
  .quiz-q { font-size: 17px; }
  .choice { padding: 12px; font-size: 15px; }
  .review-page, .review { padding: 16px 12px 40px; }
  .review-page-head { flex-wrap: wrap; }
  .flashcard { min-height: 220px; padding: 22px 18px; }
  .flashcard .front { font-size: 18px; }
  .cards-editor { padding: 16px 12px 40px; }
  .card-row { grid-template-columns: minmax(0, 1fr) auto; }
  .card-row textarea { grid-column: 1; }
  .card-row > button { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .card-row .meta { grid-column: 1 / -1; }

  /* Calendrier : cases compactes, les examens en petites barres de couleur (détails dans « À venir ») */
  .cal-page { padding: 14px 10px 40px; }
  .cal-head h2 { font-size: 19px; flex-basis: 100%; }
  .cal-main { padding: 8px; }
  .cal-nav b { min-width: 0; flex: 1; }
  .cal-dow { padding: 4px 0; font-size: 10px; }
  .cal-day { min-height: 54px; padding: 2px; gap: 2px; }
  .cal-day .num { width: 22px; height: 22px; font-size: 11.5px; align-self: center; }
  .cal-ev { font-size: 0; height: 6px; padding: 0; border-left: none; border-radius: 3px; background: var(--ev, var(--accent)); }
  .cal-ev b { display: none; }
  .cal-more { font-size: 10px; padding: 0; text-align: center; }

  /* Fenêtres : presque plein écran */
  .dialog { width: calc(100vw - 16px); max-width: none; max-height: calc(100dvh - 16px); }
  .dialog form { padding: 16px 14px; gap: 12px; }
  .dialog footer { flex-wrap: wrap; }
  .grid2 { grid-template-columns: 1fr; }
  .imp-list li { flex-wrap: wrap; }

  .toasts { left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }
  .login-card { padding: 20px 16px; }
}
@media (max-width: 420px) {
  .grades { grid-template-columns: 1fr 1fr !important; }
  .tool-grid { grid-template-columns: 1fr 1fr; }
  .home-cols { gap: 0; }
}
