/* ── 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: #deecf9;
  --dg: #d13438; --sc: #107c41; --warn: #d83b01; --info: #0078d4;
}
[data-theme="dark"] {
  --b1: #1b1b1b; --b2: #252525; --b3: #2d2d2d; --b4: #383838;
  --br: #555; --br-light: #444;
  --t1: #f3f2f1; --t2: #a19f9d; --t3: #666; --ac: #4da6ff; --ac-light: #1a3a5c;
  --dg: #f1707b; --sc: #5ec96e; --warn: #f7773c; --info: #4da6ff;
}

/* ── Reset & base ──────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }
body { background: var(--b1); color: var(--t1); display: flex; flex-direction: column; height: 100vh; overflow: hidden; font-size: .875rem; }
input, select, textarea, button { font-family: inherit; font-size: inherit; color: var(--t1); }
input[type="text"], input[type="password"], input[type="search"], input[type="number"],
input[type="date"], select, textarea {
  background: var(--b2); border: 1px solid var(--br-light); border-radius: 2px;
  padding: 6px 8px; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--ac); box-shadow: 0 0 0 1px var(--ac); }
label { display: block; font-size: .75rem; color: var(--t2); margin-bottom: 4px; font-weight: 600; }

/* ── Layout shell ──────────────────────────────────────── */
.h { display: none !important; }
#L { position: fixed; inset: 0; background: var(--b1); display: flex; align-items: center; justify-content: center; z-index: 9999; }
header { background: var(--ac); color: #fff; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; gap: 12px; }
header h2 { font-size: .95rem; font-weight: 700; }
nav { background: var(--b2); display: flex; border-bottom: 1px solid var(--br-light); padding: 0 16px; flex-shrink: 0; overflow-x: auto; }
.toolbar { background: var(--b2); padding: 8px 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--br-light); flex-shrink: 0; }
main { flex: 1; overflow: auto; padding: 16px; }

/* ── Login ─────────────────────────────────────────────── */
.login-box { background: var(--b2); padding: 40px; border-radius: 4px; width: 100%; max-width: 400px; border: 1px solid var(--br-light); box-shadow: 0 10px 30px rgba(0,0,0,.1); }
.login-box h2 { margin-bottom: 24px; color: var(--ac); }
.input-group { margin-bottom: 16px; }
.input-group input { width: 100%; }
.login-error { color: var(--dg); font-size: .8rem; min-height: 20px; margin-bottom: 8px; }

/* ── Navigation tabs ───────────────────────────────────── */
.t-btn { padding: 12px 16px; border: none; background: transparent; cursor: pointer; border-bottom: 3px solid transparent; color: var(--t2); white-space: nowrap; font-size: .82rem; transition: color .15s; }
.t-btn:hover { color: var(--t1); }
.t-btn.active { color: var(--ac); border-bottom-color: var(--ac); font-weight: 600; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 16px; border: 1px solid var(--ac); background: var(--ac); color: #fff;
  border-radius: 2px; cursor: pointer; font-weight: 600; font-size: .82rem;
  transition: opacity .15s, background .15s; white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: .78rem; }
.btn-xs { padding: 3px 8px; font-size: .72rem; }
.btn-ghost { background: transparent; color: var(--t1); border-color: var(--br-light); }
.btn-ghost:hover { background: var(--b4); }
.btn-danger { background: var(--dg); border-color: var(--dg); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success { background: var(--sc); border-color: var(--sc); color: #fff; }
.btn-success:hover { opacity: .85; }

/* ── Cards & layout helpers ────────────────────────────── */
.card { background: var(--b2); border: 1px solid var(--br-light); border-radius: 4px; padding: 20px; margin-bottom: 16px; }
.card-grid { display: grid; gap: 12px; margin-bottom: 16px; }

/* Sub-tab buttons */
.stab { background: var(--b3); color: var(--t2); border-color: var(--br-light); }
.stab.active { background: var(--ac); color: #fff; border-color: var(--ac); }

/* ── Forms ─────────────────────────────────────────────── */
.form-row { display: grid; gap: 12px; margin-bottom: 14px; }
.form-row.c2 { grid-template-columns: 1fr 1fr; }
.form-row.c3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row > div { display: flex; flex-direction: column; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }

/* ── Badges ────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .72rem; font-weight: 700; background: var(--b4); color: var(--t2); }
.badge-ok   { background: rgba(16,124,65,.12); color: var(--sc); }
.badge-warn { background: rgba(216,59,1,.1);   color: var(--warn); }
.badge-err  { background: rgba(209,52,56,.1);  color: var(--dg); }
.badge-info { background: var(--ac-light);     color: var(--ac); }

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { background: var(--b2); border: 1px solid var(--br); overflow: auto; max-height: calc(100vh - 175px); border-radius: 2px; }
.plan-h { max-height: calc(100vh - 220px); }
table { border-collapse: collapse; width: 100%; table-layout: fixed; }
th, td { border: 1px solid var(--br-light); text-align: center; height: 38px; font-size: .72rem; overflow: hidden; }
th { background: var(--b3); position: sticky; top: 0; z-index: 5; font-weight: 600; color: var(--t2); }
.sticky-col { position: sticky; left: 0; background: var(--b3) !important; z-index: 10; border-right: 2px solid var(--br) !important; width: 140px; min-width: 140px; text-align: left; padding-left: 8px; }
.v { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-weight: 700; cursor: pointer; font-size: .7rem; transition: filter .1s; }
.v:hover { filter: brightness(.92); }

/* Colonnes de date : classes générées par _rend() */
.col-today { background: rgba(15,108,189,.08) !important; }
.col-today th, .col-today td { background: rgba(15,108,189,.08) !important; }
th.col-today { color: var(--ac) !important; }
.weekend { background: var(--b4) !important; }
.jf-cell { background: rgba(251,113,133,.12) !important; }
th.jf-cell { color: #c0394a !important; }

/* Sous-titre jour dans l'en-tête */
.day-sub { display: block; font-size: .58rem; font-weight: 400; color: var(--t3); line-height: 1; }
th.col-today .day-sub { color: var(--ac); }

/* Stats */
.stats-cell { padding: 4px 6px; font-size: .7rem; color: var(--t2); line-height: 1.4; text-align: center; }
.total-h { font-weight: 700; color: var(--ac); }

/* Cellule sélectionnée (navigation clavier) */
.cur-cell { outline: 2px solid var(--ac); outline-offset: -2px; }
.warn-cell { outline: 2px solid var(--dg) !important; }

/* Cellules éditables / lecture seule */
.editable { cursor: pointer; }
.editable:hover { background: color-mix(in srgb, var(--ac-light) 40%, transparent) !important; }
.readonly { cursor: default; }

/* Indicateur de note sur une cellule */
.note-dot::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 5px; height: 5px; background: var(--warn); border-radius: 50%;
}
.v.note-dot { position: relative; }

/* Vue semaine : proposition en attente (agent) */
.pending-proposal { opacity: .7; }
.pending-proposal::after {
  content: '⏳'; position: absolute; bottom: 1px; right: 2px; font-size: .5rem;
}
.v.pending-proposal { position: relative; }

/* Cellule proposable par l'agent connecté */
.cell-propose { cursor: pointer; }
.cell-propose:hover { filter: brightness(.94); }

/* ── Légende header ────────────────────────────────────── */
.leg-item { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; color: #fff; }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Popup cellule ─────────────────────────────────────── */
.pop-btn {
  display: flex; align-items: center; gap: 6px; padding: 7px 10px;
  border: none; border-radius: 3px; cursor: pointer; font-weight: 700;
  font-size: .78rem; transition: filter .1s;
}
.pop-btn:hover { filter: brightness(.9); }
.pop-btn-lbl { font-size: .62rem; font-weight: 400; opacity: .85; }

/* ── History ───────────────────────────────────────────── */
.hist-item { display: flex; align-items: baseline; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--b4); font-size: .8rem; }
.hist-item:last-child { border-bottom: none; }
.hist-time { color: var(--t3); font-size: .7rem; white-space: nowrap; flex-shrink: 0; }
.hist-text { flex: 1; line-height: 1.4; }

/* ── Agent cards ───────────────────────────────────────── */
.agent-card { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--b3); border: 1px solid var(--br-light); border-radius: 4px; margin-bottom: 8px; gap: 10px; }
.agent-info { flex: 1; }
.agent-info strong { font-size: .85rem; }
.agent-cycle { font-size: .72rem; color: var(--t2); margin-top: 3px; }
.agent-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Demand / notification cards ───────────────────────── */
.demand-card { background: var(--b3); border: 1px solid var(--br-light); border-radius: 4px; padding: 12px 14px; margin-bottom: 10px; }
.demand-body { font-size: .8rem; line-height: 1.6; margin-bottom: 10px; }
.demand-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notif-card { background: var(--b3); border: 1px solid var(--br-light); border-radius: 4px; padding: 12px 14px; margin-bottom: 10px; }
.nc-agent { font-weight: 700; font-size: .85rem; margin-bottom: 6px; }
.nc-detail { font-size: .8rem; color: var(--t2); line-height: 1.5; margin-bottom: 10px; }
.nc-actions { display: flex; gap: 8px; }

/* ── Dashboard ─────────────────────────────────────────── */
.stat-card { background: var(--b3); border: 1px solid var(--br-light); border-radius: 4px; padding: 16px; text-align: center; }
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--ac); line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: .72rem; color: var(--t2); text-transform: uppercase; letter-spacing: .04em; }
.chart-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chart-bar-label { width: 130px; font-size: .78rem; text-align: right; color: var(--t2); flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-bar-bg { flex: 1; background: var(--b4); border-radius: 2px; height: 22px; overflow: hidden; }
.chart-bar-fill { height: 100%; display: flex; align-items: center; padding-left: 6px; font-size: .7rem; font-weight: 700; color: #fff; min-width: 2px; transition: width .3s; white-space: nowrap; }
.chart-bar-val { width: 50px; font-size: .75rem; color: var(--t2); flex-shrink: 0; }

/* ── Toast ─────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 99999; padding: 10px 20px; border-radius: 4px;
  font-size: .82rem; font-weight: 600; color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s;
  white-space: nowrap;
}
#toast.show { opacity: 1; pointer-events: auto; }
#toast.ok   { background: #107c41; }
#toast.warn { background: #d83b01; }
#toast.err  { background: #d13438; }
#toast.info { background: #0078d4; }

/* ── Status indicator ──────────────────────────────────── */
#st { font-size: .82rem; font-weight: 700; }

/* ── Print en-tête ─────────────────────────────────────── */
.no-screen { display: none; }
#print-header { display: none; padding: 0 0 8px; border-bottom: 2px solid #0f6cbd; margin-bottom: 10px; }
#print-title { font-size: 1rem; font-weight: 700; color: #0f6cbd; }
#print-subtitle { font-size: .72rem; color: #605e5c; margin-top: 2px; }

/* ── Quota badges ──────────────────────────────────────── */
.quota-badge {
  display: inline-block; padding: 2px 7px; border-radius: 10px;
  font-size: .7rem; font-weight: 700; background: var(--b4); color: var(--t2);
}
.quota-ok   { background: rgba(16,124,65,.1);  color: var(--sc); }
.quota-warn { background: rgba(209,52,56,.12); color: var(--dg); }

/* ── Scrollbars ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--b3); }
::-webkit-scrollbar-thumb { background: var(--br-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--br); }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
  .form-row.c2, .form-row.c3 { grid-template-columns: 1fr; }
  .chart-bar-label { width: 80px; }
  .t-btn { padding: 10px 10px; font-size: .75rem; }
  .sticky-col { width: 90px; min-width: 90px; }
}

/* ══════════════════════════════════════════════════════════
   IMPRESSION
   ══════════════════════════════════════════════════════════ */
@media print {
  /* Page : orientation paysage, marges réduites */
  @page { size: A4 landscape; margin: 8mm 10mm; }

  /* Forcer l'impression des couleurs de fond */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Masquer les éléments d'interface */
  header, nav, .toolbar, #lot-bar, #toast,
  #cell-popup, #notif-overlay, #diag-overlay,
  .no-print, .btn, button { display: none !important; }

  /* Afficher l'en-tête impression */
  #print-header { display: block !important; }
  .no-screen { display: block !important; }

  /* Mise en page corps */
  body {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
    background: #fff !important;
    color: #000 !important;
    font-size: .7rem;
  }
  main { padding: 0 !important; overflow: visible !important; }
  #PLAN { display: block !important; }

  /* Wrapper table */
  .table-wrap, .plan-h {
    overflow: visible !important;
    max-height: none !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  /* Table : auto-layout, chaque colonne s'adapte à son contenu */
  table {
    table-layout: fixed !important;
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: .55rem !important;
    page-break-inside: auto;
  }

  /* ── Colonne agents (première colonne) ── */
  /* th et td de la sticky-col : affichage forcé, texte visible */
  th.sticky-col,
  td.sticky-col {
    position: static !important;  /* annuler le sticky */
    display: table-cell !important;
    visibility: visible !important;
    width: 100px !important;
    min-width: 100px !important;
    max-width: 100px !important;
    border-right: 2px solid #8a8886 !important;
    text-align: left !important;
    padding: 2px 4px !important;
    font-size: .58rem !important;
    font-weight: 600 !important;
    color: #000 !important;
    /* Permettre le retour à la ligne pour les noms longs */
    white-space: normal !important;
    overflow: visible !important;
    word-break: break-word !important;
  }
  td.sticky-col {
    background: #f3f2f1 !important;
  }
  th.sticky-col {
    background: #0f6cbd !important;
    color: #fff !important;
  }

  /* ── Colonnes jours (th et td) ── */
  th, td {
    border: 1px solid #c8c6c4 !important;
    height: 18px !important;
    padding: 1px 0 !important;
    font-size: .53rem !important;
    overflow: hidden !important;
    text-align: center !important;
  }

  th:not(.sticky-col) {
    background: #edebe9 !important;
    color: #333 !important;
    font-size: .5rem !important;
    width: auto !important;
  }

  /* Sous-titres jours */
  .day-sub { display: block !important; font-size: .44rem !important; line-height: 1; }

  /* ── Cellules vacation : conserver les couleurs ── */
  .v {
    width: 100% !important;
    height: 16px !important;
    font-size: .55rem !important;
    font-weight: 700 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Mise en évidence week-end et jours fériés */
  .weekend           { background: #e8e8e8 !important; }
  .jf-cell           { background: rgba(251,113,133,.2) !important; }
  .col-today         { background: rgba(15,108,189,.1) !important; }
  th.jf-cell         { color: #a00020 !important; }
  th.col-today       { color: #0f6cbd !important; }

  /* Colonne stats / totaux */
  .stats-cell { font-size: .5rem !important; padding: 1px 2px !important; }
  .total-h    { font-size: .53rem !important; font-weight: 700 !important; }

  /* Éviter les coupures de ligne au milieu d'un agent */
  tr { page-break-inside: avoid; }
}
