/* LAYOUT-POLISH-1 — layout corrections only (no redesign). Loaded LAST so it wins over earlier per-phase rules.
   Presentation only: no markup, data, handler or permission changes. Each block names the bug it fixes. */

/* (1) Hidden-but-displayed: `.toolbar { display:flex }` beat the [hidden] attribute, so the Email Designer's
   unfinished editor controls leaked out under the "Coming soon" card (unstyled input, select and panels). */
#view-email-designer [hidden], .toolbar[hidden] { display: none !important; }

/* (2) Products / Orders lean tables (>=861px): the fixed-layout first column (34-40px) and last column (48px)
   were narrower than their own cell padding + control, so the table was ~11px wider than its card: a hidden
   scrollbar appeared inside the card and clipped the right edge of the header. Give both columns room. */
@media screen and (min-width: 861px) {
  .dt-products:not(.show-all) thead th:first-child, .dt-orders:not(.show-all) thead th:first-child,
  #view-orders .dt-orders:not(.show-all) thead th:first-child { width: 44px !important; padding-left: 12px; padding-right: 4px; }
  .dt-products:not(.show-all) tbody td:first-child, .dt-orders:not(.show-all) tbody td:first-child { padding-left: 12px; padding-right: 4px; }
  .dt-lean th:last-child, .dt-lean td:last-child { width: 56px !important; padding-left: 8px; padding-right: 8px; }
  .dt-lean th:last-child { overflow: hidden; } /* header text is visually hidden (font-size:0); its box must not widen the table */
}

/* (3) Invoices toolbar: filters (left) and actions (right) wrapped into two left-aligned rows. Let the filters
   take the free space and keep the actions on the right edge, on whichever row they land. */
@media screen and (min-width: 861px) {
  #invoicesRoot .toolbar { align-items: center; }
  #invoicesRoot .edm-filters { flex: 1 1 auto; min-width: 0; }
  #invoicesRoot .edm-actions { margin-left: auto; flex: 0 0 auto; }
}

/* (4) Phones (<=860px): every list toolbar uses one pattern. Search is full width, filters sit two-up,
   primary actions fill the row. Products/Orders (own rules) and the dashboard are untouched. */
@media screen and (max-width: 860px) {
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar {
    display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 12px;
  }
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar-left,
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar-right {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%;
  }
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar .search-box { flex: 1 1 100%; width: 100%; min-width: 0; }
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar .filter-select { flex: 1 1 calc(50% - 4px); width: auto; min-width: 0; }
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar > .btn,
  #content .view:not(#view-products):not(#view-orders):not(#view-dashboard) .toolbar-right > .btn { flex: 1 1 100%; width: 100%; justify-content: center; }
  /* invoices: From/To dates share a row, secondary actions two-up, primary full width */
  #invoicesRoot .edm-date { flex: 1 1 100%; min-width: 0; display: flex; align-items: center; gap: 8px; }
  #invoicesRoot .edm-date input { min-width: 0; flex: 1; }
  #invoicesRoot .edm-actions .btn { flex: 1 1 calc(50% - 4px); }
  #invoicesRoot .edm-actions .btn-primary { flex-basis: 100%; }
}

/* (5) Orders / Products toolbar: search and filters only went full-width below 640px, so on tablets (641-860px,
   which already use the phone card layout) the search box stayed ~125px wide. Same rule, up to 860px. */
@media screen and (min-width: 641px) and (max-width: 860px) {
  #view-products .toolbar-left, #view-orders .toolbar-left { width: 100%; }
  #view-products .toolbar-left .search-box, #view-orders .toolbar-left .search-box { flex: 1 1 100%; }
  #view-products .toolbar-left .filter-select, #view-orders .toolbar-left .filter-select { flex: 1 1 calc(33% - 6px); min-width: 0; }
}

/* (6) Dashboard on phones/tablets: the setup-guide strip sat flush against the top bar. */
@media screen and (max-width: 860px) {
  #view-dashboard .hm-guide-bar, #view-dashboard .hm-guide-card { margin-top: 8px; }
}

/* (7) Modals: 90vh ignores the mobile browser's collapsing toolbars, so a tall modal could run under the
   address bar / home indicator. Use the dynamic viewport height and respect safe areas. */
@supports (height: 100dvh) {
  .modal { max-height: calc(100dvh - 40px); }
}
.modal-overlay { padding-bottom: max(20px, env(safe-area-inset-bottom)); padding-top: max(20px, env(safe-area-inset-top)); }
