/* Demo Home — iPhone safe-area layer (2026-11-17, "safearea").
   Loaded LAST. Keeps every pop-up's header, Back (◀ Ring) and × buttons below the
   iOS status bar / Dynamic Island and above the home indicator.
   --sat/--sab/--sal/--sar = env(safe-area-inset-*). On desktop/iPad those are 0, so
   the 14px floors below match the old glass.css gaps (no visual change there).
   Test hook: <html class="sa-test"> fakes iPhone 15 Pro insets (59px top / 34px bottom). */
:root{
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sa-top: max(14px, var(--sat));
  --sa-bot: calc(14px + var(--sab));
  --sa-maxh: calc(100dvh - var(--sa-top) - var(--sa-bot));
}
html.sa-test{ --sat: 59px; --sab: 34px; }

/* ---------- atv-style sheets (Vitals, Nutrition, Health Today, Dogs, Groceries,
   Jet Log, Garage, Workouts, Settings, Remote, Routines, Alerts, Groups, Moods…) ---------- */
.atv-overlay{ box-sizing: border-box; padding-left: var(--sal); padding-right: var(--sar); }
.atv-overlay > .atv-sheet{
  max-height: var(--sa-maxh) !important;
  margin-bottom: var(--sa-bot) !important;
}
#vitalsSheet, #nutritionSheet,
#dogsOverlay > #dogsSheet, #reefDashOverlay > #reefDashSheet, #groceriesOverlay > #groceriesSheet,
#jetlogOverlay > #jetlogSheet, #garageOverlay > #garageSheet,
#workoutsOverlay > #workoutsSheet{ min-height: min(860px, calc(100dvh - 60px), var(--sa-maxh)) !important; }
@media (max-width: 760px){ #workoutsOverlay > #workoutsSheet{ min-height: 0 !important; } }

/* Sticky header: Back + title + × stay on screen while the sheet scrolls.
   --sa-pt/--sa-pl/--sa-pr are the sheet's own paddings (set by safearea.js). */
.atv-sheet > .atv-head:first-child{
  position: sticky;
  top: calc(-1 * var(--sa-pt, 16px));
  z-index: 30;
  margin-top: calc(-1 * var(--sa-pt, 16px));
  margin-left: calc(-1 * var(--sa-pl, 18px));
  margin-right: calc(-1 * var(--sa-pr, 18px));
  padding-top: var(--sa-pt, 16px);
  padding-left: var(--sa-pl, 18px);
  padding-right: var(--sa-pr, 18px);
  padding-bottom: 8px;
  margin-bottom: 4px;
  background: transparent;
  transition: background-color .2s ease, box-shadow .2s ease;
}
.atv-sheet.sa-stuck > .atv-head:first-child{
  background: rgba(16, 23, 34, 0.94);
  box-shadow: 0 1px 0 rgba(255,255,255,.07), 0 10px 22px -12px rgba(0,0,0,.7);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))){
  .atv-sheet.sa-stuck > .atv-head:first-child{
    background: rgba(16, 23, 34, 0.93);
    -webkit-backdrop-filter: blur(18px) saturate(1.3);
    backdrop-filter: blur(18px) saturate(1.3);
  }
}
/* Section tabs tuck in right under the sticky header instead of behind it. */
.atv-sheet > .vx-tabs{ top: calc(var(--sa-headh, 0px) - var(--sa-pt, 16px)); }

/* 44×44 tap targets, above content */
.atv-head .vx-back{
  position: relative; z-index: 2;
  min-height: 44px; min-width: 44px; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  touch-action: manipulation;
}
.atv-head .icon-btn{ position: relative; z-index: 2; min-width: 44px; min-height: 44px; touch-action: manipulation; }

/* ---------- vx-modal (meal detail etc.) ---------- */
.vx-modal{
  padding: max(18px, var(--sat)) max(18px, var(--sar)) max(18px, var(--sab)) max(18px, var(--sal));
}
.vx-modal-card{ max-height: calc(100dvh - max(18px, var(--sat)) - max(18px, var(--sab))); }
.vx-modal-head .icon-btn{ min-width: 44px; min-height: 44px; flex: 0 0 auto; }

/* ---------- Dental: X-ray viewer + tooth panel ---------- */
#dxXrayBox{
  padding: max(14px, var(--sat)) max(16px, var(--sar)) max(14px, var(--sab)) max(16px, var(--sal));
}
#dxXrayBox .dx-xb-bar{ position: relative; z-index: 3; }
.dx-xb-x{ width: 44px; height: 44px; flex: 0 0 auto; touch-action: manipulation; }
.dx-x{ width: 44px; height: 44px; touch-action: manipulation; }
@media (max-width: 480px){
  .dx-xb-stage img{ max-width: calc(100% - 96px); }
  .dx-xb-nav{ width: 40px; }
}

/* ---------- Vitals Ring × ---------- */
.vr-close{ width: 44px; height: 44px; }

/* ---------- Calendar / Receipts panels (they already use env(); vars make sa-test work) ---------- */
.bhcal-panel, .bhr-panel{
  inset: max(14px, var(--sat)) max(14px, var(--sar)) max(14px, var(--sab)) max(14px, var(--sal));
}
@media (max-width: 700px){
  .bhcal-panel, .bhr-panel{
    inset: max(8px, var(--sat)) max(6px, var(--sar)) max(8px, var(--sab)) max(6px, var(--sal));
  }
}
.bhcal-x, .bhr-x{ min-width: 44px; min-height: 44px; display: inline-grid; place-items: center; touch-action: manipulation; }

/* ---------- Lock sheet ---------- */
.bh-lock{ box-sizing: border-box; padding: var(--sat) var(--sar) var(--sab) var(--sal); }

/* ---------- Frosted bottom sheets: Climate, Movie Night, Dog Cam, Room Lights, Xbox ---------- */
.climate-overlay .climate-sheet:not(.lights-sheet):not(.mn-sheet),
.xbox-overlay .xbox-sheet{ max-height: calc(100% - var(--sa-top) - var(--sa-bot)) !important; }
body.has-nowbar .climate-overlay .climate-sheet:not(.lights-sheet):not(.mn-sheet),
body.has-nowbar .xbox-overlay .xbox-sheet{ max-height: calc(100% - var(--sa-top) - var(--sa-bot) - 76px) !important; }
.climate-overlay .climate-sheet.lights-sheet{ max-height: min(calc(100dvh - var(--sa-top) - var(--sa-bot)), 860px) !important; }
body.has-nowbar .climate-overlay .climate-sheet.lights-sheet{ max-height: min(calc(100dvh - var(--sa-top) - var(--sa-bot) - 76px), 780px) !important; }
html .climate-overlay.movienight-overlay .climate-sheet.mn-sheet{ height: min(calc(100% - var(--sa-top) - var(--sa-bot)), 900px); }
html body.has-nowbar .climate-overlay.movienight-overlay .climate-sheet.mn-sheet{ height: min(calc(100% - var(--sa-top) - var(--sa-bot) - 76px), 860px); }
/* Plex player (centred card) */
.climate-overlay.mn-player-overlay{
  box-sizing: border-box;
  padding: var(--sa-top) max(0px, var(--sar)) var(--sa-bot) max(0px, var(--sal));
}
.mn-player-overlay .mn-player-sheet{ max-height: min(100%, 900px) !important; }
.climate-overlay .x, .climate-overlay .climate-close{ min-width: 44px; min-height: 44px; position: relative; z-index: 3; }
