/**
 * huncoin 统一移动端样式
 * 整合所有移动端导航和响应式设计
 * 解决样式冲突和不一致问题
 */

/* ==================== 基础变量定义 ==================== */
:root {
    /* 移动端断点 */
    --mobile-breakpoint-xs: 480px;
    --mobile-breakpoint-sm: 640px;
    --mobile-breakpoint-md: 768px;
    --mobile-breakpoint-lg: 1024px;
    
    /* 移动端触摸目标尺寸 */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    
    /* 移动端导航高度 */
    --mobile-nav-height: 56px;
    
    /* 移动端间距 */
    --mobile-spacing-xs: 0.25rem;
    --mobile-spacing-sm: 0.5rem;
    --mobile-spacing-md: 0.75rem;
    --mobile-spacing-lg: 1rem;
    --mobile-spacing-xl: 1.5rem;
}

/* ==================== 防止iOS缩放 ==================== */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="tel"],
input[type="url"],
textarea,
select {
    font-size: 16px !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* ==================== 统一导航栏样式 ==================== */

/* 桌面端默认样式 */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-fixed, 1020);
    background: var(--bg-glass, rgba(0, 0, 0, 0.8));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-secondary, rgba(255, 255, 255, 0.1));
    transition: all 0.3s ease;
}

.navbar-content,
.navbar .container > div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    position: relative;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-primary, #ffffff);
    text-decoration: none;
    z-index: 2;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-link {
    color: var(--text-secondary, #a3a3a3);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-accent, #00d4ff);
}

/* 汉堡菜单按钮 - 默认隐藏 */
.navbar-toggler {
    display: none;
    width: var(--touch-target-comfortable);
    height: var(--touch-target-comfortable);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.375rem;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    padding: 0;
    margin-left: auto;
    margin-right: 0.5rem;
}

.navbar-toggler:hover,
.navbar-toggler:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-accent, #00d4ff);
    outline: none;
}

.navbar-toggler-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-primary, #ffffff);
    font-size: 1.25rem;
}

/* ==================== 移动端样式 (768px及以下) ==================== */
@media (max-width: 768px) {
    /* 导航栏容器 */
    .navbar {
        height: var(--mobile-nav-height);
        padding: 0 1rem;
    }
    
    .navbar-content,
    .navbar .container > div:first-child {
        padding: 0;
        height: var(--mobile-nav-height);
    }
    
    .navbar .container {
        padding: 0;
        width: 100%;
        max-width: 100%;
    }
    
    /* Logo尺寸调整 */
    .navbar-brand {
        font-size: 1.1rem;
        gap: 0.5rem;
        flex-shrink: 0;
    }
    
    .navbar-brand i {
        font-size: 1.25rem;
    }
    
    /* 显示汉堡菜单 */
    .navbar-toggler {
        display: flex !important;
        order: 2;
    }
    
    /* 移动端导航菜单 */
    .navbar-nav {
        position: fixed;
        top: var(--mobile-nav-height);
        left: 0;
        right: 0;
        background: var(--bg-card, rgba(0, 0, 0, 0.95));
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-bottom: 1px solid var(--border-secondary, rgba(255, 255, 255, 0.1));
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 1rem;
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 1000;
        max-height: calc(100vh - var(--mobile-nav-height));
        overflow-y: auto;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }
    
    /* 菜单显示状态 */
    .navbar-nav.show {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }
    
    /* 导航链接样式 */
    .navbar-nav li {
        width: 100%;
    }
    
    .nav-link {
        display: flex;
        align-items: center;
        width: 100%;
        padding: 0.875rem 1rem;
        min-height: var(--touch-target-min);
        font-size: 1rem;
        border-radius: 0.5rem;
        transition: all 0.2s ease;
    }
    
    .nav-link:hover,
    .nav-link:active {
        background: rgba(255, 255, 255, 0.05);
        transform: translateX(4px);
    }
    
    .nav-link.active {
        background: rgba(0, 212, 255, 0.1);
        border-left: 3px solid var(--text-accent, #00d4ff);
    }
    
    /* 钱包连接按钮 */
    #connect-wallet-btn {
        width: 100%;
        margin-top: 1rem;
        padding: 0.875rem;
        min-height: var(--touch-target-comfortable);
        font-size: 1rem;
    }
    
    /* 语言切换器位置 */
    #language-switcher {
        position: absolute;
        right: 4rem;
        top: 50%;
        transform: translateY(-50%);
    }
    
    /* 防止body滚动（当菜单打开时） */
    body.menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ==================== 小屏幕优化 (480px及以下) ==================== */
@media (max-width: 480px) {
    .navbar {
        padding: 0 0.75rem;
    }
    
    .navbar-brand {
        font-size: 1rem;
    }
    
    .navbar-brand span {
        display: none; /* 隐藏文字，只显示图标 */
    }
    
    .navbar-toggler {
        width: 40px;
        height: 40px;
    }
    
    .navbar-nav {
        padding: 0.75rem;
    }
    
    .nav-link {
        padding: 0.75rem;
        font-size: 0.9375rem;
    }
    
    #language-switcher {
        right: 3.5rem;
    }
    
    #language-switcher .lang-btn {
        padding: 0.5rem;
        font-size: 0.875rem;
        min-width: auto;
    }
    
    #language-switcher .lang-text {
        display: none; /* 只显示旗帜图标 */
    }
}

/* ==================== 触摸优化 ==================== */
@media (hover: none) and (pointer: coarse) {
    /* 移动设备触摸优化 */
    .navbar-toggler,
    .nav-link,
    .btn,
    button,
    a {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* 增加触摸反馈 */
    .navbar-toggler:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.15);
    }
    
    .nav-link:active {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* ==================== 横屏模式优化 ==================== */
@media (max-height: 500px) and (orientation: landscape) {
    .navbar {
        height: 48px;
    }
    
    .navbar-content {
        height: 48px;
    }
    
    .navbar-nav {
        top: 48px;
        max-height: calc(100vh - 48px);
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0.5rem;
    }
    
    .navbar-nav li {
        width: auto;
        flex: 0 0 auto;
    }
    
    .nav-link {
        padding: 0.5rem 1rem;
        min-height: 36px;
    }
}

/* ==================== 动画效果 ==================== */
@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* 菜单项渐进动画 */
.navbar-nav.show li {
    animation: fadeIn 0.3s ease backwards;
}

.navbar-nav.show li:nth-child(1) { animation-delay: 0.05s; }
.navbar-nav.show li:nth-child(2) { animation-delay: 0.1s; }
.navbar-nav.show li:nth-child(3) { animation-delay: 0.15s; }
.navbar-nav.show li:nth-child(4) { animation-delay: 0.2s; }
.navbar-nav.show li:nth-child(5) { animation-delay: 0.25s; }
.navbar-nav.show li:nth-child(6) { animation-delay: 0.3s; }
.navbar-nav.show li:nth-child(7) { animation-delay: 0.35s; }

/* ==================== 辅助类 ==================== */

/* 移动端显示/隐藏 */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
}

/* 防止内容被导航栏遮挡 */
body {
    padding-top: var(--mobile-nav-height);
}

@media (min-width: 769px) {
    body {
        padding-top: 80px; /* 桌面端导航栏高度 */
    }
}

/* ==================== 兼容性修复 ==================== */

/* 修复iOS Safari的导航栏问题 */
@supports (-webkit-touch-callout: none) {
    .navbar {
        -webkit-backface-visibility: hidden;
        -webkit-transform: translateZ(0);
    }
    
    .navbar-nav {
        -webkit-overflow-scrolling: touch;
    }
}

/* 修复Android Chrome的滚动问题 */
.navbar-nav::-webkit-scrollbar {
    width: 4px;
}

.navbar-nav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.navbar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* ==================== 深色模式支持 ==================== */
@media (prefers-color-scheme: dark) {
    .navbar {
        background: rgba(0, 0, 0, 0.95);
    }
    
    .navbar-nav {
        background: rgba(10, 10, 10, 0.98);
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    .navbar,
    .navbar-toggler {
        display: none !important;
    }
    
    body {
        padding-top: 0 !important;
    }
}