/* Neodico — Responsive Design (drop-in)
   - Mobile-first, fluid layout
   - CSS variables (light/dark)
   - Better forms, cards, tables, badges, pagination
   - Works with existing HTML structure used in the project
*/

/* ---------- Reset & base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
img, svg, video { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
:focus { outline: none; }

/* ---------- Design tokens ---------- */
:root {
  /* palette (light) */
  --bg: #ffffff;
  --bg-elev: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5e7eb;
  --primary: #111827;
  --primary-ink: #ffffff;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --success: #15803d;
  --ring: #6366f1;

  --radius: 14px;
  --shadow: 0 8px 24px rgba(2,6,23,.08);
  --shadow-sm: 0 2px 8px rgba(2,6,23,.06);

  --container: 1100px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
}

/* Dark mode using [data-theme="dark"] or OS preference */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-elev: #0f172a;
    --text: #f1f5f9;
    --muted: #9aa4b2;
    --border: #111827;
    --primary: #e2e8f0;
    --primary-ink: #0b1220;
    --accent: #8b5cf6;
    --accent-ink: #0b1220;
    --danger: #ef4444;
    --success: #22c55e;
    --ring: #8b5cf6;
    --shadow: 0 8px 24px rgba(0,0,0,.4);
    --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
  }
}
:root[data-theme="light"] {
  --bg: #ffffff; --bg-elev:#f8fafc; --text:#0f172a; --muted:#64748b; --border:#e5e7eb;
  --primary:#111827; --primary-ink:#ffffff; --accent:#4f46e5; --accent-ink:#ffffff; --danger:#b91c1c; --success:#15803d; --ring:#6366f1;
}
:root[data-theme="dark"] {
  --bg: #0b1220; --bg-elev:#0f172a; --text:#f1f5f9; --muted:#9aa4b2; --border:#111827;
  --primary:#e2e8f0; --primary-ink:#0b1220; --accent:#8b5cf6; --accent-ink:#0b1220; --danger:#ef4444; --success:#22c55e; --ring:#8b5cf6;
}

/* ---------- Typography ---------- */
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: clamp(22px, 2.2vw + 4px, 32px); }
h2 { font-size: clamp(18px, 1.6vw + 4px, 26px); }
h3 { font-size: clamp(16px, 1.2vw + 4px, 20px); }
p { margin: 0 0 var(--space-3); }
.muted { color: var(--muted); }
.muted-small { color: var(--muted); font-size: .92rem; }

/* ---------- Layout ---------- */
.container {
  max-width: var(--container);
  padding: 0 var(--space-4);
  margin: 0 auto;
}
.header {
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.nav .btn { margin-left: auto; }
@media (max-width: 740px) {
  .nav { flex-wrap: wrap; gap: var(--space-2); }
  .nav .btn { margin-left: 0; }
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

/* ---------- Buttons ---------- */
.btn, button, .button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
  text-decoration: none;
  transition: transform .02s ease, box-shadow .2s ease, background .2s ease, color .2s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }

/* ---------- Inputs & Forms ---------- */
input[type="text"], input[type="search"], input[type="password"], input[type="file"],
input[type="email"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}

/* ---------- Alpha index ---------- */
.alpha { display:flex; flex-wrap:wrap; gap: var(--space-1); }
.alpha a, .alpha span {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg);
}
.alpha .active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* ---------- List / term ---------- */
.list { display: grid; gap: var(--space-3); }
.term { padding-bottom: var(--space-2); border-bottom: 1px dashed var(--border); }
.term:last-child { border-bottom: none; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: .85rem; color: var(--muted);
  background: var(--bg);
}
.badge-cat {
  display: inline-flex; align-items: center;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  color: var(--text);
  padding: 2px 10px; border-radius: 999px; font-size: .85rem;
}

/* ---------- Tables ---------- */
.tbl { 
  width: 100%;
  border-collapse: collapse;
  background: var(--bg);
  border-radius: 12px;
  overflow: hidden;
  display: block;             /* responsive scroll */
  overflow-x: auto;
  white-space: nowrap;
}
.tbl th, .tbl td { 
  padding: 10px 12px; 
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.tbl thead th { background: var(--bg-elev); font-weight: 600; }
.tbl tr:last-child td { border-bottom: none; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}
.pagination a, .pagination span {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg);
}
.pagination a:hover { border-color: var(--primary); }

/* ---------- Alerts ---------- */
.flash { padding: 10px; border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border)); background: color-mix(in srgb, var(--success) 10%, var(--bg)); border-radius: 10px; }
.error { padding: 10px; border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border)); background: color-mix(in srgb, var(--danger) 10%, var(--bg)); border-radius: 10px; }

/* ---------- Footer ---------- */
footer { color: var(--muted); padding: var(--space-4) 0; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.center { text-align: center; }
.maxw-sm { max-width: 640px; }
.maxw-md { max-width: 820px; }
.maxw-lg { max-width: 980px; }
.pad-0 { padding: 0 !important; }
.pad-2 { padding: var(--space-2) !important; }
.pad-3 { padding: var(--space-3) !important; }
.gap-2 { gap: var(--space-2) !important; }
.gap-3 { gap: var(--space-3) !important; }
.mt-2 { margin-top: var(--space-2) !important; }
.mt-3 { margin-top: var(--space-3) !important; }
.mt-4 { margin-top: var(--space-4) !important; }
.round { border-radius: var(--radius) !important; }

/* ---------- Focus visible ---------- */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Code blocks (definitions may show code) ---------- */
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
}

/* ---------- Header help text ---------- */
.header .muted { margin-top: var(--space-1); }

/* --- Brand (logo + wordmark) --- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: clamp(18px, 1.6vw + 4px, 26px);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand-logo { height: 28px; width: auto; display: inline-block; }
.brand-name { letter-spacing: .2px; }
.nav .brand { margin-right: auto; } /* push buttons to the right on list pages */
@media (max-width: 740px) {
  .brand-name { display: none; } /* keep only the icon on small screens */
}

/* === Logo plus grand (override) === */
.brand-logo { height: 44px; }           /* Desktop */
.brand { font-size: clamp(20px, 2.2vw + 6px, 30px); }

@media (max-width: 740px) {
  .brand-logo { height: 36px; }         /* Mobile */
}

/* === Breadcrumbs === */
.breadcrumbs {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  color: var(--muted);
  margin-bottom: 10px;
}
.breadcrumbs a { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--border); }
.breadcrumbs .sep { opacity: .6; }

/* === Clickable terms hint (enforcé) === */
.definition a.autoterm,
.definition a[href^="/t/"],
.definition a[href*="/t/"] {
  text-decoration: none !important;
  border-bottom: 1px dotted var(--border) !important;
  color: inherit !important;
  box-shadow: none !important;
  transition: border-color .2s ease;
}
.definition a.autoterm:hover,
.definition a[href^="/t/"]:hover,
.definition a[href*="/t/"]:hover {
  border-bottom-color: var(--accent) !important;
}

/* Images dans définitions */
figure.img-def { margin: var(--space-3) 0; text-align: center; }
figure.img-def img { max-width:100%; height:auto; border:1px solid var(--border); border-radius:12px; background:var(--bg); }
figure.img-def figcaption { color: var(--muted); font-size:.9rem; margin-top:6px; }

.definition img { max-width:100%; height:auto; display:block; }
.definition figure { margin: 1em 0; }
.definition figcaption { font-size:.9rem; color:#6b7280; }

/* Centre les visuels insérés dans les définitions */
.definition figure.img-def { 
  margin: 1rem auto; 
  text-align: center;        /* centre la légende */
}

.definition figure img {
  display: block;            /* le rend centrable avec margin auto */
  max-width: 100%;
  height: auto;
  margin-inline: auto;       /* centre l’image horizontalement */
}

/* Ceinture+bretelles si un style inline force un float */
.definition img[style*="float:"] { float: none !important; margin-inline: auto !important; }


/* === Barre de recherche : 1 ligne, bouton au bout du champ === */
.header .nav .search {
  margin-left: auto;        /* pousse la recherche à droite du header */
  max-width: 560px;         /* évite de prendre toute la largeur du header */
  width: 100%;
}

.header .nav .search form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;        /* reste sur une seule ligne */
  margin: 0;
}

.header .nav .search input[type="text"] {
  flex: 1 1 auto;           /* le champ occupe tout l’espace disponible */
  min-width: 0;             /* empêche les débordements */
}

.header .nav .search form > div {
  flex: 0 0 auto;           /* le conteneur du bouton ne s’étire pas */
  display: contents;        /* neutralise le wrapper si présent */
}

.header .nav .search button {
  padding: 6px 12px;        /* bouton plus compact */
  height: 36px;
  line-height: 1;
  font-size: 14px;
  white-space: nowrap;
  border-radius: 9999px;
}

/* === Header search: 1 ligne, bouton à droite === */
.header .nav form[action$="/search.php"],
.header .nav form[action*="/search.php"]{
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-wrap: nowrap !important;
  margin: 0 !important;
  width: clamp(320px, 40vw, 560px) !important; /* ne pas occuper tout le header */
  margin-left: auto !important;                /* pousse le bloc à droite */
}

/* Le champ prend la place, mais n’impose plus 100% */
.header .nav form[action*="/search.php"] input[type="text"][name="search"],
.header .nav form[action*="/search.php"] input#search{
  flex: 1 1 auto !important;
  min-width: 0 !important;
  width: auto !important;     /* override du width:100% global */
}

/* Si le bouton est enveloppé par un <div>, on l’aplatit */
.header .nav form[action*="/search.php"] > div { 
  display: contents !important; 
}

/* Bouton compact, collé à droite */
.header .nav form[action*="/search.php"] button[type="submit"]{
  padding: 6px 12px !important;
  height: 36px !important;
  line-height: 1 !important;
  font-size: 14px !important;
  border-radius: 9999px !important;
  white-space: nowrap !important;
  flex: 0 0 auto !important;
}

/* Barre de recherche header : 1 ligne, bouton au bout */
.nav-search{
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;            /* pousse la barre à droite du header */
  max-width: 560px;              /* évite de manger tout le header */
  width: 100%;
}

/* Le champ prend la place, le bouton se colle à droite */
.nav-search input[type="search"],
.nav-search input[type="text"]{
  flex: 1 1 auto;
  min-width: 0;
  width: auto;                   /* override du width:100% global */
}

.nav-search .btn--search{
  padding: 6px 12px;
  height: 36px;
  line-height: 1;
  font-size: 14px;
  border-radius: 9999px;
  white-space: nowrap;
}

/* === Barre de recherche pleine largeur + bouton à droite === */
.nav-search{
  flex: 1 1 auto !important;   /* le bloc peut grandir */
  width: auto !important;
  min-width: 0 !important;
  margin-left: 16px !important; /* petit espace après le logo */
}

.nav-search label{
  flex: 0 0 auto;
  margin-right: 8px;
  white-space: nowrap;
}

.nav-search input[type="search"],
.nav-search input[type="text"]{
  flex: 1 1 0% !important;      /* prend tout l’espace restant */
  width: auto !important;       /* override du width:100% global */
  min-width: 0 !important;      /* autorise la réduction si besoin */
}

.nav-search .btn--search{
  flex: 0 0 auto;
  padding: 6px 12px;
  height: 36px;
  line-height: 1;
  font-size: 14px;
  border-radius: 9999px;
  white-space: nowrap;
}

/* --- Autocomplete --- */
.ac-list.hidden { display: none; }
.ac-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ac-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.ac-item:hover, .ac-item.is-active {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
}
.ac-term { font-weight: 600; }
