@import "tailwindcss";
@import "tw-animate-css";

@custom-variant dark (&:is(.dark *));

@font-face {
  font-family: "Marianne";
  src: url("https://cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11.2/dist/fonts/Marianne-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Marianne";
  src: url("https://cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11.2/dist/fonts/Marianne-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Marianne";
  src: url("https://cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11.2/dist/fonts/Marianne-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@theme inline {
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
}

:root {
  /* DSFR - Bleu France (#000091) */
  --primary: oklch(0.25 0.12 265);
  --primary-foreground: oklch(0.99 0 0);
  --sidebar-primary: oklch(0.25 0.12 265);
  --sidebar-primary-foreground: oklch(0.99 0 0);
  --chart-1: oklch(0.25 0.12 265);
  --chart-2: oklch(0.55 0.15 160);
  --chart-3: oklch(0.85 0.15 85);
  --chart-4: oklch(0.55 0.22 25);
  --chart-5: oklch(0.65 0.12 265);
  --radius: 0.25rem;
  --background: oklch(0.99 0 0);
  --foreground: oklch(0.15 0.02 260);
  --card: oklch(0.99 0 0);
  --card-foreground: oklch(0.15 0.02 260);
  --popover: oklch(0.99 0 0);
  --popover-foreground: oklch(0.15 0.02 260);
  --secondary: oklch(0.95 0.02 265);
  --secondary-foreground: oklch(0.25 0.12 265);
  --muted: oklch(0.96 0.01 265);
  --muted-foreground: oklch(0.45 0.02 260);
  --accent: oklch(0.92 0.03 265);
  --accent-foreground: oklch(0.25 0.12 265);
  --destructive: oklch(0.55 0.22 25);
  --destructive-foreground: oklch(0.99 0 0);
  --border: oklch(0.88 0.01 265);
  --input: oklch(0.88 0.01 265);
  --ring: oklch(0.25 0.12 265);
  --sidebar: oklch(0.97 0.01 265);
  --sidebar-foreground: oklch(0.15 0.02 260);
  --sidebar-accent: oklch(0.92 0.03 265);
  --sidebar-accent-foreground: oklch(0.25 0.12 265);
  --sidebar-border: oklch(0.88 0.01 265);
  --sidebar-ring: oklch(0.25 0.12 265);
  
  /* Success - Vert Emeraude */
  --success: oklch(0.55 0.15 160);
  --success-foreground: oklch(0.99 0 0);
  
  /* Warning - Jaune Tournesol */
  --warning: oklch(0.85 0.15 85);
  --warning-foreground: oklch(0.15 0.02 260);
  
  /* Font */
  --font-sans: "Marianne", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --portal-font-body: var(--font-sans);
  --portal-font-heading: var(--font-sans);
  --portal-body-scale: 1;
  --portal-heading-scale: 1;
  --portal-secondary: #1565c0;
  --portal-secondary-soft: #dbeafe;
  --portal-primary-soft: #e5f4e8;
  --portal-alert-soft: #fee2e2;
  --portal-button: #1565c0;
  --portal-button-foreground: #ffffff;
  --portal-button-hover: #0f4bb6;
  --portal-table-stripe: rgba(21, 101, 192, 0.08);
  --portal-card-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --portal-card-hover-shadow: 0 18px 38px rgba(15, 23, 42, 0.12);
  --portal-panel-shadow: 0 16px 40px rgba(15, 23, 42, 0.09);
  --portal-panel-hover-shadow: 0 22px 52px rgba(15, 23, 42, 0.12);
  --portal-card-radius: 0.8rem;
  --portal-button-radius: 0.7rem;
  --portal-input-radius: 0.7rem;
  --portal-motion-fast: 160ms;
  --portal-motion-base: 220ms;
  --portal-background-image: none;
  --portal-background-overlay: rgba(247, 250, 252, 0.72);
  --portal-background-size: cover;
  --portal-background-repeat: no-repeat;
  --portal-background-attachment: scroll;
  --portal-background-position: center;
  --portal-background-blur: 0px;
  --portal-background-presentation-mode: full;
  --portal-background-center-overlay: rgba(255, 255, 255, 0.12);
  --portal-background-edge-strength: 0.22;
  --portal-section-tint: rgba(21, 101, 192, 0.07);
  --portal-background-frame-border: rgba(148, 163, 184, 0.22);
  --portal-background-shell-shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
}

.dark {
  --primary: var(--color-blue-700);
  --primary-foreground: var(--color-blue-50);
  --sidebar-primary: var(--color-blue-500);
  --sidebar-primary-foreground: var(--color-blue-50);
  --background: oklch(0.141 0.005 285.823);
  --foreground: oklch(0.85 0.005 65);
  --card: oklch(0.21 0.006 285.885);
  --card-foreground: oklch(0.85 0.005 65);
  --popover: oklch(0.21 0.006 285.885);
  --popover-foreground: oklch(0.85 0.005 65);
  --secondary: oklch(0.24 0.006 286.033);
  --secondary-foreground: oklch(0.7 0.005 65);
  --muted: oklch(0.274 0.006 286.033);
  --muted-foreground: oklch(0.705 0.015 286.067);
  --accent: oklch(0.274 0.006 286.033);
  --accent-foreground:  oklch(0.92 0.005 65);
  --destructive: oklch(0.704 0.191 22.216);
  --destructive-foreground: oklch(0.985 0 0);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.488 0.243 264.376);
  --chart-1: var(--color-blue-300);
  --chart-2: var(--color-blue-500);
  --chart-3: var(--color-blue-600);
  --chart-4: var(--color-blue-700);
  --chart-5: var(--color-blue-800);
  --sidebar: oklch(0.21 0.006 285.885);
  --sidebar-foreground: oklch(0.85 0.005 65);
  --sidebar-accent: oklch(0.274 0.006 286.033);
  --sidebar-accent-foreground:  oklch(0.985 0 0);
  --sidebar-border: oklch(1 0 0 / 10%);
  --sidebar-ring: oklch(0.488 0.243 264.376);
}

@layer base {
  html {
    font-size: calc(16px * var(--portal-body-scale));
  }

  * {
    @apply border-border outline-ring/50;
  }

  body {
    @apply bg-background text-foreground;
    font-family: var(--portal-font-body);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
    background-image:
      linear-gradient(var(--portal-background-overlay), var(--portal-background-overlay)),
      var(--portal-background-image);
    background-attachment: var(--portal-background-attachment);
    background-position: var(--portal-background-position);
    background-repeat: var(--portal-background-repeat);
    background-size: var(--portal-background-size);
  }

  html[data-portal-background-active="false"] body {
    background-image: none;
  }

  h1, h2, h3, h4, h5, h6 {
    @apply font-bold tracking-tight;
    font-family: var(--portal-font-heading);
  }

  button:not(:disabled),
  [role="button"]:not([aria-disabled="true"]),
  [type="button"]:not(:disabled),
  [type="submit"]:not(:disabled),
  [type="reset"]:not(:disabled),
  a[href],
  select:not(:disabled),
  input[type="checkbox"]:not(:disabled),
  input[type="radio"]:not(:disabled) {
    @apply cursor-pointer;
  }
}

@layer components {
  /**
   * Custom container utility that centers content and adds responsive padding.
   *
   * This overrides Tailwind's default container behavior to:
   * - Auto-center content (mx-auto)
   * - Add responsive horizontal padding
   * - Set max-width for large screens
   *
   * Usage: <div className="container">...</div>
   *
   * For custom widths, use max-w-* utilities directly:
   * <div className="max-w-6xl mx-auto px-4">...</div>
   */
  .container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem; /* 16px - mobile padding */
    padding-right: 1rem;
  }

  .portal-immersive-page {
    background: transparent;
  }

  .portal-decorations-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
  }

  .portal-decoration-item {
    position: absolute;
    height: auto;
    max-width: 38vw;
    object-fit: contain;
    mix-blend-mode: normal;
    transform: translateZ(0);
  }

  .portal-card-shell {
    position: relative;
    isolation: isolate;
    overflow: hidden;
  }

  .portal-card-shell > :not(.portal-card-decoration) {
    position: relative;
    z-index: 1;
  }

  .portal-card-decoration {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    height: auto;
    aspect-ratio: 1 / 1;
    max-width: min(32vw, 13rem);
    transform: translateZ(0);
    will-change: transform, opacity, filter;
  }

  .portal-immersive-main {
    position: relative;
    isolation: isolate;
  }

  .portal-immersive-main > * {
    position: relative;
    z-index: 1;
  }

  .portal-immersive-main::before,
  .portal-immersive-main::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    contain: paint;
  }

  .portal-immersive-main::before {
    border-radius: clamp(1rem, 2vw, 1.75rem);
    background-image:
      linear-gradient(var(--portal-background-overlay), var(--portal-background-overlay)),
      var(--portal-background-image);
    background-attachment: var(--portal-background-shell-attachment, scroll);
    background-position: var(--portal-background-position);
    background-repeat: var(--portal-background-repeat);
    background-size: var(--portal-background-size);
    filter: blur(var(--portal-background-shell-blur, 0px));
    border: 1px solid var(--portal-background-frame-border);
    box-shadow: var(--portal-background-shell-shadow);
    z-index: -2;
  }

  .portal-immersive-main::after {
    border-radius: clamp(1rem, 2vw, 1.75rem);
    background:
      linear-gradient(
        90deg,
        color-mix(in srgb, var(--portal-background-center-overlay) calc(var(--portal-background-edge-strength) * 100%), transparent) 0%,
        transparent 14%,
        transparent 86%,
        color-mix(in srgb, var(--portal-background-center-overlay) calc(var(--portal-background-edge-strength) * 92%), transparent) 100%
      ),
      radial-gradient(circle at top right, color-mix(in srgb, var(--portal-background-center-overlay) calc(var(--portal-background-edge-strength) * 70%), transparent), transparent 32%),
      radial-gradient(circle at bottom left, color-mix(in srgb, var(--portal-background-center-overlay) calc(var(--portal-background-edge-strength) * 58%), transparent), transparent 28%);
    z-index: -1;
  }

  html[data-portal-background-active="true"][data-portal-background-presentation-mode="edge_frame"] .portal-immersive-main::after {
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb, var(--portal-background-center-overlay) 18%, transparent) 0%,
        transparent 11%,
        transparent 89%,
        color-mix(in srgb, var(--portal-background-center-overlay) 22%, transparent) 100%
      ),
      linear-gradient(
        90deg,
        transparent 0%,
        color-mix(in srgb, var(--portal-background-center-overlay) 24%, transparent) 8%,
        color-mix(in srgb, var(--portal-background-center-overlay) 72%, transparent) 18%,
        var(--portal-background-center-overlay) 28%,
        var(--portal-background-center-overlay) 72%,
        color-mix(in srgb, var(--portal-background-center-overlay) 72%, transparent) 82%,
        color-mix(in srgb, var(--portal-background-center-overlay) 24%, transparent) 92%,
        transparent 100%
      ),
      radial-gradient(circle at top left, color-mix(in srgb, var(--portal-background-center-overlay) 28%, transparent), transparent 28%),
      radial-gradient(circle at top right, color-mix(in srgb, var(--portal-background-center-overlay) 24%, transparent), transparent 30%),
      radial-gradient(circle at bottom left, color-mix(in srgb, var(--portal-background-center-overlay) 18%, transparent), transparent 28%),
      radial-gradient(circle at bottom center, color-mix(in srgb, var(--portal-background-center-overlay) 24%, transparent), transparent 26%);
  }

  html[data-portal-background-active="false"] .portal-immersive-main::before,
  html[data-portal-background-active="false"] .portal-immersive-main::after {
    opacity: 0;
  }

  .flex {
    min-height: 0;
    min-width: 0;
  }

  [data-slot="card"] {
    border-radius: var(--portal-card-radius);
    box-shadow: var(--portal-card-shadow);
    transition: box-shadow 160ms ease, border-radius 160ms ease, transform 160ms ease;
  }

  html[data-card-style="soft"] [data-slot="card"] {
    background-image: linear-gradient(180deg, var(--portal-section-tint) 0%, var(--card) 28%);
  }

  html[data-card-style="outlined"] [data-slot="card"] {
    box-shadow: none;
    border-width: 1.5px;
    background-image: none;
  }

  html[data-card-style="elevated"] [data-slot="card"] {
    border-color: transparent;
  }

  [data-slot="button"] {
    border-radius: var(--portal-button-radius);
  }

  html[data-button-style="square"] [data-slot="button"] {
    letter-spacing: 0;
  }

  [data-slot="input"],
  [data-slot="textarea"],
  [data-slot="select-trigger"] {
    border-radius: var(--portal-input-radius);
  }

  html[data-input-style="soft"] [data-slot="input"],
  html[data-input-style="soft"] [data-slot="textarea"],
  html[data-input-style="soft"] [data-slot="select-trigger"] {
    background-color: color-mix(in srgb, var(--portal-secondary) 8%, var(--card));
  }

  html[data-input-style="filled"] [data-slot="input"],
  html[data-input-style="filled"] [data-slot="textarea"],
  html[data-input-style="filled"] [data-slot="select-trigger"] {
    border-color: transparent;
    background-color: color-mix(in srgb, var(--portal-secondary) 14%, var(--card));
  }

  html[data-table-style="compact"] [data-slot="table-head"] {
    height: 2.2rem;
  }

  html[data-table-style="compact"] [data-slot="table-head"],
  html[data-table-style="compact"] [data-slot="table-cell"] {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
  }

  html[data-table-style="striped"] [data-slot="table-body"] [data-slot="table-row"]:nth-child(even) {
    background-color: var(--portal-table-stripe);
  }

  html[data-display-density="compact"] [data-slot="card"] {
    border-radius: calc(var(--portal-card-radius) - 0.12rem);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  }

  html[data-display-density="compact"] [data-slot="button"] {
    min-height: 2.5rem;
  }

  html[data-display-density="compact"] [data-slot="input"],
  html[data-display-density="compact"] [data-slot="textarea"],
  html[data-display-density="compact"] [data-slot="select-trigger"] {
    min-height: 2.5rem;
  }

  html[data-display-density="detailed"] [data-slot="card"] {
    border-radius: calc(var(--portal-card-radius) + 0.08rem);
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.1);
  }

  html[data-display-density="detailed"] [data-slot="button"] {
    min-height: 2.85rem;
  }

  html[data-display-density="detailed"] [data-slot="input"],
  html[data-display-density="detailed"] [data-slot="textarea"],
  html[data-display-density="detailed"] [data-slot="select-trigger"] {
    min-height: 2.85rem;
  }

  html[data-sidebar-style="contrast"] [data-sidebar="sidebar"] {
    background-image: linear-gradient(180deg, color-mix(in srgb, var(--sidebar) 90%, var(--primary)) 0%, var(--sidebar) 100%);
  }

  html[data-sidebar-style="floating"] [data-slot="sidebar-container"] {
    padding: 0.75rem;
  }

  html[data-sidebar-style="floating"] [data-slot="sidebar-inner"] {
    box-shadow: var(--portal-card-shadow);
  }

  @media (min-width: 640px) {
    .container {
      padding-left: 1.5rem; /* 24px - tablet padding */
      padding-right: 1.5rem;
    }
  }

  @media (min-width: 1024px) {
    .container {
      padding-left: 2rem; /* 32px - desktop padding */
      padding-right: 2rem;
      max-width: 1280px; /* Standard content width */
    }
  }

  @media (max-width: 640px) {
    .portal-immersive-main::before,
    .portal-immersive-main::after {
      border-radius: 1rem;
    }

    .portal-immersive-main::after {
      background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0.04) 18%, rgba(255, 255, 255, 0.04) 82%, rgba(255, 255, 255, 0.22) 100%),
        linear-gradient(90deg, rgba(255, 255, 255, 0.38) 0%, rgba(255, 255, 255, 0.08) 16%, rgba(255, 255, 255, 0.08) 84%, rgba(255, 255, 255, 0.34) 100%);
    }
  }

  @media (hover: none), (pointer: coarse), (prefers-reduced-motion: reduce) {
    body {
      background-attachment: scroll;
    }

    .portal-immersive-main::before {
      filter: none;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --portal-motion-fast: 0ms;
    --portal-motion-base: 0ms;
  }
}
