/* Fablabs Manager — feuille source Tailwind. Compiler : make css  (outils/tailwind/construire.sh) */
@import "./theme.css";

@tailwind base;
@tailwind components;
@tailwind utilities;

/* ------------------------------------------------------------------ base */
@layer base {
  html { font-family: theme("fontFamily.sans"); -webkit-text-size-adjust: 100%; font-feature-settings: "cv11", "ss01"; }
  body { @apply bg-gray-50 text-gray-900 antialiased dark:bg-gray-950 dark:text-gray-100; font-size: .875rem; line-height: 1.5; }
  /* Sélecteurs d'élément simples (priorité 0,0,1) déclarés après le préflight : ils remplacent ses valeurs,
     et toute classe utilitaire ou de composant (0,1,0) l'emporte, y compris en thème sombre. */
  h1 { @apply text-xl font-semibold tracking-tight sm:text-2xl; color: theme("colors.gray.900"); }
  h2 { @apply text-base font-semibold; color: theme("colors.gray.900"); }
  h3 { @apply text-sm font-semibold; color: theme("colors.gray.900"); }
  :where(.dark) h1, :where(.dark) h2, :where(.dark) h3 { color: #fff; }
  a { color: rgb(var(--fm-primary-700)); text-decoration: none; }
  a:where(:hover) { color: rgb(var(--fm-primary-800)); }
  :where(.dark) a { color: rgb(var(--fm-primary-400)); }
  :where(.dark) a:where(:hover) { color: rgb(var(--fm-primary-300)); }
  :focus-visible { @apply outline-none ring-2 ring-primary-500 ring-offset-2 ring-offset-white dark:ring-offset-gray-900; border-radius: .375rem; }
  [x-cloak], [hidden] { display: none !important; }
  .grid > *, fieldset { min-width: 0; }

  /* Champs : tous les widgets Django prennent ce style sans classe dédiée */
  input:where(:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=hidden]):not([type=range]):not([type=submit]):not([type=button])),
  select, textarea {
    @apply block w-full rounded-lg border-0 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400
           focus:ring-2 focus:ring-inset focus:ring-primary-500 disabled:cursor-not-allowed disabled:bg-gray-50 disabled:text-gray-500
           dark:bg-gray-900 dark:text-gray-100 dark:ring-gray-700 dark:placeholder:text-gray-500;
    min-height: 2.25rem;
  }
  select { @apply pr-8; }
  select[multiple] { min-height: 7rem; }
  textarea { min-height: 5rem; }
  input[type=checkbox], input[type=radio] {
    @apply h-4 w-4 border-gray-300 text-primary-700 accent-primary-700 focus:ring-primary-500 dark:border-gray-600;
  }
  input[type=file] {
    @apply block w-full text-sm text-gray-600 file:mr-3 file:cursor-pointer file:rounded-lg file:border-0 file:bg-primary-50 file:px-3 file:py-2
           file:text-sm file:font-medium file:text-primary-800 hover:file:bg-primary-100 dark:text-gray-300 dark:file:bg-primary-500/15 dark:file:text-primary-300;
  }
  [aria-invalid=true] { @apply ring-danger-500 dark:ring-danger-400; }
  table { @apply w-full; }
  svg.i { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
}

/* ------------------------------------------------------------ composants */
@layer components {
  /* Boutons */
  .btn { @apply inline-flex h-9 shrink-0 cursor-pointer select-none items-center justify-center gap-2 whitespace-nowrap rounded-lg px-3.5 text-sm font-medium
         transition-colors disabled:pointer-events-none disabled:opacity-50; text-decoration: none; }
  .btn svg { @apply h-4 w-4; }
  .btn-primary { @apply bg-primary-700 text-white shadow-sm hover:bg-primary-800 hover:text-white dark:bg-primary-600 dark:hover:bg-primary-500; }
  .btn-secondary, .btn-outline { @apply bg-white text-gray-800 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 hover:text-gray-900
         dark:bg-gray-900 dark:text-gray-100 dark:ring-gray-700 dark:hover:bg-gray-800 dark:hover:text-white; }
  .btn-ghost { @apply text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-300 dark:hover:bg-gray-800 dark:hover:text-white; }
  .btn-dark { @apply bg-gray-900 text-white shadow-sm hover:bg-gray-800 hover:text-white dark:bg-white dark:text-gray-900 dark:hover:bg-gray-200; }
  .btn-danger { @apply bg-danger-600 text-white shadow-sm hover:bg-danger-700 hover:text-white; }
  .btn-success { @apply bg-success-600 text-white shadow-sm hover:bg-success-700 hover:text-white; }
  .btn-sm { @apply h-8 px-2.5 text-xs; }
  .btn-lg { @apply h-11 px-5 text-base; }
  .btn-icon { @apply inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900
              dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-white; }
  .btn-icon svg { @apply h-5 w-5; }
  .link-button { @apply cursor-pointer border-0 bg-transparent p-0 text-left font-medium text-gray-900 hover:text-primary-700 dark:text-gray-100 dark:hover:text-primary-400; font: inherit; }

  /* Cartes */
  .card { @apply rounded-xl bg-white shadow-card ring-1 ring-gray-200/80 dark:bg-gray-900 dark:ring-gray-800; }
  .card-header { @apply flex flex-wrap items-center justify-between gap-3 border-b border-gray-100 px-5 py-3.5 dark:border-gray-800; }
  .card-header h2, .card-header h3 { @apply text-sm font-semibold; }
  .card-body { @apply p-5; }
  .card-footer { @apply flex flex-wrap items-center justify-end gap-2 rounded-b-xl border-t border-gray-100 bg-gray-50/60 px-5 py-3 dark:border-gray-800 dark:bg-gray-900/60; }

  /* Badges : ton porté par une classe tone-* */
  .badge { @apply inline-flex items-center gap-1 whitespace-nowrap rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset; }
  .badge::before { content: ""; @apply h-1.5 w-1.5 rounded-full bg-current opacity-70; }
  .badge.no-dot::before { display: none; }
  .tone-neutral { @apply bg-gray-100 text-gray-700 ring-gray-500/20 dark:bg-gray-800 dark:text-gray-300 dark:ring-gray-400/20; }
  .tone-success { @apply bg-success-50 text-success-700 ring-success-600/20 dark:bg-success-500/10 dark:text-success-400 dark:ring-success-400/25; }
  .tone-warning { @apply bg-warning-50 text-warning-700 ring-warning-600/25 dark:bg-warning-500/10 dark:text-warning-400 dark:ring-warning-400/25; }
  .tone-danger  { @apply bg-danger-50 text-danger-700 ring-danger-600/20 dark:bg-danger-500/10 dark:text-danger-400 dark:ring-danger-400/25; }
  .tone-info    { @apply bg-info-50 text-info-700 ring-info-600/20 dark:bg-info-500/10 dark:text-info-400 dark:ring-info-400/25; }
  .tone-primary { @apply bg-primary-50 text-primary-800 ring-primary-600/20 dark:bg-primary-500/10 dark:text-primary-300 dark:ring-primary-400/25; }

  /* Alertes */
  .alert { @apply flex items-start gap-3 rounded-lg px-4 py-3 text-sm ring-1 ring-inset; }
  .alert svg { @apply mt-0.5 h-4 w-4 shrink-0; }

  /* Champs de formulaire */
  .form-grid { @apply grid grid-cols-1 gap-x-4 gap-y-5 sm:grid-cols-2; }
  .form-grid .full { @apply sm:col-span-2; }
  .field { @apply flex min-w-0 flex-col gap-1.5; }
  .field > label { @apply text-sm font-medium text-gray-800 dark:text-gray-200; }
  .field .helptext, .field-help { @apply text-xs text-gray-500 dark:text-gray-400; }
  .field .errorlist, .field-error { @apply m-0 list-none p-0 text-xs font-medium text-danger-600 dark:text-danger-400; }
  .field-check { @apply flex items-start gap-2.5; }
  .field-check > label { @apply text-sm text-gray-800 dark:text-gray-200; }
  .required-mark { @apply text-danger-600 dark:text-danger-400; }

  /* Infobulles d'explication (<c-info>) : position fixe calculée en JS pour échapper aux conteneurs défilants */
  .field-label { @apply flex items-center gap-1; }
  .field-label > label { @apply text-sm font-medium text-gray-800 dark:text-gray-200; }
  .infobulle { @apply relative z-10 inline-flex align-middle; }
  .infobulle-btn { @apply inline-flex h-6 w-6 items-center justify-center rounded-full text-gray-400 transition-colors hover:text-primary-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 dark:text-gray-500 dark:hover:text-primary-400; }
  .infobulle-texte { @apply pointer-events-none invisible fixed left-0 top-0 z-[90] w-max max-w-[18rem] rounded-lg bg-gray-900 px-3 py-2 text-left text-xs font-normal normal-case leading-relaxed tracking-normal text-white opacity-0 shadow-pop transition-opacity duration-150 dark:bg-gray-100 dark:text-gray-900; }
  .infobulle[data-open] { @apply z-[95]; }
  .infobulle[data-open] .infobulle-texte { @apply visible opacity-100; }
  fieldset.form-section { @apply border-0 p-0; }
  fieldset.form-section + fieldset.form-section { @apply mt-8 border-t border-gray-100 pt-8 dark:border-gray-800; }
  fieldset.form-section > legend { @apply mb-1 text-sm font-semibold text-gray-900 dark:text-white; }
  .form-actions { @apply mt-6 flex flex-wrap items-center gap-2; }

  /* Tableaux de données */
  .table-wrap { @apply relative overflow-x-auto; }
  .data-table { @apply min-w-full text-sm; }
  .data-table thead th { @apply whitespace-nowrap border-b border-gray-200 bg-gray-50/80 px-4 py-2.5 text-left text-xs font-medium uppercase tracking-wide text-gray-500
                         dark:border-gray-800 dark:bg-gray-900/80 dark:text-gray-400; }
  .data-table tbody td { @apply border-b border-gray-100 px-4 py-3 align-middle text-gray-700 dark:border-gray-800 dark:text-gray-300; }
  .data-table tbody tr:last-child td { @apply border-b-0; }
  .data-table tbody tr { @apply transition-colors hover:bg-gray-50/80 dark:hover:bg-gray-800/40; }
  .data-table .num, .num { @apply text-right tabular-nums; }
  .row-title { @apply font-medium text-gray-900 dark:text-gray-100; }
  a.row-title { @apply hover:text-primary-700 dark:hover:text-primary-400; }
  .row-sub { @apply mt-0.5 text-xs text-gray-500 dark:text-gray-400; }

  /* Listes clé / valeur */
  .kv { @apply grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[10rem_1fr]; }
  .kv dt { @apply text-xs font-medium uppercase tracking-wide text-gray-500 sm:pt-0.5 dark:text-gray-400; }
  .kv dd { @apply m-0 text-sm text-gray-900 dark:text-gray-100; }

  /* Statistiques */
  .stat { @apply relative overflow-hidden rounded-xl bg-white p-5 shadow-card ring-1 ring-gray-200/80 dark:bg-gray-900 dark:ring-gray-800; }
  .stat-label { @apply text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400; }
  .stat-value { @apply mt-1.5 text-2xl font-semibold tabular-nums tracking-tight text-gray-900 dark:text-white; }
  .stat-hint { @apply mt-1 text-xs text-gray-500 dark:text-gray-400; }
  .stat-icon { @apply flex h-10 w-10 shrink-0 items-center justify-center rounded-lg; }
  .stat-icon svg { @apply h-5 w-5; }

  /* Barre de progression */
  .progress { @apply h-2 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-gray-800; }
  .progress > span { @apply block h-full rounded-full bg-primary-500 transition-all; }

  /* États vides */
  .empty-state { @apply flex flex-col items-center justify-center px-6 py-12 text-center; }
  .empty-state-icon { @apply mb-3 flex h-12 w-12 items-center justify-center rounded-xl bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-500; }
  .empty-state-icon svg { @apply h-6 w-6; }

  /* Onglets */
  .tabs { @apply -mb-px flex gap-1 overflow-x-auto border-b border-gray-200 dark:border-gray-800; }
  .tab { @apply whitespace-nowrap border-b-2 border-transparent px-3 py-2.5 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-800
         dark:text-gray-400 dark:hover:text-gray-200; text-decoration: none; }
  .tab[aria-selected=true], .tab.active { @apply border-primary-600 text-primary-700 dark:border-primary-400 dark:text-primary-300; }

  /* Navigation latérale */
  .nav-link { @apply flex items-center gap-3 rounded-lg px-2.5 py-2 text-sm font-medium text-gray-400 transition-colors hover:bg-white/5 hover:text-white; text-decoration: none; }
  .nav-link svg { @apply h-[18px] w-[18px] shrink-0 opacity-80; }
  .nav-link[aria-current=page] { @apply bg-white/10 text-white; }
  .nav-link[aria-current=page] svg { @apply text-primary-400 opacity-100; }
  .nav-title { @apply px-2.5 pb-1 pt-5 text-[11px] font-semibold uppercase tracking-wider text-gray-500; }

  /* Divers */
  .muted { @apply text-gray-500 dark:text-gray-400; }
  .mono { @apply font-mono text-[0.8125rem]; }
  .avatar { @apply inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary-100 text-xs font-semibold text-primary-800 dark:bg-primary-500/20 dark:text-primary-200; }
  .kbd { @apply rounded border border-gray-300 bg-gray-50 px-1.5 font-mono text-[10px] text-gray-500 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400; }
  .divider { @apply border-t border-gray-100 dark:border-gray-800; }
  .timeline { @apply relative space-y-4 border-l border-gray-200 pl-5 dark:border-gray-800; }
  .timeline > li { @apply relative list-none; }
  .timeline > li::before { content: ""; @apply absolute -left-[25px] top-1.5 h-2.5 w-2.5 rounded-full bg-gray-300 ring-4 ring-white dark:bg-gray-600 dark:ring-gray-900; }
  .timeline > li.is-current::before { @apply bg-primary-500; }
}

/* -------------------------------------------------------------- utilitaires */
@layer utilities {
  .scrollbar-thin { scrollbar-width: thin; scrollbar-color: rgb(63 63 70) transparent; }
}

/* Barre de chargement HTMX : fine, aux couleurs du thème */
#fm-progress { position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 60; pointer-events: none; opacity: 0; transition: opacity .2s; }
#fm-progress > span { display: block; height: 100%; width: 0; background: rgb(var(--fm-primary-500)); transition: width .4s ease; }
#fm-progress.is-active { opacity: 1; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }

/* Toasts */
.toast { animation: fm-in .18s ease-out both; }

/* Tom Select harmonisé */
.ts-wrapper .ts-control { @apply rounded-lg border-0 bg-white px-3 py-1.5 text-sm shadow-sm ring-1 ring-inset ring-gray-300 dark:bg-gray-900 dark:text-gray-100 dark:ring-gray-700; min-height: 2.25rem; }
.ts-wrapper.focus .ts-control { @apply ring-2 ring-primary-500; box-shadow: none; }
.ts-dropdown { @apply rounded-lg border-0 bg-white text-sm shadow-pop ring-1 ring-gray-200 dark:bg-gray-900 dark:text-gray-100 dark:ring-gray-700; }
.ts-dropdown .active { @apply bg-primary-50 text-primary-900 dark:bg-primary-500/15 dark:text-primary-100; }
.ts-control input { @apply dark:text-gray-100; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
  #fm-sidebar, #fm-topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card, .stat { box-shadow: none; }
}
