/* ==========================================================================
   components.css : composants réutilisables (boutons, badges, formulaires,
   cartes, listes de contenu, dialogues, notifications)
   ========================================================================== */

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}

.btn:hover { background: var(--bg); }
.btn.pri { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.pri:hover { background: var(--blue-d); }
.btn.danger { color: var(--red); border-color: #efc4c0; }
.btn.danger:hover { background: var(--red-t); }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.lk {
  min-height: 36px;
  padding: 0 6px;
  border: 0;
  background: none;
  color: var(--blue);
  font-weight: 500;
  text-decoration: none;
}

.lk.danger { color: var(--red); }

.ib {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-s);
  background: none;
}

.ib:hover { background: var(--bg); }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--navh) + env(safe-area-inset-bottom) + 16px);
  z-index: 15;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.b-blue { background: var(--blue-t); color: var(--blue); }
.b-amber { background: var(--amber-t); color: var(--amber); }
.b-green { background: var(--green-t); color: var(--green); }
.b-gray { background: var(--gray-t); color: var(--gray); }

/* ---------- Carte, barre d'outils, pastilles ---------- */
.card {
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 12px; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 8px; }

.search {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--faint);
  background: #fff;
}

.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-t); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--ink); }

.sel { flex: 1 1 0; min-width: 0; }

select, .input {
  width: 100%;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #fff;
}

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }

.chip {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
}

.chip b { margin-left: 6px; font-weight: 600; color: var(--mut); }
.chip[aria-pressed="true"] { background: var(--blue-t); border-color: #b9d4f2; color: var(--blue-d); }

.custom-range { display: flex; flex-wrap: wrap; gap: 10px; }
.custom-range label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--mut); }
.custom-range input { height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }

.foot {
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--mut);
  font-size: 13px;
}

.empty { padding: 32px 16px; text-align: center; color: var(--mut); }
.empty .btn { margin-top: 12px; }

/* ---------- Liste de contenu (Services, Produits, Engins…) ---------- */
.rhead { display: none; }
.ritem { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.ritem:hover { background: var(--bg); }
.rmain { min-width: 0; }
.rlink { display: block; font-weight: 600; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.rlink::after { content: ""; position: absolute; inset: 0; }  /* toute la ligne est cliquable */
.rmeta { display: flex; flex-wrap: wrap; margin-top: 2px; font-size: 13px; color: var(--mut); }
.rcol + .rcol::before { content: "·"; margin: 0 6px; }
.rside { display: flex; align-items: center; gap: 6px; color: var(--faint); }
.ract { display: none; position: relative; z-index: 1; }

.thumb {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue, 210) 60% 45%), hsl(calc(var(--hue, 210) + 40) 65% 55%));
}

/* ---------- Formulaires ---------- */
.fcard { margin-bottom: 16px; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.fcard-title { margin-bottom: 12px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--mut); }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.flabel { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
.req { color: var(--red); }
.fhint { margin-top: 4px; font-size: 12px; color: var(--mut); }
.ferr { margin-top: 4px; font-size: 13px; color: var(--red); }
textarea.input { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.input:focus, select:focus { border-color: var(--blue); outline: 0; box-shadow: 0 0 0 3px var(--blue-t); }
.input[aria-invalid="true"] { border-color: var(--red); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-row small { display: block; font-size: 12px; color: var(--mut); }

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: #c5ccd6;
  cursor: pointer;
  transition: background .2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}

.switch:checked { background: var(--blue); }
.switch:checked::after { transform: translateX(18px); }

.image-field { display: flex; align-items: center; gap: 14px; }
.image-preview { width: 88px; height: 88px; border-radius: var(--radius-s); object-fit: cover; }
.image-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.var-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.fbar {
  position: sticky;
  bottom: calc(var(--navh) + env(safe-area-inset-bottom));
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px -16px;
  padding: 10px 16px;
  background: var(--card);
  border-top: 1px solid var(--line);
}

.fbar-note { flex: 1; font-size: 13px; color: var(--amber); }
.fbar .btn.pri { flex: 1; }

/* ---------- Dialogue de confirmation ---------- */
.dialog-wrap {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 30, 50, .45);
}

.dialog {
  width: 100%;
  max-width: 420px;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  background: var(--card);
  border-radius: 16px 16px 0 0;
}

.dialog h2 { font-size: 18px; }
.dialog p { margin: 8px 0 16px; color: var(--mut); }
.dialog-actions { display: flex; flex-direction: column-reverse; gap: 8px; }

/* ---------- Notification toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--navh) + env(safe-area-inset-bottom) + 16px);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: .2s;
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: #9cc7ff; font-weight: 600; }

@media (min-width: 720px) {
  .toolbar { padding: 16px; }
  .search { flex: 1 1 240px; }
  .sel { flex: 0 0 190px; }
  .chips { flex-wrap: wrap; overflow: visible; }
  .fab { display: none; }
  .toast { bottom: 24px; }

  /* Liste de contenu en tableau */
  .rhead,
  .ritem { grid-template-columns: var(--cols); column-gap: 12px; padding: 10px 16px; }
  .rhead { display: grid; background: var(--bg); border-top: 1px solid var(--line); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--mut); }
  .rmain, .rmeta, .rside { display: contents; }
  .rcol { color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
  .rcol + .rcol::before { content: none; }
  .rcol.is-muted { color: var(--faint); }
  .rside .ic { display: none; }
  .ract { display: flex; justify-content: flex-end; gap: 4px; }

  /* Formulaire */
  .fbar { position: static; margin: 0; padding: 12px 0 0; background: none; border: 0; justify-content: flex-end; }
  .fbar .btn.pri { flex: none; }
  .fbar-note { flex: 1; }

  /* Dialogue centré */
  .dialog-wrap { align-items: center; }
  .dialog { border-radius: 16px; padding-bottom: 20px; }
  .dialog-actions { flex-direction: row; justify-content: flex-end; }
}
