/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --fond:       #f6f1eb;
  --panneau:    #fffdf9;
  --accent:     #c0582a;
  --bordure:    #e0d6c8;
  --txt-sec:    #5c5349;
  --txt-muet:   #9b9084;
  --txt-defaut: #1a1613;

  --c-sustantivo:   #2563eb;
  --c-verbo:        #dc2626;
  --c-adjetivo:     #059669;
  --c-adverbio:     #7c3aed;
  --c-pronombre:    #d97706;
  --c-preposicion:  #6b7280;
  --c-articulo:     #64748b;
  --c-conjuncion:   #6b7280;
  --c-determinante: #64748b;
  --c-interjeccion: #ec4899;
  --c-numeral:      #0891b2;

  --g-sujeto:                     #d97706;
  --g-verbo:                      #dc2626;
  --g-complemento_directo:        #2563eb;
  --g-complemento_indirecto:      #0891b2;
  --g-complemento_circunstancial: #9333ea;
  --g-relativa:                   #059669;
  --g-complemento:                #2563eb; /* rétro-compat */
}

html, body {
  height: 100%; width: 100%;
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--fond);
  color: var(--txt-defaut);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Top bar */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panneau);
  border-bottom: 1px solid var(--bordure);
  flex-shrink: 0;
  min-height: 52px;
}
#topbar h1 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 18px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
#topbar button {
  background: none;
  border: 1.5px solid var(--bordure);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--txt-sec);
  cursor: pointer;
  white-space: nowrap;
}
#topbar button:active { background: var(--bordure); }

/* Page nav — bottom bar */
#pagenav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panneau);
  border-top: 1px solid var(--bordure);
  flex-shrink: 0;
  font-size: 13px;
  color: var(--txt-muet);
  order: 2;
}
#pagenav.hidden { display: none; }
#pagenav button {
  background: none;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 14px;
  color: var(--txt-sec);
  cursor: pointer;
}
#pagenav button:disabled { opacity: .35; cursor: default; }
#pagenav button:active:not(:disabled) { background: var(--bordure); }

/* Main area: text + detail panel */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  order: 1;
}

/* Text panel */
#texte {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 80px;
  -webkit-overflow-scrolling: touch;
}

.paragraph-block {
  margin-bottom: 14px;
  line-height: 2;
}
.phrase-block {
  /* Flow inline dans .paragraph-block — les phrases d'un même
     paragraphe s'enchaînent et wrappent naturellement. */
}

.phrase-num {
  display: inline-block;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--txt-muet);
  min-width: 22px;
  text-align: center;
  margin-right: 6px;
  border-radius: 8px;
  padding: 1px 4px;
  cursor: pointer;
  vertical-align: middle;
}
.phrase-num.active {
  background: var(--accent);
  color: #fff;
}

.mot {
  display: inline;
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 0;
  transition: color .15s;
}
.mot:hover { filter: brightness(0.85) saturate(1.3); }
.mot.selected {
  background: rgba(192, 88, 42, .12);
}
.mot.expression {
  text-decoration: underline wavy var(--accent);
  text-underline-offset: 3px;
}

/* Syntactic group backgrounds */
.grp-sujeto                     { background: rgba(217,119,6,.08); }
.grp-verbo                      { background: rgba(220,38,38,.08); }
.grp-complemento_directo        { background: rgba(37,99,235,.08); }
.grp-complemento_indirecto      { background: rgba(8,145,178,.08); }
.grp-complemento_circunstancial { background: rgba(147,51,234,.08); }
.grp-relativa                   { background: rgba(5,150,105,.08); }
.grp-complemento                { background: rgba(37,99,235,.08); } /* rétro-compat */

/* ── Resize handle ─────────────────────────────────────── */
#resize-handle {
  width: 0;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--bordure);
  position: relative;
  z-index: 5;
  transition: width .25s ease;
}
#resize-handle.visible {
  width: 5px;
}
#resize-handle:hover, #resize-handle.dragging {
  background: var(--accent);
}

/* ── Detail panel ──────────────────────────────────────── */
#detail {
  width: 0;
  overflow: hidden;
  background: var(--panneau);
  border-left: 1px solid var(--bordure);
  transition: width .25s ease;
  flex-shrink: 0;
}
#detail.open {
  width: var(--detail-width, min(340px, 85vw));
}
#detail.no-transition, #resize-handle.no-transition {
  transition: none;
}
#detail-inner {
  width: var(--detail-width, min(340px, 85vw));
  min-width: 280px;
  height: 100%;
  overflow-y: auto;
  padding: 24px 20px;
  -webkit-overflow-scrolling: touch;
}
#detail-close {
  display: block;
  margin-bottom: 12px;
  font-size: 20px;
  background: none;
  border: none;
  color: var(--txt-muet);
  cursor: pointer;
}

#d-mot-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#d-mot {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 26px;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}
#d-trad-titre-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#d-trad-titre-row #d-trad-titre { flex: 1; }
.speak-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--bordure);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 16px;
  cursor: pointer;
  color: var(--txt-sec);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
.speak-btn:active { background: var(--selection); border-color: var(--accent); }
.speak-btn.speaking { background: var(--accent); color: #fff; border-color: var(--accent); }
#d-trad-speak-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.rate-btn {
  background: none;
  border: none;
  padding: 0;
  width: 24px;
  height: 14px;
  font-size: 9px;
  line-height: 1;
  color: var(--txt-muet);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity .15s, color .15s;
}
.rate-btn:hover { opacity: 1; color: var(--txt-sec); }
.rate-btn:active { color: var(--accent); }
.rate-btn:disabled { opacity: 0.2; cursor: default; }
.mot, .phrase-num {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
#d-lemme {
  font-size: 12px;
  color: var(--txt-muet);
  margin-top: 4px;
}
#d-prononciation {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--txt-sec);
  background: var(--fond);
  padding: 4px 10px;
  border-radius: 4px;
  margin-top: 6px;
  display: inline-block;
}
#d-categorie {
  display: inline-block;
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  padding: 3px 10px;
  border-radius: 10px;
  margin-top: 8px;
}
.detail-sep {
  border: none;
  border-top: 1px solid var(--bordure);
  margin: 12px 0;
}
#d-grammaire {
  font-size: 12px;
  color: var(--txt-sec);
  line-height: 1.7;
}
#d-grammaire b { color: var(--txt-defaut); }
#d-grammaire .ref-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
#d-definition {
  font-size: 13px;
  background: var(--fond);
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.6;
  margin-top: 8px;
}
#d-wordref {
  margin-top: 8px;
  font-size: 11px;
}
#d-wordref a { color: var(--accent); text-decoration: none; }

/* Expression section */
#d-expr { margin-top: 16px; }
#d-expr.hidden { display: none; }
#d-expr-titre {
  font-size: 10px;
  color: var(--txt-muet);
  letter-spacing: 2px;
  margin-bottom: 4px;
}
#d-expr-texte {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 18px;
  color: var(--accent);
}
#d-expr-sens {
  font-size: 13px;
  background: rgba(192,88,42,.06);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 4px;
  margin-top: 6px;
}

/* Translation section */
#d-trad { margin-top: 16px; }
#d-trad.hidden { display: none; }
#d-trad-titre {
  font-size: 10px;
  color: var(--txt-muet);
  letter-spacing: 2px;
  margin-bottom: 4px;
}
#d-trad-texte {
  font-size: 14px;
  font-style: italic;
  color: var(--txt-sec);
  background: rgba(192,88,42,.04);
  padding: 10px 14px;
  border-radius: 6px;
}

/* ── Welcome / empty state ─────────────────────────────── */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 40px;
  color: var(--txt-muet);
}
#welcome h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 28px;
  color: var(--accent);
  margin-bottom: 12px;
}
#welcome p { font-size: 14px; margin-bottom: 20px; }
#welcome button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 28px;
  font-size: 15px;
  cursor: pointer;
}
#welcome button:active { opacity: .8; }

/* ── Library ───────────────────────────────────────────── */
#library {
  margin-top: 24px;
  width: 100%;
  max-width: 400px;
}
#library h3 {
  font-size: 12px;
  color: var(--txt-muet);
  letter-spacing: 2px;
  margin-bottom: 10px;
  text-align: left;
}
.lib-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panneau);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s;
  text-align: left;
}
.lib-item:active { border-color: var(--accent); }
.lib-item .lib-icon {
  font-size: 24px;
  flex-shrink: 0;
}
.lib-item .lib-info { flex: 1; min-width: 0; }
.lib-item .lib-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--txt-defaut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-item .lib-pages {
  font-size: 11px;
  color: var(--txt-muet);
}
.lib-item.loading .lib-title { color: var(--txt-muet); }

/* Livres (dossier contenant des chapitres) */
.lib-book { margin-bottom: 8px; }
.lib-book .lib-item { margin-bottom: 0; }
.lib-book-caret {
  font-size: 12px;
  color: var(--txt-muet);
  flex-shrink: 0;
  transition: transform .15s;
}
.lib-book.expanded .lib-book-caret { transform: rotate(180deg); }
.lib-chapters {
  display: none;
  margin: 4px 0 0 14px;
  padding-left: 10px;
  border-left: 2px solid var(--bordure);
}
.lib-book.expanded .lib-chapters { display: block; }
.lib-chapter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 8px;
  transition: background .15s;
}
.lib-chapter:hover { background: var(--selection); }
.lib-chapter:active { background: var(--selection); }
.lib-chapter-num {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--txt-muet);
  min-width: 22px;
  text-align: left;
}
.lib-chapter-title {
  font-size: 13px;
  color: var(--txt-defaut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  flex: 1;
}
.lib-chapter.loading .lib-chapter-title { color: var(--txt-muet); }
.lib-chapter.current {
  background: var(--selection);
  border: 1px solid var(--accent);
}
.lib-chapter-badge {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--panneau);
}
.lib-book-resume {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}
.lib-book-resume:active { opacity: .8; }

/* #lib-separator retiré : les boutons sont maintenant dans leurs
   sections respectives (Analyses / Bibliothèque), plus de séparateur
   "ou" nécessaire. */

/* ── Layout desktop ≥ 900px : 2 colonnes Analyses | Bibliothèque ── */
@media (min-width: 900px) {
  #welcome {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "title    title"
      "intro    intro"
      "lastread lastread"
      "analyses library";
    column-gap: 32px;
    row-gap: 4px;
    align-items: start;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
  }
  #welcome h2     { grid-area: title;    text-align: center; }
  #welcome > p    { grid-area: intro;    text-align: center; }
  #last-read      { grid-area: lastread; max-width: none; justify-self: stretch; }
  #saved-analyses-container {
    grid-area: analyses;
    max-width: none;  /* prend toute la colonne */
    margin-top: 18px;
  }
  #library {
    grid-area: library;
    max-width: none;  /* prend toute la colonne */
    margin-top: 18px;
  }
}

/* ── Dernier document lu ───────────────────────────────── */
#last-read {
  margin-top: 12px;
  width: 100%;
  max-width: 400px;
}
#last-read.hidden { display: none; }
#last-read h3 {
  font-size: 12px;
  color: var(--txt-muet);
  letter-spacing: 2px;
  margin-bottom: 10px;
  text-align: left;
}
.last-read-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panneau);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: left;
  margin-bottom: 8px;
}
.last-read-card:last-child { margin-bottom: 0; }
.last-read-card:active { background: var(--selection); }
.last-read-card .lib-icon { font-size: 24px; flex-shrink: 0; }
.last-read-card .lib-info { flex: 1; min-width: 0; }
.last-read-card .lib-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--txt-defaut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.last-read-card .lib-pages {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}
.last-read-card .lib-arrow {
  font-size: 20px;
  color: var(--accent);
  flex-shrink: 0;
}

/* ── Légende (modal overlay) ───────────────────────────── */
#legende-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#legende-overlay.open { display: flex; }
#legende-modal {
  background: var(--fond);
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
#legende-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--panneau);
  border-bottom: 1px solid var(--bordure);
  flex-shrink: 0;
}
#legende-topbar h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 18px;
  color: var(--accent);
  flex: 1;
  margin: 0;
}
#legende-topbar button {
  background: none;
  border: 1.5px solid var(--bordure);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--txt-sec);
  cursor: pointer;
}
#legende-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.legende-section-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--txt-muet);
  letter-spacing: 1.5px;
  margin: 6px 0 8px;
}
.legende-section-title:not(:first-child) { margin-top: 18px; }
.legende-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.legende-cat {
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  cursor: pointer;
  background: var(--panneau);
  transition: border-color .15s;
}
.legende-cat:active { border-color: var(--accent); }
.legende-grp {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter .15s;
}
.legende-grp:active { filter: brightness(0.92); }
.legende-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--txt-muet);
  font-style: italic;
}

/* ── References panel (full-screen overlay) ───────────── */
#refs-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--fond);
  flex-direction: column;
}
#refs-overlay.open { display: flex; }

#refs-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panneau);
  border-bottom: 1px solid var(--bordure);
  flex-shrink: 0;
  min-height: 52px;
}
#refs-topbar h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 18px;
  color: var(--accent);
  flex: 0 0 auto;
}
#refs-search {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  background: var(--fond);
  color: var(--txt-defaut);
  font-size: 13px;
}
#refs-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#refs-topbar button {
  background: none;
  border: 1.5px solid var(--bordure);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--txt-sec);
  cursor: pointer;
}

#refs-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar with grouped themes */
#refs-sidebar {
  width: 220px;
  overflow-y: auto;
  border-right: 1px solid var(--bordure);
  background: var(--panneau);
  padding: 12px 0;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.refs-groupe-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--txt-muet);
  padding: 14px 16px 4px;
}
.refs-theme-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--txt-sec);
  cursor: pointer;
  text-align: left;
}
.refs-theme-btn:hover { background: rgba(192,88,42,.06); }
.refs-theme-btn.active {
  background: rgba(192,88,42,.10);
  color: var(--accent);
  font-weight: 600;
}
.refs-theme-btn .refs-icone { font-size: 16px; flex-shrink: 0; }

/* Résultats de recherche */
#refs-sidebar.recherche { display: flex; flex-direction: column; }
.refs-theme-btn.resultat { flex-direction: column; align-items: flex-start; gap: 2px; }
.refs-search-snippet {
  font-size: 11px;
  color: var(--txt-muet);
  line-height: 1.4;
  white-space: normal;
}
.refs-search-vide { color: var(--txt-muet); font-size: 12px; padding: 16px; }
#refs-content mark, .refs-search-snippet mark {
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  padding: 0 2px;
}
/* Lien « → Référence » du panneau détail */
#d-refs { margin-top: 2px; }
#d-refs a {
  display: block;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  margin-top: 4px;
}
#d-refs a:hover { text-decoration: underline; }

/* Content area */
#refs-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 60px;
  -webkit-overflow-scrolling: touch;
}
#refs-content:empty::after {
  content: "Choisissez un thème dans la liste.";
  color: var(--txt-muet);
  font-size: 14px;
  display: block;
  text-align: center;
  margin-top: 80px;
}

/* Fiche rendering */
.ref-fiche-titre {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 4px;
}
.ref-fiche-resume {
  font-size: 13px;
  color: var(--txt-muet);
  margin-bottom: 20px;
}
.ref-section {
  margin-bottom: 24px;
}
.ref-section-titre {
  font-size: 14px;
  font-weight: 700;
  color: var(--txt-defaut);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--bordure);
}

/* Tableau */
.ref-tableau {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}
.ref-tableau th {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 10px;
  text-align: left;
}
.ref-tableau td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--bordure);
  color: var(--txt-sec);
}
.ref-tableau tr:nth-child(even) td { background: rgba(192,88,42,.03); }
.ref-tableau td:first-child {
  font-weight: 600;
  color: var(--txt-defaut);
  white-space: nowrap;
}

/* Texte */
.ref-texte {
  font-size: 13px;
  line-height: 1.7;
  color: var(--txt-sec);
  background: var(--panneau);
  padding: 12px 16px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

/* Regles */
.ref-regle {
  margin-bottom: 10px;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
}
.ref-regle-titre {
  font-size: 13px;
  font-weight: 700;
  color: var(--txt-defaut);
}
.ref-regle-detail {
  font-size: 12px;
  color: var(--txt-sec);
  margin-top: 2px;
  line-height: 1.5;
}

/* Exemples */
.ref-exemple {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  padding: 8px 12px;
  background: var(--panneau);
  border-radius: 6px;
}
.ref-exemple-es {
  flex: 1;
  color: var(--accent);
  font-weight: 600;
}
.ref-exemple-fr {
  flex: 1;
  color: var(--txt-sec);
  font-style: italic;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 600px) {
  #detail.open {
    width: 100vw !important;
    position: absolute; right: 0; top: 0; bottom: 0; z-index: 10;
  }
  #detail-inner { width: 100vw !important; min-width: 0; }
  #resize-handle { display: none; }

  #refs-body { flex-direction: column; }
  #refs-sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--bordure);
  }
  #refs-content { padding: 16px; }
  .ref-exemple { flex-direction: column; gap: 2px; }
  .ref-tableau { font-size: 11px; }
  .ref-tableau th, .ref-tableau td { padding: 4px 6px; }
}

/* ── Phase A — partage / coller / saisie manuelle ──────── */

.hidden { display: none !important; }

/* Boutons réutilisables — utilisés dans modal saisie et vue partagée */
.btn-primary,
.btn-secondary {
  border: 1.5px solid var(--bordure);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:active { background: #a64a23; border-color: #a64a23; }
.btn-secondary {
  background: var(--panneau);
  color: var(--txt-sec);
}
.btn-secondary:active { background: var(--bordure); }

/* Bouton "Analyser un texte" sur l'écran d'accueil — hérite de
   #welcome button (couleur accent + padding), on ajoute juste un
   petit espacement avec le bouton suivant. */
#btn-analyser-home {
  margin-top: 14px;
  font-weight: 600;
}

/* Vue Texte partagé (#share-view) */
#share-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  width: 100%;
}
#share-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
#share-header h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 22px;
  color: var(--accent);
  margin: 0;
}
#btn-share-back {
  background: none;
  border: 1.5px solid var(--bordure);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 20px;
  color: var(--txt-sec);
  cursor: pointer;
}
#btn-share-back:active { background: var(--bordure); }
#share-meta {
  font-size: 12px;
  color: var(--txt-muet);
}
#share-text {
  width: 100%;
  min-height: 220px;
  padding: 14px;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  background: var(--panneau);
  color: var(--txt-defaut);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
}
#share-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#share-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Phase H — 4 boutons de mode d'analyse ──────────────── */
#share-modes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.btn-mode {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--bordure);
  border-radius: 10px;
  background: var(--panneau);
  color: var(--txt-sec);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.btn-mode:hover,
.btn-mode:active {
  background: #fff3e0;
  border-color: var(--accent);
  color: var(--accent);
}
.btn-mode.btn-mode-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-mode.btn-mode-primary:active { background: #a64a23; }
.btn-mode:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-mode-url { /* visibilité gérée par .hidden quand pas d'URL */ }
#share-error {
  padding: 10px 14px;
  background: #fff3e0;
  border: 1px solid #f5c89a;
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  text-align: center;
}

/* Estimation de coût live (Phase G.1) */
#share-cost {
  font-size: 11px;
  color: var(--txt-muet);
  text-align: right;
  padding: 0 4px;
}
#share-cost.hidden { display: none; }

/* Loader pendant l'analyse Claude (Phase D) */
#share-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panneau);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  color: var(--txt-sec);
  font-size: 14px;
}
.share-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--bordure);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: share-spin 0.8s linear infinite;
}
@keyframes share-spin {
  to { transform: rotate(360deg); }
}
#share-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Phase F — section "Analyses" (IndexedDB) ──────────── */

#saved-analyses-container {
  margin-top: 22px;
  width: 100%;
  max-width: 400px;  /* aligné sur #library pour cohérence visuelle */
}
#saved-analyses-empty {
  text-align: center;
  color: var(--txt-muet);
  font-size: 13px;
  padding: 16px 0;
  font-style: italic;
}
#saved-analyses-empty.hidden { display: none; }
#saved-analyses-container #btn-analyser-home {
  width: 100%;
  margin-top: 10px;
  /* hérite des styles #welcome button + #btn-analyser-home (accent) */
}
#library #btn-ouvrir2 {
  width: 100%;
  margin-top: 10px;
  /* hérite des styles #welcome button */
}
#saved-analyses-container h3 {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--txt-muet);
  font-weight: 600;
  margin-bottom: 8px;
}
#saved-analyses-total {
  font-size: 11px;
  color: var(--txt-muet);
  margin-bottom: 10px;
  text-align: right;
  font-style: italic;
}
#saved-analyses-total.hidden { display: none; }
#saved-analyses-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.saved-card {
  position: relative;
  min-height: 70px;
  box-sizing: border-box;
  padding: 12px 40px 12px 14px;
  background: var(--panneau);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.saved-card:hover {
  background: #fff3e0;
  border-color: var(--accent);
}
.saved-card-title {
  font-size: 14px;
  color: var(--txt-defaut);
  line-height: 1.4;
  margin-bottom: 4px;
  word-break: break-word;
}
.saved-card-meta {
  font-size: 11px;
  color: var(--txt-muet);
}
.saved-card-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  background: none;
  border: none;
  color: var(--txt-muet);
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
}
.saved-card-del:hover {
  background: var(--bordure);
  color: var(--accent);
}
.saved-card-export {
  position: absolute;
  top: 36px;
  right: 8px;
  width: 26px;
  height: 26px;
  background: none;
  border: none;
  color: var(--txt-muet);
  font-size: 15px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
}
.saved-card-export:hover {
  background: var(--bordure);
  color: var(--accent);
}

/* Modal de saisie manuelle (#manual-modal) */
#manual-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(26, 22, 19, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
#manual-modal-inner {
  background: var(--panneau);
  border-radius: 14px;
  padding: 24px;
  max-width: 540px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}
#manual-modal-inner h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 22px;
  color: var(--accent);
}
.manual-hint {
  font-size: 13px;
  color: var(--txt-muet);
  margin-bottom: 4px;
}
#manual-textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  background: var(--fond);
  color: var(--txt-defaut);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
}
#manual-textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#manual-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* ── Phase B — Modal Paramètres ─────────────────────────── */

#settings-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(26, 22, 19, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
#settings-modal-inner {
  background: var(--panneau);
  border-radius: 14px;
  padding: 22px 24px;
  max-width: 540px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  max-height: 90vh;
  overflow-y: auto;
}
#settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
#settings-modal-inner h2 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 22px;
  color: var(--accent);
  margin: 0;
}
.settings-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--txt-sec);
  margin-top: 8px;
}
#settings-api-key,
#settings-model {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  background: var(--fond);
  font-family: inherit;
  font-size: 14px;
  color: var(--txt-defaut);
}
#settings-api-key:focus,
#settings-model:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.settings-hint {
  font-size: 12px;
  color: var(--txt-muet);
}
.settings-hint a {
  color: var(--accent);
  text-decoration: none;
}
.settings-hint a:hover { text-decoration: underline; }
.settings-disclaimer {
  margin-top: 6px;
  padding: 12px 14px;
  background: #fff7eb;
  border: 1px solid #f5d6a0;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--txt-sec);
}
.settings-status {
  min-height: 1em;
  padding: 0;
  font-size: 13px;
  color: var(--txt-muet);
  text-align: center;
}
.settings-status.ok    { color: #059669; font-weight: 600; }
.settings-status.error { color: #dc2626; font-weight: 600; }
.settings-status.warn  { color: var(--accent); }
.settings-status.info  { color: var(--txt-muet); }
#settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
#settings-actions button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Bookmarklet (settings modal) ───────────────────────── */

.settings-sep {
  border: none;
  border-top: 1px solid var(--bordure);
  margin: 20px 0 4px 0;
}

#settings-bookmarklet {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bookmarklet-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#bookmarklet-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  text-decoration: none;
  background: var(--panneau);
  font-weight: 600;
  font-size: 13px;
  cursor: grab;
  user-select: none;
}
#bookmarklet-link:active { cursor: grabbing; }
#bookmarklet-link:hover { background: #fff3e0; }

#bookmarklet-code {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  background: var(--fond);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--txt-defaut);
  resize: vertical;
  min-height: 60px;
  white-space: pre-wrap;
  word-break: break-all;
}

.settings-details {
  background: var(--fond);
  border: 1px solid var(--bordure);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--txt-sec);
}
.settings-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 0;
}
.settings-details ol,
.settings-details ul {
  margin: 8px 0 8px 20px;
  line-height: 1.6;
}
.settings-details li { margin-bottom: 4px; }

