/* V177 — iPhone 14 Pro Max + iPad A16 final responsive layer */
html,body{max-width:100%;overflow-x:hidden}
img,svg,video,canvas{max-width:100%}

/* iPad / tablet: preserve full app, use comfortable two-column layouts */
@media (min-width:768px) and (max-width:1180px){
  body.nirvana-tablet .sidebar,
  body.nirvana-ipad .sidebar{width:210px!important;padding:18px 14px!important;display:flex!important}
  body.nirvana-tablet .main-shell,
  body.nirvana-ipad .main-shell{margin-left:210px!important;min-width:0!important}
  body.nirvana-tablet .side-nav button,
  body.nirvana-ipad .side-nav button{min-height:42px!important;padding:9px 10px!important;gap:9px!important}
  body.nirvana-tablet .side-nav .nav-text,
  body.nirvana-ipad .side-nav .nav-text{display:inline!important;font-size:12px!important;white-space:nowrap!important}
  body.nirvana-tablet .nav-flyout,
  body.nirvana-ipad .nav-flyout{width:min(340px,calc(100vw - 230px))!important;max-height:70dvh!important;overflow:auto!important}
  #refDashboard{padding:16px!important;gap:14px!important;min-height:auto!important}
  #refDashboard .ref-kpis{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  #refDashboard .ref-main{grid-template-columns:minmax(0,1.35fr) minmax(0,1fr)!important}
  #refDashboard .ref-goal{grid-column:1/-1!important}
  #refDashboard .ref-bottom{grid-template-columns:1fr 1fr!important}
  #refDashboard .ref-quick{grid-column:1/-1!important}
  #refDashboard .ref-quick>div{grid-template-columns:repeat(4,1fr)!important}
  #refDashboard .ref-plan #refToday{max-height:360px!important;overflow-y:auto!important;overscroll-behavior:contain!important;-webkit-overflow-scrolling:touch!important}
  #plannerPage .content,#plannerPage{min-width:0!important}
  #plannerPage .days,#plannerPage .drag-board{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:12px!important}
  #plannerPage .planner-ref-top,#plannerPage .planner-top{grid-template-columns:1fr!important}
  #plannerPage .plan-actions,#plannerPage .planner-actions{display:flex!important;flex-wrap:wrap!important;justify-content:flex-end!important;gap:8px!important;position:relative!important;z-index:20!important}
  #coachPage .v123-layout{grid-template-columns:minmax(190px,.7fr) minmax(0,2fr)!important}
  #coachPage #v123CoachMsgs{height:54dvh!important;min-height:320px!important}
}

/* iPhone 14 Pro Max / phones */
@media (max-width:767px){
  :root{--safe-bottom:max(10px,env(safe-area-inset-bottom))}
  body{padding-bottom:calc(72px + var(--safe-bottom))!important;overflow-x:hidden!important}
  .sidebar{display:none!important}
  .main-shell{margin-left:0!important;width:100%!important;min-width:0!important}
  .app-header{height:auto!important;min-height:64px!important;padding:10px 12px!important;gap:8px!important;position:sticky!important;top:0!important}
  .hello{min-width:0!important}.hello strong{font-size:17px!important}.hello span{font-size:10px!important}
  .goal-switch{transform:scale(.9);transform-origin:right center;max-width:52vw!important}
  .content{padding:10px!important;overflow:hidden!important}
  .page{max-width:100%!important;overflow-x:hidden!important}

  .mobile-nav{display:flex!important;height:calc(66px + var(--safe-bottom))!important;padding-bottom:var(--safe-bottom)!important;overflow-x:auto!important;overflow-y:hidden!important;overscroll-behavior-x:contain!important;-webkit-overflow-scrolling:touch!important;scrollbar-width:none!important}
  .mobile-nav::-webkit-scrollbar{display:none!important}
  .mobile-nav button{flex:0 0 72px!important;min-width:72px!important;height:64px!important;padding:7px 3px!important}
  .mobile-nav button span{font-size:8px!important;white-space:nowrap!important}

  #refDashboard{padding:12px!important;gap:11px!important;min-height:auto!important;overflow:visible!important}
  #refDashboard .ref-hero{display:grid!important;grid-template-columns:1fr!important;gap:10px!important}
  #refDashboard .ref-hero h1{font-size:26px!important;margin:4px 0!important}
  #refDashboard .ref-hero p{font-size:12px!important}
  #refDashboard .ref-date{width:100%!important;min-width:0!important;height:auto!important;margin:0!important}
  #refDashboard .ref-countdowns,#refDashboard .ref-countdown-row{grid-template-columns:1fr!important;gap:8px!important}
  #refDashboard .ref-kpis{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important}
  #refDashboard .ref-kpis article{padding:12px!important;grid-template-columns:42px minmax(0,1fr)!important;gap:8px!important}
  #refDashboard .ref-kpis article>span{width:42px!important;height:42px!important;font-size:21px!important}
  #refDashboard .ref-kpis b{font-size:20px!important}
  #refDashboard .ref-main{grid-template-columns:1fr!important;gap:10px!important}
  #refDashboard .ref-card{min-width:0!important;padding:13px!important;border-radius:16px!important}
  #refDashboard .ref-plan #refToday{max-height:390px!important;overflow-y:auto!important;overflow-x:hidden!important;-webkit-overflow-scrolling:touch!important;overscroll-behavior:contain!important;padding-right:4px!important}
  #refDashboard .ref-plan label{min-height:48px!important;grid-template-columns:22px minmax(0,1fr) auto!important;padding:8px!important;gap:7px!important}
  #refDashboard .ref-plan label b{font-size:11px!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important}
  #refDashboard .ref-timer .clock{font-size:46px!important;margin:18px 0!important}
  #refDashboard .ref-bottom{grid-template-columns:1fr!important;gap:10px!important}
  #refDashboard .ref-results>div{grid-template-columns:repeat(2,1fr)!important}
  #refDashboard .ref-quick>div{grid-template-columns:repeat(2,1fr)!important}

  #plannerPage{overflow:hidden!important}
  #plannerPage .page-title,#plannerPage .planner-ref-top,#plannerPage .planner-top{display:block!important}
  #plannerPage .actions,#plannerPage .plan-actions,#plannerPage .planner-actions{display:flex!important;flex-wrap:wrap!important;width:100%!important;gap:7px!important;justify-content:flex-start!important;position:relative!important;z-index:20!important}
  #plannerPage .actions button,#plannerPage .plan-actions button,#plannerPage .planner-actions button{flex:1 1 auto!important;min-width:120px!important}
  #plannerPage .week-strip-ref,#plannerPage .week-strip{display:flex!important;overflow-x:auto!important;white-space:nowrap!important;gap:6px!important;-webkit-overflow-scrolling:touch!important;padding-bottom:5px!important;scrollbar-width:none!important}
  #plannerPage .week-strip-ref::-webkit-scrollbar,#plannerPage .week-strip::-webkit-scrollbar{display:none!important}
  #plannerPage .days,#plannerPage .drag-board{display:flex!important;overflow-x:auto!important;gap:10px!important;scroll-snap-type:x proximity!important;-webkit-overflow-scrolling:touch!important;padding-bottom:8px!important}
  #plannerPage .day-card,#plannerPage .drop-day{flex:0 0 88vw!important;max-width:88vw!important;scroll-snap-align:start!important}
  #plannerPage .plan-duration-reference-grid,#plannerPage .plan-category-grid{grid-template-columns:1fr!important}
  #plannerPage .plan-duration-reference,#plannerPage .plan-category-card{min-width:0!important}

  #coachPage{overflow:hidden!important}
  #coachPage .v123-layout{display:block!important}
  #coachPage .v123-side{display:none!important}
  #coachPage .v123-chat{width:100%!important;min-width:0!important}
  #coachPage #v123CoachMsgs{height:calc(100dvh - 285px)!important;min-height:300px!important;max-height:none!important;padding-bottom:8px!important}
  #coachPage .v123-compose{position:sticky!important;bottom:calc(70px + var(--safe-bottom))!important;width:100%!important;margin:0!important;grid-template-columns:40px minmax(0,1fr) 46px!important;z-index:50!important}
  #coachPage #v123CoachInput{font-size:16px!important;min-height:56px!important;height:56px!important;max-height:120px!important}
  #coachPage .v123-compose button[type="submit"]{width:46px!important;min-width:46px!important;height:46px!important}

  .modal{padding:10px!important;align-items:end!important}
  .modal-card{width:100%!important;max-height:86dvh!important;border-radius:20px 20px 0 0!important;padding-bottom:calc(18px + var(--safe-bottom))!important}
}

/* Landscape phone: keep actions accessible without giant vertical cards */
@media (max-width:932px) and (orientation:landscape){
  #refDashboard .ref-kpis{grid-template-columns:repeat(4,minmax(0,1fr))!important}
  #refDashboard .ref-main{grid-template-columns:1.15fr 1fr!important}
  #refDashboard .ref-goal{grid-column:1/-1!important}
  #refDashboard .ref-bottom{grid-template-columns:1fr 1fr!important}
  #refDashboard .ref-quick{grid-column:1/-1!important}
  #coachPage #v123CoachMsgs{height:48dvh!important}
}
