/* Articles library — cards text-only (pas de visuel comme posters/covers).
   Pattern visuel : cards plus denses, topic badge prominent, source/date discrets,
   score badge à droite. Lecture rapide priorité.
   Override DS v0 tokens où nécessaire. */

:root {
  --surface-color-text:        #1a1a1a;
  --surface-color-bg:          #fafafa;
  --surface-color-card-bg:     #ffffff;
  --surface-color-muted:       #555;
  --surface-color-rule:        #d0d0d0;
  --surface-color-link:        #4c78a8;
  --surface-color-link-hover:  #3a5e85;
  --surface-color-primary:     #4c78a8;
  --surface-color-focus:       #4c78a8;
  --surface-color-header-bg:   transparent;
  --surface-color-footer-bg:   transparent;

  --fg: var(--surface-color-text);
  --fg-soft: var(--surface-color-muted);
  --fg-muted: #888;
  --bg: var(--surface-color-bg);
  --surface: var(--surface-color-card-bg);
  --accent: var(--surface-color-primary);
  --accent-soft: #e8f0fa;
  --border: var(--surface-color-rule);
  --border-soft: #e5e5e5;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 3px 8px rgba(0,0,0,0.08);
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ───── Layout sidebar + main ───── */
body.lib-layout {
  margin: 0;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.lib-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  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;
  text-decoration: none; color: var(--fg);
  padding: 0.2em 0.4em; border-radius: 5px;
  display: block;
}
.lib-brand:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.lib-nav { display: flex; flex-direction: column; gap: 0.15em; }
.lib-nav a {
  padding: 0.45em 0.6em;
  text-decoration: none; color: var(--fg-soft);
  border-radius: 5px; font-size: 0.95em;
}
.lib-nav a:hover { background: #f4f4f4; color: var(--fg); text-decoration: none; }
.lib-nav a.active {
  background: var(--accent-soft);
  color: var(--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(--fg-muted);
}
.lib-link-btn, .lib-action-btn {
  padding: 0.45em 0.7em; font-size: 0.92em;
  border: 1px solid var(--border); background: white;
  border-radius: 5px; cursor: pointer;
  text-decoration: none; color: var(--fg);
  text-align: center; display: inline-block;
}
.lib-link-btn:hover { background: #f0f0f0; text-decoration: none; }
.lib-action-btn {
  background: var(--accent); color: white; border-color: var(--accent);
  font-weight: 500;
}
.lib-action-btn:hover { background: #3a5e85; }
.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(--border); background: white;
  border-radius: 5px; cursor: pointer;
  text-align: left; color: var(--fg-soft);
  display: flex; justify-content: space-between; align-items: center;
}
.sort-btn:hover { background: #f4f4f4; color: var(--fg); }
.sort-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.sort-btn .sort-dir { font-weight: 700; min-width: 1em; text-align: right; }
.lib-filter {
  display: flex; align-items: center; gap: 0.4em;
  font-size: 0.92em; color: var(--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(--border); border-radius: 4px;
}
.lib-filter-label {
  margin: 0.5em 0 0.1em;
  font-size: 0.85em; font-weight: 600;
  color: var(--fg-soft);
}
.chips-wrap { display: flex; flex-wrap: wrap; gap: 0.3em; align-items: center; }
#period {
  padding: 0.35em 0.5em; font-size: 0.92em;
  border: 1px solid var(--border); border-radius: 4px;
  background: white;
}
.lib-reset-btn {
  margin-top: 0.6em;
  padding: 0.45em 0.7em; font-size: 0.9em;
  border: 1px solid var(--border); background: white;
  border-radius: 5px; cursor: pointer; color: var(--fg-soft);
}
.lib-reset-btn:hover { background: #f0f0f0; }
.lib-auth-section {
  margin-top: auto;
  padding-top: 0.8em;
  border-top: 1px solid var(--border-soft);
}

.lib-main { min-width: 0; padding: 1.3em 1.5em 2em; }
.lib-main-header {
  padding-bottom: 1em; margin-bottom: 0.8em;
  border-bottom: 1px solid var(--border-soft);
}
.lib-main-header h1 { margin: 0 0 0.3em; font-size: 1.6em; font-weight: 600; }
.lib-main-header p { margin: 0 0 0.7em; color: var(--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(--border); border-radius: 5px;
}

@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(--border-soft);
  }
  .lib-main { padding: 1em; }
}

.pill { padding: 0.1em 0.5em; border-radius: 10px; font-size: 0.78em; font-weight: 500; }
.pill.warn { color: #8a6500; background: #fff3cd; }
.pill.miss { color: #555; background: #f0f0f0; }

.segmented {
  display: inline-flex !important;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  background: white;
}
.seg-btn {
  padding: 0.4em 0.9em; background: white; border: none; cursor: pointer;
  font-size: 0.92em; color: var(--fg-soft);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover { background: #f0f0f0; }
.seg-btn.active { background: var(--accent); color: white; }

.chip {
  padding: 0.3em 0.7em; font-size: 0.85em;
  border: 1px solid var(--border); background: white; cursor: pointer;
  border-radius: 16px; color: var(--fg-soft);
  display: inline-flex; align-items: center; gap: 0.25em;
}
.chip:hover { background: #f0f0f0; }
.chip[data-state="incl"] { background: var(--accent); color: white; border-color: var(--accent); }
.chip[data-state="excl"] { background: #fce4e4; color: #b03030; border-color: #b03030; text-decoration: line-through; }

/* ───── Articles cards (text-only, denser than boardgame/movie) ───── */
#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1em;
  padding-top: 0.8em;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.9em 1em;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex; flex-direction: column; gap: 0.4em;
  text-decoration: none; color: inherit;
  position: relative;
}

/* Flag buttons + badges */
.article-flag-actions {
  position: absolute;
  bottom: 0.5em; right: 0.6em;
  display: flex; gap: 0.25em;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 3;
}
.article-card:hover .article-flag-actions,
.article-flag-actions:focus-within { opacity: 1; }
.flag-btn {
  width: 1.9em; height: 1.9em; padding: 0;
  font-size: 0.85em; line-height: 1;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border, #d0d0d0);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.flag-btn:hover { background: white; transform: scale(1.08); }
.flag-btn.active {
  background: var(--accent-soft, #e8f0fa);
  border-color: var(--accent, #4c78a8);
  box-shadow: 0 1px 4px rgba(76,120,168,0.3);
}
.flag-btn.flag-podcast.active { background: #fdebd0; border-color: #d68910; }
.flag-btn.flag-read.active    { background: #d5e8d4; border-color: #4a8a3e; }
.flag-btn.flag-bookmark.active { background: #fadbd8; border-color: #c0392b; }

.article-flag-badges {
  display: inline-flex; gap: 0.15em;
  margin-left: auto;
  font-size: 0.9em;
}
.flag-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.3em; height: 1.3em;
  background: var(--accent-soft, #e8f0fa);
  border-radius: 50%;
  font-size: 0.7em;
}
.flag-badge-podcast  { background: #fdebd0; }
.flag-badge-read     { background: #d5e8d4; }
.flag-badge-bookmark { background: #fadbd8; }

/* Article-card with bookmark: subtle highlight to make it stand out */
.article-card:has(.flag-badge-bookmark) {
  border-color: #c0392b;
  border-width: 1px;
}
.article-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  text-decoration: none;
}

.article-header {
  display: flex; align-items: center; gap: 0.4em; flex-wrap: wrap;
  font-size: 0.78em; color: var(--fg-muted);
}
.article-source { font-weight: 500; color: var(--fg-soft); }
.article-lang { padding: 0.05em 0.4em; background: #f4f4f4; border-radius: 3px; font-size: 0.85em; }
.article-date { color: var(--fg-muted); }

.article-title {
  margin: 0;
  font-size: 1em;
  font-weight: 600;
  line-height: 1.35;
  color: var(--fg);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-reason {
  font-size: 0.85em;
  color: var(--fg-soft);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

.article-footer {
  display: flex; align-items: center; gap: 0.4em; flex-wrap: wrap;
  margin-top: auto;
  padding-top: 0.4em;
  border-top: 1px solid var(--border-soft);
}

.topic-badge {
  padding: 0.18em 0.6em;
  border-radius: 12px;
  font-size: 0.78em;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--accent);
}
.theme-tag {
  padding: 0.12em 0.5em;
  border-radius: 10px;
  font-size: 0.72em;
  background: #f4f4f4;
  color: var(--fg-soft);
}

.score-badge {
  margin-left: auto;
  padding: 0.2em 0.6em;
  border-radius: 4px;
  font-size: 0.92em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.score-low    { background: #ffe5d5; color: #8b3a0e; }
.score-mid    { background: #fff3cd; color: #8a6500; }
.score-good   { background: #d4edda; color: #1d6f37; }
.score-high   { background: #c8e7c4; color: #155724; }
.score-top    { background: #4c78a8; color: white; }

.external-arrow {
  font-size: 0.8em; color: var(--fg-muted);
  margin-left: 0.2em;
}

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

/* ───── Detail modal (clic carte) ───── */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 8px;
  padding: 1.5em;
  max-width: 700px;
  width: calc(100% - 2em);
  max-height: 85vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.8em;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-close {
  position: absolute;
  top: 0.5em; right: 0.5em;
  width: 2em; height: 2em;
  background: transparent;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  color: var(--fg-soft);
  border-radius: 50%;
}
.modal-close:hover { background: #f0f0f0; }

.detail-header {
  display: flex; align-items: center; gap: 0.6em; flex-wrap: wrap;
  font-size: 0.85em;
  color: var(--fg-muted);
}
.detail-title {
  margin: 0;
  font-size: 1.3em;
  line-height: 1.35;
}
.detail-reason {
  background: #f9f9f9;
  padding: 0.8em 1em;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.95em;
  line-height: 1.5;
}
.detail-themes h4 {
  margin: 0.8em 0 0.4em;
  font-size: 0.85em;
  color: var(--fg-soft);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-theme-row {
  padding: 0.5em 0.7em;
  background: #f9f9f9;
  border-radius: 4px;
  margin-bottom: 0.4em;
}
.detail-theme-head {
  display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap;
  font-size: 0.9em; margin-bottom: 0.3em;
}
.detail-theme-id { font-weight: 600; color: var(--fg); }
.detail-theme-reason {
  font-size: 0.85em; color: var(--fg-soft);
  line-height: 1.45;
}

.detail-link-btn {
  display: inline-flex; align-items: center; gap: 0.4em;
  margin-top: 0.5em;
  padding: 0.6em 1.2em;
  background: var(--accent); color: white;
  text-decoration: none;
  border-radius: 5px;
  font-weight: 500;
  align-self: flex-start;
}
.detail-link-btn:hover { background: #3a5e85; text-decoration: none; }

footer { padding: 1em; text-align: center; color: var(--fg-soft); font-size: 0.8em; }
footer a { color: var(--accent); }

@media (max-width: 600px) {
  #cards { grid-template-columns: 1fr; }
  .article-card { padding: 0.8em 0.9em; }
  #filters { gap: 0.4em 0.7em; padding: 0.5em 0.7em; }
}
