/**
 * Mobile Responsive Stylesheet
 * Version: 1.0
 * Target: All devices < 768px
 * Author: AI Assistant (Trae IDE)
 * Date: 2026-04-03
 */

/* ========================================
   1. GLOBAL RESET & BASE STYLES FOR MOBILE
   ======================================== */

/* 防止iOS点击高亮 */
* {
    -webkit-tap-highlight-color: transparent;
}

/* 文字不可选（提升性能和体验）*/
body {
    -webkit-user-select: none;
    user-select: none;
}

/* 允许输入框选字 */
input, textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* ========================================
   2. TOOLBAR REDESIGN (移动端两行布局)
   ======================================== */

@media (max-width: 767px) {
    
    /* 工具栏容器 */
    .toolbar {
        flex-direction: column !important;
        height: auto !important;
        min-height: auto !important;
        padding: 8px !important;
        gap: 6px !important;
        
        background: linear-gradient(180deg, #1f2937 0%, #111827 100%) !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
        z-index: 100;
    }
    
    /* 第一行: 搜索 + 用户 */
    .toolbar > div:first-child,
    #user-info-area {
        width: 100% !important;
        justify-content: space-between !important;
        margin-bottom: 4px !important;
    }
    
    /* 搜索框: 自适应宽度 */
    #stock-code-input {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: none !important;
        font-size: 14px !important;
        height: 36px !important;
        padding-left: 28px !important;
        padding-right: 32px !important;
    }
    
    /* 清除按钮位置调整 */
    #btn-clear-input {
        right: 6px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
    }
    
    /* 搜索按钮 */
    #btn-search-stock {
        height: 36px !important;
        padding: 0 14px !important;
        font-size: 14px !important;
        border-radius: 6px !important;
    }
    
    /* 第二行: 周期按钮 + 功能按钮 */
    .toolbar > button:not(#btn-search-stock):not([id^="btn-"]) {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-height: 36px !important;
        min-width: 44px !important;
        padding: 6px 10px !important;
        font-size: 12px !important;
        white-space: nowrap !important;
        border-radius: 6px !important;
        flex-shrink: 0;
    }
    
    /* 预测按钮特殊样式 */
    #btn-predict {
        background: linear-gradient(135deg, #1e40af, #3b82f6) !important;
        box-shadow: 0 2px 6px rgba(30,64,175,0.3) !important;
    }
    
    /* 用户区域调整顺序到第一行右侧 */
    #user-info-area {
        order: -1;
    }
    
    /* 用户按钮尺寸优化 */
    #btn-login,
    #btn-user,
    #btn-vip {
        min-height: 36px !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
        border-radius: 6px !important;
    }
    
    /* VIP徽章优化 */
    #user-vip-badge {
        font-size: 10px !important;
        padding: 3px 8px !important;
    }
}

/* ========================================
   3. STOCK LIST (底部抽屉模式)
   ======================================== */

@media (max-width: 767px) {
    
    /* 默认隐藏侧边栏（从左侧滑出）*/
    #stock-list-container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        width: 85vw !important;
        max-width: 320px;
        height: 100vh !important;
        z-index: 999 !important;
        box-shadow: 2px 0 16px rgba(0,0,0,0.5);
        opacity: 1 !important;
    }
    
    /* 展开状态 */
    #stock-list-container.active {
        transform: translateX(0) !important;
    }
    
    /* 遮罩层 */
    #stock-list-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 998;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    
    #stock-list-overlay.active {
        display: block;
    }
    
    /* 切换按钮: FAB浮动按钮 */
    #stock-list-toggle {
        position: fixed !important;
        bottom: 80px; /* 底部TabBar上方 */
        right: 16px;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        width: 48px !important;
        height: 48px !important;
        border-radius: 50% !important;
        background: linear-gradient(135deg, #3b82f6, #2563eb) !important;
        box-shadow: 0 4px 12px rgba(59,130,246,0.4);
        z-index: 997;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* FAB图标旋转动画 */
    #stock-list-toggle.active span {
        transform: rotate(180deg);
        transition: transform 0.3s ease;
    }
    
    #stock-list-toggle span {
        transition: transform 0.3s ease;
    }
    
    /* 自选股列表项: 增大点击区域 */
    #stock-list-container li,
    #stock-list-container div[style*="padding"],
    #stock-list-container .stock-item {
        padding: 14px 16px !important;
        min-height: 56px !important;
        border-bottom: 1px solid #374151;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between;
    }
    
    /* 股票名称: 加粗加大 */
    .stock-name,
    #stock-list-container strong {
        font-size: 15px !important;
        font-weight: 600 !important;
    }
    
    /* 股票代码: 灰色小字 */
    .stock-code {
        font-size: 12px !important;
        color: #9ca3af !important;
    }
    
    /* 删除按钮: 右滑显示或常显 */
    .delete-btn,
    button[onclick*="removeStock"] {
        width: 36px !important;
        height: 36px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        border-radius: 50% !important;
        background: #ef4444 !important;
        color: white !important;
        font-size: 18px !important;
    }
}

/* ========================================
   4. CANVAS & CHART AREA
   ======================================== */

@media (max-width: 767px) {
    
    /* 图表容器 */
    canvas#klineCanvas {
        touch-action: none;
        display: block;
    }
    
    /* 图表父容器自适应高度 */
    body.has-tabbar #klineCanvas:parent,
    [style*="flex: 1"][style*="overflow: hidden"] {
        height: calc(100vh - 120px - 64px) !important; /* 工具栏 + TabBar */
    }
    
    body:not(.has-tabbar) #klineCanvas:parent,
    [style*="flex: 1"][style*="overflow: hidden"] {
        height: calc(100vh - 120px) !important;
    }
    
    /* 十字光标提示: 移动端优化 */
    .crosshair-tooltip,
    [style*="position: absolute"][style*="z-index: 10"] {
        font-size: 11px !important;
        padding: 6px 10px !important;
        pointer-events: none !important;
        border-radius: 6px !important;
    }
    
    /* MACD/统计按钮优化 */
    #btn-macd-lines,
    #btn-volume-stats {
        padding: 4px 10px !important;
        font-size: 11px !important;
        border-radius: 4px !important;
        z-index: 20 !important;
    }
}

/* ========================================
   5. BOTTOM TAB BAR (新增组件)
   ======================================== */

@media (max-width: 767px) {
    
    /* 底部导航栏容器 */
    .bottom-tabbar {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(64px + env(safe-area-inset-bottom));
        background: #1f2937;
        border-top: 1px solid #374151;
        z-index: 1000;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -2px 8px rgba(0,0,0,0.2);
    }
    
    /* Tab项 */
    .tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 0;
        color: #9ca3af;
        text-decoration: none;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
    }
    
    /* Tab图标 */
    .tab-icon {
        width: 24px;
        height: 24px;
        font-size: 20px;
        line-height: 24px;
        text-align: center;
    }
    
    /* Tab文字 */
    .tab-label {
        font-size: 10px;
        font-weight: 500;
    }
    
    /* 选中状态 */
    .tab-item.active {
        color: #3b82f6;
    }
    
    .tab-item.active .tab-icon {
        transform: scale(1.1);
    }
    
    /* 主内容区: 给底部TabBar留出空间 */
    body.has-tabbar {
        padding-bottom: 64px;
    }
    
    body.has-tabbar > div[style*="height: 100vh"],
    body.has-tabbar > div[style*="100vh"] {
        height: calc(100vh - 64px) !important;
    }
}

/* 仅在大屏隐藏TabBar */
@media (min-width: 768px) {
    .bottom-tabbar {
        display: none !important;
    }
    
    body.has-tabbar {
        padding-bottom: 0;
    }
}

/* ========================================
   6. MODALS (VIP / INVITE / LOGIN)
   ======================================== */

@media (max-width: 480px) {
    
    /* 通用模态框遮罩层 */
    .modal-overlay,
    .vip-overlay,
    .invite-overlay {
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        background: rgba(0,0,0,0.6);
    }
    
    /* 模态框容器 */
    .vip-container,
    .invite-container,
    .login-modal,
    [id$="-modal"][style*="display"][style*="absolute"] {
        width: 92vw !important;
        max-width: none !important;
        max-height: 85vh !important;
        margin: 5vh auto !important;
        border-radius: 16px !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    
    /* 模态框头部 */
    .vip-header,
    .invite-header,
    [class$="-header"] {
        padding: 16px 20px !important;
        position: sticky;
        top: 0;
        background: inherit;
        z-index: 10;
        border-radius: 16px 16px 0 0;
    }
    
    .vip-header h2,
    .invite-header h2 {
        font-size: 18px !important;
        margin: 0 !important;
    }
    
    /* 关闭按钮 */
    .vip-close,
    .invite-close,
    [class$="-close"] {
        width: 32px !important;
        height: 32px !important;
        font-size: 24px !important;
        top: 12px !important;
        right: 12px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* Tab标签: 横向滚动 */
    .vip-tabs,
    [class$="-tabs"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 16px !important;
        display: flex !important;
        gap: 4px !important;
    }
    
    .vip-tabs::-webkit-scrollbar,
    [class$="-tabs"]::-webkit-scrollbar {
        display: none;
    }
    
    .vip-tab,
    [class$="-tab"][data-level] {
        padding: 10px 16px !important;
        font-size: 14px !important;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    /* 产品卡片: 单列布局 */
    .vip-products,
    [id$="-products"] {
        grid-template-columns: 1fr !important;
        padding: 16px !important;
        gap: 12px !important;
        display: grid !important;
    }
    
    /* 产品卡片单项 */
    .product-card,
    [class*="product-card"],
    .vip-products > div {
        padding: 16px !important;
        border-radius: 12px !important;
        border: 1px solid #374151 !important;
    }
    
    .product-name {
        font-size: 16px !important;
        font-weight: 600 !important;
    }
    
    .product-price {
        font-size: 22px !important;
    }
    
    /* 支付方式: 横向排列 */
    .pay-options,
    [class*="pay-options"] {
        flex-direction: row !important;
        gap: 12px !important;
        display: flex !important;
    }
    
    .pay-option,
    [class*="pay-option"] {
        flex: 1 !important;
        padding: 12px !important;
        border-radius: 8px !important;
    }
    
    /* CTA按钮: 全宽 + 大尺寸 */
    .vip-pay-btn,
    .receive-btn,
    .copy-btn,
    [class*="pay-btn"],
    [class*="receive-btn"],
    [id^="copy-"] {
        width: 100% !important;
        height: 48px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        font-weight: 600 !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* 登录表单 */
    .login-form,
    [id*="login"][style*="modal"] form {
        padding: 20px !important;
    }
    
    .form-group,
    [class*="form-group"] {
        margin-bottom: 16px !important;
    }
    
    .form-input,
    input[type="text"],
    input[type="password"],
    input[type="tel"] {
        width: 100% !important;
        height: 48px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
        box-sizing: border-box !important;
        padding: 0 16px !important;
    }
    
    .form-button,
    button[type="submit"],
    [id*="login"][style*="modal"] button[type="button"]:not([class*="close"]) {
        width: 100% !important;
        height: 48px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
    }
    
    /* 邀请码复制区域 */
    .invite-code-box,
    .invite-link-box,
    [id*="code-box"],
    [id*="link-box"] {
        flex-direction: column !important;
        gap: 8px !important;
        display: flex !important;
    }
    
    #invite-code,
    #invite-link,
    input[id^="invite-"] {
        width: 100% !important;
        font-size: 16px !important;
        height: 44px !important;
    }
    
    /* 统计数据: 横向排列 */
    .invite-stats,
    [class*="stats"] {
        flex-direction: row !important;
        justify-content: space-around !important;
        padding: 16px !important;
        gap: 8px !important;
    }
    
    .stat-item {
        text-align: center;
        flex: 1;
    }
    
    .stat-value {
        font-size: 24px !important;
        font-weight: 700 !important;
    }
    
    .stat-label {
        font-size: 11px !important;
        color: #9ca3af !important;
    }
    
    /* 规则文本 */
    .reward-rules,
    .rule-item {
        font-size: 13px !important;
        line-height: 1.6 !important;
        padding: 8px 0 !important;
    }
}

/* ========================================
   7. USER DROPDOWN MENU
   ======================================== */

@media (max-width: 767px) {
    
    /* 下拉菜单位置调整: 底部弹出 */
    #user-dropdown-menu {
        position: fixed !important;
        top: auto !important;
        bottom: 70px; /* TabBar上方 */
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        min-width: auto !important;
        max-height: 60vh;
        overflow-y: auto;
        border-radius: 16px !important;
        animation: slideUpMobile 0.3s ease-out;
    }
    
    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    /* 同步区域: 简化布局 */
    #sync-section,
    [id="sync-section"] {
        padding: 10px !important;
        margin: 8px 0 !important;
        border-radius: 8px !important;
    }
    
    #sync-section > div:first-child,
    [id="sync-section"] > div:nth-child(2) {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    
    #btn-sync-upload,
    #btn-sync-download {
        flex: 1 !important;
        min-width: calc(50% - 3px) !important;
        height: 40px !important;
        font-size: 12px !important;
    }
    
    #sync-message {
        font-size: 11px !important;
        padding: 6px !important;
    }
}

/* ========================================
   8. SEARCH RESULTS DROPDOWN
   ======================================== */

@media (max-width: 767px) {
    
    #search-results {
        position: fixed !important;
        top: 85px !important; /* 工具栏下方 */
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-height: 60vh;
        z-index: 999;
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.4);
        overflow-y: auto;
    }
    
    .search-result-item,
    #search-results > div {
        padding: 14px 16px !important;
        min-height: 56px;
        border-bottom: 1px solid #374151;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
    }
    
    .search-result-item:hover,
    #search-results > div:hover {
        background: #374151;
    }
}

/* ========================================
   9. UTILITY CLASSES & HELPERS
   ======================================== */

/* 隐藏桌面端元素 */
.hide-on-mobile {
    display: none !important;
}

/* 显示移动端元素 */
.show-on-mobile {
    display: block !important;
}

/* 仅在特定方向显示 */
.landscape-only {
    display: none !important;
}
.portrait-only {
    display: block !important;
}

@media (orientation: landscape) and (max-height: 500px) {
    .landscape-only {
        display: block !important;
    }
    .portrait-only {
        display: none !important;
    }
    
    /* 横屏时隐藏底部TabBar */
    .bottom-tabbar {
        display: none !important;
    }
    
    body.has-tabbar {
        padding-bottom: 0;
    }
    
    /* 横屏时工具栏改为单行紧凑 */
    .toolbar {
        flex-direction: row !important;
        height: 48px !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        padding: 4px 8px !important;
    }
    
    .toolbar::-webkit-scrollbar {
        height: 4px;
    }
    
    .toolbar::-webkit-scrollbar-thumb {
        background: #4b5563;
        border-radius: 2px;
    }
}

/* ========================================
   10. PRINT STYLES (可选)
   ======================================== */

@media print {
    .toolbar,
    .bottom-tabbar,
    #stock-list-toggle,
    #stock-list-overlay,
    #user-dropdown-menu {
        display: none !important;
    }
    
    #klineCanvas {
        width: 100% !important;
        height: auto !important;
        max-height: 80vh;
    }
    
    body {
        background: white;
        color: black;
    }
}

/* ========================================
   11. ACCESSIBILITY ENHANCEMENTS
   ======================================== */

/* 焦点可见性（键盘导航）*/
:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .vip-pay-btn,
    .receive-btn,
    .tab-item.active {
        border: 2px solid currentColor;
    }
}

/* ========================================
   12. SAFE AREA SUPPORT (iPhone X+)
   ======================================== */

@supports (padding: max(0px)) {
    .bottom-tabbar {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
        height: calc(64px + env(safe-area-inset-bottom));
    }
    
    body.has-tabbar {
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
    }
    
    .toolbar {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }
}

/* ========================================
   13. DARK MODE ENHANCEMENT (Optional)
   ======================================== */

@media (prefers-color-scheme: light) {
    /* 如果未来支持浅色模式，可以在这里添加 */
    /* 当前系统为深色主题，此部分预留 */
}

/* ========================================
   END OF MOBILE STYLESHEET
   ======================================== */
