/* ============================================================
   css/db.css — styles partagés des pages « Base de Données »
   (database/buildings, database/waracademy, database/masters,
    database/pets — index + fiches).

   Extrait des <style> inline autrefois dupliqués dans 35 pages.
   Rendu identique à l'existant : les quelques différences
   historiques entre catégories sont préservées via des classes
   sur .db-page (db-index / db-wide / db-cards-sm) et un scoping
   par ancêtre (.table-container vs .db-section), pas par
   uniformisation.
   ============================================================ */

/* ---- Page ---- */
.db-page { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; }
.db-page.db-index { max-width: 1000px; }   /* sommaires (index) */
.db-page.db-wide  { max-width: 1180px; }   /* fiches Académie (11 colonnes) */

.db-breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
/* Liens du fil d'Ariane soulignés en permanence : la couleur seule ne les distingue pas
   du texte voisin (WCAG 1.4.1). */
.db-breadcrumb a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.db-page h1 { color: var(--accent); margin: 0 0 6px; }
.db-intro { color: var(--text-muted); font-size: 14px; margin: 0 0 22px; line-height: 1.5; }
.db-intro strong { color: var(--text-light); }
/* Provenance des données (fiches bâtiments) */
.db-source { color: var(--text-muted); font-size: 12px; margin: 12px 0 0; line-height: 1.5; }

/* ---- Index : grille de cartes ---- */
.db-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 12px; }
.db-card { display: flex; flex-direction: row; align-items: center; gap: 14px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--control-bg); color: var(--text-light); text-decoration: none; font-weight: 600; transition: border-color .15s, transform .1s; }
/* Carte d'un élément pas encore sorti (data-feature / data-pet, js/site-config.js). */
.db-card[hidden] { display: none; }
.db-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.db-card-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.db-card-img { width: 92px; height: 92px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 2px 6px rgba(0,0,0,.45)); }
.db-page.db-cards-sm .db-card-img { width: 84px; height: 84px; }   /* experts / familiers */
.db-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.db-card-name { font-weight: 600; }

/* ---- Fiches : tableaux ---- */
/* RÈGLE BASES DE DONNÉES : un tableau ne défile jamais verticalement dans sa propre
   boîte, seule la page défile (pas de max-height ni d'overflow vertical).
   · ≥ 1280px : aucun overflow, les colonnes tiennent ; l'en-tête reste figé sous le
     header fixe pendant le défilement de la page.
   · < 1280px : défilement HORIZONTAL seul (overflow-x, cf. style.css) ; l'en-tête ne
     peut plus suivre la page (le conteneur devient la référence du sticky), top:0 évite
     qu'il se décale dans la boîte. */
/* position: relative : les textes .db-sr (absolus) des cellules ont le conteneur pour
   bloc conteneur ; sans cela, sous 1280px, ceux des colonnes masquées par le défilement
   débordaient de la page (largeur de document 581px mesurée à 390px). */
.db-page .table-container { position: relative; max-height: none; overflow-x: auto; overflow-y: hidden; }
@media (min-width: 1280px) {
  .db-page .table-container { overflow: visible; }
}
/* Conteneur focusable (tabindex="0") : défilement horizontal au clavier, focus visible. */
.db-page .table-container:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Texte réservé aux lecteurs d'écran (libellés, annonces). */
.db-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
table.db-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.db-table th, table.db-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.db-table thead th { background: var(--control-bg); color: var(--table-head-text, var(--text-muted)); text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
/* En-tête figé : les fiches Experts/Familiers héritent déjà de `th { position:sticky }`
   (règle globale de style.css, z-index 10). Ici on ne (re)cadre que les tables à
   conteneur scrollable (bâtiments / académie) qui redéfinissaient le z-index. */
.db-page .table-container table.db-table thead th { position: sticky; top: 0; z-index: 1; }
@media (min-width: 1280px) {
  .db-page .table-container table.db-table thead th { top: var(--header-height); }
}
.db-page.db-wide .table-container table.db-table thead th { z-index: 2; }
table.db-table tbody tr:hover { background: rgba(255,255,255,0.03); }
table.db-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* En-tête d'une colonne chiffrée : aligné comme ses valeurs, juste au-dessus d'elles. */
table.db-table thead th.num { text-align: right; }
/* Pas de marge sous un tableau encadré (sinon bande vide dans la bordure). */
.db-page .table-container table.db-table { margin-bottom: 0; }
table.db-table td.tg { color: var(--accent); font-weight: 600; }
/* Truegold trempé : violet par thème, ≥ 5,7:1 sur fond, alternance et contrôles en clair,
   ≥ 6,5:1 en sombre (l'ancien #c58cff fixe tombait à 2:1 sur le parchemin clair). */
table.db-table td.ttg { color: #6a32b0; font-weight: 600; }
[data-theme="dark"] table.db-table td.ttg { color: #c58cff; }
/* Colonne Truegold avant le Truegold (niveaux 1-30) : tiret discret, comme les autres colonnes. */
table.db-table td.nil { color: var(--text-muted); font-weight: 400; }
table.db-table :is(td, th).c-lbl { font-weight: 700; color: var(--text-light); }
/* Fiches bâtiments : la cellule de niveau est un <th scope="row"> (WCAG 1.3.1). On neutralise
   le `th` global de style.css (sticky, top 0, z-index 10, fond d'en-tête) et la typographie
   des en-têtes de theme-brand.css (12px, interlettrage) : elle garde l'aspect d'une cellule.
   Spécificité (0,3,3) = la colonne figée mobile de style.css, rétablie plus bas sous 820px. */
.db-page table.db-table tbody th.c-lbl { position: static; top: auto; z-index: auto; background: transparent; font-size: inherit; letter-spacing: normal; text-transform: none; text-align: left; }
table.db-table td.c-req { white-space: normal; color: var(--text-muted); font-size: 12px; min-width: 160px; }
table.db-table td.c-wa { color: var(--text-muted); font-size: 12px; }
/* c-eff : Académie (190px, 12px) vs Experts/Familiers (150px, taille héritée) */
.db-page .table-container table.db-table td.c-eff { white-space: normal; color: var(--text-light); font-size: 12px; min-width: 190px; }
.db-section table.db-table td.c-eff { white-space: normal; color: var(--text-light); min-width: 150px; }
/* Regroupements Académie */
table.db-table tr.wa-group:hover { background: var(--table-header); }
table.db-table tr.wa-group td { background: var(--table-header); color: var(--accent); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

/* ---- Fiches bâtiments : en-têtes de statistiques ----
   Libellés LordrushHub parfois longs (« Ally Help Time (seconds/help) ») : seuls en-têtes
   autorisés à passer sur deux lignes, pour que les 12 colonnes de l'Ambassade tiennent à
   1280px. Ils ne se replient que si la place manque. Spécificité (0,2,3) > celle de
   `table.db-table th` (0,1,2) qui pose le nowrap. */
.db-page table.db-table thead th.c-stat { white-space: normal; }

/* ---- Fiches bâtiments : niveaux Truegold (30-1 … TG3) ----
   Second <tbody> ouvert par un intertitre <th scope="rowgroup">. Le `th` global de
   style.css (sticky, top 0, z-index 10) et, sous 820px, la colonne figée de style.css
   (`body.has-app-header table.db-table th:first-child`, spécificité 0,3,3) sont
   neutralisés : sélecteurs en .db-page (0,3,3 et plus), db.css chargé après style.css.
   L'intertitre défile avec ses lignes ; son libellé reste collé au bord gauche au
   défilement horizontal, comme .wa-group. Les paliers TGN (TG1, TG2…) portent le filet
   de cire et un fond teinté ; les sous-niveaux gardent l'alternance, seul leur libellé
   passe au rouge de cire. Contrastes mesurés dans Edge (clair / sombre) : libellé rouge
   sur palier teinté 5,4 / 5,3:1, intertitre 5,6 / 5,1:1, prérequis atténué sur palier
   teinté 4,85 / 6,3:1. */
.db-page table.db-table tr.lv-group th { position: static; z-index: auto; padding: 9px 10px; background: var(--table-header); box-shadow: none; color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; text-align: left; border-top: 1px solid var(--border); }
.db-page table.db-table tbody tr.lv-group:hover { background: var(--table-header); }
.db-page table.db-table tr.lv-group .lv-group-name { display: inline-block; position: sticky; left: 10px; }
.db-page table.db-table tr.lv-group .lv-group-meta { margin-left: 10px; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.db-page table.db-table tr.lv-tg .c-lbl { color: var(--accent); }
.db-page table.db-table tbody tr.lv-tier { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.db-page table.db-table tr.lv-tier .c-lbl { box-shadow: inset 3px 0 0 var(--accent); }
/* Sous 820px le tableau défile : le complément de l'intertitre passe sous le libellé,
   collé lui aussi ; la cellule de niveau, figée et opaque (style.css), reprend la teinte
   du palier et garde son filet de séparation. */
@media (max-width: 820px) {
  .db-page table.db-table tr.lv-group .lv-group-name,
  .db-page table.db-table tr.lv-group .lv-group-meta { display: block; width: fit-content; position: sticky; left: 12px; margin-left: 0; }
  .db-page table.db-table tr.lv-group .lv-group-meta { margin-top: 2px; }
  /* Colonne de niveau figée (même rendu que `td.c-lbl` dans style.css). */
  .db-page table.db-table tbody th.c-lbl { position: sticky; left: 0; z-index: 1; background: var(--bg-dark); box-shadow: 1px 0 0 var(--border); }
  .db-page table.db-table tr.lv-tier .c-lbl { background: color-mix(in srgb, var(--accent) 8%, var(--bg-dark)); box-shadow: inset 3px 0 0 var(--accent), 1px 0 0 var(--border); }
}

/* ---- Navigation groupée (bâtiments Truegold / autres) ---- */
/* Chaque groupe est un role="group" nommé par son libellé, ses pastilles une liste <ul>.
   Rendu identique aux pastilles en ligne : la liste reprend le flex de .db-switch. */
.db-switch-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; flex-basis: 100%; }
.db-switch-list > li { margin: 0; padding: 0; }
.db-switch-group { display: flex; flex-direction: column; gap: 6px; flex-basis: 100%; }
.db-switch-group + .db-switch-group { margin-top: 4px; }
.db-switch-label { color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
/* Sommaire en sections : la première suit l'intro sans double marge. */
.db-index .db-section:first-of-type { margin-top: 0; }

/* ---- Fiches Experts / Familiers : sections & blocs compétence ---- */
.db-section { margin: 30px 0 0; }
.db-section > h2 { color: var(--accent); font-size: 16px; text-transform: uppercase; letter-spacing: .03em; margin: 0 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.db-section table.db-table { margin-bottom: 4px; }
.table-wrap, .m-block { overflow-x: auto; }
.m-block { margin-bottom: 26px; }
.m-block-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.m-ico { width: 48px; height: 48px; object-fit: contain; flex-shrink: 0; border-radius: 8px; background: var(--control-bg); border: 1px solid var(--border); padding: 4px; }
.m-block-name { color: var(--accent); font-weight: 700; font-size: 15px; }
.m-block-tag { font-size: 11px; color: var(--success); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.m-block-desc { font-size: 12px; color: var(--text-muted); line-height: 1.45; margin-top: 3px; max-width: 720px; white-space: normal; }

/* ---- Navigation entre entités (switch) ---- */
.db-switch { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.db-switch-item { padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--control-bg); color: var(--text-light); text-decoration: none; font-size: 13px; font-weight: 600; transition: border-color .15s, background .15s; }
a.db-switch-item:hover { border-color: var(--accent); }
.db-switch-item.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); cursor: default; }
.db-switch.footer { margin-top: 28px; border-top: 1px solid var(--border); padding-top: 18px; }

/* ---- Barre de filtres (fiche Académie « Advanced » : 92 techs) ----
   Les puces réutilisent .db-switch-item ; seul le <button> a besoin d'un
   rappel de police, les navigateurs ne l'héritent pas. */
.db-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.db-toolbar .db-switch { margin: 0; }
button.db-switch-item { font-family: inherit; cursor: pointer; }
.db-search { flex: 1 1 200px; min-width: 160px; max-width: 300px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text-light); font-family: inherit; font-size: 13px; padding: 6px 10px; border-radius: 6px; }
.db-search:focus { outline: none; border-color: var(--accent); }
.db-search::placeholder { color: var(--text-muted); }
.db-count { font-size: 12px; color: var(--text-muted); margin-left: auto; font-variant-numeric: tabular-nums; }
/* En-tête de groupe enrichi : nom doré à gauche, effet/paliers en gris à droite */
table.db-table tr.wa-group td .wg-meta { float: right; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
/* La ligne de groupe s'étire sur toute la largeur de la table : au défilement
   horizontal son nom sortirait de l'écran et on ne saurait plus quelle recherche
   on lit. Il reste donc collé au bord gauche, comme la colonne des niveaux. */
table.db-table tr.wa-group td .wg-name { display: inline-block; position: sticky; left: 0; }
/* Sous 820px, le méta flotté à droite partirait lui aussi hors champ : on le
   repasse sous le nom. `width: fit-content` est indispensable — un bloc pleine
   largeur remplit la table entière et `sticky` n'a alors aucun jeu pour le
   ramener dans le champ. */
@media (max-width: 820px){
  table.db-table tr.wa-group td .wg-name,
  table.db-table tr.wa-group td .wg-meta { display: block; width: fit-content; position: sticky; left: 0; }
  table.db-table tr.wa-group td .wg-meta { float: none; margin-top: 2px; }
}

/* ---- En-tête de fiche (portrait + titre) ---- */
.db-head { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.db-hero { width: 84px; height: 84px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 3px 8px rgba(0,0,0,.45)); }
.db-head h1 { margin: 0; }

/* A11Y-21 : css/db.css charge après css/style.css, donc son .db-card:hover
   (non conditionnel) l'emporterait sur une règle équivalente écrite dans
   style.css à spécificité égale. Le garde-fou reduced-motion pour cette
   carte vit donc ici. */
@media (prefers-reduced-motion: reduce) {
  .db-card:hover { transform: none; }
}
@media (max-width: 520px){ .db-hero { width: 60px; height: 60px; } }
