:root{
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(15,23,42,.10);
  --primary: #2563eb;
  --shadow: 0 10px 28px rgba(15,23,42,.08);
  --radius: 16px;

  --outside: #eef2f7;
  --today: rgba(37,99,235,.10);

  --brouillon: #fde68a;
  --soumis:    #bfdbfe;
  --valide:    #bbf7d0;
  --refuse:    #fecaca;

  --weekend: rgba(15,23,42,.035);
}

*{ box-sizing:border-box; font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
body{ margin:0; background:var(--bg); color:var(--text); }

/* ============================================
   🆕 HEADER - VERSION CORRIGÉE
   ============================================ */

.top-header{
  background:#fff;
  border-bottom:1px solid var(--line);
  box-shadow:0 2px 10px rgba(15,23,42,.05);
}

.top-header__inner{
  max-width:1200px;
  margin:0 auto;
  padding:18px 16px 10px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
}

/* 🆕 Bouton retour portail - Nouveau style */
.portal-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  text-decoration: none;
  color: white;
  transition: all 0.2s ease;
  min-width: 80px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.portal-nav:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.portal-nav__icon {
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.portal-nav__svg {
  width: 28px;
  height: 28px;
  stroke: white;
}

.portal-nav__text {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
  opacity: 0.95;
}

/* Zone titre */
.brand h1{ margin:0; font-size:22px; letter-spacing:.2px; }
.subtitle{ margin:6px 0 0; color:var(--muted); font-size:13px; }

.periode-row{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.periode-pill{
  display:inline-flex;
  align-items:center;
  gap:10px;
  border-radius:999px;
  padding:6px 10px;
  border:1px solid var(--line);
  background:#fff;
  font-weight:800;
}
.periode-pill .label{ color:var(--muted); font-weight:700; }
.periode-pill .value{ font-weight:900; }

.periode-pill.brouillon{ background: var(--brouillon); }
.periode-pill.soumis   { background: var(--soumis); }
.periode-pill.valide   { background: var(--valide); }
.periode-pill.refuse   { background: var(--refuse); }

.status-badge{
  font-size:12px;
  font-weight:800;
  border-radius:999px;
  padding:6px 10px;
  border:1px solid rgba(15,23,42,.12);
  background:#fff;
}

/* ⚠️ SUPPRIMÉ : .btn-validation (géré par unifie.css) */

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-card{
  min-width:240px;
  background:#f8fafc;
  border:1px solid var(--line);
  border-radius:14px;
  padding:10px 12px;
  text-align:right;
}

.agent-card--click{
  cursor: pointer;
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.92);
}

.agent-card--click:hover{
  filter: brightness(.99);
}

.agent-card__label{ color:var(--muted); font-size:12px; }
.agent-card__name{ font-weight:700; font-size:16px; margin-top:4px; }

/* Toolbar */
.toolbar{
  max-width:1200px;
  margin:0 auto;
  padding:12px 16px 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.toolbar__left{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.toolbar__right{ display:flex; gap:10px; }

.muted{ color:var(--muted); font-size:13px; }
.sep{ color:var(--muted); }

.ghost-btn{
  border:1px solid var(--line);
  background:#fff;
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:800;
  font-size:13px;
}
.ghost-btn:hover{ background:#f8fafc; }

.admin-btn{
  border-style: dashed;
}

.ghost-link{
  color:var(--primary);
  text-decoration:none;
  font-weight:600;
}
.ghost-link:hover{ text-decoration:underline; }

/* ===== layout ===== */
.page{
  max-width:1200px;
  margin:18px auto 30px;
  padding:0 16px;
}

/* ===== calendrier ===== */
.calendar-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
}

.calendar-head{
  display:grid;
  grid-template-columns: repeat(7, 1fr);
  background: linear-gradient(180deg, #fff, #fbfdff);
  border-bottom:1px solid var(--line);
}
.dow{
  padding:10px 12px;
  color:var(--muted);
  font-weight:800;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.5px;
  border-right:1px solid var(--line);
}
.dow:last-child{ border-right:none; }
.dow.weekend{ background: var(--weekend); }

.calendar-grid{
  display:grid;
  grid-template-columns: repeat(7, 1fr);
}

.day-cell{
  min-height: 120px;
  border-right:1px solid var(--line);
  border-bottom:1px solid var(--line);
  padding:10px;
  background:#fff;
  display:flex;
  flex-direction:column;
  gap:8px;
  cursor:pointer;
}
.day-cell:nth-child(7n){ border-right:none; }
.day-cell.weekend{ background: var(--weekend); }

.day-cell.outside{
  background: var(--outside);
  color: rgba(15,23,42,.55);
  cursor:default;
}
.day-cell.outside.weekend{
  background: color-mix(in srgb, var(--outside) 80%, var(--weekend) 20%);
}

.day-cell.today{ background: var(--today); }

.day-num{
  font-weight:900;
  font-size:13px;
}

.moves{
  display:flex;
  flex-direction:column;
  gap:6px;
  flex:1;
}

.move-line{
  font-size:12px;
  color: rgba(15,23,42,.85);
  background: rgba(15,23,42,.04);
  border: 1px solid rgba(15,23,42,.08);
  border-radius:10px;
  padding:6px 8px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  cursor:pointer;
}
.move-line:hover{
  background: rgba(37,99,235,.06);
  border-color: rgba(37,99,235,.20);
}

.day-total{
  display:flex;
  justify-content:space-between;
  align-items:center;
  font-size:12px;
  color: var(--muted);
  margin-top:auto;
  padding-top:8px;
  border-top:1px dashed rgba(15,23,42,.18);
}
.day-total strong{ color: var(--text); }

/* ===== notes ===== */
.notes{
  margin-top:16px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:14px 16px;
}
.notes__title{ font-weight:900; margin-bottom:8px; }
.notes__list{ margin:0; padding-left:18px; color:var(--muted); font-size:13px; }

/* ===== tableau détails ===== */
.details-card{
  margin-top:16px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
}

.details-head{
  display:flex;
  align-items:flex-start;
  gap:12px;
  justify-content:space-between;
  padding:14px 16px;
  border-bottom:1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfdff);
}
.details-title{ font-weight:1000; font-size:16px; }
.details-subtitle{ margin-top:6px; color:var(--muted); font-size:12px; }

.table-wrap{
  overflow:auto;
}

.details-table{
  width:100%;
  border-collapse:collapse;
}
.details-table thead{
  background:#f8fafc;
  border-bottom:1px solid var(--line);
}
.details-table th{
  padding:10px 12px;
  text-align:left;
  font-weight:900;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.5px;
  color:var(--muted);
}
.details-table th.num{ text-align:right; }
.details-table th.actions{ text-align:center; }

.details-table tbody tr{
  border-bottom:1px solid var(--line);
}
.details-table tbody tr:hover{
  background:#fafbfc;
}

.details-table td{
  padding:10px 12px;
  font-size:13px;
}
.details-table td.num{
  text-align:right;
  font-variant-numeric:tabular-nums;
}
.details-table td.actions{
  text-align:center;
}

.details-table tfoot td{
  font-weight:900;
  background:#fff;
}
.tfoot-label{
  text-align:right;
  color:var(--muted);
}

/* actions */
.btn{
  border:1px solid rgba(15,23,42,.14);
  background:#fff;
  padding:8px 10px;
  border-radius:12px;
  cursor:pointer;
  font-weight:800;
  font-size:12px;
  margin-left:6px;
}
.btn:hover{ background:#f8fafc; }
.btn.primary{ background: var(--primary); border-color: var(--primary); color:#fff; }
.btn.primary:hover{ filter: brightness(.98); }
.btn.danger{ border-color: rgba(239,68,68,.35); }
.btn.danger:hover{ background: rgba(239,68,68,.06); }

/* ===== légende ===== */
.legend{
  margin-top: 16px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:14px 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.legend__title{ font-weight:900; }
.legend__items{
  display:flex;
  gap:14px;
  flex-wrap:wrap;
  color:var(--muted);
  font-size:13px;
}
.legend__item{ display:flex; align-items:center; gap:8px; }
.dot{
  width:12px; height:12px;
  border-radius:999px;
  border:1px solid rgba(15,23,42,.12);
  display:inline-block;
}
.dot.brouillon{ background: var(--brouillon); }
.dot.soumis   { background: var(--soumis); }
.dot.valide   { background: var(--valide); }
.dot.refuse   { background: var(--refuse); }

/* ===== MODAL ===== */
.modal-overlay{
  position:fixed;
  inset:0;
  background: rgba(15,23,42,.40);
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:999;
}
.modal-overlay.open{ display:flex; }

.modal{
  width: min(980px, 100%);
  background:#fff;
  border:1px solid rgba(15,23,42,.12);
  border-radius:18px;
  box-shadow: 0 25px 60px rgba(15,23,42,.22);
  overflow:hidden;
}

.modal-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
  border-bottom:1px solid rgba(15,23,42,.10);
  background: linear-gradient(180deg, #fff, #fbfdff);
}
.modal-title{ font-weight:1000; font-size:18px; }
.modal-subtitle{ margin-top:6px; color:var(--muted); font-size:12px; }

.icon-btn{
  border:1px solid rgba(15,23,42,.14);
  background:#fff;
  border-radius:12px;
  width:40px;
  height:40px;
  cursor:pointer;
  font-weight:900;
}
.icon-btn:hover{ background:#f8fafc; }

.modal-body{
  padding:16px;
}

.form-grid{
  display:grid;
  grid-template-columns: repeat(6, 1fr);
  gap:12px;
}
.field{ grid-column: span 2; }
.field.span-2{ grid-column: span 3; }
.field label{ display:block; font-size:12px; font-weight:900; color:var(--muted); margin-bottom:6px; }
.field input, .field select, .field textarea{
  width:100%;
  padding:10px 12px;
  border:1px solid rgba(15,23,42,.16);
  border-radius:12px;
  background:#fff;
}
.field textarea{
  resize: vertical;
  min-height: 90px;
}
.field input:focus, .field select:focus, .field textarea:focus{
  outline:none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.hint{ margin-top:6px; color:var(--muted); font-size:11px; }

.tools-row{
  display:flex;
  gap:12px;
  align-items:center;
  flex-wrap:wrap;
}

.btn-solid{
  border:none;
  background:#e5e7eb;
  color:#111827;
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:900;
  font-size:13px;
}
.btn-solid.maps{
  background: linear-gradient(135deg, #10b981, #059669);
  color:#fff;
}
.btn-solid:hover{ filter: brightness(.98); }

.toggle{
  display:flex;
  align-items:center;
  gap:12px;
}
.toggle-label{
  font-size:12px;
  color:var(--muted);
  font-weight:800;
  line-height:1.3;
}

.toggle-group{
  display:flex;
  gap:4px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  padding:4px;
}
.toggle-btn{
  border:none;
  background:transparent;
  padding:8px 16px;
  border-radius:8px;
  font-weight:900;
  font-size:13px;
  cursor:pointer;
}
.toggle-btn.active{
  background:var(--primary);
  color:#fff;
}

.input-unit{
  position:relative;
}
.input-unit .unit{
  position:absolute;
  right:14px;
  top:50%;
  transform:translateY(-50%);
  color:var(--muted);
  font-weight:900;
  pointer-events:none;
}

.modal-actions{
  display:flex;
  justify-content:space-between;
  padding:14px 16px;
  border-top:1px solid var(--line);
  background: linear-gradient(180deg, #fbfdff, #fff);
}
.modal-actions .left{ display:flex; gap:10px; }
.modal-actions .right{ display:flex; gap:10px; }

/* responsive */
@media(max-width:900px){
  .form-grid{
    grid-template-columns: repeat(2, 1fr);
  }
  .field{ grid-column: span 1; }
  .field.span-2{ grid-column: span 2; }
}