/*
 * Dossier chauffeur : grille des pieces et visionneuse.
 * Maquette : mockups/admin-14-driver-documents.html.
 *
 * Les pieces sont des photos de telephone : la vignette les montre ENTIERES
 * (contain), jamais rognees — une carte grise coupee ne se verifie pas.
 * Proprietes logiques partout : l'arabe passe en miroir sans regle a part.
 */

/* ------------------------------------------------------------------ Grille */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.doc-card {
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, border-color 0.15s;
}

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

.doc-card.doc-approved { border-color: #b9dcc7; }
.doc-card.doc-rejected { border-color: #f0c2c4; }
.doc-card.doc-missing { border-style: dashed; background: var(--surface-alt); }

.doc-thumb {
  /* Hauteur fixe : une photo en portrait n'etire pas sa carte. */
  height: 170px;
  overflow: hidden;
  display: grid;
  place-items: center;
  position: relative;
  border: 0;
  padding: 8px;
  width: 100%;
  cursor: zoom-in;
  background: #2b2925;
  color: #cfc8bb;
}

.doc-thumb img {
  /* Contenue dans le cadre, jamais rognee ni debordante. */
  max-width: 100%;
  max-height: 154px;
  width: auto;
  height: auto;
  display: block;
  border-radius: 4px;
}

.doc-thumb.doc-empty {
  cursor: default;
  background: var(--surface-sunk);
  color: var(--ink-500);
  gap: 6px;
  font-size: var(--text-xs);
  align-content: center;
}

.doc-icon .icon {
  width: 30px;
  height: 30px;
}

.doc-pdf {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.doc-broken {
  font-size: var(--text-xs);
  color: #cfc8bb;
}

.doc-zoom {
  position: absolute;
  inset-inline-end: 8px;
  bottom: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink-900);
  opacity: 0;
  transition: opacity 0.15s;
}

.doc-zoom .icon {
  width: 16px;
  height: 16px;
}

.doc-thumb:hover .doc-zoom,
.doc-thumb:focus-visible .doc-zoom {
  opacity: 1;
}

.doc-meta {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.doc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.doc-name {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.3;
}

.doc-top .badge {
  flex-shrink: 0;
}

.doc-sub {
  font-size: 11.5px;
  color: var(--ink-500);
}

.doc-sub .req {
  color: var(--danger);
  font-weight: 600;
}

.doc-why {
  margin: 0;
  padding: 8px 10px;
  background: #fde8e8;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #8e2a1f;
  line-height: 1.4;
}

.doc-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
}

.doc-actions .btn {
  flex: 1;
}

.doc-actions .icon,
.dv-actions .icon {
  width: 16px;
  height: 16px;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid #f0c2c4;
}

.doc-note {
  margin-top: var(--space-4);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  gap: 6px;
}

.doc-note .icon {
  width: 14px;
  height: 14px;
}

/* ------------------------------------------------------------- Visionneuse */
.doc-viewer {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: #141311;
  display: grid;
  grid-template-rows: auto 1fr auto;
  color: #fff;
  animation: dv-in 0.15s ease-out;
}

@keyframes dv-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dv-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.35);
}

.dv-title {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}

.dv-title b {
  font-size: var(--text-md);
}

.dv-title span {
  font-size: 12px;
  color: #b5afa5;
}

.dv-tools {
  margin-inline-start: auto;
  display: flex;
  gap: 6px;
}

.dv-tools button,
.dv-tools a {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.dv-tools button:hover,
.dv-tools a:hover,
.dv-tools .on {
  background: var(--brand-500);
}

.dv-stage {
  position: relative;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  overflow: hidden;
  min-height: 0;
}

.dv-frame {
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: var(--space-4) 0;
}

.dv-frame img {
  /* Toujours entiere a l'ecran : on retire les deux barres et les fleches. */
  max-width: calc(100vw - 160px);
  max-height: calc(100vh - 170px);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s ease;
  background: #fff;
}

.dv-stage.zoomed .dv-frame {
  overflow: auto;
  place-items: start center;
  cursor: zoom-out;
}

.dv-stage.zoomed .dv-frame img {
  /* Zoom reel : l'image double de largeur et la zone defile, pour lire un numero de chassis. */
  max-width: none;
  max-height: none;
  width: calc(2 * (100vw - 160px));
  cursor: zoom-out;
}

.dv-nav {
  width: 46px;
  height: 46px;
  margin: 0 auto;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.dv-nav:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.25);
}

.dv-nav:disabled {
  opacity: 0.25;
  cursor: default;
}

/* En arabe, « precedente » est a droite : les fleches suivent le sens de lecture. */
[dir='rtl'] .dv-nav .icon {
  transform: scaleX(-1);
}

.dv-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.35);
}

.dv-why {
  margin: 0;
  flex-basis: 100%;
  background: rgba(229, 72, 77, 0.18);
  color: #ffd2d4;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
}

.dv-actions {
  display: flex;
  gap: 8px;
}

.dv-actions .btn-danger-ghost {
  color: #ff9a9e;
  border-color: rgba(255, 154, 158, 0.5);
}

.dv-hint {
  margin-inline-start: auto;
  font-size: 12px;
  color: #8f887c;
}

@media (max-width: 700px) {
  .dv-stage {
    grid-template-columns: 44px 1fr 44px;
  }

  .dv-hint {
    display: none;
  }
}

/* ------------------------------------------------ Avatar avec photo */
/* La photo recouvre les initiales ; si elle ne charge pas, elle s'efface. */
.avatar {
  position: relative;
  overflow: hidden;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar.has-photo {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--brand-300);
}

.avatar.avatar-lg {
  width: 64px;
  height: 64px;
  font-size: var(--text-lg);
}

.driver-head {
  gap: var(--space-4);
}

.driver-head h2 {
  margin: 0;
}

/* La photo ouvre la fiche, comme le nom. */
.avatar-link {
  display: inline-flex;
  border-radius: 50%;
  transition: transform 0.12s;
}

.avatar-link:hover {
  transform: scale(1.08);
}

.avatar-link:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}

/* ------------------------------------------ Legende de la carte live */
/* Dit ce que veut dire chaque couleur ; porte aussi le choix Plan / Satellite. */
.map-legend {
  position: absolute;
  bottom: 68px;
  inset-inline-start: 16px;
  z-index: 500;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 10px 12px;
  min-width: 210px;
}

.map-legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-700);
}

.map-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.map-legend i.pulse {
  box-shadow: 0 0 0 4px rgba(229, 72, 77, 0.25);
}

.map-legend i.zone {
  border-radius: 50%;
  border: 2px dashed var(--brand-500);
  box-shadow: none;
  background: rgba(176, 128, 32, 0.08);
}

.legend-type {
  display: flex;
  gap: 4px;
  background: var(--surface-sunk);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 10px;
}

.legend-type[hidden] {
  display: none;
}

.legend-type button {
  flex: 1;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-500);
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.legend-type button.on {
  background: var(--surface);
  color: var(--ink-900);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Avec la legende, la note de repli OpenStreetMap passe au-dessus d'elle. */
.map-legend ~ .map-note,
.map-note:has(~ .map-legend) {
  bottom: 250px;
}
