/* 4.5.7: reserve iOS system areas once, outside the scrolling app. */
:root {
  --hm-safe-top: env(safe-area-inset-top, 0px);
  --hm-safe-bottom: env(safe-area-inset-bottom, 0px);
  --hm-safe-left: env(safe-area-inset-left, 0px);
  --hm-safe-right: env(safe-area-inset-right, 0px);
}
/* The fullscreen mobile app owns a 100dvh canvas. Do not add safe-area padding
   to body: the header and fixed bottom navigation each own their respective inset. */
body {
  padding-top: 0;
  padding-left: 0;
  padding-right: 0;
}
.auth-guard {
  padding: calc(20px + var(--hm-safe-top)) calc(16px + var(--hm-safe-right)) calc(20px + var(--hm-safe-bottom)) calc(16px + var(--hm-safe-left));
  align-items: flex-start;
}
.auth-guard .auth-guard-card { min-width: 0; margin-block: auto; }
@media (max-width: 640px) {
  .topbar { min-width:0; height:auto; min-height:56px; flex:0 0 auto!important; padding:8px 10px; gap:8px; }
  .topbar-title { min-width:0; flex:1 1 auto; display:flex; flex-direction:column; align-items:flex-start; gap:1px; line-height:1.4; }
  .topbar-title .separator { display:none; }
  .topbar-title>span:first-child { max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .topbar-title time { font-size:10px; white-space:nowrap; }
  .topbar-actions { flex:0 0 auto; gap:3px; }
  .topbar-actions .top-version { display:none; }
  .topbar .icon-button,.topbar .avatar { width:36px; height:36px; min-width:36px; flex-shrink:0; }
  .mobile-nav { left:var(--hm-safe-left); right:var(--hm-safe-right); bottom:0; padding:5px 5px calc(8px + var(--hm-safe-bottom)); }
  #mainArea { padding-bottom:calc(92px + var(--hm-safe-bottom)); scroll-padding-bottom:calc(92px + var(--hm-safe-bottom)); }
  .alert-panel { top:calc(64px + var(--hm-safe-top)); left:calc(10px + var(--hm-safe-left)); right:calc(10px + var(--hm-safe-right)); max-height:calc(100dvh - 160px - var(--hm-safe-top) - var(--hm-safe-bottom)); }
  .account-menu { max-width:calc(100vw - 24px - var(--hm-safe-left) - var(--hm-safe-right)); max-height:calc(100dvh - 150px - var(--hm-safe-top) - var(--hm-safe-bottom)); overflow-y:auto; }
  .auth-guard .auth-guard-card { padding:24px 22px; }
  .auth-guard .horizon-auth-mobile-brand { margin-bottom:20px; }
  .auth-guard .auth-guard-card h2 { font-size:26px; }
  .calm-home-header { gap:12px; }
  #home.active { gap:16px; }
  #home .summit-metric { min-height:116px; }
  #home .summit-metric-copy strong { font-size:clamp(21px,6vw,25px); overflow-wrap:anywhere; }
}
@media (max-width: 359px) {
  .topbar-title time { display:none; }
  .topbar-actions { gap:1px; }
  .topbar .icon-button,.topbar .avatar { width:32px; height:36px; min-width:32px; }
}

/* Keep the content column within its grid track, including tablet widths. */
.app-shell,.app-main,#mainArea>.page { min-width:0; max-width:100%; }
#budget>.section-intro { flex-wrap:wrap; }
#budget>.section-intro>div { min-width:0; max-width:100%; }
#budgetFlowMonth { max-width:100%; }

/* 4.6.7: give mobile navigation context and actions their own rows. */
@media (max-width:640px) {
  .app-shell { height:auto; flex:1 1 0%; min-height:0; }
  .topbar { display:grid; grid-template-columns:minmax(0,1fr); gap:8px; padding:12px 12px 10px; height:auto; flex:0 0 auto!important; }
  .topbar-title { width:100%; flex-direction:row; justify-content:space-between; align-items:center; gap:12px; min-height:20px; }
  .topbar-title time { display:block; flex:none; font-size:11px; }
  .topbar-actions { width:100%; min-width:0; justify-content:flex-end; gap:8px; flex-wrap:wrap; }
  .topbar .icon-button,.topbar .avatar { width:40px; height:40px; min-width:40px; }
  .alert-panel { top:calc(112px + var(--hm-safe-top)); max-height:calc(100dvh - 210px - var(--hm-safe-top) - var(--hm-safe-bottom)); }
}
