/* ============================================================
   PETROSPECT mobile responsiveness fixes
   ------------------------------------------------------------
   Source of truth lives at public/assets/mobile-fixes.css so it
   survives every `vite build`. dist/assets/mobile-fixes.css is a
   build output — never edit it directly.
   ------------------------------------------------------------
   Rule: Desktop (>= 1024px) MUST render bit-identically to
   before. Every RESPONSIVE override in this file is wrapped in
   a mobile or tablet media query.
   The only unconditional section (section 0 below) is the
   viewport-safe modal rule, which must apply equally on desktop
   and mobile — a tall form must not overflow the viewport at
   ANY screen size.
   ------------------------------------------------------------
   Breakpoints used:
     @media (max-width: 1023px)  → tablet + mobile    (ERP drawer + modals)
     @media (max-width: 768px)   → mobile             (homepage scale)
     @media (max-width: 480px)   → small phones
     @media (max-width: 400px)   → very narrow phones
     @media (min-width: 1024px)  → desktop no-op guards
   ============================================================ */


/* ============================================================
   0) MODAL / DIALOG VIEWPORT SAFETY  (applies at ALL widths)
   ------------------------------------------------------------
   Every dialog in the app is a shadcn <DialogContent>, which
   renders a base-ui Popup carrying data-slot="dialog-content".
   Targeting that attribute guarantees universal coverage — one
   rule, every modal: Add User, Reset Password, Add Employee,
   Add Leave, Permission/Loan/Warning requests, Add Vehicle,
   Add Oil Change, Add Maintenance, Add Attachment, Profile,
   Reset-Data, and any future dialog.
   ------------------------------------------------------------
   Why here (raw CSS, not Tailwind classes on the component)?
   The project ships a pre-compiled Tailwind stylesheet; arbitrary
   values added to source after that build (e.g. max-h-[90dvh],
   overscroll-contain) don't exist in the compiled CSS at runtime,
   so the classes would be silent no-ops. Expressing the rule as
   plain CSS here makes it robust to the build pipeline.
   ============================================================ */

/* ── DEFAULT centering (works today, even with the currently-deployed
   JS bundle that doesn't yet render the wrapper element) ─────────────
   We center the Popup itself via `position: fixed` + a half-its-own-
   size translate offset. This is the pattern that has been in
   production; it covers the gap between "new CSS deployed" and
   "new JS deployed".

   ROOT CAUSE OF "MODAL APPEARS TOO HIGH":
   The OLD dialog.tsx applied Tailwind's `-translate-x-1/2 -translate-y-1/2`
   utilities, which Tailwind v4 compiles into the modern CSS
   `translate:` property:
       translate: var(--tw-translate-x) var(--tw-translate-y);  /* = -50% -50% */
   Modern CSS treats `translate:` and `transform:` as INDEPENDENT
   properties that BOTH apply in sequence. So if a stylesheet adds
   `transform: translate(-50%, -50%) !important` thinking it's
   overriding the Tailwind centering, the browser actually STACKS
   them — the popup ends up translated by its FULL size (not half),
   pinning its top-left corner to the viewport's center and its
   visible body to the upper-left quadrant. That is the "too high"
   symptom.

   THE FIX:
   Set BOTH properties explicitly so neither contributes a stale
   value: `translate: none` neutralises the inherited Tailwind
   utility; `transform: translate(-50%, -50%)` does the actual
   centering. Result: the popup is shifted up-left by exactly half
   its own size, placing its center at viewport center.

   We additionally pin top/left/right/bottom and clear margin to
   make sure no inherited box model property nudges the position. */
[data-slot="dialog-content"] {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  /* Neutralise Tailwind v4's `translate:` utility (see comment above). */
  translate: none !important;
  transform: translate(-50%, -50%) !important;
  margin: 0 !important;

  /* Viewport-safe height cap — dvh handles mobile URL bar correctly,
     vh is the fallback for engines without dvh support. */
  max-height: 90vh !important;
  max-height: 90dvh !important;

  /* Flex column so the inner scroll wrapper owns overflow and the
     close [X] stays pinned as an out-of-flow sibling. overflow:
     hidden clips children to the rounded-xl corners. */
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

/* ── PREFERRED centering: wrapper-based flex (after JS redeploy) ─────
   Once the new dialog.tsx ships (it adds a viewport-filling wrapper
   around the Popup with `data-slot="dialog-content-wrapper"`), we
   prefer flexbox centering on that wrapper. Flexbox centering cannot
   be disturbed by transform animations or inline-style overrides:
   `align-items: center` on the parent positions the child by its
   border-box, period. The descendant selector below has higher
   specificity than the default rule, so it wins automatically once
   the wrapper appears in the DOM — no version coordination needed.

   pointer-events-none on the wrapper lets clicks pass through to the
   DialogOverlay underneath (preserving backdrop-click-to-close); the
   Popup re-enables pointer-events-auto for itself. */
[data-slot="dialog-content-wrapper"] {
  position: fixed !important;
  inset: 0 !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  z-index: 50 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 1rem !important;
  margin: 0 !important;
  pointer-events: none !important;
}
/* When the wrapper IS present, override the popup's fixed/transform
   centering with static positioning so flex centering takes over.
   Higher specificity (descendant of [data-slot="dialog-content-wrapper"])
   means this naturally beats the default rule above. We zero out
   BOTH `translate` and `transform` so no stale offset survives. */
[data-slot="dialog-content-wrapper"] [data-slot="dialog-content"] {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  translate: none !important;
  transform: none !important;
  pointer-events: auto !important;
}

/* The inner scroll wrapper inside every DialogContent. This is the
   element that actually scrolls when a form is long — footer Save/
   Cancel buttons stay reachable via the modal's own scrollbar, the
   close [X] stays visible (it's a sibling, not a descendant, of this
   scroller), and the page behind doesn't scroll on touch. */
[data-slot="dialog-content"] > div:first-child {
  flex: 1 1 auto !important;
  /* Flex items refuse to shrink below their content height by
     default (min-height: auto); without this line the overflow rule
     has nothing to overflow because the wrapper simply expands to
     fit its content and pushes past the 90dvh cap. */
  min-height: 0 !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
}


/* ============================================================
   1) HOMEPAGE  —  mobile scale fixes (<= 768px)
   ============================================================ */

@media (max-width: 768px) {
  /* Prevent any accidental horizontal scroll on the homepage */
  html, body { overflow-x: hidden !important; }

  /* ---- Navbar ---- */
  /* Shrink the big logo on the fixed top nav to ~140px so it stops
     overlapping the menu button on 375px screens. */
  .homepage-root nav svg {
    width: 140px !important;
    height: auto !important;
  }
  .homepage-root nav .max-w-7xl {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* The homepage already ships its own hamburger toggle (React state
     isMenuOpen). Force its visibility on mobile and hide the desktop
     inline nav, in case Tailwind's `lg:hidden` / `lg:flex` utilities
     fail to load. Uses attribute selectors so we don't depend on the
     compiled class names. */
  .homepage-root nav button[class*="lg:hidden"] {
    display: inline-flex !important;
  }
  .homepage-root nav div[class*="hidden"][class*="lg:flex"] {
    display: none !important;
  }

  /* ---- Hero section ---- */
  .homepage-root #home {
    height: auto !important;
    min-height: 100vh !important;
    padding-top: 5rem !important;
    padding-bottom: 3rem !important;
  }
  .homepage-root #home h1 {
    font-size: 2.5rem !important;
    line-height: 0.95 !important;
    margin-bottom: 1.5rem !important;
    letter-spacing: -0.02em !important;
  }
  .homepage-root #home h2 {
    font-size: 1.25rem !important;
    margin-bottom: 0.75rem !important;
  }
  .homepage-root #home h2 + p,
  .homepage-root #home p {
    font-size: 0.95rem !important;
    line-height: 1.5 !important;
  }

  /* Subtitle left-bar block: tighter padding */
  .homepage-root #home .border-l-4,
  .homepage-root #home [class*="border-r-4"] {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    margin-bottom: 2rem !important;
  }

  /* Hero "serving" pill */
  .homepage-root #home .glass.rounded-full {
    padding: 0.375rem 1rem !important;
    margin-bottom: 1.5rem !important;
    font-size: 0.7rem !important;
  }

  /* CTA buttons: full-width stacking with comfortable tap targets */
  .homepage-root #home a[href="#services"],
  .homepage-root #home a[href="#location"],
  .homepage-root #home a[href="#capabilities"] {
    width: 100% !important;
    padding: 1rem 1.25rem !important;
    font-size: 0.7rem !important;
    justify-content: center !important;
  }
  .homepage-root #home .flex-col.sm\:flex-row {
    flex-direction: column !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }

  /* Hero stats row — 3-up compact grid */
  .homepage-root #home .mt-20.grid {
    margin-top: 2rem !important;
    gap: 0.75rem !important;
    padding-top: 1.5rem !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
  .homepage-root #home .mt-20.grid > div > div:first-child {
    font-size: 1rem !important;
    line-height: 1.1 !important;
  }
  .homepage-root #home .mt-20.grid > div > div:last-child {
    font-size: 9px !important;
    line-height: 1.2 !important;
  }

  /* Hide decorative oversized side word on mobile */
  .homepage-root #home .text-\[15rem\] {
    display: none !important;
  }

  /* Section padding */
  .homepage-root #home .max-w-7xl,
  .homepage-root section .max-w-7xl {
    padding-left: 1.25rem !important;
    padding-right: 1.25rem !important;
  }

  /* Vertical rhythm */
  .homepage-root section.py-32 { padding-top: 3rem !important; padding-bottom: 3rem !important; }
  .homepage-root section.py-24 { padding-top: 2.5rem !important; padding-bottom: 2.5rem !important; }
  .homepage-root section.py-12 { padding-top: 1.75rem !important; padding-bottom: 1.75rem !important; }

  /* Oversized base typography caps on mobile */
  .homepage-root .text-8xl { font-size: 2.5rem !important; line-height: 1 !important; }
  .homepage-root .text-7xl { font-size: 2.25rem !important; line-height: 1 !important; }
  .homepage-root .text-6xl { font-size: 2rem !important; line-height: 1.05 !important; }
  .homepage-root .text-5xl { font-size: 1.875rem !important; line-height: 1.1 !important; }
  .homepage-root .text-4xl { font-size: 1.75rem !important; }
  .homepage-root .text-3xl { font-size: 1.5rem !important; }
  .homepage-root .text-2xl { font-size: 1.25rem !important; }

  /* Section headers cap */
  .homepage-root section h2,
  .homepage-root section .tracking-tighter.font-black {
    font-size: 1.75rem !important;
    line-height: 1.1 !important;
  }

  /* Collapse multi-col grids to single column unless 2-col was explicit */
  .homepage-root .grid.md\:grid-cols-2,
  .homepage-root .grid.md\:grid-cols-3,
  .homepage-root .grid.md\:grid-cols-4,
  .homepage-root .grid.lg\:grid-cols-2,
  .homepage-root .grid.lg\:grid-cols-3,
  .homepage-root .grid.lg\:grid-cols-4 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* About section */
  .homepage-root #about .aspect-\[4\/5\] { aspect-ratio: 4 / 3 !important; }
  .homepage-root #about .gap-20 { gap: 2rem !important; }
  .homepage-root #about .gap-16 { gap: 1.5rem !important; }
  .homepage-root #about .mb-16 { margin-bottom: 2rem !important; }

  /* Cards polish */
  .homepage-root #services .p-10,
  .homepage-root #process .p-10,
  .homepage-root #projects .p-10 { padding: 1.5rem !important; }
  .homepage-root #services .rounded-\[3rem\],
  .homepage-root #process .rounded-\[3rem\],
  .homepage-root #projects .rounded-\[3rem\] { border-radius: 1.5rem !important; }
  .homepage-root #location .p-10,
  .homepage-root #location .lg\:p-16,
  .homepage-root #location .p-16 { padding: 1.5rem !important; }
  .homepage-root #location .rounded-\[4rem\] { border-radius: 1.5rem !important; }

  /* Contain images */
  .homepage-root img { max-width: 100% !important; height: auto !important; }

  /* Footer */
  .homepage-root footer.pt-32 { padding-top: 3rem !important; }
  .homepage-root footer.pb-16 { padding-bottom: 2.5rem !important; }
  .homepage-root footer .mb-24 { margin-bottom: 2rem !important; }
  .homepage-root footer .gap-20 { gap: 2rem !important; }
  .homepage-root footer .mt-12 { margin-top: 2rem !important; }

  /* Generic gap/margin caps */
  .homepage-root .gap-20 { gap: 1.5rem !important; }
  .homepage-root .gap-16 { gap: 1.25rem !important; }
  .homepage-root .gap-12 { gap: 1rem !important; }
  .homepage-root .mt-24 { margin-top: 2rem !important; }
  .homepage-root .mt-20 { margin-top: 1.75rem !important; }
  .homepage-root .mt-16 { margin-top: 1.5rem !important; }
  .homepage-root .mb-24 { margin-bottom: 2rem !important; }
  .homepage-root .mb-20 { margin-bottom: 1.75rem !important; }
  .homepage-root .mb-16 { margin-bottom: 1.5rem !important; }
}

/* Small phones (<= 480px) */
@media (max-width: 480px) {
  .homepage-root #home .mt-20.grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }
  .homepage-root #home .mt-20.grid > div > div:first-child {
    font-size: 0.875rem !important;
  }
}

/* Very narrow phones (<= 400px) */
@media (max-width: 400px) {
  .homepage-root #home h1 { font-size: 2rem !important; }
  .homepage-root #home h2 { font-size: 1.1rem !important; }
  .homepage-root #home h2 + p { font-size: 0.875rem !important; }
  .homepage-root nav svg { width: 120px !important; }
  .homepage-root #home a[href="#services"],
  .homepage-root #home a[href="#location"],
  .homepage-root #home a[href="#capabilities"] {
    padding: 0.875rem 1.25rem !important;
    font-size: 0.65rem !important;
  }
}


/* ============================================================
   2) ERP PORTAL  —  collapsible sidebar drawer (<= 1023px)
   ============================================================ */

@media (max-width: 1023px) {
  .erp-sidebar {
    position: fixed !important;
    inset-inline-start: 0 !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 16rem !important;
    min-width: 16rem !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 60 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s ease-in-out !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35) !important;
  }
  [dir="rtl"] .erp-sidebar {
    inset-inline-start: auto !important;
    left: auto !important;
    right: 0 !important;
    transform: translateX(100%) !important;
  }
  .erp-sidebar[data-mobile-open="true"] {
    transform: translateX(0) !important;
  }

  .erp-sidebar-backdrop {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(15, 23, 42, 0.55) !important;
    backdrop-filter: blur(2px) !important;
    z-index: 55 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-in-out;
  }
  .erp-sidebar-backdrop[data-open="true"] {
    opacity: 1;
    pointer-events: auto;
  }

  .erp-mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.625rem;
    color: #475569;
    background: transparent;
    margin-inline-end: 0.5rem;
    flex-shrink: 0;
    border: none;
    cursor: pointer;
  }
  .erp-mobile-menu-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
  }

  /* Header tighter padding */
  .erp-portal header.sticky,
  .erp-portal header {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  .erp-portal header .relative.w-full.max-w-md {
    max-width: 100% !important;
  }

  /* Main content full-width + padding */
  .erp-portal main.overflow-y-auto { padding: 1rem !important; }
  .erp-portal main .max-w-7xl { max-width: 100% !important; }

  /* Card padding caps */
  .erp-portal main .p-6 { padding: 1rem !important; }
  .erp-portal main .p-8 { padding: 1rem !important; }
  .erp-portal main .p-10 { padding: 1.25rem !important; }

  /* Gap caps */
  .erp-portal main .gap-8 { gap: 0.75rem !important; }
  .erp-portal main .gap-6 { gap: 0.75rem !important; }

  /* Collapse dashboard multi-col grids */
  .erp-portal main .grid.md\:grid-cols-2,
  .erp-portal main .grid.md\:grid-cols-3,
  .erp-portal main .grid.md\:grid-cols-4,
  .erp-portal main .grid.lg\:grid-cols-2,
  .erp-portal main .grid.lg\:grid-cols-3,
  .erp-portal main .grid.lg\:grid-cols-4,
  .erp-portal main .grid.xl\:grid-cols-4 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Tables scroll horizontally */
  .erp-portal main table {
    display: block !important;
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch !important;
    white-space: nowrap !important;
  }
  .erp-portal main table thead,
  .erp-portal main table tbody,
  .erp-portal main table tr {
    display: table !important;
    width: 100% !important;
    table-layout: auto !important;
  }

  /* Modals & dialogs: width cap on mobile.
     (Max-height / overflow-y are set globally on DialogContent itself —
     see components/ui/dialog.tsx — so they apply on desktop too. Only the
     width override belongs here, to undo shadcn's sm:max-w-sm on phones.) */
  [role="dialog"] {
    max-width: calc(100vw - 1.5rem) !important;
    width: calc(100vw - 1.5rem) !important;
  }

  /* Form inputs full-width on mobile */
  .erp-portal main form input:not([type="checkbox"]):not([type="radio"]),
  .erp-portal main form select,
  .erp-portal main form textarea {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Oversized card number caps */
  .erp-portal main .text-4xl { font-size: 1.75rem !important; }
  .erp-portal main .text-5xl { font-size: 2rem !important; }
  .erp-portal main .text-3xl { font-size: 1.5rem !important; }

  /* Hide search ⌘K shortcut */
  .erp-portal header .text-\[10px\] { display: none !important; }
  /* Hide user name/role block to save space */
  .erp-portal header [class*="hidden"][class*="md:flex"] { display: none !important; }

  /* Force-reveal drawer labels */
  .erp-sidebar .flex-1 span,
  .erp-sidebar nav span,
  .erp-sidebar button span {
    display: inline !important;
  }
}

/* Phone-only (<= 640px): extra ERP density */
@media (max-width: 640px) {
  .erp-portal header .gap-3 { gap: 0.5rem !important; }
  .erp-portal header .gap-4 { gap: 0.5rem !important; }
  .erp-portal header .mr-2 { margin-right: 0.25rem !important; }
}

/* Desktop (>= 1024px): desktop identity guarantee.
   ------------------------------------------------------------
   We ONLY hide the two mobile-only DOM nodes (the drawer backdrop and the
   hamburger button) that PortalApp/Header render unconditionally. We do
   NOT override anything on .erp-sidebar here — the mobile rules above are
   already wrapped in `max-width: 1023px`, so they never reach desktop.
   Re-asserting `position: relative`, `min-width: 0`, `z-index: auto`,
   `box-shadow: none`, etc. with `!important` was changing the sidebar's
   stacking / positioning context on desktop and caused the regression. */
@media (min-width: 1024px) {
  .erp-sidebar-backdrop { display: none !important; }
  .erp-mobile-menu-btn  { display: none !important; }
}
