:root {
  --ink: #14181f;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --accent: #4f46e5;
  --accent-light: #eef2ff;
  --today: #4f46e5;
  --radius: 8px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

/* ---------- Top nav ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 16px; color: var(--accent); margin-right: 12px; }
.topbar nav { display: flex; gap: 20px; }
.topbar nav a {
  padding: 8px 2px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.topbar nav a.active { color: var(--ink); border-bottom-color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; color: var(--muted); }

/* ---------- Layout ---------- */
.page { padding: 20px 24px 60px; max-width: 1700px; margin: 0 auto; }
.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 20px; margin: 0; }
.page-header .date-title { font-size: 22px; font-weight: 600; }

.toolbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.toolbar label { font-size: 12px; color: var(--muted); margin-right: 6px; }
select, input[type=text], input[type=date], input[type=number], input[type=color] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: #fff;
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .9; color: #fff; }
.btn-danger { color: #b42318; border-color: #fda29b; }
.btn-danger:hover { background: #fef3f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- Month strip ---------- */
.month-strip { display: flex; align-items: center; gap: 8px; margin: 14px 0; }
.month-strip .months { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.month-strip .months a {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.month-strip .months a.active { background: var(--accent); color: #fff; font-weight: 600; }
.month-strip .nav-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 32px; height: 32px; cursor: pointer; }

/* ---------- Calendar grid ---------- */
.cal-scroll {
  overflow: auto;
  max-height: calc(100vh - 250px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
table.cal { border-collapse: collapse; width: 100%; min-width: 1200px; }
table.cal th, table.cal td { border: 1px solid var(--line); vertical-align: top; }
table.cal thead th {
  position: sticky; top: 0; background: #fff; z-index: 10;
  padding: 8px 6px; font-size: 12px; color: var(--muted); text-align: center; min-width: 78px;
}

/* ---------- Mode "ajuste" : tout le mois tient dans la largeur, sans scroll horizontal ----------
   table-layout: fixed force les colonnes a se partager la largeur disponible au lieu de
   s'elargir selon leur contenu. Les min-width sont donc neutralisees. */
table.cal.fit { table-layout: fixed; min-width: 0; width: 100%; }
table.cal.fit thead th { min-width: 0; padding: 6px 1px; font-size: 10.5px; }
table.cal.fit td.name-col, table.cal.fit th.name-col { min-width: 0; width: 150px; padding: 6px 8px; }
table.cal.fit .avatar { width: 22px; height: 22px; font-size: 10px; }
table.cal.fit .tech-meta .tname { font-size: 11.5px; line-height: 1.2; }
table.cal.fit .tech-meta .trole { font-size: 9.5px; }
table.cal.fit .day-cell { min-height: 46px; }
table.cal.fit .half { min-height: 22px; padding: 1px; }
table.cal.fit .pill {
  font-size: 9.5px; padding: 2px 1px; border-radius: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.cal.fit .pill.full-cell { margin: 2px; }
table.cal.fit .pill small { display: none; }      /* la note ne rentre pas a cette largeur */
table.cal.fit .half.empty { font-size: 0; }        /* masque "matin"/"apm", la case reste cliquable */
table.cal.fit thead th .hname { display: none; }   /* le nom du jour ferie reste en infobulle (title) */
table.cal.fit .pill.holiday-fill { font-size: 0; } /* idem : couleur + infobulle suffisent */
table.cal thead th.weekend { background: var(--weekend-bg); }
table.cal thead th.holiday { background: var(--holiday-bg); }
table.cal thead th.holiday .hname {
  display: block; font-size: 9px; font-weight: 600; color: var(--holiday-tile);
  line-height: 1.1; margin-top: 2px; white-space: normal;
}
table.cal thead th.today { color: var(--accent); font-weight: 700; }
table.cal td.name-col, table.cal th.name-col {
  position: sticky; left: 0; background: #fff; z-index: 5; min-width: 190px; text-align: left; padding: 8px 12px;
}
table.cal thead th.name-col { z-index: 15; } /* coin haut-gauche au-dessus de tout au scroll */
table.cal td.weekend { background: var(--weekend-bg); }
table.cal td.weekend .day-cell { background: var(--weekend-bg); }
table.cal td.holiday { background: var(--holiday-bg); }
table.cal td.holiday .day-cell { background: var(--holiday-bg); }
table.cal td.today-col { background: #f5f4ff; }

.tech-row-header { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-light); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.tech-meta .tname { font-weight: 600; font-size: 13px; }
.tech-meta .trole { font-size: 11px; color: var(--muted); text-transform: capitalize; }

td.day-cell-wrap { padding: 0; }
.day-cell {
  min-height: 58px; height: 100%; display: flex; flex-direction: column;
  box-sizing: border-box;
}
.day-cell.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-light); }

/* Demi-journees : deux zones cliquables empilees */
.half {
  flex: 1 1 50%; min-height: 27px; display: flex; align-items: stretch; justify-content: center;
  padding: 2px 3px; cursor: pointer; position: relative;
}
.half + .half { border-top: 1px dashed var(--line); }
.half.empty { color: #cbd2dc; font-size: 10px; align-items: center; }
.half:hover.empty { background: #fafbfc; color: var(--muted); }

/* Tuile (pill) affectee : dans une demi-journee ou pleine largeur */
.pill {
  border-radius: 5px; padding: 4px 6px; font-size: 11.5px; font-weight: 700;
  line-height: 1.25; text-align: center; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.pill.full-cell { flex: 1; border-radius: 4px; margin: 3px; }
.pill[draggable="true"] { cursor: grab; }
.pill[draggable="true"]:active { cursor: grabbing; }
.pill small { display: block; font-weight: 500; font-size: 9.5px; opacity: .85; }

/* Tuile par defaut sur les cases de week-end / jour ferie vides */
.pill.weekend-fill, .half.weekend-fill { background: var(--weekend-tile); cursor: pointer; }
.pill.holiday-fill, .half.holiday-fill { background: var(--holiday-tile); cursor: pointer; }
.pill.weekend-fill:hover, .half.weekend-fill:hover,
.pill.holiday-fill:hover, .half.holiday-fill:hover { filter: brightness(0.88); }

/* Libelle du jour ferie dans la tuile */
.pill.holiday-fill {
  color: #fff; font-size: 9px; font-weight: 600; line-height: 1.15;
  padding: 3px 4px; text-align: center; overflow: hidden;
}

/* ---------- Forms / cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card h2 { margin-top: 0; font-size: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 12px; align-items: end; }
.form-grid .field { display: flex; flex-direction: column; gap: 4px; }
.form-grid label { font-size: 12px; color: var(--muted); font-weight: 600; }

table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 13px; text-align: left; }
table.simple th { color: var(--muted); font-weight: 600; font-size: 12px; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: middle; margin-right: 6px; border: 1px solid rgba(0,0,0,.08); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--accent-light); color: var(--accent); }

/* ---------- Template weekly grid ---------- */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.week-grid .day { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; }
.week-grid .day h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,24,31,.45); display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 10px; width: 340px; max-width: 92vw; padding: 20px; }
.modal.modal-wide { width: 560px; }
.alert-scroll { max-height: 340px; }
.modal h3 { margin: 0 0 4px; font-size: 15px; }
.modal .sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.type-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.type-opt { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.type-opt:hover { background: #f7f8fa; }
.type-opt.selected { border-color: var(--accent); background: var(--accent-light); }
.modal-actions { display: flex; justify-content: space-between; gap: 8px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ============================================================
   RESPONSIVE MOBILE
   ============================================================ */

/* Burger : masque sur desktop, visible en petit ecran */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-left: 4px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}

/* La vue affichee (bureau ou mobile) est choisie cote serveur : une seule des deux
   est presente dans la page. On applique juste les styles adaptatifs a la barre et aux
   formulaires quand l'ecran est etroit. */
.mobile-day { display: block; }

@media (max-width: 820px) {
  .topbar { gap: 0; padding: 0 14px; height: 54px; position: relative; }
  .topbar .brand { flex: 1; font-size: 17px; order: 1; }
  .topbar .user { display: none; }
  .topbar .spacer { display: none; }

  /* Burger a droite de la barre */
  .nav-toggle { display: flex; order: 3; margin-left: auto; }

  /* Menu deroulant plein largeur sous la barre, masque par defaut */
  .topbar nav {
    order: 4;
    position: absolute;
    top: 54px;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 24px rgba(16,24,40,.12);
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
    z-index: 30;
  }
  body.nav-open .topbar nav { max-height: 420px; }
  .topbar nav a {
    padding: 15px 18px;
    font-size: 15px;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
  }
  .topbar nav a:last-child { border-bottom: none; }
  .topbar nav a.active { background: var(--accent-light); border-left-color: var(--accent); color: var(--accent); font-weight: 600; }

  /* Animation du burger en croix quand le menu est ouvert */
  body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
  body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  .page { padding: 14px 12px 80px; }
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-header .date-title { font-size: 19px; }

  /* Boutons de la barre d'outils : pleine largeur, faciles a toucher */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar .btn, .toolbar select { width: 100%; justify-content: center; text-align: center; }
  .toolbar label { display: none; }

  /* Bandeau des mois : defilement horizontal tactile */
  .month-strip .months { -webkit-overflow-scrolling: touch; }

  /* Formulaires en une colonne */
  .form-grid { grid-template-columns: 1fr; }

  /* Cartes et tableaux simples : moins de padding, police un poil plus petite */
  .card { padding: 14px; }

  /* Les tableaux "simple" (listes de membres, types, templates...) deviennent des
     cartes empilees : chaque ligne = une carte, chaque cellule = "Libelle : valeur".
     Bien plus lisible au doigt qu'un tableau qui deborde horizontalement. */
  table.simple, table.simple tbody, table.simple tr, table.simple td { display: block; width: 100%; }
  table.simple thead { display: none; } /* les entetes sont repris via data-label */
  table.simple tr {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 12px;
    margin-bottom: 10px;
  }
  table.simple td {
    border: none;
    border-bottom: 1px solid #f0f1f3;
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    font-size: 13px;
  }
  table.simple td:last-child { border-bottom: none; }
  /* Le libelle de colonne, injecte en data-label par un petit script */
  table.simple td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 11.5px;
    text-align: left;
    flex-shrink: 0;
  }
  /* Cellule d'actions (boutons) : sur toute la largeur, boutons cote a cote */
  table.simple td.actions-cell { flex-wrap: wrap; justify-content: flex-start; }
  table.simple td.actions-cell::before { width: 100%; }
  table.simple td.actions-cell .btn { flex: 1; min-width: 90px; justify-content: center; }
  table.simple td.actions-cell form { flex: 1; display: flex; }
  table.simple td.actions-cell form .btn { width: 100%; }
  /* Cellule de decision (radios Remplacer/Conserver) : label au-dessus, choix en dessous */
  table.simple td.decision-cell { flex-direction: column; align-items: flex-start; text-align: left; gap: 6px; }
  table.simple td.decision-cell::before { width: 100%; }

  /* Modale mobile : centree, compacte, hauteur limitee avec defilement interne.
     (Le plein ecran precedent etait trop imposant.) */
  .modal-backdrop { align-items: center; justify-content: center; padding: 16px; }
  .modal, .modal.modal-wide {
    width: 100%;
    max-width: 440px;
    max-height: 82dvh;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .modal h3 { font-size: 15px; margin-bottom: 2px; }
  .modal .sub { font-size: 12px; }
  /* Les zones scrollables internes s'etendent, les actions restent visibles en bas */
  .modal .type-list { flex: 1 1 auto; max-height: none; overflow-y: auto; }
  .modal .modal-actions { margin-top: 12px; flex-shrink: 0; }

  /* Liste d'alertes plus compacte : moins d'espace, texte plus petit */
  .alert-scroll { max-height: none; flex: 1 1 auto; }
  #alertModal .pill { padding: 1px 6px !important; font-size: 11px !important; }

  /* Boutons plus hauts pour le tactile (cible min ~44px) */
  .btn { padding: 10px 16px; }
  .btn-sm { padding: 7px 12px; }
}

/* ============================================================
   VUE MOBILE : meme grille que le bureau, sur quelques jours
   ============================================================ */
.mobile-grid-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.mobile-grid-nav .nav-btn { width: 44px; height: 44px; font-size: 18px; flex-shrink: 0; }

.span-switch {
  display: flex;
  background: #eef0f3;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.span-switch a {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 8px;
}
.span-switch a.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(16,24,40,.1);
}

.mobile-grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

/* La grille mobile reutilise .cal.fit : colonnes reparties, mais avec des cases
   plus grandes et lisibles au doigt (contrairement au mode "mois entier"). */
table.mobile-cal { min-width: 0; width: 100%; }
table.mobile-cal thead th {
  min-width: 0;
  padding: 10px 4px;
  font-size: 12px;
}
table.mobile-cal td.name-col,
table.mobile-cal th.name-col {
  min-width: 118px;
  width: 118px;
  padding: 8px 10px;
}
table.mobile-cal .avatar { width: 26px; height: 26px; font-size: 11px; }
table.mobile-cal .tech-meta .tname { font-size: 12.5px; line-height: 1.25; }
table.mobile-cal .tech-meta .trole { font-size: 10px; }

/* Cases : hauteur confortable, tuiles bien visibles */
table.mobile-cal .day-cell { min-height: 56px; }
table.mobile-cal .half { min-height: 27px; }
table.mobile-cal .pill {
  font-size: 13px;
  padding: 6px 4px;
  white-space: normal;
  font-weight: 700;
}
table.mobile-cal .pill.full-cell { margin: 3px; }
/* On garde les libelles matin/apm masques mais les cases restent cliquables */
table.mobile-cal .half.empty { font-size: 0; }
