/* 栈道全站布局统一层：所有页面共用一个内容宽度、同一套页面留白和响应式规则。 */
:root{
  --zd-page-max: 1000px;
  --zd-page-gutter: clamp(16px, 2.5vw, 36px);
  --zd-ui-radius: 16px;
  --zd-ui-gap: 14px;
  --zd-frame-pad-y: clamp(12px, 1.4vw, 20px);
  --zd-frame-pad-x: clamp(12px, 1.7vw, 24px);
}

/* 桌面：左栏固定，右栏收起，内容区统一 1000px；屏幕变窄时自动变 100%。 */
html body .app-main{
  padding: 0 var(--zd-page-gutter) 48px !important;
}
html body .app-main.has-forum-rail{
  display: block !important;
  grid-template-columns: none !important;
  gap: 0 !important;
}
html body .app-main > .page-content,
html body .app-main > .page-content.legacy-ui,
html body .page-content{
  width: 100% !important;
  max-width: min(var(--zd-page-max), 100%) !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}
html body .forum-rail{
  display: none !important;
}

body.page-post .app-main.has-forum-rail .app-reply-bar{
  right: calc(var(--frame-margin) + 36px) !important;
}

/* 所有页面卡片同一圆角、边框和间距，不再按页面各写一套。 */
html body .page-content > .card,
html body .page-content > .panel,
html body .page-content > .app-detail,
html body .page-content > .forum-home-head,
html body .page-content > .forum-board-head,
html body .page-content > section,
html body .page-content .msg-container,
html body .page-content .chat-shell{
  border-radius: var(--zd-ui-radius) !important;
}
html body .page-content > .card,
html body .page-content > .panel,
html body .page-content > section{
  margin-bottom: var(--zd-ui-gap) !important;
  border: 1px solid rgba(var(--mdui-color-outline-variant), .55) !important;
  background: rgb(var(--mdui-color-surface)) !important;
  box-shadow: 0 1px 2px rgba(23,32,60,.03), 0 8px 26px -24px rgba(23,32,60,.35) !important;
  overflow: hidden;
}
html body .page-content .card-header{
  padding: clamp(13px, 1.5vw, 18px) clamp(16px, 2vw, 22px) !important;
}
html body .page-content .card-body{
  padding: clamp(16px, 2vw, 22px) clamp(16px, 2vw, 22px) !important;
}

/* 页面主体统一从顶部留一点呼吸，不因 legacy-ui 而各差 24px。 */
html body .page-content{
  padding-top: 14px !important;
  padding-bottom: 44px !important;
}
html body .page-content.legacy-ui{
  padding-top: 14px !important;
  padding-bottom: 44px !important;
}

/* 图片、表格、代码块永远不许把页面撑出横向滚动。 */
html body img,
html body video,
html body iframe,
html body table,
html body pre{
  max-width: 100% !important;
}
html body pre,
html body .table-wrap{
  overflow-x: auto !important;
}

/* 桌面窗口高度用动态视口，窗口变矮时内容区自己滚，不整页乱跳。 */
@media (min-width: 960px){
  html, body{ min-height: 100%; }
  body{
    min-height: 100dvh;
    padding: var(--zd-frame-pad-y) var(--zd-frame-pad-x) !important;
  }
  html body[class][class][class] .app-frame{
    width: 100% !important;
    max-width: 1320px !important;
    grid-template-columns: clamp(196px, 18vw, 232px) minmax(0, 1fr) !important;
    height: calc(100dvh - var(--zd-frame-pad-y) - var(--zd-frame-pad-y)) !important;
    min-height: 0 !important;
    max-height: calc(100dvh - var(--zd-frame-pad-y) - var(--zd-frame-pad-y)) !important;
    margin: 0 auto !important;
  }
  /* 后台不是左栏+主区结构，不能套两列网格，否则整个管理台会被挤到 232px。 */
  html body.page-admin[class][class][class] .app-frame{
    display: block !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }
  html body.page-admin .app-main{
    width: 100% !important;
    grid-column: auto !important;
  }
  html body .app-main{
    min-height: 0 !important;
    height: auto !important;
    overflow-y: auto !important;
  }
  html body[class] .app-frame .app-main{
    padding-left: var(--zd-page-gutter) !important;
    padding-right: var(--zd-page-gutter) !important;
  }
}

/* 手机/窄屏：去掉桌面窗口边框，内容满宽，底部留出底栏安全区。 */
@media (max-width: 959px){
  html body{
    padding: 0 !important;
    min-height: 100dvh !important;
    overflow-x: hidden !important;
  }
  html body[class][class][class] .app-frame{
    width: 100% !important;
    max-width: none !important;
    display: block !important;
    grid-template-columns: minmax(0, 1fr) !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  html body .app-main{
    width: 100% !important;
    min-height: calc(100dvh - 56px) !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 clamp(14px, 4vw, 20px) calc(88px + env(safe-area-inset-bottom)) !important;
    grid-column: auto !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  html body .forum-rail{
    display: none !important;
  }
  html body .page-content,
  html body .page-content.legacy-ui{
    max-width: 100% !important;
    padding-top: 10px !important;
    padding-bottom: 24px !important;
  }
  html body .page-content > .card,
  html body .page-content > .panel,
  html body .page-content > .app-detail,
  html body .page-content > section{
    border-radius: 14px !important;
  }
  html body .page-content .card-header{
    padding: 13px 15px !important;
  }
  html body .page-content .card-body{
    padding: 15px !important;
  }
  html body .app-chip-row{
    flex-wrap: wrap !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 8px 0 !important;
    gap: 8px !important;
  }
}

