/* =========================================================
   Thème « Kiosque » : jetons de design et mise en page
   ---------------------------------------------------------
   Chargé après style.css et kiosque.css, qui n'utilisent plus
   que ces jetons pour les couleurs. Changer de thème revient à
   changer les valeurs ci-dessous.
   Accent : le vert des kiosques parisiens. Clair par défaut,
   sombre selon le réglage de l'appareil.
   ========================================================= */

:root {
  color-scheme: light dark;

  /* Couleurs (clair) : contrastes vérifiés, texte >= 5:1 sur tous les fonds */
  --bg: #f3f7f4;
  --surface: #fcfefd;
  --surface-2: #e8efea;
  --line: #d3dcd6;
  --line-strong: #b0bab4;
  --ink: #17211b;
  --ink-2: #455049;
  --ink-3: #5c6660;
  --accent: #206040;
  --accent-ink: #195b3b;
  --on-accent: #f7fbf8;
  --signal: #f5ae39;
  --on-signal: #2d1f0a;
  --signal-ink: #9a5500; /* « Nouveau » en texte sur fond clair (5,3:1) */
  --danger: #b63132;
  --success: #33854a;
  --on-image: #f7fbf8; /* texte posé sur une couverture ou un voile noir, quel que soit le thème */

  /* Mêmes couleurs en canaux RGB, pour les transparences : rgb(var(--x-rgb) / 0.2) */
  --surface-rgb: 252 254 253;
  --ink-rgb: 23 33 27;
  --accent-rgb: 32 96 64;
  --signal-rgb: 245 174 57;
  --danger-rgb: 182 49 50;
  --success-rgb: 51 133 74;
  --shadow-rgb: 21 38 28;

  /* Typographie : police système (rapide, et l'arabe s'affiche partout) */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --text-xs: 0.78rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.6rem;

  /* Espacements (base 4 px), rayons, ombres, durées */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-pill: 999px;
  --shadow-cover: 0 1px 2px rgb(var(--shadow-rgb) / 0.12), 0 4px 12px rgb(var(--shadow-rgb) / 0.08);
  --shadow-cover-hover: 0 2px 4px rgb(var(--shadow-rgb) / 0.14), 0 10px 24px rgb(var(--shadow-rgb) / 0.14);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --duration: 180ms;

  /* Hauteur de la barre d'onglets du bas (téléphone) */
  --tabbar-h: 3.75rem;

  /* Échelle des plans (z-index) */
  --z-sticky: 10;
  --z-tabbar: 20;
  --z-drawer: 30;
  --z-toast: 40;
  --z-modal: 50;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d120f;
    --surface: #151b17;
    --surface-2: #1d2520;
    --line: #2b332e;
    --line-strong: #414a44;
    --ink: #e9eeeb;
    --ink-2: #b8c0bb;
    --ink-3: #99a19c;
    --accent: #69c090;
    --accent-ink: #7ecb9f;
    --on-accent: #0a140e;
    --signal: #f5ae39;
    --on-signal: #251804;
    --signal-ink: #f9b64f;
    --danger: #ed756e;
    --success: #6cc581;

    --surface-rgb: 21 27 23;
    --ink-rgb: 233 238 235;
    --accent-rgb: 105 192 144;
    --danger-rgb: 237 117 110;
    --success-rgb: 108 197 129;
    --shadow-rgb: 0 0 0;
    --shadow-cover: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 12px rgb(0 0 0 / 0.3);
    --shadow-cover-hover: 0 2px 4px rgb(0 0 0 / 0.45), 0 10px 24px rgb(0 0 0 / 0.4);
  }
}

/* ---------- Base ---------- */

html {
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  text-wrap: balance;
  letter-spacing: -0.01em;
}

a {
  color: inherit;
}

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

::selection {
  background: rgb(var(--accent-rgb) / 0.25);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.25em;
}

/* ---------- Barre latérale (ordinateur) ---------- */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar-brand {
  text-align: left;
  margin-bottom: var(--space-5);
}

.brand-logo {
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.brand-tagline {
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.sidebar-header h2 {
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

/* ---------- En-tête de page ---------- */

.layout .page-header {
  border-bottom: 1px solid var(--line);
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
}

.layout .page-header h1 {
  font-size: var(--text-xl);
  font-weight: 700;
}

.home-header {
  text-align: left;
}

.home-header .header-top {
  justify-content: space-between;
}

.header-brand {
  align-items: flex-start;
  flex: none;
}

.home-header .toolbar {
  width: 100%;
  max-width: 40rem;
  margin: 0;
}

.home-subtitle {
  color: var(--ink-2);
  font-size: var(--text-md);
}

.menu-toggle {
  display: none;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font: 600 var(--text-sm) var(--font);
}

/* ---------- Onglets principaux ---------- */

.main-tabs {
  margin: 0;
  padding: var(--space-1);
  gap: var(--space-1);
  background: var(--surface-2);
  border: 0;
  border-radius: var(--radius-pill);
}

.main-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  min-height: 2.5rem;
  color: var(--ink-2);
  font-weight: 600;
  font-size: var(--text-sm);
  transition: background var(--duration) var(--ease-out), color var(--duration) var(--ease-out);
}

.main-tab:hover,
.main-tab:focus-visible {
  color: var(--ink);
  background: rgb(var(--ink-rgb) / 0.06);
}

.main-tab[aria-current="page"] {
  background: var(--surface);
  color: var(--accent-ink);
  box-shadow: 0 1px 2px rgb(var(--shadow-rgb) / 0.12);
}

.page-header .main-tabs {
  align-self: flex-start;
  margin-bottom: 0;
}

/* ---------- Recherche ---------- */

.search-input {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  min-height: 2.75rem;
  padding: 0 var(--space-4);
  font: var(--text-md) var(--font);
}

.search-input::placeholder {
  color: var(--ink-3);
}

.search-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.18);
  outline: 2px solid transparent; /* l'anneau ci-dessus fait office de focus visible */
}

/* ---------- Sections de l'accueil : à plat, sans cartes imbriquées ---------- */

.recent-days {
  gap: var(--space-6);
  padding: var(--space-5);
}

.day-preview {
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  gap: var(--space-4);
}

.day-preview + .day-preview {
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}

.day-preview h2,
.home-section-head h2 {
  text-align: left;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--ink);
}

.day-preview h2 .titre-date {
  display: block;
  margin-top: 2px;
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-3);
}

.jour-groupe h3 {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.jour-groupe h3 span {
  color: var(--ink-3);
}

/* ---------- Couvertures ---------- */

.preview-row {
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: var(--space-5) var(--space-4);
}

.preview-card,
.journal-card img,
.titre-card-img-wrap {
  border-radius: var(--radius-sm);
}

.preview-card {
  border: 0;
  padding: 0;
  background: var(--surface-2);
  box-shadow: var(--shadow-cover);
  transition: transform var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out);
}

.preview-card:hover,
.preview-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-cover-hover);
  border-color: transparent;
}

.preview-card:active {
  transform: scale(0.98);
}

.titre-card,
.journal-card {
  background: none;
  border: 0;
  box-shadow: none;
}

.titre-card:hover,
.titre-card:focus-visible,
.journal-card:hover,
.journal-card:focus-visible {
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

.titre-card-img-wrap {
  background: var(--surface-2);
  box-shadow: var(--shadow-cover);
  transition: box-shadow var(--duration) var(--ease-out), transform var(--duration) var(--ease-out);
}

.titre-card:hover .titre-card-img-wrap,
.titre-card:focus-visible .titre-card-img-wrap {
  transform: translateY(-2px);
  box-shadow: var(--shadow-cover-hover);
}

.titre-card:hover .titre-card-img {
  transform: none;
}

.titre-card-name,
.journal-card .journal-name {
  color: var(--ink);
  font-weight: 600;
}

.titre-card-date,
.journal-date {
  color: var(--ink-3);
}

/* Badges posés sur une couverture : toujours lisibles, quel que soit le thème */
.badge-new,
.badge-nouveau {
  background: var(--signal);
  color: var(--on-signal);
  box-shadow: none;
}

.titre-card-badge {
  background: rgb(0 0 0 / 0.68);
  color: #f7fbf8;
}

/* ---------- Pages d'un jour et d'un titre : couverture d'abord ---------- */

.gallery {
  gap: var(--space-5) var(--space-4);
  padding: var(--space-5);
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
}

.journal-card {
  position: relative; /* repère des badges et de la date posés sur la couverture */
  padding: 0;
  gap: var(--space-2);
  border-radius: 0;
  overflow: visible;
}

.journal-card img,
.journal-card .journal-thumb {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-cover);
  transition: transform var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out);
}

.journal-card:hover img,
.journal-card:focus-visible img {
  transform: translateY(-2px);
  box-shadow: var(--shadow-cover-hover);
}

.journal-card .journal-name {
  font-size: var(--text-sm);
  line-height: 1.3;
  text-align: left;
  margin: 0;
}

.journal-card .journal-date {
  font-size: var(--text-xs);
  text-align: left;
}

/* Sur la page d'un jour, la date est celle de la page : on ne la répète pas sous chaque
   couverture, sauf quand la recherche affiche aussi des éditions d'autres jours. */
#gallery:not(.avec-archives) > .journal-card .journal-date {
  display: none;
}

.journal-actions {
  margin: 0;
  justify-content: flex-start;
}

.download-button {
  padding: var(--space-1) 0;
  min-height: 2rem;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--accent-ink);
  font-size: var(--text-xs);
  font-weight: 600;
  box-shadow: none;
}

.download-button:hover,
.download-button:focus-visible {
  background: none;
  text-decoration: underline;
  transform: none;
}

.edition-date-overlay {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* ---------- Liens et boutons ---------- */

.lien-discret {
  min-height: 2.75rem;
  padding: 0 var(--space-2);
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--accent-ink);
  font: 600 var(--text-sm) var(--font);
  cursor: pointer;
}

.lien-discret:hover {
  background: rgb(var(--accent-rgb) / 0.08);
}

.lus-recemment .mes-journaux-strip .preview-card {
  aspect-ratio: 3 / 4;
}

.see-more {
  color: var(--accent-ink);
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}

.see-more:hover,
.see-more:focus-visible {
  background: rgb(var(--accent-rgb) / 0.08);
  border-color: rgb(var(--accent-rgb) / 0.4);
}

.chip {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-2);
}

.chip[aria-pressed="true"],
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.legal-footer {
  color: var(--ink-3);
  font-size: var(--text-xs);
  border-top: 1px solid var(--line);
}

/* ---------- Lecteur PDF et chargement : toujours sombres ---------- */

.lightbox-overlay,
.pdf-loader-overlay {
  color-scheme: dark;
  --bg: #0d120f;
  --surface: #151b17;
  --surface-2: #1d2520;
  --line: #2b332e;
  --line-strong: #414a44;
  --ink: #e9eeeb;
  --ink-2: #b8c0bb;
  --ink-3: #99a19c;
  --accent: #69c090;
  --accent-ink: #7ecb9f;
  --on-accent: #0a140e;
  --surface-rgb: 21 27 23;
  --ink-rgb: 233 238 235;
  --accent-rgb: 105 192 144;
  color: var(--ink);
}

/* ---------- Archives (barre latérale) : chevron dessiné selon l'état du mois ---------- */

.month-toggle .chevron {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  box-shadow: inset -2px -2px 0 currentColor; /* deux côtés d'un carré tourné = chevron */
  transform: rotate(-45deg);
  transition: transform var(--duration) var(--ease-out);
}

.month-toggle[aria-expanded="true"] .chevron {
  transform: rotate(45deg);
}

/* ---------- Barre d'outils du lecteur ---------- */

.lightbox-toolbar {
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.lightbox-nav,
.lightbox-close,
.lightbox-ouvrir {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font: 600 var(--text-sm) var(--font);
}

.lightbox-ouvrir {
  color: var(--accent-ink);
  text-decoration: none;
}

.lightbox-ouvrir:hover,
.lightbox-ouvrir:focus-visible {
  background: rgb(var(--ink-rgb) / 0.06);
}

/* ---------- Ordinateur : le nom du kiosque est dans la barre latérale ---------- */

@media (min-width: 769px) {
  .layout .header-brand {
    display: none;
  }
}

/* ---------- Téléphone : onglets en bas, en-tête compact ---------- */

@media (max-width: 768px) {
  body {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  }

  .layout .page-header {
    padding: var(--space-3) var(--space-4);
  }

  .home-header .header-top {
    flex-wrap: nowrap;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .main-tabs,
  .page-header .main-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-tabbar);
    width: 100%;
    max-width: none;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    border-radius: 0;
    border-top: 1px solid var(--line);
    background: rgb(var(--surface-rgb) / 0.96);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    backdrop-filter: saturate(1.4) blur(12px);
  }

  .main-tab {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: var(--tabbar-h);
    padding: var(--space-1) var(--space-2);
    border-radius: 0;
    font-size: 0.72rem;
    font-weight: 600;
  }

  .main-tab .icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  .main-tab[aria-current="page"] {
    background: none;
    box-shadow: none;
    color: var(--accent-ink);
  }

  .main-tab[aria-current="page"] .icon {
    stroke-width: 2.2;
  }

  .recent-days {
    padding: var(--space-4);
    gap: var(--space-5);
  }

  .preview-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4) var(--space-3);
  }

  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4) var(--space-3);
    padding: var(--space-4);
  }

  /* Les onglets du bas ramènent déjà à l'accueil */
  .back-home-container {
    display: none;
  }

  /* Lecteur plein écran, boutons réduits à leur icône */
  .lightbox-overlay {
    padding: 0;
  }

  .lightbox-content {
    width: 100%;
    height: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .lightbox-toolbar {
    padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  }

  .lightbox-toolbar .libelle {
    display: none;
  }

  .lightbox-nav,
  .lightbox-close,
  .lightbox-ouvrir {
    padding: 0;
  }

  /* Journaux : sous-titre masqué, filtres et lettres sur une ligne qui défile */
  .page-header .home-subtitle {
    display: none;
  }

  .filtres-chips,
  .layout .az-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .filtres-chips::-webkit-scrollbar,
  .layout .az-bar::-webkit-scrollbar {
    display: none;
  }

  .filtres-chips > *,
  .layout .az-bar > * {
    flex: none;
  }

  .count-line {
    margin: 0;
    font-size: var(--text-sm);
  }

  .toast-notification {
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-3));
  }
}

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