/* 响应式布局优化
 * 提供完整的移动端、平板和桌面端适配
 * 基于Bootstrap断点扩展
 */

/* ==================== 断点定义 ==================== */

/*
xs: <576px   (超小屏 - 手机竖屏)
sm: ≥576px   (小屏 - 手机横屏)
md: ≥768px   (中屏 - 平板竖屏)
lg: ≥992px   (大屏 - 平板横屏/小笔记本)
xl: ≥1200px  (超大屏 - 桌面)
xxl: ≥1400px (超超大屏 - 大桌面)
*/

/* ==================== 基础布局 ==================== */

/* 容器最大宽度 */
.container {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

@media (min-width: 576px) {
    .container {
        max-width: 540px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 720px;
    }
}

@media (min-width: 992px) {
    .container {
        max-width: 960px;
    }
}

@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
}

@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }
}

/* 流式容器 */
.container-fluid {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

/* ==================== 导航栏 ==================== */

.navbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
}

.navbar-brand {
    font-size: 1.25rem;
    white-space: nowrap;
}

.navbar-toggler {
    display: none;
    padding: 0.25rem 0.75rem;
    font-size: 1.25rem;
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 0.25rem;
    background: transparent;
    cursor: pointer;
}

.navbar-collapse {
    flex-grow: 1;
    align-items: center;
}

.navbar-nav {
    display: flex;
    flex-direction: row;
    list-style: none;
    padding-left: 0;
    margin-bottom: 0;
}

.nav-item {
    margin: 0 10px;
}

/* 移动端导航 */
@media (max-width: 991px) {
    .navbar-toggler {
        display: block;
    }

    .navbar-collapse {
        display: none;
        width: 100%;
    }

    .navbar-collapse.show {
        display: block;
    }

    .navbar-nav {
        flex-direction: column;
        width: 100%;
    }

    .nav-item {
        margin: 5px 0;
        width: 100%;
    }

    .nav-link {
        display: block;
        padding: 10px 15px;
    }
}

/* ==================== 文章列表 ==================== */

.article-list {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .article-list.grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .article-list.grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 文章卡片 */
.article-card {
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    overflow: hidden;
}

.article-card-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

@media (max-width: 767px) {
    .article-card-img {
        height: 150px;
    }
}

.article-card-body {
    padding: 15px;
}

.article-card-title {
    font-size: 1.25rem;
    margin-bottom: 10px;
}

@media (max-width: 575px) {
    .article-card-title {
        font-size: 1.1rem;
    }
}

/* ==================== 侧边栏布局 ==================== */

.main-content-wrapper {
    display: grid;
    gap: 30px;
    grid-template-columns: 1fr;
}

@media (min-width: 992px) {
    .main-content-wrapper.with-sidebar {
        grid-template-columns: 1fr 300px;
    }

    .main-content-wrapper.sidebar-left {
        grid-template-columns: 300px 1fr;
    }
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 移动端侧边栏 */
@media (max-width: 991px) {
    .sidebar {
        order: -1; /* 移到内容上方 */
    }

    .sidebar-widget {
        margin-bottom: 20px;
    }
}

/* ==================== 表格响应式 ==================== */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    table {
        font-size: 0.875rem;
    }

    table th,
    table td {
        padding: 8px 4px;
    }

    /* 隐藏不太重要的列 */
    table .hide-mobile {
        display: none;
    }
}

/* ==================== 表单 ==================== */

.form-group {
    margin-bottom: 15px;
}

.form-control {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 1rem;
    line-height: 1.5;
    border: 1px solid var(--input-border, #d0d0d0);
    border-radius: 4px;
}

@media (max-width: 575px) {
    .form-control {
        font-size: 16px; /* 防止iOS自动缩放 */
    }
}

/* 按钮组响应式 */
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 575px) {
    .btn-group {
        flex-direction: column;
    }

    .btn-group .btn {
        width: 100%;
    }
}

/* ==================== 图片响应式 ==================== */

img {
    max-width: 100%;
    height: auto;
}

.img-responsive {
    display: block;
    max-width: 100%;
    height: auto;
}

/* 图片网格 */
.image-grid {
    display: grid;
    gap: 15px;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

@media (max-width: 767px) {
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }
}

@media (max-width: 575px) {
    .image-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==================== 文字排版 ==================== */

/* 标题大小 */
h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.75rem;
}

h4 {
    font-size: 1.5rem;
}

h5 {
    font-size: 1.25rem;
}

h6 {
    font-size: 1rem;
}

@media (max-width: 767px) {
    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.75rem;
    }

    h3 {
        font-size: 1.5rem;
    }

    h4 {
        font-size: 1.25rem;
    }
}

@media (max-width: 575px) {
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }
}

/* 段落间距 */
p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

@media (max-width: 575px) {
    p {
        line-height: 1.7;
    }
}

/* ==================== 间距工具类 ==================== */

/* 移动端减少间距 */
@media (max-width: 767px) {
    .mt-md-5 {
        margin-top: 3rem !important;
    }

    .mb-md-5 {
        margin-bottom: 3rem !important;
    }

    .p-md-5 {
        padding: 2rem !important;
    }
}

@media (max-width: 575px) {
    .mt-sm-4 {
        margin-top: 1.5rem !important;
    }

    .mb-sm-4 {
        margin-bottom: 1.5rem !important;
    }

    .p-sm-4 {
        padding: 1rem !important;
    }
}

/* ==================== 显示/隐藏工具类 ==================== */

/* 移动端隐藏 */
@media (max-width: 575px) {
    .hide-xs {
        display: none !important;
    }
}

@media (max-width: 767px) {
    .hide-sm {
        display: none !important;
    }
}

@media (max-width: 991px) {
    .hide-md {
        display: none !important;
    }
}

/* 移动端显示 */
.show-xs {
    display: none !important;
}

@media (max-width: 575px) {
    .show-xs {
        display: block !important;
    }
}

.show-sm {
    display: none !important;
}

@media (max-width: 767px) {
    .show-sm {
        display: block !important;
    }
}

/* ==================== 评论区 ==================== */

.comment-list {
    list-style: none;
    padding-left: 0;
}

.comment-item {
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
}

.comment-reply {
    margin-left: 40px;
}

@media (max-width: 575px) {
    .comment-reply {
        margin-left: 20px;
    }

    .comment-item {
        padding: 10px;
    }
}

/* ==================== 分页 ==================== */

.pagination {
    display: flex;
    justify-content: center;
    list-style: none;
    padding: 0;
    gap: 5px;
}

.pagination li {
    display: inline-block;
}

.pagination a,
.pagination span {
    display: block;
    padding: 8px 12px;
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 4px;
}

@media (max-width: 575px) {
    .pagination a,
    .pagination span {
        padding: 6px 8px;
        font-size: 0.875rem;
    }

    .pagination .page-text {
        display: none; /* 隐藏"上一页"/"下一页"文字，只显示箭头 */
    }
}

/* ==================== 模态框 ==================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}

.modal-dialog {
    position: relative;
    margin: 30px auto;
    max-width: 500px;
    padding: 0 15px;
}

@media (min-width: 576px) {
    .modal-dialog {
        max-width: 500px;
    }
}

@media (min-width: 992px) {
    .modal-dialog.modal-lg {
        max-width: 800px;
    }
}

@media (max-width: 575px) {
    .modal-dialog {
        margin: 10px auto;
        max-width: 100%;
    }

    .modal-content {
        border-radius: 0;
    }
}

/* ==================== 搜索框 ==================== */

.search-form {
    display: flex;
    gap: 10px;
}

@media (max-width: 575px) {
    .search-form {
        flex-direction: column;
    }

    .search-form input {
        width: 100%;
    }

    .search-form button {
        width: 100%;
    }
}

/* ==================== 标签云 ==================== */

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.875rem;
}

@media (max-width: 575px) {
    .tag {
        font-size: 0.75rem;
        padding: 3px 8px;
    }
}

/* ==================== 面包屑 ==================== */

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 10px 15px;
    margin-bottom: 1rem;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    padding: 0 8px;
}

@media (max-width: 575px) {
    .breadcrumb {
        font-size: 0.875rem;
        padding: 8px 10px;
    }

    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 4px;
    }
}

/* ==================== 卡片 ==================== */

.card {
    border-radius: 8px;
    overflow: hidden;
}

.card-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-primary, #e0e0e0);
}

.card-body {
    padding: 15px;
}

.card-footer {
    padding: 15px;
    border-top: 1px solid var(--border-primary, #e0e0e0);
}

@media (max-width: 575px) {
    .card-header,
    .card-body,
    .card-footer {
        padding: 10px;
    }
}

/* ==================== 页脚 ==================== */

footer {
    padding: 40px 0 20px;
}

.footer-content {
    display: grid;
    gap: 30px;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

@media (max-width: 767px) {
    footer {
        padding: 30px 0 15px;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 20px;
        text-align: center;
    }
}

/* ==================== 触摸优化 ==================== */

/* 增大移动端可点击区域 */
@media (max-width: 767px) {
    a,
    button,
    .clickable {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-link,
    .btn {
        padding: 12px 20px;
    }
}

/* ==================== 性能优化 ==================== */

/* GPU加速 */
.transform-gpu {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 减少重绘 */
img,
video {
    will-change: transform;
}

/* ==================== 打印样式 ==================== */

@media print {
    .no-print,
    .navbar,
    .sidebar,
    .comments,
    footer {
        display: none !important;
    }

    .container {
        max-width: 100%;
    }

    a {
        text-decoration: underline;
    }

    a[href]:after {
        content: " (" attr(href) ")";
    }
}
