/* Philosophal — Éditeur de texte : véritable layout téléphone/tablette — 2026-09-29
   Surcharge additive. Aucun comportement de sauvegarde n'est modifié. */

:root{--editor-mobile-vh:100dvh}
html,body{max-width:100%;overflow-x:hidden}
.editor-workspace,.editor-document-bar,.editor-tabs,.editor-toolbar,.editor-secondary-bar,.editor-page-scroll{min-width:0}
.editor-canvas img,.editor-course-preview img{max-width:100%;height:auto}

@supports not (height:100dvh){:root{--editor-mobile-vh:100vh}}

@media(max-width:1024px){
  .editor-app{grid-template-columns:minmax(0,1fr)!important}
  .editor-workspace{width:100%;min-width:0}
}

@media(max-width:760px){
  html,body{height:100%;overscroll-behavior:none}
  body{min-width:0!important}

  .editor-topbar{
    box-sizing:border-box;
    min-height:52px!important;
    height:52px!important;
    padding:5px max(9px,env(safe-area-inset-right)) 5px max(10px,env(safe-area-inset-left))!important;
    gap:8px!important;
    overflow:hidden;
  }
  .editor-topbar-left{min-width:0;flex:1 1 auto}
  .editor-brand{min-width:0;gap:8px!important}
  .editor-brand-mark{width:32px!important;height:32px!important;min-width:32px!important;border-radius:10px!important}
  .editor-brand strong{font-size:.98rem!important}
  .editor-brand small{display:none!important}
  .editor-save-state{display:none!important}
  .editor-topbar-actions{
    flex:0 0 auto;
    gap:4px!important;
    min-width:0;
    overflow:hidden;
  }
  /* Sur téléphone : seuls les boutons vraiment utiles restent en haut.
     Recherche/Aperçu/Plan/Versions restent accessibles en paysage/tablette. */
  .editor-topbar-actions .editor-quiet-button{display:none!important}
  .editor-topbar-actions [data-fullscreen]{display:inline-flex!important;width:36px!important;height:36px!important;padding:0!important;font-size:0!important;justify-content:center}
  .editor-topbar-actions [data-fullscreen]::before{content:"⛶";font-size:1.05rem}
  .editor-topbar-actions .editor-icon-top{width:36px!important;height:36px!important;min-width:36px!important}

  .editor-app{
    height:calc(var(--editor-mobile-vh) - 52px)!important;
    min-height:0!important;
    overflow:hidden!important;
    grid-template-columns:minmax(0,1fr)!important;
  }
  .editor-workspace{
    display:flex!important;
    flex-direction:column!important;
    height:100%!important;
    min-height:0!important;
    overflow:hidden!important;
  }

  .editor-library{
    position:fixed!important;
    z-index:1300!important;
    top:0!important;
    left:0!important;
    bottom:0!important;
    width:min(88vw,360px)!important;
    max-width:360px!important;
    height:var(--editor-mobile-vh)!important;
    padding-top:env(safe-area-inset-top)!important;
    padding-bottom:env(safe-area-inset-bottom)!important;
    box-shadow:18px 0 50px rgba(28,24,36,.16)!important;
  }
  .editor-library-backdrop{position:fixed!important;inset:0!important;z-index:1250!important}

  .editor-document-bar{
    flex:0 0 auto!important;
    min-height:48px!important;
    padding:5px 8px!important;
    gap:7px!important;
    overflow:hidden!important;
  }
  .editor-library-trigger{
    min-width:39px!important;
    width:39px!important;
    height:38px!important;
    padding:0!important;
    justify-content:center!important;
    font-size:1rem!important;
    flex:0 0 39px!important;
  }
  .editor-library-trigger span{display:none!important}
  .editor-title-input{
    min-width:0!important;
    width:auto!important;
    flex:1 1 auto!important;
    height:38px!important;
    padding:0 3px!important;
    font-size:1rem!important;
  }
  .editor-document-actions{display:none!important}

  .editor-tabs{
    flex:0 0 auto!important;
    min-height:40px!important;
    max-height:40px!important;
    padding:3px 8px!important;
    gap:5px!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
    overscroll-behavior-x:contain;
  }
  .editor-tabs::-webkit-scrollbar{display:none}
  .editor-tabs>*{flex:0 0 auto!important;max-width:170px!important}

  .editor-toolbar{
    flex:0 0 auto!important;
    min-width:0!important;
    max-width:100vw!important;
    overflow:hidden!important;
  }
  .v3-toolbar-structured{max-width:100vw!important;overflow:hidden!important}
  .v3-toolbar-row{
    box-sizing:border-box!important;
    width:100%!important;
    max-width:100vw!important;
    min-height:42px!important;
    padding:3px 6px!important;
    display:flex!important;
    flex-wrap:nowrap!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior-x:contain;
    scrollbar-width:none;
  }
  .v3-toolbar-row::-webkit-scrollbar{display:none}
  .v3-toolbar-row>*{flex:0 0 auto!important}
  body.v3-toolbar-collapsed .v3-toolbar-row-advanced{display:none!important}
  body.v3-toolbar-collapsed .v3-toolbar-row-primary{min-height:42px!important}
  .v3-toolbar-row-primary .v3-tool-chip-toggle{position:sticky!important;left:0;z-index:5}

  /* Fallback au cas où V3 n'a pas encore restructuré la barre. */
  .editor-toolbar:not(.v3-toolbar-structured){
    display:flex!important;
    flex-wrap:nowrap!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
    padding:3px 6px!important;
  }
  .editor-toolbar:not(.v3-toolbar-structured)::-webkit-scrollbar{display:none}
  .editor-toolbar-group{flex:0 0 auto!important}

  .editor-searchbar{
    flex:0 0 auto!important;
    width:100%!important;
    max-height:132px;
    overflow:auto;
    padding:6px 8px!important;
    gap:5px!important;
    flex-wrap:wrap!important;
  }
  .editor-searchbar input{min-width:130px!important;flex:1 1 150px!important}

  .editor-secondary-bar{
    flex:0 0 auto!important;
    min-height:38px!important;
    max-height:38px!important;
    padding:3px 6px!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
    gap:6px!important;
  }
  .editor-secondary-bar::-webkit-scrollbar{display:none}
  .editor-view-settings{display:flex!important;flex:0 0 auto!important;gap:5px!important}
  .editor-view-settings label{font-size:0!important;flex:0 0 auto!important}
  .editor-view-settings select{height:30px!important;min-width:68px!important;font-size:.68rem!important;padding:0 20px 0 7px!important}
  .editor-export-menu{flex:0 0 auto!important}
  .editor-export-trigger{height:30px!important;font-size:.7rem!important;padding:0 9px!important}

  /* Le point essentiel : sur mobile la feuille suit la largeur de l'écran.
     On neutralise également un éventuel zoom mémorisé par la version desktop. */
  .editor-page-scroll{
    flex:1 1 auto!important;
    min-height:0!important;
    width:100%!important;
    max-width:100vw!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior:contain;
    padding:8px 8px max(18px,env(safe-area-inset-bottom))!important;
    scroll-padding-bottom:90px;
  }
  .editor-paper{
    box-sizing:border-box!important;
    width:100%!important;
    min-width:0!important;
    max-width:none!important;
    min-height:calc(var(--editor-mobile-vh) - 255px)!important;
    margin:0!important;
    padding:25px 18px 56px!important;
    transform:none!important;
    zoom:1!important;
    border-radius:10px!important;
    box-shadow:0 1px 7px rgba(31,26,38,.07)!important;
  }
  .editor-canvas{
    box-sizing:border-box!important;
    min-width:0!important;
    width:100%!important;
    max-width:100%!important;
    min-height:calc(var(--editor-mobile-vh) - 335px)!important;
    font-size:16px!important;
    line-height:var(--editor-line-height,1.72)!important;
    overflow-wrap:anywhere;
    word-break:normal;
    -webkit-text-size-adjust:100%;
  }
  .editor-canvas pre,.editor-canvas code{white-space:pre-wrap;overflow-wrap:anywhere}
  .editor-canvas table{display:block!important;max-width:100%!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch}
  .editor-canvas iframe,.editor-canvas video{max-width:100%!important}

  .editor-statusbar{
    flex:0 0 auto!important;
    min-height:31px!important;
    height:31px!important;
    padding:0 max(10px,env(safe-area-inset-right)) env(safe-area-inset-bottom) max(10px,env(safe-area-inset-left))!important;
    gap:10px!important;
    font-size:.67rem!important;
    white-space:nowrap;
    overflow:hidden;
  }
  .editor-shortcut-hint{display:none!important}
  .editor-status-spacer{display:none!important}
  .editor-statusbar [data-last-save]{margin-left:auto;overflow:hidden;text-overflow:ellipsis}

  .editor-outline-panel{
    position:fixed!important;
    z-index:1350!important;
    inset:auto 0 0 0!important;
    width:100%!important;
    max-width:none!important;
    max-height:min(72vh,620px)!important;
    border-radius:20px 20px 0 0!important;
    padding-bottom:env(safe-area-inset-bottom)!important;
  }
  .editor-modal-card,.editor-preview-shell{
    width:calc(100vw - 20px)!important;
    max-width:calc(100vw - 20px)!important;
    max-height:calc(var(--editor-mobile-vh) - 20px)!important;
    border-radius:18px!important;
  }
  .editor-command-palette,.editor-symbols{max-width:calc(100vw - 20px)!important}
}

@media(min-width:561px) and (max-width:760px){
  .editor-topbar-actions [data-open-search],
  .editor-topbar-actions [data-preview-document],
  .editor-topbar-actions [data-outline-toggle]{display:inline-flex!important;font-size:.72rem!important;padding:0 8px!important}
}

@media(max-width:480px){
  .editor-paper{padding:21px 15px 50px!important;border-radius:8px!important}
  .editor-page-scroll{padding-left:5px!important;padding-right:5px!important}
  .editor-view-settings label:nth-child(3),.editor-view-settings label:nth-child(4){display:none!important}
  .editor-export-trigger{padding:0 8px!important}
}

/* Quand le clavier virtuel réduit la fenêtre, préserver un minimum de zone de saisie. */
body.editor-mobile-keyboard .editor-paper{min-height:100%!important}
body.editor-mobile-keyboard .editor-canvas{min-height:260px!important}
