/*
 * Denuino Universal Theme Engine 2.0 / UI Contract 5
 *
 * Razor exposes stable semantic regions. layout.json selects the structural
 * composition. theme.css is responsible for visual design, not for guessing
 * the page geometry. The final layout contract is loaded after theme.css and
 * protects the structural invariants.
 */

body[data-theme-engine="universal"] {
  --theme-engine-content-max: var(--theme-content-max, 1480px);
  --theme-engine-gutter: var(--theme-page-gutter, clamp(14px, 2.5vw, 42px));
  --theme-engine-sidebar-width: 0px;
  --theme-engine-header-z: 120;
  --theme-engine-catalog-width: clamp(228px, 18vw, 286px);
  --theme-engine-gap: clamp(14px, 1.5vw, 24px);
  --theme-engine-control-height: 44px;
  margin: 0;
  min-inline-size: 0;
  overflow-x: clip;
}

body[data-theme-engine="universal"] .theme-u-container {
  inline-size: min(calc(100% - (2 * var(--theme-engine-gutter))), var(--theme-engine-content-max));
  min-inline-size: 0;
  margin-inline: auto;
}

body[data-theme-engine="universal"] :where(
  .theme-universal-header,
  .theme-universal-sidebar,
  .theme-universal-main,
  .theme-universal-footer,
  .theme-u-head,
  .theme-u-navigation,
  .theme-u-category-bar,
  .theme-u-footer-inner,
  .theme-catalog-shell,
  .theme-catalog-sidebar,
  .theme-catalog-main
) {
  min-inline-size: 0;
  box-sizing: border-box;
}

/* Header regions --------------------------------------------------------- */
body[data-theme-engine="universal"] .theme-universal-header {
  position: relative;
  z-index: var(--theme-engine-header-z);
  inline-size: 100%;
  max-inline-size: 100%;
  overflow: visible;
}

body[data-theme-engine="universal"] .theme-u-utility__inner,
body[data-theme-engine="universal"] .theme-u-head,
body[data-theme-engine="universal"] .theme-u-primary-nav,
body[data-theme-engine="universal"] .theme-u-category-nav,
body[data-theme-engine="universal"] .theme-u-actions,
body[data-theme-engine="universal"] .theme-u-contact,
body[data-theme-engine="universal"] .theme-u-utility-links {
  align-items: center;
}

body[data-theme-engine="universal"] .theme-u-utility__inner {
  min-block-size: 34px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

body[data-theme-engine="universal"] .theme-u-contact,
body[data-theme-engine="universal"] .theme-u-utility-links,
body[data-theme-engine="universal"] .theme-u-actions {
  min-inline-size: 0;
  display: flex;
  gap: 10px;
}

body[data-theme-engine="universal"] .theme-u-contact a,
body[data-theme-engine="universal"] .theme-u-utility-links a {
  min-inline-size: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
}

body[data-theme-engine="universal"] .theme-u-head {
  min-block-size: 88px;
  padding-block: 14px;
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(240px, 1fr) max-content;
  align-items: center;
  gap: clamp(12px, 2vw, 28px);
  container-type: inline-size;
}

body[data-theme-engine="universal"] .theme-u-brand {
  min-inline-size: 0;
  max-inline-size: 220px;
  display: grid;
  justify-items: start;
  align-content: center;
  text-decoration: none;
  overflow: hidden;
}

body[data-theme-engine="universal"] .theme-u-brand img {
  display: block;
  inline-size: min(190px, 100%);
  max-block-size: 58px;
  block-size: auto;
  object-fit: contain;
  object-position: left center;
}

body[data-theme-engine="universal"] .theme-u-brand span {
  max-inline-size: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .64rem;
  line-height: 1.2;
  letter-spacing: .13em;
  text-transform: uppercase;
}

body[data-theme-engine="universal"] .theme-u-search {
  min-inline-size: 0;
  max-inline-size: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: center;
}

body[data-theme-engine="universal"] .theme-u-search .header-search-field {
  min-inline-size: 0;
  position: relative;
}

body[data-theme-engine="universal"] .theme-u-search input {
  inline-size: 100%;
  min-inline-size: 0;
}

body[data-theme-engine="universal"] .theme-u-search .header-search-submit {
  position: static !important;
  inset: auto !important;
  inline-size: 46px !important;
  min-inline-size: 46px !important;
  max-inline-size: 46px !important;
  block-size: 42px !important;
  margin: 0 !important;
  padding: 0 !important;
  transform: none !important;
  display: inline-grid !important;
  place-items: center;
  overflow: hidden;
  white-space: nowrap;
}

/* Search labels never get squeezed into a vertical word. The button keeps a
   proper accessible aria-label and themes may opt in to a wider text button. */
body[data-theme-engine="universal"] .theme-u-search .header-search-submit > span {
  display: none !important;
}

body[data-theme-engine="universal"] .theme-u-search svg,
body[data-theme-engine="universal"] .theme-u-actions svg {
  inline-size: 19px;
  block-size: 19px;
  flex: 0 0 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body[data-theme-engine="universal"] .theme-u-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
  white-space: nowrap;
}

body[data-theme-engine="universal"] :where(.theme-u-language, .theme-u-currency, .theme-u-account, .theme-u-cart) {
  flex: 0 0 auto;
  min-inline-size: 0;
}

body[data-theme-engine="universal"] :where(.theme-u-language, .theme-u-currency) select,
body[data-theme-engine="universal"] .theme-u-account,
body[data-theme-engine="universal"] .theme-u-cart {
  min-block-size: var(--theme-engine-control-height);
  max-inline-size: 190px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
}

body[data-theme-engine="universal"] .theme-u-account > span,
body[data-theme-engine="universal"] .theme-u-cart > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-theme-engine="universal"] .theme-u-primary-nav,
body[data-theme-engine="universal"] .theme-u-category-nav {
  min-block-size: 46px;
  padding-block: 6px;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
}

body[data-theme-engine="universal"] .theme-u-primary-nav::-webkit-scrollbar,
body[data-theme-engine="universal"] .theme-u-category-nav::-webkit-scrollbar {
  display: none;
}

body[data-theme-engine="universal"] .theme-u-primary-nav a,
body[data-theme-engine="universal"] .theme-u-category-nav a {
  flex: 0 0 auto;
  min-inline-size: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  text-decoration: none;
}

body[data-theme-engine="universal"] .theme-u-category-nav img {
  inline-size: 26px;
  block-size: 26px;
  flex: 0 0 26px;
  object-fit: cover;
}

/* Declarative header visibility. These rules are structural and themes do not
   need custom selectors to remove a slot. */
body[data-theme-engine="universal"][data-theme-utility="hidden"] .theme-u-utility,
body[data-theme-engine="universal"][data-theme-primary-navigation="hidden"] .theme-u-navigation,
body[data-theme-engine="universal"][data-theme-category-navigation="hidden"] .theme-u-category-bar {
  display: none !important;
}

body[data-theme-engine="universal"][data-theme-header="compact"] .theme-u-head {
  min-block-size: 70px;
  padding-block: 10px;
  grid-template-columns: minmax(135px, 185px) minmax(220px, 1fr) max-content;
  gap: 12px;
}

body[data-theme-engine="universal"][data-theme-header="minimal"] .theme-u-head {
  min-block-size: 62px;
  padding-block: 8px;
  grid-template-columns: minmax(120px, 170px) minmax(220px, 1fr) max-content;
  gap: 10px;
}

body[data-theme-engine="universal"][data-theme-header="minimal"] .theme-u-brand span {
  display: none;
}

/* Page shell ------------------------------------------------------------- */
body[data-theme-engine="universal"] .theme-universal-workspace {
  inline-size: 100%;
  min-inline-size: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "main";
  align-items: stretch;
}

body[data-theme-engine="universal"] .theme-universal-main {
  grid-area: main;
  inline-size: 100%;
  min-inline-size: 0;
  min-block-size: 58vh;
}

body[data-theme-engine="universal"] .theme-universal-sidebar {
  grid-area: sidebar;
  display: none;
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow: hidden;
}

body[data-theme-engine="universal"] .theme-u-sidebar-brand {
  min-inline-size: 0;
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 7px;
  text-decoration: none;
  overflow: hidden;
}

body[data-theme-engine="universal"] .theme-u-sidebar-brand img {
  display: block;
  inline-size: min(155px, 100%);
  max-block-size: 54px;
  block-size: auto;
  object-fit: contain;
  object-position: left center;
}

body[data-theme-engine="universal"] .theme-u-sidebar-brand span {
  max-inline-size: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-theme-engine="universal"] :where(
  .theme-u-sidebar-primary,
  .theme-u-sidebar-categories nav,
  .theme-u-sidebar-pages
) {
  min-inline-size: 0;
  display: grid;
}

body[data-theme-engine="universal"] :where(
  .theme-u-sidebar-primary a,
  .theme-u-sidebar-categories a,
  .theme-u-sidebar-pages a
) {
  min-inline-size: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

body[data-theme-engine="universal"] :where(
  .theme-u-sidebar-primary a strong,
  .theme-u-sidebar-categories a span:last-child,
  .theme-u-sidebar-pages a
) {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
}

/* Footer ---------------------------------------------------------------- */
body[data-theme-engine="universal"] .theme-u-footer-inner {
  padding-block: clamp(28px, 4vw, 52px);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(3, minmax(0, 1fr));
  gap: clamp(24px, 4vw, 52px);
}

body[data-theme-engine="universal"] .theme-u-footer-inner > section {
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

body[data-theme-engine="universal"] .theme-u-footer-inner :where(a, span, p, h2, h3) {
  max-inline-size: 100%;
  overflow-wrap: anywhere;
}

body[data-theme-engine="universal"] .theme-u-footer-brand img {
  inline-size: min(180px, 100%);
  block-size: auto;
}

body[data-theme-engine="universal"] .theme-u-footer-bottom {
  min-block-size: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

body[data-theme-engine="universal"][data-theme-footer="compact"] .theme-u-footer-inner {
  padding-block: 26px;
  grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr));
}

body[data-theme-engine="universal"][data-theme-footer="compact"] .theme-u-footer-inner > section:nth-child(3) {
  display: none;
}

body[data-theme-engine="universal"][data-theme-footer="hidden"] .theme-universal-footer {
  display: none !important;
}

/* Component defaults for a newly uploaded theme. These values are deliberately
   neutral. A package can override every visual token in theme.css. */
body[data-theme-engine="universal"] .theme-u-search {
  padding: 4px;
  border: 1px solid var(--ui-control-border, #d8e1ec);
  border-radius: var(--ui-radius-md, 14px);
  background: var(--ui-control-bg, #fff);
}

body[data-theme-engine="universal"] .theme-u-search input {
  min-block-size: 40px;
  padding-inline: 12px !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

body[data-theme-engine="universal"] .theme-u-search .header-search-submit {
  border: 0;
  border-radius: calc(var(--ui-radius-md, 14px) - 4px);
  background: var(--ui-button-bg, #172235);
  color: var(--ui-button-text, #fff);
}

body[data-theme-engine="universal"] :where(.theme-u-language, .theme-u-currency) select,
body[data-theme-engine="universal"] .theme-u-account,
body[data-theme-engine="universal"] .theme-u-cart {
  padding-inline: 11px;
  border: 1px solid var(--ui-control-border, #d8e1ec);
  border-radius: var(--ui-radius-sm, 10px);
  background: var(--ui-control-bg, #fff);
  color: var(--ui-control-text, #172235);
}

/* Responsive header ------------------------------------------------------ */
@container (max-width: 920px) {
  body[data-theme-engine="universal"] .theme-u-head {
    grid-template-columns: minmax(125px, 180px) minmax(0, 1fr) max-content;
    gap: 10px;
  }
  body[data-theme-engine="universal"] .theme-u-account > span,
  body[data-theme-engine="universal"] .theme-u-cart > span {
    display: none;
  }
}

@media (max-width: 1100px) {
  body[data-theme-engine="universal"] .theme-u-footer-inner {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body[data-theme-engine="universal"] {
    --theme-engine-gutter: 12px;
    --theme-engine-sidebar-width: 0px !important;
  }

  body[data-theme-engine="universal"] .theme-u-utility__inner {
    min-block-size: 32px;
    gap: 10px;
  }

  body[data-theme-engine="universal"] .theme-u-contact {
    overflow-x: auto;
    scrollbar-width: none;
  }

  body[data-theme-engine="universal"] .theme-u-contact a {
    flex: 0 0 auto;
  }

  body[data-theme-engine="universal"] .theme-u-utility-links a:not(:last-child) {
    display: none;
  }

  body[data-theme-engine="universal"] .theme-u-head,
  body[data-theme-engine="universal"][data-theme-header="compact"] .theme-u-head,
  body[data-theme-engine="universal"][data-theme-header="minimal"] .theme-u-head {
    min-block-size: 0;
    padding-block: 10px;
    grid-template-columns: minmax(105px, 145px) minmax(0, 1fr);
    grid-template-areas: "brand actions" "search search";
    gap: 9px;
  }

  body[data-theme-engine="universal"] .theme-u-brand {
    grid-area: brand;
  }

  body[data-theme-engine="universal"] .theme-u-brand img {
    inline-size: min(138px, 100%);
  }

  body[data-theme-engine="universal"] .theme-u-brand span {
    display: none;
  }

  body[data-theme-engine="universal"] .theme-u-actions {
    grid-area: actions;
    justify-self: end;
    gap: 5px;
  }

  body[data-theme-engine="universal"] .theme-u-search {
    grid-area: search;
  }

  body[data-theme-engine="universal"] .theme-u-account > span,
  body[data-theme-engine="universal"] .theme-u-cart > span {
    display: none;
  }

  body[data-theme-engine="universal"] :where(.theme-u-language, .theme-u-currency) select,
  body[data-theme-engine="universal"] .theme-u-account,
  body[data-theme-engine="universal"] .theme-u-cart {
    min-block-size: 40px;
    padding-inline: 9px;
  }

  body[data-theme-engine="universal"] .theme-u-primary-nav,
  body[data-theme-engine="universal"] .theme-u-category-nav {
    min-block-size: 44px;
    padding-block: 5px;
  }

  body[data-theme-engine="universal"] .theme-universal-workspace {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: "main" !important;
  }

  body[data-theme-engine="universal"] .theme-universal-sidebar {
    display: none !important;
  }

  body[data-theme-engine="universal"] .theme-u-footer-inner,
  body[data-theme-engine="universal"][data-theme-footer="compact"] .theme-u-footer-inner {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-theme-engine="universal"] .theme-u-footer-bottom {
    padding-block: 14px;
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  body[data-theme-engine="universal"] .theme-u-contact a:first-child,
  body[data-theme-engine="universal"] .theme-u-contact a span,
  body[data-theme-engine="universal"] :where(.theme-u-language, .theme-u-currency) {
    display: none;
  }
}
