/**
 * TXL GEN4 — Base CSS
 * Reset moderne + styles de base utilisant les tokens txl-design-system
 * Remplace : design-system/reset.css + base-custom.css partiel
 */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }

  * {
    margin: 0;
    padding: 0;
  }

  html {
    color-scheme: light dark;
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
    scroll-behavior: smooth;
  }

  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
  }

  body {
    font-family: var(--txl-font);
    font-size: var(--txl-text-base);
    line-height: var(--txl-line-normal);
    color: var(--txl-text);
    background-color: var(--txl-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--txl-duration) var(--txl-ease),
                color var(--txl-duration) var(--txl-ease);
  }

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

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

  h1, h2, h3, h4, h5, h6 {
    font-weight: var(--txl-weight-semibold);
    line-height: var(--txl-line-tight);
    color: var(--txl-text);
  }

  a {
    color: var(--txl-primary);
    text-decoration: none;
    transition: color var(--txl-duration-fast) var(--txl-ease);
  }

  a:hover { color: var(--txl-primary-700); }

  ul, ol { list-style: none; }

  table { border-collapse: collapse; }

  /* Accessibilité — sr-only */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
}

@layer base {

  /* =============================================
     FOCUS VISIBLE — WCAG AA
     ============================================= */

  :focus-visible {
    outline: 2px solid var(--txl-primary);
    outline-offset: var(--txl-focus-ring-offset, 2px);
    border-radius: var(--txl-radius-sm);
  }

  /* Supprimer outline par défaut uniquement si focus-visible disponible */
  :focus:not(:focus-visible) { outline: none; }

  /* =============================================
     SKIP TO CONTENT — WCAG 2.4.1
     ============================================= */

  .skip-to-content {
    position: absolute;
    top: -9999px;
    left: var(--txl-space-4);
    z-index: calc(var(--txl-z-notification) + 1);
    padding: var(--txl-space-3) var(--txl-space-6);
    background: var(--txl-primary);
    color: var(--txl-text-on-primary);
    font-weight: var(--txl-weight-semibold);
    border-radius: var(--txl-radius);
    text-decoration: none;
    transition: top var(--txl-duration-fast) var(--txl-ease);
  }

  .skip-to-content:focus {
    top: var(--txl-space-4);
  }

  /* =============================================
     LAYOUT DE BASE
     ============================================= */

  .txl-page-wrapper {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .txl-main {
    flex: 1;
    padding-top: var(--txl-navbar-height, 4.375rem);
  }

  .txl-container {
    width: 100%;
    max-width: 1280px;
    margin-inline: auto;
    padding-inline: var(--txl-space-4);
  }

  @media (min-width: 640px) {
    .txl-container { padding-inline: var(--txl-space-6); }
  }

  @media (min-width: 1024px) {
    .txl-container { padding-inline: var(--txl-space-8); }
  }

  /* =============================================
     MESSAGES DJANGO
     ============================================= */

  .txl-messages {
    position: fixed;
    top: calc(var(--txl-navbar-height, 4.375rem) + var(--txl-space-3));
    right: var(--txl-space-5);
    z-index: var(--txl-z-notification);
    max-width: min(400px, calc(100vw - var(--txl-space-8)));
    display: flex;
    flex-direction: column;
    gap: var(--txl-space-3);
  }

  .txl-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--txl-space-3);
    padding: var(--txl-space-4) var(--txl-space-4);
    background: var(--txl-surface);
    border-radius: var(--txl-radius-md);
    box-shadow: var(--txl-shadow-md);
    border-left: 4px solid var(--txl-primary);
    animation: slideInRight 0.3s var(--txl-ease-out) both;
  }

  .txl-alert--success { border-color: var(--txl-success); }
  .txl-alert--warning { border-color: var(--txl-warning); }
  .txl-alert--error   { border-color: var(--txl-danger); }
  .txl-alert--info    { border-color: var(--txl-info); }

  .txl-alert__close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--txl-text-muted);
    padding: var(--txl-space-1);
    border-radius: var(--txl-radius-sm);
    transition: color var(--txl-duration-fast) var(--txl-ease);
  }

  .txl-alert__close:hover { color: var(--txl-text); }

  /* =============================================
     HTMX INDICATOR
     ============================================= */

  .htmx-indicator {
    opacity: 0;
    transition: opacity 200ms var(--txl-ease);
  }

  .htmx-request .htmx-indicator,
  .htmx-request.htmx-indicator {
    opacity: 1;
  }

  /* =============================================
     DARK MODE TOGGLE
     ============================================= */

  .txl-theme-toggle {
    background: none;
    border: 1px solid var(--txl-border);
    border-radius: var(--txl-radius-full);
    padding: var(--txl-space-2) var(--txl-space-3);
    cursor: pointer;
    color: var(--txl-text-secondary);
    display: flex;
    align-items: center;
    gap: var(--txl-space-2);
    transition: all var(--txl-duration-fast) var(--txl-ease);
    font-size: var(--txl-text-sm);
  }

  .txl-theme-toggle:hover {
    border-color: var(--txl-primary);
    color: var(--txl-primary);
  }

  .txl-theme-toggle .icon-sun  { display: none; }
  .txl-theme-toggle .icon-moon { display: block; }

  [data-theme="dark"] .txl-theme-toggle .icon-sun  { display: block; }
  [data-theme="dark"] .txl-theme-toggle .icon-moon { display: none; }

  /* =============================================
     CONTENT-VISIBILITY POUR SECTIONS HORS VIEWPORT
     ============================================= */

  .txl-cv-auto {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
  }

  /* =============================================
     PREFERS-REDUCED-MOTION GLOBAL
     ============================================= */

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