/*
  V11.62 — Mobile UX Scroll & Navigation Safe
  Escopo: SOMENTE mobile. Não altera desktop, Supabase, cache, PDF ou regras de negócio.
  Objetivo: melhorar navegação rápida no celular, scroll interno de modais/drawers e evitar cortes horizontais.
*/

@media (max-width:900px){
  :root{
    --dh-mobile-nav-h:76px;
    --dh-mobile-bar-gap:14px;
    --dh-mobile-safe-top:env(safe-area-inset-top,0px);
    --dh-mobile-safe-bottom:env(safe-area-inset-bottom,0px);
    --dh-mobile-visual-h:100dvh;
  }

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

  body{
    touch-action:manipulation;
    -webkit-text-size-adjust:100%;
  }

  .app,
  .main,
  .view,
  .view.active{
    min-width:0!important;
    max-width:100vw!important;
    overflow-x:hidden!important;
  }

  .main{
    padding-bottom:calc(var(--dh-mobile-nav-h) + var(--dh-mobile-safe-bottom) + 34px)!important;
  }

  .view.active{
    padding-bottom:12px!important;
  }

  .view.active > *,
  .card,
  .panel,
  .home-widget-card,
  .home-week-card,
  .quote-form-card,
  .adm-card,
  .finance-pro-card,
  .score-card,
  .content360-editor,
  .content360-side,
  .agenda-inbox-panel,
  .crm-client-panel,
  .links-filter-panel,
  .contract-card,
  .note-card,
  .purchase-card,
  .item,
  .now-item,
  .agenda-card,
  .deal-card-visual,
  .followup-card{
    max-width:100%!important;
    min-width:0!important;
    box-sizing:border-box!important;
  }

  .topbar{
    top:0!important;
    padding:calc(8px + var(--dh-mobile-safe-top)) 0 10px!important;
    margin:0 0 10px!important;
    background:linear-gradient(180deg,rgba(5,5,5,.98),rgba(5,5,5,.88) 76%,rgba(5,5,5,0))!important;
  }

  .topbar .search,
  .search,
  .search-wide{
    min-width:0!important;
    background:rgba(255,255,255,.055)!important;
    border:1px solid rgba(255,255,255,.13)!important;
    color:#f4f4f4!important;
    box-shadow:inset 0 1px 0 rgba(255,255,255,.04)!important;
  }

  .topbar .search input,
  .search input{
    color:#f4f4f4!important;
    min-width:0!important;
    width:100%!important;
  }

  .search span,
  .search .kbd{
    flex:0 0 auto!important;
  }

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

  input,
  select,
  textarea{
    width:100%!important;
  }

  .btn{
    white-space:normal!important;
    overflow-wrap:anywhere!important;
    text-align:center!important;
    line-height:1.12!important;
  }

  .form .btn,
  .card > .btn.green,
  .panel > .btn.green,
  .content360-editor .btn.green,
  .goal-simple-card .btn.green,
  .quote-form-card .btn.green,
  .adm-card .btn.green,
  .modal-box .btn.green,
  .drawer .btn.green{
    width:100%!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{
    max-width:100%!important;
    overscroll-behavior-x:contain!important;
  }

  .dh-mobile-modal-open .sidebar,
  .dh-mobile-modal-open .float,
  .dh-mobile-drawer-open .sidebar,
  .dh-mobile-drawer-open .float{
    opacity:0!important;
    pointer-events:none!important;
    transform:translateY(110%)!important;
  }

  .dh-mobile-modal-open .float-menu,
  .dh-mobile-drawer-open .float-menu{
    display:none!important;
  }

  .modal.active{
    position:fixed!important;
    inset:0!important;
    z-index:30000!important;
    display:flex!important;
    align-items:stretch!important;
    justify-content:center!important;
    overflow:hidden!important;
    padding:calc(8px + var(--dh-mobile-safe-top)) 10px 0!important;
    background:rgba(0,0,0,.72)!important;
    backdrop-filter:blur(16px) saturate(1.08)!important;
    overscroll-behavior:contain!important;
  }

  .modal-box,
  .modal-box.task-modal-wide{
    width:100%!important;
    max-width:100%!important;
    height:calc(var(--dh-mobile-visual-h) - var(--dh-mobile-safe-top) - 8px)!important;
    max-height:calc(var(--dh-mobile-visual-h) - var(--dh-mobile-safe-top) - 8px)!important;
    margin:auto 0 0!important;
    border-radius:24px 24px 0 0!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
    transform:translateZ(0)!important;
  }

  .modal-head{
    flex:0 0 auto!important;
    position:sticky!important;
    top:0!important;
    z-index:8!important;
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    gap:10px!important;
    padding:16px 16px 12px!important;
    margin:0!important;
    background:linear-gradient(180deg,rgba(18,18,18,.99),rgba(18,18,18,.94))!important;
    border-bottom:1px solid rgba(255,255,255,.08)!important;
    backdrop-filter:blur(14px)!important;
  }

  .modal-head h2,
  #modalTitle{
    min-width:0!important;
    margin:0!important;
    font-size:clamp(23px,7vw,34px)!important;
    line-height:1.02!important;
    letter-spacing:-.055em!important;
    overflow-wrap:anywhere!important;
  }

  .modal-head .btn,
  .modal-head .btn.small{
    width:auto!important;
    min-width:82px!important;
    max-width:120px!important;
    min-height:40px!important;
    height:40px!important;
    padding:0 12px!important;
    border-radius:13px!important;
    white-space:nowrap!important;
    font-size:12px!important;
  }

  #modalBody{
    flex:1 1 auto!important;
    min-height:0!important;
    height:auto!important;
    max-height:none!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    -webkit-overflow-scrolling:touch!important;
    overscroll-behavior:contain!important;
    padding:16px 16px calc(88px + var(--dh-mobile-safe-bottom))!important;
    scroll-padding-bottom:calc(108px + var(--dh-mobile-safe-bottom))!important;
  }

  #modalBody .form,
  #modalBody .grid,
  .modal-box .form,
  .modal-box .grid{
    min-width:0!important;
    max-width:100%!important;
  }

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

  .modal-box:after{
    display:none!important;
  }

  .drawer{
    z-index:30000!important;
    width:100vw!important;
    max-width:100vw!important;
    height:var(--dh-mobile-visual-h)!important;
    max-height:var(--dh-mobile-visual-h)!important;
    padding:0!important;
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
    overscroll-behavior:contain!important;
  }

  .drawer-head{
    flex:0 0 auto!important;
    position:sticky!important;
    top:0!important;
    z-index:9!important;
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    gap:10px!important;
    margin:0!important;
    padding:calc(14px + var(--dh-mobile-safe-top)) 16px 12px!important;
    background:linear-gradient(180deg,rgba(18,18,18,.99),rgba(18,18,18,.94))!important;
    border-bottom:1px solid rgba(255,255,255,.08)!important;
    backdrop-filter:blur(14px)!important;
  }

  .drawer-head h2,
  #drawerTitle{
    min-width:0!important;
    margin:0!important;
    font-size:clamp(23px,7vw,34px)!important;
    line-height:1.02!important;
    letter-spacing:-.055em!important;
    overflow-wrap:anywhere!important;
  }

  .drawer-head .btn,
  .drawer-head .btn.small{
    width:auto!important;
    min-width:82px!important;
    max-width:120px!important;
    min-height:40px!important;
    height:40px!important;
    padding:0 12px!important;
    border-radius:13px!important;
    white-space:nowrap!important;
    font-size:12px!important;
  }

  #drawerBody{
    flex:1 1 auto!important;
    min-height:0!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    -webkit-overflow-scrolling:touch!important;
    overscroll-behavior:contain!important;
    padding:16px 16px calc(88px + var(--dh-mobile-safe-bottom))!important;
    scroll-padding-bottom:calc(108px + var(--dh-mobile-safe-bottom))!important;
  }

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

  .task-save-bar .btn,
  .contract-wizard-actions .btn{
    min-height:46px!important;
  }

  .contract-wizard-actions,
  .contract-wizard-actions .right{
    display:grid!important;
    grid-template-columns:1fr!important;
    gap:8px!important;
    width:auto!important;
  }

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

  .float-main{
    box-shadow:0 18px 44px rgba(0,0,0,.52), inset 0 1px 0 rgba(255,255,255,.2)!important;
  }

  .sidebar{
    transition:transform .22s ease, opacity .18s ease!important;
  }
}

@media (max-width:560px){
  .home-ops-title h2,
  .home-hero-v62 h2,
  .hero h2,
  .commercial-hero h2,
  .content-flow-hero h2,
  .goal-simple-hero h2,
  .diag-hero h2,
  .followup-hero h2,
  .adm-hero h2,
  .links-hero h2,
  .content-hero h2,
  .greeting-hero h2{
    font-size:clamp(32px,11vw,52px)!important;
    line-height:.98!important;
  }

  .card,
  .panel,
  .home-widget-card,
  .home-week-card,
  .quote-form-card,
  .adm-card,
  .finance-pro-card,
  .score-card,
  .content360-editor,
  .content360-side,
  .agenda-inbox-panel,
  .crm-client-panel,
  .links-filter-panel{
    padding:16px!important;
    border-radius:22px!important;
  }

  .modal.active{
    padding-left:0!important;
    padding-right:0!important;
  }

  .modal-box,
  .modal-box.task-modal-wide{
    border-radius:24px 24px 0 0!important;
    height:calc(var(--dh-mobile-visual-h) - var(--dh-mobile-safe-top))!important;
    max-height:calc(var(--dh-mobile-visual-h) - var(--dh-mobile-safe-top))!important;
  }

  .modal-head,
  .drawer-head{
    padding-left:14px!important;
    padding-right:14px!important;
  }

  #modalBody,
  #drawerBody{
    padding-left:14px!important;
    padding-right:14px!important;
  }

  .modal-box .form,
  .drawer .form{
    gap:10px!important;
  }

  .modal-box .btn,
  .drawer .btn{
    min-height:44px!important;
  }
}
