/* ============================================================================================================
   ForesightDM — PHONE LAYOUT (owner 2026-11-17, signed off from the mock-up "FDM Mobile Mock-up").
   EVERYTHING here is inside one `max-width: 767px` block: from 768 px up (desktop, tablets, and a phone's
   "Desktop site" mode) this file changes nothing. Fonts and colours are the app's own (styles.css / Tailwind);
   this file only changes SPACE: the side bar becomes a ☰ menu, content takes the full width, drawers open
   full-screen, the device table stacks, and any other wide table scrolls sideways inside its box.
   Hooks it relies on: index.html (#fdm-topbar, #fdm-nav-backdrop, #fdm-nav-close, html.fdm-nav-open) and the
   board's row classes (telemetry.js: tr.fdm-dev, td.fdm-c-dot / -name / -serial / -time; table.fdm-board).
   ============================================================================================================ */
@media (max-width: 767px) {

  /* ---------- Shell: side bar → slide-in menu ---------- */
  #sidebar {
    width: 17rem !important;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 70;
  }
  html.fdm-nav-open #sidebar { transform: translateX(0); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
  /* the menu names normally appear only on mouse hover — a phone has none, so they always show in the menu */
  #dynamic-sidebar .opacity-0 { opacity: 1 !important; }
  #dynamic-sidebar button { min-height: 48px; }
  html.fdm-nav-open #fdm-nav-close { display: flex; }
  #fdm-nav-backdrop { display: none; position: fixed; inset: 0; z-index: 65; background: rgba(2, 6, 23, 0.6); }
  html.fdm-nav-open #fdm-nav-backdrop { display: block; }
  html.fdm-nav-open body { overflow: hidden; }

  /* ---------- Content: full width, tighter edges ---------- */
  #content-area .p-8 { padding: 1rem; }
  #content-area .p-6 { padding: 1rem; }
  #content-area .mb-12 { margin-bottom: 1.5rem; }
  #content-area .mb-8 { margin-bottom: 1.25rem; }
  #content-area h2.text-3xl, #content-area h1.text-3xl { font-size: 1.5rem; line-height: 2rem; }
  #content-area h2.text-2xl, #content-area h1.text-2xl { font-size: 1.25rem; line-height: 1.75rem; }
  /* phones zoom into any field under 16 px when it is tapped (iOS); 16 px stops the jump */
  input, select, textarea { font-size: 16px !important; }

  /* ---------- Drawers and the settings panel: full screen ---------- */
  #drawer, #settings-drawer, #starlink-drawer, #site-drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    border-left: 0 !important;
  }
  #drawer .p-6, #settings-drawer .p-6, #starlink-drawer .p-6 { padding: 1rem; }
  /* the device drawer's Mute / Delete bar stays at the bottom of the screen while the drawer scrolls */
  #drawer > div:last-child { position: sticky; bottom: 0; z-index: 5; }
  /* close (×) buttons get a thumb-sized target */
  #drawer > div:first-child > button, #settings-drawer > div:first-child > button,
  #starlink-drawer > div:first-child > button, #site-drawer [data-close] {
    min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  }
  #site-drawer-body { padding: 0.75rem; }
  /* site view path: one column, full-width boxes, arrows point down (was a wrapped row whose arrows pointed at nothing) */
  #site-drawer .fdm-chain { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  #site-drawer .fdm-chain > div { max-width: none; width: 100%; }
  #site-drawer .fdm-arrow { transform: rotate(90deg); align-self: center; line-height: 1; padding: 2px 0; }
  /* site map: drawn at full size (readable) and swiped sideways when it has several rooms, instead of shrunk */
  #site-drawer .fdm-map-svg { width: var(--map-w) !important; max-width: none !important; }

  /* ---------- Pop-up windows (modals): never wider or taller than the screen ---------- */
  .fixed.inset-0 > div { max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto; }
  .fixed.inset-0 > div[class*="w-["] { width: calc(100vw - 16px) !important; }

  /* ---------- Any other wide table: scrolls sideways inside its own box instead of being cut off ---------- */
  #content-area table:not(.fdm-board),
  #drawer table, #site-drawer table, #starlink-drawer table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #content-area .overflow-hidden:has(> table:not(.fdm-board)) { overflow-x: auto; }
  /* (Calendars such as the Master Schedule keep their minimum width on purpose — their box already scrolls
     sideways; squeezing them made the event names unreadable. Verified 2026-11-17.) */

  /* ---------- Tab bars (Audits & Compliance, etc.): one line that scrolls sideways, labels never squeezed ---------- */
  #content-area .flex:has(> button.border-b-2) {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  #content-area .flex:has(> button.border-b-2)::-webkit-scrollbar { display: none; }
  #content-area .flex:has(> button.border-b-2) > button { flex-shrink: 0; white-space: nowrap; }

  /* ---------- Home: module tiles two across ---------- */
  .hub-category [data-sortable-container] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 0.625rem !important; }
  .hub-category [data-sortable-container] > div { padding: 0.875rem !important; border-radius: 0.875rem; }
  .hub-category [data-sortable-container] > div > div:first-child { font-size: 1.5rem; margin-bottom: 0.5rem; }
  .hub-category [data-sortable-container] > div h3 { font-size: 0.95rem; margin-bottom: 0.25rem; }
  .hub-category [data-sortable-container] > div p {
    font-size: 0.75rem; line-height: 1.1rem;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  }
  .hub-category h3 { margin-bottom: 0.75rem !important; }
  .space-y-10 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.5rem; }

  /* ---------- Telemetry board ---------- */
  .fdm-board-head { flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
  [id^="stat-"][id$="-container"] { padding: 0.625rem 0.75rem; }
  [id^="stat-"][id$="-container"] > p:first-child { font-size: 11px; letter-spacing: 0.04em; }
  [id^="stat-"][id$="-text"] { font-size: 1.15rem; }
  table.fdm-board thead { display: none; }
  table.fdm-board, table.fdm-board tbody, table.fdm-board tr, table.fdm-board td { display: block; width: 100%; box-sizing: border-box; }
  table.fdm-board td[colspan] { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
  table.fdm-board tr.fdm-dev {
    display: grid; grid-template-columns: 26px minmax(0, 1fr);
    padding: 0.625rem 0.75rem; column-gap: 0.25rem;
  }
  table.fdm-board tr.fdm-dev > td { padding: 0 !important; width: auto; }
  tr.fdm-dev > td.fdm-c-dot { grid-row: 1 / span 2; padding-top: 0.25rem !important; }
  tr.fdm-dev > td.fdm-c-name { flex-wrap: wrap; row-gap: 0.25rem; font-size: 0.875rem; line-height: 1.25rem; }
  tr.fdm-dev > td.fdm-c-serial { display: none; }
  /* pills (modem status, cable, rogue, scan…) wrap instead of running off the edge */
  tr.fdm-dev > td.fdm-c-name span { white-space: normal !important; overflow-wrap: anywhere; max-width: 100%; }
  /* the site's status strip: tiles first, "Site view ›" wraps below when there is no room */
  table.fdm-board td[colspan] > div > div.flex { flex-wrap: wrap; row-gap: 0.5rem; }
  tr.fdm-dev > td.fdm-c-time { font-size: 0.75rem; margin-top: 0.25rem; }
}

/* very narrow phones (≤ 360 px): one module tile per row */
@media (max-width: 360px) {
  .hub-category [data-sortable-container] { grid-template-columns: minmax(0, 1fr) !important; }
}
