/* =========================================================
   Phase 7 — Centralized Library Platform
   Lean library index styling aligned to existing tool pages
   ========================================================= */

body.library-body{
  --header-h: 60px;
  background: var(--bg);
  overflow: hidden;
}

body.library-body .page-shell,
body.library-body .main-column{
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  min-height: 0;
}

.library-header{
  position: sticky;
  top: 0;
  z-index: 60;
}

.library-header .header-inner{
  position: relative;
  isolation: isolate;
  min-height: 60px;
  padding-top: 6px;
  padding-bottom: px;
  gap: 16px;
}

.library-header .brand{
  position: relative;
  z-index: 2;
  min-width: 0;
}

.library-header .brand-name{
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .1px;
}

.library-header .header-controls{
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  position: relative;
  z-index: 3;
}

.library-header .header-auth{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.library-header-search{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 760px));
  min-width: 360px;
  z-index: 5;
}

.library-search-form{
  position: relative;
  display: flex;
  align-items: center;
  pointer-events: auto;
}

.library-search-input{
  width: 100%;
  height: 36px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border), white 16%);
  background: #f4f4f5;
  color: #151517;
  padding: 0 50px 0 18px;
  font-size: 16px;
  font-weight: 500;
  outline: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}

.library-search-input::placeholder{
  color: #676b73;
}

.library-search-input:focus{
  border-color: color-mix(in srgb, var(--accent), white 20%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 74%);
}

.library-search-btn{
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #131315;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.library-search-btn:hover{
  background: rgba(0,0,0,.06);
}

.library-main{
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 22px 18px;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 16px;
  overflow: hidden;
}

.library-sidebar{
  min-width: 0;
  min-height: 0;
}

.library-sidebar-stack,
.library-sidebar-controls{
  height: 100%;
  min-height: 0;
}

.library-sidebar-controls{
  top: 0;
  padding: 12px;
  gap: 12px;
}

.library-filter-scroll{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  margin-right: -12px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.28) transparent;
}

.library-filter-scroll::-webkit-scrollbar,
.library-right-scroll::-webkit-scrollbar,
.library-detail-side-scroll::-webkit-scrollbar,
.library-map-scroll::-webkit-scrollbar{
  width: 2px;
  height: 2px;
}

.library-filter-scroll::-webkit-scrollbar-track,
.library-right-scroll::-webkit-scrollbar-track,
.library-detail-side-scroll::-webkit-scrollbar-track,
.library-map-scroll::-webkit-scrollbar-track{
  background: transparent;
}

.library-filter-scroll::-webkit-scrollbar-thumb,
.library-right-scroll::-webkit-scrollbar-thumb,
.library-detail-side-scroll::-webkit-scrollbar-thumb,
.library-map-scroll::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,0.22);
  border-radius: 999px;
}

.library-filter-scroll::-webkit-scrollbar-thumb:hover,
.library-right-scroll::-webkit-scrollbar-thumb:hover,
.library-detail-side-scroll::-webkit-scrollbar-thumb:hover,
.library-map-scroll::-webkit-scrollbar-thumb:hover{
  background: rgba(255,255,255,0.32);
}

.library-filter-dropdown{
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: rgba(255,255,255,0.02);
}

.library-filter-dropdown + .library-filter-dropdown{
  margin-top: 10px;
}

.library-filter-dropdown summary{
  padding: 14px 12px;
  font-size: 14px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  list-style: none;
  background: rgba(0,0,0,0.35);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.library-filter-dropdown summary::-webkit-details-marker{ display: none; }
.library-filter-dropdown summary::marker{ display: none; }
.library-filter-dropdown summary::after{
  content: '▸';
  font-size: 14px;
  opacity: 1;
  margin-left: 10px;
  transform: rotate(0deg);
  transition: transform 140ms ease;
}

.library-filter-dropdown[open] > summary::after{
  transform: rotate(90deg);
}

.library-filter-dropdown:not([open]) > summary{
  border-bottom: none;
}

.library-filter-list{
  padding: 10px;
  background: rgba(0,0,0,0.18);
  display: grid;
  gap: 8px;
}

.library-filter-chip{
  width: 100%;
  min-height: 30px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  border-radius:10px;
  border: 0px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease;
}

.library-filter-chip:hover{
  color: var(--text);
  border-color: rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
}

.library-filter-chip.is-active{
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent), transparent 38%);
  background: color-mix(in srgb, var(--accent), transparent 85%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent), transparent 70%);
}

.library-sidebar-actions{
  flex: 0 0 auto;
  padding-top: 1px;
}

.library-clear-btn{
  width: 100%;
}

.library-content{
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.library-right-scroll{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding-right: 4px;
}

.library-content-head{
  display: none;
}

.library-selected-note{
  display: none;
}

.library-grid-wrap{
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.library-grid-wrap.is-grid-state{
  display: grid;
  place-items: center;
}

.library-grid{
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.library-card{
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.library-card-thumb{
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.library-card-thumb img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.001);
  transition: transform .22s ease;
}

.library-card:hover .library-card-thumb img,
.library-card:focus-visible .library-card-thumb img{
  transform: scale(1.08);
}

.library-card-thumb-fallback{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: color-mix(in srgb, var(--text), transparent 18%);
}

.library-card-name{
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  text-align: center;
}

.library-empty,
.library-error,
.library-loading{
  border: 1px solid rgba(255,255,255,0.10);
  background: var(--panel);
  border-radius: 12px;
  padding: 18px;
  color: var(--muted);
  font-size: 14px;
}

.library-grid-state{
  width: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}

.library-grid-state.is-error{
  color: color-mix(in srgb, var(--text), transparent 16%);
}

.library-footer-wrap{
  margin-top: auto;
  padding-top: 18px;
}

.library-footer-wrap .site-footer{
  border-top: 1px solid var(--border);
}

.library-footer-wrap .footer-inner{
  max-width: none;
  padding-left: 0;
  padding-right: 0;
  padding-bottom: 18px;
}

@media (max-width: 1420px){
  .library-header-search{
    width: min(520px, calc(100vw - 700px));
  }
}

@media (max-width: 1200px){
  .library-main{
    grid-template-columns: 270px minmax(0, 1fr);
    padding-left: 18px;
    padding-right: 18px;
  }
  .library-grid{
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px){
  body.library-body{
    overflow: auto;
  }

  body.library-body .page-shell,
  body.library-body .main-column{
    height: auto;
    min-height: calc(100vh - var(--header-h));
    min-height: calc(100dvh - var(--header-h));
  }

  .library-header .header-inner{
    padding-top: 12px;
    padding-bottom: 12px;
  }
  .library-header-search{
    position: static;
    transform: none;
    min-width: 0;
    width: 100%;
    order: 3;
    margin-top: 6px;
  }
  .library-header .header-inner{
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
  .library-header .header-controls{
    margin-left: auto;
    flex: 0 0 auto;
  }
  .library-main{
    height: auto;
    min-height: calc(100vh - var(--header-h));
    min-height: calc(100dvh - var(--header-h));
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .library-sidebar{
    min-height: 240px;
  }
  .library-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px){
  .library-main{
    padding: 14px;
    gap: 14px;
  }
  .library-grid{
    grid-template-columns: 1fr 1fr;
  }
  .library-card-name,
  .library-filter-chip,
  .library-selected-note{
    font-size: 13px;
  }
}


/* ---------------------------------------------------------
   Product detail page
   --------------------------------------------------------- */

.library-detail-main{
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 0;
  max-width: none;
  margin: 0;
  padding: 0;
}

.library-detail-viewport{
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0;
}

.library-map-panel,
.library-preview-panel{
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.library-map-panel{
  border-right: 1px solid var(--border);
}

.library-panel-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.library-panel-title{
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.library-map-scroll{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.library-map-grid{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.library-map-card{
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: color-mix(in srgb, var(--panel), var(--bg-2) 55%);
}

.library-map-card img{
  width: 100%;
  height: auto;
  display: block;
  background: #101013;
}

.library-map-card-title{
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 800;
  border-top: 1px solid var(--border);
}


.library-preview-stage{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,.10), rgba(0,0,0,.22)),
    #101013;
}

.library-preview-stage.has-sky-bg{
  background-image:
    linear-gradient(180deg, rgba(0,0,0,.06), rgba(0,0,0,.16)),
    url('assets/hdri/Sky1_background.png');
  background-size: cover;
  background-position: center center;
}

.library-preview-canvas,
.library-preview-stage canvas{
  width: 100%;
  height: 100%;
  display: block;
}


.library-preview-stage > .pbr-viewer,
.library-preview-stage > .viewer3d-box,
.library-preview-stage > .library-product-viewer{
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
}

.library-preview-stage > .viewer3d-box{
  background: #17191d;
}

.library-preview-stage > .viewer3d-box .tg-loading{
  z-index: 20;
}

.library-preview-stage > .viewer3d-box .viewer3d-topright,
.library-preview-stage > .viewer3d-box .tg-stats{
  z-index: 12;
}

.library-preview-stage > .pbr-viewer::before{
  border-radius: 0;
}

.library-viewer-toolbar{
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 3;
}

.library-viewer-pill{
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border), white 8%);
  background: rgba(10,10,12,.64);
  color: #f2f2f3;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.library-viewer-pill.is-active,
.library-viewer-pill:hover{
  border-color: color-mix(in srgb, var(--accent), transparent 40%);
  background: rgba(10,10,12,.82);
}

.library-stage-hint{
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 3;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(10,10,12,.62);
  color: rgba(255,255,255,.82);
  font-size: 12px;
  font-weight: 700;
}

.library-detail-side{
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
}

.library-detail-side-scroll{
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 18px 12px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.28) transparent;
  scrollbar-gutter: stable;
}

.library-detail-title{
  margin: 0;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: -.02em;
}

.library-detail-content-inner{
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.library-pill-row{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.library-meta-pill{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel), var(--bg-2) 35%);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.library-detail-section{
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.library-detail-section-title{
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--muted);
}

.library-option-grid{
  display: grid;
  gap: 10px;
}

.library-option-group label{
  display: block;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
}

.library-option-group .select,
.library-preview-panel .select{
  width: 100%;
}

.library-download-btn{
  width: 100%;
  min-height: 38px;
}

.library-download-btn[disabled]{
  opacity: .5;
  cursor: not-allowed;
}

.library-detail-note{
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}



.library-product-error{
  margin: 20px;
}

@media (max-width: 1260px){
  .library-main{
    grid-template-columns: 300px minmax(0, 1fr);
  }
  .library-grid{
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .library-detail-main{
    grid-template-columns: minmax(0, 1fr) 270px;
  }
}

@media (max-width: 980px){
  .library-header .header-inner{
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .library-header .header-controls{
    width: 100%;
    flex-wrap: wrap;
  }
  .library-header-search{
    flex: 1 1 100%;
    max-width: none;
    margin-left: 0;
  }
  .library-main,
  .library-detail-main{
    height: auto;
    min-height: calc(100vh - var(--header-h));
    min-height: calc(100dvh - var(--header-h));
    grid-template-columns: 1fr;
  }
  .library-sidebar,
  .library-detail-side{
    border-right: 0;
    border-left: 0;
    border-bottom: 1px solid var(--border);
  }
  .library-right-scroll,
  .library-detail-side-scroll{
    overflow: visible;
  }
  .library-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .library-detail-viewport{
    min-height: 68vh;
    grid-template-columns: 1fr;
  }
  .library-map-panel{
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 640px){
  .library-sidebar,
  .library-right-scroll,
  .library-detail-side-scroll,
  .library-panel-head,
  .library-map-scroll{
    padding-left: 14px;
    padding-right: 14px;
  }
  .library-grid,
  .library-map-grid{
    grid-template-columns: 1fr;
  }
  .library-content-title,
  .library-detail-title{
    font-size: 26px;
  }
}
