/* SenaPed 14.16: a compact catalog rhythm and a scrollable, content-sized menu.
   The app/id prefix intentionally wins over the legacy injected order styles. */
body #app #productGrid:not([data-view="list"]) {
  align-items: start;
  gap: 14px;
}

body #app #productGrid[data-view="compact"] { grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); }
body #app #productGrid[data-view="showcase"] { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }

body #app #productGrid:not([data-view="list"]) .product-card {
  min-height: 0;
  height: auto;
  align-self: start;
}

body #app #productGrid:not([data-view="list"]) .product-body {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: max-content;
  align-content: start;
  gap: 10px;
  padding: 12px;
}

body #app #productGrid:not([data-view="list"]) .product-identity {
  display: grid;
  align-content: start;
  gap: 4px;
  min-height: 0;
}

body #app #productGrid:not([data-view="list"]) .product-brand,
body #app #productGrid:not([data-view="list"]) .product-name {
  margin: 0;
}

body #app #productGrid:not([data-view="list"]) .product-name {
  line-height: 1.4;
}

body #app #productGrid:not([data-view="list"]) .product-code {
  line-height: 1.45;
}

body #app #productGrid:not([data-view="list"]) .product-price {
  margin: 0;
  padding: 0;
}

body #app #productGrid .product-price > del:empty,
body #app #productGrid .product-discount-summary:empty {
  display: none;
  min-height: 0;
  margin: 0;
}

body #app #productGrid:not([data-view="list"]) .product-price > del:not(:empty) {
  min-height: 0;
  margin: 0 0 4px;
}

body #app #productGrid:not([data-view="list"]) .product-price-pair {
  gap: 6px;
  margin-top: 6px;
}

body #app #productGrid:not([data-view="list"]) .product-price-value {
  padding: 8px;
  border-radius: 13px;
}

body #app #productGrid:not([data-view="list"]) .product-price-value strong {
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

body #app #productGrid:not([data-view="list"]) .product-quantity-summary,
body #app #productGrid:not([data-view="list"]) .product-discount-summary:not(:empty) {
  margin-top: 6px;
  min-height: 0;
  line-height: 1.45;
}

body #app #productGrid:not([data-view="list"]) .product-actions {
  width: 100%;
  max-width: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px 40px;
  align-items: start;
  gap: 6px;
  margin: 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
}

body #app #productGrid[data-view="compact"] .product-actions {
  grid-template-columns: minmax(0, 1fr) 40px;
}

body #app #productGrid:not([data-view="list"]) .product-actions .qty-control {
  grid-column: 1 !important;
  grid-row: 1;
  grid-template-columns: 36px minmax(24px, 1fr) 36px;
  width: 100%;
  min-width: 0;
  max-width: none;
  border-radius: 13px;
}

body #app #productGrid:not([data-view="list"]) .product-actions .qty-control::after {
  content: "caixas";
  grid-column: 1 / -1;
  padding: 0 4px 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
}

body #app #productGrid:not([data-view="list"]) .qty-control button,
body #app #productGrid:not([data-view="list"]) .qty-control input {
  height: 40px;
  min-width: 0;
  padding: 0;
  font-size: 15px;
}

body #app #productGrid:not([data-view="list"]) .product-actions .product-more {
  grid-row: 1;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 13px;
}

body #app #productGrid[data-view="showcase"] .product-actions .product-discount-button { grid-column: 2; }
body #app #productGrid[data-view="showcase"] .product-actions [data-product-menu] { grid-column: 3; }

/* Preserve the full media square and the source image's aspect ratio. */
body #app #productGrid:not([data-view="list"]) .product-media {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 0;
  padding: 0;
}

body #app #productGrid .product-media img {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  object-fit: cover;
  object-position: center;
}

/* Fixed-height viewports must scroll the menu, never stretch or shrink its rows. */
body #app #appSidebar {
  justify-content: flex-start;
  gap: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 200, 117, .45) transparent;
}

body #app #appSidebar > * { flex: 0 0 auto; }

body #app #appSidebar .sidebar-nav,
body #app #appSidebar .sidebar-links {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: max-content;
  align-content: start;
  gap: 4px;
  min-height: 0;
  height: auto;
}

body #app #appSidebar .sidebar-links {
  margin-top: 10px;
  padding-top: 10px;
}

body #app #appSidebar :is(.nav-button, .sidebar-link)[hidden] { display: none !important; }

body #app #appSidebar .sidebar-head {
  min-height: 0;
  margin: 0 0 10px;
  padding: 0 0 10px;
}

body #app #appSidebar .sidebar-head .header-icon {
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  color: #282116;
  border: 1px solid rgba(214, 176, 82, .45);
  border-radius: 13px;
  background: #f6e6b8;
}

body #app #appSidebar .sidebar-head .header-icon .icon { display: block; margin: 0; width: 23px; height: 23px; }
body #app #appSidebar .sidebar-head .sidebar-menu-icon { width: 24px; height: 24px; color: #282116; }

/* Direct text nodes in resource links still create a flex gap when font-size is zero. */
body #app #appSidebar:not(.is-open) :is(.nav-button, .sidebar-link) { gap: 0; }

body #app #appSidebar.is-open :is(.nav-button, .sidebar-link) {
  min-height: 44px;
  height: auto;
  padding: 10px 12px;
  gap: 12px;
  font-size: 13px;
  line-height: 1.35;
  justify-content: flex-start;
}

body #app #appSidebar.is-open .mobile-user-account {
  margin-top: 10px;
  padding: 8px 0 0;
}

body #app #appSidebar .mobile-user-account > summary {
  min-height: 44px;
  padding: 12px;
  line-height: 1.4;
}

@media (max-width: 620px) {
  /* One readable card on narrow phones, two only where both retain useful width. */
  body #app #productGrid:not([data-view="list"]) {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    gap: 12px;
  }

  body #app #productGrid[data-view="showcase"] { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }

  body #app #productGrid:not([data-view="list"]) .product-body { padding: 12px; }
  body #app #productGrid:not([data-view="list"]) .product-name { font-size: 13px; }
  body #app #productGrid:not([data-view="list"]) .product-code { font-size: 10px; }
  body #app #productGrid:not([data-view="list"]) .product-price-value span { font-size: 9px; }
  body #app #productGrid:not([data-view="list"]) .product-price-value strong { font-size: 15px; }

  body #app #productGrid:not([data-view="list"]) .product-actions { grid-template-columns: minmax(0, 1fr) 44px 44px; }
  body #app #productGrid[data-view="compact"] .product-actions { grid-template-columns: minmax(0, 1fr) 44px; }
  body #app #productGrid:not([data-view="list"]) .product-actions .qty-control { grid-template-columns: 44px minmax(24px, 1fr) 44px; }

  body #app #productGrid:not([data-view="list"]) .qty-control button,
  body #app #productGrid:not([data-view="list"]) .qty-control input,
  body #app #productGrid[data-view="list"] .qty-control button,
  body #app #productGrid[data-view="list"] .qty-control input {
    height: 44px;
    min-height: 44px;
    font-size: 16px;
  }

  body #app #productGrid:not([data-view="list"]) .product-actions .product-more {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  /* The list's former 116px side column squeezed price and quantity together. */
  body #app #productGrid[data-view="list"] .product-card {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 0 8px;
    padding: 10px;
  }

  body #app #productGrid[data-view="list"] .product-media {
    grid-column: 1;
    grid-row: 1 / 3;
    width: 64px;
    height: 64px;
    align-self: start;
    border-radius: 12px;
  }

  body #app #productGrid[data-view="list"] .product-identity { grid-column: 2; grid-row: 1; padding: 0; }
  body #app #productGrid[data-view="list"] .product-name { font-size: 12px; line-height: 1.4; }
  body #app #productGrid[data-view="list"] .product-code { font-size: 9px; }
  body #app #productGrid[data-view="list"] .product-flags { grid-column: 2; grid-row: 2; padding: 5px 0 0; }
  body #app #productGrid[data-view="list"] .product-price { grid-column: 1 / -1; grid-row: 3; padding: 10px 0; }
  body #app #productGrid[data-view="list"] .product-price-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  body #app #productGrid[data-view="list"] .product-price-value { padding: 8px; }
  body #app #productGrid[data-view="list"] .product-price-value span { font-size: 9px; }
  body #app #productGrid[data-view="list"] .product-price-value strong { font-size: 13px; }

  body #app #productGrid[data-view="list"] .product-actions {
    grid-column: 1 / -1;
    grid-row: 4;
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
    padding: 8px 0 0;
    border-top: 1px solid var(--line);
    align-items: start;
  }

  body #app #productGrid[data-view="list"] .product-actions .qty-control {
    grid-column: 1;
    width: 100%;
    max-width: none;
    grid-template-columns: 44px minmax(24px, 1fr) 44px;
    height: 60px;
    min-height: 60px;
    grid-template-rows: 42px 16px;
    padding: 0;
  }

  body #app #productGrid[data-view="list"] .product-actions [data-product-menu] {
    display: grid;
    grid-column: 2;
    grid-row: 1;
    width: 44px;
    height: 60px;
    min-height: 60px;
  }

  body #app #productGrid[data-view="list"] .product-actions .qty-control::after {
    content: "caixas";
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 0 0 4px;
    line-height: 12px;
    text-align: center;
    font-size: 9px;
    color: var(--muted);
  }

  body #app #productGrid[data-view="list"] .product-card.is-expanded .product-list-extra {
    grid-column: 1 / -1;
    grid-row: 5;
    margin-top: 10px;
  }

  body #app #appSidebar {
    bottom: max(8px, env(safe-area-inset-bottom));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  body #app #appSidebar.is-open { padding-inline: 10px; }
  body #app #appSidebar:not(.is-open) .sidebar-head .header-icon { width: 44px; min-width: 44px; }
}

@media (max-width: 1100px) {
  body.has-sidebar-open { overflow: hidden; }
}

@media (max-width: 900px) {
  /* Let the fixed cart share the backdrop's stacking context instead of hiding below it. */
  body #app .page-shell { z-index: auto; isolation: auto; }
  body #app #appSidebar { bottom: calc(var(--mobile-nav-height) + 12px); }
  /* Do not stretch search between inherited top and bottom anchors. */
  body #app .app-header .header-search.is-mobile-open {
    position: absolute;
    top: calc(100% + 8px);
    bottom: auto;
    left: 0;
    right: 0;
    width: auto;
    min-width: 0;
    height: 52px;
    min-height: 52px;
    max-height: 52px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow);
  }

  body #app .app-header .header-search.is-mobile-open input {
    height: 50px;
    min-height: 50px;
    border: 0;
    border-radius: 15px;
    background: var(--surface);
    color: var(--ink);
    font-size: 16px;
  }
}

@media (max-width: 900px), (max-height: 700px) {
  body #app #cartPanel {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  body #app #cartPanel > * { flex: 0 0 auto; }

  body #app #cartPanel .cart-head {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--surface);
  }

  body #app #cartPanel .cart-lines {
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  body #app #cartPanel .cart-close { min-width: 44px; min-height: 44px; }
  body #app #cartPanel .cart-foot { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (hover: none) {
  body #app #productGrid .product-card:hover { transform: none; }
  body #app #productGrid .product-card:hover .product-media img { transform: scale(1.06); }
  body #app #appSidebar .nav-button:hover { transform: none; }
}
