:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #3b82f6;
  --danger: #ef4444;
  --hour-h: 64px; /* sera recalculé par JS */
  --grid-border: #eef0f4;
}

* { box-sizing: border-box; }

/* L'attribut HTML `hidden` doit toujours masquer, même quand on a défini
   un display explicite dans une classe. */
[hidden] { display: none !important; }

html {
  height: 100vh;
  overflow: hidden;
}
body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 20px;
  flex-wrap: wrap;
}

.topbar .left { display: flex; align-items: center; gap: 14px; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.status .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #cbd5e1;
  transition: background 0.3s;
}
.status.connected .dot { background: #22c55e; }
.status.disconnected .dot { background: var(--danger); }

.center {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-btn, .today-btn, .btn-ghost, .btn-primary, .btn-delete {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.nav-btn { font-size: 20px; line-height: 1; padding: 2px 10px; }
.nav-btn:hover, .today-btn:hover, .btn-ghost:hover { background: #f3f4f6; }
.week-label { font-weight: 500; min-width: 180px; text-align: center; color: var(--muted); }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-add {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-add:hover { background: #2563eb; border-color: #2563eb; }
.btn-add .plus { font-size: 18px; line-height: 1; }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.btn-delete {
  background: white;
  color: var(--danger);
  border-color: #fecaca;
}
.btn-delete:hover { background: #fef2f2; }

.right .me {
  display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted);
}
.right input[type="text"] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  width: 120px;
  font-family: inherit;
}
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}

/* Calendrier */
.calendar-wrap {
  padding: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.calendar {
  display: grid;
  grid-template-columns: 44px repeat(7, minmax(100px, 1fr));
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow: hidden;
  min-width: 900px;
}

.day-header, .hour-cell, .slot, .hour-label, .corner {
  border-right: 1px solid var(--grid-border);
  border-bottom: 1px solid var(--grid-border);
}

.corner, .day-header {
  background: #fafbfc;
  position: sticky;
  top: 0;
  z-index: 3;
  border-bottom: 1px solid var(--border);
}
.corner { border-right: 1px solid var(--border); }

.day-header {
  padding: 10px 8px;
  text-align: center;
  font-size: 13px;
  border-right: 2px solid #9ca3af;
}
.day-header .name { font-weight: 600; }
.day-header .date { color: var(--muted); font-size: 12px; margin-top: 2px; }
.day-header .tech-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
  opacity: 0.7;
}
.day-header.today .name { color: var(--accent); }
.day-header.today .date {
  display: inline-block;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: 2px;
}

.hour-label {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding: 2px 6px;
  background: #fafbfc;
  height: var(--hour-h);
  position: sticky;
  left: 0;
  z-index: 2;
  border-right: 1px solid var(--border);
}

.day-col {
  position: relative;
  border-right: 2px solid #9ca3af;
}
/* Ligne de séparation Régis | Maxime */
.day-col::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
  pointer-events: none;
  z-index: 0;
}

.slot {
  height: var(--hour-h);
  cursor: pointer;
  transition: background 0.1s;
}
.slot:hover { background: #eff6ff; }

/* Événements */
.event {
  position: absolute;
  left: 4px;
  right: 4px;
  border-radius: 6px;
  padding: 4px 5px;
  font-size: 11px;
  color: white;
}
.event.maxime {
  color: #1a1a1a;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  transition: transform 0.1s, box-shadow 0.1s;
  z-index: 1;
  line-height: 1.3;
}
.event:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
  z-index: 2;
}
.event .ev-title { font-weight: 600; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.event .ev-time { opacity: 0.9; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event .ev-author { opacity: 0.85; font-size: 11px; font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event .ev-lieu { opacity: 0.9; font-size: 11px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.event .ev-tech { opacity: 0.92; font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event.flash { animation: flashPulse 0.8s ease-out; }

@keyframes flashPulse {
  0%   { box-shadow: 0 0 0 3px rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.12); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0),   0 1px 3px rgba(0,0,0,0.12); }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}
.modal {
  background: white;
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.modal input[type="text"], .modal input[type="date"], .modal select, .modal textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.modal textarea { resize: vertical; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }
/* Sélecteur technicien */
.technicien-picker {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.tech-btn {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.tech-btn:hover { background: #f3f4f6; }
.tech-btn.selected {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--accent);
}

/* Étiquette technicien dans les événements */
.event .ev-tech { opacity: 0.92; font-size: 11px; font-weight: 600; }

.colors { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.colors .swatch {
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
}
.colors .swatch.selected {
  border-color: white;
  box-shadow: 0 0 0 2px var(--accent);
}
.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
}
.modal-actions .spacer { flex: 1; }
.modal-meta {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

/* Modale de détail */
.detail-modal { max-width: 420px; padding: 0; overflow: hidden; }

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-color-bar {
  width: 6px;
  min-height: 48px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
}
.detail-title-wrap { flex: 1; }
.detail-title-wrap h2 { margin: 0 0 4px; font-size: 18px; line-height: 1.3; }
.detail-tech {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent);
}
.detail-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}
.detail-close:hover { color: var(--text); }

.detail-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
}
.detail-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }

.detail-meta {
  padding: 0 20px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.detail-modal .modal-actions { padding: 12px 20px 20px; margin-top: 0; border-top: 1px solid var(--border); }

@media (max-width: 700px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .center, .right { justify-content: center; }
  .week-label { min-width: auto; }
}
