/* ──────────────────────────────────────────────────────
   移动端增强样式 - Mobile Enhancements
   ────────────────────────────────────────────────────── */

/* 平板适配 (768px - 1024px) */
@media (max-width: 1024px) {
  .header-right {
    gap: 8px;
  }

  .cards {
    gap: 12px;
  }
}

/* 手机适配 (max-width: 768px) */
@media (max-width: 768px) {
  /* ── 头部优化 ── */
  .header {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .header-left {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .header-right {
    flex-wrap: wrap;
    gap: 8px;
  }

  .btn {
    flex: 1 1 calc(50% - 4px);
    justify-content: center;
    min-width: 0;
    font-size: 13px;
    padding: 10px 12px;
  }

  .btn-primary {
    flex: 1 1 100%;
  }

  /* ── 搜索筛选栏 ── */
  .search-filter-bar {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
  }

  .search-filter-bar > div {
    min-width: 100% !important;
  }

  .search-filter-bar input,
  .search-filter-bar select {
    font-size: 16px; /* 防止iOS自动缩放 */
  }

  .search-filter-bar button {
    width: 100%;
  }

  /* ── 卡片网格 ── */
  .cards {
    flex-wrap: wrap;
    gap: 12px;
  }

  .card {
    padding: 16px;
    margin-bottom: 12px;
  }

  .card-value {
    font-size: 26px;
    word-break: break-all;
  }

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

  /* ── 弹窗优化 ── */
  .modal-content,
  .compare-modal-content,
  .strategy-modal-content {
    padding: 16px;
    border-radius: 12px;
    max-width: 100vw !important;
    margin: 8px;
    max-height: 90vh;
    overflow-x: hidden;
  }

  .modal-title {
    font-size: 18px;
  }

  .modal-header {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .modal-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .modal-section {
    padding: 12px;
  }

  .section-title {
    font-size: 14px;
  }

  .section-content > div {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* ── 图表优化 ── */
  .chart-container {
    height: 220px;
  }

  .period-selector {
    gap: 6px;
    flex-wrap: wrap;
  }

  .period-radio label {
    font-size: 12px;
    padding: 6px 10px;
  }

  /* ── 对比功能优化 ── */
  .compare-cards-row {
    flex-direction: column;
    gap: 12px;
  }

  .compare-card {
    min-width: 100%;
    flex: none;
  }

  .compare-chart-wrap {
    height: 200px;
  }

  .compare-table-section {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .compare-bar {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    left: 8px;
    right: 8px;
    bottom: 8px;
  }

  .compare-bar-tags {
    flex-wrap: wrap;
  }

  .compare-bar-btn {
    width: 100%;
  }

  /* ── 贡献度面板 ── */
  .contribution-content {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .contribution-chart-wrap {
    height: 240px;
  }

  .contribution-panel {
    padding: 16px;
    overflow-x: hidden;
  }

  .contribution-header {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .contribution-tabs {
    width: 100%;
  }

  .contribution-tab {
    flex: 1;
    justify-content: center;
  }

  /* 贡献度项目优化 */
  .contribution-item {
    flex-wrap: wrap;
    padding: 10px;
    gap: 8px;
  }

  .contribution-info {
    flex: 1 1 calc(100% - 40px);
    min-width: 0;
    overflow: hidden;
  }

  .contribution-name {
    white-space: normal;
    word-break: break-word;
    font-size: 12px;
  }

  .contribution-code {
    font-size: 10px;
  }

  .contribution-stats {
    flex: 0 0 100%;
    justify-content: flex-start;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
    margin-top: 4px;
  }

  .contribution-amount {
    text-align: left;
    flex: 1;
  }

  .contribution-amount-value {
    font-size: 12px;
  }

  .contribution-amount-percent {
    font-size: 10px;
  }

  .contribution-bar {
    width: 100%;
    flex: 0 0 100%;
    height: 6px;
    margin-top: 8px;
  }

  /* ── 基金信息面板 ── */
  .fund-info-content {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .fund-info-panel {
    padding: 16px;
  }

  .fund-info-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* ── 按钮组优化 ── */
  .modal-actions {
    flex-direction: column;
    gap: 8px;
  }

  .modal-actions button {
    width: 100%;
  }
}

/* 小屏手机适配 (max-width: 640px) */
@media (max-width: 640px) {
  body {
    padding: 8px;
  }

  .header {
    padding: 10px;
  }

  .btn {
    font-size: 12px;
    padding: 8px 10px;
  }

  .card {
    padding: 12px;
  }

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

  .modal-content,
  .compare-modal-content,
  .strategy-modal-content {
    padding: 12px;
    max-height: 95vh;
    margin: 4px;
    border-radius: 8px;
  }

  .chart-container {
    height: 200px;
  }

  .contribution-chart-wrap {
    height: 200px;
  }

  .compare-chart-wrap {
    height: 180px;
  }

  /* 贡献度面板小屏优化 */
  .contribution-panel {
    padding: 12px;
  }

  .contribution-item {
    padding: 8px;
  }

  .contribution-name {
    font-size: 11px;
  }

  .contribution-amount-value {
    font-size: 11px;
  }

  .contribution-bar {
    height: 4px;
  }
}

/* 超小屏适配 (max-width: 360px) */
@media (max-width: 360px) {
  body {
    padding: 4px;
  }

  .card {
    padding: 10px;
  }

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

  .btn {
    font-size: 11px;
    padding: 6px 8px;
  }

  table {
    min-width: 800px;
  }
}

/* ── 触摸优化 ── */
@media (hover: none) and (pointer: coarse) {
  /* 增大点击区域 */
  .btn,
  .action-btn,
  .period-radio label,
  .contribution-tab {
    min-height: 44px;
    min-width: 44px;
  }

  /* 移除hover效果 */
  .fund-card:hover,
  .contribution-item:hover {
    transform: none;
    background: inherit;
  }

  /* 添加active反馈 */
  .btn:active,
  .action-btn:active {
    transform: scale(0.95);
  }
}

/* ── 横屏优化 ── */
@media (max-width: 896px) and (orientation: landscape) {
  .modal-content,
  .compare-modal-content,
  .strategy-modal-content {
    max-height: 95vh;
  }

  .chart-container {
    height: 180px;
  }
}

/* ── 安全区域适配 (iPhone X+) ── */
@supports (padding: max(0px)) {
  body {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .compare-bar {
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}
