/* Meu Endo viewport geometry extension. Brand/theme stays in endo-cards.css.
   All routes inherit this file; no model/UA detection or whole-interface scaling.
   Geometry is fixed before paint; overflowing content scrolls without resizing. */
html:root {
  --app-height:100vh; --app-width:100vw; --app-offset-top:0px;
  --endo-usable-height:calc(var(--app-height) - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
  --endo-fit-unit:clamp(2px,calc((var(--endo-usable-height) - 380px) / 100),4px);
  --endo-gutter:clamp(8px,3vw,12px);
  --endo-card-height:clamp(88px,calc(var(--endo-usable-height) * .145),124px);
  --endo-dashboard-height:clamp(64px,calc(var(--endo-usable-height) * .115),104px);
  --endo-list-height:clamp(60px,calc(var(--endo-usable-height) * .105),88px);
  --endo-icon-size:clamp(28px,calc(var(--endo-usable-height) * .046),40px);
  --endo-heading-icon:clamp(32px,calc(var(--endo-usable-height) * .056),44px);
  --endo-page-size:clamp(20px,min(6.2vw,calc(var(--endo-usable-height) * .032)),26px);
  --endo-section-size:clamp(16px,calc(var(--endo-usable-height) * .025),20px);
  --endo-metric-size:clamp(20px,calc(var(--endo-usable-height) * .028),24px);
  --endo-card-size:clamp(14px,3.55vw,16px);
  --endo-touch:44px; --endo-control-height:44px;
}
/* Resolve spacing at each native module scope as well as the document root. */
html:root, html :is(.dashboard,.planilha-page,.progress-module,.my-finance,.my-agenda,.my-benefits,.my-challenges,.endo-shop,[data-endo-shell]) {
  --endo-space-1:var(--endo-fit-unit);
  --endo-space-2:calc(var(--endo-fit-unit) * 2);
  --endo-space-3:calc(var(--endo-fit-unit) * 3);
  --endo-space-4:calc(var(--endo-fit-unit) * 4);
  --endo-space-5:calc(var(--endo-fit-unit) * 5);
  --endo-space-6:calc(var(--endo-fit-unit) * 6);
  --endo-space-8:calc(var(--endo-fit-unit) * 8);
}
@supports(height:100svh){html:root{--app-height:100svh}}
@supports(height:100dvh){html:root{--app-height:100dvh}}
/* Native modules use their settled density from first paint. Loading account data,
   images or changing the global fit level must not resize its typography.
   Keep one shared scale with the existing tight mode. */
html[data-endo-density="tight"], html :is(.dashboard,.planilha-page,.progress-module,.my-finance,.my-agenda,.my-benefits,.my-challenges,.endo-shop,[data-endo-shell]) {
  --endo-fit-unit:2px;
  --endo-card-height:88px; --endo-dashboard-height:60px; --endo-list-height:56px;
  --endo-icon-size:28px; --endo-heading-icon:32px;
  --endo-page-size:20px; --endo-section-size:16px; --endo-metric-size:20px;
  --endo-card-size:14px;
}
/* Keep content and touch targets readable even when the keyboard or text zoom
   leaves too little room. Overflow is a safety valve, never hidden information. */
html body {min-width:0; margin:0;}
html :is(input,textarea,select){max-width:100%;}
html :is(input:not([type=checkbox]):not([type=radio]):not([type=range]),textarea,select){font-size:max(16px,1em);}
html :is(.endo-card,.endo-heading,.endo-button){min-width:0;max-width:100%;overflow-wrap:break-word;}
html :is(.endo-heading,.endo-card) img{max-width:100%;}
html .endo-heading{padding-block:var(--endo-space-4) var(--endo-space-6);margin-bottom:var(--endo-space-3);}
html .endo-heading p{margin-top:var(--endo-space-1);}
html .endo-card{container-type:inline-size;}
html .endo-button{min-height:44px;}

/* One shell/scroll/footer contract for all current modules and future screens.
   Horizontal deck viewports remain clipped horizontally for their gesture logic. */
html :is([data-endo-shell],.planilha-page,.progress-module,.my-finance,.my-agenda,.my-benefits,.my-challenges,.wallet) {
  box-sizing:border-box;top:var(--app-offset-top);bottom:auto;
  height:var(--app-height);max-height:var(--app-height);min-height:0;
  padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px);
  padding-left:max(0px,env(safe-area-inset-left,0px));padding-right:max(0px,env(safe-area-inset-right,0px));
  overflow-x:hidden;overflow-y:auto;
}
html [data-endo-shell]{position:fixed;inset-inline:0;display:flex;flex-direction:column;}
html :is(.mp-shell,.evo-deck,.conquests-deck,.finance-panel,.agenda-panel,.benefits-panel,.challenge-panel) {
  min-width:0;min-height:0;height:100%;max-height:100%;flex:1;box-sizing:border-box;
}
html :is([data-endo-scroll],.mp-viewport,.evo-viewport,.conquest-viewport,.finance-scroll,.agenda-scroll,.benefits-content,.challenge-content){min-height:0;min-width:0;flex:1;}
html :is([data-endo-scroll],.finance-scroll,.agenda-scroll,.benefits-content,.challenge-content) {
  overflow-y:auto;overflow-x:hidden;overscroll-behavior-y:contain;scroll-padding-block:12px;
}
html :is([data-endo-footer],.mp-footer,.progress-return,.finance-footer,.agenda-footer,.benefits-footer,.challenge-footer) {
  flex:none;padding:var(--endo-space-2) var(--endo-gutter);min-width:0;
}
html :is(.progress-return,.mp-footer,.finance-footer,.agenda-footer,.benefits-footer,.challenge-footer) :is(a,button){min-height:44px;}
html :is(.evo-pagination,.conquest-pagination,.mp-pagination){flex:none;gap:var(--endo-space-1);padding-block:var(--endo-space-1);}
html :is(.mp-dots,.evo-pagination>div,.conquest-pagination>div){flex-wrap:wrap;justify-content:center;}
html .progress-module .conquest-pagination small{display:block;}
html .progress-return small{padding-block:var(--endo-space-1);}
html :is(.mp-sync,.finance-footer>small){margin-block:var(--endo-space-1);}
html :is(.evo-slide-person,.conquest-person)>span{white-space:normal;flex-wrap:wrap;}
html :is(.evo-slide-person,.conquest-person) strong{white-space:normal;overflow:visible;text-overflow:clip;overflow-wrap:anywhere;}

/* Dashboard: actual available height, intrinsic header/footer and adaptive rows.
   If long names/challenge copy/accessibility text cannot fit at the tightest
   density, the whole dashboard scrolls rather than trapping lower navigation. */
html #app {min-height:var(--app-height);}
html #dashboard:not([hidden]) {
  position:relative;top:var(--app-offset-top);height:var(--app-height);min-height:0;
  display:flex;flex-direction:column;overflow-y:auto;overflow-x:hidden;
  padding-inline:env(safe-area-inset-left,0px) env(safe-area-inset-right,0px);
}
html .dashboard .student-card{flex:none;padding:calc(env(safe-area-inset-top,0px) + var(--endo-space-1)) var(--endo-gutter) var(--endo-space-5);}
html .dashboard .student-top{min-height:92px;padding-right:50px;gap:var(--endo-space-2);}
html .dashboard .student-photo{width:clamp(56px,calc(var(--endo-usable-height) * .10),86px);height:clamp(56px,calc(var(--endo-usable-height) * .10),86px);}
html .dashboard .student-info h1{font-size:var(--endo-page-size);margin-bottom:var(--endo-space-1);}
html .dashboard .student-actions{gap:4px;}
html .dashboard .student-actions button{width:44px;height:44px;flex-basis:44px;min-width:44px;min-height:44px;}
html .dashboard .student-meta{gap:var(--endo-space-1);}
html .dashboard .student-message{margin-top:var(--endo-space-1);padding-top:var(--endo-space-1);}
html .dashboard .dashboard-sheet {
  flex:1 0 auto;min-height:0;overflow:visible;margin-top:calc(-1 * var(--endo-space-2));
  padding:var(--endo-space-2) var(--endo-gutter) 0;
}
html .dashboard .card-section h2{margin:0 0 var(--endo-space-2);font-size:var(--endo-section-size);}
html .dashboard .card-section h2 svg{width:20px;height:20px;}
html .dashboard .card-section+.card-section{margin-top:var(--endo-space-3);}
html .dashboard .dashboard-sheet .cards {--endo-card-height:var(--endo-dashboard-height);gap:var(--endo-space-2);grid-auto-rows:minmax(var(--endo-dashboard-height),auto);}
html .dashboard .dashboard-sheet .nav-card{min-height:var(--endo-dashboard-height);height:auto;padding:var(--endo-space-2) 16px var(--endo-space-2) 8px;gap:var(--endo-space-1);}
html .dashboard .dashboard-sheet .card-text :is(strong,small){white-space:normal;overflow:visible;text-overflow:clip;overflow-wrap:break-word;}
html .dashboard .card-text small{margin-top:var(--endo-space-1);}
html .dashboard .dashboard-sheet .nav-card .card-icon{width:var(--endo-icon-size);height:var(--endo-icon-size);flex-basis:var(--endo-icon-size);top:0;}
html .dashboard .dashboard-footer{margin:var(--endo-space-2) calc(-1 * var(--endo-gutter)) 0;padding:var(--endo-space-2) var(--endo-gutter) calc(var(--endo-space-2) + env(safe-area-inset-bottom,0px));}
html .dashboard .dashboard-footer .heart-rule{margin-block:var(--endo-space-1);}
html .dashboard .dashboard-footer p{margin-top:var(--endo-space-1);}
html .dashboard .monthly-challenge-card{min-height:0;padding:var(--endo-space-2);gap:var(--endo-space-1);}

/* Login keeps the existing actions, including unavailable social options. */
html #login {height:var(--app-height);min-height:0;overflow-y:auto;overflow-x:hidden;padding:calc(env(safe-area-inset-top) + var(--endo-space-2)) env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + var(--endo-space-2)) env(safe-area-inset-left);}
html .login .login-content{min-height:100%;gap:var(--endo-space-1);padding-inline:var(--endo-gutter);}
html .login .login-logo{width:70%;max-width:clamp(160px,calc(var(--endo-usable-height) * .34),300px);margin:0 auto var(--endo-space-2);}
html .login h1{margin-bottom:var(--endo-space-1);}
html .login .login-description{margin-bottom:var(--endo-space-2);}
html .login .field{height:44px;margin-bottom:var(--endo-space-2);}
html .login .field input{font-size:16px;}
html .login .login-options{flex-wrap:wrap;margin-block:var(--endo-space-1);}
html .login .login-options :is(label,a){min-height:44px;display:inline-flex;align-items:center;}
html .login :is(.primary,.social,.plans-button){min-height:44px;height:auto;padding-block:8px;}
html .login .or{margin-block:var(--endo-space-1);}
html .login :is(.social,.plans-caption){margin-block:var(--endo-space-1);}
html .login .beta-footer{margin:0;padding-top:var(--endo-space-2);}
html #welcome{top:var(--app-offset-top);height:var(--app-height);min-height:0;overflow-y:auto;}
html #welcome>*{flex-shrink:0;}

/* Decks keep horizontal gestures. Content-sized metrics replace rigid 145–190px
   minima and empty stretch space, without hiding any prescribed activities. */
html .progress-module :is(.evo-panel,.conquest-slide){padding:0 var(--endo-gutter) var(--endo-space-2);}
html .progress-module .evo-panel{min-height:0;height:auto;}
html .progress-module .evo-panel-inner{min-height:0;}
html .progress-module :is(.evo-tile-grid,.conquest-grid,.conquest-highlights,.conquest-medals){flex:none;grid-auto-rows:minmax(var(--endo-card-height),auto);gap:var(--endo-space-2);}
html .progress-module .movement-category .conquest-grid{grid-auto-rows:minmax(var(--endo-card-height),auto);}
html .progress-module .movement-category .conquest-metric{height:auto;min-height:var(--endo-card-height);grid-template-rows:auto auto auto;padding:var(--endo-space-3);}
html .progress-module .movement-category{margin-bottom:var(--endo-space-3);}
html .progress-module .movement-category+.movement-category{padding-top:var(--endo-space-3);}
html .progress-module :is(.evo-insight,.evo-insight-card,.evo-journey-highlight,.conquest-card-preview){min-height:0;padding:var(--endo-card-padding);margin-block:var(--endo-space-2);}
html .progress-module .evo-chart{flex:none;min-height:0;padding:var(--endo-space-2);}
html .progress-module .evo-chart>svg{flex:none;min-height:0;max-height:clamp(120px,calc(var(--endo-usable-height) * .26),240px);}
html .progress-module .conquest-target{min-height:0;flex:none;gap:var(--endo-space-2);padding:var(--endo-card-padding);}
html .progress-module .conquest-ring{width:clamp(100px,calc(var(--endo-usable-height) * .16),124px);height:clamp(100px,calc(var(--endo-usable-height) * .16),124px);}
html .progress-module .conquest-ring>div{width:84%;height:84%;}
html .progress-module :is(.conquest-medal,.conquest-highlights>div){padding:var(--endo-card-padding);min-height:var(--endo-card-height);}
html .planilha-page :is(.mp-week-nav,.mp-days,.mp-day-title){margin-bottom:var(--endo-space-2);}
html .planilha-page .mp-days button{min-height:64px;padding:var(--endo-space-1);gap:var(--endo-space-1);}
html .planilha-page :is(.mp-week-item,.mp-activity)>summary{min-height:var(--endo-list-height);padding-block:var(--endo-space-2);}
html .planilha-page .mp-detail{padding:var(--endo-space-3);gap:var(--endo-space-2);}
html .planilha-page .mp-steps{gap:var(--endo-space-2);}
html .planilha-page .mp-steps li{padding-top:var(--endo-space-2);}

/* Carteirinha has a separately scrollable face only when the photo/QR and
   identity cannot fit. The QR retains a usable minimum instead of collapsing. */
html .wallet .wallet-ready{flex:1 0 350px;min-height:350px;grid-template-rows:minmax(220px,1fr) 44px auto 44px;}
html .wallet .wallet-pages{min-height:220px;}
html .wallet .wallet-page{overflow-y:auto;}
html .wallet .wallet-face{min-height:100%;height:auto;overflow:visible;padding-top:var(--endo-space-2);row-gap:var(--endo-space-2);}
html .wallet .wallet-face footer{height:auto;min-height:48px;}
html .wallet .wallet-photo{width:min(68cqw,40cqh);height:min(68cqw,40cqh);min-height:72px;min-width:72px;}
html .wallet .wallet-qr{min-height:120px;}
html .wallet .wallet-qr img{min-height:120px;max-height:calc(var(--endo-usable-height) * .4);}
html .wallet .wallet-return{margin-top:var(--endo-space-2);padding-block:var(--endo-space-2);min-height:44px;}
html .wallet .wallet-pager{height:44px;}

/* Dialog header/close and footer remain outside their exceptional body scroll. */
html .endo-birthday-dialog {
  top:calc(var(--app-offset-top) + var(--app-height) / 2 + (env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 2);
  max-height:calc(var(--endo-usable-height) - 2 * var(--endo-space-2));
  width:min(calc(var(--app-width) - 2 * var(--endo-gutter)),440px);
}
html .endo-birthday-header{padding-block:var(--endo-space-3);}
html .endo-birthday-header>img{max-height:clamp(38px,calc(var(--endo-usable-height) * .08),66px);width:auto;max-width:60%;object-fit:contain;}
html .endo-birthday-body{min-height:0;padding-block:var(--endo-space-2);overflow-y:auto;}
html .endo-birthday-portrait{width:clamp(48px,calc(var(--endo-usable-height) * .095),76px);height:clamp(48px,calc(var(--endo-usable-height) * .095),76px);}
html .endo-birthday-person{min-width:0;}
html .endo-birthday-footer{flex:none;padding-block:var(--endo-space-2);}
html .ws-dialog{top:var(--app-offset-top);bottom:auto;height:var(--app-height);max-height:var(--app-height);overflow-y:auto;}
html dialog{box-sizing:border-box;max-width:calc(var(--app-width) - 16px);max-height:calc(var(--endo-usable-height) - 16px);overflow-y:auto;}

/* A wide, short window is still usable (phone landscape/split-screen). */
@media(min-width:600px) and (max-height:600px){
  html #app{display:block;max-width:var(--endo-content-width);margin-inline:auto;}
  html .desktop-message{display:none;}
}
/* Preserve the outer controls in extremely short windows: one accessible outer
   scroll is preferable to squeezing controls under 44px or hiding content. */
@media(max-height:360px){
  html :is(.mp-shell,.evo-deck,.conquests-deck,.finance-panel,.agenda-panel,.benefits-panel,.challenge-panel){min-height:300px;max-height:none;flex-shrink:0;}
}
html[data-endo-keyboard="true"] :is(.mp-shell,.evo-deck,.conquests-deck,.finance-panel,.agenda-panel,.benefits-panel,.challenge-panel){min-height:min(300px,var(--endo-usable-height));}
@container (max-width:180px){
  .endo-card .endo-button{width:100%;}
}

/* Retain the approved inset frame where the module already uses one. */
html :is(.planilha-page,.my-finance,.my-agenda){padding:max(6px,env(safe-area-inset-top)) max(6px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(6px,env(safe-area-inset-left));}
html .wallet{padding:max(6px,env(safe-area-inset-top)) max(7px,env(safe-area-inset-right)) max(9px,env(safe-area-inset-bottom)) max(7px,env(safe-area-inset-left));}
/* Very short dialogs may scroll as a whole so their close and final action are
   still reachable if even the header plus footer exceed the available height. */
html .endo-birthday-dialog{overflow-y:auto;}
/* Secondary editors inherit the same spacing; only the exported artwork keeps
   its original pixel dimensions. */
html .ws-editor{padding:max(var(--endo-space-3),env(safe-area-inset-top)) var(--endo-gutter) max(var(--endo-space-3),env(safe-area-inset-bottom));}
html .ws-title{gap:var(--endo-space-2);margin-bottom:var(--endo-space-2);}
html .ws-preview{width:min(100%,calc(var(--endo-usable-height) * .304));margin-top:var(--endo-space-2);}
html .ws-empty{padding:var(--endo-space-6) var(--endo-gutter);}
html .wallet-preview{max-height:calc(var(--endo-usable-height) * .38);}
html :is(.challenge-card-top,.benefit-toolbar){flex-wrap:wrap;}
html :is(.finance-details dd,.benefits-content,.challenge-content){overflow-wrap:break-word;}
