/* ============================================================
   lib-shell-template — canonical reference frontend lib navigable
   Drafté 2026-05-13 thread `ao-detector-frontend-lib-shell` round-3.

   CSS variables génériques au début (--surface-accent / --surface-r-* ...)
   → override dans :root de ton style.css pour appliquer ta palette.
   Tout le reste utilise ces variables, aucun hex hardcoded en composants.

   Référence sources canoniques (cultural-library, lecture-only) :
   - boardgame/style.css (pattern le + mature)
   - papers/style.css (text-card layout)
   - articles/stats.html (heatmap source × thème)
   ============================================================ */

:root {
  /* ─── Layout dimensions ─── */
  --lib-sidebar-width: 260px;
  --lib-main-max-width: 1600px;

  /* ─── Palette ao-detector (ambre tranché David R2 thread ao-detector-frontend-lib-shell) ─── */
  --surface-accent:        #ffb300;  /* ambre administratif — registre veille/alerte cohérent 🚨 ao.alert */
  --surface-accent-bg:     #fff3cd;
  --surface-accent-hover:  #cc8800;

  /* ─── Rating color bands (scale 0-100 score Haiku, cohérent 8 univers CL) ─── */
  --surface-r-low:    #f7d7d4;  /* 0-30 : peu pertinent */
  --surface-r-mid:    #fce6cf;  /* 30-50 : indirect */
  --surface-r-good:   #fff2c2;  /* 50-70 : partiel */
  --surface-r-high:   #d9efc8;  /* 70-85 : fort */
  --surface-r-top:    #aedea7;  /* 85+ : alerte critique */

  /* ─── Hype / anticipation bands ─── */
  --surface-h-cold:   #ecf0f3;
  --surface-h-warm:   #ffe5b4;
  --surface-h-hot:    #ffcca0;
  --surface-h-fire:   #ffaf80;

  /* ─── Neutres (rarely overridés, defaults raisonnables) ─── */
  --surface-bg:           #fafafa;
  --surface-fg:           #1a1a1a;
  --surface-fg-soft:      #555;
  --surface-fg-muted:     #888;
  --surface-card-bg:      #ffffff;
  --surface-border:       #d0d0d0;
  --surface-border-soft:  #e5e5e5;

  --shadow-card:        0 1px 3px rgba(0,0,0,0.04);
  --shadow-card-hover:  0 6px 16px rgba(0,0,0,0.08);
  --shadow-modal:       0 10px 40px rgba(0,0,0,0.2);
}

* { box-sizing: border-box; }
html, body { font-size: 14px; }
body {
  margin: 0;
  background: var(--surface-bg);
  color: var(--surface-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}
a { color: var(--surface-accent); text-decoration: none; }
a:hover { color: var(--surface-accent-hover); text-decoration: underline; }

/* ─────────────────────────────────────────────────────────────
   Layout : sidebar + main
   ───────────────────────────────────────────────────────────── */

body.lib-layout {
  display: grid;
  grid-template-columns: var(--lib-sidebar-width) 1fr;
  min-height: 100vh;
}

.lib-sidebar {
  background: var(--surface-card-bg);
  border-right: 1px solid var(--surface-border);
  padding: 1em 0.9em;
  display: flex; flex-direction: column;
  gap: 0.9em;
  position: sticky; top: 0;
  max-height: 100vh; overflow-y: auto;
  font-size: 0.92em;
}

.lib-brand {
  font-size: 1.3em; font-weight: 700;
  color: var(--surface-fg);
  padding: 0.2em 0.4em;
  border-radius: 5px;
  display: block;
}
.lib-brand:hover {
  background: var(--surface-accent-bg);
  color: var(--surface-accent);
  text-decoration: none;
}

.lib-nav { display: flex; flex-direction: column; gap: 0.15em; }
.lib-nav a {
  padding: 0.45em 0.6em;
  color: var(--surface-fg-soft);
  border-radius: 5px;
  font-size: 0.95em;
}
.lib-nav a:hover {
  background: var(--surface-border-soft);
  color: var(--surface-fg);
  text-decoration: none;
}
.lib-nav a.active {
  background: var(--surface-accent-bg);
  color: var(--surface-accent);
  font-weight: 600;
}

.lib-section { display: flex; flex-direction: column; gap: 0.4em; }
.lib-section-title {
  margin: 0.5em 0 0.1em;
  font-size: 0.72em; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--surface-fg-muted);
}
.lib-link-btn {
  padding: 0.45em 0.7em; font-size: 0.92em;
  border: 1px solid var(--surface-border); background: var(--surface-card-bg);
  border-radius: 5px; cursor: pointer;
  color: var(--surface-fg);
  text-align: center;
  display: inline-block;
}
.lib-link-btn:hover { background: var(--surface-border-soft); text-decoration: none; }

.lib-main { min-width: 0; padding: 1.3em 1.5em 2em; max-width: var(--lib-main-max-width); }
.lib-main-header {
  padding-bottom: 1em;
  margin-bottom: 0.8em;
  border-bottom: 1px solid var(--surface-border);
}
.lib-main-header h1 {
  margin: 0 0 0.3em; font-size: 1.6em; font-weight: 600;
  font-family: Georgia, "Times New Roman", serif;
}
.lib-main-header p { margin: 0 0 0.7em; color: var(--surface-fg-soft); font-size: 0.95em; }
.lib-search {
  width: 100%; max-width: 480px;
  padding: 0.55em 0.85em; font-size: 1em;
  border: 1px solid var(--surface-border); border-radius: 5px;
}

/* ─────────────────────────────────────────────────────────────
   Sort buttons (verticaux, no dropdown)
   ───────────────────────────────────────────────────────────── */

.sort-buttons { display: flex; flex-direction: column; gap: 0.18em; }
.sort-btn {
  padding: 0.4em 0.7em; font-size: 0.92em;
  border: 1px solid var(--surface-border); background: var(--surface-card-bg);
  border-radius: 5px; cursor: pointer;
  text-align: left; color: var(--surface-fg-soft);
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.4em;
}
.sort-btn:hover { background: var(--surface-border-soft); color: var(--surface-fg); }
.sort-btn.active {
  background: var(--surface-accent); color: white;
  border-color: var(--surface-accent);
}
.sort-btn .sort-dir { font-weight: 700; min-width: 1em; text-align: right; }

/* ─────────────────────────────────────────────────────────────
   Filters : range, segmented, chips
   ───────────────────────────────────────────────────────────── */

.lib-filter {
  display: flex; align-items: center; gap: 0.4em;
  font-size: 0.92em; color: var(--surface-fg-soft);
}
.lib-filter span { flex: 1; }
.lib-filter input[type=number] {
  width: 4em;
  padding: 0.3em 0.4em; font-size: 0.92em;
  border: 1px solid var(--surface-border); border-radius: 4px;
}
.lib-filter-label {
  margin: 0.5em 0 0.1em;
  font-size: 0.85em; font-weight: 600; color: var(--surface-fg-soft);
}
.lib-reset-btn {
  margin-top: 0.6em;
  padding: 0.45em 0.7em; font-size: 0.9em;
  border: 1px solid var(--surface-border); background: var(--surface-card-bg);
  border-radius: 5px; cursor: pointer;
  color: var(--surface-fg-soft);
}
.lib-reset-btn:hover { background: var(--surface-border-soft); }

.segmented {
  display: inline-flex !important;
  border: 1px solid var(--surface-border);
  border-radius: 5px;
  overflow: hidden;
  gap: 0 !important;
}
.seg-btn {
  padding: 0.55em 1em;
  background: var(--surface-card-bg); border: none; cursor: pointer;
  font-size: 0.95em;
  color: var(--surface-fg-soft);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--surface-border); }
.seg-btn:hover { background: var(--surface-border-soft); }
.seg-btn.active { background: var(--surface-accent); color: white; }

.chips-wrap { display: flex; flex-wrap: wrap; gap: 0.3em; align-items: center; }
.chip {
  padding: 0.35em 0.85em;
  border: 1px solid var(--surface-border); background: var(--surface-card-bg);
  border-radius: 16px; font-size: 0.92em;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35em;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { background: var(--surface-border-soft); }
.chip[data-state="incl"] {
  background: #2a7a3a; color: white; border-color: #2a7a3a;
}
.chip[data-state="incl"]:hover { background: #226130; }
.chip[data-state="excl"] {
  background: #fce4e4; color: #b03030; border-color: #e9a9a9;
  text-decoration: line-through;
}
.chip[data-state="excl"]:hover { background: #f9d6d6; }
.chip-count {
  font-size: 0.78em;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

/* ─────────────────────────────────────────────────────────────
   Cards — 2 variants : image-card + text-card
   ───────────────────────────────────────────────────────────── */

#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2em;
  padding-top: 0.8em;
}

.card {
  background: var(--surface-card-bg);
  border: 1px solid var(--surface-border-soft);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex; flex-direction: column;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}
.card-link { display: flex; flex-direction: column; flex: 1; text-decoration: none; color: inherit; }

/* ─── Image card (boardgame/movie/jv pattern) ─── */
.card-img-wrap {
  position: relative;
  width: 100%;
  /* AT YOUR CHOICE :
     - 2 / 3 pour poster portrait (movies, books)
     - 16 / 9 pour landscape (JV, screenshots)
     - 1 / 1 pour square (boardgame)
   */
  aspect-ratio: 16 / 9;
  background: var(--surface-border-soft);
  overflow: hidden;
}
/* Background blurred du même image pour combler les bords sans cropper
   (image entière préservée via object-fit: contain). --bg-img injecté
   en style inline depuis cardHtml() — pattern boardgame généralisé. */
.card-img-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--bg-img);
  background-size: cover;
  background-position: center;
  filter: blur(18px) saturate(1.05);
  transform: scale(1.15);
  pointer-events: none;
}
.card-img {
  position: relative;
  z-index: 1;
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}

.overlay-badge {
  position: absolute;
  top: 0.5em; right: 0.5em;
  z-index: 2;  /* au-dessus de .card-img (z:1) + ::before (z:0) */
  padding: 0.18em 0.55em;
  border-radius: 10px;
  font-size: 0.75em; font-weight: 600;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.overlay-badge.warn { color: #8a6500; background: #fff3cd; }
.overlay-badge.miss { color: #555; background: rgba(240,240,240,0.95); }

.card-body {
  padding: 0.6em 0.7em 0.7em;
  display: flex; flex-direction: column; gap: 0.4em;
  flex: 1;
}
.card-title {
  margin: 0;
  font-size: 0.95em;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-authors {
  margin: 0;
  font-size: 0.8em;
  color: var(--surface-fg-soft);
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-stats { display: flex; gap: 0.3em; flex-wrap: wrap; }
.card-meta {
  font-size: 0.8em;
  color: var(--surface-fg-soft);
  margin-top: auto;
}
.card-meta-status { color: var(--surface-accent); font-weight: 500; }

/* ─── Text card (papers / articles / ao pattern) ─── */
/* À utiliser si tu n'as pas d'image. Layout text-heavy avec category
   badge en haut, title serif, abstract clamp 4 lines, footer stats. */
.card.text-card {
  /* Pas de .card-img-wrap dans le HTML pour text-card. */
}
.card.text-card .card-link {
  padding: 0.85em 1em 0.9em;
  gap: 0.45em;
}
.card-text-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5em;
}
.card-cat-badge {
  display: inline-block;
  padding: 0.18em 0.55em;
  background: var(--surface-accent-bg);
  color: var(--surface-accent);
  border-radius: 4px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.card-status {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 10px;
  font-size: 0.72em;
  font-weight: 600;
}
.card.text-card .card-title {
  font-size: 1em;
  line-height: 1.3;
  font-family: Georgia, serif;
  -webkit-line-clamp: 3;
  min-height: auto;
}
.card-abstract {
  margin: 0;
  font-size: 0.85em;
  color: var(--surface-fg-soft);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}
.card-footer {
  display: flex; flex-direction: column; gap: 0.35em;
  margin-top: auto;
  padding-top: 0.5em;
  border-top: 1px solid var(--surface-border-soft);
}
.card-tags { display: flex; gap: 0.25em; flex-wrap: wrap; }
.card-tag {
  font-size: 0.72em;
  padding: 0.1em 0.45em;
  background: var(--surface-border-soft);
  color: var(--surface-fg-soft);
  border-radius: 3px;
  white-space: nowrap;
}

/* ─── Multi-score progress bars (pour cards à 2-3 thématiques scorées) ─── */
.theme-scores {
  display: flex; flex-direction: column; gap: 0.2em;
  margin: 0.4em 0;
}
.theme-bar {
  display: grid; grid-template-columns: 4em 1fr;
  gap: 0.4em; align-items: center;
  font-size: 0.78em;
}
.theme-bar > span { color: var(--surface-fg-soft); }
.theme-bar .bar {
  background: var(--surface-accent-bg);
  border-radius: 3px; height: 1.2em;
  position: relative;
  font-size: 0.85em; font-weight: 600;
  color: white;
  padding: 0 0.4em;
  display: flex; align-items: center;
  min-width: 1.4em;
  background: linear-gradient(90deg, var(--surface-accent) var(--bar-value, 0%), var(--surface-accent-bg) var(--bar-value, 0%));
}
.theme-bar.high .bar { font-weight: 700; }

/* ─── Card decorations (pending / missing) ─── */
.card.pending { border-color: #ffd986; }
.card.missing { opacity: 0.78; }
.card.missing .card-title { color: var(--surface-fg-muted); }

/* ─── Rating tags (color bands) ─── */
.cell-tag {
  display: inline-block;
  min-width: 2.2em; text-align: center;
  padding: 0.15em 0.45em;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 0.88em;
}
.cell-tag.r-low    { background: var(--surface-r-low); }
.cell-tag.r-mid    { background: var(--surface-r-mid); }
.cell-tag.r-good   { background: var(--surface-r-good); }
.cell-tag.r-high   { background: var(--surface-r-high); }
.cell-tag.r-top    { background: var(--surface-r-top); color: #15521a; }
.cell-tag.big {
  font-size: 1.1em;
  padding: 0.2em 0.6em;
  min-width: 3em;
}

/* ─── Deadline urgency tag (carte footer + detail stats) ─── */
.deadline-tag {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 500;
  white-space: nowrap;
}
.deadline-tag.dl-far    { background: var(--surface-border-soft); color: var(--surface-fg-soft); }
.deadline-tag.dl-soon   { background: var(--surface-h-warm); color: #7a4a00; }
.deadline-tag.dl-urgent { background: var(--surface-h-fire); color: #7a2400; font-weight: 600; }
.deadline-tag.dl-past   { background: var(--surface-r-low); color: #7a1500; }

/* ─── Pills (warn / miss states header) ─── */
.pill {
  display: inline-block; padding: 0.1em 0.5em;
  border-radius: 10px; font-size: 0.85em; line-height: 1.4;
}
.pill.warn { background: #fff3cd; color: #8a6500; }
.pill.miss { background: var(--surface-border-soft); color: var(--surface-fg-soft); }

.empty-state {
  text-align: center; color: var(--surface-fg-muted);
  padding: 3em 1em; font-size: 1em;
}

/* ─────────────────────────────────────────────────────────────
   Detail view
   ───────────────────────────────────────────────────────────── */

.detail-view {
  max-width: 900px;
  margin: 0 auto;
  padding: 1em 0;
}
.detail-back {
  display: inline-block;
  color: var(--surface-accent);
  font-size: 0.95em;
  margin: 0 1em 1em;
}
.detail-back:hover { text-decoration: underline; }

.detail-body {
  display: flex; flex-direction: column;
  gap: 1.2em;
  padding: 0 1em;
  max-width: 900px;
  margin: 0 auto;
}

.detail-info { display: flex; flex-direction: column; }
.detail-title {
  margin: 0 0 0.4em;
  font-size: 1.7em;
  font-weight: 700;
  font-family: Georgia, serif;
  line-height: 1.2;
}
.detail-subtitle {
  margin: 0.4em 0 1em;
  color: var(--surface-fg-soft);
  font-size: 0.95em;
}
.detail-stats {
  display: flex; flex-wrap: wrap; gap: 0.8em 1.4em;
  margin-bottom: 1.2em;
}
.stat-block { display: flex; flex-direction: column; gap: 0.2em; }
.stat-label {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--surface-fg-muted);
  font-weight: 600;
}
.detail-overview, .detail-abstract {
  margin: 1em 0;
  padding: 0.8em 0;
  font-size: 0.95em;
  line-height: 1.6;
  border-top: 1px solid var(--surface-border-soft);
  border-bottom: 1px solid var(--surface-border-soft);
}
.detail-notes-display {
  margin: 0.8em 0;
  padding: 0.7em 0.9em;
  background: var(--surface-accent-bg);
  border-left: 3px solid var(--surface-accent);
  border-radius: 4px;
  white-space: pre-wrap;
  font-size: 0.92em;
}
.detail-links {
  margin: 1em 0;
  font-size: 0.92em;
}
.detail-links a { color: var(--surface-accent); font-weight: 500; }

/* ─────────────────────────────────────────────────────────────
   Inline edit panel (refactor 2026-05-13 — remplace edit-modal)
   ───────────────────────────────────────────────────────────── */

.detail-edit-panel {
  margin: 1.5em 0;
  padding: 1.2em 1.4em 1em;
  background: var(--surface-card-bg);
  border: 1px solid var(--surface-border-soft);
  border-left: 3px solid var(--surface-accent);
  border-radius: 6px;
  max-width: 560px;
}
.detail-edit-panel[hidden] { display: none; }
.detail-edit-panel h3 {
  margin: 0 0 0.9em;
  font-size: 1em;
  font-weight: 600;
  color: var(--surface-accent);
}
.edit-field {
  display: flex; flex-direction: column;
  gap: 0.3em;
  margin-bottom: 1em;
  font-size: 0.92em;
  color: var(--surface-fg-soft);
}
.edit-field.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.7em;
  margin-bottom: 0.8em;
}
.edit-field.inline span { flex: 0 0 auto; }
.edit-field span { font-weight: 500; }
.edit-field select,
.edit-field input[type="text"],
.edit-field input[type="number"],
.edit-field input[list],
.edit-field textarea {
  padding: 0.5em 0.7em;
  font-size: 1em;
  border: 1px solid var(--surface-border);
  border-radius: 5px;
  font-family: inherit;
  background: var(--surface-card-bg);
}
.edit-field input[type="checkbox"] {
  width: 1.1em; height: 1.1em;
  align-self: flex-start;
}
.edit-field input[type="range"] { width: 100%; }
.edit-field textarea { resize: vertical; min-height: 4em; }

.edit-actions {
  display: flex; justify-content: flex-end; align-items: center; gap: 0.6em;
  margin-top: 0.5em;
}
.edit-actions button {
  padding: 0.55em 1em; font-size: 0.95em;
  border: 1px solid var(--surface-border); background: var(--surface-card-bg);
  border-radius: 5px; cursor: pointer;
}
.edit-actions button:hover { background: var(--surface-border-soft); }
.edit-actions button[type="submit"] {
  background: var(--surface-accent); color: white; border-color: var(--surface-accent);
}
.edit-actions button[type="submit"]:hover { background: var(--surface-accent-hover); }
.edit-actions button[disabled] { opacity: 0.6; cursor: wait; }

.edit-save-status {
  display: inline-block;
  padding: 0.45em 0.8em;
  font-size: 0.9em;
  color: var(--surface-accent);
  font-weight: 500;
}
.edit-save-status.error { color: #b03030; }
.edit-error {
  margin: 0.5em 0 1em;
  padding: 0.5em 0.7em;
  background: #fce4e4; color: #b03030;
  border-radius: 4px;
  font-size: 0.88em;
}

/* ─────────────────────────────────────────────────────────────
   Stats heatmap (source × topic OU source × theme)
   ───────────────────────────────────────────────────────────── */

.heatmap-wrap { overflow-x: auto; }
.heatmap { display: grid; gap: 2px; min-width: 600px; }
.heatmap-cell {
  font-size: 0.75em; padding: 0.4em 0.5em; border-radius: 3px;
  text-align: center; cursor: default; min-height: 1.8em;
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.heatmap-header {
  font-weight: 600; font-size: 0.78em; color: var(--surface-fg-soft);
  padding: 0.4em 0.2em; text-align: left;
  white-space: nowrap;
  /* Headers verticaux : permettent d'afficher beaucoup de colonnes
     sans élargir la matrice. (cf. articles/stats refactor 2026-05-13) */
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  align-self: end;
  min-height: 7em;
}
.heatmap-row-label {
  font-size: 0.78em; color: var(--surface-fg);
  padding: 0.4em 0.5em; text-align: right; white-space: nowrap;
}
.heatmap-cell.empty { background: var(--surface-border-soft); color: var(--surface-fg-muted); }

/* ─────────────────────────────────────────────────────────────
   Responsive (mobile)
   ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  body.lib-layout { grid-template-columns: 1fr; }
  .lib-sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--surface-border);
  }
  .lib-main { padding: 1em; }
}
@media (max-width: 600px) {
  #cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.8em; }
  .detail-title { font-size: 1.4em; }
}

/* ─────────────────────────────────────────────────────────────
   Footer
   ───────────────────────────────────────────────────────────── */

footer {
  padding: 1em; text-align: center; color: var(--surface-fg-soft); font-size: 0.8em;
  border-top: 1px solid var(--surface-border-soft);
}
