/* ================================================================
   RÉVISIO — Responsive Design System
   Breakpoints: mobile <640 · tablet 640-1023 · desktop ≥1024
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700;12..96,800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&display=swap');

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 16px; }
button { font-family: inherit; cursor: pointer; border: none; }
a { text-decoration: none; color: inherit; }

/* ================================================================
   CSS VARIABLES — Light mode (default)
   ================================================================ */
:root {
  /* Layout */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 60px;
  --header-h: 54px;
  --bottom-nav-h: 68px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 5px;

  /* Fonts */
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --base-font: 16px;

  /* Light palette */
  --bg-base:    #F5F4F0;
  --bg-surface: #FFFFFF;
  --bg-hover:   #EEECEA;
  --bg-subtle:  #F9F8F5;

  --border-subtle: #ECEAE4;
  --border:        #DDD9D0;
  --border-strong: #C8C4BB;

  --text-1: #1C1B26;
  --text-2: #5C5B68;
  --text-3: #9998A4;

  --sidebar-bg:        #FFFFFF;
  --sidebar-border:    #ECEAE4;
  --nav-active-bg:     #EEECFF;
  --nav-active-color:  var(--accent);

  --mobile-header-bg:  #FFFFFF;
  --bottom-nav-bg:     rgba(255,255,255,0.88);

  /* Accent (overridden by accent theme) */
  --accent:       #534AB7;
  --accent-light: #EEEDFE;
  --accent-text:  #FFFFFF;

  /* Post-it type colors */
  --c-formule:    #534AB7;
  --c-regle:      #C2620A;
  --c-resume:     #1A7A45;
  --c-definition: #1761A0;
  --c-schema:     #8B3BAB;

  /* Shadows */
  --shadow-xs: 0 1px 3px rgba(0,0,0,.06);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.13);
}

/* ================================================================
   DARK THEME
   ================================================================ */
[data-theme="dark"] {
  --bg-base:    #0D0D17;
  --bg-surface: rgba(255,255,255,0.055);
  --bg-hover:   rgba(255,255,255,0.08);
  --bg-subtle:  rgba(255,255,255,0.03);

  --border-subtle: rgba(255,255,255,0.05);
  --border:        rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.18);

  --text-1: rgba(255,255,255,0.93);
  --text-2: rgba(255,255,255,0.55);
  --text-3: rgba(255,255,255,0.33);

  --sidebar-bg:       rgba(255,255,255,0.025);
  --sidebar-border:   rgba(255,255,255,0.07);
  --nav-active-bg:    rgba(255,255,255,0.10);
  --nav-active-color: var(--accent);

  --mobile-header-bg: rgba(13,13,23,0.92);
  --bottom-nav-bg:    rgba(13,13,23,0.88);

  --shadow-xs: 0 1px 3px rgba(0,0,0,.3);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

/* Dark accent overrides — lighter for readability */
[data-theme="dark"][data-accent="violet"] { --accent: #7B74D4; --accent-light: rgba(123,116,212,.15); }
[data-theme="dark"][data-accent="sage"]   { --accent: #5A9A22; --accent-light: rgba(90,154,34,.15);  }
[data-theme="dark"][data-accent="sky"]    { --accent: #2E80CC; --accent-light: rgba(46,128,204,.15); }
[data-theme="dark"][data-accent="coral"]  { --accent: #C45E36; --accent-light: rgba(196,94,54,.15);  }
[data-theme="dark"][data-accent="rose"]   { --accent: #C45273; --accent-light: rgba(196,82,115,.15); }
[data-theme="dark"][data-accent="slate"]  { --accent: #8A8985; --accent-light: rgba(138,137,133,.15);}

/* ================================================================
   SYSTEM PREFERENCE FALLBACK  (when script hasn't run yet)
   ================================================================ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg-base:    #0D0D17;
    --bg-surface: rgba(255,255,255,0.055);
    --bg-hover:   rgba(255,255,255,0.08);
    --bg-subtle:  rgba(255,255,255,0.03);
    --border-subtle: rgba(255,255,255,0.05);
    --border:        rgba(255,255,255,0.10);
    --border-strong: rgba(255,255,255,0.18);
    --text-1: rgba(255,255,255,0.93);
    --text-2: rgba(255,255,255,0.55);
    --text-3: rgba(255,255,255,0.33);
    --sidebar-bg:      rgba(255,255,255,0.025);
    --sidebar-border:  rgba(255,255,255,0.07);
    --nav-active-bg:   rgba(255,255,255,0.10);
    --mobile-header-bg: rgba(13,13,23,0.92);
    --bottom-nav-bg:    rgba(13,13,23,0.88);
  }
}

/* ================================================================
   ACCENT THEMES (light)
   ================================================================ */
[data-accent="violet"] { --accent: #534AB7; --accent-light: #EEEDFE; }
[data-accent="sage"]   { --accent: #3B6D11; --accent-light: #EAF3DE; }
[data-accent="sky"]    { --accent: #185FA5; --accent-light: #E6F1FB; }
[data-accent="coral"]  { --accent: #993C1D; --accent-light: #FAECE7; }
[data-accent="rose"]   { --accent: #993556; --accent-light: #FBEAF0; }
[data-accent="slate"]  { --accent: #5F5E5A; --accent-light: #F1EFE8; }

/* ================================================================
   BASE
   ================================================================ */
body {
  font-family: var(--font-body);
  font-size: var(--base-font);
  background: var(--bg-base);
  color: var(--text-1);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   AUTH OVERLAY
   ================================================================ */
.auth-overlay {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg-base);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  animation: auth-in .4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes auth-in {
  from { opacity: 0; transform: scale(.93) translateY(16px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}
.auth-logo {
  font-family: var(--font-display);
  font-size: 1.9rem; font-weight: 800;
  letter-spacing: -.04em;
  color: var(--accent);
  text-align: center; margin-bottom: 6px;
}
.auth-logo span { color: var(--text-2); font-weight: 300; }
.auth-tagline {
  text-align: center; font-size: .82rem; color: var(--text-3);
  margin-bottom: 28px;
}
.auth-tabs {
  display: flex; gap: 3px; margin-bottom: 22px;
  background: var(--bg-hover); border-radius: var(--radius-sm); padding: 3px;
}
.auth-tab {
  flex: 1; padding: 7px 12px; border-radius: 6px;
  font-size: .85rem; font-weight: 500; background: none;
  color: var(--text-2); transition: all .15s;
}
.auth-tab.active { background: var(--bg-surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-xs); }
.auth-error {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: #fee2e2; border: 1px solid #fca5a5;
  color: #b91c1c; font-size: .83rem; margin-bottom: 12px;
}
[data-theme="dark"] .auth-error { background: rgba(248,113,113,.1); border-color: rgba(248,113,113,.3); color: #fca5a5; }

/* ================================================================
   FORMS
   ================================================================ */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text-2); margin-bottom: 5px; letter-spacing: .02em;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-1);
  font-family: var(--font-body); font-size: .9rem;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-group textarea { resize: vertical; }
.form-group select { cursor: pointer; }

/* ================================================================
   BUTTONS
   ================================================================ */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
  font-family: var(--font-body); font-size: .9rem; font-weight: 600;
  transition: opacity .15s, transform .12s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:active { transform: scale(.97); }
.btn-full { width: 100%; }

.btn-icon {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-xs); background: none;
  color: var(--text-2); transition: all .15s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-1); }

.btn-sm {
  padding: 5px 11px; border-radius: var(--radius-xs);
  font-size: .8rem; font-weight: 500;
  background: var(--bg-hover); color: var(--text-2);
  border: 1px solid var(--border);
  transition: all .15s;
}
.btn-sm:hover { background: var(--border); color: var(--text-1); }

.btn-danger {
  padding: 9px 14px; border-radius: var(--radius-sm);
  background: #fee2e2; color: #b91c1c; font-size: .875rem; font-weight: 500;
  border: 1px solid #fca5a5; transition: all .15s;
}
.btn-danger:hover { background: #fecaca; }
[data-theme="dark"] .btn-danger { background: rgba(248,113,113,.1); color: #fca5a5; border-color: rgba(248,113,113,.25); }
[data-theme="dark"] .btn-danger:hover { background: rgba(248,113,113,.18); }

/* ================================================================
   APP SHELL
   ================================================================ */
#app {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar (Desktop + Tablet) ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 200;
  display: flex; flex-direction: column;
  transition: width .25s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; gap: 10px;
  flex-shrink: 0;
}
.sidebar-logo {
  font-family: var(--font-display);
  font-size: 1.15rem; font-weight: 800;
  color: var(--accent); letter-spacing: -.03em;
  white-space: nowrap; overflow: hidden;
}
.sidebar-actions {
  display: flex; align-items: center; gap: 6px;
}

/* ── Nav list ── */
.nav-list {
  flex: 1; padding: 8px; list-style: none;
  overflow-y: auto; overflow-x: hidden; scrollbar-width: none;
}
.nav-list::-webkit-scrollbar { display: none; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: .875rem; font-weight: 500;
  transition: all .15s; white-space: nowrap;
  position: relative;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-link.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-color);
  font-weight: 600;
}
.nav-link i { font-size: 1.1rem; flex-shrink: 0; }
.nav-link span { overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 8px; border-top: 1px solid var(--sidebar-border);
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.sidebar-footer .nav-link { flex: 1; }

/* ── Tablet: collapsed sidebar (icons only) ── */
@media (min-width: 640px) and (max-width: 1023px) {
  .sidebar { width: var(--sidebar-w-collapsed); }
  .sidebar-logo,
  .sidebar-header .subject-switcher,
  .nav-link span,
  .sidebar-footer .nav-link span { display: none; }
  .sidebar-header { align-items: center; padding: 12px 8px; }
  .sidebar-actions { flex-direction: column; }
  .nav-link { justify-content: center; padding: 10px; }
  .sidebar-footer { flex-direction: column; }
  .nav-link[title]::after {
    content: attr(title);
    position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
    background: var(--text-1); color: var(--bg-base);
    font-size: .75rem; padding: 4px 8px; border-radius: 6px;
    white-space: nowrap; pointer-events: none; opacity: 0;
    transition: opacity .15s;
  }
  .nav-link:hover::after { opacity: 1; }
}

/* ── Main content ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}
@media (min-width: 640px) and (max-width: 1023px) {
  .main-content { margin-left: var(--sidebar-w-collapsed); }
}

/* ── Mobile header ── */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h);
  background: var(--mobile-header-bg);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  align-items: center; padding: 0 12px; gap: 8px;
}
.mobile-logo {
  font-family: var(--font-display);
  font-size: 1.1rem; font-weight: 800;
  color: var(--accent); letter-spacing: -.03em;
  flex-shrink: 0;
}
.mobile-header-center { flex: 1; overflow: hidden; }

/* ── Mobile bottom nav ── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: var(--bottom-nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bottom-nav-bg);
  border-top: 1px solid var(--border-subtle);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  justify-content: space-around; align-items: center;
}
.bottom-nav .nav-link {
  flex-direction: column; gap: 3px;
  padding: 6px 10px; font-size: .65rem;
  color: var(--text-3); flex: 1;
  justify-content: center; text-align: center;
  border-radius: 10px;
}
.bottom-nav .nav-link.active { color: var(--accent); background: var(--nav-active-bg); }
.bottom-nav .nav-link i { font-size: 1.25rem; }

/* ── Mobile breakpoint ── */
@media (max-width: 639px) {
  .sidebar { display: none; }
  .mobile-header { display: flex; }
  .bottom-nav { display: flex; }
  .main-content {
    margin-left: 0;
    padding-top: var(--header-h);
    padding-bottom: calc(var(--bottom-nav-h) + 8px);
  }
}

/* ================================================================
   VIEWS
   ================================================================ */
.view { padding: 20px 24px 32px; animation: view-in .2s ease-out; }
.view.hidden { display: none; }
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view-header {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 16px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 10;
  background: var(--bg-base);
}
.view-header h2 {
  font-family: var(--font-display);
  font-size: 1.4rem; font-weight: 700;
  letter-spacing: -.02em; color: var(--text-1); flex: 1;
}
.counter {
  font-size: .78rem; color: var(--text-3); font-weight: 500;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-subtle); border: 1px solid var(--border-subtle);
}

@media (max-width: 639px) {
  .view { padding: 16px 16px 24px; }
  .view-header { top: 0; background: var(--bg-base); }
  .view-header h2 { font-size: 1.2rem; }
}

/* ================================================================
   SUBJECT SWITCHER
   ================================================================ */
.subject-switcher { position: relative; }
.subject-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-1); font-size: .8rem; font-weight: 600;
  cursor: pointer; transition: all .18s; max-width: 100%;
  white-space: nowrap;
}
.subject-pill:hover { border-color: var(--accent); color: var(--accent); }
.subject-pill i { font-size: .88rem; flex-shrink: 0; }
.subject-pill span { overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.subject-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 400;
  min-width: 220px; max-height: 300px; overflow-y: auto;
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: dropdown-in .15s cubic-bezier(.34,1.56,.64,1);
}
@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-5px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.subject-option {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 14px; background: none;
  color: var(--text-1); font-size: .85rem; text-align: left;
  transition: background .12s; border-bottom: 1px solid var(--border-subtle);
}
.subject-option:last-child { border-bottom: none; }
.subject-option:hover { background: var(--bg-hover); }
.subject-option.active { color: var(--accent); font-weight: 600; }
.subject-option i { color: var(--text-3); font-size: .9rem; }
.subject-option.active > i:first-child { color: var(--accent); }
.subject-option i:last-child { margin-left: auto; }
.subject-loading { padding: 12px 14px; font-size: .82rem; color: var(--text-3); }

/* Mobile subject switcher — dropdown anchored from header */
.subject-switcher-mobile { flex: 1; display: flex; justify-content: center; }
.subject-switcher-mobile .subject-pill { max-width: 180px; font-size: .75rem; padding: 5px 10px; }
.subject-switcher-mobile .subject-pill span { max-width: 120px; }
.subject-switcher-mobile .subject-dropdown {
  left: 50%; transform: translateX(-50%);
  min-width: 200px;
}
.subject-switcher-mobile .subject-dropdown:not(.hidden) {
  transform: translateX(-50%);
  animation: dropdown-in-center .15s cubic-bezier(.34,1.56,.64,1);
}
@keyframes dropdown-in-center {
  from { opacity: 0; transform: translateX(-50%) translateY(-5px) scale(.97); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ================================================================
   POSTIT CARDS
   ================================================================ */
.postit-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  padding: 16px; margin-bottom: 10px;
  transition: transform .15s, box-shadow .15s;
}
.postit-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.postit-card[data-type="formule"]    { border-left-color: var(--c-formule); }
.postit-card[data-type="règle"]      { border-left-color: var(--c-regle); }
.postit-card[data-type="résumé"]     { border-left-color: var(--c-resume); }
.postit-card[data-type="définition"] { border-left-color: var(--c-definition); }
.postit-card[data-type="schéma"]     { border-left-color: var(--c-schema); }

.postit-meta {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 8px; flex-wrap: wrap;
}
.postit-type-badge {
  font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 8px; border-radius: 999px;
  background: var(--bg-hover); color: var(--text-3);
  border: 1px solid var(--border-subtle);
}
.postit-subject { font-size: .72rem; color: var(--text-3); }
.manual-badge {
  font-size: .62rem; padding: 2px 6px; border-radius: 999px;
  background: #fef3c7; border: 1px solid #fde68a; color: #92400e;
  font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
[data-theme="dark"] .manual-badge { background: rgba(251,191,36,.12); border-color: rgba(251,191,36,.25); color: #fbbf24; }

.postit-title {
  font-family: var(--font-display);
  font-size: .975rem; font-weight: 700; color: var(--text-1);
  margin-bottom: 8px; line-height: 1.3;
}
.postit-content {
  font-size: .87rem; line-height: 1.65; color: var(--text-2);
}
.postit-content p { margin-bottom: 6px; }
.postit-content ul, .postit-content ol { padding-left: 1.2em; margin-bottom: 6px; }
.postit-content strong { color: var(--accent); font-weight: 600; }
.postit-content em { color: var(--text-1); }
.postit-content code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .8em; background: var(--bg-hover);
  border: 1px solid var(--border-subtle); padding: 1px 5px;
  border-radius: 4px; color: var(--accent);
}
.postit-actions {
  display: flex; gap: 6px; margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border-subtle); flex-wrap: wrap;
}
.postit-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: var(--radius-xs);
  font-size: .78rem; font-weight: 500;
  background: var(--bg-hover); color: var(--text-2);
  border: 1px solid var(--border-subtle); transition: all .12s;
}
.postit-action-btn:hover { background: var(--bg-surface); color: var(--text-1); border-color: var(--border); box-shadow: var(--shadow-xs); }

/* Page viewer (interactive course page navigator) */
.page-viewer {
  margin: 0 0 16px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}
.page-viewer-header {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 14px; font-size: .8rem; font-weight: 600;
  color: var(--text-2); border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-hover);
}
.page-viewer-label { color: var(--text-3); font-weight: 400; }
/* Swipe hint on the header */
.page-viewer-header::after {
  content: '← glisser →';
  margin-left: auto; font-size: .68rem; color: var(--text-3); font-weight: 400;
  letter-spacing: .01em;
}
.page-viewer-body {
  display: flex; align-items: center; gap: 6px; padding: 10px;
}
/* Zoomable image wrapper */
.page-img-wrap {
  flex: 1; min-width: 0;
  position: relative; overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg-base);
  touch-action: none;   /* let JS handle all pointer gestures */
  cursor: zoom-in;
}
.page-img-wrap.page-zoomable { user-select: none; }
.page-img {
  display: block; width: 100%; height: auto;
  border-radius: var(--radius-sm);
  transform-origin: center center;
  pointer-events: none; /* let wrap capture pointer events */
  -webkit-user-drag: none;
  will-change: transform;
}
/* Zoom hint overlay */
.zoom-hint {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.52); color: #fff; border-radius: 20px;
  padding: 4px 12px; font-size: .72rem; white-space: nowrap;
  pointer-events: none;
  transition: opacity .3s;
  opacity: 1;
}
.page-nav-btn {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: var(--radius-xs);
  background: var(--bg-hover); border: 1px solid var(--border-subtle);
  color: var(--text-2); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .12s;
}
.page-nav-btn:hover:not(:disabled) { background: var(--bg-surface); color: var(--accent); border-color: var(--accent); }
.page-nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.page-no-img {
  padding: 14px; text-align: center; font-size: .8rem; color: var(--text-3);
  background: var(--bg-hover); border-radius: var(--radius-sm);
  border: 1px dashed var(--border-subtle);
}

/* Annotation */
.annotation-section { margin-top: 12px; }
.annotation-textarea {
  width: 100%; min-height: 72px; padding: 9px 12px;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-1);
  font-family: var(--font-body); font-size: .85rem; resize: vertical; outline: none;
}
.annotation-textarea:focus { border-color: var(--accent); }
.annotation-actions { display: flex; gap: 6px; margin-top: 6px; }

/* ================================================================
   QUIZ
   ================================================================ */
.quiz-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius); box-shadow: var(--shadow-xs); padding: 20px; margin-bottom: 14px;
}
.quiz-question {
  font-family: var(--font-display);
  font-size: 1rem; font-weight: 700; color: var(--text-1);
  margin-bottom: 14px; line-height: 1.4;
}
.quiz-choices { display: flex; flex-direction: column; gap: 8px; }
.quiz-choice {
  padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-subtle); background: var(--bg-subtle);
  color: var(--text-2); font-size: .875rem; transition: all .12s;
  text-align: left;
}
.quiz-choice:hover { border-color: var(--accent); background: var(--accent-light); color: var(--text-1); }
.quiz-choice.correct { border-color: #16a34a; background: #f0fdf4; color: #15803d; }
.quiz-choice.wrong   { border-color: #dc2626; background: #fef2f2; color: #b91c1c; }
[data-theme="dark"] .quiz-choice.correct { background: rgba(22,163,74,.12); color: #4ade80; }
[data-theme="dark"] .quiz-choice.wrong   { background: rgba(220,38,38,.12); color: #f87171; }
.quiz-explanation {
  margin-top: 12px; padding: 12px; border-radius: var(--radius-sm);
  background: var(--bg-subtle); border: 1px solid var(--border-subtle);
  font-size: .85rem; color: var(--text-2); line-height: 1.55;
}
.quiz-empty {
  text-align: center; padding: 60px 20px;
}
.quiz-empty .ti { font-size: 3rem; color: #16a34a; display: block; margin-bottom: 12px; }
.quiz-empty h3 { font-size: 1.1rem; color: var(--text-1); margin-bottom: 6px; }
.quiz-empty p { color: var(--text-3); font-size: .875rem; }

/* ================================================================
   TOC
   ================================================================ */
.toc-filters {
  display: flex; gap: 7px; flex-wrap: wrap; padding-bottom: 4px;
}
select {
  padding: 6px 10px; border-radius: var(--radius-xs);
  background: var(--bg-subtle); border: 1px solid var(--border);
  color: var(--text-1); font-family: var(--font-body); font-size: .8rem;
  cursor: pointer; outline: none; transition: border-color .15s;
}
select:focus { border-color: var(--accent); }

.toc-chapter { margin-bottom: 20px; }
.toc-chapter-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; margin-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}
.toc-chapter-header h3 {
  font-family: var(--font-display);
  font-size: .9rem; font-weight: 700; color: var(--text-1); flex: 1;
}
.toc-chapter-badge {
  font-size: .7rem; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-light); color: var(--accent);
}
.toc-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle); background: var(--bg-surface);
  margin-bottom: 6px; cursor: pointer; transition: all .12s;
}
.toc-item:hover { border-color: var(--border); background: var(--bg-hover); transform: translateX(2px); }
.toc-item-type-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 5px;
  background: var(--accent);
}
.toc-item[data-type="formule"]    .toc-item-type-dot { background: var(--c-formule); }
.toc-item[data-type="règle"]      .toc-item-type-dot { background: var(--c-regle); }
.toc-item[data-type="résumé"]     .toc-item-type-dot { background: var(--c-resume); }
.toc-item[data-type="définition"] .toc-item-type-dot { background: var(--c-definition); }
.toc-item[data-type="schéma"]     .toc-item-type-dot { background: var(--c-schema); }
.toc-item-title { font-size: .875rem; font-weight: 600; color: var(--text-1); margin-bottom: 2px; }
.toc-item-meta  { font-size: .75rem; color: var(--text-3); }

/* ================================================================
   PROGRESSION — simplified layout
   ================================================================ */
.prog-layout {
  display: flex; flex-direction: column; gap: 16px;
  padding: 16px;
}

/* ── Streak card ── */
.prog-streak-card {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  border-radius: 18px;
  padding: 24px 20px;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; text-align: center;
  box-shadow: 0 6px 20px rgba(249,115,22,.35);
  color: #fff;
}
.prog-flame { font-size: 2.2rem; }
.prog-streak-number {
  font-size: 3rem; font-weight: 900; line-height: 1;
  letter-spacing: -.02em;
}
.prog-streak-label { font-size: .85rem; font-weight: 600; opacity: .88; margin-top: 2px; }
.prog-streak-best  { font-size: .75rem; opacity: .72; margin-top: 4px; }
.prog-streak-best strong { font-weight: 700; opacity: 1; }

/* ── Sections ── */
.prog-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.prog-section-title {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-3); margin-bottom: 14px;
}

/* ── Stats grid ── */
.prog-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 10px;
}
.prog-stat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 8px; border-radius: 12px;
  border: 1.5px solid transparent;
  text-align: center;
}
.prog-stat-icon { font-size: 1.3rem; }
.prog-stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.prog-stat-label { font-size: .68rem; font-weight: 600; opacity: .75; }

/* Colour per type */
.prog-stat--new      { background: #EEF2FF; border-color: #C7D2FE; color: #4338CA; }
.prog-stat--hard     { background: #FFF1F2; border-color: #FECDD3; color: #E11D48; }
.prog-stat--easy     { background: #ECFDF5; border-color: #A7F3D0; color: #065F46; }
.prog-stat--total    { background: var(--bg-hover); border-color: var(--border); color: var(--text-2); }
[data-theme="dark"] .prog-stat--new  { background: rgba(99,102,241,.12); border-color: rgba(99,102,241,.25); color: #818CF8; }
[data-theme="dark"] .prog-stat--hard { background: rgba(225,29,72,.12);  border-color: rgba(225,29,72,.25);  color: #FB7185; }
[data-theme="dark"] .prog-stat--easy { background: rgba(6,95,70,.18);    border-color: rgba(52,211,153,.25); color: #34D399; }

/* ================================================================
   CHAT
   ================================================================ */
#view-chat { display: flex; flex-direction: column; height: calc(100dvh - 2px); }
@media (max-width: 639px) {
  #view-chat { height: calc(100dvh - var(--header-h) - var(--bottom-nav-h)); }
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; min-height: 200px;
}
.chat-msg {
  padding: 10px 14px; border-radius: var(--radius); max-width: 82%; font-size: .875rem; line-height: 1.6;
}
.chat-msg.user {
  align-self: flex-end; background: var(--accent); color: #fff;
}
.chat-msg.assistant {
  align-self: flex-start; background: var(--bg-surface);
  border: 1px solid var(--border-subtle); color: var(--text-2);
}
.chat-input-area {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 0 0; border-top: 1px solid var(--border-subtle);
}
#chat-input {
  flex: 1; padding: 10px 13px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-1);
  font-family: var(--font-body); font-size: .875rem; resize: none; outline: none;
  transition: border-color .15s;
}
#chat-input:focus { border-color: var(--accent); }

/* ================================================================
   FAVORITES
   ================================================================ */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-3);
}
.empty-state i { font-size: 2.8rem; opacity: .3; margin-bottom: 14px; display: block; }
.empty-state h3 { font-size: 1rem; color: var(--text-2); margin-bottom: 6px; }
.empty-state p { font-size: .85rem; }

/* ================================================================
   SETTINGS
   ================================================================ */
.settings-sections { display: flex; flex-direction: column; gap: 12px; max-width: 600px; }
.settings-section {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius); box-shadow: var(--shadow-xs); padding: 18px;
}
.settings-section h3 {
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin-bottom: 14px;
}
.setting-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border-subtle);
}
.setting-row:last-child { border-bottom: none; }
.setting-row label { flex: 1; font-size: .875rem; color: var(--text-2); }

/* Ollama status widget */
.ollama-status-widget { display: flex; align-items: center; gap: 8px; }
.ollama-status-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  transition: background .3s;
}
.dot-ready       { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.5); }
.dot-running     { background: #3b82f6; box-shadow: 0 0 6px rgba(59,130,246,.5); animation: pulse-blue 1.5s infinite; }
.dot-downloading { background: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,.5); animation: pulse-amber 1s infinite; }
.dot-missing     { background: #f59e0b; }
.dot-error       { background: #ef4444; }
@keyframes pulse-blue  { 0%,100%{opacity:1} 50%{opacity:.4} }
@keyframes pulse-amber { 0%,100%{opacity:1} 50%{opacity:.5} }
.ollama-model-name { font-size: .82rem; font-weight: 600; color: var(--text-1); font-family: var(--font-display); }
.ollama-status-label { font-size: .75rem; color: var(--text-3); }
.btn-group {
  display: flex; gap: 2px;
  background: var(--bg-hover); border-radius: var(--radius-xs); padding: 2px;
}
.btn-option {
  padding: 5px 10px; border: none; border-radius: 5px;
  font-size: .78rem; background: none; color: var(--text-3); transition: all .15s;
}
.btn-option.active { background: var(--bg-surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-xs); }
.color-swatches { display: flex; gap: 6px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; background: var(--c); transition: all .15s; }
.swatch.active, .swatch:hover { border-color: var(--text-1); transform: scale(1.15); }
input[type="range"] { accent-color: var(--accent); cursor: pointer; }
input[type="time"] {
  padding: 5px 8px; background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text-1); font-family: var(--font-body); font-size: .85rem; outline: none;
}
/* ── iOS-style toggle switch ── */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  width: 44px; height: 26px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #C7C7CC;
  border-radius: 999px;
  transition: background .22s ease;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.15);
}
[data-theme="dark"] .toggle-slider { background: #3A3A3C; }
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.12);
  transition: transform .22s cubic-bezier(.34,1.3,.64,1);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle:hover .toggle-slider::before { box-shadow: 0 3px 8px rgba(0,0,0,.3); }
#storage-bar-container { flex: 1; height: 4px; background: var(--bg-hover); border-radius: 999px; overflow: hidden; }
#storage-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #a78bfa); border-radius: 999px; transition: width .5s; }
#storage-label { font-size: .78rem; color: var(--text-3); }
#settings-username { font-size: .875rem; color: var(--text-2); font-weight: 500; }
.doc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border-subtle);
}
.doc-item:last-child { border-bottom: none; }
.doc-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.doc-status-dot.done       { background: #16a34a; }
.doc-status-dot.processing { background: #f97316; animation: pulse-dot 1.2s infinite; }
.doc-status-dot.error      { background: #dc2626; }
.doc-status-dot.pending    { background: var(--text-3); }
@keyframes pulse-dot { 0%,100%{opacity:1}50%{opacity:.25} }
.doc-name { flex: 1; font-size: .83rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-action-btn {
  padding: 4px 8px; border: 1px solid var(--border); background: var(--bg-hover);
  border-radius: 5px; color: var(--text-3); font-size: .73rem; transition: all .15s;
}
.doc-action-btn:hover { color: var(--text-1); border-color: var(--border-strong); }
.doc-action-btn.danger:hover { color: #dc2626; border-color: #fca5a5; }

/* ================================================================
   MODALS
   ================================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 800;
  background: rgba(0,0,0,.45); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 480px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden;
  animation: modal-in .22s cubic-bezier(.34,1.56,.64,1);
}
.modal-wide { max-width: 820px; }
@keyframes modal-in {
  from { opacity: 0; transform: scale(.93) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 14px; border-bottom: 1px solid var(--border-subtle);
}
.modal-header h3 { font-family: var(--font-display); font-size: 1rem; font-weight: 700; color: var(--text-1); }
.modal-close {
  width: 28px; height: 28px; border: none; background: var(--bg-hover);
  border-radius: 7px; color: var(--text-3); font-size: .95rem;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.modal-close:hover { background: var(--border); color: var(--text-1); }
.modal-body { padding: 18px 20px; }
.modal-postit-body { display: flex; gap: 18px; }
@media (max-width: 639px) { .modal-postit-body { flex-direction: column; } }
.postit-form { flex: 1; }
.postit-preview {
  flex: 1; min-width: 0; background: var(--bg-subtle);
  border: 1px solid var(--border-subtle); border-radius: var(--radius); padding: 14px;
}

/* ================================================================
   DROP ZONE (Upload)
   ================================================================ */

/* ── Upload tabs ── */
.upload-tabs {
  display: flex; gap: 6px; margin-bottom: 14px;
}
.upload-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 12px; border-radius: 10px; font-size: .83rem; font-weight: 600;
  border: 1.5px solid var(--border); background: var(--bg-hover);
  color: var(--text-3); cursor: pointer; transition: all .18s;
}
.upload-tab.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.upload-tab:not(.active):hover { border-color: var(--accent); color: var(--accent); }

/* ── Subject row ── */
.upload-subject-row { margin-bottom: 14px; }
.upload-subject-label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--text-2); margin-bottom: 5px;
}
.upload-subject-input {
  width: 100%; padding: 9px 13px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-1);
  font-family: var(--font-body); font-size: .88rem;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.upload-subject-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; color: var(--text-3);
  transition: all .2s; cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent); background: var(--accent-light); color: var(--accent);
}
.drop-zone .ti { font-size: 2.2rem; margin-bottom: 10px; display: block; opacity: .5; }
.drop-zone p { margin-bottom: 10px; font-size: .9rem; }
.drop-zone small { font-size: .78rem; color: var(--text-3); }

/* ── Web URL form ── */
.web-url-form {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 10px; background: var(--bg-surface);
  transition: border-color .15s;
}
.web-url-form:focus-within { border-color: var(--accent); }
.web-url-icon { font-size: 1.2rem; color: var(--text-3); flex-shrink: 0; }
.web-url-input {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--text-1); font-family: var(--font-body); font-size: .88rem;
  padding: 4px 0;
}
.web-url-input::placeholder { color: var(--text-3); }
.web-url-hint {
  font-size: .75rem; color: var(--text-3); margin-top: 10px; line-height: 1.5;
}

/* ── Progress ── */
.progress-bar-container { height: 4px; background: var(--bg-hover); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #a78bfa); border-radius: 999px; transition: width .4s; }
.upload-filename { font-size: .85rem; font-weight: 600; color: var(--text-1); margin-bottom: 6px; }
.upload-stage { font-size: .78rem; color: var(--text-3); margin-top: 4px; }

/* ================================================================
   FAB (Create postit)
   ================================================================ */
.fab {
  position: fixed; z-index: 150;
  bottom: 28px; right: 24px;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md); transition: all .2s;
}
.fab:hover { transform: scale(1.08); box-shadow: var(--shadow-lg); }
.fab.hidden { display: none; }
@media (max-width: 639px) {
  .fab { bottom: calc(var(--bottom-nav-h) + 14px); right: 16px; }
}

/* ================================================================
   BADGE (nav notification)
   ================================================================ */
.badge {
  background: var(--accent); color: #fff;
  font-size: .62rem; font-weight: 700;
  padding: 1px 5px; border-radius: 999px; min-width: 16px; text-align: center;
}
.badge.hidden { display: none; }

/* ================================================================
   TOAST
   ================================================================ */
#toast-container {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 6px;
  pointer-events: none; align-items: center;
}
@media (max-width: 639px) {
  #toast-container { bottom: calc(var(--bottom-nav-h) + 10px); }
}
.toast {
  padding: 9px 18px; border-radius: 999px;
  background: var(--text-1); color: var(--bg-base);
  font-size: .83rem; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .3s cubic-bezier(.34,1.56,.64,1);
  pointer-events: auto; white-space: nowrap;
}
.toast.success { background: #16a34a; color: #fff; }
.toast.error   { background: #dc2626; color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ================================================================
   UTILITY
   ================================================================ */
.hidden { display: none !important; }
