/* ===========================================================================
   styles.css — Raffinements (Apple / Notion / Stripe)
   =========================================================================== */

:root {
  --ccih-red: #AD2A1E;
  --ccih-red-dark: #8f2218;
  --ccih-red-soft: #fbeae8;

  --ink: #1a1a1a;
  --ink-soft: #5b5b5b;
  --ink-faint: #8a8a8a;
  --line: #ebebeb;
  --line-strong: #e0e0e0;
  --bg: #fbfbfa;
  --surface: #ffffff;

  /* Domaines */
  --alfa: #2563eb;        --alfa-bg: #eef4ff;
  --avs: #0f9d6b;         --avs-bg: #e9f8f1;
  --transverse: #b45309;  --transverse-bg: #fdf3e7;

  --ok: #16a34a;
  --warn: #d97706;
  --error: #dc2626;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-md: 0 4px 12px rgba(16,24,40,.06), 0 2px 4px rgba(16,24,40,.04);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.12), 0 4px 8px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
    Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 14px;
  line-height: 1.45;
}

::selection { background: var(--ccih-red-soft); }

/* Scrollbars discrètes */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d8d8d6; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #c3c3c0; }

/* --- Boutons ---------------------------------------------------------------*/
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 9px; font-weight: 550; font-size: 13px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: all .14s ease; white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: #fafafa; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--ccih-red); border-color: var(--ccih-red); color: #fff;
}
.btn-primary:hover { background: var(--ccih-red-dark); }
.btn-ghost { border-color: transparent; box-shadow: none; background: transparent; }
.btn-ghost:hover { background: #f1f1ef; box-shadow: none; }
.btn-icon { padding: 7px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* --- Cartes ----------------------------------------------------------------*/
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-sm);
}

/* --- Puces (personnes affectées) ------------------------------------------*/
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer; transition: all .12s ease;
  max-width: 100%;
}
.chip:hover { filter: brightness(.97); }
.chip .x { opacity: 0; font-size: 13px; line-height: 1; transition: opacity .12s; margin-left: 1px; }
.chip:hover .x { opacity: .6; }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; }

.dom-ALFA       { background: var(--alfa-bg);       color: #1e40af; }
.dom-ALFA .chip-dot       { background: var(--alfa); }
.dom-AVS        { background: var(--avs-bg);        color: #066e4b; }
.dom-AVS .chip-dot        { background: var(--avs); }
.dom-TRANSVERSE { background: var(--transverse-bg); color: #92400e; }
.dom-TRANSVERSE .chip-dot { background: var(--transverse); }

/* --- Slot (créneau matin/aprem) -------------------------------------------*/
.slot {
  border-radius: 10px; padding: 8px; transition: background .12s;
  border: 1px solid transparent;
}
.slot:hover { background: #fafaf9; }
.slot-warn  { background: #fffaf0; }
.slot-error { background: #fef4f4; }

.slot-add {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 999px; border: 1px dashed var(--line-strong);
  color: var(--ink-faint); cursor: pointer; font-size: 14px; transition: all .12s;
}
.slot-add:hover { border-color: var(--ccih-red); color: var(--ccih-red); background: var(--ccih-red-soft); }

/* --- Pastilles statut ------------------------------------------------------*/
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-error { background: var(--error); }

/* --- Cellules calendrier ---------------------------------------------------*/
.day-cell { background: var(--surface); }
.day-cell.is-holiday { background: repeating-linear-gradient(45deg,#f6f6f5,#f6f6f5 8px,#f0f0ef 8px,#f0f0ef 16px); }
.day-num { font-variant-numeric: tabular-nums; }

/* --- Modale / popover ------------------------------------------------------*/
.overlay {
  position: fixed; inset: 0; background: rgba(20,20,20,.32);
  backdrop-filter: blur(2px); z-index: 40; opacity: 0; pointer-events: none;
  transition: opacity .16s;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; top: 0; right: 0; height: 100%; width: 420px; max-width: 92vw;
  background: var(--surface); z-index: 50; box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .22s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
}
.sheet.open { transform: translateX(0); }

.popover {
  position: absolute; z-index: 60; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 300px; max-height: 360px; overflow: auto; padding: 6px;
}

/* --- Liste de sélection (popover ajout) -----------------------------------*/
.opt {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 8px;
  cursor: pointer; font-size: 13px;
}
.opt:hover { background: #f5f5f4; }
.opt.disabled { opacity: .45; cursor: not-allowed; }
.opt.disabled:hover { background: transparent; }

/* --- Inputs ----------------------------------------------------------------*/
.input, select.input {
  border: 1px solid var(--line-strong); border-radius: 9px; padding: 7px 10px;
  font-size: 13px; background: var(--surface); color: var(--ink); width: 100%;
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--ccih-red); box-shadow: 0 0 0 3px var(--ccih-red-soft); }

/* --- toggles présence ------------------------------------------------------*/
.pres-cell {
  width: 26px; height: 22px; border-radius: 6px; border: 1px solid var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 10px; color: var(--ink-faint); user-select: none; transition: all .1s;
}
.pres-cell.on { background: var(--ccih-red); border-color: var(--ccih-red); color: #fff; }

/* --- Mobile -----------------------------------------------------------------*/
@media (max-width: 640px) {
  /* en-tête : barres défilables horizontalement plutôt que débordantes */
  header > div { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  header > div::-webkit-scrollbar { height: 0; }
  main { padding-left: 12px; padding-right: 12px; }
  .day-cell { border-radius: 12px; }
  /* puces un peu plus grandes au doigt */
  .chip { padding: 4px 9px; font-size: 12.5px; }
  .slot-add { width: 26px; height: 26px; }
}

/* --- Fade-in ---------------------------------------------------------------*/
@keyframes fadeUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeUp .2s ease both; }

.tab { padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 550; cursor: pointer; color: var(--ink-soft); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* --- Badge "2×" sur une puce (2ᵉ demi-journée de la semaine) ---------------*/
.chip-badge {
  font-size: 9px; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 5px;
  background: rgba(0,0,0,.12); color: inherit; margin-left: 1px;
}
.load-tag {
  font-size: 9px; font-weight: 700; padding: 1px 4px; border-radius: 5px;
  background: var(--warn); color: #fff;
}

/* --- Surlignage (tri par personne / domaine) -------------------------------*/
.chip-dim { opacity: .18; }
.chip-hl { box-shadow: 0 0 0 2px var(--ccih-red); font-weight: 650; }

/* --- Glisser-déposer --------------------------------------------------------*/
.chip[draggable="true"] { cursor: grab; }
.chip.dragging { opacity: .4; }
.slot.drop-target { background: var(--ccih-red-soft); box-shadow: inset 0 0 0 2px var(--ccih-red); }

/* --- Toast ------------------------------------------------------------------*/
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 11px;
  box-shadow: var(--shadow-lg); padding: 10px 16px; font-size: 13px; z-index: 80;
  display: flex; align-items: center; gap: 8px; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- Impression / PDF -------------------------------------------------------*/
.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  html, body { background: #fff; font-size: 10px; }
  header, #alertsPanel summary span:last-child, #toast, .overlay, .sheet, .popover,
  .slot-add, .chip .x, .print-hide, #peopleBtn, #printBtn, #resetBtn, #generateBtn { display: none !important; }
  .chip-dim { opacity: 1 !important; } /* à l'impression, pas d'atténuation */
  .print-only { display: block; }
  main { max-width: none !important; padding: 0 !important; }
  #printHeader img { height: 26px; }
  #calendar { gap: 4px; }
  .day-cell { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .chip { border: 1px solid #ddd; }
  /* Couleurs des puces fidèles à l'écran */
  .chip, .chip-dot, .dot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #alertsPanel details { break-inside: avoid; }
  #statsPanel { break-before: page; }
}
