/*
 * styles.css — feuille unique partagée par la page publique et l'éditeur.
 *
 * Choix d'accessibilité / performance :
 *  - `:focus-visible` sur les `.hotspot` (et boutons) : le focus clavier est
 *    rendu visible (outline coloré), sans perturber le clic souris.
 *  - `@media (prefers-reduced-motion: reduce)` : transitions et animations
 *    quasi instantanées, scroll automatique non fluide, pour les personnes
 *    sensibles au mouvement.
 *  - `backdrop-filter: blur()` reste utilisé sur quelques conteneurs ; sur les
 *    appareils modestes ou en plein écran il peut saccader. Une alternative
 *    opaque (fond uni RGBA élevé) est envisageable si besoin.
 *  - Les couleurs d'accent sur fond sombre restent à vérifier au contraste
 *    WCAG AA (--accent #c59f62 en texte selon la taille).
 */

:root {
  color-scheme: dark;
  --bg: #111311;
  --bg-soft: #171a17;
  --panel: rgba(24, 27, 24, 0.9);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #f4f0e8;
  --muted: #c1b8ab;
  --accent: #c59f62;
  --accent-strong: #f0c07a;
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

.editor-only[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(197, 159, 98, 0.12), transparent 30%),
    linear-gradient(180deg, #0d0f0c 0%, #161815 56%, #0f120f 100%);
  color: var(--text);
  font-family: "Trebuchet MS", "Lucida Grande", "DejaVu Sans", sans-serif;
}

body {
  padding: 28px;
}

.page-shell {
  max-width: 1600px;
  margin: 0 auto;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: start;
  flex-direction: column;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-size: 0.78rem;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}

h1 {
  font-size: clamp(2.4rem, 4vw, 4.3rem);
  line-height: 0.95;
}

.hero-copy {
  margin: 14px 0 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.55;
}

.hero-card,
.grave-list-card,
.grave-editor-card,
.stage-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-card {
  min-width: 280px;
  padding: 18px 20px;
  border-radius: 20px;
}

.hero-card-label,
.hero-card-note,
.panel-header p,
.grave-list-card p {
  color: var(--muted);
}

.hero-card-label {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
}

.hero-card-value {
  margin-top: 8px;
  font-size: 1.05rem;
  color: var(--accent-strong);
}

.hero-card-note {
  margin-top: 6px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.auth-status {
  flex: 1;
  color: var(--muted);
  font-size: 0.88rem;
}

.auth-status.is-authenticated {
  color: var(--accent-strong);
}

.login-dialog {
  width: min(420px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: #1b1e1a;
  color: var(--text);
  box-shadow: var(--shadow);
}

.login-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(4px);
}

.login-dialog form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.login-dialog .panel-header {
  margin-bottom: 4px;
}

.login-dialog .panel-header p:not(.eyebrow) {
  max-width: 330px;
}

.login-error {
  margin: 0;
  color: #ff9b8f;
  font-size: 0.9rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(340px, 0.9fr);
  gap: 22px;
  align-items: start;
}

.stage-panel,
.editor-panel {
  border-radius: 28px;
  overflow: hidden;
}

.stage-panel {
  padding: 18px;
}

.stage-panel > .grave-editor-card {
  margin-top: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-header h2 {
  font-size: 1.5rem;
}

.panel-header p {
  margin: 8px 0 0;
  line-height: 1.45;
}

.panel-header-stacked {
  align-items: flex-start;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Anneau de focus visible pour la navigation clavier (le outline:none du
   :hover ne doit pas masquer le focus au clavier). */
.button:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.button-primary {
  background: linear-gradient(135deg, #d7a860 0%, #f0c07a 100%);
  color: #21160a;
  border-color: transparent;
}

.button-primary:hover,
.button-primary:focus-visible {
  background: linear-gradient(135deg, #edbf78 0%, #ffcf8c 100%);
}

.button-secondary {
  background: rgba(255, 255, 255, 0.03);
}

.image-stage {
  position: relative;
  overflow: visible;
  border-radius: 24px;
  background: #090a09;
  outline: 1px solid rgba(255, 255, 255, 0.08);
  width: 100%;
  height: auto;
  line-height: 0;
  /* Permet le défilement natif à un doigt (pan) tout en empêchant le
     pincement natif du navigateur : le pinch-zoom est géré manuellement
     en JS (setupPinchZoom) pour zoomer uniquement la carte, pas la page. */
  touch-action: pan-x pan-y;
}

.image-stage img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.image-stage.is-dragging {
  cursor: grabbing;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
}

.hotspot {
  position: absolute;
  border: 3px solid rgb(255, 255, 0);
  background: rgba(255, 255, 0, 0.25);
  border-radius: 18px;
  cursor: grab;
  touch-action: none;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.hotspot:active,
.hotspot.is-dragging {
  cursor: grabbing;
}

.hotspot.is-readonly {
  cursor: default;
}

.hotspot.is-readonly::after {
  display: none;
}

.hotspot.is-disused {
  border-color: rgb(255, 115, 0);
  background: rgba(255, 115, 0, 0.24);
}

/* Monument / élément du cimetière (pas une sépulture) : couleur distincte. */
.hotspot.is-landmark {
  border-color: rgb(120, 180, 255);
  background: rgba(120, 180, 255, 0.22);
}

.hotspot.is-landmark::after {
  background: #8fb8ff;
  box-shadow: 0 0 0 6px rgba(120, 180, 255, 0.18);
}

.hotspot.is-landmark:hover {
  border-color: rgb(150, 200, 255);
  background: rgba(120, 180, 255, 0.16);
  box-shadow: 0 0 0 2px rgba(120, 180, 255, 0.2), 0 16px 36px rgba(0, 0, 0, 0.25);
}

.resize-handle {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 18px;
  height: 18px;
  border-radius: 5px 0 16px 0;
  background: var(--accent-strong);
  border: 2px solid #23170d;
  cursor: nwse-resize;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 6px;
  height: 6px;
  border-right: 2px solid #23170d;
  border-bottom: 2px solid #23170d;
}

.hotspot.is-resizing {
  cursor: nwse-resize;
}

.hotspot::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--accent-strong);
  border: 2px solid #23170d;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 6px rgba(240, 192, 122, 0.14);
}

.hotspot:hover
  {
  border-color: rgb(240, 193, 122);
  background: rgba(240, 192, 122, 0.18);
  box-shadow: 0 0 0 2px rgba(240, 192, 122, 0.15), 0 16px 36px rgba(0, 0, 0, 0.25);
  transform: scale(1.02);
  outline: none;
}

/* Focus clavier visible : outline coloré pour la navigation au clavier,
   sans affecter le rendu au clic souris (:focus-visible n'active que quand
   le navigateur estime que l'utilisateur navigue au clavier). */
.hotspot:focus-visible {
  outline: 3px solid rgb(240, 193, 122);
  outline-offset: 2px;
}

.hotspot.is-selected {
  border-color: rgb(255, 116, 116);
  background: rgba(255, 116, 116, 0.24);
  box-shadow: 0 0 0 3px rgba(255, 116, 116, 0.2), 0 16px 36px rgba(0, 0, 0, 0.25);
}

.hotspot.is-selected::after {
  background: #ff8f8f;
  box-shadow: 0 0 0 6px rgba(255, 116, 116, 0.18);
}

.grave-tooltip {
  position: fixed;
  z-index: 5;
  min-width: 260px;
  max-width: 330px;
  overflow: visible;
  background: rgba(18, 18, 18, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, calc(-100% - 14px));
  pointer-events: none;
  line-height: normal;
}

.grave-tooltip.is-centered {
  transform: translate(-50%, -50%);
}

.grave-tooltip::-webkit-scrollbar {
  width: 7px;
}

.grave-tooltip::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(240, 192, 122, 0.55);
}

.grave-tooltip.is-below {
  transform: translate(-50%, 14px);
}

.grave-tooltip h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
}

/* Mention « en état d'abandon » affichée sous le titre quand disused est vrai. */
.tooltip-disused {
  margin: 0 0 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 115, 0, 0.16);
  border: 1px solid rgba(255, 115, 0, 0.4);
  color: #ffb38a;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

.grave-tooltip-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 240px;
  object-fit: contain;
  margin-inline: auto;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 14px;
  margin-bottom: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Placeholder affiché dans le tooltip quand l'emplacement n'a pas de photo. */
.grave-tooltip-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-bottom: 10px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.85rem;
}

/*
 * Modale plein écran affichant le détail d'un emplacement au clic sur un
 * repère. Sur mobile c'est le moyen principal de consultation (pas de survol).
 * Le contenu réutilise les classes du tooltip (.tooltip-person, etc.).
 */
.grave-modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 28px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: #1b1e1a;
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.grave-modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.grave-modal-content {
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: 24px 22px 28px;
  line-height: normal;
}

.grave-modal-content h3 {
  font-size: 1.25rem;
  margin-bottom: 10px;
}

.grave-modal-content .grave-tooltip-image {
  max-height: 320px;
}

.grave-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.grave-modal-close:hover,
.grave-modal-close:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.grave-tooltip .tooltip-person {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.grave-tooltip .tooltip-person:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

/* Personne vacante (emplacement libre) dans le tooltip et la modale : grisée. */
.grave-tooltip .tooltip-person.is-vacant {
  opacity: 0.5;
}

.grave-tooltip .tooltip-person.is-vacant .person-name {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}

.grave-tooltip .person-name {
  color: var(--accent-strong);
  font-weight: 700;
}

.editor-panel {
  display: grid;
  gap: 16px;
}

.grave-list-card,
.grave-editor-card {
  padding: 18px;
  border-radius: 24px;
}

.grave-list-card {
  overflow: hidden;
}

.grave-list-card > summary {
  cursor: pointer;
  list-style: none;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-weight: 600;
}

.grave-list-card > summary::-webkit-details-marker {
  display: none;
}

.grave-list-card > summary::after {
  content: "+";
  float: right;
  color: var(--accent-strong);
  font-family: sans-serif;
  font-size: 1.35rem;
  line-height: 1;
}

.grave-list-card[open] > summary::after {
  content: "−";
}

.grave-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.grave-search {
  margin-top: 16px;
}

.grave-search input {
  padding-block: 10px;
}

.grave-item {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.03);
}

.grave-item > summary {
  position: relative;
  display: block;
  padding: 12px 52px 12px 52px;
  cursor: pointer;
  list-style: none;
}

.grave-item > summary::-webkit-details-marker {
  display: none;
}

.grave-item > summary::after {
  content: "+";
  position: absolute;
  top: 50%;
  right: 40px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  transform: translateY(-50%);
}

.grave-item[open] > summary::after {
  content: "−";
}

.grave-item > summary strong,
.grave-item > summary small {
  display: block;
}

.grave-item > summary small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

/* Mention « en état d'abandon » affichée dans le résumé de l'emplacement. */
.grave-list-disused {
  color: #ffb38a;
  font-weight: 600;
}

.grave-item.is-active {
  border-color: rgba(255, 116, 116, 0.65);
  background: rgba(255, 116, 116, 0.1);
}

.map-locate-button {
  position: absolute;
  top: 50%;
  left: 10px;
  z-index: 1;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 1rem;
  transform: translateY(-50%);
}

.map-locate-button:hover,
.map-locate-button:focus-visible {
  background: rgba(240, 192, 122, 0.18);
  border-color: rgba(240, 192, 122, 0.55);
  outline: none;
}

.grave-people {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.grave-person {
  display: grid;
  gap: 3px;
  padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.grave-person small {
  color: var(--muted);
  line-height: 1.35;
}

.map-viewport {
  position: relative;
  overflow: auto;
  border-radius: 24px;
}

.map-controls {
  display: none;
}

.map-viewport:fullscreen {
  padding: 14px;
  background: #090a09;
}

.editor-section {
  display: grid;
  gap: 14px;
}

.editor-block {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.editor-grid {
  display: grid;
  gap: 10px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 12px 13px;
  font: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 80px;
}

.person-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr)) auto auto;
  gap: 10px;
  align-items: end;
}

/* Ligne d'un emplacement vacant (non compté dans les inhumations) : grisée. */
.person-row.is-vacant {
  opacity: 0.55;
}

.person-vacant-toggle {
  font-size: 1rem;
  line-height: 1;
}

.icon-button {
  min-width: 40px;
  padding-inline: 12px;
}

.fullscreen-button {
  font-size: 1.35rem;
  line-height: 1;
}

.reset-button {
  font-size: 1.35rem;
  line-height: 1;
}

.muted-copy {
  color: var(--muted);
  line-height: 1.5;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

/* Aperçu + téléversement de l'image d'un emplacement. */
.image-upload {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.image-preview {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 180px;
  height: auto;
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
}

/* Placeholder quand l'emplacement n'a pas d'image associée. */
.image-preview-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.9rem;
}

.image-upload-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.image-upload-controls small {
  flex: 1;
  min-width: 0;
}

@media (max-width: 1180px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero {
    align-items: start;
  }

  .toolbar {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  body {
    padding: 10px;
  }

  h1 {
    font-size: clamp(1.8rem, 7vw, 2.6rem);
  }

  .hero-copy {
    margin-top: 10px;
  }

  .hero-card {
    min-width: 0;
    padding: 14px 16px;
  }

  .stage-panel {
    padding: 10px;
  }

  .stage-panel,
  .grave-list-card,
  .grave-editor-card,
  .hero-card {
    border-radius: 18px;
  }

  /* En-tête de panneau empilé sur mobile : titre au-dessus, barre d'outils
     en dessous en boutons pleine largeur. */
  .panel-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .panel-header h2 {
    font-size: 1.25rem;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar .button {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .person-row {
    grid-template-columns: 1fr;
  }

  /* La carte occupe la majeure partie de l'écran ; le reste défile en dessous. */
  .image-stage {
    min-height: 0;
    border-radius: 16px;
  }

  .map-viewport {
    /* Hauteur confortable pour la carte en portrait, sans occuper tout l'écran
       (la liste et l'éditeur restent accessibles en défilant). */
    height: 60dvh;
    max-height: 60dvh;
    background: #090a09;
    border-radius: 16px;
  }

  /* Repères : taille tactile minimale pour rester tapables même au zoom 1. */
  .hotspot {
    min-width: 32px;
    min-height: 32px;
  }

  /* Barre de zoom flottante en bas de la carte. */
  .map-controls {
    position: sticky;
    bottom: 10px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: max-content;
    margin: -56px auto 10px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(18, 18, 18, 0.92);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
  }

  .map-controls .button {
    min-width: 42px;
    min-height: 42px;
    padding: 9px 12px;
  }

  .map-controls span {
    min-width: 52px;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
  }

  .map-viewport:fullscreen {
    max-height: none;
    height: 100dvh;
    border-radius: 0;
  }

  .map-viewport:fullscreen .map-controls {
    position: fixed;
    bottom: 16px;
    left: 50%;
    margin: 0;
    transform: translateX(-50%);
  }

  .auth-area {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .auth-status {
    flex-basis: 100%;
  }

  /* Modale quasi plein écran sur mobile. */
  .grave-modal {
    max-width: calc(100% - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 18px;
  }
}

/* Respecte prefers-reduced-motion : transitions/animations quasi
   instantanées et scroll non fluide, pour les personnes sensibles au
   mouvement (bonne pratique d'accessibilité). */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  html {
    scroll-behavior: auto;
  }
}