/* mobile.css — P234-PWA: responsive layer for the console. Loaded after the inline styles.
   Rules of the layer, on phones/tablets (≤840px):
   1. Nothing is wider than the screen: page never scrolls sideways; wide TABLES scroll inside their card.
   2. Inline pixel widths / min-widths from older screens are neutralised; grids collapse to one column.
   3. Nav: ☰ drawer + bottom tab bar (mobile-nav.js) instead of the 40-item strip.
   4. 40px touch targets, 16px inputs (no iOS zoom), safe-area aware. */
html { -webkit-text-size-adjust: 100%; }
* { -webkit-tap-highlight-color: transparent; }
.card { max-width: 100%; }
.wide { grid-column: span 2; }
#mnav-title, #mnav-btn, #mtabs { display: none; }

@media (max-width: 840px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  body { font-size: 14px; }
  #shell.on { grid-template-columns: 1fr; max-width: 100vw; }

  /* ---- top bar ---- */
  aside { position: sticky; top: 0; z-index: 50; height: auto; flex-direction: row; align-items: center; flex-wrap: nowrap;
          padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px; gap: 8px; overflow: hidden; }
  aside .brand { padding: 0 4px; font-size: 18px; white-space: nowrap; flex: 0 0 auto; }
  #nav { display: none; }
  #mnav-title { display: block; flex: 1; min-width: 0; color: #fff; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
  #mnav-btn { display: block; flex: 0 0 auto; width: 40px; height: 40px; border: 0; border-radius: 10px; background: rgba(255,255,255,.1); color: #fff; font-size: 20px; padding: 0; }
  aside .foot { display: none; }
  #joy-chip { margin: 0; padding: 4px 8px; font-size: 11px; line-height: 1.2; white-space: nowrap; flex: 0 0 auto; }
  #joy-chip b { font-size: 12px; }
  #joy-chip br { display: none; }
  #pwa-install { flex: 0 0 auto; width: auto; padding: 6px 10px; font-size: 12px; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; color: #fff; }
  #vdock { display: none; }

  /* ---- bottom tab bar ---- */
  #mtabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--forest-deep); border-top: 1px solid rgba(255,255,255,.12);
           padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px)); }
  #mtabs button { flex: 1; background: none; border: 0; color: #BFCEC2; font-size: 11px; font-weight: 600; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; border-radius: 10px; min-height: 48px; }
  #mtabs button span { font-size: 20px; line-height: 1; }
  #mtabs button.on { color: #fff; background: rgba(255,255,255,.12); }

  /* ---- drawer ---- */
  #mdrawer { position: fixed; inset: 0; z-index: 9400; background: rgba(20,30,25,.5); display: flex; justify-content: flex-end; }
  #mdrawer .panel { width: min(320px, 86vw); height: 100%; background: var(--card); display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,.3); }
  #mdrawer .head { display: flex; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 8px; font: 700 20px var(--display); color: var(--forest); }
  #mdrawer .head button { width: 40px; height: 40px; border: 0; background: var(--sage); border-radius: 10px; font-size: 16px; }
  #mdrawer input { margin: 4px 12px 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
  #mdrawer-list { flex: 1; overflow-y: auto; padding: 0 8px; -webkit-overflow-scrolling: touch; }
  #mdrawer-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 12px; font-size: 15px; color: var(--ink); border-radius: 10px; min-height: 44px; }
  #mdrawer-list button.on { background: var(--sage); color: var(--forest); font-weight: 600; }
  #mdrawer .foot { padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
  #mdrawer .foot button { width: 100%; padding: 10px; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; font-size: 14px; }

  /* ---- content: never wider than the screen ---- */
  main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom, 0px)); max-width: 100vw; overflow-x: hidden; }
  main * { max-width: 100%; box-sizing: border-box; }
  main table { max-width: none; }                            /* tables may be wide … */
  .card, .tblwrap { overflow-x: auto; }                        /* … but scroll inside their card */
  main [style*="min-width"] { min-width: 0 !important; }
  main [style*="width:"][style*="px"]:not(table):not(canvas):not(img):not(svg) { width: auto !important; max-width: 100%; }
  main [style*="grid-template-columns"]:not(.sp-dialpad) { grid-template-columns: 1fr !important; }
  main .sp-dialpad { grid-template-columns: repeat(3, 1fr) !important; }
  main .sp-key, main .sp-round, main .sp-side { max-width: none; }
  main [style*="columns:"] { columns: 1 !important; }
  canvas, img, svg, video, iframe { max-width: 100%; height: auto; }
  .wide { grid-column: span 1; }
  .screen-title { font-size: 22px; }
  .screen-sub { margin-bottom: 12px; }
  .card { padding: 14px 14px; margin-bottom: 12px; border-radius: 12px; }
  td { max-width: 220px; }
  th, td { padding: 9px 10px; }
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar > * { min-width: 0; max-width: 100%; }
  .toolbar input, .toolbar select { flex: 1 1 140px; }
  .toolbar input[type="file"] { flex: 1 1 100%; }
  .toolbar .grow { flex: 1 1 0; }
  input, select, textarea { font-size: 16px; padding: 9px 10px; border-radius: 8px; }
  .btn, button.btn { min-height: 40px; padding: 8px 14px; }
  #login { margin: 8vh auto; }

  /* ---- floating things ---- */
  #vpanel, #vtoast { left: 8px !important; right: 8px !important; width: auto !important; max-width: none; }
  #vpanel { bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important; }
  #joy-toasts { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); width: calc(100% - 24px); }
  .joy-toast { max-width: 100%; }
  #joy-pal { padding-top: 6vh; }
}
