/**
 * 移动端样式文件
 * Mobile-specific Styles
 * 支持 320px - 768px 屏幕
 */

/* =====================
   基础变量覆盖
   ===================== */
:root {
    --mobile-padding: 12px;
    --mobile-radius: 12px;
    --mobile-font-base: 14px;
    --mobile-card-height: auto;
    --bottom-nav-height: 56px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* =====================
   媒体查询基础设置
   ===================== */
@media screen and (max-width: 768px) {
    /* 基础重置 */
    body {
        font-size: var(--mobile-font-base);
        padding-top: 60px !important;
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 10px) !important;
        -webkit-tap-highlight-color: transparent;
        overscroll-behavior-y: contain;
    }

    * {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* 隐藏PC端元素 */
    .desktop-only {
        display: none !important;
    }

    /* =====================
       导航栏优化
       ===================== */
    .navbar {
        padding: 8px 12px !important;
        height: 60px;
    }

    .navbar-brand {
        font-size: 16px !important;
        padding: 0 !important;
    }

    .navbar-collapse {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: #343a40;
        padding: 12px;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
        z-index: 1050;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    .navbar-nav {
        margin: 0 !important;
    }

    .nav-item {
        margin: 4px 0;
    }

    .nav-link {
        padding: 12px 16px !important;
        border-radius: 8px;
        font-size: 15px;
    }

    .nav-link:active {
        background: rgba(255,255,255,0.1);
    }

    /* 导航栏更新时间移动端优化 */
    .navbar-text {
        font-size: 11px !important;
        padding: 4px 8px;
        background: rgba(255,255,255,0.1);
        border-radius: 4px;
    }

    /* =====================
       股票卡片移动端优化
       ===================== */
    .stock-card {
        border-radius: var(--mobile-radius) !important;
        margin-bottom: 12px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
        border: none !important;
        overflow: hidden;
    }

    .stock-card:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }

    .stock-card .card-header {
        padding: 12px var(--mobile-padding) !important;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    }

    .stock-card .card-body {
        padding: 12px var(--mobile-padding) !important;
    }

    .stock-card .card-footer {
        padding: 10px var(--mobile-padding) !important;
        border-top: 1px solid #eee;
    }

    /* 卡片头部优化 */
    .stock-card h4 {
        font-size: 17px !important;
        margin-bottom: 2px !important;
    }

    .stock-card h4 a {
        color: white !important;
    }

    .stock-card .text-muted.small {
        font-size: 12px !important;
        color: rgba(255,255,255,0.8) !important;
    }

    /* 徽章优化 */
    .stock-card .badge {
        font-size: 10px !important;
        padding: 4px 8px !important;
    }

    /* =====================
       价格显示优化
       ===================== */
    .price-display {
        font-size: 28px !important;
        line-height: 1.2;
    }

    .price-display-large {
        padding: 12px 0 !important;
    }

    .price-display-large .display-4 {
        font-size: 36px !important;
    }

    .change-percent {
        font-size: 16px !important;
    }

    .h5 {
        font-size: 15px !important;
    }

    /* =====================
       信息项优化
       ===================== */
    .info-item {
        padding: 8px !important;
        background-color: #f8f9fa;
        border-radius: 8px !important;
        margin-bottom: 8px;
    }

    .info-item .text-muted.small {
        font-size: 11px !important;
        display: block;
        margin-bottom: 2px;
    }

    .info-item .fw-bold {
        font-size: 14px !important;
    }

    /* =====================
       按钮优化
       ===================== */
    .btn {
        padding: 10px 16px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
        min-height: 44px;
        touch-action: manipulation;
    }

    .btn-sm {
        padding: 8px 12px !important;
        font-size: 13px !important;
        min-height: 36px;
    }

    .btn-outline-primary {
        border-width: 1.5px;
    }

    .btn:active {
        transform: scale(0.96);
    }

    /* =====================
       页面标题优化
       ===================== */
    .page-title {
        font-size: 20px !important;
        padding: 12px var(--mobile-padding) !important;
        margin: 0 !important;
    }

    h1 {
        font-size: 22px !important;
    }

    h2 {
        font-size: 18px !important;
    }

    h5 {
        font-size: 15px !important;
    }

    /* =====================
       表格优化
       ===================== */
    .table {
        font-size: 13px !important;
    }

    .table td, .table th {
        padding: 10px 8px !important;
        vertical-align: middle;
    }

    /* =====================
       警告框优化
       ===================== */
    .alert {
        padding: 14px var(--mobile-padding) !important;
        border-radius: var(--mobile-radius) !important;
        font-size: 13px !important;
        margin: 12px var(--mobile-padding) !important;
    }

    .alert h5 {
        font-size: 14px !important;
        margin-bottom: 8px !important;
    }

    .alert ul {
        padding-left: 18px !important;
    }

    .alert li {
        margin-bottom: 4px !important;
    }

    /* =====================
       底部导航栏
       ===================== */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
        padding-bottom: var(--safe-area-bottom);
        background: white;
        display: flex;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
        z-index: 1000;
        border-top: 1px solid #eee;
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        color: #888;
        text-decoration: none;
        padding: 6px 0;
        transition: color 0.2s;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-item:active {
        background: rgba(0,0,0,0.03);
    }

    .bottom-nav-item.active {
        color: #667eea;
    }

    .bottom-nav-item i {
        font-size: 22px;
        margin-bottom: 3px;
    }

    .bottom-nav-item span {
        font-size: 10px;
    }

    /* =====================
       下拉刷新
       ===================== */
    .pull-to-refresh {
        position: relative;
        overflow: hidden;
    }

    .pull-to-refresh-indicator {
        position: absolute;
        top: -50px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 36px;
        background: white;
        border-radius: 50%;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: top 0.3s;
        z-index: 100;
    }

    .pull-to-refresh.pulling .pull-to-refresh-indicator {
        top: 10px;
    }

    .pull-to-refresh.refreshing .pull-to-refresh-indicator {
        top: 10px;
        animation: spin 1s linear infinite;
    }

    .pull-to-refresh.refreshing .pull-to-refresh-indicator i {
        animation: none;
    }

    /* =====================
       触摸手势优化
       ===================== */
    .swipe-container {
        overflow: hidden;
        position: relative;
    }

    .swipe-content {
        transition: transform 0.3s ease;
    }

    /* =====================
       股票列表优化
       ===================== */
    .stock-list {
        padding: 0 var(--mobile-padding);
    }

    .stock-list-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 14px var(--mobile-padding);
        background: white;
        border-radius: var(--mobile-radius);
        margin-bottom: 10px;
        box-shadow: 0 2px 6px rgba(0,0,0,0.05);
        min-height: 70px;
    }

    .stock-list-item:active {
        background: #f8f9fa;
    }

    .stock-list-left {
        flex: 1;
    }

    .stock-list-name {
        font-size: 15px;
        font-weight: 600;
        color: #333;
        margin-bottom: 2px;
    }

    .stock-list-code {
        font-size: 12px;
        color: #999;
    }

    .stock-list-right {
        text-align: right;
    }

    .stock-list-price {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 2px;
    }

    .stock-list-change {
        font-size: 12px;
    }

    /* =====================
       详情页优化
       ===================== */
    .detail-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 16px var(--mobile-padding);
        border-radius: 0 0 20px 20px;
        margin-bottom: 16px;
    }

    .detail-stock-name {
        font-size: 20px;
        font-weight: 600;
        margin-bottom: 4px;
    }

    .detail-stock-code {
        font-size: 13px;
        opacity: 0.8;
    }

    .detail-price {
        font-size: 32px;
        font-weight: bold;
        margin: 12px 0;
    }

    .detail-change {
        font-size: 15px;
        display: inline-block;
        padding: 4px 12px;
        background: rgba(255,255,255,0.2);
        border-radius: 20px;
    }

    .detail-info-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 0 var(--mobile-padding);
    }

    .detail-info-cell {
        background: white;
        padding: 12px;
        border-radius: 10px;
        text-align: center;
        box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    }

    .detail-info-cell .label {
        font-size: 11px;
        color: #999;
        margin-bottom: 4px;
    }

    .detail-info-cell .value {
        font-size: 14px;
        font-weight: 600;
        color: #333;
    }

    /* =====================
       K线图移动端优化
       ===================== */
    #klineChart {
        height: 300px !important;
        border-radius: var(--mobile-radius) !important;
    }

    /* =====================
       加载动画
       ===================== */
    .mobile-loading {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 40px;
    }

    .mobile-loading .spinner {
        width: 32px;
        height: 32px;
        border: 3px solid #f0f0f0;
        border-top-color: #667eea;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

    /* =====================
       骨架屏
       ===================== */
    .skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: 4px;
    }

    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }

    .skeleton-card {
        height: 180px;
        border-radius: var(--mobile-radius);
        margin-bottom: 12px;
    }

    /* =====================
       Toast提示
       ===================== */
    .mobile-toast {
        position: fixed;
        bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 20px);
        left: 50%;
        transform: translateX(-50%) translateY(100px);
        background: rgba(0,0,0,0.8);
        color: white;
        padding: 12px 24px;
        border-radius: 24px;
        font-size: 14px;
        z-index: 9999;
        opacity: 0;
        transition: all 0.3s;
    }

    .mobile-toast.show {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }

    /* =====================
       弹窗优化
       ===================== */
    .mobile-modal .modal-content {
        border-radius: var(--mobile-radius) var(--mobile-radius) 0 0 !important;
        margin-top: auto;
        min-height: 50vh;
    }

    .mobile-modal .modal-header {
        padding: 16px var(--mobile-padding) !important;
        border-bottom: 1px solid #eee;
    }

    .mobile-modal .modal-body {
        padding: 16px var(--mobile-padding) !important;
    }

    .mobile-modal .modal-footer {
        padding: 12px var(--mobile-padding) !important;
        border-top: 1px solid #eee;
    }

    .mobile-modal .btn-close {
        position: absolute;
        right: 12px;
        top: 12px;
    }

    /* =====================
       空状态
       ===================== */
    .empty-state {
        text-align: center;
        padding: 60px 20px;
        color: #999;
    }

    .empty-state i {
        font-size: 64px;
        margin-bottom: 16px;
        opacity: 0.5;
    }

    .empty-state p {
        font-size: 14px;
    }

    /* =====================
       容器优化
       ===================== */
    .container-fluid {
        padding-left: var(--mobile-padding) !important;
        padding-right: var(--mobile-padding) !important;
    }

    .row {
        margin-left: calc(-1 * var(--mobile-padding)) !important;
        margin-right: calc(-1 * var(--mobile-padding)) !important;
    }

    .col, [class*="col-"] {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    /* =====================
       投资提示优化
       ===================== */
    .investment-tip {
        margin: 12px 0 !important;
        padding: 14px !important;
        border-radius: var(--mobile-radius) !important;
    }

    /* =====================
       回到顶部按钮
       ===================== */
    .back-to-top {
        position: fixed;
        bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 16px);
        right: 16px;
        width: 44px;
        height: 44px;
        background: white;
        border-radius: 50%;
        box-shadow: 0 2px 12px rgba(0,0,0,0.15);
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
        z-index: 999;
    }

    .back-to-top.show {
        opacity: 1;
        visibility: visible;
    }

    .back-to-top:active {
        transform: scale(0.9);
    }

    /* =====================
       页脚移动端优化
       ===================== */
    footer {
        padding: 20px var(--mobile-padding) !important;
        margin-top: 20px !important;
    }

    footer h5 {
        font-size: 14px !important;
        margin-bottom: 8px !important;
    }

    footer p {
        font-size: 12px !important;
    }

    footer hr {
        margin: 12px 0 !important;
    }

    footer small {
        font-size: 11px !important;
    }
}

/* =====================
   小屏幕优化 (320px - 374px)
   ===================== */
@media screen and (max-width: 374px) {
    :root {
        --mobile-padding: 10px;
        --mobile-font-base: 13px;
    }

    .price-display {
        font-size: 24px !important;
    }

    .stock-card h4 {
        font-size: 15px !important;
    }

    .btn {
        padding: 8px 14px !important;
        font-size: 13px !important;
    }
}

/* =====================
   大屏幕平板 (768px+)
   ===================== */
@media screen and (min-width: 769px) {
    .bottom-nav {
        display: none !important;
    }

    .mobile-only {
        display: none !important;
    }
}

/* =====================
   横屏模式优化
   ===================== */
@media screen and (max-width: 768px) and (orientation: landscape) {
    #klineChart {
        height: 250px !important;
    }

    body {
        padding-bottom: 60px !important;
    }

    .bottom-nav {
        height: 50px;
        padding-bottom: 0;
    }
}

/* =====================
   深色模式支持
   ===================== */
@media (prefers-color-scheme: dark) {
    @media screen and (max-width: 768px) {
        body {
            background-color: #1a1a2e;
            color: #e0e0e0;
        }

        .stock-card,
        .stock-list-item,
        .detail-info-cell {
            background-color: #252538;
            color: #e0e0e0;
        }

        .info-item {
            background-color: #1f1f35;
        }

        .bottom-nav {
            background: #1a1a2e;
            border-top-color: #333;
        }

        .bottom-nav-item {
            color: #888;
        }

        footer {
            background-color: #151525 !important;
        }
    }
}

/* =====================
   减少动画（无障碍）
   ===================== */
@media (prefers-reduced-motion: reduce) {
    @media screen and (max-width: 768px) {
        * {
            animation: none !important;
            transition: none !important;
        }
    }
}
