/**
 * Sun Team - 响应式优化样式
 * Responsive Optimizations
 * 
 * 目标：全设备适配 (Mobile + Tablet + Desktop)
 * 更新日期: 2026-03-12
 */

/* ========================================
   1. 基础响应式设置
   ======================================== */

/* 防止水平滚动 */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* 平滑滚动 */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

/* 触摸优化 */
* {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* 图片自适应 */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ========================================
   2. 平板适配 (769px - 1024px)
   ======================================== */

@media (min-width: 769px) and (max-width: 1024px) {
  /* 容器调整 */
  .header-inner,
  main,
  .pricing-container,
  .pricing-cards,
  .features {
    max-width: 100%;
    padding-left: 20px;
    padding-right: 20px;
  }
  
  /* Hero区域 */
  .hero {
    padding: 60px 20px 80px;
  }
  
  .hero h1 {
    font-size: 2.5rem;
  }
  
  /* 网格布局调整 */
  .features {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }
  
  .pricing-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .pricing-card-mini.featured {
    transform: scale(1);
  }
  
  /* Agent网格 */
  .agents-grid {
    gap: 12px;
  }
  
  .agent-chip {
    padding: 10px 16px;
    font-size: 13px;
  }
  
  /* Stats bar */
  .stats-bar {
    gap: 40px;
    padding: 32px;
  }
  
  .stat-value {
    font-size: 2.2rem;
  }
  
  /* Live feed grid */
  .agents-live-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Reviews */
  .reviews-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Quick entry */
  .quick-entry-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Case studies */
  .case-studies .card-col-2 {
    grid-template-columns: 1fr;
  }
  
  /* Footer grid */
  footer > div:first-child {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ========================================
   3. 移动端适配 (<= 768px)
   ======================================== */

@media (max-width: 768px) {
  /* 强制所有网格布局在移动端变为单列 - 最高优先级 */
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns: repeat(2"],
  [style*="display: grid"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    grid-template-columns: none !important;
  }
  
  /* 特定组件覆盖 */
  section > div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  /* Quick Entry Grid 移动端优化 - 2列 */
  section:has(.nav-card) > div[style*="grid-template-columns: repeat(4"] {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  /* Pricing Cards 移动端单列 */
  .pricing-cards,
  section:has(.pricing-card-mini) > div {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    max-width: 400px !important;
    margin: 0 auto !important;
  }
  
  /* Features section 强制单列 */
  section.features,
  .features {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  /* Reviews section 强制单列 */
  .reviews-grid,
  section:has(.review-card) > div {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  /* Services & Products 强制单列 */
  section:has(> div > div > h3) > div[style*="grid-template-columns: repeat(3"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  /* 字体缩放 */
  :root {
    font-size: 14px;
  }
  
  h1 { font-size: 1.75rem !important; line-height: 1.2; }
  h2 { font-size: 1.5rem !important; }
  h3 { font-size: 1.25rem !important; }
  
  /* 容器内边距 */
  .header-inner {
    padding: 0 16px;
    height: 56px;
  }
  
  main {
    padding: 60px 16px 100px !important;
    max-width: 100% !important;
  }
  
  /* Hero区域优化 */
  .hero {
    padding: 40px 16px 60px !important;
  }
  
  .hero h1 {
    font-size: 1.85rem !important;
    line-height: 1.2;
  }
  
  .hero p {
    font-size: 1rem !important;
    padding: 0 8px;
  }
  
  /* CTA按钮 */
  .cta-buttons {
    flex-direction: column !important;
    gap: 12px !important;
    padding: 0 8px !important;
  }
  
  .cta-buttons .btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 14px 20px !important;
    font-size: 15px;
  }
  
  /* 网格布局统一处理 */
  .grid,
  .grid-2,
  .grid-3,
  .grid-4,
  .grid-6,
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns: repeat(2"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  /* Feature cards */
  .features {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    margin-top: 40px !important;
  }
  
  .feature-card {
    padding: 20px !important;
  }
  
  .feature-card h3 {
    font-size: 1.1rem !important;
  }
  
  .feature-card p {
    font-size: 0.9rem !important;
  }
  
  /* Agent cards */
  .agents-grid {
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;
  }
  
  .agent-chip {
    width: 100% !important;
    max-width: 280px !important;
    justify-content: center !important;
    padding: 10px 14px !important;
    font-size: 12px !important;
  }
  
  .agent-avatar {
    width: 24px !important;
    height: 24px !important;
    font-size: 12px !important;
  }
  
  /* Agent status cards */
  .agent-status-card {
    min-width: 80px !important;
    padding: 12px !important;
  }
  
  /* Stats bar */
  .stats-bar {
    flex-direction: column !important;
    gap: 20px !important;
    padding: 24px !important;
  }
  
  .stat-value {
    font-size: 1.8rem !important;
  }
  
  /* Live feed */
  .live-feed {
    margin: 40px -16px !important;
    padding: 20px 16px !important;
    border-radius: 0 !important;
  }
  
  .agents-live-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .agent-live-card {
    flex-direction: row !important;
    text-align: left !important;
    align-items: center !important;
  }
  
  /* Model providers */
  .model-providers {
    margin: 24px -16px !important;
    padding: 20px 16px !important;
    border-radius: 0 !important;
  }
  
  .model-providers-grid {
    flex-direction: column !important;
    gap: 10px !important;
  }
  
  .model-provider-card {
    flex-direction: row !important;
    text-align: left !important;
    gap: 12px !important;
    padding: 12px 16px !important;
  }
  
  /* Demand radar */
  .demand-radar {
    padding: 20px 16px !important;
  }
  
  .demand-radar-pipeline {
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .pipeline-stage {
    width: 100% !important;
  }
  
  /* Reviews */
  .reviews-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  .review-card {
    padding: 16px !important;
  }
  
  /* Services & Products */
  .services-grid,
  .products-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  /* Pricing cards */
  .pricing-cards {
    grid-template-columns: 1fr !important;
    max-width: 400px !important;
    margin: 0 auto !important;
  }
  
  .pricing-card-mini {
    padding: 20px !important;
  }
  
  /* Case studies */
  .case-card {
    padding: 16px !important;
  }
  
  .case-card .card-col-2 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  
  /* Quick entry links */
  .quick-entry-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .nav-card {
    padding: 16px 8px !important;
  }
  
  .nav-card span:first-child {
    font-size: 24px !important;
  }
  
  /* Subscribe section */
  .subscribe-section form {
    flex-direction: column !important;
    width: 100% !important;
  }
  
  .subscribe-section input,
  .subscribe-section button {
    width: 100% !important;
  }
  
  /* Contact section */
  .contact form {
    flex-direction: column !important;
    width: 100% !important;
  }
  
  /* Footer */
  footer {
    padding: 32px 16px 100px !important;
  }
  
  footer > div:first-child {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
    text-align: center !important;
  }
  
  footer ul {
    justify-content: center !important;
  }
  
  /* Bottom nav - 修复宽度溢出问题 */
  .bottom-nav {
    padding: 10px 8px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  
  .bottom-nav > div {
    max-width: 100% !important;
    padding: 0 8px !important;
    gap: 4px !important;
  }
  
  .bottom-nav a {
    font-size: 11px !important;
    padding: 6px 8px !important;
    white-space: nowrap !important;
  }
  
  /* FAQ section */
  details {
    margin-bottom: 8px !important;
  }
  
  summary {
    padding: 12px 16px !important;
    font-size: 14px !important;
  }
  
  /* Free tools grid */
  .free-tools > div {
    grid-template-columns: 1fr !important;
  }
}

/* ========================================
   4. 小屏手机适配 (<= 480px)
   ======================================== */

@media (max-width: 480px) {
  :root {
    font-size: 13px;
  }
  
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  
  .hero h1 {
    font-size: 1.6rem !important;
  }
  
  /* Stats 2列 */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Quick entry 2列 */
  .quick-entry-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  .nav-card {
    padding: 12px 8px !important;
  }
  
  .nav-card span:first-child {
    font-size: 20px !important;
  }
  
  .nav-card span:nth-child(2) {
    font-size: 12px !important;
  }
  
  /* Agent cards 更紧凑 */
  .agent-chip {
    padding: 8px 12px !important;
    font-size: 11px !important;
  }
  
  /* Live feed 更紧凑 */
  .agent-live-card {
    padding: 12px !important;
  }
  
  .agent-live-avatar {
    width: 36px !important;
    height: 36px !important;
    font-size: 16px !important;
  }
  
  /* Pricing */
  .pricing-amount {
    font-size: 2rem !important;
  }
  
  /* Buttons */
  .btn {
    padding: 12px 16px !important;
    font-size: 14px !important;
  }
}

/* ========================================
   5. 超小屏适配 (<= 375px)
   ======================================== */

@media (max-width: 375px) {
  .hero h1 {
    font-size: 1.4rem !important;
  }
  
  /* Agent名字隐藏 */
  .agent-chip span:last-child {
    display: none !important;
  }
  
  /* Bottom nav 更紧凑 */
  .bottom-nav a {
    font-size: 10px !important;
    padding: 4px 8px !important;
  }
  
  /* Stats 单列 */
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ========================================
   6. 横屏模式优化
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
  .hero {
    padding: 24px 0 40px !important;
  }
  
  .hero h1 {
    font-size: 1.75rem !important;
  }
  
  /* Nav 更窄 */
  .nav {
    width: 50% !important;
    max-width: 200px !important;
  }
  
  /* Features 2列 */
  .features {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ========================================
   7. 触摸设备优化
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  /* 增大触摸目标 */
  .btn,
  .nav a,
  .nav button,
  .feature-card,
  .agent-card,
  .pricing-card,
  .faq-item,
  .task-filter,
  .stage-btn,
  .nav-card,
  .card-block {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* 表单输入 */
  input,
  textarea,
  select {
    min-height: 44px;
    font-size: 16px !important; /* 防止iOS缩放 */
  }
  
  /* 点击反馈 */
  .btn:active,
  .card:active,
  .agent-card:active,
  .pricing-card:active,
  .nav-card:active,
  .card-block:active {
    transform: scale(0.97);
  }
  
  /* 禁用hover效果 */
  .card:hover,
  .feature-card:hover,
  .pricing-card:hover,
  .agent-card:hover,
  .nav-card:hover,
  .card-block:hover {
    transform: none;
  }
}

/* ========================================
   8. 表格响应式
   ======================================== */

@media (max-width: 768px) {
  .comparison-table,
  .ability-table,
  .relationship-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  
  .comparison-table th,
  .comparison-table td,
  .ability-table th,
  .ability-table td {
    padding: 12px 8px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }
}

/* ========================================
   9. 模态框/弹窗优化
   ======================================== */

@media (max-width: 768px) {
  .modal-content {
    margin: 16px !important;
    padding: 24px 16px !important;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .role-card-content {
    max-width: 90% !important;
    padding: 20px !important;
  }
}

/* ========================================
   10. Safe Area 支持 (iPhone X+)
   ======================================== */

@supports (padding: max(0px)) {
  .header {
    padding-top: max(0px, env(safe-area-inset-top));
  }
  
  .mobile-nav,
  .bottom-nav {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  
  main {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* ========================================
   11. 减少动画偏好支持
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================
   12. 打印样式
   ======================================== */

@media print {
  .header,
  .mobile-nav,
  .bottom-nav,
  .nav-toggle,
  .menu-toggle {
    display: none !important;
  }
  
  main {
    padding: 20px !important;
  }
}

/* ========================================
   13. 特定组件修复
   ======================================== */

/* Pipeline bar 移动端 */
@media (max-width: 768px) {
  .pipeline-bar {
    height: 8px !important;
  }
  
  .demand-radar-progress {
    margin: 16px 0 !important;
  }
}

/* Hero agents grid 移动端 */
@media (max-width: 768px) {
  #hero-agents-grid {
    gap: 6px !important;
  }
  
  #hero-agents-grid .agent-chip {
    padding: 6px 10px !important;
    font-size: 11px !important;
  }
}

/* Subscribe form 移动端 */
@media (max-width: 768px) {
  #subscribe-form {
    flex-direction: column !important;
    gap: 12px !important;
  }
  
  #subscribe-email {
    width: 100% !important;
  }
}

/* Quick subscribe 移动端 */
@media (max-width: 768px) {
  form[onsubmit="handleQuickSubscribe(event)"] {
    flex-direction: column !important;
    gap: 8px !important;
  }
  
  form[onsubmit="handleQuickSubscribe(event)"] input,
  form[onsubmit="handleQuickSubscribe(event)"] button {
    width: 100% !important;
  }
}

/* Case studies 移动端 */
@media (max-width: 768px) {
  .case-studies {
    gap: 16px !important;
  }
  
  .case-card .flex-center-gap12 {
    flex-direction: column !important;
    text-align: center !important;
    gap: 8px !important;
  }
}

/* Footer bottom nav 间距修复 */
footer > div:last-of-type {
  margin-bottom: 80px;
}

/* 防止底部导航遮挡内容 */
body {
  padding-bottom: 80px;
}

/* ========================================
   14. 滚动条美化
   ======================================== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color);
}

/* 移动端隐藏滚动条但保持功能 */
@media (max-width: 768px) {
  ::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
}
