/* ═══════════════════════════════════════════════════════════
   MANGAVAULT — RESPONSIVE MOBILE  v2
   À inclure APRÈS main.css dans index.html
   <link rel="stylesheet" href="/css/mobile.css">
   ═══════════════════════════════════════════════════════════ */

/* ── HAMBURGER BUTTON ─────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background .2s;
  flex-shrink: 0;
}
.hamburger:hover { background: var(--surface); }
.hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all .3s ease;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── OVERLAY MENU MOBILE ──────────────────────────────────── */
.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 56px 0 0 0;
  background: var(--bg);
  backdrop-filter: blur(20px);
  z-index: 490;
  flex-direction: column;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  overflow-y: auto;
  animation: slideDown .22s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.mobile-nav-overlay.open { display: flex; }

.mobile-nav-overlay a,
.mobile-nav-overlay button.nav-mobile-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 22px;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  border: none;
  background: none;
  font-family: var(--font);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .15s, color .15s;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
}
.mobile-nav-overlay a:last-child,
.mobile-nav-overlay button.nav-mobile-btn:last-child { border-bottom: none; }
.mobile-nav-overlay a:hover,
.mobile-nav-overlay button.nav-mobile-btn:hover { background: var(--surface); color: var(--accent); }
.mobile-nav-overlay .nav-admin-link { color: var(--accent); }

.mobile-nav-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.mobile-nav-user {
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mobile-nav-user .nav-avatar-lg {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; overflow: hidden; flex-shrink: 0;
}
.mobile-nav-user .nav-avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.mobile-nav-username { font-size: 15px; font-weight: 600; }

/* ══════════════════════════════════════════════════════════
   BREAKPOINT PRINCIPAL — ≤ 768px
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── HEADER ──────────────────────────────────────────────
     FIX : quand connecté, le pseudo + bouton déco débordaient
     et poussaient le hamburger hors de l'écran.
     Solution : on cache TOUT dans .header-right et #authButtons,
     le hamburger reste toujours visible collé à droite.
  ─────────────────────────────────────────────────────────── */
  #header {
    padding: 0 14px;
    height: 56px;
    gap: 10px;
    overflow: hidden; /* aucun débordement horizontal */
  }

  .logo {
    font-size: 17px;
    letter-spacing: 2px;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .logo-icon { font-size: 15px; }

  /* Cacher la nav desktop */
  .nav-links { display: none !important; }

  /* Cacher TOUT le header-right (pseudo, avatar, déco, connexion, inscription) */
  .header-right { display: none !important; }

  /* Afficher le hamburger collé à droite */
  .hamburger {
    display: flex;
    margin-left: auto;
  }

  /* ── PAGE ────────────────────────────────────────────── */
  .page { min-height: calc(100vh - 56px); }

  /* ── HERO ────────────────────────────────────────────── */
  .hero { padding: 28px 16px 24px; }
  .hero-text h1 { font-size: clamp(26px, 8vw, 44px); }
  .hero-text p  { font-size: 13px; }
  .hero::before { font-size: 110px; }

  /* ── SECTIONS ────────────────────────────────────────── */
  .section,
  .chapter-list-section { padding: 20px 14px; }
  .section-header { gap: 10px; margin-bottom: 16px; flex-direction: column; align-items: flex-start; }
  .section-header h2 { font-size: 20px; }
  .search-wrap { width: 100%; }
  .search-wrap input { width: 100%; }

  /* ── MANGA GRID ──────────────────────────────────────── */
  .manga-grid {
    grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
    gap: 12px;
  }
  .manga-grid.mini {
    grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
  }
  .manga-info { padding: 8px 10px 10px; }
  .manga-title { font-size: 12px; }

  /* ── MANGA DETAIL ────────────────────────────────────── */
  .manga-detail-hero { flex-direction: column; gap: 20px; padding: 24px 14px; }
  .manga-detail-cover { width: 130px; margin: 0 auto; }
  .manga-detail-title { font-size: clamp(22px, 7vw, 36px); }
  .manga-detail-actions { flex-direction: column; }
  .manga-detail-actions > * { width: 100%; text-align: center; }

  /* ── CHAPTER LIST ────────────────────────────────────── */
  .chapter-list { max-width: 100%; }
  .chapter-row { padding: 10px 12px; }
  .chapter-num { font-size: 15px; min-width: 44px; }

  /* ── READER ──────────────────────────────────────────── */
  .reader-toolbar { padding: 6px 10px; top: 56px; flex-wrap: wrap; gap: 6px; }
  body.scan-reading #page-scan-reader .reader-toolbar { top: 0; }
  body.scan-reading #scanReaderContent { padding-top: 60px; }
  .reader-left { gap: 8px; }
  .reader-info { font-size: 11px; }
  .reader-right { gap: 6px; flex-wrap: wrap; }
  .ch-select { max-width: 110px; font-size: 11px; }
  .ch-arrow-btn { display: none; }
  .view-scroll { padding: 6px 2px; }
  .view-single { padding: 8px; min-height: calc(100vh - 120px); }
  .view-double { padding: 8px 2px; gap: 2px; }
  .view-single img { max-height: calc(100vh - 140px); }
  .view-double img { max-height: calc(100vh - 140px); max-width: 49.5%; }

  /* ── BLOG ────────────────────────────────────────────── */
  .blog-hero { padding: 28px 14px 20px; flex-direction: column; gap: 14px; }
  .blog-hero-text h1 { font-size: clamp(26px, 8vw, 44px); }
  .blog-toolbar { padding: 14px 14px 0; gap: 10px; }
  .search-input { width: 100%; }
  .blog-grid { grid-template-columns: 1fr; gap: 14px; }
  .blog-card-body { padding: 16px; }
  .blog-card-footer { padding: 10px 16px; }

  /* ── ARTICLE ─────────────────────────────────────────── */
  .article-container,
  .article-body-wrap { padding: 20px 14px; }
  .article-hero { padding: 24px 14px 20px; }
  .article-title { font-size: clamp(22px, 6vw, 38px); }
  .comments-section { padding: 0 14px 32px; }

  /* ── WRITE ───────────────────────────────────────────── */
  .write-container { padding: 20px 14px; }
  .write-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .write-header h1 { font-size: 24px; }

  /* ── REQUESTS ────────────────────────────────────────── */
  .req-type-selector { flex-direction: column; }
  .req-type-option { justify-content: flex-start; }
  .req-filter { font-size: 12px; padding: 5px 10px; }

  /* ── MESSAGES ────────────────────────────────────────── */
  .messages-layout {
    grid-template-columns: 1fr;
    height: calc(100vh - 56px);
  }
  .convos-panel { display: flex; }
  .convos-panel.mobile-hidden { display: none !important; }
  .chat-panel.mobile-hidden { display: none !important; }
  .chat-back-btn { display: flex !important; }
  .msg-bubble { max-width: 82%; font-size: 13px; }

  /* ── ADMIN ───────────────────────────────────────────── */
  .admin-container { padding: 20px 14px; }
  .admin-title { font-size: clamp(22px, 6vw, 36px); }
  .admin-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .admin-tabs { flex-wrap: wrap; gap: 6px; }
  .admin-tab { font-size: 12px; padding: 6px 10px; }

  /* ── PROFILE ─────────────────────────────────────────── */
  .profile-hero { padding: 24px 14px 20px; flex-direction: column; align-items: center; text-align: center; }
  .profile-stats { justify-content: center; }
  .profile-section { padding: 20px 14px; }

  /* ══════════════════════════════════════════════════════
     MODALS MOBILE — style "bottom sheet"
     FIX : les modals apparaissaient coupées ou mal
     positionnées. Elles glissent maintenant depuis le bas,
     pleine largeur, avec scroll interne si besoin.
  ═════════════════════════════════════════════════════════ */
  .modal-overlay {
    align-items: flex-end;  /* colle en bas de l'écran */
    padding: 0;
  }

  .modal {
    width: 100vw;
    max-width: 100vw;
    border-radius: 20px 20px 0 0;
    padding: 8px 20px 36px; /* 8px en haut pour la poignée */
    max-height: 88vh;
    overflow-y: auto;
    box-sizing: border-box;
    animation: sheetUp .28s cubic-bezier(.32,.72,0,1);
  }
  @keyframes sheetUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
  }

  /* Poignée visuelle (drag handle) */
  .modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 20px;
  }

  .modal h2 { font-size: 21px; margin-bottom: 14px; }

  /* Inputs plus grands pour le toucher, et on désactive
     le zoom automatique iOS (font-size ≥ 16px) */
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px !important;
    padding: 12px 14px;
  }

  /* Bouton principal dans modal */
  .btn-accent.full { padding: 14px; font-size: 15px; }

  /* Résultats de recherche dans "Nouvelle conversation" :
     limite la hauteur pour rester dans la modal */
  #userSearchResults {
    max-height: 180px;
    overflow-y: auto;
  }

  /* Buttons héros */
  .hero .btn-accent,
  .hero .btn-ghost { width: 100%; text-align: center; margin-top: 6px; }

  /* ── TOASTS ──────────────────────────────────────────── */
  .toast {
    bottom: 16px;
    font-size: 12px;
    padding: 8px 16px;
    max-width: 90vw;
    text-align: center;
    white-space: normal;
  }

  /* ── POLL ────────────────────────────────────────────── */
  .poll-widget { padding: 14px 16px; }
}

/* ══════════════════════════════════════════════════════════
   TRÈS PETIT ÉCRAN — ≤ 380px
   ══════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .manga-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .logo { font-size: 15px; letter-spacing: 1px; }
  .admin-stats { grid-template-columns: 1fr 1fr; }
}

/* ══════════════════════════════════════════════════════════
   TABLETTE — 769px → 1024px
   ══════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  #header { padding: 0 20px; gap: 16px; }
  .nav-links a { padding: 5px 9px; font-size: 12px; }
  .section, .chapter-list-section { padding: 28px 20px; }
  .hero { padding: 48px 20px 36px; }
  .manga-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .blog-grid  { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .manga-detail-hero { padding: 32px 20px; gap: 24px; }
  .hamburger { display: none; }
  .mobile-nav-overlay { display: none !important; }
}

/* ══════════════════════════════════════════════════════════
   BOUTON RETOUR CHAT (caché sur desktop, visible sur mobile)
   ══════════════════════════════════════════════════════════ */
.chat-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color .15s;
  flex-shrink: 0;
}
.chat-back-btn:hover { color: var(--accent); }

/* ══════════════════════════════════════════════════════════
   NAV AVATAR (header desktop)
   ══════════════════════════════════════════════════════════ */
.nav-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
  flex-shrink: 0;
}
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ══════════════════════════════════════════════════════════
   SAFE AREA iPhone (notch / home indicator)
   ══════════════════════════════════════════════════════════ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-input-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .progress-bar {
    bottom: env(safe-area-inset-bottom);
  }
  @media (max-width: 768px) {
    .modal {
      padding-bottom: calc(36px + env(safe-area-inset-bottom));
    }
  }
}
