/* ================================================================
   mobile.css — Refonte UX mobile myMecanic
   Bottom navigation bar (style Facebook / TikTok)
   Optimisé pour iPhone 13, Samsung Galaxy, et tous les mobiles
   ================================================================ */

/* ── Variables mobile ──────────────────────────────────────── */
:root {
  --mobile-nav-h: 62px;
  --mobile-header-h: 52px;
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-safe-top: env(safe-area-inset-top, 0px);
  --mobile-nav-total: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom));
}

/* ═══════════════════════════════════════════════════════════
   BOTTOM NAVIGATION BAR — cachée par défaut, affichée en
   mobile uniquement via .is-mobile-loaded (ajouté par JS
   au chargement si largeur ≤ 980px — jamais au resize).
   ═══════════════════════════════════════════════════════════ */
.mobile-nav {
  display: none;
}

@media (max-width: 980px) {

  /* ── Affichage de la bottom nav ──────────────────────────── */
  .is-mobile-loaded .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom));
    padding-bottom: var(--mobile-safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    align-items: stretch;
  }

  /* ── Item de navigation ──────────────────────────────────── */
  .mobile-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: color 0.15s, transform 0.1s;
    cursor: pointer;
    border: none;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    position: relative;
  }

  .mobile-nav__item:active {
    transform: scale(0.92);
  }

  .mobile-nav__item.is-active {
    color: var(--primary);
  }

  /* ── Indicateur actif (point sous l'icône) ───────────────── */
  .mobile-nav__item.is-active::after {
    content: '';
    position: absolute;
    bottom: calc(var(--mobile-safe-bottom) + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
  }

  /* ── Icône ───────────────────────────────────────────────── */
  .mobile-nav__icon {
    font-size: 22px;
    line-height: 1;
    display: block;
    transition: transform 0.15s;
  }

  .mobile-nav__item.is-active .mobile-nav__icon {
    transform: scale(1.12);
  }

  /* ── Label ───────────────────────────────────────────────── */
  .mobile-nav__label {
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    text-align: center;
  }

  /* ── Bouton FAB central (+ Nouveau) ─────────────────────── */
  .mobile-nav__fab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav__fab-btn {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--primary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    font-weight: 300;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.45);
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
    margin-top: -6px;
    text-decoration: none;
    line-height: 1;
  }

  .mobile-nav__fab-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  }

  .mobile-nav__fab-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
    margin-top: 1px;
  }

  /* ── Badge notification ──────────────────────────────────── */
  .mobile-nav__badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    border: 1.5px solid var(--surface);
  }

  /* ═══════════════════════════════════════════════════════════
     HEADER MOBILE — Version slim et épurée
     ═══════════════════════════════════════════════════════════ */

  .header {
    height: var(--mobile-header-h);
    padding: 0 14px;
    padding-top: var(--mobile-safe-top);
  }

  /* Masquer l'email sur mobile */
  .header__userEmail {
    display: none;
  }

  /* Masquer le bouton Déconnexion sur mobile (accessible via la sidebar) */
  .header__logout-btn {
    display: none;
  }

  /* Header title plus compact */
  .header__title {
    font-size: 16px;
    font-weight: 800;
  }

  /* Burger masqué sur mobile (remplacé par bottom nav) */
  .burger {
    display: none !important;
  }

  /* Avatar interactif */
  .header__avatar {
    width: 34px;
    height: 34px;
    cursor: pointer;
  }

  /* ═══════════════════════════════════════════════════════════
     CONTENU PRINCIPAL — Ajustements pour la bottom nav
     ═══════════════════════════════════════════════════════════ */

  /* Ajouter du padding en bas pour que le contenu ne soit pas caché */
  .app__main {
    padding-bottom: calc(var(--mobile-nav-total) + 24px) !important;
  }

  /* Footer app caché sur mobile (remplacé par la bottom nav) */
  .app__footer {
    display: none;
  }

  /* ═══════════════════════════════════════════════════════════
     SIDEBAR MOBILE — Améliorée
     ═══════════════════════════════════════════════════════════ */

  /* Fermer le bouton visible et bien positionné */
  [data-sidebar-close] {
    display: inline-flex !important;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    border: 1px solid var(--border) !important;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--muted);
    cursor: pointer;
    background: var(--surface-2) !important;
  }

  /* Cacher le toggle collapse dans la sidebar (non nécessaire sur mobile) */
  .sidebarToggle {
    display: none !important;
  }

  /* Sidebar prend toute la hauteur avec safe areas */
  .app__sidebar {
    padding-bottom: var(--mobile-safe-bottom);
  }

  /* ═══════════════════════════════════════════════════════════
     COMPOSANTS — Améliorations mobile générales
     ═══════════════════════════════════════════════════════════ */

  /* Boutons plus grands sur mobile (tap targets) */
  .btn {
    min-height: 40px;
    padding: 10px 16px;
  }

  .btn--sm {
    min-height: 36px;
    padding: 8px 12px;
  }

  /* Cards plus arrondies et aérées */
  .card {
    border-radius: 16px;
  }

  /* Inputs plus grands */
  .input {
    font-size: 16px; /* Évite le zoom auto sur iOS */
    padding: 12px 14px;
    min-height: 48px;
  }

  select.input {
    min-height: 48px;
  }

  /* Tables: amélioration de l'affichage card */
  .table tr {
    border-radius: 14px;
    margin-bottom: 12px;
  }

  /* KPIs: 2 colonnes sur mobile */
  .dash-kpiStrip {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  /* Page top: actions en colonne sur petit écran */
  .page__top {
    flex-direction: column;
    align-items: stretch;
  }

  .page__actions {
    justify-content: flex-start;
  }

  /* Dashboard KPI cards plus compactes sur mobile */
  .dash-kpiCard {
    padding: 14px 14px;
  }

  .dash-kpiCard__value {
    font-size: 26px;
  }

  /* Dernier KPI seul sur sa ligne → pleine largeur */
  .dash-kpiStrip > :last-child:nth-child(odd) {
    grid-column: span 2;
  }

  /* Actions dashboard sur mobile: colonne */
  .dash-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .dash-actions {
    flex-wrap: wrap;
  }

  .dash-actions .btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
    font-size: 12px;
    padding: 9px 10px;
  }

  /* Card header avec toolbar : empilement vertical */
  .card__header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .card__header .card__title {
    margin-bottom: 0;
  }

  /* Search bar pleine largeur */
  .search {
    min-width: 100%;
  }

  /* Toolbar pleine largeur */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .toolbar > * {
    width: 100%;
  }

  .toolbar .btn {
    justify-content: center;
  }

  /* Toast repositionné pour ne pas cacher la bottom nav */
  .toasts {
    top: auto;
    bottom: calc(var(--mobile-nav-total) + 10px);
    right: 14px;
    left: 14px;
    max-width: 100%;
  }

  /* Modal: full-width sur mobile */
  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal__panel {
    width: 100%;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
  }

  /* Bouton Guide (tour) repositionné au-dessus de la bottom nav */
  .tour-fab {
    bottom: calc(var(--mobile-nav-total) + 12px) !important;
    right: 14px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   TRÈS PETITS ÉCRANS (< 390px — Samsung Galaxy S, iPhone SE...)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 389px) {
  .mobile-nav__label {
    font-size: 9px;
  }

  .mobile-nav__icon {
    font-size: 20px;
  }

  .mobile-nav__fab-btn {
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .dash-kpiStrip {
    grid-template-columns: 1fr !important;
  }

  .app__main {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   DESKTOP — Sécurité : si .is-mobile-loaded absent → tout caché.
   Empêche la nav d'apparaître sur desktop au resize.
   ═══════════════════════════════════════════════════════════════ */
html:not(.is-mobile-loaded) .mobile-nav {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   DARK MODE — Ajustements pour la bottom nav
   ═══════════════════════════════════════════════════════════════ */
body[data-theme="dark"] .mobile-nav,
.mobile-nav {
  background: rgba(22, 27, 39, 0.95);
}

body[data-theme="light"] .mobile-nav {
  background: rgba(255, 255, 255, 0.95);
}

/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS — Feedback tactile
   ═══════════════════════════════════════════════════════════════ */
@keyframes navTap {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.88); }
  100% { transform: scale(1); }
}

.mobile-nav__item:active .mobile-nav__icon {
  animation: navTap 0.2s ease;
}

/* ═══════════════════════════════════════════════════════════════
   HACK iOS: évite le double-tap zoom sur les liens de nav
   ═══════════════════════════════════════════════════════════════ */
.mobile-nav__item,
.mobile-nav__fab-btn {
  touch-action: manipulation;
}

/* ═══════════════════════════════════════════════════════════════
   BOTTOM SHEETS — Plus & Profil (style iOS)
   ═══════════════════════════════════════════════════════════════ */

/* Backdrop commun */
.mobile-sheet {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
}

.mobile-sheet.is-open {
  display: block;
}

.mobile-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: sheetFadeIn 0.22s ease;
}

@keyframes sheetFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Panel slide-up */
.mobile-sheet__panel {
  position: absolute;
  bottom: calc(var(--mobile-nav-total));
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  padding-bottom: 8px;
  animation: sheetSlideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 75vh;
  overflow-y: auto;
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Handle bar */
.mobile-sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 6px;
}

/* Header du sheet */
.mobile-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.mobile-sheet__title {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mobile-sheet__close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Items de navigation dans le sheet */
.mobile-sheet__nav {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-sheet__item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 12px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.mobile-sheet__item:active {
  background: var(--surface-2);
}

.mobile-sheet__item-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.mobile-sheet__item-label {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.mobile-sheet__item-arrow {
  color: var(--muted);
  font-size: 12px;
  opacity: 0.6;
}

/* Séparateur dans le sheet */
.mobile-sheet__sep {
  height: 1px;
  background: var(--border);
  margin: 6px 12px;
}

/* Item danger (Déconnexion) */
.mobile-sheet__item--danger {
  color: var(--danger);
}

.mobile-sheet__item--danger .mobile-sheet__item-icon {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
}

/* Item actif (page courante) */
.mobile-sheet__item.is-active {
  color: var(--primary);
}

.mobile-sheet__item.is-active .mobile-sheet__item-icon {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.3);
}

/* Toggle mode sombre dans le sheet */
.mobile-sheet__toggle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mobile-sheet__toggle-label {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* Profile header dans le sheet avatar */
.mobile-sheet__profile-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
}

.mobile-sheet__profile-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.4);
  flex-shrink: 0;
}

.mobile-sheet__profile-info {
  flex: 1;
  min-width: 0;
}

.mobile-sheet__profile-name {
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-sheet__profile-email {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* Light mode */
body[data-theme="light"] .mobile-sheet__panel {
  background: #fff;
}

body[data-theme="light"] .mobile-sheet__item:active {
  background: var(--surface-2);
}
