/*
  responsive.css - mobile and tablet layout for the whole application.

  Loaded last in mybase.html so it wins over custom.css and side_menu.css on
  equal specificity. Everything here is scoped to a breakpoint, so the desktop
  layout is untouched above 1024px.

  Two problems drive this file:
    1. The left flyout rail (side_menu.css) opens its panels on :hover /
       :focus-within only. A touch screen has no hover, so on a phone or tablet
       every module's sub-menu was unreachable. Below 1024px (and on any
       coarse-pointer device) the rail becomes a slide-in drawer and the panels
       become a tap accordion, driven by responsive.js.
    2. The application's report tables set fixed pixel widths for print and
       overflowed the viewport. responsive.js wraps each table in
       .vg-table-scroll, which scrolls the table instead of the page.
*/

/* ------------------------------------------------------------------ base -- */
html {
  -webkit-text-size-adjust: 100%;
}

img,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

/* The FAB navbar is static; a long report scrolls it away. The menu button
   below is fixed, so navigation stays one tap away. */
.navbar .navbar-brand {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------- scrollable table zone -- */
.vg-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* A table inside a scroll zone keeps its natural width and scrolls, rather
   than squashing its columns into unreadable vertical text. */
.vg-table-scroll > table {
  margin-bottom: 0;
}

@media print {
  .vg-table-scroll {
    overflow: visible !important;
    max-width: none !important;
  }
}

/* --------------------------------------------------------- menu button ---- */
.glfm-menu-toggle {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 2100;
  display: none;
  align-items: center;
  gap: 8px;
  min-width: 44px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: #ffffff;
  background: #111827;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.28);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
}

.glfm-menu-toggle:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.glfm-menu-toggle-bars {
  font-size: 1.1rem;
  line-height: 1;
}

.glfm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1999;
  display: none;
  background: rgba(15, 23, 42, 0.45);
  -webkit-tap-highlight-color: transparent;
}

body.glfm-nav-open .glfm-backdrop {
  display: block;
}

/* Lock the page behind the open drawer. */
body.glfm-nav-open {
  overflow: hidden;
}

@media print {
  .glfm-menu-toggle,
  .glfm-backdrop {
    display: none !important;
  }
}

/* ------------------------------------------------------- phone / tablet --- */
@media (max-width: 1024px) {
  /* The rail becomes a slide-in drawer instead of a fixed column that eats
     most of the screen. */
  body .glfm-shell {
    position: fixed;
    top: 0;
    right: auto;
    bottom: 0;
    left: 0;
    width: min(86vw, 340px);
    max-width: 340px;
    margin: 0;
    z-index: 2000;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 220ms ease, visibility 220ms ease;
    will-change: transform;
  }

  body.glfm-nav-open .glfm-shell {
    transform: translateX(0);
    visibility: visible;
  }

  body .glfm-shell .glfm-rail {
    width: 100%;
    max-height: 100%;
    min-height: 100%;
    padding: 12px 12px 24px;
    border-radius: 0 18px 18px 0;
    box-shadow: 16px 0 40px rgba(15, 23, 42, 0.32);
  }

  /* Touch targets: every rail and panel row is comfortably tappable. */
  body .glfm-shell .glfm-rail-link,
  body .glfm-shell .glfm-panel-link {
    min-height: 48px;
  }

  /* Panels are a tap accordion on touch - no hover anywhere below this
     breakpoint. These rules also neutralise side_menu.css's own
     :hover / :focus-within panel rules, which are useless on a phone.

     The :not(.glfm-tap-open) guard is what makes the accordion work at all. A
     touch tap leaves the trigger hovered (Chrome's sticky hover) and focused,
     and these four selectors carry one class more than the reveal rule below
     (four vs three), so without the guard they out-specified it and the panel
     stayed shut however many times it was tapped: the class went on, the
     sub-menu never appeared. */
  body .glfm-shell .glfm-rail-item:not(.glfm-tap-open):hover > .glfm-panel,
  body .glfm-shell .glfm-rail-item:not(.glfm-tap-open):focus-within > .glfm-panel,
  body .glfm-shell .glfm-panel-item:not(.glfm-tap-open):hover > .glfm-panel,
  body .glfm-shell .glfm-panel-item:not(.glfm-tap-open):focus-within > .glfm-panel {
    display: none;
  }

  body .glfm-shell .glfm-panel {
    position: static;
    top: auto;
    left: auto;
    width: 100%;
    min-height: 0;
    max-height: none;
    margin: 6px 0 6px 8px;
    padding: 10px;
    border-radius: 14px;
    opacity: 1;
    visibility: visible;
    overflow: visible;
    box-shadow: none;
    pointer-events: auto;
    transition: none;
  }

  body .glfm-shell .glfm-panel:not(.glfm-sub-panel) {
    display: none;
  }

  body .glfm-shell .glfm-sub-panel {
    display: none;
    margin-left: 8px;
  }

  body .glfm-shell li.glfm-tap-open > .glfm-panel {
    display: block;
  }

  /* Chevron turns to point down while a panel is expanded. */
  body .glfm-shell .glfm-rail-item.glfm-tap-open > .glfm-rail-link .glfm-rail-chevron,
  body .glfm-shell .glfm-panel-item.glfm-tap-open > .glfm-panel-link .glfm-panel-chevron {
    transform: rotate(90deg);
  }

  body .glfm-shell .glfm-rail-chevron,
  body .glfm-shell .glfm-panel-chevron {
    transition: transform 160ms ease;
  }

  /* The menu button is shown, and the navbar keeps clear of it. Measured: the
     button ends at x=81 with its label (x=52 icon-only), so the navbar gutter
     has to be wider than that or the brand's first letter sits under it. */
  .glfm-menu-toggle {
    display: inline-flex;
  }

  .navbar > .container,
  .navbar > .container-fluid {
    padding-left: 96px;
  }

  .navbar .navbar-brand {
    max-width: 100%;
  }

  /* Reports and screens: use the width we have. */
  .container,
  .container-fluid {
    max-width: 100%;
    padding-left: 10px;
    padding-right: 10px;
  }

  /* Bootstrap's .row pulls -15px to cancel the container gutter. With the
     gutter narrowed above, that pull would push content 5px past the screen
     edge (measured on the inventory transaction journal: barLeft -5).
     Cancel it so the content sits exactly on the gutter. */
  .container > .row,
  .container-fluid > .row {
    margin-left: 0;
    margin-right: 0;
  }

  /* The shared report action bar wraps instead of running off the edge. */
  .report-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .report-actions > .text-muted {
    flex: 1 1 100%;
    margin-left: 0 !important;
  }

  .report-actions .btn {
    min-height: 40px;
  }

  .report-actions .form-inline {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .report-actions .form-inline .form-control {
    width: 100%;
    min-width: 0 !important;
  }

  /* Standard report header meta runs as a list rather than one long line. */
  .standard-report-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
  }

  /* FAB list/form controls: no control wider than the screen. */
  .form-control,
  .select2-container,
  .select2-container--default {
    max-width: 100%;
  }

  .filters .form-group,
  .well .form-group {
    margin-bottom: 10px;
  }
}

/* ------------------------------------------------ coarse pointer, any size */
/* A touch device wider than 1024px (a large tablet in landscape) still has no
   hover, so the panels must still be tappable there. */
@media (hover: none) and (pointer: coarse) {
  .glfm-shell .glfm-rail-item:not(.glfm-tap-open):hover > .glfm-panel,
  .glfm-shell .glfm-rail-item:not(.glfm-tap-open):focus-within > .glfm-panel,
  .glfm-shell .glfm-panel-item:not(.glfm-tap-open):hover > .glfm-panel,
  .glfm-shell .glfm-panel-item:not(.glfm-tap-open):focus-within > .glfm-panel {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .glfm-shell .glfm-rail-item.glfm-tap-open > .glfm-panel,
  .glfm-shell .glfm-panel-item.glfm-tap-open > .glfm-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
}

/* ------------------------------------------------------------ small phone -- */
@media (max-width: 480px) {
  .glfm-menu-toggle-label {
    display: none;
  }

  .glfm-menu-toggle {
    padding: 8px 10px;
  }

  .navbar > .container,
  .navbar > .container-fluid {
    padding-left: 68px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  /* Report action buttons: two comfortable columns rather than a cramped row. */
  .report-actions .btn {
    flex: 1 1 auto;
  }
}

/* ----------------------------------------------------------------- money -- */
/* Every currency cell and input lines up on its decimal. One class, loaded last (this stylesheet is
   linked from mybase.html after custom.css and side_menu.css), so a report table's own column rules
   cannot shift a money column left. !important is needed for the same reason: Bootstrap's
   `.table > tbody > tr > td` (three elements) out-specifies a single class. */
.vg-money {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

input.vg-money {
  text-align: right !important;
}

/* -------------------------------------------------------------- availability -- */
/* The age of a memoised QuantityAvailable figure (app/availability.py). Muted and smaller so the
   number reads first and the "as of <time>" sits beside it; a stale figure is then visibly stale
   rather than looking like a live stock count. */
.vg-avail-age {
  display: inline-block;
  margin-left: 0.35em;
  color: #888;
  font-size: 0.85em;
  white-space: nowrap;
}
