/* ------------------------------------------------------------------
   Mobile / PWA layer. Everything here is additive: the desktop layout
   above is untouched at >=760px, and the tab bar only exists on phones.
   ------------------------------------------------------------------ */
.tabbar { display: none; }

@media (max-width: 759px) {
  body {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  /* header: brand row, then a wrapping nav that scrolls sideways */
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px 8px;
    position: sticky; top: 0; z-index: 20;
  }
  .brand { font-size: 15px; }
  .brand .tag { display: none; }
  .brandrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .badges { display: flex; gap: 6px; flex: 0 0 auto; }
  .badges .modelbadge { font-size: 11px; padding: 3px 8px; }
  nav {
    display: flex; flex-wrap: nowrap; gap: 8px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px; scrollbar-width: none;
  }
  nav::-webkit-scrollbar { display: none; }
  nav a, nav .modelbadge, nav button {
    flex: 0 0 auto; white-space: nowrap;
    min-height: 36px; display: inline-flex; align-items: center;
  }
  nav a {
    background: #21262d; border: 1px solid var(--line);
    border-radius: 18px; padding: 0 14px; font-size: 13px;
  }
  nav button { padding: 0 14px; }

  main { padding: 12px 12px 4px; }
  h1 { font-size: 18px; }
  h2 { font-size: 15px; margin-top: 22px; }

  /* cards go single-column and get real tap height */
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .card { padding: 14px 16px; }
  .kv { padding: 5px 0; }
  .kvgrid { grid-template-columns: 1fr; gap: 0; }

  /* wide tables scroll instead of crushing columns */
  /* rosters keep nowrap+scroll (numbers stay aligned); prose tables wrap */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .feed, .incidents { white-space: normal; }
  /* incidents: drop hits/last-seen/status on phones so the title has the width */
  .incidents th:nth-child(n+4), .incidents td:nth-child(n+4) { display: none; }
  .incidents td:nth-child(3) { word-break: break-word; }
  th, td { padding: 8px 10px; }

  /* forms stack, controls get thumb-sized */
  .modeform, .modelform { flex-direction: column; align-items: stretch; gap: 10px; }
  select { min-width: 0; width: 100%; min-height: 44px; font-size: 16px; }
  button { min-height: 44px; font-size: 15px; padding: 10px 16px; }
  .confirmbox { min-height: 44px; }

  /* fleet: one box per screen-width, numbers big enough to read at arm's length */
  .fleetgrid { grid-template-columns: 1fr; gap: 12px; }
  .fleetcard { padding: 14px; }
  .fleetcard .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .fleetcard .stat { padding: 10px 12px; }
  .fleetcard .stat span { font-size: .72rem; }
  .fleetcard .stat b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
  .provs { display: table; font-size: .85rem; }

  .raw, .detail, .triage { font-size: 12px; }
  footer { padding: 14px 12px 8px; }

  /* fixed bottom tab bar, thumb reach, safe-area aware */
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(22, 27, 34, .96);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 0 10px; font-size: 11px; color: var(--muted);
    min-height: 56px;
  }
  .tabbar a span { font-size: 17px; line-height: 1; }
  .tabbar a.on { color: var(--accent); }

  /* collapsible sections: summary is the tap target, h2 inside it */
  details.sec > summary { list-style: none; display: flex; align-items: center; gap: 8px;
    min-height: 44px; color: var(--text); }
  details.sec > summary::-webkit-details-marker { display: none; }
  details.sec > summary::after { content: BE; margin-left: auto; color: var(--muted); }
  details.sec:not([open]) > summary::after { content: B8; }
  details.sec > summary h2 { margin: 0; }
}

@media (display-mode: standalone) {
  /* installed: the header is the only chrome, so pin it to the notch */
  header { padding-top: calc(10px + env(safe-area-inset-top)); }
}
