/* ============================================================
   mobile.css — responsive + touch layer for FNSKU Label Generator
   Loaded after the app's own <style> block so it wins on cascade.
   Nothing here changes the printed label, only the app chrome.
   ============================================================ */

/* Respect notches / gesture bars on phones and in the Android wrapper */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* Hamburger button — injected by platform.js, hidden on desktop */
#nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  margin-right: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
#nav-toggle:hover { background: var(--border); }

/* Backdrop behind the off-canvas sidebar */
#nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
body.nav-open #nav-backdrop { opacity: 1; pointer-events: auto; }

/* ---------- Tablet and below ---------- */
@media (max-width: 1100px) {
  /* Create page: preview drops under the form instead of a fixed 400px rail.
     minmax(0,1fr) rather than 1fr matters here: a bare 1fr track floors at the
     content's min-content width, and the live preview is a fixed 384px label,
     so the column would refuse to shrink below ~422px and push the whole form
     into a horizontal scroll. */
  #page-create > div {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #page-create > div > * { min-width: 0; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Phones / small tablets ---------- */
@media (max-width: 900px) {
  .shell { display: block; min-height: 100vh; }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 262px;
    max-width: 82vw;
    z-index: 900;
    transform: translateX(-102%);
    transition: transform .24s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .5);
    padding-top: env(safe-area-inset-top);
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }

  #nav-toggle { display: flex; }

  .main { min-height: 100vh; overflow: visible; }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 700;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    gap: 10px;
  }
  .topbar h1 { font-size: 15px; }
  /* The version string eats the whole row on a phone */
  .topbar-meta { display: none; }

  .content {
    padding: 14px;
    padding-bottom: calc(26px + env(safe-area-inset-bottom));
    overflow: visible;
  }

  /* One column forms — two 50% fields are unusable at 360px */
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 15px 16px; }

  /* 16px inputs stop iOS/Android from zooming on focus */
  input, select { font-size: 16px; padding: 11px 12px; }
  .qty-row input { width: 68px; }
  .qty-btn { width: 38px; height: 38px; font-size: 18px; }

  /* Comfortable touch targets */
  .btn { padding: 11px 16px; font-size: 14px; }
  .btn-sm { padding: 9px 13px; font-size: 13px; }
  .btn-row .btn { flex: 1 1 auto; justify-content: center; }
  .nav-item { padding: 12px 11px; font-size: 14px; }
  .tog { padding: 3px 0; }
  .tog-box { width: 21px; height: 21px; }

  /* Size picker: three equal cards that wrap cleanly */
  .size-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .sz-btn { padding: 10px 6px; font-size: 11px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 22px; }

  /* ---- Tables become stacked cards -------------------------------------
     A 7-column table at 360px can only be a sideways scroll, and the Actions
     column ends up permanently off screen. So each row becomes a card with the
     column name printed beside its value.

     platform.js copies each column heading onto its cells as data-label, and
     re-declares the ARIA roles that display:block strips off table elements,
     so this stays a real table for a screen reader. */
  .table-wrap { -webkit-overflow-scrolling: touch; overflow: visible; }
  .table-wrap table { min-width: 0; display: block; }

  /* Visually hidden, but still in the accessibility tree */
  .table-wrap thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .table-wrap tbody { display: block; }

  .table-wrap tbody tr {
    display: block;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 12px;
    margin-bottom: 9px;
  }
  .table-wrap tbody tr:last-child { margin-bottom: 0; }
  .table-wrap tbody tr:hover td { background: transparent; }

  .table-wrap tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 5px 0;
    border-bottom: none;
    text-align: right;
  }

  .table-wrap tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--text3);
    text-align: left;
  }
  /* "No labels saved yet" and other full-width cells get no label chip */
  .table-wrap tbody td:not([data-label]) {
    display: block;
    text-align: center;
  }
  .table-wrap tbody td:not([data-label])::before { content: none; }

  /* The Actions cell holds buttons, so give them room */
  .table-wrap tbody td .actions { flex-wrap: wrap; justify-content: flex-end; }

  .modal { padding: 18px; width: 100%; border-radius: 14px; }
  .modal-foot .btn { flex: 1; justify-content: center; }

  #toast {
    left: 14px;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    max-width: none;
  }

  .csv-drop { padding: 22px 14px; }
  .bulk-grid { grid-template-columns: 1fr; }
}

/* ---------- Narrow phones ---------- */
@media (max-width: 400px) {
  .content { padding: 11px; }
  .card { padding: 13px 13px; }
  .stats-grid { grid-template-columns: 1fr; }
}

/* ---------- Running as an installed app / inside the Android wrapper ---------- */
/* No text selection on chrome elements, so long-press feels native */
body.native-shell .nav-item,
body.native-shell .btn,
body.native-shell .sz-btn,
body.native-shell .card-title,
body.native-shell .topbar h1 {
  -webkit-user-select: none;
  user-select: none;
}
/* The wrapper prints through Android's print service, so hide nothing else */
body.native-shell #nav-toggle { display: flex; }

/* Never let the app's own print rule fight the Android print WebView */
@media print {
  #nav-toggle, #nav-backdrop { display: none !important; }
}
