/* Phone layer — pairs with mobile.js. Everything that changes layout is inside a max-width query, so desktop is untouched.
   ≤860px: bottom tab bar, sticky title bar, drawer extras, one-row tab strips, pinned first column on wide tables.
   ≤640px: tables as cards (body.tables-as-table switches back), dialogs as bottom sheets. */

/* empty nav badges rendered as grey dashes on every screen */
nav a .n:empty{display:none}
.bbar,.navfind,.msort,.tview{display:none}

@media (max-width:860px){
  body.hd-in{--bbh:calc(60px + env(safe-area-inset-bottom))}
  body.hd-in.kbd{--bbh:0px}

  /* bottom tab bar */
  body.hd-in .bbar{display:grid;grid-template-columns:repeat(var(--bbn,5),minmax(0,1fr));position:fixed;left:0;right:0;bottom:0;z-index:1400;
    background:rgba(27,26,23,.97);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border-top:1px solid rgba(255,255,255,.08);
    padding:4px max(4px,env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px,env(safe-area-inset-left))}
  body.hd-in.kbd .bbar{display:none}
  .bbar a,.bbar button{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;min-height:54px;
    background:none;border:none;border-radius:12px;color:#B9B4A8;text-decoration:none;font:600 11px/1.1 var(--font-sans);cursor:pointer;padding:0;-webkit-tap-highlight-color:transparent}
  .bbar a.on,.bbar button.on{color:#fff}
  .bbar a.on svg,.bbar button.on svg{color:var(--brand)}
  .bbar a:active,.bbar button:active{background:rgba(255,255,255,.08)}
  .bbar .bbn:empty,.bbar .bn:empty{display:none}
  .bbar .bbn,.bbar .bn{position:absolute;top:4px;left:calc(50% + 6px);min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:var(--danger);
    color:#fff;font:700 10.5px/18px var(--mono);font-style:normal;text-align:center}
  .bbar .bbn{background:var(--brand)}
  /* the bar replaces the ☰ and 🔔 in the title bar */
  body.hd-in main .hamb,body.hd-in main .topbar #bell{display:none}

  /* room for the bar: page end, toasts, embedded tools, Ask AI */
  body.hd-in main{padding-bottom:calc(var(--bbh) + 28px)}
  body.hd-in #toast{bottom:calc(var(--bbh) + 12px);max-width:calc(100vw - 32px)}
  body.hd-in .idlewarn{bottom:calc(var(--bbh) + 12px)}
  body.hd-in #toolhost{bottom:var(--bbh);padding-bottom:6px}
  body.hd-in main:has(.askai){padding-bottom:calc(var(--bbh) + 6px)}

  /* sticky title bar */
  main>.topbar{position:sticky;top:0;z-index:60;flex-wrap:nowrap;gap:8px;margin:0 -14px 12px;padding:calc(8px + env(safe-area-inset-top)) 14px 8px;
    background:rgba(250,249,246,.95);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}
  main>.topbar h1{font-size:22px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
  main>.topbar #topright{flex:none}
  main>.topbar #topright .btn{padding:0 10px}

  /* menu drawer */
  nav.side{height:100dvh;padding-top:calc(16px + env(safe-area-inset-top));padding-bottom:calc(16px + env(safe-area-inset-bottom));overscroll-behavior:contain;z-index:1500}
  body.navopen{overflow:hidden}
  .navfind{display:block;padding:0 4px 6px}
  .navfind input{width:100%;min-height:42px;border-radius:11px;border:1px solid rgba(255,255,255,.18);background:rgba(255,255,255,.07);color:#fff;padding:8px 12px;font-size:16px}
  .navfind input::placeholder{color:#9C978C}
  nav.side a[hidden],nav.side .grp[hidden],nav.side .navsub[hidden]{display:none}
  nav.side a{min-height:44px}

  /* tab strips and pill rows stay one row and swipe sideways */
  .tabs,.pills{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch;scroll-behavior:smooth}
  .tabs::-webkit-scrollbar,.pills::-webkit-scrollbar{display:none}
  .tabs a,.pills button{flex:none;white-space:nowrap}
  main>.tabs,main>.pills{margin-left:-14px;margin-right:-14px;padding-left:14px;padding-right:14px}

  /* wide tables that stay tables: keep the row name in view while scrolling sideways */
  .tablewrap.mwide td:first-child,.tablewrap.mwide th:first-child{position:sticky;left:0;z-index:1;background:var(--surface);max-width:44vw;min-width:8.5em;white-space:normal;box-shadow:1px 0 0 var(--line)}
  .tablewrap.mwide th:first-child{z-index:3;background:var(--surface-2)}

  .grid2{grid-template-columns:repeat(auto-fit,minmax(min(100%,340px),1fr))}
  iframe.embed{height:calc(100dvh - 110px - var(--bbh,0px))}
}

@media (max-width:640px){
  /* tables as cards */
  body:not(.tables-as-table) .tablewrap.cardable{border:none;background:transparent;border-radius:0;overflow:visible}
  body:not(.tables-as-table) .cardable table,body:not(.tables-as-table) .cardable tbody{display:block;width:100%}
  body:not(.tables-as-table) .cardable thead{display:none}
  body:not(.tables-as-table) .cardable tr{display:block;background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:11px 13px 9px;margin-bottom:8px}
  body:not(.tables-as-table) .cardable tr.click:active{background:#FBFAF7}
  body:not(.tables-as-table) .cardable td{display:flex;flex-wrap:wrap;justify-content:flex-end;align-items:baseline;gap:4px 8px;padding:3px 0;border:none;white-space:normal;
    text-align:right;overflow-wrap:anywhere;min-height:0;background:none}
  body:not(.tables-as-table) .cardable td::before{content:attr(data-label);flex:none;max-width:46%;text-align:left;font-family:var(--mono);font-size:10px;font-weight:700;
    letter-spacing:.06em;text-transform:uppercase;color:var(--muted);padding-top:2px;margin-right:auto}
  body:not(.tables-as-table) .cardable td>.bar{flex:1 1 40%;max-width:60%;align-self:center}
  body:not(.tables-as-table) .cardable td:first-child{display:block;text-align:left;font-weight:600;font-size:15px;padding:0 0 7px;margin-bottom:5px;border-bottom:1px solid var(--line)}
  body:not(.tables-as-table) .cardable td:first-child::before,body:not(.tables-as-table) .cardable td.mspan::before{display:none}
  body:not(.tables-as-table) .cardable td:not([data-label]):not(:first-child){display:flex;justify-content:flex-start;flex-wrap:wrap;text-align:left;padding-top:6px}
  body:not(.tables-as-table) .cardable td:not([data-label]):not(:first-child)::before{display:none}
  body:not(.tables-as-table) .cardable td:empty{display:none}
  body:not(.tables-as-table) .cardable td.mspan{display:block;text-align:left}
  body:not(.tables-as-table) .cardable td input,body:not(.tables-as-table) .cardable td select{max-width:60%}
  body:not(.tables-as-table) .cardable td .items{max-width:100%;white-space:normal}
  body:not(.tables-as-table) .cardable tr.mfold:not(.mopen) td.mx{display:none}
  body:not(.tables-as-table) .cardable tr.mfold::after{content:attr(data-more);display:block;margin:6px -13px -9px;padding:8px 13px;border-top:1px dashed var(--line);
    font-size:12.5px;font-weight:600;color:var(--brand);cursor:pointer}
  body:not(.tables-as-table) .cardable tr.mfold.mopen::after{content:"Show fewer ▴"}
  body:not(.tables-as-table) .ttools .mhint{display:none}
  .ttools{flex-wrap:wrap;gap:6px}
  .ttools .tview{display:inline-flex}
  body:not(.tables-as-table) .ttools .msort{display:block;width:auto;min-height:30px;padding:3px 26px 3px 9px;font-size:13px;border-radius:8px}
  .ttools>.muted{margin-right:auto}

  /* dialogs slide up from the bottom */
  .omodal{align-items:flex-end;padding:0}
  .osheet,.osheet.wide{max-width:none;max-height:92dvh;border-radius:20px 20px 0 0;padding:8px 16px calc(20px + env(safe-area-inset-bottom));animation:hdsheet .22s ease-out;
    transition:transform .2s;overscroll-behavior:contain}
  .osheet::before{content:"";display:block;width:42px;height:5px;border-radius:5px;background:var(--line);margin:2px auto 12px}
  .osheet .row.end{position:sticky;bottom:calc(-20px - env(safe-area-inset-bottom));background:var(--surface);padding:10px 0 4px;margin-bottom:-4px}
}
@keyframes hdsheet{from{transform:translateY(40px);opacity:.4}to{transform:none;opacity:1}}
@media (prefers-reduced-motion:reduce){.osheet{animation:none}}
/* the title-bar ☰ only means something when the sidebar is a drawer */
@media (min-width:861px){main .topbar .hamb{display:none}}
