/* ==========================================================================
   IBS Fiche Generator — Design System
   Palette source: ref/color2.jpg (Powder Blue / Blue Gray / Classic Blue /
   Blue Slate / Midnight) + shell language: ref/inspire.jpg
   Single-hue cool ramp (hue ~205-210). No warm tones.
   Rule: components NEVER use raw hex — tokens only.
   ========================================================================== */

:root {
  /* ---- Blue ramp (verbatim from color2.jpg, lightest → deepest) ---- */
  --blue-50: #e8f4fd;    /* white + Powder Blue — page wash */
  --blue-100: #b3def8;   /* Powder Blue  */
  --blue-200: #58a1d3;   /* Blue Gray    */
  --blue-300: #2c74a8;   /* Blue Gray ↔ Classic Blue, for rings and charts */
  --blue-400: #0f4c81;   /* Classic Blue */
  --blue-500: #022c50;   /* Blue Slate   */
  --blue-900: #06172e;   /* Midnight     */

  /* ---- Neutrals (sampled from inspire.jpg) ---- */
  --white: #ffffff;
  --gray-25: #fcfcfc;
  --gray-50: #f8f8f8;
  --gray-100: #f3f3f3;
  --gray-150: #e0e0e0;
  --gray-300: #b4b4b4;
  --gray-500: #6b6b6b;   /* 5.74:1 on white — WCAG AA for small text */
  --gray-800: #0d0d0d;
  --black: #000000;

  /* ---- Surfaces ---- */
  --bg: var(--blue-50);
  --bg-panel: var(--white);
  --bg-inset: var(--gray-100);
  --bg-invert: var(--blue-900);

  /* ---- Text ---- */
  --fg: var(--gray-800);
  --fg-dim: var(--gray-500);
  --fg-invert: var(--white);
  --fg-invert-dim: var(--blue-200);

  /* ---- Borders ---- */
  --border: #d9e7f2;             /* white ↔ Powder Blue, tinted to the ramp */
  --border-strong: var(--blue-200);
  --border-invert: rgba(255, 255, 255, 0.16);

  /* ---- Accents ---- */
  --accent: var(--blue-400);         /* primary action = Classic Blue */
  --accent-hover: var(--blue-500);   /* hover deepens to Blue Slate */
  --accent-soft: var(--blue-100);    /* highlight washes / selected rows */
  --accent-mid: var(--blue-300);     /* charts, progress fill secondary */
  --warn: var(--blue-400);
  --danger: var(--blue-500);
  --success: var(--blue-400);   /* status hues must clear 4.5:1 as text */

  /* Filled status surfaces — text sits on the dark end of the ramp */
  --success-surface: var(--blue-100);
  --success-on: var(--blue-500);
  --warn-surface: var(--blue-100);
  --warn-on: var(--blue-500);
  --danger-surface: var(--blue-100);
  --danger-on: var(--blue-900);
  --focus-ring: var(--blue-300);

  /* ---- Radius scale ---- */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 16px;      /* cards, panels */
  --radius-lg: 24px;
  --radius-pill: 999px;

  /* ---- Spacing scale (4px base) ---- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 28px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* ---- Elevation: hairline-first, shadows near-absent ---- */
  --shadow-sm: 0 1px 2px rgba(0, 15, 34, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 15, 34, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 15, 34, 0.10);
  --shadow-pop: 0 16px 56px rgba(0, 15, 34, 0.18);
  --scrim: rgba(0, 15, 34, 0.36);

  /* ---- Typography ---- */
  --font: "Inter", "General Sans", -apple-system, BlinkMacSystemFont,
          "Segoe UI", system-ui, sans-serif;
  --font-display: "General Sans", "Inter", -apple-system, system-ui, sans-serif;
  --font-fiche: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;

  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 26px;
  --fs-2xl: 34px;
  --fs-stat: 42px;

  --lh-tight: 1.15;
  --lh-snug: 1.35;
  --lh-normal: 1.6;

  --tracking-tight: -0.02em;
  --tracking-stat: -0.03em;
  --tracking-wide: 0.08em;

  /* ---- Motion ---- */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 380ms;

  /* ---- Layout ---- */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --shell-max: 1440px;
}

/* ==========================================================================
   Reset
   ========================================================================== */

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

/* Author `display` values (.drawer { display:flex }, .modal-backdrop { display:grid })
   outrank the UA sheet's [hidden] rule, which leaves a closed overlay laid over the
   page swallowing clicks. This single rule keeps `hidden` authoritative. */
[hidden] {
  display: none !important;
}

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

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

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 650;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--fg);
}

p { margin: 0; }

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

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

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

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

ul, ol { margin: 0; padding: 0; list-style: none; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

::selection {
  background: var(--accent-soft);
  color: var(--blue-900);
}

/* Scrollbar — thin, hairline, no chrome */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ==========================================================================
   Shell — sidebar + main (per inspire.jpg: fixed left rail, no topbar)
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  padding: var(--sp-7) var(--sp-5);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-2);
}

.sidebar__mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--bg-invert);
  color: var(--fg-invert);
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: none;
}

.sidebar__name {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
  line-height: 1.2;
}

.sidebar__sub {
  font-size: var(--fs-xs);
  color: var(--fg-dim);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  border-radius: var(--radius-pill);
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--fg-dim);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-inset);
  color: var(--fg);
}

.nav-item[aria-current="page"],
.nav-item.is-active {
  background: var(--accent);
  color: var(--fg-invert);
}

.nav-item[aria-current="page"]:hover,
.nav-item.is-active:hover {
  background: var(--accent-hover);
}

.nav-item__icon {
  width: 18px;
  height: 18px;
  flex: none;
  opacity: 0.75;
}

.nav-item[aria-current="page"] .nav-item__icon,
.nav-item.is-active .nav-item__icon {
  opacity: 1;
}

.sidebar__foot {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.sidebar__avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-dim);
  flex: none;
}

.sidebar__who { min-width: 0; }
.sidebar__who-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__who-role {
  font-size: var(--fs-xs);
  color: var(--fg-dim);
}

.main {
  min-width: 0;
  padding: var(--sp-8) var(--sp-8) var(--sp-12);
}

.main__inner {
  max-width: var(--shell-max);
  margin: 0 auto;
}

/* ---- Page header ---- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-6);
  margin-bottom: var(--sp-8);
  flex-wrap: wrap;
}

.page-head__title {
  font-size: var(--fs-xl);
  font-weight: 700;
}

.page-head__sub {
  margin-top: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--fg-dim);
}

.page-head__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ==========================================================================
   Typography helpers
   ========================================================================== */

.eyebrow {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-dim);
}

.text-dim { color: var(--fg-dim); }
.mono { font-family: var(--font-mono); font-size: var(--fs-sm); }

/* Fiche titles use the serif — the one place a second typeface appears */
.fiche-title {
  font-family: var(--font-fiche);
  font-weight: 700;
  letter-spacing: 0;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1100px) {
  :root { --sidebar-w: 84px; }
  .sidebar {
    padding: var(--sp-6) var(--sp-3);
    align-items: center;
  }
  .sidebar__name,
  .sidebar__sub,
  .sidebar__who,
  .nav-item span { display: none; }
  .nav-item {
    justify-content: center;
    padding: 12px;
  }
  .main { padding: var(--sp-6) var(--sp-5) var(--sp-10); }
}

@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .sidebar__nav {
    flex-direction: row;
    overflow: visible;
    gap: var(--sp-1);
  }
  .sidebar__brand,
  .sidebar__foot { display: none; }
  .nav-item span { display: none; }
  .nav-item[aria-current="page"] { background: var(--bg-invert); }
  .main { padding: var(--sp-5) var(--sp-4) var(--sp-10); }

  .page-head {
    margin-bottom: var(--sp-6);
    align-items: stretch;
    flex-direction: column;
    gap: var(--sp-4);
  }

  /* Search takes the full row, actions wrap beneath it */
  .page-head__actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .search {
    flex: 1 1 100%;
    min-width: 0;
  }
}

/* The action row carries seven buttons (Recharger, Étapes, Mes fiches, École,
   Importer, Nouvelle fiche + the search box). Below this width they no longer
   fit on one line and push the document wider than the viewport, so they wrap
   before the layout collapse at 720px kicks in. */
@media (max-width: 1100px) {
  .page-head__actions {
    flex-wrap: wrap;
  }
  .page-head__actions .search {
    flex: 1 1 200px;
    min-width: 0;
  }
}

@media (max-width: 480px) {
  .page-head__title { font-size: var(--fs-lg); }
  .stat__value { font-size: var(--fs-2xl); }
  .card { padding: var(--sp-4); }
  .modal { border-radius: var(--radius); }
  .modal__head,
  .modal__body,
  .modal__foot { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .toast-stack {
    left: var(--sp-4);
    right: var(--sp-4);
    bottom: var(--sp-4);
  }
}

@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;
  }
}
