/* header.css */

/* 头部样式
   在页面顶部添加蓝色边框，作为品牌识别元素
   简单而有效地传达网站身份
*/
.header {
    position: sticky;
    top: 0;
    height: 70px; /* 固定高度 */
    background-color: black;
    border-top: solid 4px #007bff; /* 减小边框厚度 */
    z-index: 1000;
}

.menu-search-container {
    position: sticky;
    top: 70px; /* 与header高度一致 */
    background-color: black;
    z-index: 999; /* 新增：导航区域整体层级，高于页面主体内容 */
}

/* 导航栏样式 - 修复下拉菜单遮挡问题 */
.menu-bar {
    position: relative;
    z-index: 1000;
}

/* 导航栏高度设置为40px（更紧凑） */
.navbar {
    height: 40px !important;
    min-height: 40px !important;
}

.navbar-collapse {
    overflow: visible !important;
}

.navbar-nav {
    overflow: visible !important;
}

.dropdown-menu {
    z-index: 1001;
    position: absolute;
}

/* ========== 宽屏样式修复 ========== */
@media (min-width: 992px) {
    /* 确保头部在宽屏下高度固定 */
    .header {
        height: 70px !important; /* 明确固定高度 */
    }

    /* 确保logo图片在宽屏下高度固定 */
    .header img {
        height: 60px !important; /* 固定logo高度 */
    }

    /* 确保菜单搜索容器在宽屏下正确位置 */
    .menu-search-container {
        top: 70px; /* 与.header高度一致 */
    }

    /* 导航展开时的容器：强制单行 + 溢出滚动 */
    .navbar-expand-lg .navbar-collapse .navbar-nav {
        display: flex;
        flex-wrap: nowrap;     /* 核心：强制不换行 */
        overflow-x: auto;      /* 溢出时显示横向滚动条 */
        -ms-overflow-style: none; /* 隐藏 IE/Edge 滚动条 */
        scrollbar-width: none;    /* 隐藏 Firefox 滚动条 */
        padding-bottom: 0.3rem;   /* 防止滚动条遮挡底部 */
    }

    /* 隐藏 WebKit 内核浏览器滚动条（如 Chrome/Safari） */
    .navbar-expand-lg .navbar-collapse .navbar-nav::-webkit-scrollbar {
        display: none;
    }

    /* 导航项：禁止压缩 + 文字不折行 */
    .navbar-expand-lg .navbar-collapse .nav-item {
        flex: 0 0 auto;        /* 禁止导航项被压缩/拉伸 */
        white-space: nowrap;   /* 确保文字不换行 */
        margin-right: 0.25rem;    /* 导航项之间的间距（可按需调整） */
    }

    /* 确保下拉菜单在宽屏下也能正常显示 */
    .navbar-expand-lg .dropdown-menu {
        position: absolute;
    }

    /* 宽屏下标题区域垂直居中 */
    .col-7.col-sm-8.d-none.d-md-block {
        display: flex !important;
        align-items: center;
        justify-content: flex-end;
        height: 70px; /* 与header高度一致 */
        padding-top: 0 !important; /* 移除原有的顶部padding */
    }

    .col-7.col-sm-8.d-none.d-md-block h2 {
        margin: 0; /* 移除默认margin */
        line-height: 1.2; /* 调整行高 */
    }

    /* logo容器垂直居中 */
    .col-5.col-sm-4 {
        display: flex;
        align-items: center;
        height: 70px; /* 与header高度一致 */
        padding-top: 0 !important; /* 移除原有的顶部padding */
    }
}

/* ========== 手机端极致紧凑优化 ========== */
@media (max-width: 991.98px) {
    /* 头部进一步压缩 */
    .header {
        height: 60px !important;
        border-top: solid 3px #007bff;
    }

    .header img {
        height: 50px !important; /* 减小logo */
    }

    .col-5 {
        padding-top: 2px !important;
    }

    /* 菜单搜索容器极致紧凑 */
    .menu-search-container {
        top: 60px; /* 调整位置 */
        padding: 3px 8px !important; /* 极致紧凑的内边距 */
        height: 44px; /* 固定高度 */
    }

    /* 导航栏在手机端极致简化 */
    .navbar {
        padding: 0;
        height: 38px !important;
        min-height: 38px !important;
    }

    /* 汉堡菜单固定宽度 */
    .navbar-toggler {
        border: 1px solid rgba(255, 255, 255, 0.3);
        padding: 4px 8px !important;
        width: 50px !important; /* 固定宽度 */
        min-width: 50px !important;
        max-width: 50px !important;
        height: 32px;
        font-size: 0.9rem;
        flex-shrink: 0 !important; /* 防止被压缩 */
        margin-right: 8px !important;
    }

    .navbar-toggler-icon {
        width: 18px;
        height: 18px;
    }

    .navbar-toggler:focus {
        box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.5);
    }

    /* 搜索栏布局调整 */
    .search-bar {
        margin-left: 0px;
        margin-right: 0px;
        width: 100%; /* 占据剩余宽度 */
        display: flex;
        flex: 1; /* 关键：占据剩余空间 */
    }

    /* 输入框组占据全部可用空间 */
    .input-group {
        height: 32px;
        width: 100%; /* 占据全部宽度 */
        flex: 1; /* 关键：占据剩余空间 */
    }

    /* 搜索输入框占据剩余宽度 */
    form.search-bar .search-input.form-control {
        width: 100% !important; /* 占据输入框组的全部宽度 */
        height: 32px !important;
        font-size: 0.85rem;
        padding: 4px 8px !important;
        flex: 1; /* 关键：占据剩余空间 */
    }

    /* 搜索按钮固定宽度 */
    form.search-bar .btn {
        width: 50px !important; /* 固定宽度 */
        min-width: 50px !important;
        max-width: 50px !important;
        height: 32px !important;
        padding: 4px 8px !important;
        font-size: 0.85rem;
        flex-shrink: 0 !important; /* 防止被压缩 */
    }

    /* 主容器布局：汉堡菜单(固定) + 搜索栏(剩余) */
    .d-flex.align-items-center {
        justify-content: space-between;
        height: 38px;
        gap: 8px; /* 元素间距 */
    }

    /* 导航区域固定宽度 */
    .menu {
        flex: 0 0 auto !important; /* 不拉伸 */
        width: auto !important;
    }

    /* 搜索区域占据剩余空间 */
    .col-auto.px-1 {
        flex: 1 !important; /* 关键：占据剩余空间 */
        padding-left: 0 !important;
        padding-right: 0 !important;
        min-width: 0; /* 允许缩小 */
    }

    /* 手机端下拉菜单展开时的背景 - 紧凑布局 */
    .navbar-collapse.collapsing,
    .navbar-collapse.show {
        position: fixed;
        top: 103px; /* 60px header + 43px menu-search-container */
        left: 0;
        right: 0;
        background-color: rgba(0, 0, 0, 0.98);
        backdrop-filter: blur(3px);
        padding: 12px 15px !important; /* 减少内边距 */
        margin: 0;
        border-top: 1px solid #333;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
        z-index: 1002;
        max-height: calc(100vh - 103px);
        overflow-y: auto;
    }

    /* 导航项在手机端的极致紧凑样式 */
    .navbar-nav {
        width: 100%;
    }

    .nav-item.dropdown {
        width: 100%;
        margin-bottom: 6px !important; /* 减少间距 */
    }

    .nav-link {
        color: #fff !important;
        padding: 8px 10px !important; /* 极致紧凑的内边距 */
        border-radius: 4px;
        transition: all 0.2s ease;
        font-size: 0.9rem;
        min-height: 32px;
        display: flex;
        align-items: center;
    }

    .nav-link:hover,
    .nav-link:focus {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
    }

    /* 下拉菜单在手机端的紧凑样式 */
    .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin-top: 3px !important;
        background-color: rgba(35, 35, 35, 0.95) !important;
        border: 1px solid #444;
        box-shadow: none;
        padding: 4px 0 !important;
    }

    .dropdown-item {
        color: #e0e0e0 !important;
        padding: 6px 15px !important; /* 减少内边距 */
        border-bottom: 1px solid #444;
        font-size: 0.85rem;
        min-height: 28px;
        display: flex;
        align-items: center;
    }

    .dropdown-item:hover,
    .dropdown-item:focus {
        background-color: rgba(255, 255, 255, 0.08);
        color: #fff !important;
    }

    .dropdown-item:last-child {
        border-bottom: none;
    }
}

/* 补充：确保访问过的链接也保持白色 */
.menu .menu-bar .nav-link:visited,
.menu .menu-bar .dropdown-item:visited {
    color: #e0e0e0 !important;
}

/* 超小屏幕额外优化（小于576px） */
@media (max-width: 575.98px) {
    .header {
        height: 55px !important;
    }

    .header img {
        height: 45px !important;
    }

    .menu-search-container {
        top: 55px;
        padding: 2px 6px !important;
        height: 40px;
    }

    .navbar {
        height: 36px !important;
        min-height: 36px !important;
    }

    /* 超小屏幕进一步减小按钮宽度 */
    .navbar-toggler {
        width: 45px !important;
        min-width: 45px !important;
        max-width: 45px !important;
        height: 30px;
        padding: 3px 6px !important;
        margin-right: 6px !important;
    }

    form.search-bar .search-input.form-control {
        height: 30px !important;
        font-size: 0.8rem;
        padding: 3px 6px !important;
    }

    form.search-bar .btn {
        width: 45px !important;
        min-width: 45px !important;
        max-width: 45px !important;
        height: 30px !important;
        padding: 3px 6px !important;
    }

    .input-group {
        height: 30px;
    }

    .navbar-collapse.collapsing,
    .navbar-collapse.show {
        top: 95px; /* 55px header + 40px menu-search-container */
        max-height: calc(100vh - 95px);
    }
}