/* =====================================================================
   Bibliotheque Sante - feuille de style unique
   Palette sobre, typographie systeme, aucun asset externe.
   ===================================================================== */

:root {
  --bg: #f7f8f7;
  --surface: #ffffff;
  --surface-2: #f1f3f2;
  --border: #e2e6e3;
  --border-strong: #cfd6d1;
  --text: #1b201d;
  --text-muted: #67736c;
  --text-faint: #93a09a;
  --accent: #2f7d63;
  --accent-soft: #e6f2ed;
  --accent-text: #1f5745;
  --danger: #b3413a;
  --danger-soft: #fbeceb;
  --warn: #9a6a12;
  --warn-soft: #fbf2e0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 4px 14px rgba(20, 30, 25, .05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #141816;
  --surface: #1b201e;
  --surface-2: #232927;
  --border: #2c3431;
  --border-strong: #3b4541;
  --text: #e6ebe8;
  --text-muted: #9aa8a2;
  --text-faint: #6d7c76;
  --accent: #5fbe9c;
  --accent-soft: #1d312a;
  --accent-text: #8ad3b8;
  --danger: #e0776f;
  --danger-soft: #33211f;
  --warn: #d3a552;
  --warn-soft: #322a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- Header */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 620;
  letter-spacing: -.01em;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 15px;
}

.search-wrap { flex: 1; max-width: 620px; position: relative; }
.search-wrap input {
  width: 100%;
  padding: 9px 34px 9px 34px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg);
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); background: var(--surface); }
.search-wrap .icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); pointer-events: none; font-size: 13px;
}
.search-wrap .clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--text-faint); cursor: pointer;
  padding: 2px 6px; border-radius: 50%;
}
.search-wrap .clear:hover { background: var(--surface-2); color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* Sur petit ecran, la recherche passe sur sa propre ligne. */
@media (max-width: 720px) {
  header.topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .brand span:not(.mark) { font-size: 15px; }
  .search-wrap { order: 3; flex: 1 0 100%; max-width: none; }
  .topbar-actions { gap: 6px; }
  main { padding: 18px 14px 60px; }
}

.role-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 12px; font-weight: 550;
}
.role-chip.editeur { background: var(--accent-soft); color: var(--accent-text); }
.role-chip.admin { background: var(--warn-soft); color: var(--warn); }

/* ---------------------------------------------------------------- Boutons */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: var(--border-strong); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- Layout */

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 80px; }

.layout { display: grid; grid-template-columns: 232px 1fr; gap: 26px; align-items: start; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  aside.filters { position: static !important; }
}

aside.filters { position: sticky; top: 74px; }

.facet { margin-bottom: 20px; }
.facet h3 {
  margin: 0 0 8px;
  font-size: 11px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint);
}
.facet-list { display: flex; flex-direction: column; gap: 1px; }
.facet-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 5px 8px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: 14px;
  border: 0; background: none; text-align: left; width: 100%;
}
.facet-item:hover { background: var(--surface-2); color: var(--text); }
.facet-item.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.facet-item .n { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.facet-item.on .n { color: var(--accent-text); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-pill {
  padding: 3px 9px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); cursor: pointer;
}
.tag-pill:hover { border-color: var(--border-strong); color: var(--text); }
.tag-pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

/* ---------------------------------------------------------------- Results */

.results-head {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.results-head .count { color: var(--text-muted); font-size: 13.5px; }
.results-head select {
  margin-left: auto; width: auto; flex: 0 0 auto;
  padding: 5px 9px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
}

.card-list { display: flex; flex-direction: column; gap: 9px; }

.card {
  display: block;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); text-decoration: none; }
.card h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -.01em; }
.card p { margin: 0; color: var(--text-muted); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 9px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 550; letter-spacing: .01em;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid transparent;
}
.badge.type-pathologie { background: #fdecec; color: #a3423d; }
.badge.type-substance  { background: #e6f2ed; color: #1f5745; }
.badge.type-document   { background: #e9eefb; color: #3a5090; }
.badge.type-note       { background: #fbf2e0; color: #8a6113; }
:root[data-theme="dark"] .badge.type-pathologie { background: #34211f; color: #e59a94; }
:root[data-theme="dark"] .badge.type-substance  { background: #1d312a; color: #8ad3b8; }
:root[data-theme="dark"] .badge.type-document   { background: #1f2740; color: #9db1e8; }
:root[data-theme="dark"] .badge.type-note       { background: #322a1a; color: #d9b678; }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.prive { border-color: var(--border-strong); }

.empty {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); margin-bottom: 6px; font-size: 16px; }

/* ---------------------------------------------------------------- Fiche */

.fiche { max-width: 780px; margin: 0 auto; }
.fiche > header { margin-bottom: 22px; }
.fiche h1 { margin: 8px 0 8px; font-size: 30px; line-height: 1.2; letter-spacing: -.02em; }
.fiche .lede { color: var(--text-muted); font-size: 16.5px; margin: 0 0 12px; }
.fiche .byline { color: var(--text-faint); font-size: 13px; }

.prose { font-size: 15.5px; line-height: 1.68; }
.prose h2 { font-size: 20px; margin: 30px 0 10px; letter-spacing: -.01em; }
.prose h3 { font-size: 16.5px; margin: 22px 0 8px; }
.prose p { margin: 0 0 14px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 22px; }
.prose li { margin-bottom: 4px; }
.prose blockquote {
  margin: 0 0 14px; padding: 8px 16px;
  border-left: 3px solid var(--accent); background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-muted);
}
.prose code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.prose pre { background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 26px 0; }
.prose table { border-collapse: collapse; width: 100%; margin-bottom: 14px; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--surface-2); }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-top: 22px;
}
.panel h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-faint); font-weight: 650; }
.panel ul { margin: 0; padding-left: 18px; }
.panel li { margin-bottom: 5px; }

.attach-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.attach-row:last-child { border-bottom: 0; }
.attach-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-row .size { color: var(--text-faint); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.disclaimer {
  margin-top: 26px; padding: 11px 14px;
  background: var(--warn-soft); color: var(--warn);
  border-radius: var(--radius-sm); font-size: 13px;
}

/* ---------------------------------------------------------------- Forms */

.form-grid { display: grid; gap: 14px; max-width: 860px; margin: 0 auto; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

label.field { display: block; }
label.field > span {
  display: block; margin-bottom: 5px;
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint);
}
input[type="text"], input[type="email"], input[type="password"], input[type="url"], select, textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; font-family: var(--mono); font-size: 13.5px; line-height: 1.6; }

.editor-tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.editor-tabs button {
  border: 0; background: none; padding: 5px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: 13.5px;
}
.editor-tabs button.on { background: var(--surface-2); color: var(--text); font-weight: 550; }

.preview {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; background: var(--surface); min-height: 160px;
}

.sticky-actions {
  position: sticky; bottom: 0; margin-top: 18px;
  display: flex; gap: 8px; align-items: center;
  padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%);
}

/* ---------------------------------------------------------------- Tables */

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; padding: 8px 10px; color: var(--text-faint);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:hover td { background: var(--surface-2); }
table.data td.mono { font-family: var(--mono); font-size: 12.5px; color: var(--text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
}
.stat .v { font-size: 24px; font-weight: 620; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12.5px; color: var(--text-muted); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs button {
  border: 0; background: none; padding: 9px 14px; cursor: pointer;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 560; }

/* ---------------------------------------------------------------- Divers */

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 100;
  animation: rise .18s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 16, 13, .45);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px; width: min(440px, 100%); box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 14px; font-size: 18px; }

.login-page { max-width: 340px; margin: 8vh auto; }
.login-page h1 { font-size: 22px; margin: 0 0 4px; }
.login-page p.sub { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }

.crumb { color: var(--text-muted); font-size: 13.5px; margin-bottom: 4px; }
.crumb a { color: var(--text-muted); }

.chips-input {
  display: flex; flex-wrap: wrap; gap: 5px; padding: 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.chips-input input { border: 0; padding: 2px 4px; flex: 1; min-width: 100px; background: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface-2); border-radius: 999px; padding: 2px 5px 2px 9px; font-size: 13px;
}
.chip button { border: 0; background: none; cursor: pointer; color: var(--text-faint); padding: 0 3px; }
.chip button:hover { color: var(--danger); }

.skeleton { background: var(--surface-2); border-radius: var(--radius); height: 74px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
