/* ==========================================================================
   BizFlow — style.css
   Design tokens, reset, typographie, layout global et header.
   Toutes les couleurs/espacements passent par des variables : le thème
   sombre se contente de redéfinir ces variables.
   ========================================================================== */

/* ---------- 1. Design tokens ----------
   Identité BizFlow « Enseigne, version pro » : l'indigo et le jaune soleil
   des enseignes peintes des boutiques, dans une mise en page sobre.
   Une seule audace (le panneau jaune de la caisse du jour) ; ailleurs, la
   couleur porte un sens : bissap = alerte ou reste dû, menthe = positif.
   Contrastes vérifiés : texte ≥ 4,5:1, contours et icônes ≥ 3:1 (WCAG 2.1 AA). */
:root {
  /* Typographie : Atkinson Hyperlegible (texte, très lisible) et
     Bricolage Grotesque (titres et grands chiffres, façon lettre peinte) */
  --font-sans: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Bricolage Grotesque', 'Atkinson Hyperlegible', -apple-system, 'Segoe UI', sans-serif;
  --fs-xs: 0.75rem;     /* 12px */
  --fs-sm: 0.8125rem;   /* 13px */
  --fs-base: 0.875rem;  /* 14px */
  --fs-md: 1rem;        /* 16px */
  --fs-lg: 1.125rem;    /* 18px */
  --fs-xl: 1.5rem;      /* 24px */
  --fs-2xl: 1.75rem;    /* 28px */
  --fs-display: 2.75rem; /* 44px — montant de la caisse du jour */

  /* Surfaces : blanc légèrement bleuté */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafd;
  --surface-hover: #f0f2f9;
  --surface-active: #e6e9f5;

  /* Bordures (décoratives) — les champs utilisent --border-input */
  --border: #e2e5f1;
  --border-strong: #cfd4e8;
  --border-input: #7d84a6;

  /* Texte — encre indigo */
  --text: #141a3a;
  --text-2: #454d77;
  --text-3: #5d6488;
  --text-inverse: #ffffff;

  /* Marque — indigo des enseignes */
  --primary: #1e2a78;
  --primary-hover: #151f5c;
  --primary-soft: #e8ebfa;
  --primary-text: #1e2a78;
  --primary-solid: #1e2a78;
  --primary-solid-hover: #151f5c;

  /* Jaune soleil : le panneau « Ventes du jour », seul aplat vif de la page */
  --sun: #ffc21a;
  --sun-deep: #e6ae14;
  --sun-ink: #1e2a78;
  --bissap: #c2185b;

  /* Menu latéral indigo */
  --nav-bg: #1e2a78;
  --nav-hover: #26338a;
  --nav-active: #2c3990;
  --nav-text: #d6dbf5;
  --nav-text-strong: #ffffff;
  --nav-line: #36439a;

  /* États : couleur vive (icônes, graphiques) + variante texte sur fond pâle */
  --success: #0c7a50;
  --success-soft: #e3f4ec;
  --success-text: #0a6a45;
  --warning: #c7860a;          /* safran : stock faible */
  --warning-soft: #fbf1dc;
  --warning-text: #8a5700;
  --danger: #b0164f;           /* bissap : rupture, reste dû, baisse */
  --danger-soft: #fde7ee;
  --danger-text: #9c1245;
  --info: #3f4fb0;
  --info-soft: #eceefb;
  --info-text: #2f3c96;

  /* Données (catégories : alimentation 1, électroménager 2, entretien 3, boissons 4, hygiène 5) */
  --chart-1: #1e2a78;          /* indigo */
  --chart-2: #9aa3e6;          /* lavande */
  --chart-3: #0c7a50;          /* menthe */
  --chart-4: #e3a90c;          /* jaune soleil foncé */
  --chart-5: #b0164f;          /* bissap */
  --series-profit: #0c7a50;

  /* Rayons hiérarchisés : panneaux 12, contrôles 8, petits éléments 6 */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  /* Ombres : réservées à ce qui flotte (menus, toasts) */
  --shadow-xs: 0 1px 1px rgba(15, 42, 32, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 42, 32, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 42, 32, 0.08), 0 2px 4px -2px rgba(15, 42, 32, 0.04);
  --shadow-lg: 0 16px 40px -8px rgba(15, 42, 32, 0.18), 0 4px 12px -4px rgba(15, 42, 32, 0.08);
  /* Anneau de focus plein et contrasté (WCAG 2.4.7) */
  --ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);

  /* Espacements */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Layout */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --header-h: 64px;
  --content-max: 1440px;
  --page-pad: 32px;

  /* Animations */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d1030;
  --surface: #151a3d;
  --surface-2: #1a1f47;
  --surface-hover: #20265a;
  --surface-active: #272e68;

  --border: #262c5c;
  --border-strong: #353c75;
  --border-input: #7178ad;

  --text: #eef0fb;
  --text-2: #b9bee2;
  --text-3: #9aa0cc;

  --primary: #aeb6f5;
  --primary-hover: #c6ccf8;
  --primary-soft: rgba(174, 182, 245, 0.14);
  --primary-text: #c2c9f8;
  --primary-solid: #3a49b8;
  --primary-solid-hover: #4757c8;

  --nav-bg: #11163a;
  --nav-hover: #1b2150;
  --nav-active: #232a62;
  --nav-line: #262c5c;

  --success: #3fbf8f;
  --success-soft: rgba(63, 191, 143, 0.14);
  --success-text: #6fd4ad;
  --warning: #e9ad3a;
  --warning-soft: rgba(233, 173, 58, 0.13);
  --warning-text: #ecb54d;
  --danger: #ff7aa8;
  --danger-soft: rgba(255, 122, 168, 0.13);
  --danger-text: #ff8db4;
  --info: #9aa5f0;
  --info-soft: rgba(154, 165, 240, 0.14);
  --info-text: #b0b8f4;

  --chart-1: #8c98ea;
  --chart-2: #c9cff7;
  --chart-3: #3fbf8f;
  --chart-4: #f0b429;
  --chart-5: #ff6f9f;
  --series-profit: #3fbf8f;

  --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 48px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);

  color-scheme: dark;
}

/* ---------- 2. Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

img,
svg,
canvas {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  width: 100%;
}

[hidden] {
  display: none !important;
}

/* Focus clavier : anneau visible ; le contour transparent reste visible en mode Contraste élevé */
:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--ring);
}

/* Les titres reçoivent le focus au changement de page : pas d'anneau sur eux */
[tabindex="-1"]:focus {
  outline: none;
  box-shadow: none;
}

::selection {
  background: var(--primary-soft);
  color: var(--primary-text);
}

/* Icônes Lucide : taille par défaut cohérente */
.lucide {
  width: 18px;
  height: 18px;
  stroke-width: 1.85;
  flex-shrink: 0;
}

/* Utilitaires */
.text-right { text-align: right; }

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

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 1000;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-solid);
  color: var(--text-inverse);
  font-weight: 500;
  transition: top var(--dur) var(--ease);
}

.skip-link:focus {
  top: 12px;
}

/* ---------- 3. Layout ---------- */
.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.main-wrapper {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--dur-slow) var(--ease-out);
}

.sidebar-collapsed .main-wrapper {
  margin-left: var(--sidebar-w-collapsed);
}

.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-8) var(--page-pad) 48px;
  outline: none;
}

.view {
  animation: view-in var(--dur-slow) var(--ease-out);
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* En-tête de page */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-head__title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.page-head__subtitle {
  margin-top: 6px;
  color: var(--text-3);
  font-size: var(--fs-base);
}

.page-head__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ---------- 4. Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--header-h);
  padding: 0 var(--page-pad);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header__left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.icon-btn.header__menu {
  display: none;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: var(--fs-base);
  white-space: nowrap;
}

.breadcrumb__root {
  color: var(--text-3);
}

.breadcrumb__sep {
  width: 14px;
  height: 14px;
  color: var(--text-3);
}

.breadcrumb__current {
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Recherche */
.header__search {
  position: relative;
  width: 100%;
  max-width: 400px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 38px;
  padding: 0 10px 0 12px;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  color: var(--text-3);
  box-shadow: var(--shadow-xs);
  cursor: text;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.search-field:hover {
  border-color: var(--text-3);
}

/* L'anneau est porté par le champ entier, pas par l'input */
.search-field input:focus-visible {
  box-shadow: none;
}

.search-field:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.search-field .lucide {
  width: 16px;
  height: 16px;
}

.search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-base);
}

.search-field input::placeholder {
  color: var(--text-3);
}

.search-field input::-webkit-search-cancel-button {
  display: none;
}

.search-field__kbd {
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.icon-btn.header__search-toggle {
  display: none;
}

.header__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  flex: 1;
}

.header__divider {
  width: 1px;
  height: 24px;
  margin: 0 var(--space-2);
  background: var(--border);
}

/* Bascule d'icône du thème */
.theme-icon--sun { display: none; }
[data-theme="dark"] .theme-icon--sun { display: block; }
[data-theme="dark"] .theme-icon--moon { display: none; }

/* Profil */
.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease);
}

.profile:hover,
.profile[aria-expanded="true"] {
  background: var(--surface-hover);
}

.profile__info {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.profile__name {
  font-size: var(--fs-sm);
  font-weight: 600;
}

.profile__role {
  font-size: var(--fs-xs);
  color: var(--text-3);
}

.profile__chevron {
  width: 16px;
  height: 16px;
  color: var(--text-3);
  transition: transform var(--dur) var(--ease);
}

.profile[aria-expanded="true"] .profile__chevron {
  transform: rotate(180deg);
}

/* Accessibilité : respect des préférences de mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Compte employé : ce qui est réservé à l'administrateur disparaît */
[data-role="employee"] [data-admin-only] {
  display: none !important;
}

/* Indicateur de synchronisation (en-tête, appareil relié seulement) */
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
}

.sync-pill[hidden] { display: none; }
.sync-pill .lucide { width: 16px; height: 16px; }
.sync-pill.is-ok { background: var(--success-soft); color: var(--success-text); }
.sync-pill.is-busy { background: var(--info-soft); color: var(--info-text); }
.sync-pill.is-offline { background: var(--warning-soft); color: var(--warning-text); }
.sync-pill.is-error { background: var(--danger-soft); color: var(--danger-text); }

@media (max-width: 640px) {
  /* Sur téléphone : l'icône seule, le texte reste lu par les lecteurs d'écran */
  .sync-pill { padding: 0 8px; }
  .sync-pill span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
