/* ALAN on a phone (Dylan, 4 Nov 2026). Same pages, same features: only the layout changes, and only under 900px. See static/js/mobile.js. */
@media screen and (max-width: 900px) {
  :root { --rail-width: 0px; --mob-nav: 58px; --mob-top: 52px; --header-height: var(--mob-top); }
  html, body { overflow-x: hidden; -webkit-text-size-adjust: 100%; }
  body.has-header { padding-bottom: calc(var(--mob-nav) + env(safe-area-inset-bottom)); }

  /* Rail becomes a bottom bar */
  .global-header { position: fixed !important; top: auto !important; left: 0 !important; right: 0 !important; bottom: 0 !important; width: 100% !important;
    height: calc(var(--mob-nav) + env(safe-area-inset-bottom)) !important; padding: 0 4px env(safe-area-inset-bottom) !important; flex-direction: row !important; align-items: stretch !important; z-index: 180 !important; overflow: visible !important; }
  .gh-centre, .gh-actions, .gh-operator-pill { display: none !important; }
  .gh-left { flex: 1; display: flex !important; flex-direction: row !important; align-items: stretch; gap: 2px; padding: 0 !important; margin: 0 !important; width: 100%; }
  .gh-nav-tab, button.mob-more-btn { flex: 1 1 0; min-width: 0; display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10.5px !important; font-weight: 600; padding: 6px 0 !important; margin: 4px 0; background: transparent; border: 0; color: var(--rail-ink, #c9d3de); border-radius: 8px; }
  .gh-nav-tab span { display: block !important; white-space: nowrap; }
  button.mob-more-btn svg { width: 19px; height: 19px; stroke: currentColor; }
  body.mob-more button.mob-more-btn { background: rgba(255,255,255,.1); color: #fff; }

  /* More menu: profile, scan, settings, log out */
  .gh-right { display: none !important; }
  body.mob-more .gh-right { display: flex !important; position: fixed; right: 8px; bottom: calc(var(--mob-nav) + env(safe-area-inset-bottom) + 8px); width: 210px; flex-direction: column; align-items: stretch; gap: 2px; padding: 8px !important; background: var(--rail, #243040); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35); border: 0 !important; z-index: 181; }
  body.mob-more .gh-right a { width: auto !important; height: 46px !important; display: flex !important; align-items: center; justify-content: flex-start; gap: 12px; padding: 0 12px !important; color: #fff; text-decoration: none; font-size: 15px; }
  .mob-scrim { display: none; }
  body.mob-more .mob-scrim, body.mob-forms .mob-scrim { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 179; }

  /* Top bar */
  .gh-topbar { left: 0 !important; height: auto !important; min-height: 52px; flex-wrap: wrap; padding: 6px 12px !important; gap: 6px 8px !important; }
  .gh-topbar::before { content: ''; flex: 0 0 28px; height: 28px; background: url('/static/images/alan-logo.png') center/contain no-repeat; }
  .gh-page-title { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 15px !important; }
  .gh-hello, .kbd { display: none !important; }
  .aa-open { margin: 0 !important; flex: none; order: 2; min-height: 36px; }
  #gh-search-slot { order: 3; flex: 1 0 100% !important; }
  #gh-search-slot:empty { display: none; }
  #gh-search-slot .orders-tab-search { width: 100% !important; max-width: none !important; }

  /* Content */
  body.has-header .content { margin-top: var(--mob-top) !important; padding: 12px !important; width: 100% !important; max-width: 100% !important; min-width: 0 !important; box-sizing: border-box; }
  body.has-header .flash-messages { margin-top: var(--mob-top) !important; margin-left: 0 !important; }
  .content :not(table, thead, tbody, tfoot, tr, td, th, table *, svg, svg *) { max-width: 100%; box-sizing: border-box; }
  .content h1, .content h2 { font-size: 20px; overflow-wrap: anywhere; }
  .content [style*="grid-template-columns"], .ncr-card .body-split, .ncr-card .meta-grid { grid-template-columns: 1fr !important; }
  .content [style*="min-width"]:not(th, td) { min-width: 0 !important; }
  .content [style*="display:flex"]:not([style*="flex-direction:column"]):not([style*="flex-direction: column"]), .content [style*="display: flex"]:not([style*="flex-direction:column"]):not([style*="flex-direction: column"]), .card-head, .section-header { flex-wrap: wrap; }
  [id$="-overlay"] > div > div[style*="overflow"], .qms-modal-card > * { max-width: 100%; }
  [id$="-overlay"] form { min-width: 0; width: 100%; }
  .content .card-title, .content [style*="nowrap"]:not(th, td, button, a.btn) { white-space: normal !important; overflow-wrap: anywhere; }

  .tile-header { height: auto !important; flex-wrap: wrap !important; gap: 8px; }
  .tile-header > * { min-width: 0; }
  .content .card, .content details.card, .content form { min-width: 0 !important; width: auto !important; }
  .content .form-group, .content .inline-form { width: 100% !important; flex: 1 1 100% !important; }
  /* Tabs scroll sideways */
  .tabs, .qms-tabs-row { display: flex !important; flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 6px; padding-bottom: 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { flex: none !important; white-space: nowrap; max-width: none !important; }

  /* Touch: big enough to hit, and 16px stops iOS zooming into every field */
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { font-size: 16px !important; min-height: 42px; max-width: 100%; }
  input[type=checkbox], input[type=radio] { min-width: 20px; min-height: 20px; }
  .btn, .content button, .modal-content button { min-height: 38px; min-width: 38px; touch-action: manipulation; }

  /* Forms & Records list opens as a sheet */
  .qms-page-flex { display: block !important; height: auto !important; min-height: 0 !important; overflow: visible !important; }
  .qms-content-col { width: 100% !important; max-width: 100% !important; min-width: 0 !important; padding: 0 !important; overflow: visible !important; height: auto !important; }
  button.mob-forms-btn { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 14px; margin: 0 0 12px; background: var(--surface, #fff); border: 1px solid var(--line, #e5e7eb); border-radius: 10px; font: inherit; font-weight: 600; color: var(--ink, #1f2937); text-align: left; }
  .qms-forms-sidebar { display: none !important; }
  body.mob-forms .qms-forms-sidebar { display: block !important; position: fixed !important; inset: 0 !important; width: 100% !important; max-width: none !important; height: auto !important; max-height: none !important; flex: none !important; overflow-y: auto !important; z-index: 9500; background: var(--surface, #fff); padding: 12px 12px calc(24px + env(safe-area-inset-bottom)) !important; margin: 0 !important; border-radius: 0 !important; }
  body.mob-forms .qms-forms-sidebar .sidebar-toggle { display: none; }
  body.mob-forms .qms-forms-sidebar a { min-height: 44px; display: flex !important; align-items: center; gap: 10px; padding: 8px !important; justify-content: flex-start !important; }
  body.mob-forms .qms-forms-sidebar .fr-name { display: block !important; font-size: 14px; }
  body.mob-forms .qms-forms-sidebar .fr-code { min-width: 44px !important; text-align: left !important; }
  body.mob-forms .qms-forms-sidebar .group-label { display: block !important; }
  body.mob-forms .qms-forms-sidebar .qms-reg-forms { display: block !important; }
  .mob-forms-close { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 16px; padding: 6px 4px 10px; background: var(--surface, #fff); z-index: 1; }
  .mob-forms-close button { font-size: 22px; border: 0; background: none; min-width: 44px; min-height: 44px; color: var(--ink, #1f2937); }

  /* Documents: list on top, chosen document below */
  .cd-page-flex { flex-direction: column !important; height: auto !important; min-height: 0 !important; overflow: visible !important; }
  .cd-sidebar, .cd-main-pane { flex: none !important; width: 100% !important; max-width: 100% !important; height: auto !important; max-height: none !important; overflow: visible !important; }
  .cd-main-pane { min-height: 0 !important; scroll-margin-top: calc(var(--mob-top) + 8px); }
  .cd-placeholder { display: none !important; }
  .cd-doc-header { flex-wrap: wrap !important; height: auto !important; gap: 8px !important; }
  .cd-doc-header > * { flex-wrap: wrap !important; min-width: 0; }
  .cd-doc-header .cd-h-title { flex: 1 1 100% !important; order: -1; line-height: 1.3 !important; }
  .cd-main-pane iframe, .cd-main-pane embed, .cd-main-pane object { width: 100% !important; height: 70vh !important; }

  /* Tables: cards when simple, sideways scroll when not */
  table.mob-cards, table.mob-cards tbody { display: block; width: 100% !important; min-width: 0 !important; }
  table.mob-cards thead { display: none; }
  table.mob-cards tr { display: block; background: var(--surface, #fff); border: 1px solid var(--line, #e5e7eb); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
  table.mob-cards td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; width: auto !important; min-width: 0 !important; max-width: none !important; border: 0 !important; padding: 5px 0 !important; text-align: right; white-space: normal !important; overflow-wrap: anywhere; }
  table.mob-cards td[data-label]::before { content: attr(data-label); flex: 0 0 38%; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted, #6b7280); }
  table.mob-cards td:not([data-label]), table.mob-cards td.mob-whole { display: block; text-align: left; }
  table.mob-cards td:empty { display: none; }
  table.mob-cards td > * { max-width: 100%; }
  .mob-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; max-width: 100%; }
  .mob-scroll > table { width: max-content !important; min-width: 100%; max-width: none !important; }

  /* Pop-ups fill the screen */
  .modal-content, .modal > div, .confirm-modal-box, .assign-modal-overlay > div, .scan-modal-overlay > div, .qms-modal-overlay > div,
  [id$="-overlay"]:not(#operator-panel-overlay) > div, #lot-info-popup > div, [id$="-modal"] > div {
    width: 100% !important; max-width: 100% !important; min-width: 0 !important; max-height: 100dvh !important; border-radius: 0 !important; overflow-y: auto !important; box-sizing: border-box; }
  [id$="-overlay"]:not(#operator-panel-overlay), .modal, .qms-modal-overlay { align-items: flex-start !important; padding: 0 !important; overflow-y: auto; }
  #aa-drawer { width: 100% !important; }
  #aa-drawer.aa-on { z-index: 9990; }

  /* Scan mode opens as a panel */
  .global-header.scan-active .gh-scanbar { position: fixed !important; inset: 0 0 calc(var(--mob-nav) + env(safe-area-inset-bottom)) 0 !important; left: 0 !important; width: 100% !important; height: auto !important; overflow-y: auto; z-index: 182; padding: 12px; }
  .gh-scanbar-inner { flex-direction: column !important; height: auto !important; }
  .gh-scanbar-group { border-right: 0 !important; }
  .gh-scanbar-btns { flex-wrap: wrap !important; }
  .gh-scanbar-btns button { min-height: 44px; flex: 1 1 45%; }
  #scan-right-cluster { margin-top: 12px; display: flex; justify-content: flex-end; }
  #scan-right-cluster .gh-operator-pill { display: none !important; }
  #scan-right-cluster a { width: auto !important; height: 44px !important; display: flex !important; align-items: center; gap: 8px; padding: 0 16px !important; border-radius: 10px; background: #243040 !important; text-decoration: none; }
  #scan-right-cluster .mob-label { color: #fff; }
  #scan-right-cluster .mob-label::after { content: ' off'; }
}
