/* =================== PHONES & SMALL TABLETS ===================
   Everything stays usable with no sideways scrolling. The PDF/print layout
   (.cert.print) is deliberately left untouched so certificates stay A4. */
.tbl-tools { display: none; }

@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  body { padding-bottom: env(safe-area-inset-bottom); }

  /* top bar */
  .topbar { gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar .lbl, .who .nm, .logo small, .mode-pill { display: none !important; }
  .topbar .btn { padding: 8px 10px; }
  .sync-pill { height: 34px; padding: 0 10px; font-size: 12px; }
  .sync-pill span:not(.spin) { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  .locked-banner.pending { flex-wrap: wrap; }
  .logo { min-width: 0; }
  .logo b { font-size: 17px; }
  .who { gap: 6px; }
  main { padding: 14px 12px 90px; }

  /* page headers, filters, stats */
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 24px; }
  .page-head > .btn { width: 100%; justify-content: center; }
  .toolbar { gap: 8px; }
  .toolbar .tabs { width: 100%; }
  .toolbar .tabs button { flex: 1; padding: 8px 4px; }
  .toolbar select, #fsite { flex: 1 1 calc(50% - 4px); min-width: 0; max-width: none; }
  .search { flex: 1 1 100%; min-width: 0; }
  .stats { gap: 8px; margin-bottom: 14px; }
  .stat { padding: 12px; }
  .stat .n { font-size: 22px; }
  .stat .l { font-size: 12px; }

  /* sheet list rows */
  .sheet-row { gap: 4px 10px; padding: 12px 12px 12px 0; }
  .sheet-row .acts .btn { font-size: 0; padding: 9px; gap: 0; }
  .sheet-row .acts .btn svg { width: 18px; height: 18px; }
  .sheet-row .cust { min-width: 0; }
  .sheet-row .cust span { white-space: normal; }
  .site-tag { margin-bottom: 2px; }

  /* editor toolbar */
  .ed-bar { position: static; margin: 0 0 12px; padding: 4px 0 0; background: none; gap: 10px; }
  .ed-title { flex: 1 1 calc(100% - 60px); }
  .ed-title h2 { font-size: 17px; white-space: normal; }
  .ed-title small { white-space: normal; }
  #vt { width: 100%; }
  #vt button { flex: 1; }
  .ed-bar .spacer { display: none; }
  .ed-acts { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .ed-acts .btn { justify-content: center; padding: 10px 6px; font-size: 13px; min-width: 0; }
  .ed-acts .btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ed-acts #b-done { grid-column: 1 / -1; padding: 13px; font-size: 15px; }
  .locked-banner { font-size: 13px; }

  /* form view */
  .fv { gap: 12px; }
  .fv-sec > h3 { padding: 12px 14px; }
  .fv-grid { padding: 14px; gap: 12px; }
  .fv input, .fv select, .fv textarea, .modal input, .modal select, .modal textarea,
  .search input, .toolbar select, .field input { font-size: 16px; }   /* stops iPhone zooming in */
  .fv-f.pfrow .seg, .cc.pfc .ticks { width: 100%; }
  .fv-f.pfrow .seg { display: flex; }
  .seg button { flex: 1; padding: 10px 6px; }

  /* tables become stacked cards (form + editable certificate views) */
  .fv table, .fv tbody, .fv tr, .fv td,
  .cert:not(.print) table, .cert:not(.print) tbody, .cert:not(.print) tr, .cert:not(.print) td { display: block; width: 100% !important; }
  .fv thead, .cert:not(.print) thead { display: none; }
  .tbl-wrap { overflow: visible; }
  .fv tr, .cert:not(.print) tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 10px; position: relative;
    padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg2); }
  .cert:not(.print) tr { background: #f7f9fd; border-color: #c9cfdb; }
  .fv td, .cert:not(.print) td { padding: 0; border: 0; height: auto; min-width: 0; }
  .fv td.wide, .cert:not(.print) td.wide { grid-column: 1 / -1; }
  .fv td::before, .cert:not(.print) td::before { content: attr(data-l); display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
  .cert:not(.print) td::before { color: #5b6478; text-transform: uppercase; letter-spacing: .3px; font-size: 9.5px; }
  .fv td.rx, .cert:not(.print) td.rx { position: absolute; top: 2px; right: 2px; width: auto !important; }
  .fv td.rx::before, .cert:not(.print) td.rx::before { content: none; }
  .fv tr:has(td.rx) td:first-child, .cert:not(.print) tr:has(td.rx) td:first-child { padding-right: 26px; }
  .fv td input, .fv td select, .fv td .seg { display: flex; width: 100%; }
  .fv td input, .fv td select { display: block; }
  .cert:not(.print) td input, .cert:not(.print) td select { display: block; width: 100%; background: #fff; border: 1px solid #c9cfdb; border-radius: 6px; padding: 8px; font-size: 16px; color: #141a26; }
  .cert:not(.print) td input:focus, .cert:not(.print) td select:focus { border-color: var(--accent); background: #fffdf2; outline: none; }
  .cert:not(.print) td .val { min-height: 18px; }
  .tbl-tools { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 13px; color: var(--muted); }
  .tbl-tools .bulk { font-size: 13px; padding: 6px 12px; margin: 0; }
  .add-row { width: 100%; justify-content: center; padding: 10px; }

  /* certificate view: reflows to the screen (the PDF stays A4) */
  .cert-stage { overflow: visible; margin: 0; padding: 0 0 20px; }
  .cert:not(.print) { width: 100%; min-height: 0; padding: 16px 12px 14px; border-radius: 12px; font-size: 13px; }
  .cert:not(.print) .cert-head { flex-direction: column; gap: 10px; }
  .cert:not(.print) .cert-ttl { text-align: left; max-width: none; }
  .cert:not(.print) .cert-co { align-items: flex-start; }
  .cert:not(.print) .cert-co img { height: 56px; }
  .cert:not(.print) .cert-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .cert:not(.print) .cc.s2, .cert:not(.print) .cc.s3, .cert:not(.print) .cc.s4 { grid-column: 1 / -1; }
  .cert:not(.print) .cc.pfc { flex-wrap: wrap; }
  .cert:not(.print) .cc input, .cert:not(.print) .cc select, .cert:not(.print) .cc textarea { font-size: 16px; padding: 6px; }
  .cert:not(.print) .ticks { flex-wrap: wrap; gap: 8px; }
  .cert:not(.print) .ticks button, .cert:not(.print) .ticks span { font-size: 12px; padding: 4px 2px; }
  .cert:not(.print) .ticks i { width: 16px; height: 16px; }
  .cert:not(.print) .cert-foot { flex-direction: column; gap: 4px; }

  /* modals & admin */
  .modal-bg { padding: 10px; align-items: end; }
  .modal { padding: 20px 16px; border-radius: 18px; max-height: 94vh; }
  .modal .foot { flex-wrap: wrap; }
  .modal .foot .btn { flex: 1 1 auto; justify-content: center; }
  .pw-row { flex-wrap: wrap; }
  .pw-row input { flex: 1 1 100%; }
  .pw-row .btn { flex: 1; justify-content: center; }
  .user-row { padding: 12px; gap: 8px 12px; }
  .user-row .acts { display: flex; flex-wrap: wrap; gap: 6px; }
  .user-row .acts .btn { flex: 1 1 auto; justify-content: center; }
  .u-main { min-width: 0; }
  .u-email { overflow-wrap: anywhere; }
  .backup-row .u-main b { overflow-wrap: anywhere; font-size: 14px; }
  .doc-view iframe { height: 70vh; }
  .glass { padding: 30px 20px 24px; }
  .toasts { left: 12px; right: 12px; transform: none; }
  .toast { text-align: center; }
}

@media (max-width: 480px) {
  .fv-grid { grid-template-columns: minmax(0, 1fr); }
  .fv-f, .fv-f.s2, .fv-f.s3, .fv-f.s4 { grid-column: 1 / -1; }
  .cert:not(.print) .cert-grid { grid-template-columns: minmax(0, 1fr); }
  .cert:not(.print) .cc { grid-column: 1 / -1; }
  .types { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .type-tile { padding: 14px 12px; }
  .type-tile span { font-size: 12px; }
}
