/*
 * mobile-nav.css — Barre d'onglets fixe en bas (mobile uniquement)
 * Phase 2 PWA BRICK·INVEST
 *
 * Structure injectée par mobile-nav.js :
 *   #mobile-tab-bar      — barre du bas (4 onglets)
 *   #mobile-more-overlay — fond semi-transparent du panneau
 *   #mobile-more-panel   — panneau slide-up "Plus"
 *
 * Desktop (>768px) : tout masqué, aucun impact sur le layout existant.
 */

/* ── Masqué par défaut sur desktop ── */
#mobile-tab-bar,
#mobile-more-overlay,
#mobile-more-panel { display: none; }

/* ══════════════════════════════════════════
   Mobile uniquement
   ══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Header : rangée unique, hauteur fixe ── */
  header {
    height: 56px !important;
    flex-wrap: nowrap !important;
    padding: 0 14px !important;
    align-items: center !important;
  }
  .logo  { height: 56px !important; flex: initial !important; }
  .header-right { height: 56px !important; }
  .header-date  { display: none !important; }
  .hamburger    { display: none !important; }

  /* ── Masquer la nav horizontale ── */
  .nav-center { display: none !important; }

  /* ── Décaler le contenu pour ne pas passer sous la barre ── */
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important; }
  .app  { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important; }

  /* ── Modales et popups au-dessus de la barre ── */
  .modal-bg    { z-index: 1100 !important; }
  #surcartonPop { z-index: 1100 !important; }

  /* ══════════════════════════════════
     Barre d'onglets
     ══════════════════════════════════ */
  #mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg2, #1c1c1c);
    border-top: 1px solid var(--border, #262626);
    z-index: 1000;
    justify-content: space-around;
    align-items: stretch;
  }

  .mob-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 48px;
    color: var(--text3, #555);
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    padding: 0 4px;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.12s, opacity 0.12s;
  }

  /* Fix iOS Safari : flex:1 peut ne pas s'appliquer aux <button> dans un flex parent */
  #mobile-tab-bar > button.mob-tab {
    -webkit-flex: 1 1 0;
    flex: 1 1 0;
    width: 25%;
    min-width: 0;
    display: -webkit-flex;
    display: flex;
  }
  .mob-tab:active { opacity: 0.65; }
  .mob-tab.active { color: var(--orange, #E8922A); }
  .mob-tab.more-active { color: var(--orange, #E8922A); opacity: 0.75; }

  .mob-tab-icon  { font-size: 20px; line-height: 1; pointer-events: none; }
  .mob-tab-label {
    font-size: 10px;
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    line-height: 1;
    pointer-events: none;
  }

  /* ══════════════════════════════════
     Overlay du panneau Plus
     ══════════════════════════════════ */
  #mobile-more-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1001;
  }
  #mobile-more-overlay.open { display: block; }

  /* ══════════════════════════════════
     Panneau Plus (bottom sheet)
     Fermé : display:none (aucun pixel rendu, poignée incluse)
     Ouvert : slide-up via @keyframes (transition incompatible avec display:none)
     ══════════════════════════════════ */
  #mobile-more-panel {
    display: none;
    position: fixed;
    left: 0; right: 0;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    max-height: 68vh;
    background: var(--bg2, #1c1c1c);
    border-top: 1px solid var(--border, #262626);
    border-radius: 16px 16px 0 0;
    z-index: 1002;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #mobile-more-panel.open {
    display: flex;
    flex-direction: column;
    animation: mob-panel-up 0.26s cubic-bezier(0.34, 1.15, 0.64, 1);
  }
  @keyframes mob-panel-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* Poignée visuelle */
  .mob-panel-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    cursor: pointer;
  }
  .mob-panel-handle::after {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--border2, #333);
    border-radius: 2px;
  }

  /* Grille 3 colonnes */
  .mob-panel-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 4px 10px 18px;
  }

  .mob-panel-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 12px 6px;
    color: var(--text2, #9aa0ae);
    text-decoration: none;
    border-radius: 10px;
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transition: background 0.1s, color 0.1s;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-panel-item:active { background: var(--bg3, #242424); }
  .mob-panel-item.active { color: var(--orange, #E8922A); }

  .mob-panel-icon { font-size: 22px; line-height: 1; }

  /* ══════════════════════════════════
     Classe utilitaire : carrousel horizontal
     ══════════════════════════════════ */
  .mobile-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 10px;
    padding: 4px 16px 12px 16px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mobile-carousel::-webkit-scrollbar { display: none; }
  .mobile-carousel > * {
    scroll-snap-align: start;
    flex: 0 0 auto;
    min-width: 140px;
  }

  /* ══════════════════════════════════
     Stats — 2× .kpi-grid.dash7 → carrousel
     ══════════════════════════════════ */
  .kpi-grid.dash7 {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 10px;
    padding: 4px 0 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .kpi-grid.dash7::-webkit-scrollbar { display: none; }
  .kpi-grid.dash7 > .kpi-card {
    flex: 0 0 auto;
    min-width: 130px;
    scroll-snap-align: start;
  }

  /* ══════════════════════════════════
     Stock — accordéon Vinted : empilement vertical sur mobile
     ══════════════════════════════════ */
  /* acc-wrap passe d'une grille 3 colonnes desktop à 1 colonne */
  .acc-wrap { grid-template-columns: 1fr !important; padding: 12px 14px !important; gap: 12px !important; }
  /* acc-stats : grille 2×3 compacte (pas de carrousel) */
  .acc-stats { display: grid !important; grid-template-columns: 1fr 1fr; gap: 6px; overflow: visible; }
  .acc-stats > .acc-stat { flex: none; min-width: 0; }

  /* Infos set (mobile uniquement) */
  .acc-mobile-info { display: block; padding-bottom: 10px; border-bottom: 1px solid var(--border, #262626); margin-bottom: 4px; }
  /* Boutons d'action (mobile uniquement) */
  .acc-mobile-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border, #262626);
    margin-top: 4px;
  }
  .acc-mobile-actions > .btn { width: 100%; text-align: left; font-size: 14px; padding: 9px 14px; }

  /* ══════════════════════════════════
     Stock — .kpi-grid.stock → grille 2×2 (4 cartes visibles, 3 cachées)
     ══════════════════════════════════ */
  .kpi-grid.stock {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    overflow: visible;
    padding: 0 0 8px;
  }
  .kpi-grid.stock > .kpi-card { flex: none; min-width: 0; }
  /* Masquer Valeur LEGO, Plus-value latente, Remise moyenne */
  .kpi-grid.stock .kpi-card:has(#kLego),
  .kpi-grid.stock .kpi-card:has(#kPV),
  .kpi-grid.stock .kpi-card:has(#kRemise) { display: none; }

  /* ══════════════════════════════════
     Stock — accordéon : polices réduites + width correcte
     ══════════════════════════════════ */
  .acc-wrap { width: 100%; box-sizing: border-box; }
  .acc-stat { padding: 5px 8px; }
  .acc-stat-k { font-size: 12px; }
  .acc-stat-v { font-size: 15px; }

  /* ══════════════════════════════════
     KPI cards — réduction police universelle (toutes pages)
     Cible : .kpi-card / .kpi-label / .kpi-value (et .kpi-val alias prévision) / .kpi-sub
     Ces styles écrasent les définitions inline de chaque page grâce à la priorité
     de source de mobile-nav.css (chargé en dernier dans <head>).
     ══════════════════════════════════ */
  .kpi-card {
    height: auto !important;
    padding: 10px !important;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
  }
  .kpi-label { font-size: 13px !important; }
  .kpi-value { font-size: 27px !important; }
  .kpi-val   { font-size: 27px !important; }
  .kpi-sub   { font-size: 12px !important; white-space: normal !important; }

  /* ══════════════════════════════════
     Ventes — .kpi-grid.ventes + .kpi-group → grille 2×2 (remplace carrousel)
     ══════════════════════════════════ */
  .kpi-grid.ventes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    overflow: visible;
    padding: 0 0 8px;
  }
  .kpi-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  /* ══════════════════════════════════
     Ventes — réordonnancement KPI mobile
     Ligne 1 : Ventes | Capital investi
     Ligne 2 : Durée moy. | CA total
     Ligne 3 : Profit brut | Profit net | ROI net (pleine largeur)
     ══════════════════════════════════ */
  .kpi-g-ventes  { order: 1; }
  .kpi-g-capital { order: 2; }
  .kpi-g-duree   { order: 3; }
  .kpi-g-ca      { order: 4; }
  .kpi-profit-group { order: 5; }

  /* Carte profit unifiée : span 2 colonnes, 3 sous-blocs horizontaux dans un seul cadre */
  .kpi-profit-group {
    grid-column: 1 / -1 !important;
    display: flex !important;
    flex-direction: row !important;   /* sous-blocs côte à côte (écrase flex-direction:column de .kpi-group) */
    gap: 0 !important;
    background: var(--bg2, #1c1c1c);
    border: 1px solid var(--border, #262626) !important;
    border-top: 2px solid var(--green, #4caf50) !important;
    border-radius: var(--radius, 8px);
    padding: 10px 12px !important;
    min-width: 0;
    box-sizing: border-box;
  }
  /* Chaque sous-bloc : fond transparent, pas de bordure individuelle, séparateur vertical */
  .kpi-profit-group .kpi-card {
    background: transparent !important;
    border: none !important;
    border-left: 1px solid var(--border, #262626) !important;
    border-radius: 0 !important;
    padding: 0 10px !important;
    height: auto !important;
    flex: 1;
    min-width: 0;
    text-align: center;
  }
  .kpi-profit-group .kpi-card:first-child {
    border-left: none !important;
    padding-left: 0 !important;
  }
  /* Alignement labels : réserve l'espace de 2 lignes pour tous les labels,
     texte collé en bas → les valeurs s'alignent quelle que soit la longueur du label */
  .kpi-profit-group .kpi-label {
    min-height: 2.8em;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }
} /* end @media */
