/* v345: site-wide Urgent message banner + admin Settings panel.
   Last-loaded contrast343.css may still win on generic text colours;
   these rules are specific enough to stay readable in Light and Dark. */

#siteUrgent[hidden],
#siteUrgent:empty{display:none !important;margin:0;padding:0;height:0;border:0}

#siteUrgent{
  position:sticky;
  top:0;
  z-index:40;
  box-sizing:border-box;
  width:100%;
  margin:0;
  padding:10px 16px;
  padding-top:calc(10px + env(safe-area-inset-top, 0px));
  padding-left:max(16px, env(safe-area-inset-left, 0px));
  padding-right:max(16px, env(safe-area-inset-right, 0px));
  background:#7f1d1d;
  color:#ffffff;
  border:0;
  border-bottom:1px solid #9f2a2a;
}

html[data-theme=light] #siteUrgent{
  background:#7f1d1d;
  color:#ffffff;
  border-bottom-color:#9f2a2a;
}
html[data-theme=dark] #siteUrgent{
  background:#9f1239;
  color:#ffffff;
  border-bottom-color:#e11d48;
}

#siteUrgent .urg-inner{
  display:flex;
  align-items:flex-start;
  gap:12px;
  max-width:1100px;
  margin:0 auto;
}

#siteUrgent .urg-ico{
  flex:none;
  width:22px;
  height:22px;
  margin-top:1px;
  stroke:currentColor;
  fill:none;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}

#siteUrgent .urg-txt{
  flex:1 1 auto;
  min-width:0;
  font-size:15px;
  font-weight:700;
  line-height:1.4;
  color:#ffffff;
  -webkit-text-fill-color:#ffffff;
}

#siteUrgent .urg-txt strong{display:block;font-size:11px;letter-spacing:.06em;text-transform:uppercase;opacity:.9;margin:0 0 2px;font-weight:800}

#siteUrgent .urg-x{
  appearance:none;
  flex:none;
  min-width:44px;
  min-height:44px;
  margin:-8px -8px -8px 0;
  border:0;
  border-radius:12px;
  background:transparent;
  color:#ffffff;
  -webkit-text-fill-color:#ffffff;
  font:inherit;
  font-weight:800;
  font-size:14px;
  cursor:pointer;
  display:grid;
  place-items:center;
}
#siteUrgent .urg-x:hover,
#siteUrgent .urg-x:focus-visible{
  background:rgba(255,255,255,.16);
  outline:2px solid #ffffff;
  outline-offset:1px;
}

/* Push the sticky topbar below the banner so nothing is covered and there is no overlap gap. */
html.urgent-on .topbar{
  top:var(--urgent-h, 0px);
  padding-top:10px;
}

/* ---- Settings panel (only mounted for @APJJ / @gymbro) ---- */
#moreContent .urg-admin{
  margin:16px 0 0;
}
#moreContent .urg-admin h3{margin:0 0 6px}
#moreContent .urg-admin .urg-lead{margin:0 0 12px;font-size:14px;line-height:1.45;color:var(--muted)}
#moreContent .urg-admin textarea{
  width:100%;
  min-height:92px;
  max-height:200px;
  resize:vertical;
  box-sizing:border-box;
  margin:0;
}
#moreContent .urg-admin .urg-count{
  margin:6px 0 12px;
  font-size:12px;
  font-weight:700;
  color:var(--muted);
  text-align:right;
}
#moreContent .urg-admin .urg-actions{display:flex;flex-wrap:wrap;gap:8px}
#moreContent .urg-admin .urg-status{margin:10px 0 0;font-size:14px;min-height:1.2em}
#moreContent .urg-admin .urg-status.err{color:var(--danger,#e5484d)}
#moreContent .urg-admin .urg-status.ok{color:var(--accent-text,var(--accent))}
#moreContent .urg-admin .urg-off{margin:0;color:var(--muted)}

/* v347: keep the full urgent banner visible above page chrome.
   Cause: #siteUrgent is position:sticky; top:0; (now z-index:40). On Social
   (#apjjsocial / html.hs-open) .tt-head is position:fixed at
   top:var(--tt-top, 0px) with z-index:30. On phones the main .topbar is
   hidden, and social-feed measure() never counted #siteUrgent, so --tt-top
   was 0 and the Social header covered all but the last line of the banner.
   Headers now sit at max(--tt-top, --urgent-h). Dismiss stays tappable. */
html.urgent-on{
  --tt-top-safe:max(var(--tt-top, 0px), var(--urgent-h, 0px));
}

/* Social feed chrome */
html.urgent-on.hs-open #homeSocial .hs-tt .tt-head{
  top:var(--tt-top-safe);
  /* The banner already includes the safe-area inset; do not add it again. */
  padding-top:8px;
}
html.urgent-on.hs-open #homeSocial .hs-tt .tt-feed{
  top:calc(var(--tt-top-safe) + var(--tt-head, 60px)) !important;
}
html.urgent-on.hs-open #homeSocial .hs-tt .tt-note{
  top:calc(var(--tt-top-safe) + var(--tt-head, 60px) + 6px);
}
html.urgent-on.hs-open #homeSocial .hs-tt > .tt-newpill{
  top:calc(var(--tt-top-safe) + var(--tt-head, 60px) + 10px);
}
html.urgent-on.hs-open #homeSocial .hs-tt > .tt-ptr{
  top:calc(var(--tt-top-safe) + var(--tt-head, 60px) - 34px);
}
html.urgent-on.hs-open #homeSocial .hs-tt > .st-host{
  top:calc(var(--tt-top-safe) + var(--tt-headonly, 60px));
}

@media (min-width:900px){
  html.urgent-on.hs-open #homeSocial .hs-tt .tt-head{
    padding-top:8px;
  }
}

@media (min-width:1000px){
  html.urgent-on.hs-open:has(#homeSocial .hs-tt){
    --tt-cw:max(360px,calc((100vh - var(--tt-top-safe) - var(--tt-bot,0px) - 28px) * 9 / 16));
  }
  html.urgent-on.hs-open #homeSocial .hs-tt .tt-feed{
    top:var(--tt-top-safe)!important;
  }
  html.urgent-on.hs-open #homeSocial .hs-tt .tt-head{
    top:calc(var(--tt-top-safe) + 14px);
  }
  html.urgent-on.hs-open #homeSocial .hs-tt .tt-guestbar{
    top:calc(var(--tt-top-safe) + var(--tt-head,300px) + 26px);
  }
  html.urgent-on.hs-open #homeSocial .hs-tt .tt-note{
    top:calc(var(--tt-top-safe) + 20px);
  }
  html.urgent-on.hs-open #homeSocial .hs-tt .tt-step{
    top:calc(var(--tt-top-safe) + (100vh - var(--tt-top-safe) - var(--tt-bot,0px)) / 2 - 49px);
  }
  html.urgent-on.hs-open #homeSocial .hs-tt > .tt-newpill{
    top:calc(var(--tt-top-safe) + 22px);
  }
  html.urgent-on.hs-open #homeSocial .hs-tt > .st-host{
    top:calc(var(--tt-top-safe) + var(--tt-headonly,300px) + 26px);
  }
}

/* Other sticky/fixed top chrome in the main app (Home/Plan/Progress/More/Profile/Messages).
   Run tracker and games sit under the main .topbar or are separate pages. */
html.urgent-on .pf-nav{
  top:calc(var(--pf-top, 64px) + var(--urgent-h, 0px));
}
html.urgent-on .pf-panel{
  scroll-margin-top:calc(var(--pf-top, 64px) + var(--urgent-h, 0px) + 76px);
}
html.urgent-on .msg-ih{
  top:var(--urgent-h, 0px);
}

/* v347: locked-height Run screens must leave room for the urgent banner.
   Cause: #view-run.rtk-on is height:calc(100dvh - 52px - 72px) with overflow:hidden
   (body.rtk-open and #app are also overflow:hidden). That formula only subtracts
   the topbar and tabbar. When #siteUrgent is showing, the topbar sits below
   --urgent-h, so the run view is taller than the remaining space and Start Run
   (and the bottom of the live / finish / snap screens) is clipped under the
   tabbar. The start column already scrolls inside .rtk-start; the box itself
   must end above the nav. */
html.urgent-on #view-run.rtk-on{
  height:calc(100dvh - 52px - 72px - var(--urgent-h, 0px));
  max-height:calc(100dvh - 52px - 72px - var(--urgent-h, 0px));
  min-height:0;
}
@media (min-width:900px){
  html.urgent-on #view-run.rtk-on{
    height:calc(100dvh - 68px - 76px - var(--urgent-h, 0px));
    max-height:calc(100dvh - 68px - 76px - var(--urgent-h, 0px));
  }
}
html.urgent-on #view-run.rtk-on.rtk-finish{
  height:auto;
  max-height:calc(100dvh - 52px - 72px - var(--urgent-h, 0px));
}
@media (min-width:900px){
  html.urgent-on #view-run.rtk-on.rtk-finish{
    max-height:calc(100dvh - 68px - 76px - var(--urgent-h, 0px));
  }
}

/* Older full-screen run overlay, if still used with the site chrome. */
html.urgent-on .run-screen{
  top:var(--urgent-h, 0px);
}

/* Bottom nav: sit flush on the viewport bottom. No extra gap under the bar;
   keep only the iPhone home-bar inset. Desktop top-nav rules are unchanged. */
@media (max-width:899px){
  html .tabbar{
    bottom:0;
    margin-bottom:0;
    padding-bottom:env(safe-area-inset-bottom, 0px) !important;
  }
}
