/* Orgue moléculaire
   Concept : une paillasse de laboratoire. Fond papier filtre légèrement vert,
   encre sombre, un seul accent qui change avec le domaine (framboise pour
   l'arôme, iris pour le parfum). Les statuts réglementaires ont leurs propres
   couleurs sémantiques, indépendantes de l'accent. */
:root {
  --paper: #f3f5f1;
  --surface: #ffffff;
  --sunk: #e9ece7;
  --ink: #1c2320;
  --muted: #5a645f;
  --line: #d6dcd6;
  --arome: #9e2f4c;
  --arome-soft: #f6e6ea;
  --parfum: #4f42a0;
  --parfum-soft: #ebe8f7;
  --ok: #2b7a4b;
  --ok-soft: #e2f1e7;
  --warn: #9a6200;
  --warn-soft: #f8edd8;
  --bad: #b02a22;
  --bad-soft: #f8e3e1;
  --info: #2c5f8a;
  --info-soft: #e2ecf5;
  --accent: var(--arome);
  --accent-soft: var(--arome-soft);
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 8px 24px rgba(20, 30, 25, .08);

  --f-display: "Spectral", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --s-xs: .75rem; --s-sm: .875rem; --s-md: 1rem; --s-lg: 1.25rem; --s-xl: 1.75rem; --s-2xl: 2.4rem;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111513; --surface: #181d1b; --sunk: #1f2522; --ink: #e5ebe7; --muted: #9ba6a0; --line: #2d3531;
    --arome: #ec8aa2; --arome-soft: #3a2129; --parfum: #ada3f2; --parfum-soft: #29253f;
    --ok: #6cc590; --ok-soft: #1c3326; --warn: #e6b45c; --warn-soft: #3a2e17; --bad: #f28b82; --bad-soft: #3e1f1d;
    --info: #8dbbe3; --info-soft: #1d2c3a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111513; --surface: #181d1b; --sunk: #1f2522; --ink: #e5ebe7; --muted: #9ba6a0; --line: #2d3531;
  --arome: #ec8aa2; --arome-soft: #3a2129; --parfum: #ada3f2; --parfum-soft: #29253f;
  --ok: #6cc590; --ok-soft: #1c3326; --warn: #e6b45c; --warn-soft: #3a2e17; --bad: #f28b82; --bad-soft: #3e1f1d;
  --info: #8dbbe3; --info-soft: #1d2c3a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
body[data-domaine="parfum"] { --accent: var(--parfum); --accent-soft: var(--parfum-soft); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--s-md)/1.55 var(--f-body);
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 30; background: var(--surface);
}
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--f-mono); font-size: .92em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.wrap {
  max-width: 1120px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ------------------------------------------------------------ barre du haut */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-name { font-family: var(--f-display); font-weight: 600; font-size: 1.2rem; letter-spacing: .01em; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; flex: 1 1 auto; }
.tab {
  border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer;
  color: var(--muted); font-size: var(--s-sm); font-weight: 500;
}
.tab:hover { color: var(--ink); background: var(--sunk); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--sunk); box-shadow: inset 0 -2px 0 var(--accent); }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--paper); }
.seg button {
  border: 0; background: none; padding: 5px 14px; border-radius: 999px; cursor: pointer;
  font-size: var(--s-sm); font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed="true"][data-domaine="arome"] { background: var(--arome); color: var(--surface); }
.seg button[aria-pressed="true"][data-domaine="parfum"] { background: var(--parfum); color: var(--surface); }
select, input[type="search"], input[type="text"] {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px;
  font-size: var(--s-sm); min-width: 0; max-width: 100%;
}
select { padding-right: 28px; }

/* ------------------------------------------------------------ vues */
main { padding-block: 28px 56px; }
.view { display: grid; gap: 28px; }
.eyebrow {
  margin: 0; font-size: var(--s-xs); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; color: var(--accent);
}
h1, h2, h3 { text-wrap: balance; margin: 0; }
h1 { font-family: var(--f-display); font-weight: 600; font-size: clamp(1.7rem, 4.5vw, var(--s-2xl)); line-height: 1.15; }
h2 { font-family: var(--f-display); font-weight: 600; font-size: var(--s-xl); line-height: 1.2; }
h3 { font-size: var(--s-md); font-weight: 600; }
p { margin: 0; }
.lede { color: var(--muted); max-width: 65ch; }

/* ------------------------------------------------------------ correcteur */
.ask { display: grid; gap: 14px; }
.ask-form { display: flex; gap: 8px; flex-wrap: wrap; }
.ask-form input {
  flex: 1 1 280px; font-size: var(--s-md); padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
.ask-form input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  border: 0; border-radius: 10px; padding: 12px 18px; cursor: pointer; font-weight: 600;
  background: var(--accent); color: var(--surface);
}
.btn:hover { filter: brightness(1.08); }
.ctx-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: var(--s-sm); color: var(--muted); }
.chip-groups { display: grid; gap: 10px; }
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.chip-group-label { font-size: var(--s-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); min-width: 88px; font-weight: 600; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px;
  font-size: var(--s-sm); cursor: pointer; color: var(--ink);
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.result { display: grid; gap: 22px; }
.diag {
  display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); padding: 22px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
}
.diag-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: baseline; justify-content: space-between; }
.diag p { max-width: 75ch; }
.levers { display: grid; gap: 6px; padding: 14px 16px; background: var(--sunk); border-radius: 8px; font-size: var(--s-sm); }
.levers ul { margin: 0; padding-left: 1.1em; display: grid; gap: 4px; }
.see-also { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: var(--s-sm); color: var(--muted); }

.sugg-list { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.sugg {
  display: grid; gap: 6px 20px; padding: 16px 18px; border-top: 1px solid var(--line);
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr) minmax(0, 15rem);
  align-items: start;
}
.sugg:first-child { border-top: 0; }
.sugg-name { display: grid; gap: 4px; min-width: 0; }
.sugg-name button {
  all: unset; cursor: pointer; font-weight: 600; color: var(--ink); text-decoration: underline;
  text-decoration-color: var(--line); text-underline-offset: 3px; overflow-wrap: anywhere;
}
.sugg-name button:hover { text-decoration-color: var(--accent); color: var(--accent); }
.sugg-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: var(--s-xs); color: var(--muted); }
.sugg-body { display: grid; gap: 4px; min-width: 0; }
.sugg-body .sense { font-size: var(--s-sm); color: var(--muted); }
.sugg-badges { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; min-width: 0; }
.list-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.list-title h3 { font-size: var(--s-lg); font-family: var(--f-display); }
details.excluded { border: 1px dashed var(--line); border-radius: var(--r); padding: 12px 16px; background: var(--paper); }
details.excluded summary { cursor: pointer; font-weight: 600; font-size: var(--s-sm); }
details.excluded ul { margin: 10px 0 0; padding-left: 1.1em; display: grid; gap: 6px; font-size: var(--s-sm); }
.empty { padding: 22px; border: 1px dashed var(--line); border-radius: var(--r); color: var(--muted); display: grid; gap: 10px; }

/* ------------------------------------------------------------ pastilles */
.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 9px 2px 8px;
  font-size: var(--s-xs); font-weight: 600; line-height: 1.6; max-width: 100%; white-space: normal;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.neutral { background: var(--sunk); color: var(--muted); }
.tag { display: inline-block; font-size: var(--s-xs); padding: 1px 8px; border-radius: 4px; background: var(--sunk); color: var(--muted); }
.dose { display: inline-block; font-size: var(--s-xs); font-weight: 600; padding: 1px 8px; border-radius: 4px; border: 1px solid var(--line); color: var(--ink); }

/* Jeux d'orgue : la puissance olfactive en 5 tuyaux */
.pipes { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; vertical-align: middle; }
.pipes i { display: block; width: 4px; border-radius: 1px 1px 0 0; background: var(--line); }
.pipes i:nth-child(1) { height: 5px; } .pipes i:nth-child(2) { height: 7px; } .pipes i:nth-child(3) { height: 9px; }
.pipes i:nth-child(4) { height: 11px; } .pipes i:nth-child(5) { height: 14px; }
.pipes i.on { background: var(--accent); }

/* ------------------------------------------------------------ bibliothèque */
.lib-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lib-tools input { flex: 1 1 240px; padding: 10px 12px; font-size: var(--s-md); }
.lib-count { font-size: var(--s-sm); color: var(--muted); }
.lib-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table.lib { width: 100%; border-collapse: collapse; font-size: var(--s-sm); }
table.lib th {
  text-align: left; font-size: var(--s-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--paper); white-space: nowrap;
}
table.lib td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.lib tr:last-child td { border-bottom: 0; }
table.lib tbody tr { cursor: pointer; }
table.lib tbody tr:hover td { background: var(--paper); }
.lib-name { font-weight: 600; }
.lib-odeur { color: var(--muted); max-width: 34ch; }
.status-dual { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.fam-dots { display: flex; gap: 4px; flex-wrap: wrap; }

/* ------------------------------------------------------------ fiche (dialog) */
dialog.fiche {
  width: min(860px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line);
  border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog.fiche::backdrop { background: rgba(10, 16, 13, .45); }
.fiche-inner { display: grid; gap: 20px; padding: 22px 24px 26px; }
.fiche-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.fiche-head h2 { overflow-wrap: anywhere; }
.close {
  border: 1px solid var(--line); background: var(--paper); border-radius: 999px; width: 34px; height: 34px; flex: none;
  cursor: pointer; font-size: 18px; line-height: 1;
}
.idgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 18px; font-size: var(--s-sm); }
.idgrid dt { font-size: var(--s-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.idgrid dd { margin: 0; overflow-wrap: anywhere; }
.fiche-sec { display: grid; gap: 10px; }
.fiche-sec > h3 { font-size: var(--s-xs); text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.sense-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.sense-grid > div { display: grid; gap: 2px; }
.sense-grid .k { font-size: var(--s-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.reg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.reg-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: grid; gap: 6px; align-content: start; font-size: var(--s-sm); min-width: 0; }
.reg-card h4 { margin: 0; font-size: var(--s-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.reg-card p, .reg-card li { overflow-wrap: anywhere; }
.reg-card ul { margin: 0; padding-left: 1.1em; display: grid; gap: 3px; }
.accords { display: flex; flex-wrap: wrap; gap: 6px; }
.note-warn { font-size: var(--s-sm); background: var(--warn-soft); color: var(--ink); padding: 10px 12px; border-radius: 8px; }

/* ------------------------------------------------------------ pages texte */
.prose { display: grid; gap: 18px; max-width: 78ch; }
.prose p, .prose li { color: var(--ink); }
.prose ul { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; }
.prose h2 { margin-top: 10px; }
.cards-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.panel h3 { font-family: var(--f-display); font-size: var(--s-lg); }
.panel ul { margin: 0; padding-left: 1.1em; display: grid; gap: 5px; font-size: var(--s-sm); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table.plain { width: 100%; border-collapse: collapse; font-size: var(--s-sm); }
table.plain th, table.plain td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.plain th { font-size: var(--s-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: var(--paper); }
table.plain tr:last-child td { border-bottom: 0; }
.linkbtn { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

footer { border-top: 1px solid var(--line); background: var(--surface); }
footer .wrap { padding-block: 20px 28px; font-size: var(--s-xs); color: var(--muted); display: grid; gap: 6px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .sugg { grid-template-columns: minmax(0, 1fr); }
  .sugg-badges { flex-direction: row; flex-wrap: wrap; }
  .chip-group-label { min-width: 100%; }
}
@media (max-width: 640px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; order: 3; flex-basis: 100%; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; }
  .controls { margin-left: auto; }
  table.lib thead { display: none; }
  table.lib, table.lib tbody, table.lib tr, table.lib td { display: block; width: 100%; }
  table.lib tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.lib td { border: 0; padding: 3px 0; }
  table.lib td.c-classe, table.lib td.c-cas { display: inline-block; width: auto; margin-right: 10px; }
  .fiche-inner { padding: 18px 16px 22px; }
  dialog.fiche { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .result { animation: rise .25s ease-out; }
  @keyframes rise { from { transform: translateY(4px); } to { transform: none; } }
}
