/* Agora v2 — static/css/readers.css: universal viewer, 100% front (PDF.js,
   Word .docx, SheetJS spreadsheet, PowerPoint .pptx, OpenDocument, EPUB,
   ZIP, SVG, JSON, Diff, highlighted code). 100% Halo theme tokens
   (tests/front/theme.test.mjs: no hardcoded colour). */

html.lct-open, html.lct-open body { overflow: hidden; }

.lct-veil {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(var(--shadow-rgb), .78);
  display: flex; flex-direction: column;
}

.lct-frame {
  flex: 1; min-height: 0; width: 100%;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
}

.lct-top {
  flex: none; min-height: 54px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.lct-info { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1 1 220px; }
.lct-badge {
  flex: none; font: 700 10.5px/1.2 var(--mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 6px;
  background: rgba(var(--accent-rgb), .15); border: 1px solid rgba(var(--accent-rgb), .4);
  color: var(--accent);
}
.lct-titles { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lct-name { font-size: 14px; font-weight: 650; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lct-meta { font: 11.5px var(--mono); color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lct-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lct-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }

.lct-rech {
  min-height: 32px; width: 210px; max-width: 45vw; padding: 0 10px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; font: 12.5px var(--sans); outline: none;
}
.lct-rech:focus { border-color: var(--accent); }
.lct-counter { font: 500 11.5px var(--mono); color: var(--muted); padding: 0 4px; white-space: nowrap; }

.lct-body {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; flex-direction: column;
}
.lct-state {
  margin: auto; padding: 32px 20px; text-align: center;
  font-size: 13.5px; color: var(--muted); max-width: 480px;
}

/* -- Layout with a side panel (PDF, DOCX outline, PPTX thumbnails, ZIP) -- */
.lct-split {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}
.lct-nav {
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px;
}
.lct-nav-t {
  font: 700 10.5px var(--mono); text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); padding: 4px 6px 6px;
}
.lct-nav-item {
  text-align: left; background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 7px 9px; color: var(--muted); font: 12.5px/1.35 var(--sans); cursor: pointer;
  display: flex; align-items: baseline; gap: 7px;
}
.lct-nav-item:hover { color: var(--text); background: var(--panel-2); }
.lct-nav-item.on {
  color: var(--text); font-weight: 620;
  background: rgba(var(--accent-rgb), .14); border-color: rgba(var(--accent-rgb), .42);
}
.lct-nav-num { font: 600 11px var(--mono); color: var(--accent-2); flex: none; }
.lct-main { min-height: 0; overflow: auto; padding: 22px; }

@media (max-width: 820px) {
  .lct-split { grid-template-columns: 1fr; }
  .lct-nav { max-height: 150px; border-right: 0; border-bottom: 1px solid var(--line); }
  .lct-main { padding: 12px; }
}

/* -- PDF.js: scrolling pages + selectable text layer
   ------------------------- */
.lct-pdf-stream {
  display: flex; flex-direction: column; align-items: stretch; gap: 18px;
  padding: 20px 14px 48px;
}
.lct-pdf-page {
  position: relative; margin: 0 auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 10px 28px rgba(var(--shadow-rgb), .35);
  overflow: hidden; flex: none;
}
.lct-pdf-page.cible { outline: 2px solid var(--accent-2); outline-offset: 3px; }
.lct-pdf-canvas { display: block; width: 100%; height: 100%; }
.lct-pdf-txt {
  position: absolute; inset: 0; overflow: hidden; line-height: 1;
  user-select: text; -webkit-user-select: text;
}
.lct-pdf-txt span {
  position: absolute; white-space: pre; transform-origin: 0 0;
  color: transparent; cursor: text;
}
.lct-pdf-txt ::selection { background: rgba(var(--accent-rgb), .35); }
.lct-pdf-num {
  position: absolute; right: 8px; bottom: 6px; pointer-events: none;
  font: 600 10.5px var(--mono); padding: 2px 6px; border-radius: 5px;
  background: var(--panel); color: var(--faint); border: 1px solid var(--line);
}

/* -- Rich document: Word (.docx), OpenDocument (.odt), EPUB, Markdown
   -------- */
.lct-page-doc {
  width: min(820px, 100%); margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px 38px; line-height: 1.65; font-size: 15px; color: var(--text);
  box-shadow: 0 10px 30px rgba(var(--shadow-rgb), .25);
}
@media (max-width: 640px) { .lct-page-doc { padding: 18px 16px; } }
.lct-page-doc h1, .lct-page-doc h2, .lct-page-doc h3, .lct-page-doc h4 {
  color: var(--text); line-height: 1.3; margin: 1.2em 0 .45em; font-weight: 700;
}
.lct-page-doc h1:first-child, .lct-page-doc h2:first-child { margin-top: 0; }
.lct-page-doc h1 { font-size: 24px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.lct-page-doc h2 { font-size: 19px; }
.lct-page-doc h3 { font-size: 16px; color: var(--accent); }
.lct-page-doc p { margin: 0 0 .85em; overflow-wrap: anywhere; }
.lct-page-doc ul, .lct-page-doc ol { margin: 0 0 .9em 1.4em; }
.lct-page-doc li { margin-bottom: .3em; }
.lct-page-doc blockquote {
  margin: .8em 0; padding: 8px 14px; border-left: 3px solid var(--accent);
  background: var(--panel-2); border-radius: 0 8px 8px 0; color: var(--muted);
}
.lct-page-doc img { max-width: 100%; height: auto; border-radius: 8px; margin: 8px 0; }
.lct-page-doc a { color: var(--accent-2); text-decoration: underline; }
.lct-page-doc table, .lct-slide-table {
  width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13.5px;
}
.lct-page-doc th, .lct-page-doc td, .lct-slide-table th, .lct-slide-table td {
  border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top;
}
.lct-page-doc th, .lct-slide-table th { background: var(--panel-2); font-weight: 650; }
.lct-doc-mark { background: rgba(var(--warn-rgb), .28); color: var(--text); border-radius: 3px; padding: 0 2px; }

/* -- Spreadsheet (SheetJS .xlsx / .xls / .ods / .csv / .tsv)
   ----------------- */
.lct-tabs-bar {
  flex: none; display: flex; align-items: center; gap: 5px; overflow-x: auto;
  padding: 7px 16px; background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.lct-table-wrap { flex: 1; min-height: 0; overflow: auto; }
.lct-table {
  border-collapse: separate; border-spacing: 0; min-width: 100%;
  font-size: 13px; color: var(--text);
}
.lct-table th, .lct-table td {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 6px 10px; white-space: nowrap; max-width: 380px;
  overflow: hidden; text-overflow: ellipsis;
}
.lct-table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--panel);
  font: 600 11.5px var(--mono); color: var(--muted); text-align: left; cursor: pointer;
  user-select: none;
}
.lct-table thead th:hover { color: var(--text); background: var(--panel-2); }
.lct-table thead th.sort { color: var(--accent); }
.lct-table .col-num {
  position: sticky; left: 0; z-index: 1; background: var(--panel);
  font: 500 11px var(--mono); color: var(--faint); text-align: right; width: 46px; cursor: default;
}
.lct-table thead .col-num { z-index: 3; }
.lct-table tbody tr:hover td { background: rgba(var(--accent-rgb), .06); }

/* -- PowerPoint (.pptx) & Impress (.odp) presentations
   ----------------------- */
.lct-slide-scène {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  max-width: 1060px; margin: 0 auto; width: 100%;
}
.lct-slide-canvas {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  container-type: inline-size;
  background: var(--panel); border: 1px solid var(--ligne-forte); border-radius: 14px;
  padding: 3.5% 4.5%; overflow: auto;
  box-shadow: 0 14px 36px rgba(var(--shadow-rgb), .4);
}
.lct-slide-canvas.flux { display: flex; flex-direction: column; gap: 14px; justify-content: center; }
.lct-slide-block { overflow-wrap: anywhere; }
.lct-slide-block.pos { position: absolute; overflow: auto; }
.lct-slide-block.role-titre { font-size: clamp(14px, 3.1cqw, 28px); font-weight: 720; color: var(--text); line-height: 1.25; }
.lct-slide-block.role-sous-titre { font-size: clamp(12px, 2.1cqw, 19px); color: var(--muted); line-height: 1.4; }
.lct-slide-block.role-corps { font-size: clamp(11px, 1.9cqw, 16.5px); color: var(--text); line-height: 1.45; }
.lct-slide-p { margin-bottom: .4em; }
.lct-slide-p.chip-tag { padding-left: 1.1em; position: relative; }
.lct-slide-p.chip-tag::before { content: '•'; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
.lct-slide-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; display: block; }
.lct-slide-notes {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 15px; font-size: 13px; color: var(--muted); white-space: pre-wrap; line-height: 1.5;
}
.lct-slide-notes-t { font: 700 10.5px var(--mono); text-transform: uppercase; color: var(--faint); margin-bottom: 4px; }

/* -- Highlighted code (Highlight.js), Diff, JSON & SVG
   ----------------------- */
.lct-code-frame {
  width: min(1140px, 100%); margin: 18px auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden;
}
.lct-code-table { width: 100%; border-collapse: collapse; font: 12.5px/1.55 var(--mono); }
.lct-code-ln {
  width: 48px; padding: 0 10px; text-align: right; user-select: none;
  color: var(--faint); border-right: 1px solid var(--line); background: var(--panel-2);
  vertical-align: top;
}
.lct-code-src { padding: 0 14px; white-space: pre; color: var(--text); vertical-align: top; }
.lct-code-frame.wrap .lct-code-src { white-space: pre-wrap; overflow-wrap: anywhere; }
.lct-code-bloc { margin: 0; padding: 14px 16px; overflow-x: auto; font: 12.5px/1.55 var(--mono); color: var(--text); }

/* Highlight.js classes mapped to Halo tokens (>= 4.5:1 dark & light) */
.lct-code-frame .hljs-keyword, .lct-code-frame .hljs-selector-tag, .lct-code-frame .hljs-built_in { color: var(--accent); font-weight: 600; }
.lct-code-frame .hljs-string, .lct-code-frame .hljs-attr, .lct-code-frame .hljs-addition { color: var(--live); }
.lct-code-frame .hljs-number, .lct-code-frame .hljs-literal, .lct-code-frame .hljs-variable, .lct-code-frame .hljs-template-variable { color: var(--warn); }
.lct-code-frame .hljs-title, .lct-code-frame .hljs-section, .lct-code-frame .hljs-type { color: var(--accent-2); font-weight: 600; }
.lct-code-frame .hljs-comment, .lct-code-frame .hljs-quote, .lct-code-frame .hljs-meta { color: var(--faint); font-style: italic; }
.lct-code-frame .hljs-deletion { color: var(--bad); }

/* Unified diff */
.lct-diff-file {
  width: min(1140px, 100%); margin: 16px auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.lct-diff-header {
  padding: 9px 14px; background: var(--panel-2); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font: 600 12.5px var(--mono); color: var(--text);
}
.lct-diff-stats { display: flex; gap: 8px; font-size: 11.5px; }
.lct-diff-more { color: var(--live); }
.lct-diff-less { color: var(--bad); }
.lct-diff-tr.add td { background: rgba(var(--live-rgb), .11); }
.lct-diff-tr.del td { background: rgba(var(--bad-rgb), .11); }
.lct-diff-tr.hunk td { background: rgba(var(--accent-rgb), .1); color: var(--accent); font-weight: 600; }
.lct-diff-tr.meta td { color: var(--faint); }

/* Tree JSON */
.lct-json-tree {
  width: min(1040px, 100%); margin: 18px auto; padding: 18px 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  font: 13px/1.6 var(--mono); color: var(--text);
}
.lct-json-node { padding-left: 18px; border-left: 1px dashed var(--line); margin-left: 4px; }
.lct-json-node > summary { cursor: pointer; list-style: revert; color: var(--muted); }
.lct-json-key { color: var(--accent-2); }
.lct-json-str { color: var(--live); overflow-wrap: anywhere; }
.lct-json-num { color: var(--warn); }
.lct-json-bool { color: var(--accent); font-weight: 600; }
.lct-json-null { color: var(--faint); font-style: italic; }

/* Safe SVG preview */
.lct-svg-scène {
  flex: 1; width: 100%; display: grid; place-items: center; padding: 28px; overflow: auto;
}
.lct-svg-frame {
  width: min(820px, 100%);
  padding: 24px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); box-shadow: 0 10px 30px rgba(var(--shadow-rgb), .3);
  display: grid; place-items: center;
}
.lct-svg-frame.clair { background: var(--text); }
[data-theme="clair"] .lct-svg-frame.clair { background: var(--panel); }
.lct-svg-img { max-width: 100%; max-height: 460px; height: auto; object-fit: contain; display: block; transform-origin: center; }

/* Enriched Office / PDF cards in Attachments & the thread */
.fich-card .fich-apercu-btn {
  width: 100%; min-height: 110px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer; padding: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
}
.fich-card .fich-apercu-btn:hover { border-color: var(--accent); background: rgba(var(--accent-rgb), .08); }
.fich-card .fich-apercu-vig { max-height: 130px; max-width: 100%; border-radius: 6px; object-fit: contain; }
.fich-card .fich-fmt-tag {
  font: 700 11px var(--mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; color: var(--accent);
  background: rgba(var(--accent-rgb), .14); border: 1px solid rgba(var(--accent-rgb), .35);
}

/* ==================== VIEWER ALREADY OPEN IN PLACE (.lct-inline) ==================== */

.lct-inline {
  width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--text);
  display: flex; flex-direction: column; overflow: hidden;
}

.lct-inline-top {
  flex: none; padding: 8px 12px;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap;
}
.lct-inline-top .lct-info { flex: 1 1 180px; min-width: 0; }
.lct-inline-top .lct-name { font-size: 13.5px; }
.lct-inline-top .lct-rech { width: 155px; min-height: 29px; font-size: 12px; }
.lct-inline-top .lct-tools { gap: 5px; }
.lct-inline-top .lct-actions { gap: 6px; }

.lct-inline-leg {
  padding: 7px 14px; margin: 0;
  background: var(--panel); border-bottom: 1px solid var(--line);
  font-size: 13px; line-height: 1.45; color: var(--muted);
}

.lct-inline-body {
  position: relative; width: 100%; min-width: 0;
  display: flex; flex-direction: column; overflow: auto;
  background: var(--bg);
}
.lct-inline-body .lct-state { padding: 22px 16px; }

/* Heights adapted per family when reading in place */
.lct-inline[data-mode="pdf"] .lct-inline-body { height: 520px; }
.lct-inline.compact[data-mode="pdf"] .lct-inline-body,
.trv-section.cols-2 .lct-inline[data-mode="pdf"] .lct-inline-body,
.trv-section.cols-3 .lct-inline[data-mode="pdf"] .lct-inline-body { height: 360px; }

.lct-inline[data-mode="docx"] .lct-inline-body,
.lct-inline[data-mode="odf"] .lct-inline-body,
.lct-inline[data-mode="epub"] .lct-inline-body,
.lct-inline[data-mode="markdown"] .lct-inline-body { max-height: 480px; }
.lct-inline.compact[data-mode="docx"] .lct-inline-body,
.lct-inline.compact[data-mode="odf"] .lct-inline-body { max-height: 340px; }

.lct-inline .lct-main { padding: 14px; }
.lct-inline .lct-page-doc {
  width: 100%; border-radius: 10px; padding: 20px 24px;
  box-shadow: none; font-size: 14.5px;
}

.lct-inline[data-mode="tableur"] .lct-inline-body { max-height: 420px; background: var(--panel); }
.lct-inline.compact[data-mode="tableur"] .lct-inline-body { max-height: 320px; }

.lct-inline[data-mode="pptx"] .lct-inline-body { max-height: none; overflow: visible; }
.lct-inline[data-mode="pptx"] .lct-main { overflow: visible; }
.lct-inline[data-mode="pptx"] .lct-slide-canvas { box-shadow: 0 6px 20px rgba(var(--shadow-rgb), .25); }

.lct-inline[data-mode="code"] .lct-inline-body,
.lct-inline[data-mode="diff"] .lct-inline-body,
.lct-inline[data-mode="json"] .lct-inline-body { max-height: 420px; }
.lct-inline.compact[data-mode="code"] .lct-inline-body,
.lct-inline.compact[data-mode="diff"] .lct-inline-body,
.lct-inline.compact[data-mode="json"] .lct-inline-body { max-height: 300px; }
.lct-inline .lct-code-frame,
.lct-inline .lct-diff-file,
.lct-inline .lct-json-tree {
  width: 100%; margin: 0; border: 0; border-radius: 0;
}
.lct-inline[data-mode="diff"] .lct-main { padding: 0; }

.lct-inline[data-mode="svg"] .lct-svg-scène { padding: 16px; }
.lct-inline[data-mode="svg"] .lct-svg-frame { padding: 14px; box-shadow: none; max-width: 100%; }

.lct-inline[data-mode="zip"] .lct-inline-body { height: 360px; }
.lct-inline[data-mode="zip"] .lct-split { grid-template-columns: 190px minmax(0, 1fr); }
@media (max-width: 720px) {
  .lct-inline[data-mode="zip"] .lct-split { grid-template-columns: 1fr; }
}

/* In compositions (Page mode): .trv-bl-meta sits under the viewer without
   ever covering the buttons */
.trv-bl-meta { pointer-events: none; }
.trv-bl:hover .trv-bl-meta, .trv-bl:focus-within .trv-bl-meta, .trv-bl.foc .trv-bl-meta { pointer-events: auto; }
.trv-bl:has(.lct-inline) { padding-bottom: 10px; }
.trv-bl:has(.lct-inline) .trv-bl-meta { position: static; margin-top: 8px; }
.trv-file:has(.lct-inline-leg) + .trv-leg { display: none; }

/* In the thread's Files (/fils/<id>/fichiers): wide cards to read each
   document directly */
.fich-grid:has(.lct-inline) {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr));
}
.piece.attachment-reader-host { width: min(860px, 100%); padding: 0; background: none; border: 0; }
