/* shared.css - 全站通用样式表 */

/* 基础变量定义 */
:root {
    --primary-color: #007bff; /* 主题蓝色 */
    --secondary-color: #6c757d; /* 次要灰色 */
    --accent-color: #28a745; /* 强调绿色 */
    --danger-color: #dc3545; /* 危险红色 */
    --text-color: #333; /* 主要文本颜色 */
    --light-text-color: #555; /* 辅助文本颜色 */
    --white-color: #fff; /* 白色 */
    --light-bg: #f8f9fa; /* 浅色背景 */
    --dark-bg: #343a40; /* 深色背景 */
    --border-color: #dee2e6; /* 边框颜色 */
    --font-family-sans: 'Roboto', 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --header-height: 80px;
    --footer-height: auto;
    --box-shadow-light: 0 2px 10px rgba(0,0,0,0.05);
    --box-shadow-medium: 0 5px 15px rgba(0,0,0,0.1);
    --transition-speed: 0.3s;
}

/* 全局重置与基础样式 */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    -webkit-text-size-adjust: 100%; /* Prevent text zoom on orientation change */
}

body {
    font-family: var(--font-family-sans);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--white-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    width: 100%;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-speed) ease;
}

a:hover,
a:focus {
    color: #0056b3;
    text-decoration: underline;
    outline: none;
}

ul {
    list-style: none;
}

img {
    max-width: 100%;
    height: auto;
    display: block; /* Remove extra space below images */
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.5em;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-color);
}

p {
    margin-bottom: 1em;
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    border: 1px solid transparent;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--white-color);
    border-color: var(--primary-color);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: #0056b3;
    border-color: #0056b3;
    color: var(--white-color);
    text-decoration: none;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--white-color);
    border-color: var(--secondary-color);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: #5a6268;
    border-color: #545b62;
    color: var(--white-color);
    text-decoration: none;
    transform: translateY(-1px);
}

.btn-tertiary {
    background-color: transparent;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-tertiary:hover,
.btn-tertiary:focus {
    background-color: var(--primary-color);
    color: var(--white-color);
    text-decoration: none;
    transform: translateY(-1px);
}

/* 头部样式 */
.main-header {
    background-color: var(--white-color);
    box-shadow: var(--box-shadow-light);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 15px 0;
    width: 100%;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    margin-right: 20px;
}

.logo a {
    display: flex;
    align-items: center;
    color: inherit;
}

.logo-img {
    height: 40px;
    margin-right: 10px;
    flex-shrink: 0;
}

.logo-text {
    font-size: 1.8em;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

.main-nav {
    flex-grow: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.nav-toggle {
    display: none; /* 默认在桌面端隐藏 */
    background: none;
    border: none;
    font-size: 1.7em;
    cursor: pointer;
    color: var(--text-color);
    padding: 5px;
}

.nav-menu {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
}

.nav-item {
    position: relative;
    margin-left: 25px;
}

.nav-link {
    display: block;
    padding: 10px 0;
    color: var(--text-color);
    font-weight: 500;
    white-space: nowrap;
    transition: color var(--transition-speed) ease;
}

.nav-link.active,
.nav-link:hover,
.nav-link:focus {
    color: var(--primary-color);
    text-decoration: none;
}

.has-submenu {
    position: relative;
}

.submenu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--white-color);
    box-shadow: var(--box-shadow-medium);
    min-width: 180px;
    z-index: 1001;
    border-radius: 5px;
    padding: 10px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease, visibility var(--transition-speed) ease;
}

.has-submenu:hover .submenu,
.has-submenu:focus-within .submenu {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.submenu li {
    margin: 0;
}

.submenu-link {
    display: block;
    padding: 10px 20px;
    color: var(--text-color);
    white-space: nowrap;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

.submenu-link:hover,
.submenu-link:focus {
    background-color: var(--light-bg);
    color: var(--primary-color);
    text-decoration: none;
}

.header-actions {
    display: flex;
    align-items: center;
    margin-left: 20px;
    flex-shrink: 0;
}

.search-box {
    position: relative;
    margin-right: 15px;
    display: flex;
    align-items: center;
}

.search-box input {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    width: 150px;
    transition: width var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.search-box input:focus {
    width: 200px;
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.search-box button {
    background: none;
    border: none;
    position: absolute;
    right: 10px;
    cursor: pointer;
    color: var(--secondary-color);
    font-size: 1em;
    padding: 0;
}

.search-box button:hover {
    color: var(--primary-color);
}

.login-btn, .register-btn {
    margin-left: 10px;
}

/* 主内容区域 */
#main-content {
    flex: 1; /* 使主内容区域占据剩余空间，将footer推到底部 */
    padding: 40px 0;
}

/* 底部样式 */
.main-footer {
    background-color: var(--dark-bg);
    color: #f8f9fa;
    padding: 40px 0 20px;
    font-size: 0.9em;
}

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

.footer-section h3 {
    color: var(--white-color);
    margin-bottom: 20px;
    font-size: 1.2em;
    position: relative;
    padding-bottom: 5px;
}

.footer-section h3::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 40px;
    height: 2px;
    background-color: var(--primary-color);
}

.footer-section p,
.footer-section ul {
    margin-bottom: 10px;
}

.footer-section ul li {
    margin-bottom: 8px;
}

.footer-section a {
    color: #ccc;
    transition: color var(--transition-speed) ease;
}

.footer-section a:hover,
.footer-section a:focus {
    color: var(--white-color);
    text-decoration: underline;
}

.social-icons {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.social-icons a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    background-color: #555;
    color: var(--white-color);
    border-radius: 50%;
    transition: background-color var(--transition-speed) ease;
}

.social-icons a:hover {
    background-color: var(--primary-color);
    text-decoration: none;
    transform: translateY(-2px);
}

.contact-info p {
    display: flex;
    align-items: flex-start;
    margin-bottom: 10px;
    line-height: 1.4;
}

.contact-info i {
    margin-right: 10px;
    color: var(--primary-color);
    font-size: 1.1em;
    flex-shrink: 0;
    padding-top: 2px; /* Align icon better with text */
}

.footer-bottom {
    border-top: 1px solid #444;
    padding-top: 20px;
    text-align: center;
}

.footer-bottom p {
    margin-bottom: 5px;
    color: #aaa;
}

.footer-bottom a {
    color: #aaa;
}

.footer-bottom a:hover {
    color: var(--white-color);
}

/* 返回顶部按钮 */
#scrollToTopBtn {
    display: none; /* 默认隐藏 */
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 99;
    border: none;
    outline: none;
    background-color: var(--primary-color);
    color: var(--white-color);
    cursor: pointer;
    padding: 15px;
    border-radius: 50%;
    font-size: 18px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transition: background-color var(--transition-speed) ease, transform var(--transition-speed) ease, opacity var(--transition-speed) ease;
    opacity: 0.8;
}

#scrollToTopBtn:hover {
    background-color: #0056b3;
    transform: translateY(-3px) scale(1.05);
    opacity: 1;
}

/* 响应式设计 */
@media (max-width: 992px) {
    .header-container {
        flex-wrap: wrap;
        justify-content: space-between; /* Keep logo left, actions right */
    }

    .logo {
        margin-bottom: 0;
        margin-right: 15px;
    }

    .main-nav {
        order: 3; /* Move nav below logo and actions on smaller screens */
        width: 100%;
        justify-content: center;
        margin-top: 15px;
    }

    .nav-toggle {
        display: block; /* 在小屏幕显示导航切换按钮 */
        margin-left: auto; /* Push toggle to the right */
    }

    .nav-menu {
        flex-direction: column;
        width: 100%;
        max-height: 0; /* 初始隐藏菜单 */
        overflow: hidden;
        transition: max-height 0.5s ease-out, padding 0.5s ease-out;
        background-color: #f8f8f8;
        border-top: 1px solid var(--border-color);
        padding: 0;
        align-items: stretch; /* Stretch items to fill width */
    }

    .nav-menu.active {
        max-height: 500px; /* 展开菜单的高度，需要根据内容调整 */
        padding: 10px 0;
        overflow-y: auto; /* Allow scrolling if menu is too long */
    }

    .nav-item {
        margin: 0;
        border-bottom: 1px solid var(--border-color);
        width: 100%;
        text-align: center;
    }

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

    .nav-link {
        padding: 15px 0;
    }

    .has-submenu:hover .submenu {
        display: none; /* 在小屏幕禁用hover显示子菜单 */
    }

    .nav-item.has-submenu > .nav-link {
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative; /* For the chevron icon */
    }

    .nav-item.has-submenu > .nav-link i {
        margin-left: 8px;
        transform: rotate(0deg); /* 初始状态 */
        transition: transform var(--transition-speed) ease;
    }

    /* 子菜单切换时的图标旋转 */
    .nav-item.has-submenu.open > .nav-link i {
        transform: rotate(180deg);
    }

    .submenu {
        position: static; /* 子菜单变为静态流式布局 */
        display: none;
        box-shadow: none;
        background-color: #eee;
        border-radius: 0;
        width: 100%;
        padding: 0;
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .nav-item.has-submenu.open .submenu {
        display: block;
    }

    .submenu li {
        border-bottom: 1px solid #ddd;
    }

    .submenu li:last-child {
        border-bottom: none;
    }

    .submenu-link {
        padding: 12px 0 12px 40px; /* 增加子菜单项缩进 */
        text-align: center;
    }

    .header-actions {
        margin-left: auto; /* Push actions to the right */
        display: flex;
        gap: 10px;
    }

    .search-box {
        margin-right: 0;
    }

    .login-btn, .register-btn {
        margin-left: 0;
    }

    .footer-grid {
        grid-template-columns: 1fr; /* 底部在小屏幕上堆叠 */
        text-align: center;
    }

    .footer-section ul {
        padding-left: 0;
    }

    .footer-section h3::after {
        left: 50%;
        transform: translateX(-50%);
    }

    .social-icons {
        justify-content: center;
    }

    .contact-info p {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .logo-text {
        font-size: 1.6em;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
        margin-top: 15px;
        margin-left: 0;
        flex-wrap: wrap;
    }
    .search-box {
        width: 100%;
        max-width: 300px;
        margin-bottom: 10px;
        margin-right: 0;
    }
    .search-box input {
        width: 100%;
    }
    .login-btn, .register-btn {
        width: 48%; /* Adjust for two buttons side-by-side */
        max-width: 145px;
        margin: 0 5px;
    }

    #main-content {
        padding: 30px 0;
    }

    .main-footer {
        padding: 30px 0 15px;
    }

    .footer-grid {
        gap: 20px;
        margin-bottom: 20px;
    }

    .footer-section h3 {
        margin-bottom: 15px;
    }
}

@media (max-width: 480px) {
    .logo-img {
        height: 35px;
    }
    .logo-text {
        font-size: 1.4em;
    }
    .btn {
        padding: 8px 15px;
        font-size: 0.9em;
    }
    .header-actions {
        flex-direction: column;
        gap: 8px;
    }
    .login-btn, .register-btn {
        width: 100%;
        max-width: 250px;
        margin: 0;
    }
    #scrollToTopBtn {
        padding: 12px;
        font-size: 16px;
        bottom: 20px;
        right: 20px;
    }
    .footer-bottom p {
        font-size: 0.8em;
    }
}
/* 移动端内容区防溢出（系统追加，请勿删除） */
@media (max-width: 768px) {
  .page-content img {
    max-width: 100% !important;
    height: auto !important;
    display: block;
  }
  .page-content {
    overflow-x: hidden;
    max-width: 100%;
  }
  body {
    overflow-x: hidden;
  }
}
