/* Dashboard on phones. Loaded after the page's own styles. Desktop is untouched:
   everything here sits inside max-width media queries. */

@media (max-width:820px){
  /* Nothing may push the page sideways. `clip` (not hidden) keeps sticky headers working. */
  html,body{overflow-x:clip}
  .main,.page{min-width:0;max-width:100vw}

  /* Bigger tap targets, and 16px inputs so iPhones don't zoom in on focus. */
  .btn{min-height:38px}
  .btn.sm{min-height:34px}
  input,select,textarea{font-size:16px!important}

  /* Segmented toggles and tab rows scroll instead of overflowing the page. */
  .seg{display:flex;max-width:100%;overflow-x:auto;scrollbar-width:none}
  .seg::-webkit-scrollbar{display:none}
  .seg button{flex:0 0 auto;height:32px}

  /* Highlighted chat words wrap instead of running off the edge. */
  mark{word-break:break-word;overflow-wrap:anywhere}

  /* "Needs your attention" cards: buttons in a tidy grid, dismiss in the corner. */
  .attn{position:relative;padding-right:44px}
  .attn .acts{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;width:100%}
  .attn .acts .btn{width:100%;justify-content:center}
  .attn .acts .btn.primary{grid-column:1/-1}
  .attn .acts [data-dismiss]{position:absolute;top:10px;right:8px;width:34px;min-height:34px;padding:0}

  /* Room for the bottom tab bar. */
  .page{padding-bottom:calc(84px + env(safe-area-inset-bottom))}

  /* Tour tooltip sits at the bottom on phones so it never covers the top bar. */
  .tour-tip{left:12px!important;right:12px!important;top:auto!important;
    bottom:calc(76px + env(safe-area-inset-bottom))!important;width:auto}
}

@media (max-width:640px){
  /* Tables become stacked cards: one card per row, each cell labelled from its column header
     (dashboard-mobile.js copies the header text into data-label). */
  .main table.m-cards,.main table.m-cards tbody,.main table.m-cards tr,.main table.m-cards td{display:block;width:100%}
  .main table.m-cards thead{display:none}
  .main table.m-cards tr{border:1px solid var(--line);border-radius:12px;background:var(--surface);
    padding:10px 12px;margin:0 0 10px}
  .main table.m-cards td{display:flex;justify-content:space-between;align-items:center;gap:12px;
    border:0!important;padding:5px 0!important;text-align:right;min-width:0}
  .main table.m-cards td::before{content:attr(data-label);color:var(--muted);font-size:12px;
    font-weight:600;text-align:left;flex:0 0 auto;max-width:45%}
  .main table.m-cards td:first-child{justify-content:flex-start;text-align:left;font-weight:600;
    font-size:14px;padding-bottom:8px!important;margin-bottom:4px;border-bottom:1px solid var(--line)!important}
  .main table.m-cards td:first-child::before{display:none}
  .main table.m-cards td:empty{display:none}
  .main table.m-cards td>*{min-width:0;overflow-wrap:anywhere}
  /* The wrapper that used to scroll sideways no longer needs to. */
  .main .m-cards-wrap{overflow-x:visible!important}
}

/* Bottom tab bar (phones only). Built by dashboard-mobile.js from the real nav. */
.m-tabbar{display:none}
@media (max-width:820px){
  .m-tabbar{display:flex;position:fixed;left:0;right:0;bottom:0;z-index:40;
    background:color-mix(in srgb,var(--surface) 94%,transparent);
    -webkit-backdrop-filter:blur(14px);backdrop-filter:blur(14px);
    border-top:1px solid var(--line);padding:6px 6px calc(6px + env(safe-area-inset-bottom))}
  .m-tabbar button{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;
    background:none;border:0;color:var(--muted);font-size:11px;font-weight:600;padding:6px 0;
    border-radius:10px;min-height:48px;position:relative}
  .m-tabbar button svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:2}
  .m-tabbar button[aria-current="page"]{color:var(--accent,var(--green))}
  .m-tabbar .m-badge{position:absolute;top:2px;left:calc(50% + 6px);min-width:16px;height:16px;
    border-radius:8px;background:var(--red,#ff4d5e);color:#fff;font-size:10px;line-height:16px;padding:0 4px}
  body:has(.app.nav-open) .m-tabbar{display:none}
}
