/* Shared screen geometry. Keep text alignment and each component's overlay
   lifecycle intact; only the presentation of pages and dialogs is centered. */
@media screen {
  :root {
    --ui-dialog-gutter: 24px;
    --ui-dialog-radius: var(--tdf-radius-lg, 18px);
    --ui-dialog-height: var(--tdf-visible-viewport-height, 100dvh);
    --ui-dialog-top: var(--tdf-visible-viewport-top, 0px);
    --ui-dialog-room: calc(var(--ui-dialog-height) - 2 * var(--ui-dialog-gutter));
  }

  /* Existing page widths remain appropriate to their content, with equal
     margins inside the available workspace (including the admin sidebar). */
  body :is(.admin-wrap, .customer-main, .sale-main, .promotion-main,
           .customer-login-layout, .kitchen-head, .kitchen-footer) {
    margin-inline: auto;
    min-inline-size: 0;
  }

  /* Native dialogs share the same outer spacing. Fullscreen media remains
     fullscreen, while compact keyboard positioning stays component-owned. */
  body dialog:not(.is-fullscreen):not(#photo-viewer):not(#recipe-photo) {
    inset-inline: 50vw auto;
    margin-inline: 0;
    transform: translateX(-50%);
    max-inline-size: calc(100% - 2 * var(--ui-dialog-gutter));
    max-block-size: min(var(--ui-dialog-room), calc(var(--v14-visual-height, 100dvh) - 12px));
    border-radius: var(--ui-dialog-radius);
  }

  /* Equal space on every side replaces the edge-anchored product/cart drawer.
     Separate header, scrolling body and action rows remain unchanged. */
  html body.web-order.quick-order-open #product-page,
  html body.web-order #cart-panel,
  html body :is(.sf-purpose-panel, .sku-share-panel, .support-dialog) {
    box-sizing: border-box;
    position: fixed;
    inset: auto;
    inset-block: calc(var(--ui-dialog-top) + var(--ui-dialog-height) / 2) auto;
    inset-inline: 50% auto;
    margin: 0;
    transform: translate(-50%, -50%);
    max-inline-size: calc(100% - 2 * var(--ui-dialog-gutter));
    max-block-size: var(--ui-dialog-room);
    border: 1px solid var(--tdf-border, #d8e1db);
    border-radius: var(--ui-dialog-radius);
    box-shadow: var(--tdf-shadow-sheet, 0 24px 64px #0d25183d);
  }

  html body.web-order.quick-order-open #product-page {
    inline-size: min(1120px, calc(100% - 2 * var(--ui-dialog-gutter)));
    block-size: min(880px, var(--ui-dialog-room));
    height: min(880px, var(--ui-dialog-room));
    padding: 0;
  }

  html body.web-order #cart-panel {
    inline-size: min(760px, calc(100% - 2 * var(--ui-dialog-gutter)));
    block-size: min(880px, var(--ui-dialog-room));
    height: min(880px, var(--ui-dialog-room));
    padding: 0;
    visibility: hidden;
    pointer-events: none;
    transition: none;
  }
  html body.web-order #cart-panel.open {
    transform: translate(-50%, -50%);
    visibility: visible;
    pointer-events: auto;
  }

  html body .sf-purpose-panel {
    inline-size: min(900px, calc(100% - 2 * var(--ui-dialog-gutter)));
    height: min(800px, var(--ui-dialog-room));
  }
  html body :is(.sku-share-panel, .support-dialog) {
    height: fit-content;
    max-height: var(--ui-dialog-room);
  }

  @media (min-width: 1000px) and (min-height: 521px) {
    html body.purchase-refined.web-order.quick-order-open #product-page .product-layout {
      grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr);
      align-items: start;
      gap: 28px;
      padding: 8px;
    }
    html body.purchase-refined.web-order.quick-order-open #product-page .v21-main-photo {
      height: clamp(260px, 38dvh, 400px);
      block-size: clamp(260px, 38dvh, 400px);
      max-block-size: none;
    }
  }

  @media (max-width: 700.98px), (max-height: 520px) {
    :root {
      --ui-dialog-gutter: max(8px, env(safe-area-inset-top), env(safe-area-inset-bottom),
                                  env(safe-area-inset-left), env(safe-area-inset-right));
      --ui-dialog-radius: 14px;
    }
    /* Mobile editor uses the same inset surface as the storefront dialogs. */
    body .sku-editor-dialog {
      width: calc(100% - 2 * var(--ui-dialog-gutter));
      height: var(--ui-dialog-room);
      margin: auto;
    }
  }
}

/* A standalone product uses a content row and a separate buying row on PC too.
   This keeps thumbnails and disclosure buttons above the action bar. */
@media screen and (min-width:701px) {
  html.sf-root:has(body.sf-enhanced.web-order--product) { height:100%; overflow:hidden; }
  html body.sf-enhanced.web-order--product {
    display:grid; grid-template-rows:minmax(0,1fr) auto;
    height:100svh; min-height:0; width:100%; margin:0; padding:0; overflow:hidden;
  }
  html body.sf-enhanced.web-order--product .sf-page-scroll {
    grid-row:1; min-height:0; overflow:auto; scrollbar-gutter:stable;
    overscroll-behavior-y:contain; scroll-padding:24px; padding-bottom:16px;
  }
  html body.sf-enhanced.web-order--product .main-head { position:static!important; }
  html body.sf-enhanced.web-order--product>.sf-product-dock {
    grid-row:2; position:static!important; inset:auto; display:grid;
    grid-template-columns:minmax(0,.85fr) minmax(0,1.15fr); align-items:center; gap:12px;
    box-sizing:border-box; width:min(1280px,100%); min-width:0; justify-self:center;
    margin:0; padding:12px 24px max(12px,env(safe-area-inset-bottom));
    border:0; border-top:1px solid var(--tdf-border); border-radius:0;
    background:var(--tdf-surface); box-shadow:none;
  }
  html body.sf-enhanced.web-order--product>.sf-product-dock .variant-submit-meta { margin:0; display:grid; gap:2px; }
  html body.sf-enhanced.web-order--product>.sf-product-dock .product-buy-actions { min-width:0; }
  html body.sf-enhanced.web-order--product>.sf-product-dock .product-buy-actions>button { min-width:0; }
}
@media screen {
  html body .main-head>.support-launcher--inline {
    position:static; inset:auto; transform:none; grid-column:1/-1; justify-self:end;
    margin:0; min-height:44px; padding:8px 12px; border-radius:8px; box-shadow:none;
  }
}

/* Let every table column scroll into view on phones instead of leaving a
   frozen name column over its sort, stock or edit controls. */
@media screen and (max-width:700px) {
  html body.admin-body .admin-data-list table.adl-table :is(th,td).adl-pinned {
    position:relative; inset:auto; z-index:auto; box-shadow:none;
  }
}

@media screen {
  /* Admin list tables own their header layout, including at card breakpoints. */
  html body.admin-body .admin-data-list table.adl-table thead {
    clip-path:none; clip:auto; width:auto; height:auto; overflow:visible;
  }
  /* Saving stays in document flow rather than covering the last filter/row. */
  html body.admin-body .ba-savebar { position:static; inset:auto; box-shadow:none; }
}

@media screen {
  /* Gift preview/detail dialogs follow the same centered surface as ordering. */
  html body[data-gift-realm] #modal { inset:0; margin:auto; }
}

@media screen and (max-width:700px) {
  /* Frozen header/filter rows take most of a short phone viewport. Let them
     scroll with the table so record links can always enter the free area. */
  html body.admin-body .admin-data-list table.adl-table thead :is(th,td) {
    position:relative; inset:auto; z-index:auto;
  }
}

/* Action rows are already outside scrolling content. Large page scroll margins
   must not make Chromium scroll the outer shell when these buttons gain focus. */
@media screen {
  html body.web-order>.sf-product-dock { --ui-scroll-clearance:0px; }
}
@media screen and (max-width:700px) and (max-height:360px) {
  html body.web-order { --ui-scroll-clearance:8px; }
}
