/* =========================================================================
   Chantier — Design system « Ardoise & Sarcelle »
   Desktop d'abord : barre latérale + zone de contenu large.
   Mobile : tiroir latéral + barre d'onglets pilotée par les icônes.
   ========================================================================= */

:root {
  /* Surfaces claires */
  --bg: #f1f5f9;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  /* Texte */
  --text: #0f172a;
  --text-2: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;

  /* Accent sarcelle */
  --accent: #0d9488;
  --accent-2: #14b8a6;
  --accent-deep: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-tint: #f0fdfa;

  /* Sémantique */
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --err: #dc2626;
  --err-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --violet: #7c3aed;
  --violet-soft: #ede9fe;

  /* Barre latérale */
  --sidebar: #0f172a;
  --sidebar-2: #16213a;
  --sidebar-line: #24314d;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #7f8ea8;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px -6px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 12px 32px -12px rgba(15, 23, 42, 0.25);

  --sidebar-w: 248px;
  --topbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14.5px; }
.hidden { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
p { margin: 0; }
img, video { max-width: 100%; }

/* ============================ Coquille de l'application ============================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- Barre latérale (desktop) ---------- */
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--sidebar-line);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--sidebar-line);
}
.sidebar-brand .boot-logo {
  width: 38px; height: 38px; border-radius: 11px; font-size: 17px;
  box-shadow: none; flex-shrink: 0;
}
.sidebar-brand b { display: block; font-size: 15.5px; color: #fff; letter-spacing: -0.02em; }
.sidebar-brand small { display: block; font-size: 11px; color: var(--sidebar-muted); letter-spacing: 0.02em; }

.sidebar-nav { padding: 12px 10px; flex: 1; }
.sidebar-section {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-muted);
  padding: 14px 10px 6px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
}
.sidebar-link i { width: 18px; text-align: center; font-size: 14px; color: var(--sidebar-muted); transition: color 0.13s; }
.sidebar-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar-link:hover i { color: #fff; }
.sidebar-link.active { background: var(--accent); color: #fff; font-weight: 650; }
.sidebar-link.active i { color: #fff; }
.sidebar-link .count-badge {
  margin-left: auto;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--err);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.sidebar-footer { padding: 12px; border-top: 1px solid var(--sidebar-line); }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--sidebar-line);
  border-radius: var(--radius-sm);
  background: var(--sidebar-2);
  color: var(--sidebar-text);
  cursor: pointer;
  text-align: left;
}
.sidebar-user .avatar { width: 34px; height: 34px; font-size: 12px; }
.sidebar-user b { display: block; font-size: 12.5px; color: #fff; }
.sidebar-user small { display: block; font-size: 10.5px; color: var(--sidebar-muted); }
.sidebar-user .chev { margin-left: auto; color: var(--sidebar-muted); font-size: 11px; }

/* ---------- Colonne principale ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 19px; font-weight: 720; letter-spacing: -0.025em; line-height: 1.2; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
/* Spécificité 2 classes : doit primer sur `.icon-btn { display: grid }` déclaré juste après */
.icon-btn.menu-btn { display: none; }

.icon-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-2); font-size: 14px; position: relative; cursor: pointer;
  transition: background 0.13s, border-color 0.13s;
}
.icon-btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.icon-btn .dot { position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--err); box-shadow: 0 0 0 2px var(--surface); }

/* Bouton « Ajouter » de la barre supérieure : placé à gauche des notifications */
.icon-btn.add-btn {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(13, 148, 136, .28);
}
.icon-btn.add-btn:hover { background: var(--accent-strong, #0f766e); border-color: var(--accent-strong, #0f766e); }

/* Pastille de couleur utilisée par la liste des catégories */
.dot-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; display: inline-block; }

.view { flex: 1; padding: 22px 24px 40px; width: 100%; max-width: 1440px; margin: 0 auto; }
.view-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.view-head .grow { min-width: 0; }

/* ============================ Composants génériques ============================ */

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff;
  background: var(--accent); flex-shrink: 0;
  letter-spacing: -0.01em;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.card.tapable { cursor: pointer; transition: border-color 0.14s, box-shadow 0.14s, transform 0.13s; }
.card.tapable:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.card.tapable:active { transform: scale(0.995); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.sm { gap: 6px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.truncate-2 { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.small { font-size: 13px; }
.bold { font-weight: 650; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.right { margin-left: auto; }
.center { text-align: center; }

/* Grilles utilitaires */
.grid { display: grid; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; align-items: start; }
.card-grid > .card { margin-bottom: 0; }

.section-title {
  display: flex; align-items: center; gap: 8px;
  margin: 22px 0 10px;
  font-size: 12px; font-weight: 720;
  text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted);
}
.section-title .count {
  background: var(--surface-3); color: var(--text-2);
  border-radius: 999px; padding: 1px 8px;
  font-size: 10.5px; letter-spacing: 0;
}
.sidebar .btn,
.sidebar .sidebar-link { color: var(--sidebar-text); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
  transition: background 0.13s, border-color 0.13s, box-shadow 0.13s, transform 0.1s;
}
.btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 8px 18px -10px rgba(13, 148, 136, 0.9); }
.btn.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.soft { background: var(--accent-tint); border-color: #99f6e4; color: var(--accent-deep); }
.btn.soft:hover { background: var(--accent-soft); }
.btn.danger { background: var(--err-soft); border-color: #fecaca; color: #b91c1c; }
.btn.danger:hover { background: #fecaca; }
.btn.ok { background: var(--ok-soft); border-color: #a7f3d0; color: #047857; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { padding: 0; width: 38px; height: 38px; flex-shrink: 0; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

/* ---------- Chips / étiquettes ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 620;
  background: var(--surface-3); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.ok { color: #047857; background: var(--ok-soft); border-color: #a7f3d0; }
.chip.warn { color: #b45309; background: var(--warn-soft); border-color: #fde68a; }
.chip.err { color: #b91c1c; background: var(--err-soft); border-color: #fecaca; }
.chip.info { color: #1d4ed8; background: var(--info-soft); border-color: #bfdbfe; }
.chip.violet { color: #6d28d9; background: var(--violet-soft); border-color: #ddd6fe; }
.chip.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chips-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.dot-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 720;
  display: grid; place-items: center; flex-shrink: 0;
}
.clamp, .clamp2 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp { -webkit-line-clamp: 1; }
.clamp2 { -webkit-line-clamp: 2; }

/* ---------- Filtres / recherche ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex-shrink: 0; padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background 0.13s, color 0.13s, border-color 0.13s;
}
.filter:hover { background: var(--surface-3); color: var(--text-2); }
.filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter.active .tiny { color: rgba(255, 255, 255, 0.8); }

.search { position: relative; margin-bottom: 12px; max-width: 520px; }
.search i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted-2); font-size: 13px; }
.search input { padding-left: 38px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { margin-bottom: 0; flex: 1; min-width: 220px; }

/* ---------- Formulaires ---------- */
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color 0.13s, box-shadow 0.13s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px; }
label.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 11.5px; font-weight: 650; color: var(--muted); margin-bottom: 5px; letter-spacing: 0.01em; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.switch {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer;
}
.switch input { width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); }
.switch .grow { font-size: 13.5px; }
.seg { display: flex; gap: 4px; background: var(--surface-3); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; }
.seg button {
  flex: 1; padding: 7px; border-radius: 7px; border: 0;
  background: transparent; color: var(--muted);
  font-weight: 620; font-size: 13px; cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Statistiques / KPI ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px;
  position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  display: block;
}
.stat .k { font-size: 11.5px; color: var(--muted); font-weight: 620; display: flex; align-items: center; gap: 6px; }
.stat .k i { color: var(--muted-2); }
.stat .v { font-size: 25px; font-weight: 760; letter-spacing: -0.035em; margin-top: 7px; color: var(--text); }
.stat .v small { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.stat.accent { background: linear-gradient(150deg, var(--accent-tint), #ffffff 65%); border-color: #99f6e4; }
.stat.accent .k i, .stat.accent .v { color: var(--accent-deep); }
.stat.tapable { cursor: pointer; transition: border-color 0.14s, box-shadow 0.14s; }
.stat.tapable:hover { border-color: var(--accent-2); box-shadow: var(--shadow); }

.hero-card {
  background: linear-gradient(120deg, #0f172a 0%, #134e4a 55%, #0d9488 100%);
  border-radius: var(--radius-lg); padding: 20px 22px;
  color: #fff; border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-lg);
}
.hero-card .k { color: rgba(255, 255, 255, 0.75); font-size: 11.5px; font-weight: 620; }
.hero-card .v { font-size: 27px; font-weight: 780; letter-spacing: -0.035em; margin-top: 3px; }
.hero-card .avatar { background: rgba(255, 255, 255, 0.18) !important; color: #fff; }

/* ---------- Listes ---------- */
.list-item { display: flex; gap: 12px; align-items: flex-start; }
.list-item .avatar { border-radius: 11px; }
.list-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 7px; font-size: 11.5px; color: var(--muted); }
.list-meta span { display: inline-flex; align-items: center; gap: 4px; }
.list-meta i { font-size: 10.5px; color: var(--muted-2); }

.progress { height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }

.task-row { display: flex; gap: 11px; align-items: flex-start; }
.checkbox {
  width: 21px; height: 21px; border-radius: 6px;
  border: 1.5px solid var(--line-strong); flex-shrink: 0; margin-top: 1px;
  display: grid; place-items: center; color: transparent;
  background: var(--surface); cursor: pointer; font-size: 10px;
  transition: background 0.13s, border-color 0.13s;
}
.checkbox:hover { border-color: var(--accent); }
.checkbox.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.task-row.done .title { text-decoration: line-through; color: var(--muted); }
.late { color: #b91c1c; font-weight: 620; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty i { font-size: 30px; margin-bottom: 12px; display: block; color: var(--line-strong); }
.empty .t { font-weight: 650; color: var(--text-2); margin-bottom: 4px; font-size: 14px; }

/* ---------- Tableaux clé/valeur ---------- */
.kv {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; color: var(--text-2); }

.total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.total-row.big { font-size: 19px; font-weight: 760; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 6px; }

/* ---------- Panneaux / feuilles ---------- */
/* z-index 130 : une feuille (dont la confirmation de suppression) doit toujours
   passer AU-DESSUS de la visionneuse média (.lightbox, z-index 90). Sinon la
   demande de confirmation restait invisible derrière la photo et le bouton
   « Supprimer » semblait ne rien faire. */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 130;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.16s ease; backdrop-filter: blur(2px);
  padding: 0;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line); border-bottom: 0;
  padding: 8px 20px calc(22px + var(--safe-b));
  box-shadow: var(--shadow-lg);
  animation: slideup 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes slideup { from { transform: translateY(22px); opacity: 0.7; } }
.sheet-grab { width: 40px; height: 4px; border-radius: 999px; background: var(--line-strong); margin: 6px auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h3 { font-size: 17px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

.modal-full {
  position: fixed; inset: 0; z-index: 70; overflow-y: auto;
  background: var(--bg); padding: 0 0 calc(26px + var(--safe-b));
  animation: fade 0.14s;
}
.modal-full .detail-head {
  position: sticky; top: 0; z-index: 5;
  background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(12px);
  padding: 12px 20px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
}
.modal-full .detail-body { padding: 20px; max-width: 880px; margin: 0 auto; }

/* ---------- Médias ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.media-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--surface-3); cursor: pointer; border: 1px solid var(--line);
}
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .badge-kind {
  position: absolute; bottom: 4px; left: 4px;
  font-size: 9.5px; padding: 1px 6px; border-radius: 5px;
  background: rgba(15, 23, 42, 0.75); color: #fff; font-weight: 600;
}
.media-tile .audio-ph { display: grid; place-items: center; height: 100%; color: var(--accent); font-size: 21px; }

/* Croix de suppression posée sur la tuile : un seul geste, sans passer par la
   visionneuse. Cible de 28 px pour rester cliquable au doigt. */
.media-tile .tile-del {
  position: absolute; top: 3px; right: 3px;
  width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center;
  border: none; cursor: pointer; padding: 0;
  background: rgba(15, 23, 42, 0.62); color: #fff;
  font-size: 11px; opacity: 0; transition: opacity 0.14s, background 0.14s;
}
.media-tile:hover .tile-del, .media-tile:focus-within .tile-del { opacity: 1; }
.media-tile .tile-del:hover { background: var(--err); }
/* Sur écran tactile il n'y a pas de survol : la croix reste visible. */
@media (hover: none) {
  .media-tile .tile-del { opacity: 1; background: rgba(15, 23, 42, 0.5); }
}
.media-tile.file-tile { display: flex; flex-direction: column; align-items: stretch; justify-content: center; padding: 6px; gap: 4px; }
.media-tile .file-name { font-size: 10px; line-height: 1.25; text-align: center; color: var(--text-2); word-break: break-word; }

.capture-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.capture-btn {
  flex: 1; min-width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 12px 6px; border-radius: var(--radius-sm);
  border: 1px dashed var(--line-strong); background: var(--surface-2);
  color: var(--text-2); font-size: 11.5px; font-weight: 620; cursor: pointer;
  transition: background 0.13s, border-color 0.13s;
}
.capture-btn:hover { background: var(--accent-tint); border-color: var(--accent-2); }
.capture-btn i { font-size: 17px; color: var(--accent); }
.capture-btn.recording { border-color: var(--err); background: var(--err-soft); animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: 0.65; } }

.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(8, 12, 22, 0.94);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.lightbox img, .lightbox video { max-height: 88vh; border-radius: 12px; }
.lightbox .close { position: absolute; top: 18px; right: 20px; font-size: 22px; color: #fff; cursor: pointer; }

/* ---------- Messagerie ---------- */
.msg-list { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 10px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; }
.bubble.in { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; align-self: flex-start; }
.bubble.out { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.bubble .meta { font-size: 10.5px; opacity: 0.72; margin-top: 4px; }
.bubble .body { word-break: break-word; }
.composer { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 0; background: linear-gradient(0deg, var(--bg) 65%, transparent); }
.composer textarea { min-height: 44px; max-height: 120px; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.card.unread { border-color: #5eead4; background: linear-gradient(180deg, var(--accent-tint), var(--surface)); }

.conv-header {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.conv-thread {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 260px; max-height: 60vh; overflow-y: auto;
  padding: 6px 2px 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.conv-composer {
  display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap;
  margin-top: 12px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); position: sticky; bottom: 0;
}
.conv-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.conv-composer textarea { flex: 1 1 150px; resize: none; min-height: 42px; }
.conv-composer .btn { flex-shrink: 0; }

/* Barre d'outils du composeur : pièce jointe, caméra, micro, vidéo, envoyer */
.conv-tools { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.conv-tools .icon-btn { width: 38px; height: 38px; font-size: 14px; }
.conv-tools .btn.primary { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; }

/* Pièce jointe en attente : occupe toute la largeur au-dessus du texte */
.conv-attach-bar { flex: 1 1 100%; }
.attach-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: var(--radius-sm);
  background: var(--accent-tint); border: 1px solid #5eead4;
  font-size: 12.5px; font-weight: 600; color: var(--text);
}
.attach-chip img { width: 34px; height: 34px; border-radius: 7px; object-fit: cover; flex-shrink: 0; }
.attach-chip > i { font-size: 17px; color: var(--accent); flex-shrink: 0; }
.attach-chip .icon-btn { width: 26px; height: 26px; font-size: 11px; border: none; background: transparent; }
.attach-chip .icon-btn:hover { background: #ffffff55; }

/* Média dans une bulle de conversation */
.bubble-media { margin: -2px -4px 6px; }
.bubble-media img,
.bubble-media video {
  display: block; width: 100%; max-width: 260px;
  border-radius: 10px; background: #000;
}
.bubble-media video { max-height: 240px; }
.bubble-media audio { display: block; width: 240px; max-width: 100%; height: 38px; }
.bubble-file {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; margin-bottom: 6px;
  border-radius: 10px; text-decoration: none;
  background: var(--surface-3); border: 1px solid var(--line);
  color: var(--text); font-size: 12.5px;
}
.bubble.out .bubble-file { background: #ffffff22; border-color: #ffffff33; color: #fff; }
.bubble-file > i:first-child { font-size: 17px; color: var(--accent); flex-shrink: 0; }
.bubble.out .bubble-file > i:first-child { color: #fff; }
.bubble-file > i:last-child { font-size: 12px; opacity: 0.7; flex-shrink: 0; }

/* Suppression d'un média depuis la bulle */
.bubble-del {
  border: none; background: transparent; cursor: pointer;
  color: inherit; opacity: 0.55; padding: 0 0 0 6px; font-size: 10.5px;
}
.bubble-del:hover { opacity: 1; color: var(--err); }

/* Bouton « Supprimer » dans la visionneuse.
   `right` + `transform` : sans largeur explicite, le bouton restait collé au
   bord gauche sur les petits écrans et empiétait sur la photo. */
.lb-delete { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 2; }

/* ---------- Toast / spinner ---------- */
.toast-wrap {
  position: fixed; left: 0; right: 0; bottom: calc(24px + var(--safe-b));
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none; padding: 0 16px;
}
.toast {
  max-width: 520px; width: fit-content;
  padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600;
  background: var(--text); border: 1px solid var(--text);
  color: #fff; box-shadow: var(--shadow-lg);
  animation: toastin 0.18s ease;
}
.toast.ok { background: #065f46; border-color: #065f46; }
.toast.err { background: #991b1b; border-color: #991b1b; }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } }
.spinner-sm {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  animation: spin 0.7s linear infinite; display: inline-block;
}
.spinner-sm.dark { border-color: var(--line-strong); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Démarrage / connexion ---------- */
.boot {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; gap: 20px;
  align-items: center; justify-content: center;
  background: var(--sidebar);
}
.boot-logo {
  width: 68px; height: 68px; border-radius: 19px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent-2), var(--accent-deep));
  color: #fff; font-size: 29px;
  box-shadow: 0 18px 38px -14px rgba(13, 148, 136, 0.85);
}
.boot-spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18); border-top-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
}

.login { min-height: 100vh; display: grid; grid-template-columns: 1fr; background: var(--bg); }
.login-panel {
  display: none;
  background: linear-gradient(150deg, #0f172a 0%, #134e4a 60%, #0d9488 100%);
  color: #fff; padding: 48px 44px;
  flex-direction: column; justify-content: space-between;
}
.login-panel h2 { color: #fff; font-size: 30px; line-height: 1.15; letter-spacing: -0.03em; max-width: 380px; }
.login-panel .lead { color: rgba(255, 255, 255, 0.78); font-size: 14.5px; margin-top: 14px; max-width: 360px; }
.login-panel .feat { display: flex; align-items: center; gap: 11px; margin-top: 14px; font-size: 13.5px; color: rgba(255, 255, 255, 0.88); }
.login-panel .feat i { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.12); font-size: 12.5px; }
.login-main { display: flex; flex-direction: column; justify-content: center; padding: 34px 22px calc(34px + var(--safe-b)); }
.login-inner { width: 100%; max-width: 420px; margin: 0 auto; }
.login-logo {
  width: 50px; height: 50px; border-radius: 15px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent-2), var(--accent-deep));
  color: #fff; font-size: 22px; margin-bottom: 18px;
}
.login h1 { font-size: 25px; line-height: 1.18; letter-spacing: -0.03em; }
.login h1 span { color: var(--accent); }
.login p.sub { color: var(--muted); margin-top: 8px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.login-form input { padding: 11px 13px; }
.demo-list { margin-top: 22px; display: flex; flex-direction: column; gap: 6px; }
.demo-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  text-align: left; color: var(--text); cursor: pointer; width: 100%;
  transition: border-color 0.13s, background 0.13s;
}
.demo-item:hover { border-color: var(--accent-2); background: var(--accent-tint); }
.demo-item .avatar { width: 32px; height: 32px; font-size: 12px; }
.demo-item small { display: block; color: var(--muted); font-size: 11px; }
.demo-item .chev { margin-left: auto; color: var(--muted-2); font-size: 11px; }

/* ---------- Barre d'onglets mobile ---------- */
.bottomnav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px -8px rgba(15, 23, 42, 0.18);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; border: 0; background: none;
  color: var(--muted); font-size: 10px; font-weight: 620;
  position: relative; cursor: pointer;
}
.nav-item i { font-size: 17px; }
.nav-item.active { color: var(--accent); }
.nav-item .badge { position: absolute; top: 0; right: 50%; transform: translateX(18px); }

/* ============================ Responsive ============================ */

@media (min-width: 1024px) {
  .login { grid-template-columns: 1.05fr 1fr; }
  .login-panel { display: flex; }
  .login-main { padding: 40px 56px; }
}

@media (max-width: 1023px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  /* La barre latérale devient un tiroir */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 55;
    width: 272px; height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-backdrop {
    position: fixed; inset: 0; z-index: 54;
    background: rgba(15, 23, 42, 0.45);
    animation: fade 0.16s;
  }

  .icon-btn.menu-btn { display: grid; }
  .topbar { padding: 0 16px; gap: 11px; }
  .topbar-sub { display: none; }
  .view { padding: 16px 16px calc(84px + var(--safe-b)); }
  .bottomnav { display: flex; }
  .card-grid { grid-template-columns: minmax(0, 1fr); }
  .toast-wrap { bottom: calc(78px + var(--safe-b)); }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 13px; }
  .stat .v { font-size: 21px; }
  .card { padding: 14px; }
  .topbar-title { font-size: 17px; }
  .sheet-backdrop { align-items: flex-end; }
  .hero-card { padding: 17px; }
  .hero-card .v { font-size: 23px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .bubble { max-width: 88%; }
}

/* ============================ Page publique ============================ */
.pub-body { background: var(--bg); }
.pub-wrap { max-width: 760px; margin: 0 auto; padding: 0 0 40px; }
.pub-hero {
  padding: 28px 22px 24px;
  background: linear-gradient(150deg, #0f172a 0%, #134e4a 62%, #0d9488 100%);
  color: #fff;
}
.pub-hero h1, .pub-hero .k { color: #fff; }
.pub-top {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.pub-post {
  padding: 18px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.pub-post h3 { font-size: 16.5px; margin-bottom: 6px; }
.pub-post .body { color: var(--text-2); font-size: 14px; white-space: pre-wrap; line-height: 1.55; }
.pub-gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 10px; }
.pub-gallery > * { border-radius: 10px; overflow: hidden; aspect-ratio: 1; object-fit: cover; width: 100%; }

@media (max-width: 560px) {
  .pub-hero { padding: 22px 16px 18px; }
  .pub-post { padding: 14px; }
}


/* ---------- Matrice des permissions (Profils) ---------- */
/* Trois colonnes Lecture / Modification / Suppression : la grille rend lisible
   d'un coup d'œil ce qu'un profil peut faire, sans dérouler 35 interrupteurs. */
.perm-matrix { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.perm-head, .perm-row {
  display: grid;
  grid-template-columns: 1fr 62px 62px 62px;
  align-items: center;
  gap: 4px;
}
.perm-head {
  background: var(--surface-3);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
}
.perm-head .perm-res { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.perm-head .perm-col {
  font-size: 9.5px; font-weight: 680; color: var(--muted);
  text-align: center; line-height: 1.15; display: flex;
  flex-direction: column; align-items: center; gap: 2px;
}
.perm-head .perm-col i { font-size: 10px; color: var(--muted-2); }
.perm-row { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.perm-row:last-child { border-bottom: 0; }
.perm-row:nth-child(even) { background: var(--surface-2); }
.perm-row .perm-res { font-size: 12.5px; font-weight: 600; color: var(--text); padding-right: 6px; }
.perm-cell { display: grid; place-items: center; min-height: 30px; border-radius: 7px; cursor: pointer; }
.perm-cell:hover { background: var(--accent-tint); }
.perm-cell.empty { cursor: default; }
.perm-cell.empty:hover { background: transparent; }
.perm-cell input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* Résumé chiffré par colonne sur chaque carte de profil */
.perm-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.perm-count {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 7px; font-size: 11.5px;
  background: var(--surface-3); border: 1px solid var(--line); color: var(--muted);
}
.perm-count i { font-size: 10px; color: var(--muted-2); }
.perm-count b { color: var(--text); font-weight: 720; }

/* ---------- Corbeille d'une discussion (Messagerie) ---------- */
/* La carte est cliquable : la corbeille est en position absolue pour rester
   hors du flux et ne pas décaler l'avatar ni le texte du dernier message. */
article[data-conv] { position: relative; }
.conv-del {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  border: 1px solid transparent; background: transparent;
  color: var(--muted-2); font-size: 11.5px; cursor: pointer;
  opacity: 0; transition: opacity .14s, background .14s, color .14s;
  z-index: 2;
}
article[data-conv]:hover .conv-del,
article[data-conv]:focus-within .conv-del { opacity: 1; }
.conv-del:hover { background: var(--err-soft); border-color: #fecaca; color: var(--err); }
/* Écrans tactiles : pas de survol, la corbeille doit rester atteignable. */
@media (hover: none) {
  .conv-del { opacity: 1; color: var(--muted); }
}

/* ---------- Page Profil ---------- */
/* En-tête : identité + métadonnées du compte. Sur mobile tout est empilé,
   sur grand écran la grille des métadonnées s'étale en colonnes. */
.prof-head .avatar { flex: 0 0 auto; }
.prof-name {
  font-size: 17px; font-weight: 650; letter-spacing: -.01em;
  color: var(--text); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prof-meta {
  display: grid; grid-template-columns: 1fr; gap: 0;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--line);
}
.prof-meta > div {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 5px 0;
}
.prof-meta .k { font-size: 11.5px; color: var(--muted); }
.prof-meta .v { font-size: 12.5px; font-weight: 600; color: var(--text); text-align: right; }
@media (min-width: 640px) {
  .prof-meta { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .prof-meta > div { flex-direction: column; align-items: flex-start; gap: 2px; padding: 0; }
  .prof-meta .v { text-align: left; }
}

/* Note d'information : champs non modifiables par l'utilisateur. */
.prof-note {
  display: flex; align-items: flex-start; gap: 7px;
  margin: 4px 0 14px; padding: 9px 11px;
  border-radius: 9px;
  background: var(--info-soft); color: var(--info);
  font-size: 11.5px; line-height: 1.45;
}
.prof-note i { margin-top: 2px; font-size: 10.5px; opacity: .85; }

/* Palette de couleurs d'avatar : pastilles cliquables, la coche n'apparaît
   que sur la teinte sélectionnée. */
.prof-colors { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 7px; }
.prof-color {
  position: relative; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  border: 2px solid transparent;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.prof-color input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.prof-color i { color: #fff; font-size: 11px; opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s; }
.prof-color:hover { transform: scale(1.06); }
.prof-color:has(input:checked) { border-color: var(--text); box-shadow: 0 0 0 2px #fff inset; }
.prof-color:has(input:checked) i { opacity: 1; transform: scale(1); }
.prof-color:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Carte PWA : pastille d'icône + contenu, alignés en haut. */
.prof-pwa-icon {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-tint); color: var(--accent);
  font-size: 16px;
}
.prof-pwa-icon.done { background: var(--ok-soft); color: var(--ok); }

/* Étapes d'installation manuelle (iOS). */
.prof-steps {
  margin: 12px 0 8px; padding-left: 20px;
  font-size: 12.5px; line-height: 1.6; color: var(--text);
}
.prof-steps li { margin-bottom: 5px; }
.prof-steps b { font-weight: 650; }
