/* ─── IMPORT POLICE ─────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;500;600;700&display=swap');

/* ─── VARIABLES DE DESIGN ───────────────────────────────────────────────── */
:root {
  --color-bg: #f0f0f8;
  --color-bg-alt: #e8e8f4;
  --color-surface: #ffffff;
  --color-surface-hover: #f7f7fc;
  --color-border: #dde0ef;
  --color-border-light: #eaedf8;

  --color-primary: #7b9ec7;
  --color-primary-light: #b8d0e8;
  --color-primary-dark: #5a80a8;
  --color-accent: #9b85c4;
  --color-accent-light: #c9bde6;

  --color-text: #3a3a4a;
  --color-text-muted: #7a7a8a;
  --color-text-light: #a0a0b0;

  --color-success: #7bbf8a;
  --color-success-bg: #eef7f1;
  --color-warning: #d4b870;
  --color-warning-bg: #fdf8ec;
  --color-error: #c48a8a;
  --color-error-bg: #fdf2f2;

  --font: 'Nunito', 'Segoe UI', sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow: 0 2px 12px rgba(100, 100, 150, 0.10);
  --shadow-hover: 0 4px 20px rgba(100, 100, 150, 0.18);
  --transition: 0.2s ease;
  --sidebar-width: 240px;
  --touch-target: 44px;
}

/* ─── RESET & BASE ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: var(--color-primary-dark);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--color-accent); }

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button, input, textarea, select {
  font-family: var(--font);
  font-size: 1rem;
}

/* ─── MISE EN PAGE PRINCIPALE ───────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Barre latérale */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
}

.sidebar-logo .app-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-logo .system-name {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  min-height: var(--touch-target);
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background var(--transition), color var(--transition);
  border-radius: 0;
  position: relative;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: var(--color-bg);
  color: var(--color-accent);
}

.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}

.sidebar-nav .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-nav .badge {
  margin-left: auto;
  background: var(--color-error);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border-light);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.sidebar-footer .user-email {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Contenu principal */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem;
  min-height: 100vh;
  min-width: 0;
}

.page-header {
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
}

.page-subtitle {
  color: var(--color-text-muted);
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

/* ─── COMPOSANTS COMMUNS ────────────────────────────────────────────────── */

/* Cartes */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border: 1px solid var(--color-border-light);
  transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-hover); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

/* Boutons — minimum 44px de hauteur (accessibilité touch) */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  min-height: var(--touch-target);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover { background: var(--color-primary-dark); color: white; }

.btn-accent {
  background: var(--color-accent);
  color: white;
}
.btn-accent:hover { background: #8a74b3; color: white; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: var(--color-bg); color: var(--color-text); }

.btn-danger {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid #e8c0c0;
}
.btn-danger:hover { background: #f8e4e4; }

.btn-sm {
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  min-height: var(--touch-target);
}

.btn-icon {
  padding: 0.5rem;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--color-bg); color: var(--color-text); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Formulaires */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  min-height: var(--touch-target);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 1rem;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(123, 158, 199, 0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237a7a8a' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

.form-hint {
  font-size: 0.82rem;
  color: var(--color-text-light);
  margin-top: 0.3rem;
}

.form-error {
  font-size: 0.85rem;
  color: var(--color-error);
  margin-top: 0.3rem;
}

/* Grilles */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.grid-members {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

/* Avatar */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-bg-alt);
  flex-shrink: 0;
}

.avatar-placeholder {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  background: var(--color-primary);
  flex-shrink: 0;
  font-size: 0.9em;
}

.avatar-sm { width: 36px; height: 36px; }
.avatar-md { width: 52px; height: 52px; }
.avatar-lg { width: 80px; height: 80px; }
.avatar-xl { width: 120px; height: 120px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-primary { background: var(--color-primary-light); color: var(--color-primary-dark); }
.badge-accent { background: var(--color-accent-light); color: #6a5aa0; }
.badge-success { background: var(--color-success-bg); color: #4a8a5a; }
.badge-warning { background: var(--color-warning-bg); color: #8a6a20; }
.badge-error { background: var(--color-error-bg); color: #a06060; }
.badge-muted { background: var(--color-bg-alt); color: var(--color-text-muted); }

/* Séparateur */
.divider {
  height: 1px;
  background: var(--color-border-light);
  margin: 1.25rem 0;
}

/* Texte vide / placeholder */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
  margin-bottom: 1rem;
}

/* ─── BANNIÈRE ──────────────────────────────────────────────────────────── */
.banner {
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  line-height: 1.5;
}

.banner-warning {
  background: var(--color-warning-bg);
  border: 1px solid #e8d898;
  color: #7a6020;
}

.banner-info {
  background: #eef3fb;
  border: 1px solid #c0d4ec;
  color: #3a5a80;
}

/* ─── CARTE MEMBRE / ALTER ──────────────────────────────────────────────── */
.member-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-light);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
  box-shadow: var(--shadow);
}

.member-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.member-card-color-bar {
  height: 5px;
  background: var(--color-primary-light);
}

.member-card-body {
  padding: 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.member-card-info {
  flex: 1;
  min-width: 0;
}

.member-card-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-card-display-name {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.member-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.member-fronting-indicator {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 10px;
  height: 10px;
  background: var(--color-success);
  border-radius: 50%;
  box-shadow: 0 0 0 2px white;
}

/* ─── WIDGET FRONT ACTIF ────────────────────────────────────────────────── */
.front-widget {
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-accent-light) 100%);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--color-border-light);
}

.front-widget-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary-dark);
  margin-bottom: 0.75rem;
}

.front-widget-members {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.front-member-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: white;
  padding: 0.3rem 0.7rem 0.3rem 0.3rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.front-member-chip.co-conscious {
  opacity: 0.7;
  font-style: italic;
}

/* ─── TOASTS / NOTIFICATIONS ────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 340px;
  width: calc(100vw - 2rem);
}

.toast {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow-hover);
  border-left: 4px solid var(--color-primary);
  animation: slideIn 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.toast.toast-success { border-color: var(--color-success); }
.toast.toast-error   { border-color: var(--color-error); }
.toast.toast-warning { border-color: var(--color-warning); }

.toast-message { flex: 1; }
.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1rem;
  padding: 0;
  line-height: 1;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toast-close:hover { color: var(--color-text); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── MODALE ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 58, 74, 0.4);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
  overflow-y: auto;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(50, 50, 100, 0.18);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  animation: scaleIn 0.2s ease;
  margin: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
  padding: 0.25rem;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { color: var(--color-text); background: var(--color-bg); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border-light);
  flex-wrap: wrap;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* ─── PAGE CONNEXION ────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8eaf6 0%, #f3e5f5 50%, #e8f5e9 100%);
  padding: 1rem;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(100, 100, 150, 0.15);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .logo-name {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-accent);
}

.login-logo .logo-tagline {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ─── TABLEAU ───────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-light);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

thead th {
  background: var(--color-bg);
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-hover); }

tbody td {
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  color: var(--color-text);
  vertical-align: middle;
}

/* Tableau responsive : carte sur mobile */
@media (max-width: 640px) {
  .table-card table,
  .table-card thead,
  .table-card tbody,
  .table-card th,
  .table-card td,
  .table-card tr {
    display: block;
  }

  .table-card thead { display: none; }

  .table-card tbody tr {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    background: var(--color-surface);
    box-shadow: var(--shadow);
    padding: 0.5rem;
  }

  .table-card tbody tr:hover { background: var(--color-surface); }

  .table-card tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 0.88rem;
    min-height: 0;
  }

  .table-card tbody td:last-child { border-bottom: none; }

  .table-card tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    flex-shrink: 0;
  }

  .table-card .table-wrapper {
    border: none;
    overflow: visible;
  }

  .table-card table { min-width: 0; }
}

/* ─── TOGGLE SWITCH ─────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--color-border);
  border-radius: 999px;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider {
  background: var(--color-primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ─── COLOR PICKER CUSTOM ───────────────────────────────────────────────── */
.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-input-wrap input[type="color"] {
  width: 44px;
  height: 44px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px;
  background: var(--color-surface);
  transition: border-color var(--transition);
}

.color-input-wrap input[type="color"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* ─── JOURNAL ───────────────────────────────────────────────────────────── */
.journal-entry {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-light);
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: box-shadow var(--transition);
}

.journal-entry:hover { box-shadow: var(--shadow-hover); }

.journal-entry-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.3rem;
}

.journal-entry-date {
  font-size: 0.82rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

.journal-entry-excerpt {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.journal-content {
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 1rem;
  color: var(--color-text);
}

.comment {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
}

.comment-author {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

/* ─── MESSAGES INTERNES ─────────────────────────────────────────────────── */
.messages-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  height: calc(100vh - 8rem);
}

.threads-list {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-light);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.thread-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  min-height: var(--touch-target);
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-light);
  transition: background var(--transition);
}

.thread-item:hover, .thread-item.active { background: var(--color-bg); }
.thread-item:last-child { border-bottom: none; }

.thread-item .unread-badge {
  margin-left: auto;
  background: var(--color-accent);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}

.message-thread {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
}

.message-thread-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.message-list {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message-bubble {
  max-width: 75%;
  background: var(--color-bg);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  line-height: 1.55;
}

.message-bubble.sent {
  align-self: flex-end;
  background: var(--color-primary-light);
}

.message-meta {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-top: 0.25rem;
}

.message-input-bar {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border-light);
  display: flex;
  gap: 0.75rem;
}

.messages-mobile-back {
  display: none;
  flex-shrink: 0;
}

/* ─── PANEL ADMIN ───────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--color-border-light);
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── PAGE PARTAGE PUBLIQUE ─────────────────────────────────────────────── */
.share-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.share-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

/* ─── PAGINATION ────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.pagination-btn {
  padding: 0.4rem 0.85rem;
  min-height: var(--touch-target);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-family: var(--font);
  font-weight: 600;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-text);
}

.pagination-btn.active {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── RESPONSIVE MOBILE ─────────────────────────────────────────────────── */

/* Mobile nav toggle — barre de navigation fixe en bas ou hamburger */
.mobile-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  min-width: var(--touch-target);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 1rem;
  font-size: 1.2rem;
  touch-action: manipulation;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }

  .main-content {
    margin-left: 0;
    padding: 1rem;
  }

  .mobile-nav-toggle {
    display: flex;
  }

  /* En-têtes de page sur mobile */
  .page-header {
    margin-bottom: 1.25rem;
  }

  .page-header > div, .page-header {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .page-title { font-size: 1.4rem; }

  /* Grilles */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-members { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

  /* Messages mobile : vue liste ↔ conversation */
  .messages-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 0;
  }

  .message-thread {
    display: none !important;
  }

  .messages-thread-open .threads-list {
    display: none;
  }

  .messages-thread-open .message-thread {
    display: flex !important;
    flex-direction: column;
    min-height: calc(100vh - 8rem);
  }

  .messages-mobile-back {
    display: inline-flex !important;
  }

  .message-input-bar {
    flex-wrap: nowrap;
    gap: 0.4rem;
  }

  .message-input-bar #reply-from {
    max-width: 110px;
    font-size: 0.85rem;
  }

  #btn-reply {
    min-width: 80px;
    flex-shrink: 0;
  }

  /* Modales — pas de scroll horizontal */
  .modal-overlay {
    overflow-x: hidden;
  }

  .modal {
    padding: 1.25rem;
    max-height: 95vh;
    max-width: calc(100vw - 2rem);
    overflow-x: hidden;
    word-break: break-word;
    border-radius: var(--radius);
  }

  .modal-footer {
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  /* Stats grid */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Card header avec bouton */
  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-header .btn {
    align-self: flex-start;
  }

  /* Filtres */
  .filter-bar {
    flex-direction: column;
  }

  .filter-bar .form-input,
  .filter-bar .form-select {
    max-width: 100% !important;
    width: 100%;
  }

  /* Partage public */
  .share-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
}

@media (max-width: 480px) {
  .grid-members { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 1.75rem 1.25rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  .message-bubble { max-width: 90%; }

  /* Toasts pleine largeur */
  #toast-container {
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
  }
}

/* ─── CHANGELOG ─────────────────────────────────────────────────────────────── */
.changelog-entry {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-light);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.changelog-version-badge {
  display: inline-flex;
  align-items: center;
  background: var(--color-accent-light);
  color: #6a5aa0;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  margin-right: 0.6rem;
}

.changelog-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
  display: inline;
}

.changelog-date {
  font-size: 0.82rem;
  color: var(--color-text-light);
  margin-left: 0.5rem;
}

.changelog-content {
  margin-top: 1rem;
  font-size: 0.93rem;
  line-height: 1.65;
  color: var(--color-text);
}

.changelog-unseen-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--color-accent);
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ─── ADMIN SMTP ─────────────────────────────────────────────────────────────── */
.smtp-test-result {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  margin-top: 0.75rem;
}

.smtp-test-result.success {
  background: var(--color-success-bg);
  color: #4a8a5a;
  border: 1px solid #b8dfc4;
}

.smtp-test-result.error {
  background: var(--color-error-bg);
  color: #a06060;
  border: 1px solid #e8c0c0;
}

/* ─── MODE SOMBRE ────────────────────────────────────────────────────────── */

[data-theme="dark"] {
  --color-bg: #1a1a2e;
  --color-bg-alt: #16213e;
  --color-surface: #1e2a40;
  --color-surface-hover: #253356;
  --color-border: #2d3a55;
  --color-border-light: #243050;

  --color-text: #e0e0ee;
  --color-text-muted: #9898b8;
  --color-text-light: #5a5a7a;

  --color-primary: #7b9ec7;
  --color-primary-light: #3d5a7a;
  --color-primary-dark: #9fbad8;
  --color-accent: #9b85c4;
  --color-accent-light: #3d2e60;

  --color-success: #5a9f69;
  --color-success-bg: #1a3022;
  --color-warning: #c4a450;
  --color-warning-bg: #2d2510;
  --color-error: #c08080;
  --color-error-bg: #2d1a1a;

  --shadow: 0 2px 16px rgba(0, 0, 10, 0.5);
  --shadow-hover: 0 4px 24px rgba(0, 0, 10, 0.6);
}

[data-theme="dark"] .btn-danger {
  border-color: var(--color-error);
  background: var(--color-error-bg);
  color: var(--color-error);
}

[data-theme="dark"] .btn-danger:hover {
  background: #3d2020;
}

[data-theme="dark"] .member-card {
  background: var(--color-surface);
}

/* Badges alters au front — lisibilité en mode sombre */
[data-theme="dark"] .badge-member-front {
  color: #e8e8f8 !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* ─── TOGGLE MODE SOMBRE ─────────────────────────────────────────────────── */

.dark-mode-toggle {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--color-border-light);
}

.dark-toggle-btn {
  width: 100%;
  justify-content: flex-start;
  min-height: 40px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  gap: 0.5rem;
}

/* ─── SIDEBAR LOGO CLIQUABLE ─────────────────────────────────────────────── */

.sidebar-logo-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: opacity var(--transition);
}

.sidebar-logo-link:hover {
  opacity: 0.8;
}

/* ─── AVATAR + NOM SYSTÈME DANS LE FOOTER ───────────────────────────────── */

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  overflow: hidden;
}

.sidebar-system-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-system-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-system-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── LIEN EMAIL UTILISATEUR ─────────────────────────────────────────────── */

.user-email-link {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition);
}

.user-email-link:hover {
  color: var(--color-accent);
}

/* ─── SELECT AVEC RECHERCHE INTÉGRÉE ────────────────────────────────────── */

.searchable-select {
  position: relative;
  width: 100%;
}

.searchable-select-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  min-height: var(--touch-target);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.searchable-select-display:hover,
.searchable-select-display:focus {
  border-color: var(--color-primary);
  outline: none;
}

.searchable-select-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  font-size: 1rem;
}

.searchable-select-arrow {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-left: 0.5rem;
  transition: transform var(--transition);
}

.searchable-select.open .searchable-select-arrow {
  transform: rotate(180deg);
}

.searchable-select-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  overflow: hidden;
}

.searchable-select-search {
  display: block;
  width: 100%;
  border: none !important;
  border-bottom: 1px solid var(--color-border) !important;
  border-radius: 0 !important;
  min-height: unset !important;
  height: 40px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  background: var(--color-bg);
}

.searchable-select-search:focus {
  outline: none;
  box-shadow: none !important;
}

.searchable-select-list {
  max-height: 220px;
  overflow-y: auto;
}

.searchable-select-option {
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background var(--transition);
  border-bottom: 1px solid var(--color-border-light);
}

.searchable-select-option:last-child {
  border-bottom: none;
}

.searchable-select-option:hover {
  background: var(--color-bg);
}

.searchable-select-option.selected {
  color: var(--color-accent);
  font-weight: 700;
}

.searchable-select-empty {
  padding: 0.75rem 0.9rem;
  color: var(--color-text-muted);
  font-size: 0.88rem;
  font-style: italic;
  text-align: center;
}

/* ─── PAGE RECHERCHE GLOBALE ─────────────────────────────────────────────── */

.search-hero {
  max-width: 640px;
  margin: 0 auto 2rem;
  text-align: center;
}

.search-input-wrap {
  margin-top: 1rem;
}

.search-input-large {
  width: 100%;
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
  border-radius: var(--radius-lg);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  min-height: 56px;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font);
}

.search-input-large:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.search-results {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.search-category {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-category-header {
  padding: 0.75rem 1.25rem;
  background: var(--color-bg);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-result-item {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--color-bg);
}

.search-result-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--color-text);
}

.search-result-excerpt {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.95rem;
}

