:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #111827;
  --accent-text: #ffffff;
  --star: #f5a524;
  --todo: #b45309;
  --todo-bg: #fef3c7;
  --ok: #047857;
  --ok-bg: #d1fae5;
  --off: #4b5563;
  --off-bg: #e5e7eb;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --reply-bg: #f3f6fb;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #e8eaed;
    --muted: #9aa1ad;
    --accent: #e8eaed;
    --accent-text: #0f1115;
    --todo: #fbbf24;
    --todo-bg: #3a2c0b;
    --ok: #34d399;
    --ok-bg: #0d3326;
    --off: #b6bcc7;
    --off-bg: #2a2f39;
    --danger: #f87171;
    --danger-bg: #3b1515;
    --reply-bg: #1b2230;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { white-space: nowrap; font-weight: 700; letter-spacing: -0.01em; text-decoration: none; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  white-space: nowrap; padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted);
}
.topbar nav a.active, .topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.sync-pill { font-size: 12px; color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); text-decoration: none;
  font-size: 13px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.flash {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border);
}

/* Cartes de synthese par source */
.source-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 20px;
}
.source-card {
  display: block; padding: 12px; border-radius: var(--radius); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border);
}
.source-card:hover { border-color: var(--muted); }
.source-card.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.source-card .name { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.source-card .rating { font-size: 20px; font-weight: 700; margin-top: 4px; }
.source-card .rating small { font-size: 12px; font-weight: 400; color: var(--muted); }
.source-card .todo { font-size: 12px; color: var(--muted); }
.source-card .todo b { color: var(--todo); }

/* Filtres */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px; margin-bottom: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.segmented { display: inline-flex; max-width: 100%; overflow-x: auto; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; white-space: nowrap; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.filters select, .filters input[type=search] {
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
}
.filters input[type=search] { flex: 1; min-width: 160px; }
.result-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.result-count { color: var(--muted); margin: 0; font-size: 13px; }

/* Avis */
.review {
  padding: 14px 16px; margin-bottom: 10px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  transition: opacity .25s;
}
.review.fading { opacity: .35; }
.review header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.src { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.stars { color: var(--star); letter-spacing: 1px; font-size: 14px; }
.stars .off { color: var(--border); }
.meta { color: var(--muted); font-size: 12px; }
.badge {
  margin-left: auto; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--off-bg); color: var(--off);
}
.badge.todo { background: var(--todo-bg); color: var(--todo); }
.badge.replied, .badge.done { background: var(--ok-bg); color: var(--ok); }
.review h3 { margin: 10px 0 4px; font-size: 15px; }
.review .body { margin: 6px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.review .body.clamped { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.review .empty { color: var(--muted); font-style: italic; }
.reply {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--reply-bg);
  border-left: 3px solid var(--ok); white-space: pre-line; font-size: 13px;
}
.reply .reply-head { font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 4px; white-space: normal; }
.review footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.review footer .spacer { flex: 1; }
.review footer a.link { font-size: 12px; color: var(--muted); text-decoration: none; padding: 3px 6px; border-radius: 6px; }
.review footer a.link:hover { color: var(--text); background: var(--surface-2); }
.note {
  width: 100%; margin-top: 8px; padding: 6px 8px; min-height: 34px; resize: vertical;
  border: 1px dashed var(--border); border-radius: 8px; background: transparent; font-size: 13px;
}
.note:focus { border-style: solid; outline: none; border-color: var(--muted); }
.note.saved { border-color: var(--ok); }

.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 20px; align-items: center; }
.pagination span { color: var(--muted); font-size: 13px; padding: 0 8px; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }

/* Page sources */
.panel { padding: 16px; margin-bottom: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel p.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-top: 1px solid var(--border); vertical-align: top; font-size: 13px; }
th { color: var(--muted); font-weight: 500; border-top: none; font-size: 12px; }
.run-status { font-weight: 600; font-size: 12px; padding: 1px 7px; border-radius: 999px; }
.run-status.ok { background: var(--ok-bg); color: var(--ok); }
.run-status.error { background: var(--danger-bg); color: var(--danger); }
.run-status.skipped, .run-status.never { background: var(--off-bg); color: var(--off); }
.run-message { color: var(--muted); font-size: 12px; margin-top: 2px; max-width: 360px; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }

/* Login */
.login {
  max-width: 340px; margin: 12vh auto; padding: 28px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 20px; color: var(--muted); }
.login input { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); margin-bottom: 12px; }
.login .btn { width: 100%; justify-content: center; padding: 9px; }
.error { color: var(--danger); margin-bottom: 12px; font-size: 13px; }

@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .sync-pill { display: none; }
  .badge { margin-left: 0; }
}
