/* ============================================================
   ETF量化投研系统 — 移动端Chrome适配
   支持：响应式布局、触控交互、安全区域、视口高度
   ============================================================ */

/* ── 基础视口和安全区域 ── */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --vh: 1vh;
}

/* 修复移动端Chrome地址栏收起导致的视口高度问题 */
html {
    height: -webkit-fill-available;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* ── 触控优化 ── */
@media (hover: none) and (pointer: coarse) {
    /* 增大点击目标 */
    button, .btn, a, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }

    /* 优化按钮间距 */
    .btn-group, .action-buttons {
        gap: 12px;
    }

    /* 禁用hover效果 */
    .hover-effect:hover {
        transform: none;
        box-shadow: inherit;
    }

    /* 优化滚动 */
    .scrollable {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
}

/* ── 响应式断点 ── */

/* 平板竖屏 (768px - 1024px) */
@media screen and (max-width: 1024px) {
    .container {
        padding: 16px;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .charts-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .two-col {
        grid-template-columns: 1fr;
    }

    /* 表格横向滚动 */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }
}

/* 手机横屏 (640px - 768px) */
@media screen and (max-width: 768px) {
    .container {
        padding: 12px;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px 12px;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .chart-panel {
        padding: 16px;
        min-height: 280px;
    }

    .chart-panel h2 {
        font-size: 15px;
        margin-bottom: 14px;
    }

    /* 头部导航 */
    .header {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 16px;
    }

    .header-nav {
        order: 3;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .header-nav::-webkit-scrollbar {
        display: none;
    }

    .header-nav a {
        white-space: nowrap;
        padding: 8px 14px;
        font-size: 13px;
    }

    /* 搜索框 */
    .search-box input {
        width: 120px;
        font-size: 14px;
    }

    /* 按钮优化 */
    .btn, button {
        padding: 10px 16px;
        font-size: 14px;
    }

    /* 表单元素 */
    input, select, textarea {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 10px 12px;
    }

    /* 模态框 */
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 10px;
        max-height: calc(var(--vh, 1vh) * 90);
        overflow-y: auto;
    }

    /* 卡片布局 */
    .card-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* 文字调整 */
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }

    .text-sm { font-size: 12px; }
    .text-lg { font-size: 16px; }
}

/* 手机竖屏 (480px以下) */
@media screen and (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .stats-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px 10px;
    }

    .stat-card .stat-value {
        font-size: 20px;
    }

    .stat-card .stat-label {
        font-size: 12px;
    }

    .chart-panel {
        padding: 12px;
        min-height: 240px;
        border-radius: 8px;
    }

    .chart-panel h2 {
        font-size: 14px;
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    /* 头部简化 */
    .header {
        padding: 10px 12px;
    }

    .header h1 {
        font-size: 16px;
    }

    .search-box input {
        width: 100px;
        font-size: 14px;
    }

    /* 按钮 */
    .btn, button {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* 表格 */
    table {
        font-size: 12px;
    }

    th, td {
        padding: 8px 6px;
    }

    /* 弹窗 */
    .modal-content {
        padding: 16px;
        border-radius: 10px;
    }

    /* 列表项 */
    .list-item {
        padding: 10px;
        margin-bottom: 8px;
    }

    /* 标签 */
    .badge, .tag {
        padding: 4px 8px;
        font-size: 11px;
    }

    /* 间距调整 */
    .mb-3 { margin-bottom: 12px; }
    .mt-3 { margin-top: 12px; }
    .p-3 { padding: 12px; }
}

/* ── 移动端特有组件 ── */

/* 底部安全区域填充 */
.safe-bottom {
    padding-bottom: calc(var(--sab) + 16px);
}

/* 移动端底部导航栏 */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-white, #fff);
    border-top: 1px solid var(--border, #e8ecf1);
    padding: 8px 0 calc(8px + var(--sab));
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

@media screen and (max-width: 768px) {
    .mobile-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    body {
        padding-bottom: calc(60px + var(--sab));
    }

    .header-nav {
        display: none;
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 12px;
    color: var(--text-secondary, #636e72);
    text-decoration: none;
    font-size: 10px;
    transition: color 0.2s;
}

.mobile-nav-item.active {
    color: var(--accent, #4a90d9);
}

.mobile-nav-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 2px;
}

/* 移动端菜单按钮 */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    padding: 8px;
    cursor: pointer;
}

@media screen and (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
}

/* 移动端侧边菜单 */
.mobile-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--bg-white, #fff);
    z-index: 2000;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-sidebar.open {
    left: 0;
}

.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
}

@media screen and (max-width: 768px) {
    .mobile-sidebar,
    .mobile-sidebar-overlay {
        display: block;
    }
}

/* ── 触控反馈 ── */
@media (hover: none) {
    .touch-feedback {
        -webkit-tap-highlight-color: transparent;
    }

    .touch-feedback:active {
        opacity: 0.7;
        transform: scale(0.98);
    }

    /* 长按菜单 */
    .long-pressable {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ── 输入框优化 ── */
@media screen and (max-width: 768px) {
    /* 防止输入时页面缩放 */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
        transform: translateZ(0);
    }

    /* 搜索框优化 */
    input[type="search"] {
        -webkit-appearance: none;
        appearance: none;
    }

    input[type="search"]::-webkit-search-cancel-button {
        -webkit-appearance: none;
        height: 14px;
        width: 14px;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E") center/contain no-repeat;
    }
}

/* ── 滚动条优化 ── */
@media screen and (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }

    ::-webkit-scrollbar-track {
        background: transparent;
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.2);
        border-radius: 2px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: rgba(0,0,0,0.3);
    }
}

/* ── 打印隐藏 ── */
@media print {
    .mobile-nav,
    .mobile-menu-btn,
    .mobile-sidebar,
    .mobile-sidebar-overlay {
        display: none !important;
    }
}

/* ── 暗色模式适配 ── */
html.dark .mobile-nav {
    background: var(--bg-white, #161822);
    border-top-color: var(--border, #2a2d3e);
}

html.dark .mobile-sidebar {
    background: var(--bg-white, #161822);
}

html.dark .mobile-nav-item {
    color: var(--text-secondary, #a0a0b0);
}

html.dark .mobile-nav-item.active {
    color: var(--accent, #5b9bd5);
}

/* ── 动画优化 ── */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
