@media(max-width:800px){
  html,body{max-width:100%;overflow-x:hidden}
  .app,.desktop-main,.view,.panel,.calendarbox,.sheet,.detailbox,.property,.setting,.kpi{min-width:0;max-width:100%}
  .desktop-main{width:100%!important;margin-left:0!important;padding:82px 12px 28px!important}
  .view{width:100%!important;overflow:visible}

  /* page headers */
  .page-head,.pipeline-head,.panelhead,.client-topbar,.report-toolbar,.toolbar{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-start!important}
  .page-head>div:first-child,.pipeline-head>div:first-child,.client-topbar>div:first-child{min-width:0;flex:1 1 100%}
  .page-head h1,.page-head h2,.pipeline-head h1,.pipeline-head h2,.client-header h1{font-size:24px!important;line-height:1.08!important;word-break:break-word}
  .page-head p,.pipeline-head p,.client-header p{font-size:12px!important;line-height:1.5!important}
  .page-head .btn,.pipeline-head .btn,.client-actions .btn{min-height:42px}

  /* dashboard */
  .hero{height:auto!important;min-height:190px!important;padding:22px 18px!important;border-radius:16px!important}
  .hero h1{font-size:31px!important;line-height:1.02!important;max-width:88%}
  .hero p{font-size:12px!important;max-width:92%!important}
  .hero:before{position:static!important;display:inline-flex!important;align-self:flex-start;margin:0 0 34px!important;font-size:8px!important;letter-spacing:.12em!important}
  .kpis,.reports-grid,.pipeline-stats,.dashboard-alerts,.report-summary{grid-template-columns:1fr 1fr!important;gap:10px!important}
  .kpi{padding:14px!important;border-radius:11px!important}
  .kpi strong{font-size:25px!important}
  .grid2,.calendar-grid,.detailgrid2,.client-layout,.settings,.settings-shell{grid-template-columns:1fr!important;gap:12px!important}
  .panel,.calendarbox,.detailbox,.setting{padding:14px!important}
  .task,.leadrow,.note-row,.team-row{align-items:flex-start!important;gap:10px!important}
  .time{white-space:normal!important;text-align:right;max-width:92px}

  /* toolbar / filters */
  .toolbar,.report-toolbar{width:100%}
  .toolbar .search,.report-toolbar .search,.search{width:100%!important;min-width:0!important;flex:1 1 100%!important}
  .toolbar select,.toolbar button,.report-toolbar select,.report-toolbar button{flex:1 1 calc(50% - 6px);min-width:0;min-height:42px}

  /* tables */
  .tablewrap{width:100%;max-width:100%;overflow-x:auto!important;-webkit-overflow-scrolling:touch;border-radius:10px}
  .table{min-width:680px;width:max-content!important}
  .table th,.table td{padding:11px 10px!important;font-size:11px!important}

  /* leads and client detail */
  .lead-overview-stats,.info-grid{grid-template-columns:1fr 1fr!important;gap:9px!important}
  .client-topbar{flex-direction:column!important}
  .client-actions{width:100%;display:grid!important;grid-template-columns:1fr 1fr;gap:8px;margin-top:4px}
  .client-actions .btn{width:100%}
  .client-side{grid-template-columns:1fr!important;position:static!important}
  .client-header,.client-card,.detail-card{min-width:0!important;max-width:100%!important}

  /* pipeline */
  .pipeline{display:flex!important;gap:10px!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch;scroll-snap-type:x proximity;padding:2px 2px 12px!important;width:100%!important}
  .pipeline .col,.col{min-width:min(84vw,310px)!important;max-width:min(84vw,310px)!important;scroll-snap-align:start;border-radius:14px!important}
  .card{border-radius:11px!important}

  /* appointments/calendar */
  .week{grid-template-columns:repeat(5,minmax(54px,1fr))!important;overflow-x:auto;padding-bottom:5px}
  .day{padding:9px 6px!important}
  .appointment{padding:12px!important}
  .appointment-time{flex:0 0 58px!important}
  .appointment-body{min-width:0!important}

  /* properties */
  .property-grid{grid-template-columns:1fr 1fr!important;gap:10px!important}
  .property-img{height:128px!important}
  .property-body{padding:11px!important}
  .property-body strong{font-size:16px!important}

  /* settings / reports */
  .settings{gap:10px!important}
  .setting{min-width:0!important}
  .campaign-summary-row{grid-template-columns:minmax(0,1fr) auto auto!important;gap:8px!important}
  .campaign-summary-row>*{min-width:0}
  .chart{overflow-x:auto;min-width:0}

  /* forms */
  .formgrid{grid-template-columns:1fr!important;gap:9px!important}
  input,select,textarea{max-width:100%;font-size:16px!important}
  .sheet input,.sheet select,.sheet textarea{width:100%}
  .new-lead-stage{width:100%}

  /* modals */
  .modal{align-items:flex-end!important;padding:0!important}
  .modal .sheet{width:100%!important;max-width:none!important;max-height:88dvh!important;overflow-y:auto;border-radius:18px 18px 0 0!important;padding:18px 14px calc(18px + env(safe-area-inset-bottom))!important}
  .modal .panelhead{position:sticky;top:0;background:#fff;z-index:2;padding-bottom:8px}

  /* generic protection */
  img,svg,canvas{max-width:100%}
  button{max-width:100%}
  .grow{min-width:0!important}
  .grow small{white-space:normal!important;overflow:visible!important;text-overflow:clip!important}
}

@media(max-width:520px){
  .desktop-main{padding-left:10px!important;padding-right:10px!important}
  .kpis,.reports-grid,.pipeline-stats,.dashboard-alerts,.report-summary,.property-grid,.lead-overview-stats,.info-grid{grid-template-columns:1fr!important}
  .toolbar select,.toolbar button,.report-toolbar select,.report-toolbar button{flex-basis:100%}
  .client-actions{grid-template-columns:1fr!important}
  .page-head h1,.page-head h2,.pipeline-head h1,.pipeline-head h2,.client-header h1{font-size:22px!important}
  .hero h1{font-size:28px!important}
  .panelhead{flex-direction:row!important;align-items:center!important}
  .campaign-summary-row{grid-template-columns:1fr!important}
}
