/* ============================================================
   xn-adaptive.css
   盘神资源论坛 · 主题级自适应与图片展示增强
   加载位置：header_link_after.htm 末尾，晚于主题 main.css/bbs.css
   ============================================================ */

:root {
  --xn-container: 1320px;
  --xn-sidebar: 240px;
  --xn-header-height: 64px;
  --xn-header-top: 16px;
  --xn-radius: 12px;
}

/* ---------- 1. 页面容器 ---------- */
#body .container {
  width: 100%;
  max-width: var(--xn-container);
  margin-right: auto;
  margin-left: auto;
  padding-right: 20px;
  padding-left: 20px;
}

/* ---------- 2. 顶部导航 ---------- */
#header.page-header {
  position: fixed !important;
  top: var(--xn-header-top) !important;
  left: 50% !important;
  width: min(var(--xn-container), calc(100% - 40px)) !important;
  max-width: var(--xn-container) !important;
  margin: 0 !important;
  transform: translateX(-50%) !important;
  z-index: 9999 !important;
  border-radius: 14px !important;
  border: 1px solid var(--bs-border-color) !important;
  background: var(--content-background-color) !important;
}

/* 去掉旧主题铺满视口的顶部渐变，避免头部和容器视觉错位 */
#header.page-header::before {
  display: none !important;
}

#header.page-header .navbar {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  min-height: var(--xn-header-height);
  padding: 8px 16px !important;
  border-radius: 14px !important;
  gap: 2px;
}

/* 把 logo 真正放到最左边，导航其次，右侧操作最后 */
#header.page-header .navbar .logo {
  order: -1;
  flex: 0 0 auto !important;
  margin-right: 6px !important;
  margin-left: 0 !important;
}

#header.page-header .navbar .logo img {
  max-height: 36px !important;
  width: auto !important;
  border-radius: 8px;
}

#header.page-header .navbar #navbarNav {
  order: 0;
  flex: 1 1 auto !important;
  min-width: 0;
  margin-right: 6px;
  margin-left: 0 !important;
}

#header.page-header .navbar #navbarNav #leftNav {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 1px;
  margin: 0;
}

#header.page-header .navbar #navbarNav #leftNav > li {
  flex: 0 0 auto;
}

#header.page-header .navbar #navbarNav #leftNav > li > a {
  display: inline-flex !important;
  align-items: center;
  white-space: nowrap !important;
  font-size: 13px !important;
  line-height: 20px !important;
  padding: 8px 9px !important;
  border-radius: 9px !important;
}

#header.page-header .navbar #navbarNav #leftNav > li > a i {
  font-size: 17px !important;
  line-height: 20px !important;
  margin-right: 2px;
}

/* 应用下拉菜单保持在导航层之上 */
#header.page-header .navbar #leftNav .dropdown-menu {
  z-index: 10001;
  font-size: 13px;
}

#header.page-header .navbar #headerNav {
  order: 1;
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  margin-left: auto;
}

#header.page-header .navbar #headerNav .navbar-nav {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  flex-wrap: nowrap !important;
  margin: 0;
}

#header.page-header .navbar #headerNav .nav-link {
  white-space: nowrap !important;
  font-size: 13px;
  padding: 6px 8px !important;
}

#header.page-header .navbar #headerNav .dropdown-menu {
  z-index: 10001;
}

/* 桌面端主内容：左栏 240，正文弹性，右栏 300 */
.page-content {
  margin-top: 72px !important;
  margin-left: var(--xn-sidebar) !important;
  min-width: 0;
}

.main-wrapper {
  padding: 16px 0 28px 16px !important;
  min-width: 0;
}

.page-sidebar {
  top: 112px !important;
  width: var(--xn-sidebar) !important;
  max-height: calc(100% - 128px) !important;
}

body.sidebar-hidden .page-content {
  margin-left: 0 !important;
  transform: none !important;
  padding-left: 0 !important;
}

/* 头部宽度与 Bootstrap 容器保持同一断点，避免中等屏幕头宽内容窄 */
@media (max-width: 1399.98px) {
  #header.page-header {
    width: min(1140px, calc(100% - 40px)) !important;
  }
}

@media (max-width: 1199.98px) {
  #header.page-header {
    width: min(960px, calc(100% - 32px)) !important;
  }
}

@media (min-width: 1200px) {
  .main-wrapper > .row > .main {
    flex: 1 1 0% !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0;
  }

  .main-wrapper > .row > .aside {
    flex: 0 0 300px !important;
    width: 300px !important;
    max-width: 300px !important;
    min-width: 0;
  }
}

/* ---------- 3. 列表封面：默认小图 ---------- */
.bottom_img_box {
  display: block !important;
  margin-top: 0.5rem !important;
}

.bottom_img_box .img-thumbnail {
  display: block !important;
  flex: 0 0 auto !important;
  width: 220px !important;
  max-width: 100% !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  border-radius: var(--xn-radius) !important;
  overflow: hidden;
}

.bottom_img_box .img-thumbnail a {
  display: block !important;
  line-height: 0;
}

.bottom_img_box .subject_body_img {
  display: block !important;
  width: 100% !important;
  height: 120px !important;
  max-height: 120px !important;
  object-fit: cover !important;
  border-radius: var(--xn-radius) !important;
  transition: transform 0.25s ease, filter 0.25s ease;
}

.bottom_img_box .img-thumbnail:hover .subject_body_img {
  transform: scale(1.03);
  filter: brightness(1.04);
}

/* ---------- 4. 帖子正文图片：缩略图 + 点击放大 ---------- */
.message .post-img,
.message img.post-img {
  display: inline-block !important;
  width: auto !important;
  height: auto !important;
  max-width: 200px !important;
  max-height: 140px !important;
  margin: 6px 8px 6px 0 !important;
  padding: 0 !important;
  object-fit: cover !important;
  vertical-align: middle;
  border-radius: 8px !important;
  cursor: zoom-in !important;
  background: var(--bs-secondary-pale, #f4f5f7);
  box-shadow: 0 2px 8px rgba(20, 28, 45, 0.10);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.message .post-img:hover,
.message img.post-img:hover {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 6px 18px rgba(20, 28, 45, 0.18);
  filter: brightness(1.03);
}

/* 图片标题/说明在缩略图下方时保持紧凑 */
.message .post-img + br {
  line-height: 0;
}

/* 灯箱 */
.xn-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 54px 72px 48px;
  background: rgba(8, 12, 20, 0.90);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.xn-lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

.xn-lightbox__figure {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0;
  pointer-events: none;
}

.xn-lightbox__img {
  display: block;
  width: auto !important;
  height: auto !important;
  max-width: min(1200px, calc(100vw - 150px)) !important;
  max-height: calc(100vh - 120px) !important;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  user-select: none;
}

.xn-lightbox__bar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90vw;
  padding: 6px 10px;
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  background: rgba(16, 22, 34, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.xn-lightbox__count {
  min-width: 42px;
  text-align: center;
  color: rgba(255, 255, 255, 0.82);
  font-variant-numeric: tabular-nums;
}

.xn-lightbox__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.xn-lightbox__btn:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.05);
}

.xn-lightbox__btn[disabled] {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.xn-lightbox__close {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 3;
  width: 38px;
  height: 38px;
  font-size: 24px;
}

.xn-lightbox__hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

body.xn-lightbox-open {
  overflow: hidden !important;
  touch-action: none;
}

/* ---------- 5. 平板 ---------- */
@media (max-width: 1399.98px) {
  /* 旧主题会隐藏全部导航文字和侧栏；这里保留导航文字，
     侧栏仍可点击汉堡按钮以浮层方式展开 */
  .page-sidebar {
    transform: scale(0, 1) !important;
  }

  #header.page-header .navbar #navbarNav {
    flex: 1 1 auto !important;
  }

  #header.page-header .navbar #navbarNav #leftNav > li > a:not(#sidebar-toggle) {
    display: inline-flex !important;
  }

  .page-content {
    margin-left: 0 !important;
  }

  /* 侧栏展开时不再把正文整体右推，避免横向溢出 */
  body.sidebar-hidden .page-content {
    transform: none !important;
    padding-left: 0 !important;
  }

  .page-sidebar {
    z-index: 10000;
  }

  body.sidebar-hidden .page-sidebar {
    transform: scale(1, 1) !important;
  }

  #header.page-header .navbar #headerNav .d-none.d-lg-inline {
    display: none !important;
  }
}

/* 窄平板/大屏手机：隐藏顶部导航文字，保留左侧汉堡和右侧操作 */
@media (max-width: 1100px) {
  #header.page-header .navbar #navbarNav #leftNav > li:not(:first-child) {
    display: none !important;
  }

  #header.page-header .navbar #navbarNav #leftNav > li:first-child {
    display: block !important;
  }
}

/* ---------- 6. 手机 ---------- */
@media (max-width: 991.98px) {
  #body .container {
    padding-right: 12px;
    padding-left: 12px;
  }

  #header.page-header {
    top: 8px !important;
    width: min(720px, calc(100% - 24px)) !important;
    border-radius: 12px !important;
  }

  #header.page-header .navbar {
    min-height: 54px;
    padding: 5px 10px !important;
    border-radius: 12px !important;
  }

  #header.page-header .navbar .logo img {
    max-height: 32px !important;
  }

  #header.page-header .navbar #headerNav .nav-link {
    padding: 4px 6px !important;
  }

  .page-content {
    margin-top: 76px !important;
    margin-left: 0 !important;
  }

  .main-wrapper {
    padding: 8px 0 82px !important;
  }

  .page-sidebar {
    top: 76px !important;
    left: 12px;
    max-height: calc(100% - 88px) !important;
  }

  body.sidebar-hidden .page-sidebar {
    transform: scale(1, 1) !important;
  }

  /* 列表封面进一步缩小 */
  .bottom_img_box .img-thumbnail {
    width: 170px !important;
  }

  .bottom_img_box .subject_body_img {
    height: 105px !important;
    max-height: 105px !important;
  }

  /* 手机端正文图片：约两张一排，点击后全屏查看 */
  .message .post-img,
  .message img.post-img {
    max-width: 43vw !important;
    max-height: 120px !important;
    margin: 4px 6px 4px 0 !important;
  }

  .xn-lightbox {
    padding: 10px;
  }

  .xn-lightbox__img {
    max-width: 96vw !important;
    max-height: calc(100vh - 100px) !important;
    border-radius: 8px;
  }

  .xn-lightbox__bar {
    top: 8px;
    padding: 5px 8px;
  }

  .xn-lightbox__close {
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
  }

  .xn-lightbox__hint {
    display: none;
  }
}

@media (max-width: 576px) {
  #header.page-header .navbar #headerNav .nav-link i {
    font-size: 17px;
  }

  .page-content {
    margin-top: 74px !important;
  }

  .bottom_img_box .img-thumbnail {
    width: 156px !important;
  }

  .bottom_img_box .subject_body_img {
    height: 96px !important;
    max-height: 96px !important;
  }

  .message .post-img,
  .message img.post-img {
    max-width: 42vw !important;
    max-height: 108px !important;
  }

  .thread-main .card-body,
  .thread-main .card-header {
    padding-right: 14px !important;
    padding-left: 14px !important;
  }
}

/* 高对比/深色主题下灯箱仍保持黑底白字，不依赖主题变量 */
body.dark-style .xn-lightbox {
  background: rgba(5, 8, 14, 0.94);
}

/* 兼容 prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .bottom_img_box .subject_body_img,
  .message .post-img,
  .xn-lightbox,
  .xn-lightbox__btn {
    transition: none !important;
  }
}
