/* =========================================================
   BramSamnang 2 & 3 — MOBILE SKIN  (Phase 1)
   EVERY rule in this file is scoped to  html.ui-mobile.
   With that class absent the file is inert, so the desktop /
   PC-browser layout in styles.css is byte-for-byte unchanged.
   The class is added by js/mobile.js when:
     - ?ui=mobile  or localStorage de_ui set to mobile
     - running inside the Android APK (Capacitor)
     - the viewport is a phone/tablet (max 820px, coarse pointer)
   ========================================================= */

html.ui-mobile {
  --m-bar: 52px;              /* top app bar height  */
  --m-tabs: 58px;             /* bottom tab bar height */
  --m-safe-t: env(safe-area-inset-top, 0px);
  --m-safe-b: env(safe-area-inset-bottom, 0px);
  --m-touch: 44px;            /* minimum tap target */
  -webkit-tap-highlight-color: rgba(192, 57, 43, .15);
}
html.ui-mobile, html.ui-mobile body { height: 100%; overscroll-behavior-y: none; }
html.ui-mobile body {
  padding-top: calc(var(--m-bar) + var(--m-safe-t));
  padding-bottom: calc(var(--m-tabs) + var(--m-safe-b));
  font-size: 15px;
  overflow-x: hidden;
}
/* iOS zooms the page when a focused input is under 16px — never let that happen */
html.ui-mobile input,
html.ui-mobile select,
html.ui-mobile textarea { font-size: 16px !important; }

/* ============ TOP APP BAR ============ */
html.ui-mobile .m-appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 120;
  height: calc(var(--m-bar) + var(--m-safe-t));
  padding: var(--m-safe-t) 6px 0;
  display: flex; align-items: center; gap: 4px;
  background: linear-gradient(180deg, var(--red-light) 0%, var(--red) 55%, var(--red-dark) 100%);
  color: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}
html.ui-mobile .m-appbar button {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  min-width: var(--m-touch); height: var(--m-touch);
  font-size: 20px; line-height: 1; border-radius: 10px;
}
html.ui-mobile .m-appbar button:active { background: rgba(255, 255, 255, .18); }
html.ui-mobile .m-title {
  flex: 1 1 auto; min-width: 0;
  font-weight: 800; font-size: 16px; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
html.ui-mobile .m-user { font-size: 13px !important; font-weight: 700; padding: 0 10px; width: auto; }

/* ============ DRAWER — holds the real .topnav so routing + permissions keep working ============ */
html.ui-mobile .m-scrim {
  position: fixed; inset: 0; z-index: 130;
  background: rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
html.ui-mobile.m-open .m-scrim { opacity: 1; pointer-events: auto; }
html.ui-mobile .m-drawer {
  position: fixed; z-index: 140; top: 0; bottom: 0; left: 0;
  width: min(84vw, 320px);
  background: #1c1c1c; color: #eee;
  transform: translateX(-100%); transition: transform .2s ease;
  display: flex; flex-direction: column;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--m-safe-t) + 8px) 0 calc(var(--m-safe-b) + 16px);
  box-shadow: 2px 0 18px rgba(0, 0, 0, .5);
}
html.ui-mobile.m-open .m-drawer { transform: translateX(0); }
html.ui-mobile .m-drawer-foot {
  margin-top: auto; padding: 14px 16px 0; border-top: 1px solid #333;
  display: flex; flex-direction: column; gap: 8px;
}
html.ui-mobile .m-drawer-foot button {
  background: #2a2a2a; border: 1px solid #3a3a3a; color: #eee;
  border-radius: 8px; min-height: var(--m-touch); font-size: 14px; font-weight: 700; cursor: pointer;
}
html.ui-mobile .m-drawer-foot .m-ver { color: #777; font-size: 11px; text-align: center; }

/* the desktop nav, re-laid-out as a vertical list that is always expanded */
html.ui-mobile .topnav {
  position: static; display: block; padding: 0; background: transparent;
}
html.ui-mobile .topnav .nav-brand {
  display: block; padding: 6px 16px 12px; font-size: 18px; color: #ffd84d;
}
html.ui-mobile .topnav .nav-link,
html.ui-mobile .nav-menu button {
  display: block; width: 100%; text-align: left;
  min-height: var(--m-touch); padding: 12px 18px; font-size: 15px;
}
html.ui-mobile .nav-group { position: static; }
html.ui-mobile .nav-group > .nav-link {         /* section header, not a hover trigger */
  color: #ffb27a; font-size: 12px; letter-spacing: .8px; text-transform: uppercase;
  padding: 16px 16px 6px; min-height: 0; pointer-events: none;
}
html.ui-mobile .nav-menu,
html.ui-mobile .nav-group:hover .nav-menu {     /* always expanded — hover does not exist on touch */
  display: block; position: static; min-width: 0; background: transparent; box-shadow: none;
}
html.ui-mobile .nav-menu button { padding-left: 28px; }
html.ui-mobile .topnav .nav-link.active,
html.ui-mobile .nav-menu button.active { background: var(--red); color: #fff; }
html.ui-mobile .topnav .nav-user { display: none; }   /* replaced by the app-bar avatar */

/* ============ BOTTOM TAB BAR ============ */
html.ui-mobile .m-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
  height: calc(var(--m-tabs) + var(--m-safe-b));
  padding-bottom: var(--m-safe-b);
  display: flex; background: #1c1c1c;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, .3);
}
html.ui-mobile .m-tabs button {
  flex: 1 1 0; min-width: 0; position: relative;
  background: transparent; border: 0; color: #bdbdbd; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10px; font-weight: 700; padding: 0 2px;
}
html.ui-mobile .m-tabs button .m-ico { font-size: 19px; line-height: 1; }
html.ui-mobile .m-tabs button.active { color: #fff; }
html.ui-mobile .m-tabs button.active::before {
  content: ""; position: absolute; top: 0; width: 26px; height: 3px;
  border-radius: 0 0 3px 3px; background: var(--red);
}
html.ui-mobile .m-tabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* the login gate owns the whole screen — hide our chrome behind it */
html.ui-mobile body.locked .m-appbar,
html.ui-mobile body.locked .m-tabs,
html.ui-mobile body.locked .m-drawer,
html.ui-mobile body.locked .m-scrim,
html.ui-mobile body.locked .m-install { display: none !important; }
html.ui-mobile body.locked { padding: 0; }

/* ============ GENERIC PAGE LAYOUT ============ */
html.ui-mobile .page-pad { padding: 12px 12px 24px; max-width: none; }
html.ui-mobile .page-h { font-size: 19px; margin: 2px 0 10px; }
html.ui-mobile .page-h3 { font-size: 16px; margin: 18px 0 8px; }
html.ui-mobile .report-head { flex-direction: column; align-items: stretch; gap: 8px; }
/* the button cluster some report heads carry — :not() keeps it off .dash-tools,
   which is a grid below and would otherwise lose the cascade to this rule */
html.ui-mobile .report-head > div:not(.dash-tools) { display: flex; gap: 8px; }
html.ui-mobile .report-head > div:not(.dash-tools) > button { flex: 1 1 0; }

/* filters + forms: two fields per row, thumb-sized controls */
html.ui-mobile .filters,
html.ui-mobile .form-grid,
html.ui-mobile .dash-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
html.ui-mobile .filters > button,
html.ui-mobile .form-grid > .ff--actions,
html.ui-mobile .dash-tools > button { grid-column: 1 / -1; }
/* a grid item defaults to min-width:auto and would push the page sideways */
html.ui-mobile .filters > *,
html.ui-mobile .form-grid > *,
html.ui-mobile .dash-tools > * { min-width: 0; }
html.ui-mobile .ff input,
html.ui-mobile .ff select { min-height: var(--m-touch); width: 100%; min-width: 0; }
html.ui-mobile .ff--actions { display: flex; }
html.ui-mobile .ff--actions button { flex: 1 1 0; }
html.ui-mobile .btn-submit,
html.ui-mobile .btn-outline { min-height: var(--m-touch); padding: 0 14px; font-size: 15px; }

/* dashboard */
html.ui-mobile .dash-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
html.ui-mobile .dash-links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
html.ui-mobile .dash-links button { width: 100%; }

/* ============ TABLES — keep every column, scroll sideways, freeze the label column ============ */
html.ui-mobile .table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
}
html.ui-mobile table.data { font-size: 12px; }
html.ui-mobile table.data th,
html.ui-mobile table.data td { padding: 8px; }
html.ui-mobile table.data th:first-child,
html.ui-mobile table.data td:first-child {
  position: sticky; left: 0; z-index: 2;
  background: #fff; box-shadow: 1px 0 0 #ecd7e2;
}
html.ui-mobile table.data th:first-child { background: var(--red); z-index: 3; }
html.ui-mobile table.data tr:nth-child(even) td:first-child { background: #faf3f7; }
html.ui-mobile table.data tr.group td:first-child { background: #fbe0ee; }
html.ui-mobile table.data tr.total td:first-child { background: #f0f0f0; }
html.ui-mobile .sumtab { min-width: 0; width: 100%; font-size: 14px; }
html.ui-mobile .sumtab input { width: 100%; min-height: var(--m-touch); }

/* ============ MODALS ============ */
html.ui-mobile .modal { padding: 12px; align-items: flex-end; }
html.ui-mobile .modal-box {
  width: 100%; max-height: 88vh; overflow: auto;
  border-radius: 16px 16px 12px 12px; padding: 18px 16px calc(18px + var(--m-safe-b));
}
html.ui-mobile .modal.gate { align-items: center; }
html.ui-mobile .modal.gate .modal-box { width: 100%; max-width: 380px; }
html.ui-mobile .modal-actions { flex-wrap: wrap; }
html.ui-mobile .modal-actions button { flex: 1 1 40%; }
html.ui-mobile .modal-wide { width: 100%; }

/* ============ ENTRY FORM — Phase 1 usable stacked layout; Phase 2 replaces it with your design ============ */
/* the desktop entry page pins itself to the viewport and never scrolls — on a phone it must flow */
html.ui-mobile #view-entry { height: auto; overflow: visible; }
html.ui-mobile #view-entry .app { height: auto; display: block; max-width: none; }

html.ui-mobile #view-entry .ctrl-row--top {
  display: block; padding: 8px 10px 4px;
  /* sticks BELOW the fixed app bar, not under it */
  position: sticky; top: calc(var(--m-bar) + var(--m-safe-t)); z-index: 20; background: #fff;
  border-bottom: 1px solid var(--pink-border);
}
/* series A–E: one swipeable row, big tap targets */
html.ui-mobile .top-series {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
html.ui-mobile .top-series::-webkit-scrollbar { display: none; }
html.ui-mobile .top-series .check-group { flex: 0 0 auto; }
html.ui-mobile #view-entry .ctrl-row--top .badge { width: 36px; height: 36px; font-size: 16px; }
html.ui-mobile #view-entry .ctrl-row--top .cbx { width: 24px; height: 24px; }
html.ui-mobile .top-modes { display: flex; gap: 12px; padding: 4px 0 6px; }
html.ui-mobile #view-entry .ctrl-row--top .pill--mini { min-height: 36px; padding: 0 16px; font-size: 15px; }
/* dealer / page / date / draw / product — two per row */
html.ui-mobile .top-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
html.ui-mobile .top-inputs .hc-dealer { grid-column: 1 / -1; }
html.ui-mobile .hc-field { display: flex; flex-direction: column; gap: 3px; }
html.ui-mobile .hc-field input,
html.ui-mobile .hc-field select { width: 100%; min-height: var(--m-touch); }

html.ui-mobile #view-entry .entry-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  overflow: visible; padding: 10px; align-items: end;
}
html.ui-mobile #view-entry .entry-row > * { min-width: 0; }
/* .entry-row children are fixed in index.html, in this order:
   1 Box Type · 2 Selection 1 · 3 Selection 2 · 4 Amount · 5 Filter · 6 Submit
   7 Next Column · 8 New Sheet.
   Full-width rows for the ones that need the room; the rest pair up 2-per-row.
   Selection 1 must be full width — it shares its row with the R and # buttons. */
html.ui-mobile #view-entry .entry-row > :nth-child(1),
html.ui-mobile #view-entry .entry-row > :nth-child(2),
html.ui-mobile #view-entry .entry-row > :nth-child(5),
html.ui-mobile #view-entry .entry-row > :nth-child(6) { grid-column: 1 / -1; }
html.ui-mobile #view-entry .field { min-width: 0; }
html.ui-mobile #view-entry .field input,
html.ui-mobile #view-entry .field select { width: 100%; min-width: 0; height: var(--m-touch); }
html.ui-mobile #view-entry .sel1-wrap { display: flex; gap: 6px; }
html.ui-mobile #view-entry .sel1-wrap input { flex: 1 1 auto; width: auto; }
html.ui-mobile #view-entry .r-btn { width: var(--m-touch); height: var(--m-touch); flex: 0 0 auto; font-size: 17px; }
html.ui-mobile #view-entry .parity { display: flex; width: 100%; min-width: 0; height: var(--m-touch); }
html.ui-mobile #view-entry .parity-btn { flex: 1 1 0; min-width: 0; height: var(--m-touch); padding: 0; }
html.ui-mobile #view-entry .btn-act { height: var(--m-touch); width: 100%; }
html.ui-mobile #view-entry #submitBtn { grid-column: 1 / -1; font-size: 17px; }

html.ui-mobile #view-entry .sheet {
  display: grid; grid-auto-flow: column; grid-auto-columns: 88%;
  gap: 8px; padding: 0 10px 12px;
  overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
html.ui-mobile #view-entry .column { scroll-snap-align: center; }
html.ui-mobile #view-entry .col-list { max-height: 46vh; overflow-y: auto; }
html.ui-mobile #view-entry .info-row { margin: 0 10px 10px; flex-direction: column; align-items: stretch; gap: 6px; }
html.ui-mobile #view-entry .shortcuts { display: none; }   /* no physical keyboard on a phone */
html.ui-mobile #view-entry .dbstatus { text-align: right; }

/* ============ INSTALL (Add to Home Screen) INVITATION ============ */
html.ui-mobile .m-install {
  position: fixed; z-index: 125; left: 10px; right: 10px;
  bottom: calc(var(--m-tabs) + var(--m-safe-b) + 10px);
  background: #fff; border: 1px solid var(--pink-border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
html.ui-mobile .m-install[hidden] { display: none; }
html.ui-mobile .m-install .m-install-txt { flex: 1 1 auto; font-size: 13px; color: #333; line-height: 1.35; }
html.ui-mobile .m-install .m-install-txt b { color: var(--red); display: block; font-size: 14px; }
html.ui-mobile .m-install button { min-height: 38px; padding: 0 12px; font-size: 14px; }

/* ============ MISC ============ */
html.ui-mobile .muted { font-size: 13px; }
html.ui-mobile .edit-banner { margin: 0 10px; }
html.ui-mobile .pe-sheet { padding-bottom: 12px; }
html.ui-mobile .pe-col { flex: 0 0 82%; }
