/* ═══════════════════════════════════════════════════
   CAPACITOR.CSS — Mobile-first overrides for ProxiChip
   ═══════════════════════════════════════════════════ */

/* ── iOS Safe Area (Dynamic Island / Notch) ── */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --mob-header-h: 56px;
  --mob-nav-h: 60px;
}

/* ── Pas de scroll horizontal — protection globale ── */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}
.app-layout {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
}
.main, .page, .card, .kpi-grid, .grid-2, .grid-3 {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Les tableaux restent scrollables dans leur conteneur */
.table-responsive,
div[style*="overflow-x"] {
  -webkit-overflow-scrolling: touch;
}

/* ══════════════════════════════════════════════════════
   MOBILE ONLY  (≤ 768px)
══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── 1. Masquer le header desktop et la sidebar ── */
  .sidebar { display: none !important; }
  .header  { display: none !important; }

  /* ── 2. Compenser la Dynamic Island sur body (login, register) ── */
  body {
    padding-top: var(--sat);
    padding-bottom: var(--sab);
  }

  /* ── 3. Layout principal ── */
  .app-layout {
    flex-direction: column;
  }
  .main {
    padding-top: calc(var(--mob-header-h) + var(--sat));
    padding-bottom: calc(var(--mob-nav-h) + var(--sab));
    min-height: 100dvh;
  }
  .page { padding: 1rem !important; }

  /* ── 4. Mobile Header (barre du haut) ── */
  .mob-header {
    display: flex !important;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(var(--mob-header-h) + var(--sat));
    padding-top: var(--sat);
    background: var(--bg, #070B14);
    border-bottom: 1px solid var(--border-soft, rgba(255,255,255,.06));
    align-items: center;
    justify-content: space-between;
    padding-left: 1.1rem;
    padding-right: 1rem;
    z-index: 900;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  .mob-header-left {
    display: flex;
    align-items: center;
    gap: .6rem;
  }
  .mob-logo-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent, #6366f1), var(--accent-2, #8b5cf6));
    border-radius: 8px;
    font-size: .6rem;
    font-weight: 900;
    color: #fff;
    letter-spacing: .04em;
    flex-shrink: 0;
  }
  .mob-header-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text, #e8f2ff);
    letter-spacing: -.01em;
  }
  .mob-header-right {
    display: flex;
    align-items: center;
    gap: .5rem;
  }
  .mob-avatar-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent-dim, rgba(99,102,241,.15));
    border: 2px solid var(--accent, #6366f1);
    color: var(--accent, #6366f1);
    font-size: .75rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
  }
  .mob-avatar-btn:active { background: var(--accent-dim, rgba(99,102,241,.25)); }

  /* ── 5. Mobile Bottom Nav ── */
  .mob-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--mob-nav-h) + var(--sab));
    padding-bottom: var(--sab);
    background: var(--bg, #070B14);
    border-top: 1px solid var(--border-soft, rgba(255,255,255,.06));
    align-items: center;
    justify-content: space-around;
    z-index: 900;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  .mob-tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    background: none;
    border: none;
    color: var(--text-muted, #6b7a99);
    font-size: .6rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    padding: .35rem .5rem;
    border-radius: 10px;
    transition: color .15s;
    flex: 1;
  }
  .mob-tab-btn i { font-size: 1.25rem; transition: transform .15s; }
  .mob-tab-btn.active { color: var(--accent, #6366f1); }
  .mob-tab-btn.active i { transform: scale(1.1); }

  /* ── 6. Admin bottom nav ── */
  .mobile-admin-nav { display: flex !important; }
  .back-btn { display: flex !important; }
  .main.admin-main { padding-bottom: calc(var(--mob-nav-h) + var(--sab)); }

  /* ── 7. Grilles → 1 colonne ── */
  .grid-2  { grid-template-columns: 1fr !important; }
  .kpi-grid { grid-template-columns: 1fr 1fr !important; }

  /* ── 8. Page header → compact ── */
  .page-header { margin-bottom: 1rem !important; }
  .page-header h1 { font-size: 1.4rem !important; }
  .page-header p { font-size: .8rem !important; }

  /* ── 9. Cards ── */
  .card { border-radius: 14px !important; }
  .card-header { flex-wrap: wrap; gap: .5rem; }

  /* ── 10. KPI cards ── */
  .kpi-card { padding: 1rem !important; }
  .kpi-value { font-size: 1.5rem !important; }

  /* ── 11. Tableau Commandes → cards ── */
  .orders-table-wrap { display: none !important; }
  .orders-cards-wrap { display: flex; flex-direction: column; gap: .75rem; }

  /* ── 12. Boutons header admin ── */
  .header-actions .btn-secondary { display: none !important; }

  /* ── 13. Touch-friendly inputs ── */
  input, select, textarea {
    font-size: 16px !important; /* évite le zoom auto sur iOS */
  }
}

/* ── Cacher les éléments mobile sur desktop ── */
.mob-header     { display: none; }
.mob-bottom-nav { display: none; }

/* ── Badge pill dans le header mobile ── */
.mob-badge-pill {
  display: none; /* affiché par JS si >1 badge */
  align-items: center;
  gap: .3rem;
  background: var(--bg-2, rgba(255,255,255,.05));
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: .25rem .65rem .25rem .45rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  font-family: inherit;
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mob-badge-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success, #22c55e);
  flex-shrink: 0;
}

/* ── Bottom sheet (badge picker) ── */
.mob-sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1100;
  opacity: 0;
  transition: opacity .3s;
}
.mob-sheet-overlay.open { opacity: 1; }

.mob-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-card, #101828);
  border-radius: 20px 20px 0 0;
  padding: .75rem 1.25rem 2rem;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
  z-index: 1101;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,0,.67,0);
  max-height: 75vh;
  overflow-y: auto;
}
.mob-sheet.open { transform: translateY(0); }

.mob-sheet-handle {
  width: 36px; height: 4px;
  background: var(--border, rgba(255,255,255,.15));
  border-radius: 99px;
  margin: 0 auto .875rem;
}
.mob-sheet-title {
  font-size: 1rem; font-weight: 700;
  color: var(--text);
  margin-bottom: .875rem;
}
.mob-sheet-new-btn {
  width: 100%;
  padding: .75rem;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: none;
  color: var(--text-muted);
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: .25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  transition: color .15s, border-color .15s;
}
.mob-sheet-new-btn:active { color: var(--accent); border-color: var(--accent); }

/* ── Link items : border visible + contenu contenu sur mobile ── */
@media (max-width: 768px) {
  .link-item {
    border-color: var(--border, rgba(0,198,255,.12)) !important;
    background: var(--bg-card, #101828) !important;
    overflow: hidden !important;       /* empêche le débordement */
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .link-url {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100%;
  }
  /* Contenir tout le tab-content pour éviter le débord */
  #tab-links, #tab-links .card, #tab-links .grid-2 {
    overflow: hidden;
    max-width: 100%;
    box-sizing: border-box;
  }
  /* Hint du formulaire lien */
  #link-url-hint {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
}

/* ── NFC preview card : contenu sur mobile ── */
@media (max-width: 768px) {
  .nfc-preview {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    flex-shrink: 1 !important;
  }
  /* Wrapper centré de la carte badge */
  .card > div > .nfc-preview,
  .card div[style*="justify-content:center"] .nfc-preview,
  .card div[style*="justify-content: center"] .nfc-preview {
    width: 100% !important;
    max-width: 100% !important;
  }
  /* Texte settings : pas de coupure */
  .settings-section p,
  .card p,
  .setting-row span {
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal !important;
  }
}

/* ── Admin bottom nav (réutilisé) ── */
.mobile-admin-nav { display: none; }
.back-btn { display: none; }

/* ── iOS safe area pour la bottom nav desktop non-cachée ── */
@media (min-width: 769px) {
  .mob-header, .mob-bottom-nav { display: none !important; }
}
