/* EMKAN v146 — SAFE FOUNDATION RESET
   This replaces v145's over-broad layout overrides. It centralizes only the
   shared geometry that is truly common: header rails, context/breadcrumb row,
   disclosure rhythm, responsive rails. Module-specific content layouts are
   deliberately left to their own stable CSS (especially Education/RTL). */

:root{
  --emkan-nav-width:1040px;
  --emkan-context-width:1380px;
  --emkan-context-top:14px;
  --emkan-context-bottom:20px;
  --emkan-context-rule-pad:11px;
  --emkan-disclosure-row:28px;
  --emkan-disclosure-pad:3px;
  --emkan-disclosure-leading:1.5;
}

/* ---------- 1) HEADER: shorten the whole rail, do not crush labels ---------- */
@media (min-width:1280px){
  html body .site-header{
    width:min(var(--emkan-nav-width),calc(100% - 160px))!important;
    max-width:var(--emkan-nav-width)!important;
    margin-inline:auto!important;
  }
  html body .site-header .nav-frame{
    width:100%!important;height:34px!important;min-height:34px!important;
    margin-top:13px!important;padding:0!important;
    border-top:1px solid var(--line)!important;border-bottom:1px solid var(--line)!important;
    box-sizing:border-box!important;
  }
  html body .site-header .primary-nav{
    width:100%!important;height:34px!important;min-height:34px!important;
    margin:0!important;padding-inline:92px!important;
    display:flex!important;align-items:center!important;justify-content:center!important;
    box-sizing:border-box!important;
  }
  html body .site-header .nav-list{
    width:max-content!important;max-width:100%!important;margin-inline:auto!important;
    gap:clamp(18px,1.35vw,26px)!important;min-height:0!important;
  }
  html body .site-header .language-button{
    position:absolute!important;top:50%!important;left:24px!important;right:auto!important;
    transform:translateY(-50%)!important;margin:0!important;
  }
  html body .site-header .theme-button,
  html body .site-header .nav-frame>#themeButton.theme-button{
    position:absolute!important;top:50%!important;right:24px!important;left:auto!important;
    transform:translateY(-50%)!important;margin:0!important;
  }
}
@media (min-width:901px) and (max-width:1279px){
  html body .site-header{
    width:min(1000px,calc(100% - 64px))!important;max-width:1000px!important;margin-inline:auto!important;
  }
  html body .site-header .nav-frame{
    width:100%!important;height:34px!important;min-height:34px!important;margin-top:12px!important;padding:0!important;
    border-top:1px solid var(--line)!important;border-bottom:1px solid var(--line)!important;box-sizing:border-box!important;
  }
  html body .site-header .primary-nav{
    width:100%!important;height:34px!important;min-height:34px!important;margin:0!important;padding-inline:82px!important;
    display:flex!important;align-items:center!important;justify-content:center!important;box-sizing:border-box!important;
  }
  html body .site-header .nav-list{
    width:max-content!important;max-width:100%!important;margin-inline:auto!important;gap:clamp(13px,1.25vw,20px)!important;min-height:0!important;
  }
  html body .site-header .language-button{
    position:absolute!important;top:50%!important;left:18px!important;right:auto!important;transform:translateY(-50%)!important;margin:0!important;
  }
  html body .site-header .theme-button,
  html body .site-header .nav-frame>#themeButton.theme-button{
    position:absolute!important;top:50%!important;right:18px!important;left:auto!important;transform:translateY(-50%)!important;margin:0!important;
  }
}
@media (min-width:901px){
  html body .site-header .nav-list>li{margin:0!important;padding:0!important;min-height:0!important}
  html body .site-header .nav-link{padding:0!important;line-height:1.24!important}
}

/* ---------- 2) MOBILE/TABLET HEADER: two thin rails, compact permanent row ---------- */
@media (max-width:900px){
  :root{--emkan-context-top:12px;--emkan-context-bottom:16px;--emkan-context-rule-pad:10px}
  html body .site-header{width:min(720px,calc(100% - 34px))!important;max-width:720px!important;margin-inline:auto!important}
  html body .site-header .nav-frame{
    width:100%!important;min-height:34px!important;height:auto!important;margin-top:9px!important;padding:0 9px!important;
    display:grid!important;grid-template-columns:76px minmax(0,1fr) 38px!important;
    grid-template-areas:"lang toggle theme" "nav nav nav"!important;align-items:center!important;
    border-top:1px solid var(--line)!important;border-bottom:1px solid var(--line)!important;overflow:hidden!important;box-sizing:border-box!important;
  }
  html body .site-header .language-button,
  html body .site-header .theme-button,
  html body .site-header .nav-frame>#themeButton.theme-button{
    position:static!important;inset:auto!important;transform:none!important;margin:0!important;min-height:28px!important;height:28px!important;
  }
  html body .site-header .language-button{grid-area:lang!important;justify-self:start!important;padding:0!important}
  html body .site-header .theme-button,
  html body .site-header .nav-frame>#themeButton.theme-button{grid-area:theme!important;justify-self:end!important;width:28px!important;min-width:28px!important;padding:0!important}
  html body .site-header .mobile-menu-button{grid-area:toggle!important;justify-self:center!important;width:30px!important;height:30px!important;min-height:30px!important;margin:0!important}
  html body .site-header .primary-nav{grid-area:nav!important;width:100%!important;padding-inline:0!important;margin:0!important}
  html body .site-header .nav-list{width:100%!important;max-width:none!important;margin:0!important;padding:4px 0 6px!important;gap:0!important}
  html body .site-header .nav-link,
  :is(html[lang="fa"],html[lang="ar"]) body .site-header .nav-link{padding:5px 3px!important;line-height:1.3!important}
}
@media (max-width:560px){
  html body .site-header{width:calc(100% - 28px)!important}
  html body .site-header .nav-frame{min-height:33px!important;margin-top:8px!important;padding-inline:8px!important;grid-template-columns:74px minmax(0,1fr) 36px!important}
  html body .site-header .theme-icon-wrap,html body .site-header .theme-icon{width:13px!important;height:13px!important}
}

/* ---------- 3) ONE CONTEXT / BREADCRUMB FRAME ---------- */
@media (min-width:901px){:root{--emkan-context-physical-width:min(var(--emkan-context-width),calc(100vw - 96px))}}
@media (max-width:900px){:root{--emkan-context-physical-width:min(720px,calc(100vw - 34px))}}
@media (max-width:560px){:root{--emkan-context-physical-width:calc(100vw - 28px)}}

html body .page-shell>main:has(>:is(.emkan-context-bar,.store-context-bar,.podcast-context-bar,.product-toolbar)),
html body :is(.detail-main,.articles-main--architecture-tools,.article-page,.store-category-main,.podcast-main,.product-main):has(>:is(.emkan-context-bar,.store-context-bar,.podcast-context-bar,.product-toolbar)){
  padding-top:0!important;margin-top:0!important;
}
html body :is(main>.emkan-context-bar,.article-page>.emkan-context-bar,.store-category-main>.store-context-bar,.podcast-main>.podcast-context-bar,.product-main>.product-toolbar){
  position:relative!important;left:50%!important;right:auto!important;transform:translateX(-50%)!important;
  width:var(--emkan-context-physical-width)!important;max-width:none!important;box-sizing:border-box!important;
  margin-top:var(--emkan-context-top)!important;margin-right:0!important;margin-bottom:var(--emkan-context-bottom)!important;margin-left:0!important;
  padding:0 0 var(--emkan-context-rule-pad)!important;min-height:32px!important;
  border-top:0!important;border-bottom:1px solid var(--line)!important;
}
/* Historic R&D/article top offsets are the only module-specific offsets neutralized centrally. */
html body.emkan-v136-rd-section .detail-main,
html body.emkan-v136-rd-articles .articles-main--architecture-tools,
html body.emkan-v136-rd-article .article-page{margin-top:0!important;padding-top:0!important}

/* ---------- 4) ONE DISCLOSURE RHYTHM ---------- */
html body :is(.category-list ul,.article-category-list ul,.detail-subcategory-list,.v49-filter-list,.podcast-filter-list,.podcast-topics,.podcast-seasons,.store-subcategory-list,.store-sort-list,.civil-filter-list,.research-filter-list,.research-category-list,.article-filter-list,.emkan-filter-list){
  gap:0!important;row-gap:0!important;margin-top:0!important;margin-bottom:0!important;padding-top:2px!important;padding-bottom:3px!important;
}
html body :is(.category-button,.article-category-choice,.detail-subcategory-list a,.v49-filter-option,.podcast-filter-list button,.podcast-topics button,.podcast-seasons button,.store-subcategory-list a,.store-sort-list button,.civil-filter-list button,.research-filter-list button,.research-category-list button,.article-filter-list button,.emkan-filter-list button,.emkan-filter-list a,.emkan-landing-category){
  min-height:0!important;margin:0!important;padding:var(--emkan-disclosure-pad) 0!important;line-height:var(--emkan-disclosure-leading)!important;
}
html body :is(.category-toggle,.article-category-toggle,.detail-subcategory-filter>summary,.v49-plain-filter>summary,.podcast-filter>summary,.rail-filter>summary,.store-subcategory-filter>summary,.store-sort-filter>summary){
  min-height:var(--emkan-disclosure-row)!important;margin:0!important;padding:5px 0!important;line-height:1.45!important;box-sizing:border-box!important;
}

/* ---------- 5) EDUCATION: DO NOT REORDER MODULE COLUMNS HERE.
   v90/v115 are the authoritative education layouts. Only enforce native text direction. ---------- */
:is(html[lang="fa"],html[lang="ar"]) body.content-section-page #contentApp :is(.v49-rail,.v49-results-wrap,.v49-detail,.v49-reading,.v49-section,.v69-content-search-rail,.v69-content-detail-body,.learning-side,.learning-tree,.learning-panels){direction:rtl!important;text-align:right!important}
html[lang="en"] body.content-section-page #contentApp :is(.v49-rail,.v49-results-wrap,.v49-detail,.v49-reading,.v49-section,.v69-content-search-rail,.v69-content-detail-body,.learning-side,.learning-tree,.learning-panels){direction:ltr!important;text-align:left!important}
:is(html[lang="fa"],html[lang="ar"]) body.content-section-page #contentApp input[type="search"]{direction:rtl!important;text-align:right!important}
html[lang="en"] body.content-section-page #contentApp input[type="search"]{direction:ltr!important;text-align:left!important}

/* Education physical placement stays with the proven v72/v74/v134 module rules.
   Do not redefine its grid here: the former foundation did that and shifted
   search/cards to the wrong physical side in RTL. */

/* ---------- 6) EDUCATION POSTER: always square ---------- */
html body.v115-course-detail #contentApp .v115-course-poster{aspect-ratio:1/1!important;width:min(320px,100%)!important;height:auto!important;overflow:hidden!important}
html body.v115-course-detail #contentApp .v115-course-poster img{width:100%!important;height:100%!important;aspect-ratio:1/1!important;object-fit:cover!important;display:block!important}
@media (min-width:901px){html body.v115-course-detail #contentApp .v115-course-poster{height:320px!important}}

/* ---------- 7) VIRTUAL LESSONS: compact article-like disclosures ---------- */
html body.content-section-page #contentApp .emkan-v135-lessons{display:block!important;margin:0!important;padding:0!important}
html body.content-section-page #contentApp details.emkan-v135-lesson{
  display:block!important;margin:0!important;padding:0!important;border:0!important;border-bottom:1px solid var(--line)!important;background:transparent!important;box-shadow:none!important;border-radius:0!important;opacity:1!important;
}
html body.content-section-page #contentApp details.emkan-v135-lesson.is-locked{opacity:.52!important}
html body.content-section-page #contentApp .emkan-v146-lesson-summary{
  list-style:none!important;display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;gap:16px!important;align-items:center!important;
  min-height:46px!important;padding:10px 0!important;cursor:pointer!important;color:var(--fg)!important;
}
html body.content-section-page #contentApp .emkan-v146-lesson-summary::-webkit-details-marker{display:none!important}
html body.content-section-page #contentApp .emkan-v146-lesson-summary-main{min-width:0!important;display:flex!important;align-items:baseline!important;gap:12px!important;flex-wrap:wrap!important}
html body.content-section-page #contentApp .emkan-v146-lesson-summary-title{font-size:11.5px!important;font-weight:600!important;line-height:1.65!important}
html body.content-section-page #contentApp .emkan-v146-lesson-summary-meta{font-size:9.5px!important;color:var(--category-muted)!important;line-height:1.5!important;white-space:nowrap!important}
html body.content-section-page #contentApp .emkan-v146-lesson-mark{position:relative!important;width:12px!important;height:12px!important;flex:0 0 12px!important}
html body.content-section-page #contentApp .emkan-v146-lesson-mark::before,
html body.content-section-page #contentApp .emkan-v146-lesson-mark::after{content:""!important;position:absolute!important;left:50%!important;top:50%!important;background:currentColor!important;transform:translate(-50%,-50%)!important;transition:opacity .18s ease!important}
html body.content-section-page #contentApp .emkan-v146-lesson-mark::before{width:10px!important;height:1px!important}
html body.content-section-page #contentApp .emkan-v146-lesson-mark::after{width:1px!important;height:10px!important}
html body.content-section-page #contentApp details.emkan-v135-lesson[open] .emkan-v146-lesson-mark::after{opacity:0!important}
html body.content-section-page #contentApp .emkan-v146-lesson-body{display:grid!important;grid-template-columns:minmax(220px,.8fr) minmax(0,1.2fr)!important;gap:28px!important;padding:10px 0 18px!important}
html body.content-section-page #contentApp .emkan-v146-lesson-body .emkan-v135-lesson-copy{min-width:0!important}
html body.content-section-page #contentApp .emkan-v146-lesson-body .emkan-v135-video-wrap{width:100%!important;aspect-ratio:16/9!important}
@media(max-width:760px){
  html body.content-section-page #contentApp .emkan-v146-lesson-summary{min-height:42px!important;padding:9px 0!important;gap:10px!important}
  html body.content-section-page #contentApp .emkan-v146-lesson-body{grid-template-columns:1fr!important;gap:13px!important;padding:8px 0 15px!important}
}

/* ---------- 8) responsive safety ---------- */
html,body{max-width:100%}html body .page-shell{overflow-x:clip}
html body :is(.site-header,.emkan-context-bar,.store-context-bar,.podcast-context-bar,.product-toolbar){box-sizing:border-box!important}
