:root {
  --green: #2e7d32;
  --green-bg: #e6f4ea;
  --mauve: #8b5cf6;
  --orange: #e8890c;
  --orange-bg: #fdf0dd;
  --mauve-bg: #f2ecfe;
  --red: #c62828;
  --red-bg: #fbe6e6;
  --ink: #1f2430;
  --muted: #6b7280;
  --border: #dfe3e8;
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  /* Bleu de la charte du Service des batiments : Pantone Process Blue C,
     soit rgb(0, 133, 202) en sRGB - la couleur exacte du logo. */
  --accent: #0085ca;
  --accent-dark: #006da6;
  --accent-soft: #e6f4fa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Les controles de formulaire n'heritent pas de la police du document par defaut
   (ils utilisent une police systeme, souvent Arial) : on les aligne sur celle du body
   pour n'avoir qu'une seule police dans toute l'application. */
button, input, select, textarea {
  font-family: inherit;
}

/* Le bandeau reste pleine largeur, mais son contenu est aligne sur celui de la page
   (memes max-width et padding horizontal que .layout) pour que le logo et le lien
   restent a l'aplomb des blocs situes en dessous, meme sur ecran large. */
header.app-header {
  background: #163a5f;
  color: white;
  padding: 0.9rem 0;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 60px;
  width: auto;
}

header.app-header h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
}

header.app-header .subtitle {
  font-size: 0.8rem;
  color: #c7d6e8;
  margin-top: 0.15rem;
}

header.app-header nav a {
  color: #dce8fb;
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
}
header.app-header nav a:hover { background: rgba(255,255,255,0.1); }

/* Bandeau d'information : aligne sur le contenu de la page, dans le bleu de la charte. */
.info-block-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1rem 0;
}

.info-block {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.info-block-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.info-block-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  font-style: italic;
  flex-shrink: 0;
}

.info-block-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-dark);
}

.info-block-meta {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--muted);
}

.info-block-body {
  font-size: 0.9rem;
  line-height: 1.5;
}
.info-block-body > *:first-child { margin-top: 0; }
.info-block-body > *:last-child { margin-bottom: 0; }
.info-block-body p { margin: 0.4rem 0; }
.info-block-body h2, .info-block-body h3, .info-block-body h4 {
  margin: 0.6rem 0 0.3rem;
  font-size: 1rem;
}
.info-block-body ul, .info-block-body ol { margin: 0.4rem 0; padding-left: 1.5rem; }
.info-block-body a { color: var(--accent-dark); }
.info-block-body blockquote {
  margin: 0.5rem 0;
  padding-left: 0.75rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.layout {
  display: grid;
  /* minmax(0, 1fr) et non 1fr : sinon la colonne ne peut pas descendre sous la largeur
     minimale de son contenu (le plan), ce qui faisait deborder la page sur mobile. */
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

/* Placement explicite : le bloc d'informations generales se met sous le plan (colonne 1),
   le panneau lateral reste en haut a droite. Sans cela, le placement automatique de la
   grille enverrait le bloc a droite du plan. */
.layout > .panel:first-child { grid-column: 1; grid-row: 1; }
.general-block { grid-column: 1; grid-row: 2; }
.side-panel { grid-column: 2; grid-row: 1 / span 2; }

.general-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.general-block-head h2 {
  margin: 0;
  font-size: 1rem;
}

/* Icone devant les titres de section : meme couleur d'accent partout, taille alignee sur le texte. */
h2 .h2-icon {
  width: 1.05em;
  height: 1.05em;
  margin-right: 0.4rem;
  vertical-align: -0.18em;
  color: var(--accent);
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* Une seule colonne : on laisse l'ordre naturel du document (plan, infos, panneau). */
  .layout > .panel:first-child,
  .general-block,
  .side-panel { grid-column: 1; grid-row: auto; }
}

.panel {
  min-width: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.floor-tabs {
  display: flex;
  gap: 0.4rem;
}

.floor-tabs button {
  border: 1px solid var(--border);
  background: white;
  color: var(--ink);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.floor-tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.time-bar {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
}

/* Une seule police et une seule taille dans toute la barre temporelle : les controles
   de formulaire (boutons, input date) n'heritent pas de la police du document par defaut,
   d'ou le melange de polices sans cette regle. Taille alignee sur les onglets d'etage. */
.time-bar,
.time-bar button,
.time-bar input,
.time-bar span {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 400;
}

/* Grille a 3 colonnes egales pour vraiment centrer le groupe de boutons de pas dans la
   barre, quelle que soit la largeur du bouton "Aujourd'hui" a gauche (une simple
   justify-content: space-between le decale, il n'est pas au milieu de la ligne entiere). */
.time-bar-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.6rem;
}
.time-bar-top #todayBtn { grid-column: 1; justify-self: start; }
.time-bar-top .date-nav { grid-column: 2; justify-self: center; }

/* Groupe segmente : les boutons de pas encadrent la date, en un seul bloc visuel. */
.date-nav {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.date-nav .step-btn {
  border: none;
  border-right: 1px solid var(--border);
  background: white;
  color: var(--ink);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}
.date-nav .step-btn:last-child { border-right: none; }
.date-nav .step-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.date-nav .step-btn:disabled { color: #b9c0ca; cursor: default; }

.date-nav .date-label-wrap {
  position: relative;
  display: flex;
  flex: 0 0 210px;
  width: 210px;
  border-right: 1px solid var(--border);
}

.date-nav .date-label {
  flex: 1;
  border: none;
  background: white;
  color: var(--ink);
  padding: 0.4rem 0.3rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  font-weight: 600;
}
.date-nav .date-label:hover { background: var(--accent-soft); color: var(--accent); }

/* Champ date invisible mais toujours dispose sous l'etiquette : il n'est plus affiche,
   il sert uniquement a ouvrir le calendrier natif du navigateur au bon endroit. */
.date-nav .date-label-wrap input[type="date"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  border: none;
  padding: 0;
}

/* Meme traitement visuel que l'onglet de l'etage affiche : bleu quand on est sur aujourd'hui. */
.time-bar-top .small-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}
.time-bar-top .small-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.time-bar-top .small-btn.active:hover { background: var(--accent); }

.time-bar-slider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.slider-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

/* Rail dessine nous-memes : le fond gris est recouvert de portions colorees marquant
   les periodes ou au moins un local de l'etage affiche est en travaux. */
.slider-segments {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  border-radius: 3px;
  background: #d7dbe0;
  pointer-events: none;
}

/* Le curseur natif est rendu transparent pour laisser voir le rail ci-dessus
   (et supprimer au passage le remplissage bleu par defaut du navigateur). */
.time-bar-slider input[type="range"] {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
.time-bar-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: transparent;
}
.time-bar-slider input[type="range"]::-moz-range-track {
  height: 6px;
  background: transparent;
}
.time-bar-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--ink);
  cursor: pointer;
}
.time-bar-slider input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--ink);
  cursor: pointer;
}

.slider-bound {
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 560px) {
  .time-bar-top { display: flex; flex-direction: column; align-items: stretch; }
  .time-bar-top #todayBtn { justify-self: stretch; }
  .date-nav { width: 100%; }
  .date-nav .date-label-wrap { flex: 1 1 auto; width: auto; min-width: 0; }
}

button.small-btn {
  border: 1px solid var(--border);
  background: white;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
}
button.small-btn:hover { background: #f0f2f5; }

.legend {
  display: flex;
  gap: 1rem;
  font-size: 0.82rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.legend span.swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 3px;
  margin-right: 0.3rem;
  vertical-align: -1px;
}

/* Bouton de recentrage : meme gabarit que les commandes de zoom de Leaflet. */
.recenter-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.recenter-btn svg { width: 16px; height: 16px; }
.recenter-btn:hover { color: var(--accent); }

#map {
  height: 600px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #eef1f4;
}

/* Sur mobile, la colonne est etroite : 600px de haut donnent un plan tres allonge.
   On passe a un format carre, plus proche des proportions du batiment. */
@media (max-width: 900px) {
  #map {
    height: auto;
    aspect-ratio: 1 / 1;
  }
}

.room-label {
  pointer-events: none;
}

/* Zoom eloigne : on masque d'abord le nom et le numero du local, puis, un niveau plus
   loin, les noms de personnes. L'etiquette entiere ne disparait qu'a ce second seuil. */
.labels-hidden .room-label .room-name,
.labels-hidden .room-label .room-number { display: none; }
.occupants-hidden .room-label { display: none; }

.room-label-inner {
  display: inline-block;
  transform: translate(-50%, -50%);
  text-align: center;
  line-height: 1.3;
  white-space: nowrap;
}

.room-label .room-name {
  font-size: 13px;
  font-weight: 600;
  color: #1f2430;
  text-shadow: 0 0 2px white, 0 0 2px white, 0 0 2px white;
}

.room-label .room-number {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-shadow: 0 0 2px white, 0 0 2px white, 0 0 2px white, 0 0 2px white;
}

.room-label .room-occupants {
  margin-bottom: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.occupant-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #c7ced8;
  border-radius: 5px;
  padding: 2px 3px 2px 7px;
  font-size: 13px;
  font-weight: 500;
  color: #163a5f;
  cursor: grab;
  pointer-events: auto;
}
.occupant-tag:active { cursor: grabbing; }

.occupant-extra {
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.tag-remove {
  border: none;
  background: transparent;
  color: var(--red);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0 3px;
  pointer-events: auto;
}
.tag-remove:hover { background: var(--red-bg); border-radius: 3px; }

path.room-drop-hover {
  stroke: var(--accent) !important;
  stroke-width: 3 !important;
  stroke-dasharray: 5, 4;
}

.side-panel h2 {
  font-size: 1rem;
  margin-top: 0;
  margin-bottom: 0.5rem;
}
.side-panel h2 label { cursor: pointer; }

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.status-disponible { background: var(--green-bg); color: var(--green); }
.status-temporaire { background: var(--mauve-bg); color: var(--mauve); }
.status-occupe { background: var(--orange-bg); color: var(--orange); }
.status-ferme { background: var(--red-bg); color: var(--red); }

.occupant-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}
.occupant-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.occupant-list .tag-remove { font-size: 1rem; flex-shrink: 0; }
.occupant-list li:last-child { border-bottom: none; }
.occupant-service { color: var(--muted); font-size: 0.8rem; }

.empty-hint {
  color: var(--muted);
  font-size: 0.88rem;
}

/* Travaux rattaches au local selectionne : liseré coloré selon le statut, et mise en
   evidence de ceux qui couvrent la date consultee. */
.work-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
}

.work-item {
  border-left: 3px solid var(--border);
  border-radius: 0 6px 6px 0;
  background: #f7f8fa;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}
.work-item[data-status="disponible"] { border-left-color: var(--green); }
.work-item[data-status="temporaire"] { border-left-color: var(--mauve); }
.work-item[data-status="occupe"] { border-left-color: var(--orange); }
.work-item[data-status="ferme"] { border-left-color: var(--red); }

/* Mise en evidence du travail couvrant la date consultee, aux couleurs de son statut. */
.work-item.current[data-status="disponible"] {
  background: var(--green-bg);
  box-shadow: inset 0 0 0 1px var(--green);
}
.work-item.current[data-status="temporaire"] {
  background: var(--mauve-bg);
  box-shadow: inset 0 0 0 1px var(--mauve);
}
.work-item.current[data-status="occupe"] {
  background: var(--orange-bg);
  box-shadow: inset 0 0 0 1px var(--orange);
}
.work-item.current[data-status="ferme"] {
  background: var(--red-bg);
  box-shadow: inset 0 0 0 1px var(--red);
}

.work-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.work-dates { font-weight: 600; }

.work-current-badge {
  background: var(--muted);
  color: white;
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.work-item.current[data-status="disponible"] .work-current-badge { background: var(--green); }
.work-item.current[data-status="temporaire"] .work-current-badge { background: var(--mauve); }
.work-item.current[data-status="occupe"] .work-current-badge { background: var(--orange); }
.work-item.current[data-status="ferme"] .work-current-badge { background: var(--red); }

.work-ics-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.35rem;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 0.78rem;
  cursor: pointer;
}
.work-ics-btn svg { width: 13px; height: 13px; }
.work-ics-btn:hover { border-color: var(--accent); color: var(--accent); }

.work-status { color: var(--muted); }
.work-comment { margin-top: 0.15rem; }

form.self-report {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
form.self-report input, form.self-report select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
}
form.self-report button.submit-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.55rem;
  font-weight: 600;
  cursor: pointer;
}
form.self-report button.submit-btn:hover { background: var(--accent-dark); }

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.3rem;
  margin-top: 0.3rem;
}
.avatar-picker button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.35rem 0;
  text-align: center;
  cursor: pointer;
}
.avatar-picker button:hover { background: #f0f2f5; }
.avatar-picker button.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.feedback {
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  margin-top: 0.4rem;
}
.feedback.ok { background: var(--green-bg); color: var(--green); }
.feedback.error { background: var(--red-bg); color: var(--red); }

/* Chaque bloc du panneau lateral est separe du precedent par un filet et de l'air,
   pour distinguer nettement consultation, declaration et recherche. */
/* Un local est selectionne : le detail se detache sur un fond grise, pour que le lien
   entre le clic sur le plan et le remplissage du panneau soit evident. */
#roomDetails.has-room {
  background: #e8ecf0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}

.side-section + .side-section {
  margin-top: 1.4rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--border);
}

.side-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
}

.field-hint {
  font-size: 0.85rem;
  color: var(--muted);
}
.search-results {
  margin-top: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}
.search-results .result {
  padding: 0.4rem 0.2rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
}
.search-results .result:hover { background: #f0f2f5; }

footer.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 1.5rem 1rem;
}
