/* ==========================================================================
   Lisière — interface de lecture
   ========================================================================== */

body.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Barre supérieure --------------------------------------------------- */

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .8rem;
  height: 52px;
  padding: 0 .8rem;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
}

.bar-mark {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  color: var(--ink);
  flex: 0 0 auto;
}
.bar-mark svg { display: block; }
.bar-mark span { font-weight: 600; letter-spacing: -.01em; font-size: .95rem; }

.bar-doc {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  gap: .6rem;
  padding-left: .8rem;
  border-left: 1px solid var(--rule);
  height: 26px;
}
.bar-title {
  font-weight: 500;
  font-size: .92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-meta { font-size: .78rem; color: var(--ink-3); white-space: nowrap; flex: 0 0 auto; }
@media (max-width: 720px) { .bar-meta { display: none; } }

.bar-tools { display: flex; align-items: center; gap: .3rem; flex: 0 0 auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  height: 32px;
  padding: 0 .6rem;
  background: transparent;
  color: var(--ink-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .85rem;
  cursor: pointer;
}
.btn:hover { background: var(--paper-3); color: var(--ink); }
.btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-pale); }
.btn svg { display: block; }

.btn-primary {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
  font-weight: 500;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--paper); }
[data-theme="dark"] .btn-primary { color: #12211c; }
[data-theme="dark"] .btn-primary:hover { color: #12211c; }

.btn-icon { padding: 0; width: 32px; justify-content: center; }

/* --- Recherche ---------------------------------------------------------- */

.find {
  display: none;
  align-items: center;
  gap: .35rem;
  height: 32px;
  padding: 0 .35rem 0 .6rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.find.is-open { display: flex; }
.find input {
  width: 11rem;
  border: 0;
  background: none;
  outline: none;
  font-size: .85rem;
}
.find-count { font-size: .75rem; color: var(--ink-3); min-width: 3.2rem; text-align: right; }
.find button {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border: 0; background: none; color: var(--ink-2);
  border-radius: 2px; cursor: pointer;
}
.find button:hover { background: var(--paper-3); color: var(--ink); }
@media (max-width: 900px) { .find input { width: 7rem; } }

/* --- Corps -------------------------------------------------------------- */

/* La grille garde toujours ses trois colonnes ; seules leurs largeurs varient.
   Chaque zone est placée explicitement, sinon masquer un panneau ferait glisser
   la colonne de lecture dans une colonne de largeur nulle. */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--col-files) minmax(0, 1fr) var(--col-spine);
  min-height: 0;
  --col-files: 232px;
  --col-spine: 268px;
}
.layout[data-files="off"] { --col-files: 0px; }
.layout[data-spine="off"] { --col-spine: 0px; }

.files  { grid-column: 1; }
.reader { grid-column: 2; }
.spine  { grid-column: 3; }

/* --- Panneau des fichiers ---------------------------------------------- */

.files {
  border-right: 1px solid var(--rule);
  background: var(--paper-2);
  overflow-y: auto;
  padding: .9rem .6rem 2rem;
  min-width: 0;
}
.layout[data-files="off"] .files { display: none; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  padding: 0 .4rem .5rem;
  font-size: .8rem;
  color: var(--ink-3);
}
.panel-head button {
  border: 0; background: none; color: var(--ink-3);
  font-size: .78rem; cursor: pointer; padding: 0; text-decoration: underline;
}
.panel-head button:hover { color: var(--accent); }

.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.file-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: .45rem .5rem;
  border: 0;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  line-height: 1.3;
}
.file-item:hover { background: var(--paper-3); }
.file-item[aria-current="true"] { background: var(--accent-pale); }
.file-item[aria-current="true"] .file-name { color: var(--accent); font-weight: 600; }
.file-name {
  font-size: .85rem;
  display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-size { font-size: .72rem; color: var(--ink-3); }

.files-empty { padding: .4rem; font-size: .82rem; color: var(--ink-3); line-height: 1.5; }

/* --- Colonne de lecture ------------------------------------------------- */

.reader { overflow-y: auto; scroll-behavior: smooth; position: relative; min-width: 0; }
@media (prefers-reduced-motion: reduce) { .reader { scroll-behavior: auto; } }

.reader-inner { padding: 3.2rem 3rem 8rem; display: flex; justify-content: center; }
@media (max-width: 700px) { .reader-inner { padding: 2rem 1.2rem 6rem; } }

.sheet { width: 100%; max-width: var(--measure); }

/* --- Écran d'accueil / dépôt ------------------------------------------- */

.start { max-width: 34rem; margin: 2vh auto 0; }
.start h1 {
  font-family: var(--font-ui);
  font-size: 1.7rem;
  letter-spacing: -.03em;
  margin: 0 0 .5rem;
}
.start p { color: var(--ink-2); margin: 0 0 1.6rem; max-width: 46ch; }

.drop-target {
  display: grid;
  place-items: center;
  gap: .7rem;
  padding: 3rem 1.5rem;
  border: 1.5px dashed var(--rule);
  border-radius: 6px;
  background: var(--paper-2);
  text-align: center;
  cursor: pointer;
  width: 100%;
  color: inherit;
  font: inherit;
}
.drop-target:hover { border-color: var(--accent); background: var(--accent-pale); }
.drop-target strong { font-weight: 600; font-size: 1rem; }
.drop-target span { font-size: .85rem; color: var(--ink-2); }

.start-more { margin-top: 1.4rem; display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; align-items: center; font-size: .85rem; color: var(--ink-2); }
.start-more button { border: 0; background: none; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; font-size: .85rem; }

.shortcuts { margin-top: 2.6rem; border-top: 1px solid var(--rule); padding-top: 1rem; }
.shortcuts dl {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: .35rem 1rem;
  font-size: .84rem;
  color: var(--ink-2);
  margin: 0;
}
.shortcuts dt { color: var(--ink-3); }
.shortcuts dd { margin: 0; }
.shortcuts kbd {
  font-family: var(--font-mono);
  font-size: .74rem;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  padding: .05em .35em;
  background: var(--paper-2);
}

/* --- Sommaire à repères (signature) ------------------------------------ */

.spine {
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  padding: 1.4rem 1.1rem 4rem 0;
  min-width: 0;
}
.layout[data-spine="off"] .spine { display: none; }

.spine-head {
  font-size: .78rem;
  color: var(--ink-3);
  padding: 0 0 .8rem 1.6rem;
}

.spine-track {
  position: relative;
  padding-left: 1.6rem;
}
.spine-list { list-style: none; margin: 0; padding: 0; }
.spine-track::before {
  content: "";
  position: absolute;
  left: .55rem; top: .35rem; bottom: .35rem;
  width: 1px;
  background: var(--rule);
}
.spine-run {
  position: absolute;
  left: .5rem;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  opacity: .85;
}

.spine-link {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  cursor: pointer;
  padding: .16rem 0 .16rem .3rem;
  font-size: .82rem;
  line-height: 1.35;
  color: var(--ink-2);
  position: relative;
}
.spine-link::before {
  content: "";
  position: absolute;
  top: .62em;
  height: 1px;
  background: var(--ink-3);
  right: calc(100% + .12rem);
}
.spine-link[data-level="1"] { font-weight: 600; color: var(--ink); }
.spine-link[data-level="1"]::before { width: 1.05rem; }
.spine-link[data-level="2"]::before { width: .75rem; }
.spine-link[data-level="3"]::before { width: .45rem; }
.spine-link[data-level="4"]::before,
.spine-link[data-level="5"]::before,
.spine-link[data-level="6"]::before { width: .22rem; }
.spine-link[data-level="3"] { padding-left: .9rem; font-size: .79rem; }
.spine-link[data-level="4"],
.spine-link[data-level="5"],
.spine-link[data-level="6"] { padding-left: 1.5rem; font-size: .77rem; color: var(--ink-3); }

.spine-link:hover { color: var(--accent); }
.spine-link[aria-current="true"] { color: var(--accent); font-weight: 600; }
.spine-link[aria-current="true"]::before { background: var(--accent); height: 2px; }

.spine-empty { font-size: .82rem; color: var(--ink-3); }

/* --- Superposition de dépôt -------------------------------------------- */

.dropveil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
}
.dropveil.is-on { display: grid; }
.dropveil-box {
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: var(--paper-2);
  padding: 3rem 4rem;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 500;
  box-shadow: 0 20px 60px rgba(0,0,0,.12);
}
.dropveil-box span { display: block; font-size: .85rem; font-weight: 400; color: var(--ink-2); margin-top: .4rem; }

/* --- Messages ----------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.6rem;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: var(--paper);
  padding: .55rem 1rem;
  border-radius: 20px;
  font-size: .85rem;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
}
.toast.is-on { opacity: 1; }

/* --- Tiroirs mobiles ---------------------------------------------------- */

@media (max-width: 1080px) {
  /* Le sommaire passe en tiroir posé sur le texte : sa colonne disparaît. */
  .layout { --col-spine: 0px; }
  .spine {
    position: fixed;
    top: 52px; right: 0; bottom: 0;
    width: 268px;
    background: var(--paper);
    z-index: 30;
    padding-left: .4rem;
    box-shadow: -8px 0 24px rgba(0,0,0,.10);
  }
}

@media (max-width: 860px) {
  /* Le bouton principal se réduit à son icône : la barre tient sur la largeur. */
  .btn-primary .btn-label { display: none; }
  .btn-primary { padding: 0; width: 32px; justify-content: center; }
}

@media (max-width: 760px) {
  /* La liste des fichiers passe elle aussi en tiroir. */
  .layout { --col-files: 0px; }
  .files {
    position: fixed;
    top: 52px; left: 0; bottom: 0;
    width: 232px;
    z-index: 30;
    box-shadow: 8px 0 24px rgba(0,0,0,.10);
  }
  .bar { gap: .4rem; padding: 0 .5rem; }
  .bar-mark span { display: none; }
}

/* --- Impression --------------------------------------------------------- */

@page { margin: 18mm 16mm; }

@media print {
  body.app { height: auto; overflow: visible; display: block; }
  .bar, .files, .spine, .dropveil, .toast, .code-copy, .anchor { display: none !important; }
  .layout { display: block; }
  .reader { overflow: visible; }
  .reader-inner { padding: 0; display: block; }
  .sheet { max-width: none; }
  .doc { font-size: 11pt; max-width: none; color: #000; }
  .doc pre, .doc blockquote, .doc figure, .doc table { break-inside: avoid; }
  .doc h1, .doc h2, .doc h3 { break-after: avoid; }
  .doc a { color: #000; }
}
