/*
  V11.61 — Mobile Shell/Layout Safe
  Escopo: SOMENTE regras mobile via media queries.
  Não altera desktop, Supabase, cache, PDF, renderizações ou lógica dos módulos.
*/

@media (hover:none), (pointer:coarse){
  .btn,
  .nav button,
  .fav-star,
  .link-chip,
  .client-chip,
  .contract-step-pill,
  input,
  select,
  textarea{
    -webkit-tap-highlight-color:transparent!important;
    touch-action:manipulation!important;
  }
}

@media (max-width:900px){
  :root{
    --dh-mobile-nav-h:76px;
    --dh-mobile-safe-bottom:env(safe-area-inset-bottom,0px);
    --dh-mobile-safe-left:env(safe-area-inset-left,0px);
    --dh-mobile-safe-right:env(safe-area-inset-right,0px);
    --dh-mobile-page-x:12px;
  }

  html,
  body{
    width:100%!important;
    max-width:100%!important;
    overflow-x:hidden!important;
  }

  body{
    min-height:100dvh!important;
    overscroll-behavior-y:none!important;
  }

  .app{
    width:100%!important;
    max-width:100vw!important;
    min-height:100dvh!important;
    overflow-x:hidden!important;
  }

  .main{
    width:100%!important;
    max-width:100vw!important;
    min-width:0!important;
    padding-left:max(var(--dh-mobile-page-x),var(--dh-mobile-safe-left))!important;
    padding-right:max(var(--dh-mobile-page-x),var(--dh-mobile-safe-right))!important;
    padding-bottom:calc(var(--dh-mobile-nav-h) + var(--dh-mobile-safe-bottom) + 22px)!important;
    overflow-x:hidden!important;
  }

  .view,
  .view.active,
  .grid,
  .form,
  .card,
  .panel,
  .hero,
  .home-ops-hero,
  .home-hero-v62,
  .clean-home-hero,
  .greeting-hero,
  .link-card,
  .contract-card,
  .crm-card,
  .job-card,
  .agenda-card,
  .finance-row,
  .item{
    max-width:100%!important;
    min-width:0!important;
    box-sizing:border-box!important;
    overflow-wrap:anywhere!important;
  }

  .topbar{
    position:sticky!important;
    top:0!important;
    z-index:50!important;
    width:100%!important;
    max-width:100%!important;
    padding:10px 0 12px!important;
    margin:0 0 8px!important;
    border-radius:0!important;
    background:linear-gradient(180deg,rgba(5,5,5,.96),rgba(5,5,5,.82) 72%,rgba(5,5,5,0))!important;
    backdrop-filter:blur(16px) saturate(1.08)!important;
  }

  .brand,
  .brand-clean{
    display:none!important;
  }

  .top-actions,
  .top-actions-left{
    width:100%!important;
    max-width:100%!important;
    display:flex!important;
    align-items:center!important;
    gap:8px!important;
    flex-wrap:nowrap!important;
    overflow:visible!important;
  }

  .search,
  .search-wide,
  .topbar .search{
    flex:1 1 auto!important;
    width:auto!important;
    max-width:none!important;
    min-width:0!important;
    height:44px!important;
  }

  .search input,
  .topbar .search input{
    min-width:0!important;
    width:100%!important;
    font-size:16px!important;
  }

  .top-logout-btn{
    flex:0 0 auto!important;
    min-width:44px!important;
    min-height:44px!important;
    height:44px!important;
    padding:0 12px!important;
    white-space:nowrap!important;
  }

  .sidebar{
    position:fixed!important;
    inset:auto 0 0 0!important;
    width:100%!important;
    max-width:100%!important;
    height:calc(var(--dh-mobile-nav-h) + var(--dh-mobile-safe-bottom))!important;
    max-height:calc(var(--dh-mobile-nav-h) + var(--dh-mobile-safe-bottom))!important;
    padding:8px 10px calc(8px + var(--dh-mobile-safe-bottom))!important;
    border-right:0!important;
    border-top:1px solid rgba(255,255,255,.10)!important;
    background:rgba(8,8,8,.94)!important;
    backdrop-filter:blur(20px) saturate(1.15)!important;
    box-shadow:0 -18px 60px rgba(0,0,0,.58)!important;
    overflow:hidden!important;
    z-index:9999!important;
  }

  .side-logo-box,
  .side-bottom,
  .sidebar-scroll-arrow,
  .sidebar-tooltip{
    display:none!important;
  }

  .nav{
    width:100%!important;
    height:100%!important;
    margin:0!important;
    padding:0 2px!important;
    display:flex!important;
    flex-direction:row!important;
    align-items:center!important;
    justify-content:flex-start!important;
    gap:8px!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    scroll-snap-type:x proximity!important;
    -webkit-overflow-scrolling:touch!important;
    scrollbar-width:none!important;
  }

  .nav::-webkit-scrollbar{
    display:none!important;
  }

  .nav button{
    flex:0 0 50px!important;
    width:50px!important;
    min-width:50px!important;
    height:50px!important;
    min-height:50px!important;
    margin:0!important;
    border-radius:17px!important;
    scroll-snap-align:center!important;
  }

  .nav button span{
    display:none!important;
  }

  .float{
    right:max(14px,var(--dh-mobile-safe-right))!important;
    bottom:calc(var(--dh-mobile-nav-h) + var(--dh-mobile-safe-bottom) + 14px)!important;
    z-index:9998!important;
  }

  .float-main{
    width:54px!important;
    height:54px!important;
    min-width:54px!important;
    min-height:54px!important;
    border-radius:18px!important;
  }

  .float-menu{
    right:0!important;
    bottom:64px!important;
    width:min(292px,calc(100vw - 28px))!important;
    max-height:calc(100dvh - var(--dh-mobile-nav-h) - var(--dh-mobile-safe-bottom) - 104px)!important;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch!important;
  }

  .modal.active{
    align-items:flex-end!important;
    padding:0!important;
  }

  .modal-box,
  .modal-box.task-modal-wide{
    width:100%!important;
    max-width:100%!important;
    max-height:calc(100dvh - 8px)!important;
    border-radius:24px 24px 0 0!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }

  .modal-head{
    flex:0 0 auto!important;
    position:sticky!important;
    top:0!important;
    z-index:4!important;
    background:linear-gradient(180deg,rgba(18,18,18,.98),rgba(18,18,18,.92))!important;
    backdrop-filter:blur(14px)!important;
  }

  #modalBody{
    flex:1 1 auto!important;
    min-height:0!important;
    max-height:none!important;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch!important;
    padding-bottom:calc(18px + var(--dh-mobile-safe-bottom))!important;
  }

  .drawer{
    width:100vw!important;
    max-width:100vw!important;
    height:100dvh!important;
    max-height:100dvh!important;
    right:-100vw!important;
    border-radius:0!important;
    overflow:auto!important;
    -webkit-overflow-scrolling:touch!important;
  }

  .drawer.active{
    right:0!important;
  }

  .drawer-head{
    position:sticky!important;
    top:0!important;
    z-index:5!important;
    background:linear-gradient(180deg,rgba(18,18,18,.98),rgba(18,18,18,.90))!important;
    backdrop-filter:blur(14px)!important;
  }

  .btn,
  button,
  input,
  select,
  textarea{
    max-width:100%!important;
  }

  .btn,
  .nav button,
  .fav-star,
  .contract-step-pill{
    min-height:44px!important;
  }

  input,
  select,
  textarea{
    font-size:16px!important;
  }

  .toolbar,
  .period-controls,
  .home-mode-row,
  .home-meta-row,
  .quote-mini-actions,
  .adm-actions,
  .deal-actions-row,
  .followup-actions,
  .contract-wizard-steps,
  .links-filter-toolbar,
  .crm-client-toolbar{
    overflow-x:auto!important;
    overflow-y:hidden!important;
    flex-wrap:nowrap!important;
    -webkit-overflow-scrolling:touch!important;
    scrollbar-width:none!important;
  }

  .toolbar::-webkit-scrollbar,
  .period-controls::-webkit-scrollbar,
  .home-mode-row::-webkit-scrollbar,
  .home-meta-row::-webkit-scrollbar,
  .quote-mini-actions::-webkit-scrollbar,
  .adm-actions::-webkit-scrollbar,
  .deal-actions-row::-webkit-scrollbar,
  .followup-actions::-webkit-scrollbar,
  .contract-wizard-steps::-webkit-scrollbar,
  .links-filter-toolbar::-webkit-scrollbar,
  .crm-client-toolbar::-webkit-scrollbar{
    display:none!important;
  }

  .contract-wizard-steps{
    display:flex!important;
    gap:8px!important;
    margin:0 -2px!important;
    padding:0 2px 4px!important;
  }

  .contract-step-pill{
    flex:0 0 auto!important;
    white-space:nowrap!important;
  }

  .contract-wizard-step.active{
    min-width:0!important;
  }

  .contract-wizard-actions{
    position:sticky!important;
    bottom:calc(-1 * var(--dh-mobile-safe-bottom))!important;
    z-index:3!important;
    margin:12px -16px calc(-1 * var(--dh-mobile-safe-bottom))!important;
    padding:12px 16px calc(12px + var(--dh-mobile-safe-bottom))!important;
    background:linear-gradient(180deg,rgba(18,18,18,0),rgba(18,18,18,.98) 22%)!important;
    border-top:1px solid rgba(255,255,255,.08)!important;
  }

  .contract-wizard-actions,
  .contract-wizard-actions .right{
    width:auto!important;
    display:flex!important;
    gap:8px!important;
    align-items:stretch!important;
  }

  .contract-wizard-actions .right{
    flex:1 1 auto!important;
    justify-content:flex-end!important;
  }

  .contract-wizard-actions .btn{
    flex:0 0 auto!important;
  }

  .contract-legal-doc,
  .quote-preview-wrap,
  .quote-preview,
  .quote-table,
  .finance-cashmap,
  .calendar-grid,
  .kanban,
  .pipeline,
  .pipeline-v5,
  .pipeline-board-visual,
  .content-board{
    max-width:100%!important;
  }

  .quote-preview-wrap,
  .contract-legal-doc,
  .finance-chart,
  .finance-cashmap,
  .calendar-grid{
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch!important;
  }
}

@media (max-width:560px){
  :root{
    --dh-mobile-nav-h:74px;
    --dh-mobile-page-x:10px;
  }

  .top-actions-left{
    gap:7px!important;
  }

  .top-logout-btn{
    width:44px!important;
    min-width:44px!important;
    padding:0!important;
    font-size:0!important;
    border-radius:14px!important;
  }

  .top-logout-btn::before{
    content:'⏻';
    font-size:17px!important;
    line-height:1!important;
  }

  .nav{
    gap:7px!important;
    padding-left:0!important;
    padding-right:0!important;
  }

  .nav button{
    flex-basis:48px!important;
    width:48px!important;
    min-width:48px!important;
    height:48px!important;
    min-height:48px!important;
    border-radius:16px!important;
  }

  .links-grid,
  .crm-grid,
  .client-grid,
  .quote-archive-grid,
  .home-module-stats,
  .home-quick-grid,
  .quick-grid-v62,
  .finance-pro-grid,
  .finance-card-grid,
  .contract-summary,
  .goal-source-grid,
  .goal-path-grid,
  .diag-grid,
  .followup-kpis,
  .content-scoreboard,
  .ai-grid{
    grid-template-columns:1fr!important;
  }

  .contract-wizard-actions{
    display:grid!important;
    grid-template-columns:1fr!important;
  }

  .contract-wizard-actions .right{
    display:grid!important;
    grid-template-columns:1fr!important;
    width:100%!important;
  }

  .contract-wizard-actions .btn,
  .contract-wizard-actions .right .btn,
  .modal-head .btn,
  .drawer-head .btn{
    width:100%!important;
  }

  .contract-legal-header,
  .contract-legal-body{
    padding:20px!important;
  }

  .contract-legal-signatures{
    grid-template-columns:1fr!important;
    gap:28px!important;
  }
}

@media (max-width:390px){
  :root{
    --dh-mobile-page-x:8px;
  }

  .nav button{
    flex-basis:46px!important;
    width:46px!important;
    min-width:46px!important;
    height:46px!important;
    min-height:46px!important;
  }

  .float-main{
    width:50px!important;
    height:50px!important;
    min-width:50px!important;
    min-height:50px!important;
  }
}
