/* ══════════════════════════════════════════════════════════════
   OpexMM — mobile.css
   Loaded ONLY via <link media="(max-width: 820px)">.
   Desktop never loads this file. Purely additive — no logic changes.
   Shopfloor-first: Worker report screen + Work Orders + Machines.
   ══════════════════════════════════════════════════════════════ */

:root {
  --m-nav-h: 62px;
  --m-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── 1. GLOBAL ─────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: hidden; }
body { padding-bottom: calc(var(--m-nav-h) + var(--m-safe-bottom)); }

/* Full usable width on phones */
.dashboard-shell {
  width: calc(100% - 12px) !important;
  max-width: none !important;
  padding-top: 8px;
}

/* 16px inputs prevent iOS auto-zoom; big touch targets everywhere */
input, select, textarea, button {
  font-size: 16px !important;
}
.secondary-button, .plus-button, .tab-button, .wo-status-btn {
  min-height: 44px;
}
.machine-item { min-height: 56px; }

/* ── 2. TOPBAR — compact single row ────────────────────────── */
.topbar {
  padding: 8px 12px;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
}
/* Override the legacy 768px block in styles.css that stacked &
   stretched these (caused the full-width bell box, hidden menu) */
.topbar-actions {
  width: auto !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 8px;
  flex-shrink: 0;
}
#userMenuButton { display: inline-flex !important; }
.user-menu-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-bell {
  width: auto !important;
  flex: 0 0 auto !important;
  padding: 8px 12px !important;
  border-radius: 8px;
}
.user-menu-drop { right: 0; left: auto; max-width: 88vw; }
.topbar-brand .eyebrow { display: none; }
.topbar-brand h1 {
  font-size: 1rem;
  line-height: 1.2;
  /* Long title → short brand on phones */
  visibility: hidden;
  position: relative;
  height: 1.2em;
  overflow: hidden;
}
.topbar-brand h1::before {
  content: "⚙ OpexMM";
  visibility: visible;
  position: absolute;
  left: 0; top: 0;
  font-size: 1.05rem;
  font-weight: 800;
}
.status-chip { display: none; }

/* ── 3. TAB STRIP → hidden; bottom nav takes over ──────────── */
.tab-strip { display: none !important; }

.m-bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 900;
  display: flex;
  height: calc(var(--m-nav-h) + var(--m-safe-bottom));
  padding-bottom: var(--m-safe-bottom);
  background: var(--card-bg, var(--panel, #101418));
  border-top: 1px solid var(--border-strong, var(--border, #2a3138));
  box-shadow: 0 -4px 16px rgba(0,0,0,.25);
}
.m-bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--muted, #8a949e);
  font-size: 0.68rem !important;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  padding: 6px 2px;
}
.m-bottom-nav button .m-ico { font-size: 1.35rem; line-height: 1; }
.m-bottom-nav button.is-active { color: var(--accent, #ffb400); }

/* "More" sheet */
.m-more-sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--m-nav-h) + var(--m-safe-bottom));
  z-index: 899;
  background: var(--card-bg, var(--panel, #101418));
  border-top: 1px solid var(--border-strong, #2a3138);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -10px 30px rgba(0,0,0,.45);
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.m-more-sheet[hidden] { display: none; }
.m-more-sheet button {
  min-height: 52px;
  border: 1px solid var(--border, #2a3138);
  background: var(--field-bg, transparent);
  color: var(--text, #e8edf2);
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
}
.m-scrim {
  position: fixed; inset: 0;
  z-index: 898;
  background: rgba(0,0,0,.45);
}
.m-scrim[hidden] { display: none; }

/* ── 4. LIST ↔ DETAIL DRILLDOWN ────────────────────────────── */
/* Default (list mode): show ONLY the list card, full width */
.machine-workspace { display: block !important; margin-top: 10px; }
.workspace-divider { display: none !important; }
.machine-workspace > *:not(.machine-list-card) { display: none !important; }
.machine-list-card { width: 100%; }
.machine-list { max-height: none; }

/* Detail mode (class added by mobile.js): hide list, show detail */
.machine-workspace.m-detail > .machine-list-card { display: none !important; }
.machine-workspace.m-detail > *:not(.machine-list-card):not(.workspace-divider):not([hidden]) {
  display: block !important;
}

/* Floating back-to-list button (injected by mobile.js) */
.m-back-btn {
  position: fixed;
  left: 12px;
  bottom: calc(var(--m-nav-h) + var(--m-safe-bottom) + 12px);
  z-index: 890;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 24px;
  border: 1px solid var(--border-strong, #2a3138);
  background: var(--accent, #ffb400);
  color: #111;
  font-weight: 800;
  font-size: 0.95rem !important;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  cursor: pointer;
}
.m-back-btn[hidden] { display: none; }

/* ── 5. PANELS / FORMS — single column, breathing room ─────── */
.panel-header { flex-wrap: wrap; gap: 8px; padding: 10px 2px 6px; }
.panel-header h2 { font-size: 1.15rem; }
.panel-kicker { display: none; }

/* Header badges/buttons form one tidy wrapping row */
.panel-header > div:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}
.panel-header > div:last-child > * { flex: 1 1 auto; text-align: center; }

/* Cards use the full width with less inner padding */
.card { border-radius: 8px; }
.section-heading { padding: 12px 14px; }
.machine-search-wrap { padding: 8px 10px; }

.machine-form,
.parts-form-section,
.users-form-grid,
.settings-grid,
.settings-info-grid,
.documentation-grid,
.schedule-layout,
.documentation-layout {
  grid-template-columns: 1fr !important;
  display: grid;
}
.machine-form label, .parts-form-section label { min-width: 0; }

/* Action rows wrap instead of overflow */
.action-row { flex-wrap: wrap !important; gap: 6px !important; }

/* Tables & wide content scroll horizontally instead of breaking layout */
.users-table-wrap, .cal-grid-wrap, table { max-width: 100%; }
.tab-panel { overflow-x: hidden; }
.users-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Calendar: allow horizontal scroll of the 7-column grid */
.cal-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cal-grid { min-width: 640px; }

/* ── 6. WORKER REPORT SCREEN — shopfloor priority ──────────── */
.report-screen { padding: 16px 14px calc(var(--m-nav-h) + 20px); }
.report-header h2 { font-size: 1.3rem; }
.report-form { max-width: 100%; }
.report-form select,
.report-form textarea {
  font-size: 17px !important;
  padding: 14px 12px;
}
.report-form textarea { min-height: 130px; }
.report-upload-label {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.report-submit-btn {
  position: sticky;
  bottom: calc(var(--m-nav-h) + var(--m-safe-bottom) + 8px);
  width: 100%;
  min-height: 58px !important;
  font-size: 1.05rem !important;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(0,0,0,.45);
  z-index: 10;
}

/* Worker screen has no tabs → hide bottom nav there (JS adds body class) */
body.m-worker-mode .m-bottom-nav,
body.m-worker-mode .m-back-btn { display: none !important; }
body.m-worker-mode { padding-bottom: 0; }

/* ── 7. LOGIN ──────────────────────────────────────────────── */
.login-box { width: min(94vw, 420px); padding: 20px 16px; }
.login-header h1 { font-size: 1.05rem; }

/* ── 8. MODALS fit small screens ───────────────────────────── */
[class*="modal"] [class*="box"], .login-box { max-height: 92vh; overflow-y: auto; }

/* ── 9. MAX mascot out of the way of the nav ───────────────── */
#maxContainer, .max-container, #maxMascot {
  bottom: calc(var(--m-nav-h) + var(--m-safe-bottom) + 10px) !important;
}
