:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; position: relative; }

/* --- Sidebar Desktop --- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: #14162b;
  color: #fff;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, width 0.2s ease;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 20px;
}
.sidebar .brand {
  font-size: 19px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}
.sidebar .brand span { color: #8b8ffc; }
.sidebar nav { flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex;
  align-items: center;
  padding: 11px 20px;
  color: #c6c8e0;
  font-weight: 500;
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.09); border-left-color: #8b8ffc; color: #fff; font-weight: 600; }
.sidebar .user-box {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12.5px;
  color: #9ea0c4;
  line-height: 1.5;
}
.sidebar .user-box a { color: #8b8ffc; font-weight: 500; }

.sidebar-backdrop {
  display: none;
}
.mobile-toggle-btn, .mobile-close-btn {
  display: none;
}

/* --- Zone Principale --- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-pill {
  font-size: 12px;
  font-weight: 600;
  background: #f3f4f6;
  color: #4b5563;
  padding: 5px 12px;
  border-radius: 999px;
}

.content { padding: 24px 28px; max-width: 1200px; width: 100%; box-sizing: border-box; }

/* --- Cartes & Grilles --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.card h2 { margin-top: 0; font-size: 16px; font-weight: 700; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.stat-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-card .value { font-size: 24px; font-weight: 800; margin-top: 6px; color: var(--text); }
.stat-card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* --- Tableaux --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; background: #fafafa; }
tr:last-child td { border-bottom: none; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}
.table-wrap table { min-width: 600px; }

/* --- Boutons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  min-height: 38px;
  transition: background 0.15s ease, transform 0.1s ease;
  touch-action: manipulation;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn:active { transform: scale(0.98); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f9fafb; color: var(--text); }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 11px; font-size: 12.5px; min-height: 30px; border-radius: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* --- Badges --- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.gray { background: #f3f4f6; color: #4b5563; }
.badge.blue { background: #eef2ff; color: #4338ca; }
.badge.green { background: #ecfdf5; color: #047857; }
.badge.red { background: #fef2f2; color: #b91c1c; }
.badge.amber { background: #fffbeb; color: #b45309; }

/* --- Formulaires --- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-group .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=file], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  box-sizing: border-box;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* --- Alertes --- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 13.5px; line-height: 1.4; }
.alert.success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* --- Barres d'outils et Tabs --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--primary); }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.toolbar .left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }

/* --- Authentification --- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-box { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 36px; width: 380px; max-width: 100%; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.login-box h1 { font-size: 20px; text-align: center; margin-top: 0; }

.progress-bar { background: #eef0f4; border-radius: 999px; height: 10px; overflow: hidden; }
.progress-bar .fill { background: var(--primary); height: 100%; transition: width .3s ease; }

.ql-editor { 
  min-height: 280px; 
  background: #fff; 
  font-family: Arial, Helvetica, sans-serif; 
  font-size: 15px; 
  line-height: 1.5; 
  color: #1f2937; 
  padding: 16px 20px;
}
.ql-editor p {
  margin: 0 0 6px 0;
  line-height: 1.5;
}
.ql-editor p:last-child {
  margin-bottom: 0;
}
.ql-editor h1, .ql-editor h2, .ql-editor h3 {
  margin: 12px 0 6px 0;
  line-height: 1.3;
}
.editor-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }

.merge-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.merge-tags button { background: #f3f4f6; border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.merge-tags button:hover { background: #e5e7eb; }

.kv-list { display: grid; grid-template-columns: 180px 1fr; row-gap: 8px; font-size: 13.5px; }
.kv-list dt { color: var(--muted); }

.preview-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* --- Planning & Calendrier Mensuel (Vue par Cases) --- */
.cal-board {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  margin-bottom: 24px;
}
.cal-days-header-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}
.cal-days-header-col {
  padding: 10px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-right: 1px solid #f1f5f9;
}
.cal-days-header-col:last-child {
  border-right: none;
}
.cal-table-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: #e2e8f0;
  gap: 1px;
}
.cal-box-day {
  min-height: 140px;
  background: #ffffff;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  transition: background .15s ease;
  box-sizing: border-box;
}
.cal-box-day:hover {
  background: #fafbff;
}
.cal-box-day.box-out-month {
  background: #fafafa;
}
.cal-box-day.box-out-month .cal-box-num {
  color: #94a3b8;
  font-weight: 500;
}
.cal-box-day.box-is-today {
  background: #fbfdff;
}

.cal-box-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 6px;
  min-height: 28px;
}
.cal-box-num-container {
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-box-num {
  font-size: 14px;
  font-weight: 600;
  color: #334155;
  line-height: 1;
}
.today-bubble {
  background: #1a73e8;
  color: #ffffff !important;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 4px rgba(26, 115, 232, 0.3);
}

.cal-box-cumul-wrap {
  position: absolute;
  right: 0;
  top: 4px;
}
.cal-box-cumul-pill {
  font-size: 9.5px;
  font-weight: 700;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 1px 5px;
  border-radius: 999px;
  white-space: nowrap;
}
.cal-box-cumul-pill.over-quota {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

.cal-box-events {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.cal-event-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s ease;
  font-size: 11px;
  line-height: 1.3;
  user-select: none;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}
.cal-event-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.cal-event-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cal-event-time {
  font-size: 10.5px;
  color: #64748b;
  font-weight: 500;
  flex-shrink: 0;
}
.cal-event-title {
  font-size: 11px;
  font-weight: 600;
  color: #1e293b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* --- Vue Agenda Day Card --- */
.day-card { border-left: 4px solid var(--primary); transition: box-shadow .2s; }
.day-card-today { border-left: 4px solid var(--success); background: #fafdfb; }
.day-card-past { opacity: 0.85; border-left: 4px solid #9ca3af; }
.day-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.day-title-box { display: flex; align-items: center; gap: 10px; }
.day-date-label { font-size: 15px; font-weight: 700; color: var(--text); }
.day-cumul-summary { display: flex; align-items: center; gap: 10px; }

.cumul-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: #f3f4f6;
  border: 1px solid var(--border);
}
.cumul-pill.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.cumul-pill.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.cumul-pill .cumul-label { font-weight: 500; }
.cumul-pill .cumul-value { font-weight: 800; font-size: 14px; }
.cumul-pill .cumul-limit { font-size: 11.5px; opacity: 0.8; }

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  box-sizing: border-box;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 440px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* =========================================================
   ADAPTATION RESPONSIVE SMARTPHONES & TABLETTES (< 768px)
   ========================================================= */
@media (max-width: 768px) {
  /* Navigation Drawer sur Smartphone */
  body.sidebar-open {
    overflow: hidden;
  }
  
  .sidebar-backdrop {
    display: block;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 998;
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 270px;
    max-width: 85vw;
    z-index: 999;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px;
    cursor: pointer;
    color: var(--text);
  }
  .mobile-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
  }

  .topbar {
    padding: 12px 16px;
  }
  .topbar h1 {
    font-size: 17px;
  }
  .user-pill {
    display: none;
  }

  .content {
    padding: 14px 12px;
  }

  /* Cartes et Formulaires */
  .card {
    padding: 14px 12px;
    margin-bottom: 14px;
    border-radius: 8px;
  }
  .grid-4, .grid-3, .grid-2 {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card {
    padding: 12px 10px;
  }
  .stat-card .value {
    font-size: 19px;
  }
  .stat-card .label {
    font-size: 10.5px;
  }

  /* Éviter le zoom automatique iOS sur les inputs */
  input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
    font-size: 16px !important;
    padding: 11px 12px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .toolbar .left {
    width: 100%;
    justify-content: space-between;
  }
  .planning-view-toggle {
    display: flex;
    width: 100%;
    gap: 4px;
  }
  .planning-view-toggle a {
    flex: 1;
    text-align: center;
  }

  .kv-list {
    grid-template-columns: 1fr;
    row-gap: 4px;
  }
  .kv-list dt {
    font-weight: 700;
    color: var(--text);
  }

  /* Calendrier Mensuel sur Smartphone */
  .cal-board {
    margin-bottom: 16px;
    border-radius: 8px;
  }
  .cal-days-header-col {
    padding: 6px 2px;
    font-size: 10px;
  }
  .cal-box-day {
    min-height: 85px;
    padding: 4px 2px;
  }
  .cal-box-header {
    min-height: 22px;
    margin-bottom: 3px;
  }
  .cal-box-num {
    font-size: 11.5px;
  }
  .today-bubble {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }
  .cal-box-cumul-wrap {
    display: none; /* Sur très petit écran, masque le texte long et garde la pastille d'événement */
  }
  .cal-event-item {
    padding: 2px 3px;
    gap: 2px;
    font-size: 9.5px;
    line-height: 1.2;
  }
  .cal-event-time {
    display: none; /* Masque l'heure dans la case miniature pour laisser la place au titre */
  }
  .cal-event-title {
    font-size: 9.5px;
  }

  /* Agenda list */
  .day-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .day-cumul-summary {
    width: 100%;
  }
  .cumul-pill {
    width: 100%;
    justify-content: space-between;
  }
}

/* Écrans très étroits (< 480px) */
@media (max-width: 480px) {
  .grid-4 {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .stat-card {
    padding: 10px 8px;
  }
  .stat-card .value {
    font-size: 17px;
  }
  .btn {
    font-size: 13px;
  }
}
