/* ==========================================================
 * GAMT 统一移动端适配样式
 * 所有页面引入此文件，确保手机端显示一致
 * ========================================================== */

/* ── 基础：rem 换算基准 ── */
html {
  /* 桌面默认：1rem = 16px */
  font-size: 16px;
}

/* 平板：字体略小 */
@media (max-width: 1024px) {
  html {
    font-size: 15px;
  }
}

/* 手机：字体放大到合适阅读 */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
  
  /* 小屏手机：再放大一点 */
  @media (max-width: 480px) {
    html {
      font-size: 13px;
    }
  }
}

/* ── 全局移动端优化 ── */
@media (max-width: 768px) {
  body {
    font-size: 1rem !important; /* 统一基础字号 */
    padding: 0.75rem !important;
    min-height: 100vh;
    overflow-x: hidden;
  }
  
  /* 防止水平滚动 */
  * {
    max-width: 100%;
    box-sizing: border-box;
  }
  
  /* 触摸优化：最小点击区域 44x44px */
  button, a, .nav-item, .strat-tab, .refresh-btn, .filter-btn, .rt-fbtn, .tab {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 0.5rem 0.875rem !important;
    font-size: 0.875rem !important;
    touch-action: manipulation; /* 防止双击缩放 */
  }
  
  /* 强制所有小字体放大 */
  .hero-meta, .stat, .s-label, .s-sub, .filter-label, .tab-count,
  [style*="font-size:10px"], [style*="font-size:11px"], [style*="font-size:12px"] {
    font-size: 0.8rem !important;
  }
}

/* ── 侧边栏：手机端完全隐藏，默认不显示 ── */
@media (max-width: 768px) {
  /* 强制隐藏侧边栏 */
  .sidebar {
    display: none !important;
    position: fixed;
    left: -100%;
    transition: left 0.3s ease;
    z-index: 999;
    width: 75vw !important; /* 最多占75%屏宽 */
    max-width: 280px !important;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
  }
  
  /* 点击汉堡菜单后才显示 */
  .sidebar.mobile-open {
    display: flex !important;
    left: 0;
  }
  
  /* 主内容区占满屏幕 */
  .main {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  /* 汉堡菜单按钮 */
  .mobile-menu-toggle {
    display: block !important;
    position: fixed;
    top: 8px;
    left: 12px;
    z-index: 1000;
    background: var(--accent, #ff8c00);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  }
  
  /* 遮罩层 */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 998;
  }
  
  .sidebar-overlay.active {
    display: block;
  }
}

/* 桌面端隐藏汉堡菜单 */
@media (min-width: 769px) {
  .mobile-menu-toggle {
    display: none !important;
  }
}

/* ── 头部：手机端调整 ── */
@media (max-width: 768px) {
  .header, .hero {
    padding: 0.75rem 3rem 0.75rem 3rem !important; /* 左侧留给汉堡菜单 */
    height: auto !important;
    min-height: 48px !important;
    flex-wrap: wrap;
  }
  
  .header .title, .hero-title, h1, h2 {
    font-size: 1.125rem !important;
  }
  
  .header .meta, .hero-meta {
    font-size: 0.8rem !important;
    flex-wrap: wrap;
    gap: 8px !important;
  }
  
  .refresh-btn, .hero button {
    font-size: 0.875rem !important;
    padding: 0.625rem 0.875rem !important;
    min-height: 44px !important;
  }
  
  /* Hero stats - 确保统计数字足够大 */
  .hero-stats .stat {
    font-size: 0.8rem !important;
  }
  
  .hero-stats .stat b {
    font-size: 1rem !important;
  }
}

/* ── 内容区：手机端间距优化 ── */
@media (max-width: 768px) {
  .content {
    padding: 12px !important;
  }
  
  .card {
    padding: 12px !important;
    margin-bottom: 12px !important;
    border-radius: 8px !important;
  }
  
  .card-title {
    font-size: 1rem !important;
    margin-bottom: 8px !important;
  }
  
  /* 耐心资本信号摘要栏：手机端优化 */
  #patientSignalBar, #patientExplain {
    font-size: 0.85rem !important;
    line-height: 1.8 !important;
    padding: 0.875rem !important;
  }
  
  /* 信号列表改为竖向堆叠 */
  #patientSignalBar br {
    display: block !important;
    content: "" !important;
    margin: 0.5rem 0 !important;
  }
}

/* ── 总览卡片：手机端单列 ── */
@media (max-width: 768px) {
  .overview-grid, .summary-cards, .hero-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  
  .ov-card, .s-card {
    padding: 0.875rem 1rem !important;
  }
  
  .ov-label, .s-label {
    font-size: 0.8rem !important;
  }
  
  .ov-value, .s-value {
    font-size: 1.5rem !important;
  }
  
  .ov-sub, .ov-tag, .s-sub {
    font-size: 0.8rem !important;
  }
}

/* ── 表格：手机端横向滚动 + 字体调整 ── */
@media (max-width: 768px) {
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px; /* 抵消card padding */
    padding: 0 12px;
  }
  
  .s-table, table {
    font-size: 0.8rem !important;
    min-width: 600px; /* 保持表格可读性 */
  }
  
  .s-table th, table th {
    font-size: 0.75rem !important;
    padding: 8px 6px !important;
    white-space: nowrap;
  }
  
  .s-table td, table td {
    font-size: 0.8rem !important;
    padding: 8px 6px !important;
  }
  
  /* 标签字体 */
  .tag, .tag-green, .tag-amber, .tag-slate {
    font-size: 0.7rem !important;
    padding: 2px 6px !important;
  }
}

/* ── 策略 Tab：手机端堆叠 ── */
@media (max-width: 768px) {
  .strat-tabs {
    flex-direction: column !important;
    gap: 8px !important;
  }
  
  .strat-tab {
    width: 100% !important;
    text-align: center;
    font-size: 0.9rem !important;
    padding: 10px 14px !important;
  }
}

/* ── 导航项：手机端字体调整 ── */
@media (max-width: 768px) {
  .nav-item {
    font-size: 0.9rem !important;
    padding: 10px 16px !important;
  }
  
  .nav-group-title {
    font-size: 1rem !important;
    padding: 12px 16px 6px !important;
  }
  
  .sidebar .logo {
    font-size: 1.1rem !important;
    padding: 14px 16px !important;
  }
}

/* ── 股票池特定优化 ── */
@media (max-width: 768px) {
  .ss-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  .ss-stat .ss-label {
    font-size: 0.75rem !important;
  }
  
  .ss-stat .ss-val {
    font-size: 1.3rem !important;
  }
  
  .ss-desc, .ss-extra-info {
    font-size: 0.85rem !important;
  }
  
  /* 耐心资本等多卡片布局：手机端改为单列 */
  #patientStateBoard,
  .patient-cards, .strategy-cards, [class*="card-row"], [class*="cards-grid"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  
  .state-card, .patient-cards > *, .strategy-cards > * {
    width: 100% !important;
    max-width: 100% !important;
  }
  
  /* 状态卡片内部文字优化 */
  .state-card .k {
    font-size: 0.9rem !important;
  }
  
  .state-card .v {
    font-size: 1.1rem !important;
  }
  
  .state-card .s, .state-card .algo {
    font-size: 0.75rem !important;
    line-height: 1.6 !important;
  }
}

/* ── iframe 模块：手机端高度调整 ── */
@media (max-width: 768px) {
  .embed-frame {
    min-height: 500px !important;
    border-radius: 8px !important;
  }
}

/* ── 筛选器：手机端堆叠 ── */
@media (max-width: 768px) {
  .rt-filters {
    flex-direction: column !important;
    gap: 10px !important;
  }
  
  .rt-flabel {
    font-size: 0.85rem !important;
  }
  
  .rt-fbtn {
    font-size: 0.85rem !important;
    padding: 8px 12px !important;
  }
  
  .rt-fcount {
    font-size: 0.8rem !important;
  }
}

/* ── 标识/徽章：手机端可读性 ── */
@media (max-width: 768px) {
  .sector-tag, .tb, .cb {
    font-size: 0.75rem !important;
    padding: 3px 8px !important;
  }
  
  .mono, .sb-val {
    font-size: 0.75rem !important;
  }
  
  .np-tag, .np-names {
    font-size: 0.75rem !important;
  }
  
  .badge, .new-badge {
    font-size: 0.7rem !important;
    padding: 2px 6px !important;
  }
}

/* ── 用户信息：手机端简化 ── */
@media (max-width: 768px) {
  .user-info {
    font-size: 0.7rem !important;
    padding: 10px 16px !important;
  }
}

/* ── 图表容器：手机端自适应 ── */
@media (max-width: 768px) {
  canvas, .chart-container {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* ── 日期标签和环境徽章 ── */
@media (max-width: 768px) {
  .date-tag {
    font-size: 0.75rem !important;
    padding: 4px 8px !important;
  }
  
  .env-badge {
    font-size: 0.75rem !important;
    padding: 4px 10px !important;
  }
}

/* ── 模块分组行 ── */
@media (max-width: 768px) {
  .module-group-row td {
    font-size: 0.95rem !important;
    padding: 8px 10px !important;
  }
  
  .module-sub-row td {
    font-size: 0.8rem !important;
    padding: 6px 10px 6px 16px !important;
  }
  
  .module-sub-list {
    font-size: 0.8rem !important;
  }
}

/* ── 横屏优化 ── */
@media (max-width: 768px) and (orientation: landscape) {
  .header {
    min-height: 40px !important;
  }
  
  .content {
    padding: 8px !important;
  }
  
  .card {
    padding: 10px !important;
  }
}

/* ── 高分辨率屏幕优化 ── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}
