:root {
  --bleu: #1B6FA8;
  --bleu-fonce: #124f7a;
  --or: #E8A33D;
  --gris-fond: #f4f6f8;
  --gris-bordure: #dde3e8;
  --texte: #22303c;
  --rouge: #c0392b;
  --vert: #2e8b57;
  --blanc: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Poppins, Arial, sans-serif;
  background: var(--gris-fond);
  color: var(--texte);
}

a { color: var(--bleu); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--bleu-fonce);
  color: var(--blanc);
  padding: 12px 16px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
}
.mobile-topbar .menu-toggle {
  background: none; border: 1px solid rgba(255,255,255,0.4); color: var(--blanc);
  font-size: 1.1rem; line-height: 1; padding: 6px 10px; border-radius: 6px; cursor: pointer;
}
.mobile-topbar-title { font-weight: 700; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 39;
}

.sidebar {
  width: 230px;
  background: var(--bleu-fonce);
  color: var(--blanc);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar .brand {
  padding: 20px 16px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.sidebar .brand img { max-width: 100%; max-height: 70px; }
.sidebar .brand .brand-text { font-weight: 700; font-size: 1.05rem; margin-top: 8px; }

.sidebar nav { flex: 1; padding: 10px 0; }
.sidebar nav a {
  display: block;
  padding: 12px 20px;
  color: rgba(255,255,255,0.85);
  border-left: 3px solid transparent;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: rgba(255,255,255,0.08);
  border-left-color: var(--or);
  color: var(--blanc);
  text-decoration: none;
}

.sidebar .logout { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.15); }
.sidebar .logout button {
  background: none; border: 1px solid rgba(255,255,255,0.4); color: var(--blanc);
  padding: 8px 12px; border-radius: 6px; cursor: pointer; width: 100%;
}
.sidebar .logout button:hover { background: rgba(255,255,255,0.1); }

.main { flex: 1; padding: 24px 32px; max-width: 1200px; }

/*
 * Les pages restent larges de 1200px pour rester lisibles, mais la frise du
 * calendrier gagne à occuper tout l'écran : plus la fenêtre est large, plus on
 * voit de jours sans faire glisser. La marge négative rattrape exactement ce
 * que `.main` laisse de côté (230px de menu + 2 × 32px de marge), et ne fait
 * rien tant que la fenêtre n'est pas assez large.
 */
@media (min-width: 769px) {
  .card.pleine-largeur { max-width: none; margin-right: min(0px, calc(1438px - 100vw)); }
}

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 1.5rem; }

.btn {
  display: inline-block;
  background: var(--bleu);
  color: var(--blanc);
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
}
.btn:hover { background: var(--bleu-fonce); text-decoration: none; color: var(--blanc); }
.btn.secondary { background: var(--blanc); color: var(--bleu); border: 1px solid var(--bleu); }
.btn.secondary:hover { background: var(--gris-fond); }
.btn.danger { background: var(--rouge); }
.btn.gold { background: var(--or); color: #3a2a04; }
.btn.small { padding: 5px 10px; font-size: 0.82rem; }

.card {
  background: var(--blanc);
  border: 1px solid var(--gris-bordure);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.stat-tile { background: var(--blanc); border: 1px solid var(--gris-bordure); border-radius: 10px; padding: 18px; }
.stat-tile .label { font-size: 0.82rem; color: #64758a; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-tile .value { font-size: 1.6rem; font-weight: 700; color: var(--bleu-fonce); margin-top: 6px; }

table { width: 100%; border-collapse: collapse; background: var(--blanc); }
table.card-table { border: 1px solid var(--gris-bordure); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--gris-bordure); font-size: 0.92rem; }
th { background: var(--gris-fond); color: #4b5a68; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafcfe; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; }
.badge.dispo { background: #e2f4ea; color: var(--vert); }
.badge.loue { background: #fdecea; color: var(--rouge); }
.badge.entretien { background: #fff3da; color: #8a5a00; }
.badge.warn { background: #fff3da; color: #8a5a00; }
.badge.expired { background: #fdecea; color: var(--rouge); }
/* Bien en sommeil : gris volontairement terne, il ne doit attirer aucun regard. */
.badge.sommeil { background: #eceff1; color: #55636e; }

/* Encadré « ce qui revient à un bénéficiaire », sur la page Infos du parc. */
.part-benef { flex: 1 1 200px; min-width: 190px; border: 1px solid var(--gris-bordure); border-radius: 8px; padding: 12px 14px; background: #fbfcfd; }
.part-benef-nom { font-weight: 700; color: var(--bleu-fonce); }
.part-benef-montant { font-size: 1.2rem; font-weight: 700; margin-top: 6px; color: #22303c; }
tr.ligne-sommeil td { opacity: 0.55; }

/*
 * Couleur des locations : elle suit le STATUT enregistré, pas les dates.
 * Les teintes sont les mêmes que celles des barres du calendrier et de la
 * frise (voir COULEURS dans src/services/frise.js) : une location vue orange
 * sur la frise doit être orange dans la liste, sinon on croit à deux locations.
 */
.badge.statut-a_venir  { background: #fdf0d9; color: #8a5a00; }  /* confirmée : orange */
.badge.statut-en_cours { background: #e2f4ea; color: #1e6b3a; }  /* en cours  : vert   */
.badge.statut-terminee { background: #eceff1; color: #55636e; }  /* terminée  : gris   */
.badge.statut-annulee  { background: #fdecea; color: var(--rouge); }

/* Puce de couleur reprise dans les légendes du calendrier et de la frise. */
.puce-statut { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

.alert-box { border-radius: 8px; padding: 12px 16px; margin-bottom: 10px; font-size: 0.9rem; }
.alert-box.warn { background: #fff3da; border: 1px solid #f1c876; }
.alert-box.danger { background: #fdecea; border: 1px solid #f0b4ac; }
.alert-box.info { background: #e6f0f8; border: 1px solid #b7d4e8; }

form .field { margin-bottom: 14px; }
form label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; color: #445; }
form input[type=text], form input[type=number], form input[type=date], form input[type=password],
form input[type=tel], form select, form textarea, form input[type=time] {
  width: 100%; padding: 9px 10px; border: 1px solid var(--gris-bordure); border-radius: 6px; font-size: 0.92rem;
  font-family: inherit;
}
form textarea { resize: vertical; min-height: 70px; }
form .checkbox-row { display: flex; align-items: center; gap: 8px; }
form .checkbox-row input { width: auto; }
form .actions { margin-top: 18px; display: flex; gap: 10px; }

.flash { margin-bottom: 16px; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bleu-fonce); }
.login-box { background: var(--blanc); padding: 32px; border-radius: 12px; width: 320px; text-align: center; }
.login-box img { max-width: 160px; margin-bottom: 10px; }
.login-box h1 { font-size: 1.2rem; margin: 0 0 20px; color: var(--bleu-fonce); }
.login-box .error { color: var(--rouge); font-size: 0.85rem; margin-bottom: 12px; }
/* Confirmation sur les pages hors connexion (mot de passe réinitialisé, lien envoyé). */
.login-box .reussite { color: #1e6b3a; background: #e2f4ea; border-radius: 6px; padding: 8px 10px; font-size: 0.85rem; margin-bottom: 12px; }

.muted { color: #778; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; color: var(--bleu-fonce); }

/*
 * Bloc replié : on ne voit que son titre, un clic le déroule. Pour les actions
 * rares (changer de bien en pleine location, prolonger) dont le formulaire
 * poussait le reste de la fiche hors de l'écran à chaque visite.
 * Le triangle est dessiné à la main : celui du navigateur n'est pas alignable.
 */
details.bloc-repliable > summary.section-title { cursor: pointer; list-style: none; margin-bottom: 0; }
details.bloc-repliable > summary.section-title::-webkit-details-marker { display: none; }
details.bloc-repliable > summary.section-title::before { content: '▸'; display: inline-block; width: 16px; color: var(--bleu); }
details.bloc-repliable[open] > summary.section-title { margin-bottom: 12px; }
details.bloc-repliable[open] > summary.section-title::before { content: '▾'; }
details.bloc-repliable > summary.section-title:hover { color: var(--bleu); }
.tag-list a { margin-right: 10px; }

.photo-thumb { width: 90px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--gris-bordure); }
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.doc-history { border-left: 3px solid var(--gris-bordure); padding-left: 12px; margin-top: 8px; }
.doc-history .old { opacity: 0.6; }

#calendar, #global-calendar { background: var(--blanc); padding: 10px; border-radius: 10px; border: 1px solid var(--gris-bordure); }

.calendar-legend { display: flex; gap: 16px; margin-bottom: 10px; font-size: 0.85rem; color: #556; }
.calendar-legend span { display: flex; align-items: center; gap: 6px; }
.calendar-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

.gc-event { display: flex; align-items: baseline; gap: 6px; padding: 1px 4px; overflow: hidden; line-height: 1.35; }
.gc-event .gc-title { font-size: 0.78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-event .gc-range { font-size: 0.7rem; opacity: 0.9; white-space: nowrap; flex-shrink: 0; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
  .mobile-topbar { display: flex; }

  .app-shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 240px;
    max-width: 80vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 40;
    overflow-y: auto;
  }

  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-open .sidebar-overlay { display: block; }

  .main { padding: 16px; padding-top: 68px; max-width: 100%; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .tag-list { display: flex; flex-wrap: wrap; gap: 8px; }

  table.card-table { display: block; overflow-x: auto; white-space: nowrap; }

  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }

  .login-box { width: 90vw; max-width: 320px; }
}

/*
 * Dates et heures tapées au clavier : un format impossible (31/02, année à
 * trois chiffres) se voit tout de suite. Sans le menu déroulant du navigateur,
 * rien d'autre ne prévenait avant l'enregistrement.
 */
form input.saisie-invalide {
  border-color: #b3261e;
  background: #fdf3f2;
}
