/* Feuille de style unique du hub : thème clair, barre latérale, couleur de marque réglable par organisation

La couleur de marque arrive par les variables --brand, --brand-contrast et --brand-ink,
posées par theme.js à partir de l'organisation. Les valeurs ci-dessous servent avant
la connexion et si le JavaScript n'a pas encore tourné */

:root {
  /* marque, « Midnight Black » de Kia par défaut */
  --brand: #05141f;
  --brand-contrast: #ffffff;
  --brand-ink: #05141f;

  /* un seul accent, pour les liens et la mise en avant */
  --accent: #1d5c96;
  --accent-soft: #eaf1f8;

  /* neutres */
  --bg: #ffffff;
  --surface: #fafbfc;
  --surface-muted: #f2f4f6;
  --field: #ffffff;
  --text: #0e1a24;
  --text-muted: #55606b;
  --border: #e1e5ea;
  --border-strong: #c3cad2;
  /* contour des champs : 3:1 minimum sur bg, surface et surface-muted (WCAG 1.4.11), voir tests/test_contrast.py */
  --field-border: #7f8a95;
  --placeholder: #6b7580;

  /* couleurs sémantiques, volontairement distinctes de la marque */
  --success: #1e7a46;
  --success-soft: #e8f5ed;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --draft: #6941c6;
  --draft-soft: #f3effc;
  --archived: #5f6b76;
  --archived-soft: #eef1f4;

  --radius: 8px;
  --sidebar-width: 256px;
  --shadow: 0 1px 2px rgba(5, 20, 31, 0.05), 0 1px 1px rgba(5, 20, 31, 0.03);
  --shadow-hover: 0 4px 12px rgba(5, 20, 31, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { color: var(--brand-ink); line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 700; margin: 0 0 0.35rem; }
h2 { font-size: 1.15rem; font-weight: 650; margin: 0 0 0.85rem; }
h3 { font-size: 1rem; font-weight: 650; margin: 0 0 0.6rem; }
p { margin: 0 0 0.75rem; }

.hidden { display: none !important; }

/* lu par les lecteurs d'écran, invisible à l'écran */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* lien d'évitement : premier arrêt de tabulation, visible seulement au focus */
.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 10;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  background: var(--bg);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-hover);
}

.skip-link:focus { top: 0.5rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }

/* focus toujours visible, y compris à la souris pour les champs */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
/* cibles de focus programmé (contenu principal, alertes) : pas d'anneau, ce ne sont pas des commandes */
[tabindex="-1"]:focus { outline: none; }

/* barre latérale : haut aux couleurs de l'organisation, navigation sur fond clair */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar__top {
  background: var(--brand);
  color: var(--brand-contrast);
  border-radius: var(--radius);
  padding: 0.9rem 0.95rem;
}

.sidebar__top :focus-visible { outline-color: var(--brand-contrast); }

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  color: var(--brand-contrast);
  text-decoration: none;
}

.brand:hover { color: var(--brand-contrast); }
.brand__logo { height: 32px; width: auto; max-width: 72px; object-fit: contain; flex: none; }
.brand__text { display: grid; min-width: 0; line-height: 1.25; }
.brand__name { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em; }
/* pas d'opacité réduite : avec une couleur de marque quelconque, le contraste ne serait plus garanti */
.brand__org { font-size: 0.86rem; overflow-wrap: anywhere; }

.sidebar__toggle { display: none; }

.sidebar__panel { display: flex; flex-direction: column; gap: 1.25rem; flex: 1; }

.nav__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.nav__link {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.nav__link:hover { background: var(--surface-muted); color: var(--text); }

/* lien actif : fond de marque et texte de contraste, lisible quelle que soit la couleur choisie */
.nav__link[aria-current="page"] { background: var(--brand); color: var(--brand-contrast); font-weight: 650; }

.nav-icon { flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sidebar__user { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }
.user-card { display: grid; gap: 0.1rem; margin: 0 0 0.6rem; padding: 0 0.75rem; line-height: 1.3; }
.user-card__name { font-weight: 650; font-size: 0.92rem; }
.user-card__email { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.org-picker { display: grid; gap: 0.3rem; padding: 0 0.25rem; font-size: 0.85rem; font-weight: 600; }
.org-picker select { padding: 0.4rem 0.5rem; font-size: 0.88rem; }

/* sous 900 px : barre compacte en haut, la navigation se déplie derrière le bouton Menu */
@media (max-width: 899px) {
  .app-layout { display: block; }

  .sidebar {
    z-index: 20;
    height: auto;
    max-height: 100vh;
    padding: 0;
    gap: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
  }

  .sidebar__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border-radius: 0;
    padding: 0.55rem 16px;
  }

  .sidebar__toggle {
    font: inherit;
    font-weight: 600;
    font-size: 0.93rem;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    flex: none;
    min-height: 2.5rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--brand-contrast);
    border-radius: 6px;
    background: transparent;
    color: var(--brand-contrast);
    cursor: pointer;
  }

  .sidebar__panel { display: none; padding: 12px 16px 16px; }
  .sidebar--open { overflow-y: auto; }
  .sidebar--open .sidebar__panel { display: flex; }
}

.burger { display: grid; gap: 4px; width: 18px; }
.burger span { display: block; height: 2px; border-radius: 2px; background: currentColor; transition: transform 0.15s ease, opacity 0.15s ease; }
[aria-expanded="true"] .burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
[aria-expanded="true"] .burger span:nth-child(2) { opacity: 0; }
[aria-expanded="true"] .burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* mise en page */

.page { width: 100%; max-width: 1160px; margin: 0 auto; padding: 2.25rem 32px 4rem; }
.page--narrow { max-width: 760px; }

@media (max-width: 899px) {
  .page { padding: 1.5rem 20px 3.5rem; }
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-head h1 { margin-bottom: 0.3rem; }
.page-head p { margin: 0; max-width: 60ch; }

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}

.panel .panel { background: var(--surface); box-shadow: none; }

.notice {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-muted);
  margin-bottom: 1rem;
}

.notice--error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.notice--success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }

/* formulaires */

.form { display: grid; gap: 1.1rem; }
.form-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }

label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.92rem; color: var(--text); }
label .hint { font-weight: 400; color: var(--text-muted); font-size: 0.85rem; }

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  width: 100%;
  min-width: 0;
}

input::placeholder, textarea::placeholder { color: var(--placeholder); }
/* champ signalé en erreur : bordure plus épaisse en plus de la couleur, pour ne pas reposer sur la couleur seule */
[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
textarea { min-height: 7rem; resize: vertical; }

fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
legend { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.4rem; width: 100%; }
.radio { display: flex; align-items: center; gap: 0.45rem; font-weight: 400; }
.radio input { width: auto; accent-color: var(--brand); }

.button {
  font: inherit;
  font-weight: 600;
  font-size: 0.93rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: var(--brand-contrast);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover { background: color-mix(in srgb, var(--brand) 86%, #ffffff); color: var(--brand-contrast); text-decoration: none; }
.button--ghost { background: var(--field); border-color: var(--border-strong); color: var(--brand-ink); }
.button--ghost:hover { background: var(--surface-muted); color: var(--brand-ink); }
.button--danger { background: var(--field); border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.button--danger:hover { background: var(--danger-soft); color: var(--danger); }
.button--danger-solid { background: var(--danger); border-color: var(--danger); color: #ffffff; }
.button--danger-solid:hover { background: color-mix(in srgb, var(--danger) 86%, #000000); color: #ffffff; }
.button--small { min-height: 2rem; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.external-icon { font-size: 0.85em; line-height: 1; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

/* catalogue */

/* recherche sur toute la largeur, puis les listes alignées, qui passent à la ligne par colonnes entières */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.filters > .filters__search { grid-column: 1 / -1; }

.result-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; font-size: 0.92rem; }

.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.card:hover,
.card:focus-within { box-shadow: var(--shadow-hover); border-color: var(--border-strong); }
.card--featured { border-top: 3px solid var(--accent); }

.card__title { font-size: 1.08rem; font-weight: 650; margin: 0; }
.card__title a { color: var(--brand-ink); text-decoration: none; }
.card__title a:hover { color: var(--accent); text-decoration: underline; }

.card__description {
  color: var(--text-muted);
  font-size: 0.93rem;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* département et ouvertures, les deux repères qu'on cherche en parcourant le catalogue */
.card__facts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.75rem; margin: auto 0 0; padding-top: 0.25rem; }
.card__facts div { display: grid; gap: 0.05rem; min-width: 0; }
.card__facts dt { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-muted); }
.card__facts dd { margin: 0; font-size: 0.92rem; font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.card__facts div:last-child { text-align: right; }

.card__footer { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 0.7rem; border-top: 1px solid var(--border); }
.card__meta { font-size: 0.84rem; color: var(--text-muted); margin: 0; min-width: 0; }

.badges { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.badge {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.12rem 0.5rem;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge--type { color: var(--text); background: var(--bg); border-color: var(--border-strong); }
.badge--featured { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.badge--draft { background: var(--draft-soft); color: var(--draft); border-color: color-mix(in srgb, var(--draft) 25%, transparent); }
.badge--archived { background: var(--archived-soft); color: var(--archived); }

.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.tag {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text-muted);
  cursor: pointer;
}

.tag:hover { border-color: var(--accent); color: var(--accent); }

.load-more { display: flex; justify-content: center; margin-top: 1.5rem; }
.load-more .button { gap: 0.5rem; }

[aria-busy="true"] .cards { opacity: 0.6; transition: opacity 0.15s ease; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }

/* fiche outil */

.detail-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.45rem 1.5rem;
  margin: 1.25rem 0;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.detail-meta dt { color: var(--text-muted); }
.detail-meta dd { margin: 0; overflow-wrap: anywhere; }

/* tableau de bord */

.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 1.25rem; }

.stat {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.2rem;
}

.stat__value { font-size: 2.25rem; font-weight: 700; line-height: 1.05; color: var(--brand-ink); font-variant-numeric: tabular-nums; }
.stat__label { color: var(--text-muted); font-size: 0.82rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }

/* répartition par département en pleine largeur, puis les deux classements côte à côte */
.dashboard-grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 720px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}
.dashboard-grid .panel { margin-bottom: 0; }
.panel--wide { grid-column: 1 / -1; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }
.bar__label { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; font-size: 0.93rem; }
.bar__name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.bar__value { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar__track { height: 10px; background: var(--surface-muted); border-radius: 999px; overflow: hidden; margin-top: 0.35rem; }
.bar__fill { height: 100%; min-width: 4px; background: var(--brand); border-radius: 999px; }

.ranking { list-style: none; counter-reset: rang; margin: 0; padding: 0; display: grid; }
.ranking li {
  counter-increment: rang;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.ranking li:last-child { border-bottom: 0; }
.ranking li::before { content: counter(rang); flex: none; width: 1.5rem; color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.ranking__label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ranking .count { color: var(--text-muted); font-size: 0.88rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* administration */

/* relative : les textes masqués (position absolue) restent dans la zone défilante au lieu d'élargir la page */
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; white-space: nowrap; font-size: 0.85rem; }
td select { min-width: 130px; }
/* en-tête de ligne (nom de la personne) : lu comme tel par les lecteurs d'écran, affiché comme une cellule */
tbody th { color: var(--text); font-weight: 400; font-size: inherit; white-space: normal; }

.link-box { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.link-box input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

.contrast-warning { color: var(--danger); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }

.color-field { display: flex; gap: 0.5rem; align-items: center; }
.color-field input[type="color"] { width: 3rem; height: 2.55rem; padding: 0.2rem; cursor: pointer; flex: none; }

.brand-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--brand-contrast);
}

/* boîte de confirmation */

.confirm-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 1.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 12px 32px rgba(5, 20, 31, 0.18);
}

.confirm-dialog::backdrop { background: rgba(5, 20, 31, 0.45); }
.confirm-dialog p { color: var(--text-muted); }
.confirm-dialog__actions { justify-content: flex-end; margin-top: 1rem; }

/* connexion */

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--surface-muted); }
.auth-card { width: 100%; max-width: 410px; background: var(--bg); border-top: 4px solid var(--brand); padding: 1.75rem; }
.auth-card h1 { margin-bottom: 0.25rem; }

@media (max-width: 560px) {
  h1 { font-size: 1.4rem; }
  .page { padding: 1.25rem 16px 3rem; }
  .panel { padding: 1rem; }
  .detail-meta { grid-template-columns: 1fr; gap: 0.1rem; }
  .detail-meta dd { margin-bottom: 0.5rem; }
  .link-box { flex-direction: column; }
  .page-head .button { width: 100%; }
}

/* mouvements réduits sur demande du système */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
