/* DealerPulse — Phase 1 responsive navigation.
 * A bottom tab bar + slide-up drawer that REPLACE the desktop horizontal nav on
 * phones. Entirely gated behind max-width:768px, so the desktop app is untouched.
 * Built by mBuildNav() in js/app.js from the same RBAC-filtered tab set. */

/* Hidden by default (desktop). */
#m-bottomnav, #m-drawer, #m-drawer-scrim { display: none; }

@media (max-width: 768px) {
  /* Desktop horizontal nav off; bottom bar on. */
  #main-nav { display: none !important; }
  main.main { padding-bottom: 70px !important; }

  /* ── Bottom tab bar ── */
  #m-bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    background: #ffffff; border-top: 1px solid var(--v6-stroke, #B0B0B0);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -1px 8px rgba(31, 56, 100, .09);
  }
  #m-bottomnav .m-item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 7px 2px 6px; min-height: 56px;
    border: 0; background: none; cursor: pointer;
    color: #616161; font: 600 10px/1.1 var(--v6-font);
    text-align: center; -webkit-tap-highlight-color: transparent;
  }
  #m-bottomnav .m-item .m-ic { font-size: 20px; line-height: 1; }
  #m-bottomnav .m-item.on { color: #0F548C; font-weight: 600; background: #CCE0F5; box-shadow: inset 0 3px 0 var(--v6-action); }
  #m-bottomnav .m-item.on .m-ic { transform: translateY(-1px); }

  /* ── Drawer (bottom sheet) with every tab ── */
  #m-drawer-scrim {
    display: none; position: fixed; inset: 0; z-index: 1001;
    background: rgba(15, 27, 45, .45);
  }
  #m-drawer-scrim.open { display: block; }

  #m-drawer {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1002;
    background: #ffffff; border-radius: 16px 16px 0 0;
    max-height: 74vh; overflow-y: auto;
    transform: translateY(100%); transition: transform .22s ease;
    padding: 6px 0 calc(14px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 26px rgba(15, 27, 45, .28);
  }
  #m-drawer.open { transform: translateY(0); }
  #m-drawer .m-drawer-h {
    text-align: center; padding: 10px 12px 6px; color: #616161;
    font: 600 12px/1.2 var(--v6-font); letter-spacing: 0;
  }
  #m-drawer .m-drawer-h::before {
    content: ''; display: block; width: 40px; height: 4px; border-radius: 2px;
    background: #cbd5e1; margin: 0 auto 12px;
  }
  #m-drawer .m-row {
    display: flex; align-items: center; gap: 14px; width: 100%;
    padding: 14px 22px; border: 0; background: none; text-align: left; cursor: pointer;
    color: #242424; font: 500 15px/1.2 var(--v6-font);
  }
  #m-drawer .m-row .m-ic { font-size: 18px; width: 24px; text-align: center; }
  #m-drawer .m-row.on { color: #0F548C; font-weight: 600; background: #CCE0F5; box-shadow: inset 4px 0 0 var(--v6-action); }
  #m-drawer .m-row:active { background: #f1f5f9; }

  /* ── Phase 2: responsive tables → cards ──
   * A table tagged .rtable (by mAdaptTables() in js/app.js) becomes a stacked
   * list of cards on phones: header row hidden, each body row a card, each cell
   * a "Label: value" line (label from data-label). The first cell is the card
   * title. Desktop is unaffected (all of this lives inside the 768px query). */
  table.rtable { display: block; width: 100%; border: 0; }
  table.rtable thead { display: none; }
  table.rtable tbody { display: block; }
  table.rtable tr {
    display: block; background: #fff; border: 1px solid var(--v6-card-line, #BDBDBD); border-radius: 12px;
    margin: 0 0 10px; padding: 4px 14px; box-shadow: 0 1px 3px rgba(31, 56, 100, .06);
  }
  table.rtable td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    width: auto; padding: 8px 0; border: 0; border-bottom: 1px solid var(--v6-row, #D0D0D0);
    text-align: right; font-size: 14px; white-space: normal;
  }
  table.rtable td:last-child { border-bottom: 0; }
  table.rtable td::before {
    content: attr(data-label); flex: 0 1 auto; text-align: left;
    font: 600 11px/1.3 var(--v6-font); letter-spacing: 0; color: #616161;
  }
  /* First cell = the card's title (dealer / VIN / model), no label. */
  table.rtable td:first-child {
    justify-content: flex-start; text-align: left;
    font: 700 15px/1.25 var(--v6-font); color: var(--v6-action);
    padding: 10px 0 8px; border-bottom: 1px solid var(--v6-row, #D0D0D0);
  }
  table.rtable td:first-child::before { display: none; }
  /* Empty-label cells (e.g. action-button columns) drop the label chip. */
  table.rtable td[data-label=""]::before,
  table.rtable td:not([data-label])::before { content: ""; }

  /* Action cells (contain buttons/links/inputs) — the label:value flex cramps
   * buttons in portrait. Give them the full card width: label on its own line,
   * then the controls laid out left-aligned with room to wrap and stay tappable. */
  table.rtable td:has(button),
  table.rtable td:has(a),
  table.rtable td:has(input),
  table.rtable td:has(select) {
    display: block; text-align: left; padding: 8px 0;
  }
  table.rtable td:has(button)::before,
  table.rtable td:has(a)::before,
  table.rtable td:has(input)::before,
  table.rtable td:has(select)::before {
    display: block; margin-bottom: 7px;
  }
  table.rtable td button,
  table.rtable td .btn,
  table.rtable td a.btn,
  table.rtable td a,
  table.rtable td input[type="button"],
  table.rtable td input[type="submit"] {
    min-height: 40px; padding: 9px 15px; margin: 3px 8px 3px 0;
    display: inline-flex; align-items: center; justify-content: center;
    white-space: nowrap; font-size: 13px; line-height: 1;
  }
  /* Bare text-link actions (e.g. NaTIS file, "View in list") stay inline-friendly. */
  table.rtable td a { text-decoration: none; }

  /* ── Non-table wide layouts (RSM Report, Sales Dashboard summaries) ──
   * Side-by-side card grids (e.g. Heroes | Potential) are laid out with an inline
   * `grid-template-columns:1fr 1fr` (or 1fr 1fr 1fr) — their content forces the
   * row wider than a phone, causing horizontal scroll. Stack them to one column.
   * And the KPI tile strip (.sd-kpi-row) crams up to 7 tiles across → give it a
   * readable 2-per-row so the numbers aren't clipped. */
  main.main [style*="grid-template-columns:1fr 1fr"],
  main.main [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
  .sd-kpi-row { grid-template-columns: repeat(2, 1fr) !important; }
}

/* v6: the phone bar/drawer icons are SVG now */
#m-bottomnav .m-item .m-ic .v6-ic, #m-drawer .m-row .m-ic .v6-ic { width: 22px; height: 22px; }
