/**
 * NoteLab.cloud - Feuille de styles dédiée MOBILE (Téléphones & Tablettes < 768px)
 * assets/css/notepad-mobile.css
 */

@media (max-width: 768px) {
  /* =============================================================
     1. CONTENEUR GLOBAL & CORPS
     ============================================================= */
  html, body {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    touch-action: pan-y;
  }

  .app-wrapper {
    height: 100dvh;
    height: -webkit-fill-available;
    width: 100vw;
    overflow: hidden;
    position: relative;
  }

  /* =============================================================
     2. SIDEBAR MOBILE (Tiroir coulissant fluide / Drawer)
     ============================================================= */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .sidebar-backdrop.active,
  .sidebar:not(.collapsed) ~ .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 84vw !important;
    max-width: 320px !important;
    height: 100dvh !important;
    height: -webkit-fill-available !important;
    z-index: 1000 !important;
    background-color: #15161a !important;
    border-right: 1px solid var(--border-color) !important;
    box-shadow: 12px 0 35px rgba(0, 0, 0, 0.65) !important;
    transform: translateX(0) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  .sidebar.collapsed {
    transform: translateX(-100%) !important;
    box-shadow: none !important;
    pointer-events: none !important;
  }

  .sidebar-header {
    padding: 14px 16px;
    min-height: 52px;
  }

  .sidebar-search {
    padding: 10px 14px;
  }

  .search-input-wrapper input {
    font-size: 16px !important; /* Empêche le zoom automatique forcé sur iOS Safari */
  }

  .sidebar-notes-list {
    padding: 8px 10px;
    -webkit-overflow-scrolling: touch;
  }

  .note-item {
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    touch-action: manipulation;
  }

  .note-item:active {
    background: rgba(255, 255, 255, 0.08);
    transform: scale(0.99);
  }

  /* =============================================================
     3. ESPACE ÉDITEUR PRINCIPAL
     ============================================================= */
  .main-editor-pane {
    width: 100vw !important;
    min-width: 0 !important;
    flex: 1 1 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* =============================================================
     4. BARRE D'OUTILS GLISSABLE AU DOIGT (SWIPE / TOUCH TOOLBAR)
     ============================================================= */
  .editor-top-bar {
    height: 48px !important;
    min-height: 48px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    background: rgba(23, 24, 29, 0.96) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    border-bottom: 1px solid var(--border-color) !important;
    position: relative;
    z-index: 40;
    overflow: hidden;
    padding: 0;
  }

  /* Conteneur glissable au doigt */
  .toolbar-group {
    display: flex !important;
    align-items: center !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    height: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
    scrollbar-width: none !important; /* Firefox */
    touch-action: pan-x !important;
    padding-left: 2px;
    padding-right: 14px;
    /* Masquage dégradé subtil à droite pour indiquer qu'on peut glisser */
    mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
  }

  .toolbar-group::-webkit-scrollbar {
    display: none !important; /* Chrome, Safari, Edge */
  }

  /* Boutons tactiles avec micro-animation fluide au toucher */
  .toolbar-btn {
    width: 42px !important;
    min-width: 42px !important;
    height: 100% !important;
    border-right: 1px solid var(--border-color) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    transition: transform 0.1s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.15s ease !important;
    -webkit-tap-highlight-color: transparent;
  }

  .toolbar-btn:active {
    transform: scale(0.88);
    background-color: rgba(255, 255, 255, 0.12) !important;
  }

  .toolbar-btn svg {
    width: 18px !important;
    height: 18px !important;
  }

  /* Bouton toggle sidebar toujours accessible */
  #btn-toggle-sidebar {
    background-color: rgba(255, 255, 255, 0.03);
  }

  #btn-toggle-sidebar:active {
    background-color: rgba(59, 130, 246, 0.2) !important;
  }

  /* Menus déroulants de style & police dans la barre tactile */
  .custom-dropdown-container {
    flex-shrink: 0 !important;
    height: 100% !important;
    display: inline-flex !important;
    align-items: center !important;
  }

  .custom-dropdown-trigger {
    height: 100% !important;
    padding: 0 12px !important;
    font-size: 0.82rem !important;
    border-right: 1px solid var(--border-color) !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    transition: background-color 0.15s ease, transform 0.1s ease !important;
  }

  .custom-dropdown-trigger:active {
    background: rgba(255, 255, 255, 0.08) !important;
    transform: scale(0.97);
  }

  .custom-dropdown-label {
    max-width: 90px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  /* Menus déroulants popups sur mobile */
  .custom-dropdown-menu {
    position: fixed !important;
    top: 52px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: calc(100vw - 16px) !important;
    max-height: 55vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    background: #191a20 !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.8) !important;
    border-radius: 12px !important;
    padding: 8px !important;
    z-index: 1000 !important;
  }

  .custom-dropdown-item {
    padding: 10px 14px !important;
    font-size: 0.92rem !important;
    border-radius: 8px !important;
    min-height: 44px !important;
  }

  .custom-dropdown-item:active {
    background: rgba(255, 255, 255, 0.1) !important;
  }

  /* Palette de couleurs de surlignage sur mobile */
  .highlight-menu {
    position: fixed !important;
    top: 52px !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
  }

  .highlight-colors-palette {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 10px !important;
    padding: 10px !important;
  }

  .highlight-color-btn {
    width: 100% !important;
    height: 38px !important;
    border-radius: 8px !important;
  }

  /* Actions de droite (Sauvegarde & Statut) */
  .editor-top-actions {
    flex-shrink: 0 !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 8px 0 6px !important;
    background: inherit !important;
    border-left: 1px solid var(--border-color) !important;
    z-index: 5 !important;
  }

  .last-save-status {
    display: none !important; /* Trop encombrant sur mobile */
  }

  .btn-save-cloud {
    height: 34px !important;
    padding: 0 12px !important;
    font-size: 0.8rem !important;
    border-radius: 6px !important;
    gap: 5px !important;
    font-weight: 600 !important;
    transition: transform 0.1s ease, filter 0.15s ease !important;
  }

  .btn-save-cloud:active {
    transform: scale(0.93) !important;
  }

  .btn-save-cloud svg {
    width: 13px !important;
    height: 13px !important;
  }

  /* Sur écrans très étroits (< 390px), masquer le texte "Enregistrer" et ne garder que l'icône */
  @media (max-width: 390px) {
    .btn-save-cloud .save-btn-text {
      display: none !important;
    }
    .btn-save-cloud {
      width: 34px !important;
      padding: 0 !important;
      justify-content: center !important;
    }
  }

  /* =============================================================
     5. ZONE DE TEXTE & ÉCRITURE MOBILE
     ============================================================= */
  .editor-scroll-area {
    padding: 0 !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .editor-workspace {
    padding: 16px 16px 90px 16px !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    border-left: none !important;
    border-right: none !important;
    box-sizing: border-box !important;
  }

  .note-title-input {
    font-size: 1.45rem !important;
    margin-bottom: 0.85rem !important;
    padding: 0 !important;
  }

  .note-content-editor {
    font-size: 1rem !important;
    line-height: 1.65 !important;
    min-height: 380px !important;
    padding-bottom: 40px !important;
  }

  /* Citations, code et listes optimisés pour mobile */
  .note-content-editor blockquote {
    margin: 0.8rem 0 !important;
    padding: 8px 12px !important;
    font-size: 0.95rem !important;
  }

  .note-content-editor pre {
    padding: 10px 12px !important;
    font-size: 0.85rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* =============================================================
     6. DIALOGUES ET MODALS SUR MOBILE
     ============================================================= */
  .custom-modal-backdrop,
  .modal-backdrop {
    padding: 12px !important;
  }

  .custom-modal-dialog,
  .modal-dialog {
    width: 94% !important;
    max-width: 94% !important;
    padding: 20px 16px !important;
    box-sizing: border-box !important;
  }

  .custom-modal-input {
    font-size: 16px !important; /* Empêche le zoom forcé d'iOS */
    padding: 11px 12px !important;
  }

  .custom-modal-actions {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .custom-modal-actions button {
    flex: 1 1 auto;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn-modal-unlink {
    width: 100% !important;
    margin-bottom: 4px !important;
  }

  /* =============================================================
     7. MENU CONTEXTUEL SUR MOBILE
     ============================================================= */
  .notelab-context-menu {
    position: fixed !important;
    max-width: 88vw !important;
    border-radius: 10px !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.8) !important;
  }

  .ctx-item {
    padding: 10px 14px !important;
    font-size: 0.92rem !important;
  }
}
