/* ── Variables ────────────────────────────────────── */
:root {
  --b1: #f3f2f1; --b2: #ffffff; --b3: #faf9f8; --b4: #edebe9;
  --br: #8a8886; --br-light: #c8c6c4;
  --t1: #201f1e; --t2: #605e5c; --t3: #a19f9d;
  --ac: #0f6cbd; --ac-light: #eff6ff;
  --dg: #d13438; --sc: #107c41; --warn: #d83b01; --info: #0078d4;
}

/* ── Reset & base ────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif; }
body { background: var(--b1); color: var(--t1); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.h { display: none !important; }

/* ── Login ───────────────────────────────────────── */
#L { position: fixed; inset: 0; background: var(--b1); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.login-box { background: var(--b2); padding: 40px; border-radius: 4px; width: 100%; max-width: 380px; border: 1px solid var(--br-light); box-shadow: 0 10px 30px rgba(0,0,0,.1); }
.login-box h2 { margin-bottom: 20px; color: var(--ac); font-size: 1.2rem; }
.login-error { color: var(--dg); font-size: .8rem; min-height: 18px; margin: 6px 0; }

/* ── Structure ───────────────────────────────────── */
header { background: var(--ac); color: #fff; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
nav { background: var(--b2); display: flex; border-bottom: 1px solid var(--br-light); padding: 0 8px; overflow-x: auto; flex-shrink: 0; }
.toolbar { background: var(--b2); padding: 8px 16px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--br-light); flex-wrap: wrap; flex-shrink: 0; }
main { flex: 1; overflow: auto; padding: 16px; min-height: 0; }

/* ── Navigation principale ───────────────────────── */
.t-btn { padding: 11px 14px; border: none; background: transparent; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; font-size: .82rem; color: var(--t1); transition: background .1s; }
.t-btn:hover { background: var(--b3); }
.t-btn.active { color: var(--ac); border-bottom-color: var(--ac); font-weight: 600; }

/* ── Sous-onglets (stab) ─────────────────────────── */
.stab-bar { display: flex; border-bottom: 1px solid var(--br-light); margin-bottom: 14px; overflow-x: auto; }
.stab { padding: 8px 14px; border: none; background: transparent; cursor: pointer; border-bottom: 2px solid transparent; font-size: .78rem; color: var(--t2); white-space: nowrap; }
.stab:hover { background: var(--b3); }
.stab.active { color: var(--ac); border-bottom-color: var(--ac); font-weight: 600; }

/* ── Boutons ─────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 7px 14px; border: 1px solid transparent; border-radius: 2px; cursor: pointer; font-size: .82rem; font-weight: 600; background: var(--ac); color: #fff; transition: opacity .15s; line-height: 1.2; }
.btn:hover { opacity: .87; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm  { padding: 5px 10px; font-size: .75rem; }
.btn-xs  { padding: 3px 7px;  font-size: .68rem; }
.btn-ghost   { background: transparent; color: var(--ac); border-color: var(--br-light); }
.btn-ghost:hover { background: var(--b3); }
.btn-danger  { background: var(--dg); color: #fff; }
.btn-success { background: var(--sc); color: #fff; }
.btn-warn    { background: var(--warn); color: #fff; }

/* ── Inputs & formulaires ────────────────────────── */
input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="month"],
input[type="search"], textarea, select {
  padding: 6px 9px; border: 1px solid var(--br-light); border-radius: 2px;
  font-size: .82rem; background: var(--b2); color: var(--t1); font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--ac); outline-offset: 1px; border-color: var(--ac); }
textarea { resize: vertical; }
.input-group { margin-bottom: 12px; }
.input-group label { display: block; font-size: .78rem; color: var(--t2); margin-bottom: 5px; font-weight: 600; }
.form-row { display: grid; gap: 10px; margin-bottom: 10px; }
.form-row.c2 { grid-template-columns: 1fr 1fr; }
.form-row.c3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row label { display: block; font-size: .72rem; color: var(--t2); margin-bottom: 3px; font-weight: 600; }

/* ── Cartes ──────────────────────────────────────── */
.card { background: var(--b2); border: 1px solid var(--br-light); border-radius: 4px; padding: 16px; margin-bottom: 12px; }
.card-grid { display: grid; gap: 10px; margin-bottom: 16px; }

/* ── Badges ──────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px; font-size: .68rem; font-weight: 600; background: var(--b4); color: var(--t2); }
.badge-warn { background: rgba(216,59,1,.12);   color: var(--warn); }
.badge-ok   { background: rgba(16,124,65,.12);  color: var(--sc);   }
.badge-err  { background: rgba(209,52,56,.12);  color: var(--dg);   }
.badge-info { background: rgba(15,108,189,.12); color: var(--ac);   }

/* ── Table planning ──────────────────────────────── */
.table-wrap { background: var(--b2); border: 1px solid var(--br); overflow: auto; max-height: calc(100vh - 210px); }
table { border-collapse: collapse; table-layout: fixed; }
th, td { border: 1px solid var(--br-light); text-align: center; height: 38px; font-size: .75rem; white-space: nowrap; }
th { background: var(--b3); position: sticky; top: 0; z-index: 5; font-weight: 600; }
.sticky-col { position: sticky; left: 0; background: var(--b3) !important; z-index: 10; border-right: 2px solid var(--br) !important; width: 150px; min-width: 150px; text-align: left; padding-left: 8px; }
/* Colonnes jours : largeur fixe identique pour tous (évite écarts M/S/D) */
#p-wrap th:not(.sticky-col), #p-wrap td:not(.sticky-col),
#w-wrap th:not(.sticky-col), #w-wrap td:not(.sticky-col) { width: 36px; min-width: 36px; }
#w-wrap th:not(.sticky-col) { min-width: 110px; width: 110px; }
#a-wrap th:not(.sticky-col), #a-wrap td:not(.sticky-col) { width: 28px; min-width: 28px; }
/* Écart visuel entre agents dans la vue mensuelle */
#p-wrap tbody tr:not(:last-child) td { border-bottom: 4px solid var(--b1); }
.day-sub { display: block; font-size: .6rem; color: var(--t3); font-weight: 400; }
.v { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-weight: 700; cursor: pointer; position: relative; }
.col-today { background: #fffbeb !important; }
.weekend { background: rgba(0,0,0,.03) !important; color: var(--t2); }
.jf-cell { background: #fff0f3 !important; }
.editable { cursor: pointer; }
.readonly { cursor: default; }
.cell-propose { cursor: pointer; }
.pending-proposal { opacity: .65; }
.note-dot::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--warn);
}

/* ── Légende ─────────────────────────────────────── */
.legend-wrap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.leg-item { display: flex; align-items: center; gap: 4px; font-size: .72rem; color: var(--t2); }
.leg-dot { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }

/* ── Agents ──────────────────────────────────────── */
.agent-card { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--b3); border: 1px solid var(--br-light); border-radius: 4px; margin-bottom: 6px; gap: 10px; }
.agent-info { flex: 1; font-size: .82rem; min-width: 0; }
.agent-cycle { font-size: .7rem; color: var(--t2); margin-top: 3px; word-break: break-all; }
.agent-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Demandes ────────────────────────────────────── */
.demand-card { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--b3); border: 1px solid var(--br-light); border-left: 3px solid var(--ac); border-radius: 4px; margin-bottom: 6px; gap: 10px; }
.demand-body { flex: 1; font-size: .82rem; min-width: 0; }
.demand-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Graphiques en barres ────────────────────────── */
.chart-bar-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: .75rem; }
.chart-bar-label { width: 150px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; color: var(--t2); }
.chart-bar-bg { flex: 1; background: var(--b4); border-radius: 2px; height: 20px; overflow: hidden; min-width: 40px; }
.chart-bar-fill { height: 100%; min-width: 2px; display: flex; align-items: center; padding: 0 6px; font-size: .68rem; font-weight: 700; color: #fff; border-radius: 2px; transition: width .3s ease; }
.chart-bar-val { width: 52px; text-align: left; font-weight: 700; flex-shrink: 0; }

/* ── Historique ──────────────────────────────────── */
.hist-item { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--b4); font-size: .78rem; }
.hist-time { color: var(--t3); white-space: nowrap; flex-shrink: 0; width: 128px; }
.hist-text { flex: 1; color: var(--t1); line-height: 1.4; }

/* ── Statistiques ────────────────────────────────── */
.stat-card { background: var(--b2); border: 1px solid var(--br-light); border-radius: 4px; padding: 12px 10px; text-align: center; }
.stat-num { font-size: 1.55rem; font-weight: 700; color: var(--ac); line-height: 1.1; }
.stat-label { font-size: .7rem; color: var(--t2); margin-top: 3px; }
.stats-cell { font-size: .65rem; line-height: 1.7; padding: 2px 4px; text-align: left; }
.total-h { font-weight: 700; color: var(--sc); }

/* ── Popup cellule ───────────────────────────────── */
#cell-popup {
  position: fixed; z-index: 2000; background: var(--b2);
  border: 1px solid var(--br-light); border-radius: 4px; padding: 10px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18); min-width: 210px; max-width: 250px;
}
#pop-label { font-size: .75rem; font-weight: 700; color: var(--t2); margin-bottom: 8px; }
#pop-vac-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 8px; }
#pop-note-txt { width: 100%; height: 52px; font-size: .75rem; margin-bottom: 6px; resize: none; }
.pop-btn { padding: 6px 4px; border: none; border-radius: 3px; cursor: pointer; font-size: .75rem; font-weight: 700; text-align: center; line-height: 1.2; }
.pop-btn:hover { filter: brightness(.92); }
.pop-btn-lbl { display: block; font-size: .58rem; font-weight: 400; margin-top: 1px; opacity: .85; }

/* ── Overlay notifications ───────────────────────── */
#notif-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.48); z-index: 9999; display: none; align-items: center; justify-content: center; }
.notif-box { background: var(--b2); padding: 24px; border-radius: 6px; max-width: 440px; width: 90%; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0,0,0,.22); }
.notif-box h3 { margin-bottom: 4px; font-size: 1rem; }
#notif-subtitle { font-size: .78rem; color: var(--t2); margin-bottom: 12px; }
#notif-list { flex: 1; overflow-y: auto; margin-bottom: 14px; }
.notif-card { border: 1px solid var(--br-light); border-left: 3px solid var(--ac); border-radius: 4px; padding: 10px 12px; margin-bottom: 8px; }
.nc-agent { font-weight: 700; font-size: .85rem; margin-bottom: 4px; }
.nc-detail { font-size: .78rem; color: var(--t2); margin-bottom: 6px; line-height: 1.4; }
.nc-actions { display: flex; gap: 6px; }

/* ── Toast ───────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--t1); color: #fff; padding: 9px 20px; border-radius: 4px;
  font-size: .82rem; opacity: 0; transition: all .22s ease; z-index: 9999;
  pointer-events: none; white-space: nowrap; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
#toast.show  { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.ok    { background: var(--sc); }
#toast.err   { background: var(--dg); }
#toast.warn  { background: var(--warn); }
#toast.info  { background: var(--info); }

/* ── Statut sync ─────────────────────────────────── */
#st { font-size: .85rem; font-weight: 600; letter-spacing: .01em; }
#st.ok      { color: #6ee7b7; }
#st.err     { color: #fca5a5; }
#st.syncing { color: #fde68a; }

/* ── Section lot (admin) ─────────────────────────── */
.lot-section { background: var(--b3); border: 1px solid var(--br-light); border-radius: 4px; padding: 14px 16px; margin-top: 14px; }
.lot-controls { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.lot-controls label { font-size: .75rem; color: var(--t2); font-weight: 600; }

/* ── Toolbar interne (semaine / annuel) ──────────── */
.inner-toolbar { display: flex; gap: 8px; align-items: center; padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--br-light); flex-wrap: wrap; }

/* ── Mode sombre ─────────────────────────────────── */
[data-theme="dark"] {
  --b1: #1b1a19; --b2: #252423; --b3: #2d2c2b;
  --b4: #3b3a39; --br: #484644; --br-light: #3b3a39;
  --t1: #f3f2f1; --t2: #c8c6c4; --t3: #8a8886;
  --ac: #2899f5; --ac-light: #0c2d4a;
}
[data-theme="dark"] .col-today  { background: #3d3b1e !important; }
[data-theme="dark"] .weekend    { background: rgba(255,255,255,.03) !important; }
[data-theme="dark"] .jf-cell    { background: #3d1c24 !important; }
[data-theme="dark"] th          { background: var(--b3) !important; }

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 700px) {
  header h2 { font-size: .85rem; }
  nav { padding: 0 2px; }
  .t-btn { padding: 9px 7px; font-size: .72rem; }
  .toolbar { padding: 5px 8px; gap: 5px; }
  main { padding: 6px; }
  .sticky-col { width: 80px !important; min-width: 80px !important; font-size: .65rem; padding-left: 4px; }
  #p-wrap th:not(.sticky-col), #p-wrap td:not(.sticky-col) { width: 26px; min-width: 26px; }
  .btn { padding: 5px 9px; font-size: .74rem; }
  .lot-section { padding: 10px; }
  .lot-controls { flex-direction: column; align-items: flex-start; }
}

/* ── Impression ──────────────────────────────────── */
#print-title, #print-subtitle { display: none; }
@media print {
  /* Conserver les couleurs (style Microsoft Fluent) */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  @page { margin: 1cm 0.8cm; size: landscape; }

  /* Masquer les éléments non imprimables */
  .no-print, header, nav, .toolbar, .lot-section,
  #cell-popup, #notif-overlay, #toast { display: none !important; }

  /* Débloquer le scroll pour impression complète */
  html, body { height: auto !important; overflow: visible !important; }
  main { padding: 4px; overflow: visible !important; }
  .table-wrap { overflow: visible !important; max-height: none !important; border: 1px solid var(--br) !important; }

  /* Colonnes agents en impression */
  .sticky-col { position: relative !important; width: 140px !important; background: var(--b4) !important; font-weight: 700; }

  /* Titres impression */
  #print-title   { display: block !important; font-size: 1.05rem; font-weight: 700; color: var(--ac); margin-bottom: 2px; }
  #print-subtitle { display: block !important; font-size: .72rem; color: var(--t2); margin-bottom: 8px; }

  /* Cellules vacations : forcer les couleurs de fond */
  .v { print-color-adjust: exact; -webkit-print-color-adjust: exact; font-size: .68rem; }
  th { background: var(--b3) !important; font-size: .68rem; }
  .col-today { background: #fffbeb !important; }
  .weekend   { background: #f5f5f5 !important; }
  .jf-cell   { background: #fff0f3 !important; }
}
