/* ECG GroupSync — layout layer: fluid width on every screen + mobile rules. Loaded after shared.css. */
/* Pages use the full available width (shell gives them the whole area next to the sidebar). */
.page-wrap { max-width: none; padding-left: clamp(14px, 2.2vw, 40px); padding-right: clamp(14px, 2.2vw, 40px); }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
/* Inside the shell frame the page has no topbar/sidebar of its own. */
body.embedded { --nav-h: 0px; --sidebar-w: 0px; }
body.embedded .sticky-head { top: 0; }

@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 15px; padding-bottom: env(safe-area-inset-bottom); overflow-x: hidden; }
  .app-nav { padding: 0 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

  /* Page shell */
  .page-wrap { padding: 14px 12px 56px; }
  .page-head { margin-bottom: 12px; gap: 8px; }
  .page-title { font-size: 20px; }
  .page-head .spacer { flex-basis: 100%; height: 0; }
  .page-head .btn, .page-head .export-wrap { flex: 1 1 auto; }
  .page-head .export-wrap .btn { width: 100%; }
  .export-menu { right: auto; left: 0; }

  /* Touch-friendly controls; 16px inputs stop iOS zooming on focus */
  .btn, .btn--sm { min-height: 40px; }
  input, select, textarea, .field input, .field select, .field textarea, .search-box input { font-size: 16px !important; }
  .field input, .field select { min-height: 42px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
  .form-grid { grid-template-columns: 1fr; }

  /* Toolbar: search on its own line, filters side by side */
  .toolbar { gap: 8px; }
  .search-box { flex: 1 1 100%; min-width: 0; }
  .toolbar select { flex: 1 1 0; min-width: 0; max-width: 100%; }
  .tag-filter-wrap { flex: 1 1 0; min-width: 0; }
  .tag-filter-btn { width: 100%; justify-content: space-between; min-height: 40px; }
  .toolbar { position: relative; }
  .tag-filter-wrap { position: static; }
  .tag-filter-pop { left: 0; right: 0; width: auto; max-width: none; }

  /* Dialogs become full-width sheets */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-overlay .modal { max-width: none; width: 100%; border-radius: 16px 16px 0 0; max-height: 94vh; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .modal-close { width: 40px; height: 40px; }
  .cropper { justify-content: center; }
  .contact-row { flex-wrap: wrap; }
  .contact-row select { width: 100%; }

  /* Tables: horizontal scroll by default … */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.tbl thead th { position: static; }
  table.tbl { min-width: 560px; }

  /* … but the member directory becomes a list of cards */
  table.tbl-cards { min-width: 0; }
  table.tbl-cards thead { display: none; }
  table.tbl-cards, table.tbl-cards tbody { display: block; }
  .table-wrap:has(table.tbl-cards) { overflow: visible; background: none; border: 0; box-shadow: none; }
  table.tbl-cards tbody tr.viewable { display: block; position: relative; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 12px; padding: 12px 44px 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
  table.tbl-cards tbody tr.viewable.mine { box-shadow: inset 3px 0 0 var(--accent, var(--brand)); }
  table.tbl-cards tbody tr.viewable:active { background: var(--surface-alt); }
  table.tbl-cards tbody tr.viewable td { display: block; padding: 0; border: 0; }
  table.tbl-cards td.col-division { display: none !important; }
  table.tbl-cards td.col-company { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
  table.tbl-cards td.col-email, table.tbl-cards td.col-phone { margin-top: 6px; font-size: 14px; word-break: break-all; }
  table.tbl-cards td.col-email a, table.tbl-cards td.col-phone a { display: inline-block; padding: 4px 0; }
  table.tbl-cards td.col-tags { margin-top: 8px; }
  table.tbl-cards td.col-tags:not(:has(.chip)) { display: none; }
  table.tbl-cards td.col-email:has(> .muted-text), table.tbl-cards td.col-phone:has(> .muted-text) { display: none; }
  table.tbl-cards td.cell-actions { position: absolute; top: 6px; right: 4px; }
  table.tbl-cards tr.group-sep { display: block; }
  table.tbl-cards tr.group-sep td { display: block; padding: 10px 2px 6px; font-weight: 600; color: var(--text-muted); border: 0; }
  table.tbl-cards tr.load-more-sentinel, table.tbl-cards tr.load-more-sentinel td { display: block; }

  /* Row action menu / user menu never wider than the screen */
  .row-menu, .user-menu { max-width: calc(100vw - 16px); }
  .user-menu { min-width: 200px; }

  /* Portal-access page list */
  #userlist { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .u-table { min-width: 520px; }

  /* ── App feel (phones) ─────────────────────────────────── */
  body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain; }
  .page-wrap { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 22px; letter-spacing: -.01em; }
  .count-pill { font-size: 12px; }
  /* search + filters stay pinned at the top of the list while scrolling */
  .sticky-head { display: contents; }
  .toolbar { position: sticky; top: 0; z-index: 20; background: var(--body-bg); margin: 0 -12px 10px; padding: 8px 12px; box-shadow: 0 1px 0 var(--border-soft); }
  .search-box input { height: 46px; font-size: 16px; }
  /* secondary actions: compact chips; "Add member" becomes a floating button */
  .page-head .btn--sm { min-height: 36px; font-size: 13px; padding: 0 12px; flex: 0 0 auto; }
  #add-btn { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30; height: 52px; padding: 0 22px; border-radius: 26px; font-size: 15px; font-weight: 700; box-shadow: 0 6px 18px rgba(0,0,0,.28); }
  body.embedded #add-btn { bottom: calc(18px + env(safe-area-inset-bottom)); }
  /* richer member cards */
  table.tbl-cards tbody tr.viewable { padding: 14px 48px 12px 14px; border-radius: 14px; }
  table.tbl-cards .avatar-img, table.tbl-cards .avatar-ini { width: 46px; height: 46px; font-size: 15px; }
  table.tbl-cards .namecell { gap: 12px; }
  table.tbl-cards .namecell .nname { font-size: 16px; }
  table.tbl-cards .namecell .njob { font-size: 13px; }
  table.tbl-cards td.col-company { margin: 8px 0 0 58px; font-size: 13px; }
  table.tbl-cards td.col-email, table.tbl-cards td.col-phone { margin: 4px 0 0 58px; }
  table.tbl-cards td.col-email a::before { content: "\2709\00a0\00a0"; color: var(--text-muted); }
  table.tbl-cards td.col-phone a::before { content: "\260E\00a0\00a0"; color: var(--text-muted); }
  table.tbl-cards td.col-phone a { color: var(--brand) !important; }
  table.tbl-cards td.col-tags { margin-left: 58px; }
  /* Admin lists: roomier rows, no hover-only affordances */
  .table-wrap { border-radius: 14px; }
  table.tbl tbody td { padding: 12px; }

  /* No visible scrollbars on phones: the page should feel like an app, not a framed box */
  html { scrollbar-width: none; }
  ::-webkit-scrollbar { width: 0; height: 0; display: none; }
}

/* No pinch/double-tap zoom: app-like on phones and tablets. */
html, body { touch-action: pan-x pan-y; }
