/* ==================================================================
   JetStream Live — MOBILE SHELL
   ------------------------------------------------------------------
   Loaded by every page. Everything here is inside a max-width query,
   so the desktop site is completely untouched.

   The problem this solves: the desktop .nav-bar is a flex row of 8
   items with white-space:nowrap. On a phone it is wider than the
   screen, which forces the WHOLE page wider than the viewport. That
   is why content was cut off on the left with dead space on the
   right. A desktop nav squeezed onto a phone is also the single
   clearest "this is a website" signal.

   The fix: hide it on mobile and replace it with a bottom tab bar
   plus a drawer for everything else, which is the standard mobile
   app layout.
   ================================================================== */

:root{
  --jsl-tabbar-h:56px;
}

@media(max-width:900px){

  /* ---- kill the desktop nav and the overflow it causes ---- */
  /* app.html uses a bare <nav>, other pages use .nav-bar. Hide both, or
     app.html ends up with two stacked headers on a phone. */
  .nav-bar,body>nav,nav.nav-bar{display:none!important}
  html,body{max-width:100%;overflow-x:hidden}
  .wrap,.container,main,section,footer{max-width:100%!important;box-sizing:border-box}
  img,video,canvas,table,pre{max-width:100%}

  /* ---- compact app header ---- */
  .jslm-top{
    position:sticky;top:0;z-index:400;
    display:flex;align-items:center;gap:10px;
    height:52px;padding:0 14px;
    padding-top:env(safe-area-inset-top,0px);
    height:calc(52px + env(safe-area-inset-top,0px));
    background:rgba(10,4,32,0.94);
    backdrop-filter:blur(14px);
    border-bottom:1px solid rgba(255,255,255,0.07);
  }
  .jslm-top .jslm-brand{
    font-family:'Orbitron',monospace;font-weight:900;font-size:14px;
    letter-spacing:.5px;color:#fff;text-decoration:none;
    margin-right:auto;display:flex;align-items:center;gap:8px;
  }
  .jslm-top .jslm-brand span{color:#22d3ee}
  .jslm-burger{
    width:38px;height:38px;border:0;background:transparent;
    display:flex;align-items:center;justify-content:center;
    color:#fff;font-size:20px;cursor:pointer;border-radius:10px;
  }
  .jslm-burger:active{background:rgba(255,255,255,0.08)}

  /* ---- bottom tab bar ---- */
  .jslm-tabs{
    position:fixed;left:0;right:0;bottom:0;z-index:500;
    display:flex;
    background:rgba(10,4,32,0.96);
    backdrop-filter:blur(18px);
    border-top:1px solid rgba(255,255,255,0.08);
    padding-bottom:env(safe-area-inset-bottom,0px);
  }
  .jslm-tab{
    flex:1;
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:3px;
    height:var(--jsl-tabbar-h);
    color:rgba(255,255,255,0.45);
    text-decoration:none;
    font-family:'Exo 2',system-ui,sans-serif;
    font-size:10px;font-weight:600;letter-spacing:.3px;
    -webkit-tap-highlight-color:transparent;
  }
  .jslm-tab svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:1.9;
    stroke-linecap:round;stroke-linejoin:round}
  .jslm-tab.active{color:#22d3ee}
  .jslm-tab:active{background:rgba(255,255,255,0.05)}

  /* Content must clear the fixed tab bar or the last item is unreachable. */
  body{
    padding-bottom:calc(var(--jsl-tabbar-h) + env(safe-area-inset-bottom,0px))!important;
  }
  /* Full-height map pages size themselves around both bars. */
  /* jsl.css sizes this as calc(100vh - 58px) for the old fixed nav. That
     nav is hidden now, and there is a tab bar at the bottom, so the height
     has to be recomputed against the new chrome or the map runs off screen. */
  .map-layout{
    height:calc(100dvh - 52px - var(--jsl-tabbar-h) - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px))!important;
    min-height:0!important;
  }
  #map,.leaflet-container{height:100%!important}

  /* ---- slide-in drawer for everything not in the tab bar ---- */
  .jslm-scrim{
    position:fixed;inset:0;z-index:600;
    background:rgba(0,0,0,0.55);
    opacity:0;pointer-events:none;transition:opacity .2s;
  }
  .jslm-scrim.open{opacity:1;pointer-events:auto}
  .jslm-drawer{
    position:fixed;top:0;bottom:0;right:0;z-index:601;
    width:min(78vw,320px);
    background:#0d0620;
    border-left:1px solid rgba(255,255,255,0.08);
    transform:translateX(100%);
    transition:transform .24s cubic-bezier(.2,.7,.3,1);
    display:flex;flex-direction:column;
    padding-top:env(safe-area-inset-top,0px);
    padding-bottom:env(safe-area-inset-bottom,0px);
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  .jslm-drawer.open{transform:translateX(0)}
  .jslm-drawer-head{
    display:flex;align-items:center;justify-content:space-between;
    padding:16px 18px 12px;
    font-family:'Orbitron',monospace;font-weight:900;font-size:13px;color:#fff;
  }
  .jslm-drawer-close{
    width:34px;height:34px;border:0;background:transparent;color:#fff;
    font-size:20px;cursor:pointer;border-radius:9px;
  }
  .jslm-drawer a{
    display:flex;align-items:center;gap:12px;
    padding:14px 18px;min-height:48px;
    color:rgba(255,255,255,0.82);text-decoration:none;
    font-family:'Exo 2',system-ui,sans-serif;font-size:14px;font-weight:600;
    border-bottom:1px solid rgba(255,255,255,0.04);
    -webkit-tap-highlight-color:transparent;
  }
  .jslm-drawer a:active{background:rgba(255,255,255,0.06)}
  .jslm-drawer a.active{color:#22d3ee}

  /* ---- native feel ---- */
  html{-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}
  body{
    -webkit-user-select:none;user-select:none;
    overscroll-behavior-y:none;
    touch-action:manipulation;
  }
  input,textarea,[contenteditable],.selectable{-webkit-user-select:text;user-select:text}
}

/* Desktop keeps the original nav; the mobile shell stays hidden. */
@media(min-width:901px){
  .jslm-top,.jslm-tabs,.jslm-drawer,.jslm-scrim{display:none!important}
}

/* ==================================================================
   CONFLICT FIXES
   ------------------------------------------------------------------
   Things that were positioned assuming a fixed 58px top nav and an
   empty bottom of the screen. Both assumptions change on mobile.
   ================================================================== */
@media(max-width:900px){

  /* The floating AI and theme buttons, the AI panel and the status
     bar all sit at the bottom, where the tab bar now is. Lift them
     clear of it, or they are unreachable. */
  #jaiBtn{
    bottom:calc(var(--jsl-tabbar-h) + 16px + env(safe-area-inset-bottom,0px))!important;
    right:16px!important;width:52px!important;height:52px!important;
  }
  #themeBtn{
    bottom:calc(var(--jsl-tabbar-h) + 16px + env(safe-area-inset-bottom,0px))!important;
    right:78px!important;width:46px!important;height:46px!important;
  }
  #jaiPanel{
    bottom:calc(var(--jsl-tabbar-h) + 78px + env(safe-area-inset-bottom,0px))!important;
    right:12px!important;left:12px!important;
    width:auto!important;max-width:none!important;
    height:min(60dvh,460px)!important;
  }
  #appStatusBar{
    bottom:calc(var(--jsl-tabbar-h) + env(safe-area-inset-bottom,0px))!important;
    max-width:100%!important;font-size:10px!important;
  }

  /* The old nav was position:fixed at 58px tall, so pages padded
     themselves down to clear it. With it hidden that padding leaves
     a blank strip under the new header. */
  #tracker{padding-top:0!important}
  .geo-banner{top:calc(52px + env(safe-area-inset-top,0px))!important}

  /* Desktop-sized fixed panels that would overflow a phone. */
  .modal{max-width:calc(100vw - 28px)!important;max-height:86dvh!important;overflow-y:auto}
  .user-dropdown{right:8px!important;max-width:calc(100vw - 16px)!important}
}
