﻿/* ================================================== */
/* BIBLIOTHEQUE-MOBILE.CSS — Responsive Bibliothèque   */
/* ================================================== */

/* Icône filtre inline : cachée par défaut, révélée par les media queries mobile ci-dessous */
.search-filter-icon { display: none; }

/* ===========================
   MOBILE — max 500px
   =========================== */
@media (max-width: 500px) and (pointer: coarse),
       (pointer: coarse) and (max-height: 600px) and (orientation: landscape) {

  /* --- HERO SECTION --- */
  .library-hero {
    max-width: 100%;
    margin-right: 0;
    padding: 0;
  }

  .library-hero h1 {
    font-size: 1.6rem;
    text-align: center;
    margin-bottom: 0.8rem;
  }

  /* --- ONGLETS MOBILE --- */
  .library-tabs {
    display: inline-flex;
    gap: 2px;
    margin-bottom: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    width: auto;
    max-width: 100%;
  }

  .library-tabs::-webkit-scrollbar {
    display: none;
  }

  .library-tab {
    padding: 7px 12px;
    font-size: 12px;
    gap: 4px;
    min-width: 0;
    flex-shrink: 0;
  }

  .library-tab span {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Toolbar : 2 lignes via flex-wrap
     Ligne 1 : search bar (avec icône filtre à droite)
     Ligne 2 : onglets (gauche) | compteur (droite) */
  .library-row-1 {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 1rem;
  }

  .library-row-2 {
    display: none;
  }

  .category-filters {
    display: none !important;
  }

  .library-search-box {
    order: 0;
    flex: 0 0 100%;
    max-width: 100%;
    width: 100%;
    position: relative;
  }

  .library-search-box input {
    font-size: 16px;
    padding: 0.7rem 1rem 0.7rem 2.3rem;
  }

  /* Bouton filtre desktop masqué sur mobile — icône inline dans la search bar */
  .filters-btn {
    display: none !important;
  }

  /* Compteur visible en 2e ligne (droite) */
  .library-stats {
    order: 3;
    display: flex !important;
    flex: 0 0 auto;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary, #888);
    white-space: nowrap;
  }

  .library-sort-controls {
    display: none !important;
  }

  /* Icône filtre inline dans la search bar */
  .search-filter-icon {
    display: flex;
    position: absolute;
    right: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--muted, #888);
    cursor: pointer;
    z-index: 2;
    transition: background 0.2s ease, color 0.2s ease;
    padding: 0;
    box-sizing: border-box;
    line-height: 0;
    font-size: 0;
    flex-shrink: 0;
  }

  .search-filter-icon svg {
    display: block;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    pointer-events: none;
  }

  .search-filter-icon:active { background: rgba(0, 0, 0, 0.06); }

  .search-filter-icon.has-filters {
    color: white !important;
    background: var(--brand-green, #1A5238);
    border-radius: 50%;
  }

  .search-filter-icon.has-filters svg { stroke: white !important; }

  .library-search-box:has(.search-filter-icon) input { padding-right: 2.8rem; }

  /* --- GRILLE DE LIVRES --- */
  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 16px 12px;
    padding: 8px 4px;
    margin-bottom: 30px;
  }

  .book-card {
    padding: 8px;
  }

  .book-card-title {
    font-size: 13px;
    line-height: 1.3;
    height: 2.6em;
  }

  .book-card-author {
    font-size: 12px;
  }

  .book-card-fav-badge {
    width: 26px;
    height: 26px;
    top: 6px;
    right: 6px;
  }

  /* Pas de hover sur mobile */
  .book-card:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(44, 53, 57, 0.05);
  }

  .book-card:hover .book-card-cover {
    transform: none;
  }

  /* Active state pour feedback tactile */
  .book-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }

  /* --- HISTORIQUE --- */
  .history-cards {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 0 4px;
  }

  .history-empty svg {
    width: 48px;
    height: 48px;
  }

  .history-empty p {
    font-size: 14px;
  }

  /* --- LECTEUR PDF INTÉGRÉ --- */
  .pdf-viewer-container {
    border-radius: 0;
    min-height: auto;
  }

  .pdf-viewer-header {
    padding: 12px 16px;
    flex-direction: column;
    gap: 8px;
    min-height: auto;
  }

  .pdf-viewer-left,
  .pdf-viewer-right {
    width: 100%;
    justify-content: center;
  }

  .pdf-viewer-input {
    min-width: auto;
    width: 100%;
  }

  .pdf-viewer-separator {
    display: none;
  }

  .pdf-viewer-wrap {
    padding: 8px;
  }

  .pdf-viewer-wrap iframe {
    min-height: 400px;
    border-radius: 4px;
  }

  /* --- VUE MINDMAP --- */
  /* Cacher filtres catégorie et tri en mode mindmap : inutiles + libèrent de l'espace */
  .library-hero.is-mindmap .library-row-2,
  .library-hero.is-mindmap .library-sort-controls {
    display: none !important;
  }

  .mindmap-view-container {
    height: calc(100dvh - 275px) !important;
    min-height: unset !important;
    border-radius: 8px;
    overflow: hidden;
  }

  .mindmap-view-container .xmind-container {
    min-height: unset !important;
    height: 100% !important;
    border-radius: 8px;
    overflow: hidden;
    touch-action: none; /* Pan/zoom géré par JS */
  }

  /* Contrôles mindmap compacts */
  .mindmap-view-container .xmind-controls {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .mindmap-view-container .zoom-slider-container {
    padding: 4px 8px;
    gap: 4px;
  }

  .mindmap-view-container .zoom-slider {
    width: 80px;
  }

  .mindmap-view-container .zoom-label {
    font-size: 12px;
  }

  .mindmap-view-container #zoomLevel {
    font-size: 11px;
    min-width: 32px;
  }

  .mindmap-view-container .reset-btn,
  .mindmap-view-container .control-btn {
    padding: 5px 8px;
    font-size: 0.8rem;
    margin-left: 4px;
  }

  /* Nœuds mindmap réduits pour mobile */
  .node.root-node {
    width: 120px !important;
    height: 120px !important;
    font-size: 1.1em !important;
    padding: 15px 20px !important;
    border-width: 3px !important;
  }

  .node.category-node {
    width: 70px !important;
    height: 70px !important;
    font-size: 0.7em !important;
    padding: 5px !important;
    border-width: 2px !important;
  }

  .node.book-node {
    width: 65px !important;
  }

  .book-cover-img {
    width: 65px !important;
    height: 97px !important;
  }

  .category-background-circle {
    width: 260px;
    height: 260px;
  }

  /* Modal livre : pleine largeur en bas sur mobile */
  .book-modal {
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    max-width: none !important;
    max-height: 50vh;
    overflow-y: auto;
    border-radius: 10px;
    padding: 0.75rem 1rem;
  }

  .modal-book-cover {
    width: 48px;
    height: 72px;
  }

  .modal-book-title {
    font-size: 0.85rem;
    padding-right: 28px;
  }

  /* Mobile : boutons d'action en grille 2 colonnes, cibles tactiles ≥44px */
  .book-modal .modal-actions {
    gap: 8px;
    margin-top: 0.85rem;
  }

  .book-modal .modal-actions .btn {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    padding: 0;
    min-height: unset;
    border-radius: 10px;
  }

  .book-modal .modal-actions .btn svg {
    width: 20px;
    height: 20px;
  }

  /* Tooltip mindmap : masqué sur mobile (la modal book-modal suffit) */
  .mm-book-tooltip {
    display: none !important;
  }

  /* --- BOOK DETAIL CONTAINER --- */
  .book-detail-container {
    padding: 0;
  }
}

/* ===========================
   PETIT MOBILE — max 480px
   =========================== */
@media (max-width: 480px) {

  .library-hero h1 {
    font-size: 1.4rem;
  }

  .books-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 8px;
    padding: 4px 2px;
  }

  .book-card {
    padding: 6px;
  }

  .book-card-title {
    font-size: 12px;
  }

  .book-card-author {
    font-size: 11px;
  }

  .filter-btn {
    padding: 6px 12px;
    font-size: 11px;
  }

  .page-number {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }

  .page-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Mindmap encore plus compact sur 480px */
  .mindmap-view-container {
    height: calc(100dvh - 275px) !important;
  }

  .mindmap-view-container .zoom-slider {
    width: 60px;
  }

  .node.root-node {
    width: 100px !important;
    height: 100px !important;
    font-size: 0.9em !important;
    padding: 10px 15px !important;
  }

  .node.category-node {
    width: 55px !important;
    height: 55px !important;
    font-size: 0.6em !important;
  }

  .node.book-node {
    width: 55px !important;
  }

  .book-cover-img {
    width: 55px !important;
    height: 82px !important;
  }

  .category-background-circle {
    width: 200px;
    height: 200px;
  }

  .book-modal {
    left: 4px !important;
    right: 4px !important;
    bottom: 4px !important;
    padding: 0.6rem 0.75rem;
  }

  /* Petit mobile : conserver les boutons carrés 44x44 */
  .book-modal .modal-actions .btn {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    padding: 0;
  }
}

/* ===========================
   TRÈS PETIT MOBILE — max 360px
   =========================== */
@media (max-width: 360px) {

  .library-hero h1 {
    font-size: 1.2rem;
  }

  .books-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 6px;
  }

  .book-card-title {
    font-size: 11px;
  }
}

/* ===========================
   TABLETTE — 769px à 1024px
   =========================== */
@media (min-width: 769px) and (max-width: 1024px) {

  .library-hero h1 {
    font-size: 1.9rem;
  }

  .library-row-1 {
    gap: 10px;
  }

  .library-search-box {
    max-width: 350px;
  }

  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(max(170px, (100% - 100px) / 6), 1fr));
    gap: 24px 20px;
    padding: 12px;
  }

  .mindmap-view-container {
    height: calc(100dvh - 120px);
    min-height: unset !important;
  }

  .mindmap-view-container .zoom-slider {
    width: 120px;
  }

  .book-modal {
    width: 300px;
  }
}

/* ===========================
   ORIENTATION PAYSAGE MOBILE
   =========================== */
@media (pointer: coarse) and (max-height: 600px) and (orientation: landscape) {
  .mindmap-view-container {
    height: calc(100dvh - 60px) !important;
  }

  .mindmap-view-container .xmind-controls {
    padding: 4px 8px;
    gap: 4px;
  }

  .book-modal {
    max-height: 60vh;
    width: fit-content;
    min-width: 280px;
    max-width: 70vw;
  }

  /* Layout horizontal pour paysage */
  .book-modal .modal-book-info {
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
  }

  .book-modal .modal-book-cover {
    width: 50px;
    height: 75px;
  }

  .book-modal .modal-actions {
    display: flex;
    flex-direction: row;
    gap: 0.4rem;
  }

  .mm-book-tooltip {
    max-width: fit-content;
    min-width: 160px;
  }
}
