/* ════════════════════════════════════════════════════════════════════
   Field mode — the phone layout (≤768px). js/field-mode.js adds
   body.field-mode on phones; nothing here applies without it, so the
   desktop and tablet layouts are untouched.

   Approved with Yani on 2026-10-16 (mock-ups): same header on every
   screen (logo left; VERA, search, bell right), near-white page, white
   cards, a "Today" home with three tiles and a ring task list, and a
   bottom bar Today · Tasks · Report · Scan · More. Every module, form
   and question stays reachable: this changes layout, not features.
   ════════════════════════════════════════════════════════════════════ */

body.field-mode:not(.dark-mode) { --bg: #FCFCFC; }
body.field-mode { background: var(--bg); }

/* ── Header: logo on the left, the menu button gives way to "More" ── */
body.field-mode #hamburger { display: none !important; }
body.field-mode .mob-topbar-logo { position: static; transform: none; margin-right: auto; }
body.field-mode .topbar-right { gap: 6px !important; }
body.field-mode .mob-header-btn,
body.field-mode .notif-bell { color: var(--text); }

/* The header site switcher stays rendered but out of sight: app-scope.js
   only reads and restores pickers that are on the page. The site line on
   Today drives it (fmPickSite in js/field-mode.js). */
body.field-mode #app-scope.hide-mob {
  display: flex !important; position: absolute !important; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; margin: 0 !important; padding: 0; border: 0;
}

/* ── Bottom bar ── */
body.field-mode .mob-nav-item.active { background: none; }
body.field-mode .mob-nav-item .mni-svg { stroke: var(--text3); }
body.field-mode .mob-nav-item.active .mni-svg { stroke: var(--text); }
body.field-mode .mob-nav-item .mnl { color: var(--text3); }
body.field-mode .mob-nav-item.active .mnl { color: var(--text); font-weight: 600; }
body.field-mode .fm-scan-item { justify-content: flex-end; margin-top: -20px; }
body.field-mode .fm-scan-circle {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--text); color: var(--bg2);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
body.field-mode .fm-scan-circle svg { stroke: var(--bg2); }

/* ── Shared building blocks ── */
.fm-page { padding: 2px 0 8px; }
.fm-h1 { font-size: 20px; font-weight: 600; color: var(--text); margin: 2px 0 12px; }
.fm-sub { font-size: 12.5px; color: var(--text2); }
.fm-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 2px 6px 2px 14px; margin-bottom: 12px;
}
.fm-group { font-size: 12.5px; font-weight: 600; color: var(--text2); padding-top: 10px; }
.fm-group.late { color: var(--danger); }
.fm-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 0; min-height: 52px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.fm-row + .fm-row { border-top: 1px solid var(--bg3); }
.fm-row-main { flex: 1; min-width: 0; }
.fm-row-title { font-size: 15px; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.fm-row-meta { font-size: 12.5px; color: var(--text3); margin-top: 1px; }
.fm-row-meta.late { color: var(--danger); }
.fm-go { flex-shrink: 0; width: 24px; height: 24px; color: var(--text3); }

/* Ring: tick an action done; opens the form for checks and permits. */
.fm-ring {
  width: 26px; height: 26px; box-sizing: border-box; flex-shrink: 0;
  border-radius: 50%; border: 2px solid var(--text3); background: none;
  display: flex; align-items: center; justify-content: center;
  color: transparent; padding: 0; cursor: pointer;
}
.fm-ring.late { border-color: var(--danger); }
.fm-ring.on { background: var(--success); border-color: var(--success); color: #fff; }
.fm-row.done .fm-row-title { text-decoration: line-through; color: var(--text3); }
.fm-undo { color: var(--text); text-decoration: underline; cursor: pointer; margin-left: 4px; }

/* ── Today ── */
.fm-hello { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.fm-hello-name { font-size: 18px; font-weight: 600; color: var(--text); }
.fm-sync { border-radius: 10px; padding: 2px 9px; font-size: 11.5px; white-space: nowrap; }
.fm-sync.ok { background: var(--success-l); color: var(--success); }
.fm-sync.wait { background: var(--amber-l); color: var(--amber); }
.fm-where {
  font-size: 13px; color: var(--text2); margin: 3px 0 14px;
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
}
.fm-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.fm-tile {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 4px; text-align: center; cursor: pointer; color: var(--text);
  font: inherit; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.fm-tile svg { width: 26px; height: 26px; }
.fm-tile span { font-size: 14px; font-weight: 600; }
.fm-tile.primary { background: var(--safety-orange); border-color: var(--safety-orange); color: #fff; }
.fm-empty { text-align: center; color: var(--text3); font-size: 13.5px; padding: 18px 8px 22px; }

/* ── Tasks ── */
.fm-chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px 2px; scrollbar-width: none; }
.fm-chips::-webkit-scrollbar { display: none; }
.fm-chip {
  border: 1px solid var(--border); border-radius: 16px; padding: 6px 12px; font-size: 13px;
  white-space: nowrap; background: var(--bg2); color: var(--text); cursor: pointer; font-family: inherit;
}
.fm-chip.on { background: var(--text); color: var(--bg2); border-color: var(--text); }

/* ── More ── */
.fm-search {
  display: flex; align-items: center; gap: 8px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; margin-bottom: 12px;
}
.fm-search svg { width: 18px; height: 18px; color: var(--text3); flex-shrink: 0; }
.fm-search input { flex: 1; border: none; outline: none; background: none; padding: 11px 0; color: var(--text); font-family: inherit; }
.fm-mod-ico { width: 20px; height: 20px; color: var(--text2); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.fm-mod-ico svg, .fm-mod-ico i { width: 20px; height: 20px; }
.fm-badge { border-radius: 10px; padding: 1px 8px; font-size: 11.5px; background: var(--safety-orange-l); color: var(--safety-orange); }

/* The old drawer is replaced by the More page in field mode. */
body.field-mode #mob-drawer,
body.field-mode #mob-overlay { display: none !important; }

/* ════════════ Step 2: forms ════════════ */

/* While a step-by-step form or an inspection is on screen the bottom bar
   steps aside; the form's own action bar takes the bottom. */
body.field-mode.fm-form-open .mob-nav { display: none !important; }
body.field-mode.fm-form-open .content { padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important; }

/* The form's top row becomes "× Title", pinned under the header. */
body.field-mode .mw-root > .mw-head {
  margin: -14px -12px 12px !important; padding: 6px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 6;
  width: calc(100% + 24px); max-width: none !important; box-sizing: border-box;
}
body.field-mode .mw-head > .btn-secondary:first-child,
body.field-mode .insf-bar-row > .btn-secondary:first-child {
  font-size: 0 !important; width: 38px; height: 38px; padding: 0 !important; flex-shrink: 0;
  border: none !important; background: none !important; box-shadow: none !important;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text);
}
body.field-mode .mw-head > .btn-secondary:first-child::before,
body.field-mode .insf-bar-row > .btn-secondary:first-child::before {
  content: "\00D7"; font-size: 30px; line-height: 1; font-weight: 300;
}
.fm-draft { font-size: 12px; color: var(--text3); white-space: nowrap; }

/* Back / Next at the bottom of the screen (Next black, Submit orange). */
body.field-mode .mw-bar {
  position: fixed !important; left: 0; right: 0; bottom: 0 !important; z-index: 250 !important; margin: 0 !important;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) !important;
  background: var(--bg2) !important; border-top: 1px solid var(--border);
}
body.field-mode .mw-root { padding-bottom: 84px; }   /* room above the fixed bar */
body.field-mode .mw-bar .btn { height: 48px; border-radius: 12px; font-size: 15px; font-weight: 600; }
body.field-mode .mw-bar .mw-next { background: var(--text) !important; color: var(--bg2) !important; border-color: var(--text) !important; }
body.field-mode .mw-bar .mw-next.mw-last { background: var(--safety-orange) !important; border-color: var(--safety-orange) !important; color: #fff !important; }

/* Report (Quick Capture) keeps the header visible above it. */
body.field-mode #obs-quick-sheet { top: calc(52px + env(safe-area-inset-top)) !important; }
body.field-mode #obs-quick-sheet > div:first-child { padding: 6px 12px !important; justify-content: flex-start !important; gap: 4px; }
body.field-mode #obs-quick-sheet > div:first-child > div { font-size: 15px !important; font-weight: 600 !important; }
body.field-mode.gs-mobile-open .topbar { z-index: 9600; }

/* Inspection in progress: × title, score and progress pinned under the
   header; big answers; Next unanswered at the bottom. */
body.field-mode .insf-bar { background: var(--bg2); }
body.field-mode .insf-score .panel-title { display: none; }
body.field-mode .insf-score #ins-score-pct { font-size: 18px; font-weight: 700; color: var(--success); }
body.field-mode .insf-bar-row { padding-bottom: 8px; gap: 6px; }
body.field-mode .insf-progress { height: 5px; border-radius: 3px; margin: 0 0 10px !important; overflow: hidden; }
body.field-mode .insf-progress #ins-score-bar { background: var(--success); border-radius: 3px; }
body.field-mode .insf-q .cbtn { height: 50px; font-size: 15px; border-radius: 12px; }
body.field-mode.fm-ins-open .insf-wrap { padding-bottom: 76px; }
.fm-flash { box-shadow: 0 0 0 3px var(--safety-orange) !important; transition: box-shadow .2s; }

.fm-actbar { display: none; }
body.field-mode.fm-ins-open .fm-actbar {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 250;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--border);
}
.fm-actbtn {
  flex: 1; height: 48px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--text); color: var(--bg2); font: inherit; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.fm-actbtn.submit { background: var(--safety-orange); color: #fff; }

/* ════════════ Step 3: lists and records ════════════ */

/* List pages: the title is back (the header only carries the logo on
   phones), a "‹ More" link above it, and the New button in orange. */
body.field-mode .page-header-title { display: block; font-size: 20px; font-weight: 600; color: var(--text); margin: 0; }
.fm-back {
  background: none; border: none; padding: 2px 0; margin: 0 0 6px; color: var(--text2);
  font: inherit; font-size: 14px; display: inline-flex; align-items: center; gap: 2px; cursor: pointer;
}
.fm-back svg { width: 18px; height: 18px; }
body.field-mode .page-header-actions .btn { border-radius: 12px; min-height: 42px; }
body.field-mode .page-header-actions .btn-primary { background: var(--safety-orange); border-color: var(--safety-orange); color: #fff; }

/* Cards: rounder, flat, status labels side by side. */
body.field-mode .tbl tbody tr { border-radius: 14px; box-shadow: none; padding-right: 40px; }   /* text clears the arrow */
body.field-mode .tbl tbody td:has(> .bdg:only-child),
body.field-mode .tbl tbody td:has(> span[class*="bdg"]:only-child) {
  display: inline-block !important; width: auto !important; margin: 4px 6px 0 0;
}

/* Records (incident, CAPA, NCR...): "‹ Back" with the status on the
   first line, the title large underneath. */
body.field-mode [id$="-detail"] > div:first-child:has(> .btn-secondary.btn-sm:first-child) {
  flex-wrap: wrap; row-gap: 4px; margin-bottom: 12px !important;
}
body.field-mode [id$="-detail"] > div:first-child:has(> .btn-secondary.btn-sm:first-child) > .btn-secondary.btn-sm:first-child {
  background: none !important; border: none !important; box-shadow: none !important;
  padding: 4px 0 !important; color: var(--text2); font-size: 14px;
}
body.field-mode [id$="-detail"] > div:first-child:has(> .btn-secondary.btn-sm:first-child) > div:nth-child(2) {
  order: 3; flex: 0 0 100% !important; font-size: 18px !important; font-weight: 600 !important; line-height: 1.3;
}
body.field-mode [id$="-detail"] > div:first-child:has(> .btn-secondary.btn-sm:first-child) > div:nth-child(3) { margin-left: auto; }

/* Steps as one progress bar (buildStepper in js/app.js, phones). Each
   reached segment is still tappable to open that step. */
.sg-segs { display: flex; gap: 4px; }
.sg-seg { flex: 1; height: 22px; display: flex; align-items: center; }
.sg-seg[onclick] { cursor: pointer; }
.sg-seg::before { content: ""; flex: 1; height: 6px; border-radius: 3px; background: var(--border); }
.sg-seg.done::before { background: var(--success); }
.sg-seg.active::before { background: var(--safety-orange); }
.sg-segs-label { font-size: 13px; font-weight: 600; color: var(--text2); margin-top: 2px; }

/* Back / Next under a record: Back white, Next black. */
body.field-mode .sg-pager { gap: 8px; padding: 10px 12px; }
body.field-mode .sg-pager > * { flex: 1; }
body.field-mode .sg-pager > .btn { height: 48px; border-radius: 12px; justify-content: center; font-size: 15px; font-weight: 600; }
body.field-mode .sg-pager > .btn:first-child { background: var(--bg2); }
body.field-mode .sg-pager > .btn:last-child:not(:first-child) { background: var(--text); color: var(--bg2); border-color: var(--text); }
body:not(.field-mode) .fm-back { display: none; }

/* ════════════ Step 4 ════════════ */

/* Notifications: a full page between the header and the bottom bar. */
body.field-mode .notif-panel {
  top: calc(52px + env(safe-area-inset-top)) !important; left: 0 !important; right: 0 !important;
  bottom: calc(65px + env(safe-area-inset-bottom)) !important; width: auto !important; max-height: none !important;
  border-radius: 0 !important; border: none !important; box-shadow: none !important; background: var(--bg);
}
body.field-mode .notif-panel .notif-panel-head { background: var(--bg2); }
body.field-mode .notif-panel .fm-notif-back { margin: 0 auto 0 0; }
body.field-mode .notif-item { padding: 14px 16px; border-bottom: 1px solid var(--bg3); }

/* Profile: certificates and emergency on top of your own profile. */
.fm-me { margin-bottom: 4px; }
body:not(.field-mode) .fm-me { display: none; }
.fm-call {
  flex-shrink: 0; border-radius: 10px; padding: 7px 14px; font-size: 13px; font-weight: 600;
  background: var(--success-l); color: var(--success);
}

/* ════════════ VERA ════════════
   The ENSURE header stays above VERA (its icon turns orange). VERA's own
   row reads × · VERA · history, new. While the keyboard is up (body.fm-kb,
   js/field-mode.js) VERA takes the whole visible screen again, exactly as
   js/ai-assistant.js sizes it, so typing on iPhones is unchanged. */
body.field-mode:not(.fm-kb) #ai-panel {
  top: calc(52px + env(safe-area-inset-top)) !important;
  height: calc(100dvh - 52px - env(safe-area-inset-top)) !important;
}
body.field-mode:not(.fm-kb) #ai-backdrop { top: calc(52px + env(safe-area-inset-top)) !important; }
body.field-mode .ai-hdr { padding: 6px 10px !important; gap: 4px; border-bottom: 1px solid var(--border); }
body.field-mode.fm-kb .ai-hdr { padding-top: calc(6px + env(safe-area-inset-top)) !important; }
body.field-mode .ai-hdr .ai-actions { display: contents; }
body.field-mode .ai-hdr > h3 { order: 1; flex: 1; justify-content: center; text-align: center; margin: 0; }
body.field-mode .ai-hdr .ai-actions > button { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; }
body.field-mode .ai-hdr .ai-actions > button:last-child { order: 0; }
body.field-mode .ai-hdr .ai-actions > button:not(:last-child) { order: 2; }
body.field-mode:has(#ai-panel.open) #mob-ai-trigger { color: var(--safety-orange); }
.fm-saved-note { font-size: 12.5px; color: var(--amber); background: var(--amber-l); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }

/* Phone notifications card on Today (js/push.js) */
.fm-push { padding: 14px 16px !important; }
.fm-push-title { font-size: 15px; font-weight: 600; color: var(--text); }
.fm-push-text { font-size: 13px; color: var(--text2); margin: 4px 0 12px; line-height: 1.45; }
.fm-push-row { display: flex; gap: 8px; align-items: center; }
.fm-push-btn { flex: 1; height: 44px; border: none; border-radius: 12px; background: var(--text); color: var(--bg2); font: inherit; font-weight: 600; cursor: pointer; }
.fm-push-later { height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg2); color: var(--text2); font: inherit; cursor: pointer; }

/* Report sheet (fmReport): which kind of record to create */
.fm-sheet-wrap { position: fixed; inset: 0; z-index: 9000; background: rgba(20,20,20,0); transition: background .2s; }
.fm-sheet-wrap.open { background: rgba(20,20,20,.45); }
.fm-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg2);
  border-radius: 22px 22px 0 0; padding: 10px 14px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease-out;
}
.fm-sheet-wrap.open .fm-sheet { transform: translateY(0); }
.fm-sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 12px; }
.fm-sheet-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.fm-sheet-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px;
  border: none; border-radius: 14px; background: var(--bg); color: var(--text); font: inherit;
  cursor: pointer; -webkit-tap-highlight-color: transparent; margin-bottom: 8px;
}
.fm-sheet-row:active { background: var(--bg3); }
.fm-sheet-row > svg { color: var(--text3); flex-shrink: 0; }
.fm-sheet-ic { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.fm-sheet-ic.obs { background: var(--safety-orange); color: #fff; }
.fm-sheet-ic.inc { background: var(--danger-l); color: var(--danger); }
.fm-sheet-ic.capa { background: var(--green-l); color: var(--green); }
.fm-sheet-ic.ncr { background: var(--amber-l); color: var(--amber); }
.fm-sheet-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fm-sheet-name { font-size: 15px; font-weight: 600; }
.fm-sheet-sub { font-size: 12px; color: var(--text2); margin-top: 1px; }
.fm-sheet-cancel {
  width: 100%; height: 44px; margin-top: 2px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg2); color: var(--text2); font: inherit; font-size: 15px; cursor: pointer;
}

/* Permit form open: no list header above it (More, title, + New Permit) */
body.field-mode #p-ptw:has(#ptw-form-page:not(:empty):not([style*="display: none"])) > .page-header,
body.field-mode #p-ptw:has(#ptw-form-page:not(:empty):not([style*="display: none"])) > .fm-back { display: none !important; }

/* ── Today shortcuts (js/field-home.js): hold to edit, minus, Add ── */
.fm-tile { position: relative; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; min-width: 0; }
.fm-tile .fm-tile-label { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.2; padding: 0 6px; word-break: break-word; }
.fm-tile .fm-tile-ico { display: flex; width: 26px; height: 26px; }
.fm-tile .fm-tile-ico svg, .fm-tile .fm-tile-ico i { width: 26px; height: 26px; }
.fm-tile .fm-tile-x {
  position: absolute; top: -7px; left: -7px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--text2); color: var(--bg2); font-size: 18px; font-weight: 600; line-height: 1;
  display: flex; align-items: center; justify-content: center; z-index: 1;
}
.fm-tile-add { border-style: dashed; color: var(--safety-orange); background: transparent; }
.fm-tiles.editing .fm-tile:not(.fm-tile-add) { animation: fm-wig .3s ease-in-out infinite; }
@keyframes fm-wig { 0%, 100% { transform: rotate(-1.2deg); } 50% { transform: rotate(1.2deg); } }
@media (prefers-reduced-motion: reduce) { .fm-tiles.editing .fm-tile { animation: none; } }
.fm-home-bar { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 2px; }
.fm-home-bar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.fm-home-done { border: none; background: none; color: var(--safety-orange); font: inherit; font-weight: 600; font-size: 15px; padding: 8px 4px; cursor: pointer; }
.fm-home-hint { font-size: 12px; color: var(--text2); margin-bottom: 12px; }
.fm-home-reset { display: block; margin: -6px auto 14px; border: none; background: none; color: var(--text2); font: inherit; font-size: 13px; text-decoration: underline; padding: 6px 10px; cursor: pointer; }
.fm-sheet-tall { max-height: 82vh; display: flex; flex-direction: column; }
.fm-pick-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; margin-bottom: 8px; }
.fm-pick-h { font-size: 12px; font-weight: 600; color: var(--text2); margin: 10px 0 6px; }
.fm-pick-wait { font-size: 13px; color: var(--text3); padding: 6px 2px; }
.fm-sheet-row > .fm-mod-ico { width: 24px; height: 24px; }
.fm-sheet-row > .fm-mod-ico svg, .fm-sheet-row > .fm-mod-ico i { width: 22px; height: 22px; }
.fm-tiles.editing .fm-tile { touch-action: none; }
.fm-tile.fm-dragging { animation: none !important; z-index: 5; position: relative; box-shadow: 0 8px 22px rgba(0,0,0,.22); transition: none; opacity: .95; }
.fm-tile.fm-drop { outline: 2px solid var(--safety-orange); outline-offset: -2px; }
