/* ========================================================================== */
/*  BASE CSS — propre, extensible, accessible                                 */
/*  - Tokens (variables de design)                                            */
/*  - Reset raisonnable + normalisation                                       */
/*  - Utilitaires sobres (spacing/visually-hidden/container/...)              */
/*  - Hooks thème sombre via [data-theme="dark"] (optionnel)                  */
/* ========================================================================== */

/* ---------------------------------- */
/* Cascade Layers (prépare la suite)  */
/* ---------------------------------- */
@layer tokens, base, utilities;

/* ============================== */
/*        VARIABLES / TOKENS      */
/* ============================== */

@layer tokens {
  :root {
    /* 🖋️ Texte & surfaces */
    --text-main: #222831;
    --text-muted: #6b7280;
    --surface: #ffffff;
    --surface-contrast: #f5f7fb;

    /* 📐 Espacements (8pt scale) */
    --spacing-2xs: 4px;
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;

    /* 🔠 Typo (fonts) */
    --font-main: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Noto Sans",
      "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
    --font-accent: "Poppins", "Roboto", var(--font-main);

    /* 🔠 Typo — échelle de tailles */
    --font-size-xs: 0.75rem;   /* 12px */
    --font-size-sm: 0.875rem;  /* 14px */
    --font-size-md: 1rem;      /* 16px */
    --font-size-lg: 1.125rem;  /* 18px */
    --font-size-xl: 1.25rem;   /* 20px */
    --font-size-2xl: 1.5rem;   /* 24px */
    --font-size-3xl: 1.875rem; /* 30px */
    --font-size-4xl: 2.25rem;  /* 36px */

    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* 🧱 Rayons / ombres */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.10);
    --shadow-lg: 0 14px 32px rgba(0, 0, 0, 0.16);

    /* 📐 Layout */
    --layout-min-width: 360px; /* mobile-first safe */
    --container-max: 1200px;

    /* 📱 Breakpoints */
    --bp-sm: 480px;
    --bp-md: 768px;
    --bp-lg: 1024px;
    --bp-xl: 1280px;

    /* 🔎 Focus */
    --focus-ring: 2px solid var(--color-primary);
    --focus-offset: 2px;

    /* 🖱️ Sélection */
    --selection-bg: rgba(13, 110, 253, 0.2);
    --selection-fg: inherit;

    /* 🧭 Bordures subtiles */
    --border-subtle: 1px solid rgba(15, 23, 42, 0.08);
    --border-subtle-dark: 1px solid rgba(15, 23, 42, 0.35);

    /* 🧭 Aliases pour ta charte existante (optionnel) */
    --pc-accent: var(--color-primary);
    --pc-shadow: var(--shadow-md);
  }

  /* Thème sombre optionnel : active-le en posant [data-theme="dark"] sur <html> */
  [data-theme="dark"] {
    color-scheme: dark;
    --text-main: #e5e7eb;
    --text-muted: #a1a1aa;
    --surface: #0b0f14;
    --surface-contrast: #0f1720;
    --color-light: #111827;
    --color-dark: #f5f7fb;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 14px 32px rgba(0, 0, 0, 0.7);

    --border-subtle: var(--border-subtle-dark);
  }
}

/* ============================== */
/*           RESET / BASE         */
/* ============================== */

@layer base {
  /* Box-sizing universel + reset marge/padding par défaut */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html,
  body {
    margin: 0;
    padding: 0;
  }

  /* Améliorations d’accessibilité et de rendu texte */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
  }

  /* Respecte les préférences utilisateurs (réduction de mouvement) */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* Sélection de texte */
  ::selection {
    background: var(--selection-bg);
    color: var(--selection-fg);
  }

  /* Structure globale */
  html {
    min-width: var(--layout-min-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  body {
    flex-direction: column;
    flex: 1;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    font-size: var(--font-size-md);
    background-color: var(--surface);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
  }

  main {
    flex: 1;
    display: block;
  }

  /* Images */
  img,
  svg,
  video,
  canvas {
    display: block;
    max-width: 100%;
    height: auto;
  }

  /* Titres : normalise marges verticales + hiérarchie */
  h1, h2, h3, h4, h5, h6 {
    line-height: 1.25;
    margin: 0 0 var(--spacing-md);
    font-family: var(--font-accent);
    font-weight: var(--font-weight-semibold);
  }

  h1 {
    font-size: clamp(1.875rem, 2vw + 1.25rem, var(--font-size-4xl));
    letter-spacing: -0.03em;
  }

  h2 {
    font-size: clamp(1.5rem, 1.5vw + 1rem, var(--font-size-3xl));
    letter-spacing: -0.02em;
  }

  h3 { font-size: var(--font-size-2xl); }
  h4 { font-size: var(--font-size-xl); }
  h5 { font-size: var(--font-size-lg); }

  h6 {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  p {
    margin: 0 0 var(--spacing-md);
    font-size: var(--font-size-md);
  }

  small,
  .text-sm {
    font-size: var(--font-size-sm);
  }

  /* Listes */
  ul,
  ol {
    padding-inline-start: 1.25rem;
    margin: 0 0 var(--spacing-md);
  }

  li { margin-block: 0.25rem; }

  /* Liens */
  a {
    color: var(--color-primary);
    text-decoration: none;
  }
  a:hover { text-decoration: none; }
  
  /* Exception : pas de soulignement sur les cartes de personnages */
  a.person-card:hover,
  a.link-card:hover {
    text-decoration: none;
  }
  
  a:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
    border-radius: 4px;
  }

  /* Formulaires — reset doux */
  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
    background: transparent;
    border: 0;
  }

  button { cursor: pointer; }

  /* Focus accessible */
  :where(a, button, input, select, textarea):focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
  }

  /* Tables : base neutre (stylise via une classe utilitaire si besoin) */
  table { width: 100%; border-collapse: collapse; }
  th, td { padding: 8px 10px; text-align: left; }
}

/* ============================== */
/*            UTILITAIRES         */
/* ============================== */

@layer utilities {
  /* Visually hidden pour accessibilité */
  .visually-hidden,
  .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;
  }

  /* Conteneur max (layout) */
  .container {
    width: 100%;
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--spacing-md);
  }

  .container--wide {
    max-width: 1400px;
  }

  @media (min-width: 1024px) {
    .container {
      padding-inline: var(--spacing-lg);
    }
  }

  /* Piles verticales rapides */
  .stack-xs > * + * { margin-top: var(--spacing-xs); }
  .stack-sm > * + * { margin-top: var(--spacing-sm); }
  .stack-md > * + * { margin-top: var(--spacing-md); }
  .stack-lg > * + * { margin-top: var(--spacing-lg); }
  .stack-xl > * + * { margin-top: var(--spacing-xl); }

  /* Gaps utilitaires (Flex/Grid) */
  .gap-xs { gap: var(--spacing-xs); }
  .gap-sm { gap: var(--spacing-sm); }
  .gap-md { gap: var(--spacing-md); }
  .gap-lg { gap: var(--spacing-lg); }
  .gap-xl { gap: var(--spacing-xl); }

  /* Textes */
  .text-muted { color: var(--text-muted) !important; }

  /* Layout helpers */
  .cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-sm);
  }

  .grid {
    display: grid;
    gap: var(--spacing-md);
  }

  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  @media (max-width: 768px) {
    .grid-2,
    .grid-3,
    .grid-4 {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  /* Cartes */
  .card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: var(--border-subtle);
    padding: var(--spacing-md);
  }

  .card--flush {
    padding: 0;
  }

  .card__header,
  .card__footer {
    padding: var(--spacing-md);
    border-bottom: var(--border-subtle);
  }

  .card__footer {
    border-top: var(--border-subtle);
    border-bottom: none;
  }

  .card__body {
    padding: var(--spacing-md);
  }

  /* Table “propre” opt-in (évite de sur-styliser <table> global) */
  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
  }
  .table th,
  .table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
  }
  .table thead th {
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 600;
    opacity: 0.8;
  }
  .table--zebra tbody tr:nth-child(even) {
    background: var(--surface-contrast);
  }

  /* Badges */
  .badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    background: var(--surface-contrast);
    color: var(--text-muted);
  }

  .badge-primary {
    background: rgba(13, 110, 253, 0.1);
    color: var(--color-primary);
  }

  .badge-success {
    background: rgba(25, 135, 84, 0.12);
    color: var(--color-success);
  }

  .badge-danger {
    background: rgba(220, 53, 69, 0.12);
    color: var(--color-danger);
  }

  /* ========================= */
  /*         BUTTONS           */
  /* ========================= */

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: 1.2;
    text-decoration: none;
    background-color: var(--color-light);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    transition:
      background-color 0.16s ease-out,
      color 0.16s ease-out,
      box-shadow 0.16s ease-out,
      transform 0.08s ease-out;
  }

  .btn:hover {
    text-decoration: none;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
  }

  .btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
  }

  .btn-primary {
    background-color: var(--color-primary);
    color: #fff;
  }

  .btn-primary:hover {
    background-color: var(--color-primary-dark);
  }

  .btn-outline {
    background-color: transparent;
    border-color: rgba(148, 163, 184, 0.6);
    color: var(--text-main);
    box-shadow: none;
  }

  .btn-outline:hover {
    background-color: var(--surface-contrast);
    border-color: rgba(148, 163, 184, 0.9);
  }

  .btn-ghost {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    padding-inline: 0.25rem;
  }

  .btn-ghost:hover {
    background-color: rgba(148, 163, 184, 0.12);
  }

  .btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: var(--font-size-xs);
    border-radius: var(--radius-sm);
  }

  .btn-lg {
    padding: 0.7rem 1.2rem;
    font-size: var(--font-size-md);
  }
}
