/* CRM-MOBILE-20261101: root employee / management shell (dashboard and its panels) on a phone. Layout only; no function, handler, id or class is changed.
   Every rule sits inside a max-width query (820px and below), so desktop and wide tablets are untouched.
   Loaded after /css/rg-mobile.css (last stylesheet of the page); selectors carry #appView so they also beat the redesign stylesheet. */

@media screen and (max-width: 820px) {

  /* ---- frame ---- */
  #appView .workspace, #appView .view-panel, #appView .view-panel > * { min-width: 0; }
  #appView .workspace { padding-left: 12px; padding-right: 12px; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); overflow-wrap: break-word; }
  #appView .topbar { padding-top: max(10px, env(safe-area-inset-top, 0px)); gap: 8px; }
  #appView .topbar > div:first-child { min-width: 0; }
  #appView .mobile-menu-button { min-width: 44px; min-height: 44px; justify-content: center; padding: 0; font-size: 22px; }
  #appView .top-actions { gap: 8px; }
  #appView .top-actions > button { min-height: 44px; width: 100%; justify-content: center; }
  #appView .section-heading { flex-wrap: wrap; gap: 8px; }
  #appView .ghost-button, #appView .primary-button, #appView .danger-button { min-height: 44px; }

  /* ---- sidebar drawer: keep the existing slide-in, 44px rows ---- */
  #appView .sb { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom, 0px); }
  #appView.nav-open .sb { box-shadow: 14px 0 44px rgba(0, 0, 0, .5); }
  #appView .sb .ni { min-height: 44px; font-size: 14px; }
  #appView .sb .sb-close { min-width: 44px; min-height: 44px; }
  #appView .sb #logoutButton { min-height: 44px; }
  #appView .sb .rg-nav-search-wrap, #appView .sb .rg-nav-search-wrap input { min-height: 44px; }
  #appView .sb .rg-nav-search-wrap input { font-size: 16px; }
  #appView .sb [onclick*="rgOpenAbout"] { min-height: 44px; font-size: 12px !important; }

  /* ---- panels that kept a fixed two-column grid on a phone ---- */
  #appView .leader-command-panel, #appView .meeting-log-panel .form-grid, #appView .form-grid, #appView .split-layout { grid-template-columns: minmax(0, 1fr); }
  #appView .view-panel [style*="grid-template-columns"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)) !important; }
  #appView .leader-command-metrics { min-width: 0; }
  #appView .metric-grid { gap: 10px; }

  /* ---- tables: real table layout inside a horizontal scroller (the shared phone rule turned them into blocks and squeezed every column) ---- */
  #appView .table-wrap, #appView .data-table-wrap, #appView :is(div, section):has(> table), #appView :is(div, section):has(> div > table) { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  #appView table { display: table; min-width: 640px; }
  #appView table th { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
  #appView table td { overflow-wrap: break-word; word-break: normal; }
  #appView table td button { white-space: nowrap; }

  /* ---- inputs: 16px (no iOS zoom), 44px tall ---- */
  #appView input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]), #appView select, #appView textarea { font-size: 16px !important; }
  #appView input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]), #appView select { min-height: 44px; }
  #appView textarea { min-height: 96px; }
  #appView input[type="checkbox"], #appView input[type="radio"] { width: 24px; height: 24px; }
  #appView .filter-row, #appView .toolbar, #appView .lead-filters { flex-wrap: wrap; gap: 8px; }
  #appView .filter-row > *, #appView .toolbar > *, #appView .lead-filters > * { flex: 1 1 150px; min-width: 0; }
  #appView .chip, #appView .filter-chip, #appView [role="tab"], #appView .tab-button { min-height: 44px; }

  /* ---- dialogs (native dialog elements, outside the app shell): full-height sheet, action bar pinned ---- */
  html body dialog[open]:not(#rgm) { width: 100vw !important; max-width: 100vw !important; max-height: 100vh !important; max-height: 100dvh !important; margin: auto 0 0 0 !important; border-radius: 16px 16px 0 0 !important; box-sizing: border-box; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom, 0px); }
  html body dialog#leadDialog[open] { height: 100vh !important; height: 100dvh !important; border-radius: 0 !important; }
  dialog .form-grid, dialog .wide-grid { grid-template-columns: minmax(0, 1fr); }
  dialog [style*="grid-template-columns"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)) !important; }
  html body dialog :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not(#rgm) { font-size: 16px !important; }
  dialog input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]), dialog select { min-height: 44px; }
  dialog input[type="checkbox"], dialog input[type="radio"] { width: 24px; height: 24px; }
  html body dialog :is(button, .icon-button, [role="tab"]):not(#rgm) { min-height: 44px; min-width: 44px; }
  dialog .dialog-actions { position: sticky; bottom: 0; z-index: 3; flex-wrap: wrap; gap: 8px; background: #fff; padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  dialog .dialog-actions > button { flex: 1 1 140px; justify-content: center; }
  dialog .crm-leads-dlg-tabbar { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  dialog .crm-leads-dlg-tab { flex: 0 0 auto; }
  dialog .crm-leads-dlg-hero { flex-wrap: wrap; }
}

@media screen and (max-width: 480px) {
  #appView .workspace { padding-left: 10px; padding-right: 10px; }
}
