/* Feuille de style partagée de l'application (mise en page, liste, fiche).
   Palette neutre + accent indigo, ombres douces plutôt que bordures dures. */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2430;
  --text-muted: #6b7280;
  --text-faint: #9aa1ac;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 6px rgba(16, 24, 40, 0.05);
  --shadow-hover: 0 2px 4px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1c1f28;
    --border: #2c303b;
    --text: #e7e9ee;
    --text-muted: #9ba0ab;
    --text-faint: #6b7280;
    --accent: #818cf8;
    --accent-hover: #a5b0f8;
    --accent-soft: rgba(129, 140, 248, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 6px rgba(0, 0, 0, 0.25);
    --shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.gl-topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: .6rem 1.25rem;
  font-size: .82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.gl-topbar::before {
  content: "◆";
  color: var(--accent);
  font-size: .7rem;
}

.gl-title {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 1.25rem;
  color: var(--text);
}

.gl-toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; }
.gl-toolbar input[type=search] {
  flex: 1;
  padding: .6rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.gl-toolbar input[type=search]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.gl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table.gl-table { width: 100%; border-collapse: collapse; }
table.gl-table thead { background: color-mix(in srgb, var(--surface) 96%, var(--text) 4%); }
table.gl-table th {
  padding: .7rem .9rem;
  text-align: left;
  font-size: .74rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
table.gl-table td {
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
table.gl-table tbody tr:last-child td { border-bottom: none; }
table.gl-table th[data-align=right], table.gl-table td[data-align=right] { text-align: right; }
table.gl-table th button {
  background: none; border: none; font: inherit; font-weight: inherit;
  text-transform: inherit; letter-spacing: inherit; color: inherit;
  cursor: pointer; padding: 0; display: inline-flex; align-items: center; gap: .25rem;
}
table.gl-table th button:hover { color: var(--accent); }
table.gl-table tbody tr { transition: background-color .1s ease; }
table.gl-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, var(--surface) 96%); }
table.gl-table a { color: var(--accent); text-decoration: none; font-weight: 550; }
table.gl-table a:hover { color: var(--accent-hover); text-decoration: underline; }

.gl-pagination {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem .9rem; font-size: .85rem; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.gl-pagination button {
  padding: .4rem .85rem; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm); cursor: pointer; font-size: .85rem;
  transition: border-color .15s ease, color .15s ease;
}
.gl-pagination button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.gl-pagination button:disabled { opacity: .4; cursor: default; }

.gl-btn {
  padding: .55rem 1.1rem; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 550;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
  gap: .4rem; border: 1px solid transparent; transition: all .15s ease;
}
.gl-btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.gl-btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-hover); }
.gl-btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.gl-btn-secondary:hover { border-color: var(--text-faint); }
.gl-btn-danger { background: none; color: #dc2626; border-color: color-mix(in srgb, #dc2626 40%, var(--border) 60%); }
.gl-btn-danger:hover { background: color-mix(in srgb, #dc2626 12%, var(--surface) 88%); }

.gl-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.gl-header-row .gl-title { margin: 0; }

/* Fiche */
.gl-field { margin-bottom: 1.15rem; }
.gl-field label {
  display: block; font-weight: 600; font-size: .78rem; margin-bottom: .35rem;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
}
.gl-field input[type=text], .gl-field input[type=number], .gl-field input[type=date],
.gl-field select, .gl-field textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: .95rem; font-family: inherit;
  background: var(--surface); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.gl-field input:focus, .gl-field select:focus, .gl-field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.gl-field textarea { min-height: 5rem; resize: vertical; }
.gl-field input[type=checkbox] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

.gl-actions { display: flex; gap: .6rem; margin-top: 1.5rem; }

@media (max-width: 640px) {
  .app-content { padding: 1.25rem .9rem 2.5rem; }
  table.gl-table thead { display: none; }
  table.gl-table, table.gl-table tbody, table.gl-table tr, table.gl-table td { display: block; width: 100%; }
  table.gl-table tr {
    border-bottom: 1px solid var(--border); padding: .75rem .9rem;
  }
  table.gl-table tr:last-child { border-bottom: none; }
  table.gl-table td { border: none; padding: .25rem 0; }
  table.gl-table td[data-align=right] { text-align: left; }
  table.gl-table td::before {
    content: attr(data-label); display: block; font-size: .68rem; font-weight: 650;
    text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin-bottom: .1rem;
  }
}

/* ── Mise en page applicative (menu latéral + contenu) ────────────────── */

.app-shell { display: flex; min-height: 100vh; }

/* Bandeau latéral : toujours visible (icônes + libellés), rétractable en
   rail d'icônes via le bouton « — un seul mécanisme, identique mobile/desktop.
   État mémorisé côté navigateur (localStorage), donc les éléments de connexion
   (utilisateur, engrenage, déconnexion) restent en permanence dans le menu,
   quelle que soit la page. */
.sidebar {
  width: 230px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1.25rem 0;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
  transition: width .15s ease;
}

.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem 1.25rem; border-bottom: 1px solid var(--border); margin-bottom: .75rem; }
.sidebar-brand { font-weight: 700; font-size: 1.05rem; color: var(--text); overflow: hidden; white-space: nowrap; }
.sidebar-brand-short { display: none; }
.sidebar-collapse-btn {
  border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 1rem;
  padding: .2rem .4rem; border-radius: var(--radius-sm); line-height: 1; flex: 0 0 auto;
}
.sidebar-collapse-btn:hover { background: var(--accent-soft); color: var(--accent); }

.sidebar-nav { display: flex; flex-direction: column; gap: .1rem; flex: 1; padding: 0 .6rem; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .75rem; border-radius: var(--radius-sm); color: var(--text-muted);
  text-decoration: none; font-size: .92rem; font-weight: 550; white-space: nowrap;
}
.sidebar-nav a:hover { background: var(--accent-soft); color: var(--accent); }
.sidebar-nav a.active { background: var(--accent-soft); color: var(--accent); }

.nav-icon {
  display: none; flex: 0 0 auto; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  align-items: center; justify-content: center; font-weight: 700; font-size: .78rem;
  background: var(--accent-soft); color: var(--accent); text-transform: uppercase;
}

.sidebar-user {
  border-top: 1px solid var(--border); padding: .9rem 1.25rem 0; margin-top: .75rem;
  display: flex; align-items: center; justify-content: space-between; font-size: .85rem; gap: .5rem;
}
.sidebar-user-name { color: var(--text-muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-actions { display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }
.sidebar-icon-link {
  color: var(--text-muted); text-decoration: none; font-size: 1rem; line-height: 1;
  width: 1.6rem; height: 1.6rem; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}
.sidebar-icon-link:hover { background: var(--accent-soft); color: var(--accent); }

.app-main { flex: 1; min-width: 0; margin-left: 230px; transition: margin-left .15s ease; }
.app-content { max-width: 1040px; margin: 0 auto; padding: 2rem 1.25rem 3rem; }

.breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem;
  font-size: .83rem; color: var(--text-muted); margin-bottom: 1.1rem;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumb-sep { color: var(--text-faint); }
.breadcrumb-current { color: var(--text); font-weight: 600; }

/* Rail d'icônes (menu réduit) : déclenché soit par le bouton «, soit par
   défaut sur petit écran (voir le script inline dans base.html). */
html.sidebar-collapsed-pref .sidebar { width: 64px; }
html.sidebar-collapsed-pref .app-main { margin-left: 64px; }
html.sidebar-collapsed-pref .sidebar-brand-full,
html.sidebar-collapsed-pref .nav-label,
html.sidebar-collapsed-pref .sidebar-user-name { display: none; }
html.sidebar-collapsed-pref .sidebar-brand-short { display: inline; }
html.sidebar-collapsed-pref .sidebar-top { padding: 0 .8rem 1.25rem; justify-content: center; flex-direction: column; gap: .5rem; }
html.sidebar-collapsed-pref .sidebar-collapse-btn { transform: rotate(180deg); }
html.sidebar-collapsed-pref .sidebar-nav a { justify-content: center; padding: .55rem 0; }
html.sidebar-collapsed-pref .nav-icon { display: inline-flex; }
html.sidebar-collapsed-pref .sidebar-user { flex-direction: column; padding: .9rem .5rem 0; gap: .6rem; }

/* ── Fiche : carte resserrée pour les formulaires ─────────────────────── */
.gl-form-card { max-width: 560px; padding: 1.4rem 1.6rem; }

/* ── Connexion ─────────────────────────────────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2rem 2.25rem; width: 100%; max-width: 360px;
}
.login-title { font-size: 1.2rem; font-weight: 650; margin: 0 0 1.25rem; text-align: center; }
.login-error {
  background: color-mix(in srgb, #dc2626 12%, var(--surface) 88%); color: #dc2626;
  border-radius: var(--radius-sm); padding: .6rem .8rem; font-size: .85rem; margin-bottom: 1rem;
}

/* ── Liste de cases à cocher (modules d'un utilisateur) ───────────────── */
.module-checklist {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .75rem .9rem;
}
.module-check {
  display: flex; align-items: center; gap: .45rem; font-size: .88rem; font-weight: 500;
  text-transform: none; letter-spacing: normal; color: var(--text);
}
.module-check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

/* ── Pages bespoke : section de détail, listes clé/valeur, badges ────────── */
.gl-section { padding: 1.1rem 1.3rem; margin-bottom: 1.1rem; }
.gl-section-title { font-size: 1rem; font-weight: 650; color: var(--text); }
.gl-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .85rem; }
.gl-btn-sm { padding: .4rem .8rem; font-size: .82rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.kv dt { font-weight: 600; color: var(--text-muted); font-size: .85rem; }
.kv dd { margin: 0; font-size: .92rem; }

.badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--border); color: var(--text-muted);
}
.badge-positive { background: color-mix(in srgb, #16a34a 15%, var(--surface) 85%); color: #16a34a; }
.badge-negative { background: color-mix(in srgb, #dc2626 15%, var(--surface) 85%); color: #dc2626; }
.badge-warning { background: color-mix(in srgb, #d97706 15%, var(--surface) 85%); color: #d97706; }

dialog.qr-dialog {
  border: none; border-radius: var(--radius-sm); padding: 1.25rem;
  max-width: 22rem; width: 90vw; box-shadow: var(--shadow-hover);
  background: var(--surface); color: var(--text);
}
dialog.qr-dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog.qr-dialog img { display: block; width: 100%; height: auto; }

.gl-doc-links { display: flex; flex-wrap: wrap; gap: .6rem; }
.gl-empty { color: var(--text-faint); font-style: italic; font-size: .9rem; margin: .5rem 0 0; }

.gl-table td a, .gl-table td form { display: inline; }
.gl-table td a { color: var(--accent); text-decoration: none; font-size: .88rem; font-weight: 550; }
.gl-table td a:hover { text-decoration: underline; }

.search-result-list { list-style: none; margin: .75rem 0 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.search-result-list li + li { border-top: 1px solid var(--border); }
.search-result-btn {
  width: 100%; text-align: left; background: var(--surface); border: none; padding: .65rem .85rem;
  cursor: pointer; display: flex; flex-direction: column; gap: .1rem; font: inherit; color: var(--text);
}
.search-result-btn:hover { background: var(--accent-soft); }
.text-muted { color: var(--text-muted); font-size: .82rem; }
