/* ══════════════════════════════════════════════════════════════════════
   CollabHub — Responsive / Mobile layer
   ----------------------------------------------------------------------
   Hand-authored plain CSS, loaded AFTER tailwind.css (survives rebuilds).
   Targets: iPhone 17 / 16 / Pro Max / SE · Android flagship + small · iPad
            & Android tablets · both portrait & landscape.

   Strategy
     • < 1024px  → off-canvas drawer sidebar + hamburger (phones & tablet portrait)
     • >= 1024px → original fixed sidebar untouched (desktop / tablet landscape)
     • Touch targets >= 44px · notch / dynamic-island safe-area · fluid spacing
     • Tables keep their columns and scroll horizontally (auto-wrapped in JS)
   ══════════════════════════════════════════════════════════════════════ */

/* Use dynamic viewport height so the iOS/Android URL bar can't clip the shell */
.ch-shell { height: 100vh; height: 100dvh; }

/* Chrome hooks hidden on desktop */
#ch-hamburger,
#ch-mobile-scrim { display: none; }

/* ──────────────────────────────────────────────────────────────────────
   PHONES + TABLET PORTRAIT  (< 1024px) — drawer navigation
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {

  /* — Hamburger in the topbar — */
  #ch-hamburger {
    display: grid; place-items: center;
    width: 42px; height: 42px; margin-left: -6px; margin-right: 2px;
    border: 0; border-radius: 0.625rem; cursor: pointer;
    background: transparent; color: var(--ch-text-2);
    transition: background-color .15s;
  }
  #ch-hamburger:hover { background: var(--ch-surface-3); }
  #ch-hamburger:active { background: var(--ch-surface-3); }

  /* — Sidebar becomes an off-canvas drawer — */
  #ch-sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; height: 100dvh;
    width: 284px !important;
    max-width: 86vw;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.16, 1, .3, 1);
    will-change: transform;
    box-shadow: 6px 0 32px rgba(0, 0, 0, .28);
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
  }
  html[data-mobile-nav="open"] #ch-sidebar { transform: translateX(0); }

  /* Force the expanded look while it is a drawer, even if the user left the
     desktop sidebar collapsed (data-state="collapsed"). */
  #ch-sidebar[data-state="collapsed"] { width: 284px !important; }
  #ch-sidebar[data-state="collapsed"] .sb-text,
  #ch-sidebar[data-state="collapsed"] .sb-badge,
  #ch-sidebar[data-state="collapsed"] .sb-section,
  #ch-sidebar[data-state="collapsed"] .sb-sub,
  #ch-sidebar[data-state="collapsed"] .sb-search,
  #ch-sidebar[data-state="collapsed"] .sb-foot { display: revert; opacity: 1; }
  #ch-sidebar[data-state="collapsed"] .sb-search-collapsed { display: none; }
  #ch-sidebar[data-state="collapsed"] .sb-header { justify-content: space-between; }
  #ch-sidebar[data-state="collapsed"] .nav-link,
  #ch-sidebar[data-state="collapsed"] .sb-item { justify-content: flex-start; }

  /* Bigger touch targets inside the drawer nav (>= 44px) */
  #ch-sidebar .nav-link { padding-top: 0.6rem; padding-bottom: 0.6rem; }
  #ch-sidebar .nav-sub  { padding-top: 0.55rem; padding-bottom: 0.55rem; }

  /* — Scrim behind the drawer — */
  #ch-mobile-scrim {
    display: block; position: fixed; inset: 0; z-index: 70;
    background: rgba(0, 0, 0, .45);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none;
    transition: opacity .28s ease;
  }
  html[data-mobile-nav="open"] #ch-mobile-scrim { opacity: 1; pointer-events: auto; }
  html[data-mobile-nav="open"] body { overflow: hidden; }

  /* — Topbar: tighten + respect side safe-areas — */
  header.ch-topbar {
    padding-left: max(0.875rem, env(safe-area-inset-left)) !important;
    padding-right: max(0.875rem, env(safe-area-inset-right)) !important;
    gap: 0.25rem;
  }
  /* Hide the long search pill on small screens (cmd-K still on hamburger-adjacent) */
  header.ch-topbar .ch-topbar-search { display: none !important; }
  /* Topbar controls: comfortable hit area */
  header.ch-topbar button,
  header.ch-topbar a,
  header.ch-topbar select { min-height: 40px; }

  /* — Main content: fluid padding + safe-area + bottom breathing room — */
  main.ch-main {
    padding-left: max(0.9rem, env(safe-area-inset-left));
    padding-right: max(0.9rem, env(safe-area-inset-right));
    padding-top: 1.1rem;
    padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* — Tables keep columns + scroll horizontally (wrapper added by JS) — */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll > table { min-width: max-content; }
  /* Force single-line cells so the table grows and scrolls instead of the
     rows getting tall — except cells that already self-limit their width. */
  .table-scroll .data-table td,
  .table-scroll .data-table th { white-space: nowrap; }
  .table-scroll .data-table .truncate,
  .table-scroll .data-table .line-clamp-2,
  .table-scroll .data-table .refjob,
  .table-scroll .data-table .whitespace-normal { white-space: normal; }

  /* Modals already go full-screen < 640px (see input.css #6); make sure the
     tablet range (641–1023) keeps them comfortably inset. */
  #modal-panel { max-width: min(92vw, 640px); }

  /* Page section headers wrap their action buttons gracefully */
  main.ch-main .flex.justify-between.items-start.flex-wrap > .flex { row-gap: 0.5rem; }
}

/* ──────────────────────────────────────────────────────────────────────
   SMALL PHONES  (<= 430px)  — iPhone Pro Max down to 360px Android
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 430px) {
  main.ch-main {
    padding-left: max(0.8rem, env(safe-area-inset-left));
    padding-right: max(0.8rem, env(safe-area-inset-right));
  }
  /* KPI / stat grids: 2-up stays readable; oversized hero numbers trimmed */
  main.ch-main .text-\[26px\] { font-size: 22px; }
  /* Action-button rows in page headers: let primary buttons fill the row */
  main.ch-main header .btn,
  main.ch-main .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  /* Charts that are fixed-height shrink a touch on tiny screens */
  #ch-pipeline { height: 150px !important; }
}

/* ──────────────────────────────────────────────────────────────────────
   VERY SMALL  (<= 360px)  — compact Android / iPhone SE
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 360px) {
  /* Force single-column for 2-up KPI grids that would crowd at 320–360px */
  main.ch-main .grid.grid-cols-2:not(.keep-2col) { grid-template-columns: 1fr; }
}

/* ──────────────────────────────────────────────────────────────────────
   AUTH PAGES (login / force-password) — hero hides, form centers
   The templates already use lg:grid-cols-2 + hidden lg:flex, so nothing to
   override; we only guarantee the form panel can scroll on short landscapes.
   ────────────────────────────────────────────────────────────────────── */
@media (max-height: 560px) and (max-width: 1023px) {
  .ch-auth-scroll { overflow-y: auto; }
}

/* ──────────────────────────────────────────────────────────────────────
   Restore desktop drawer transition cleanup (>=1024) — make sure no stray
   transform lingers if the viewport grows past the breakpoint.
   ────────────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
  #ch-sidebar { transform: none !important; }
}
