/* =============================================================
   Vigie — base : remise à zéro, typographie, mise en page, en-tête
   ============================================================= */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-height) + 16px);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-web);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-wrap: pretty;
  overflow-x: hidden;
}

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

svg.icon {
  flex-shrink: 0;
}

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

button {
  cursor: pointer;
}

a {
  color: var(--brand-text);
  text-decoration: none;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  color: var(--text-strong);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

ul,
ol {
  padding: 0;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 200;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: var(--weight-semibold);
}

.skip-link:focus {
  top: calc(env(safe-area-inset-top, 0px) + 12px);
}

.container {
  width: 100%;
  max-width: var(--container-xl);
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left, 0px));
}

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

/* ── En-tête ─────────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--header-bg);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: 60px;
}

@media (min-width: 768px) {
  .header-inner {
    height: var(--header-height);
    gap: var(--space-6);
  }
}

/*
 * Signature commune des outils Skazy Formation.
 * À gauche : la pastille (favicon de l'outil) et le nom, un seul lien vers les annonces.
 * À droite, en derniers : « Les outils » (la roue), un filet, puis le logo Skazy Formation.
 */
.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--text-strong);
  text-decoration: none;
  flex-shrink: 0;
}

.brand:hover {
  text-decoration: none;
}

/* Pastille : 24 px sur téléphone, 28 px sur ordinateur. */
.brand-tile {
  display: block;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-right: 10px;
}

/* Logo officiel Skazy Formation (SVG) : « skazy » suit le thème, « formation » reste vert. */
.logo {
  display: block;
  height: 30px;
  width: auto;
  aspect-ratio: 218 / 72;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .brand-tile {
    width: 28px;
    height: 28px;
  }

  .logo {
    height: 32px;
  }
}

@media (min-width: 1100px) {
  .logo {
    height: 36px;
  }
}

.logo-skazy {
  fill: var(--logo-skazy);
}

.logo-formation {
  fill: var(--color-primary);
}

.brand-app {
  font-weight: var(--weight-bold);
  font-size: 1.0625rem;
  color: var(--text-strong);
  white-space: nowrap;
}

.top-nav {
  display: none;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
  justify-content: center;
}

.top-nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
  text-decoration: none;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.top-nav a:hover {
  color: var(--brand-text);
  background: var(--accent-subtle);
}

.top-nav a[aria-current='page'] {
  color: var(--brand-text);
  background: var(--accent-subtle);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: var(--weight-bold);
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  flex-shrink: 0;
}

/* « Les outils » : la roue des outils Skazy Formation, vers leur page d'accueil. */
.tools-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
  padding: 7px;
  border-radius: var(--radius-full);
  color: var(--text-strong);
  font-size: 0.9375rem;
  font-weight: var(--weight-bold);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--transition-fast);
}

.tools-link:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.tools-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

/* Sur téléphone et tablette, seule la roue s'affiche ; le texte reste le nom accessible. */
.tools-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 1100px) {
  .tools-link {
    padding: 7px 14px 7px 8px;
  }

  .tools-text {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
  }
}

.header-divider {
  flex-shrink: 0;
  width: 1px;
  height: 24px;
  margin-inline: 4px;
  background: var(--border-strong);
}

/* Logo Skazy Formation : dernier élément du bandeau, vers formation.skazy.nc. */
.skazy-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  text-decoration: none;
}

.skazy-link:hover {
  text-decoration: none;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-2);
  white-space: nowrap;
}

.sync-status:empty {
  display: none;
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}

.sync-status[data-tone='ok'] .sync-dot {
  background: var(--success);
}

.sync-status[data-tone='warning'] .sync-dot {
  background: var(--warning);
}

.sync-status[data-tone='busy'] .sync-dot {
  background: var(--brand);
  animation: pulse 1.2s ease-in-out infinite;
}

.sync-text {
  display: none;
}

@media (min-width: 768px) {
  .top-nav {
    display: flex;
  }
}

@media (min-width: 1100px) {
  .sync-text {
    display: inline;
  }
}

/* ── Contenu ─────────────────────────────────────────────────────── */

.main {
  padding-block: var(--space-6) calc(96px + env(safe-area-inset-bottom, 0px));
  outline: none;
}

@media (min-width: 768px) {
  .main {
    padding-block: var(--space-8) var(--space-16);
  }
}

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 40vh;
  color: var(--text-2);
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}

.noscript {
  padding: var(--space-8) var(--space-4);
  text-align: center;
}

/* ── Navigation mobile (bas d'écran) ─────────────────────────────── */

.bottom-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--header-bg);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border);
}

.bottom-nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: var(--weight-semibold);
  color: var(--text-2);
  text-decoration: none;
}

.bottom-nav a[aria-current='page'] {
  color: var(--brand-text);
}

.bottom-nav a[aria-current='page']::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 32px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--brand);
  transform: translateX(-50%);
}

.bottom-nav .nav-badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

/* ── Remonter en haut (toutes les vues) ──────────────────────────── */

/* Caché tant qu'on n'a pas défilé d'un écran (app.js) ; au-dessus de la barre d'onglets sur téléphone. */
.back-to-top {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(65px + 16px + env(safe-area-inset-bottom, 0px));
  z-index: 55;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-primary-dark);
  color: #ffffff;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity var(--transition-normal), transform var(--transition-normal), visibility 0s linear 250ms, background var(--transition-fast);
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity var(--transition-normal), transform var(--transition-normal), visibility 0s, background var(--transition-fast);
}

.back-to-top:hover {
  background: #336a54;
}

@media (min-width: 768px) {
  .back-to-top {
    right: 24px;
    bottom: 24px;
    width: 48px;
    height: 48px;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

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