/* mobile.css — Couche UX mobile native (Improved Agency v4)
   Mobile-first : safe areas, touch targets 44px+, typographie anti-zoom iOS */

:root {
  --nav-height: calc(72px + env(safe-area-inset-bottom, 0px));
  --header-height: 56px;
  --touch-min: 44px;
  --page-x: clamp(14px, 4vw, 20px);
  --sheet-radius: 24px;
}

/* ─── Page shell (wrapper standard des écrans) ─────────────── */
.page-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

.page-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top, 0px)) var(--page-x) 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.page-header--sticky {
  position: sticky;
  top: 0;
}

.page-header__main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.page-header__text { min-width: 0; flex: 1; }

.page-header__eyebrow {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand);
  margin-bottom: 2px;
}

.page-header__title {
  font-size: clamp(20px, 5.5vw, 24px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-header__subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
  line-height: 1.4;
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.page-back {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}
.page-back:active { transform: scale(0.92); background: var(--bg-3); }

.page-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 0 var(--page-x) var(--nav-height);
}

.page-body--flush { padding-left: 0; padding-right: 0; }

.subscription-banner {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px var(--page-x, 10px);
  background: linear-gradient(90deg, var(--brand), #006b4f);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

/* Barre d'actions collante au-dessus de la nav */
.mobile-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--nav-height);
  z-index: 90;
  display: flex;
  gap: 10px;
  padding: 10px var(--page-x);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
}
.mobile-action-bar .btn { flex: 1; min-height: var(--touch-min); }

/* ─── Touch & inputs natifs ────────────────────────────────── */
@media (max-width: 899px) {
  .form-input,
  .search-bar input,
  select.form-input,
  textarea.form-input {
    font-size: 16px !important; /* évite le zoom auto iOS */
    min-height: var(--touch-min);
    border-radius: 14px;
  }

  textarea.form-input { min-height: 96px; }

  .btn {
    min-height: var(--touch-min);
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .btn-sm {
    min-height: 38px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .icon-btn {
    width: var(--touch-min);
    height: var(--touch-min);
  }

  /* Désactive les effets hover sur écran tactile */
  @media (hover: none) {
    .card-interactive:hover,
    .pipeline-card:hover,
    .fab-menu-item:hover {
      transform: none;
      box-shadow: inherit;
    }
  }

  .card-interactive:active,
  .pipeline-card:active {
    transform: scale(0.98);
    opacity: 0.92;
  }

  /* Topbar legacy → compacte */
  .topbar {
    padding: max(10px, env(safe-area-inset-top, 0px)) var(--page-x) 10px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: clamp(18px, 5vw, 22px) !important;
  }

  /* Scroll global avec espace nav */
  body:has(.bottom-nav.visible) .scroll-zone {
    padding-bottom: calc(var(--nav-height) + 12px) !important;
  }

  body:has(.bottom-nav.visible) #app {
    padding-bottom: 0;
  }

  /* Toast au-dessus de la barre */
  .toast {
    bottom: calc(var(--nav-height) + 12px) !important;
    left: var(--page-x) !important;
    right: var(--page-x) !important;
    width: auto !important;
    max-width: none !important;
  }

  /* Sabi au-dessus de la nav */
  #sabi-command-bubble {
    bottom: calc(var(--nav-height) + 12px) !important;
    right: var(--page-x) !important;
  }

  #sabi-command-panel {
    bottom: calc(var(--nav-height) + 72px) !important;
    right: var(--page-x) !important;
    left: var(--page-x) !important;
    width: auto !important;
    max-width: none !important;
  }

  /* Sheets pleine largeur mobile — au-dessus de la bottom nav (z-index 1000) */
  .sheet-overlay {
    align-items: flex-end;
    z-index: 1200;
  }
  .sheet {
    max-height: min(96dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 4px));
    width: 100%;
    max-width: none;
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  }
  .sheet-handle {
    width: 48px;
    height: 5px;
    margin: 10px auto 6px;
  }
  .sheet-body {
    padding: 8px var(--page-x) calc(24px + env(safe-area-inset-bottom, 0px));
  }

  body.sheet-open .bottom-nav {
    pointer-events: none;
  }
  body.sheet-open .sheet-overlay,
  body.sheet-open .sheet-body {
    touch-action: pan-y;
  }

  /* Tab bar scrollable sur petit écran */
  .tab-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-btn { flex: 0 0 auto; min-width: max-content; padding: 10px 14px; }

  /* Grilles KPI une colonne si très étroit */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Menu mobile grid */
  .mobile-menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 0 var(--page-x);
  }

  .mobile-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 92px;
    padding: 12px 8px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 18px;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.15s ease;
  }
  .mobile-menu-item:active { transform: scale(0.96); }

  .mobile-menu-section {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-4);
    padding: 16px var(--page-x) 8px;
  }

  /* Confirm sheet : boutons empilés sur très petit écran */
  .confirm-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
  }
  .confirm-actions .btn { width: 100%; min-height: var(--touch-min); }

  /* Kanban horizontal fluide */
  .kanban-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding: 0 var(--page-x) 8px;
    margin: 0 calc(var(--page-x) * -1);
  }
  .kanban-scroll > * {
    scroll-snap-align: start;
    flex: 0 0 min(85vw, 320px);
  }

  /* Chips horizontaux */
  .chip-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2px var(--page-x) 10px;
    scrollbar-width: none;
  }
  .chip-scroll::-webkit-scrollbar { display: none; }

  /* Toggle actif dans les en-têtes */
  .icon-btn--active {
    background: var(--brand) !important;
    border-color: var(--brand) !important;
    color: #fff !important;
  }

  /* Grilles listes → une colonne sur mobile */
  #clients-list,
  #projects-list {
    grid-template-columns: 1fr !important;
  }

  /* Dashboard : actions header compactes */
  .page-header__actions--compact .icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  /* Meeting stats : 2 colonnes au lieu de 3 */
  #meetings-stats {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Gateway : pills scrollables */
  .gw-pills {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px var(--page-x) 4px;
    scrollbar-width: none;
  }
  .gw-pills::-webkit-scrollbar { display: none; }

  /* WhatsApp / CRM : layout empilé */
  .cs-layout {
    flex-direction: column !important;
    height: 100dvh;
  }
  .cs-layout .cs-sidebar {
    width: 100% !important;
    max-height: 45dvh;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
  }
  .cs-layout .cs-chat {
    flex: 1 !important;
    min-height: 0;
  }
  .cs-layout.cs-chat-open .cs-sidebar { display: none; }
  .cs-layout.cs-chat-open .cs-chat { max-height: none; }

  /* KPI pipeline leads */
  .leads-kpi-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px var(--page-x) 0;
    scrollbar-width: none;
  }
  .leads-kpi-scroll::-webkit-scrollbar { display: none; }
  .leads-kpi-scroll > * { flex: 0 0 min(42vw, 160px); }

  /* Chat CRM : padding mobile */
  #chat-messages { padding: 16px var(--page-x) !important; }
  #chat-input-area { padding: 12px var(--page-x) calc(12px + env(safe-area-inset-bottom, 0px)) !important; }
  #wa-quick-replies { padding: 0 var(--page-x) !important; }
  #cs-back-list { display: none !important; }
  .cs-layout.cs-chat-open #cs-back-list { display: inline-flex !important; }

  /* Footers fixes au-dessus de la bottom nav */
  body:has(.bottom-nav.visible) .form-footer {
    bottom: var(--nav-height) !important;
  }

  /* Grilles formulaire profil lead → 1 colonne */
  .form-grid { grid-template-columns: 1fr !important; }

  /* Onglets profil scrollables */
  .profile-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 16px;
  }
  .profile-tabs::-webkit-scrollbar { display: none; }
  .profile-tabs .tab { flex: 0 0 auto; white-space: nowrap; }

  /* Actions rapides profil */
  .profile-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .profile-actions::-webkit-scrollbar { display: none; }
  .profile-actions .btn { flex: 0 0 auto; white-space: nowrap; }
}

/* Desktop : page shell avec sidebar */
@media (min-width: 900px) {
  .page-header { padding-top: 16px; }
  .page-body { padding-bottom: 24px; }
  .mobile-action-bar { display: none; }
  .confirm-actions { flex-direction: row; }
  .camp-action-bar { bottom: 0 !important; }
  body:has(.bottom-nav.visible) .form-footer { bottom: 0 !important; }
}
