/**
 * Mobile Responsive Styles
 * Comprehensive mobile optimization for Orbvop
 */

/* ========================================
   Mobile Breakpoints
   - sm: 640px
   - md: 768px
   - lg: 1024px
   - xl: 1280px
   ======================================== */

/* ========================================
   Base Mobile Styles (< 768px)
   ======================================== */

@media (max-width: 767px) {
  html {
    /* 取消部分浏览器双击缩放延迟；子元素可覆盖（如横向滚动区） */
    touch-action: manipulation;
  }

  /* 主内容叠在氛围层之上，避免部分 WebKit 下 mix-blend 导致正文不可见 */
  main.relative {
    isolation: isolate;
  }

  /* 手机端：底层背景饱和度与不透明度降低，减轻视觉疲劳 */
  body[data-view="landing"] .app-ambient-base,
  body.app-theme-light[data-view="landing"] .app-ambient-base {
    opacity: 0.75;
  }

  .app-ambient-canvas {
    opacity: 0.6;
    filter: saturate(0.75);
  }

  .app-ambient-orbs .ambient-orb,
  .app-ambient-fog,
  .app-ambient-mesh,
  .app-ambient-rays,
  .app-ambient-stars {
    opacity: 0.6;
  }

  /* 防止背景/内容向右滑动溢出 */
  body,
  #app,
  main.relative,
  .landing-page {
    overflow-x: hidden;
  }

  .landing-page {
    max-width: 100vw;
  }

  /* Reset section padding */
  .lp-section {
    padding: 64px 16px;
  }
  
  .lp-section::before {
    top: calc(-1 * var(--app-header-offset));
    height: 80px;
  }
  
  .lp-container {
    padding: 0 4px;
  }
  
  /* Header mobile：顶栏可折行，保留面包屑（勿 display:none），避免主区被固定栏遮挡 */
  .app-header {
    padding: 0;
    height: auto;
    min-height: 52px;
    overflow-x: clip;
    overflow-y: visible;
  }

  /*
   * 上行：Logo + 右侧控件；下行：主导航横向滑动（含 Home / Drafts / Upload…）
   * 初始占位；挂载后由 syncAppHeaderOffset.js 按真实高度覆写
   */
  :root {
    --app-header-offset: max(96px, calc(env(safe-area-inset-top, 0px) + 84px));
  }

  html {
    scroll-padding-top: calc(var(--app-header-offset, 96px) + 10px);
  }

  #app {
    padding-top: var(--app-header-offset, 96px);
    scroll-padding-top: calc(var(--app-header-offset, 96px) + 10px);
  }

  .header-inner {
    gap: 8px 10px;
    min-width: 0;
    padding: 10px 12px 10px;
    flex-wrap: wrap;
    align-items: flex-start;
    row-gap: 8px;
    min-height: 0;
  }

  .brand {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 108px);
    gap: 8px;
  }

  .header-right {
    order: 2;
    flex: 0 0 auto;
    margin-left: auto;
    gap: 6px;
    min-width: 0;
  }

  .nav-cluster {
    order: 10;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: visible;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  /* 手机端已有 Home/Drafts Tab，旁路草稿按钮与副标题重复占高 */
  .nav-cross-link {
    display: none !important;
  }

  .header-social {
    display: none;
  }

  .nav-cluster-main {
    min-width: min-content;
  }

  .nav-breadcrumb {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    min-width: min-content;
  }

  .nav-breadcrumb .nav-arrow {
    display: none;
  }

  /* 落地页 / 开始页：Tab 已表达线路，面包屑再占宽易挤占首屏 */
  body[data-view="landing"] .nav-breadcrumb .nav-item,
  body[data-view="upload-flow"] .nav-breadcrumb .nav-item {
    display: none;
  }

  .nav-lane-tab,
  .nav-item {
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-arrow {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
  }

  .nav-upload-hint {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-cross-btn {
    max-width: min(220px, 88vw);
    padding: 8px 12px;
  }

  .nav-cross-sub {
    display: none;
  }

  .header-right > * {
    transform: none;
  }
  
  .logo-wrapper {
    width: 32px;
    height: 32px;
  }
  
  .brand-name {
    font-size: 16px;
  }
  
  .brand-tagline {
    display: none;
  }
  
  .header-right .lang-trigger,
  .header-right .theme-toggle-btn {
    padding: 6px;
    border-radius: 8px;
  }
  
  .status-badge {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  .status-gpu {
    display: none;
  }
  
  /* Hero section mobile */
  .hero-section {
    padding: 24px 16px 48px;
    min-height: auto;
  }

  .hero-full {
    padding-top: 12px;
    padding-bottom: 48px;
    min-height: auto;
    max-height: none;
  }

  .landing-page .lp-product-chrome__demo-badge {
    font-size: 9px;
    padding: 2px 6px;
  }

  .hero-video-play {
    width: 72px;
    height: 72px;
  }

  .hero-video-play svg {
    width: 30px;
    height: 30px;
  }
  
  .hero-badge {
    padding: 6px 12px;
    font-size: 11px;
    margin-bottom: 16px;
  }
  
  .hero-title {
    font-size: 28px;
    line-height: 1.2;
    margin-bottom: 12px;
  }
  
  .hero-subtitle {
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 24px;
  }
  
  .hero-cta-group {
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }
  
  .hero-cta-group .grad-btn,
  .hero-cta-group .ghost-btn {
    width: 100%;
    justify-content: center;
    padding: 14px 24px;
  }
  
  /* Feature cards mobile */
  .features-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .feature-card {
    padding: 20px;
  }
  
  .feature-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
  }
  
  .feature-card h3 {
    font-size: 16px;
    margin-bottom: 8px;
  }
  
  .feature-card p {
    font-size: 13px;
  }
  
  /* Demo section mobile */
  .demo-container {
    padding: 0 8px;
  }
  
  .demo-header h2 {
    font-size: 24px;
  }
  
  .demo-header p {
    font-size: 14px;
  }
  
  /* Upload zone mobile */
  .upload-zone {
    padding: 32px 16px;
    min-height: 180px;
  }
  
  .upload-zone-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
  }
  
  .upload-zone-text {
    font-size: 14px;
  }
  
  .upload-zone-hint {
    font-size: 12px;
  }
  
  /* Compare section mobile */
  .compare-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  
  .compare-card {
    padding: 20px;
  }
  
  /* Stats section mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  
  .stat-item {
    padding: 16px;
  }
  
  .stat-number {
    font-size: 28px;
  }
  
  .stat-label {
    font-size: 12px;
  }
  
  /* Growth calculator mobile */
  .growth-calculator {
    padding: 20px;
    margin: 0 8px;
  }
  
  .growth-header h3 {
    font-size: 18px;
  }
  
  .growth-form {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .growth-input,
  .growth-select {
    padding: 12px;
    font-size: 16px; /* Prevents iOS zoom */
  }
  
  .growth-result {
    padding: 16px;
  }
  
  .growth-result-value {
    font-size: 28px;
  }
  
  /* CTA section mobile */
  .cta-container {
    padding: 48px 16px;
  }
  
  .cta-container h2 {
    font-size: 24px;
  }
  
  .cta-container p {
    font-size: 14px;
  }
  
  /* Footer mobile */
  .landing-footer {
    padding: 32px 16px;
  }
  
  .footer-links {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  /* 主应用：底部安全区（刘海屏 Home 条）、避免底部按钮被遮挡 */
  #app {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  /* 上传页玻璃面板：收窄左右内边距，减少小屏横向溢出 */
  body[data-view="upload-flow"] .upload-flow-atmo.upload-flow-atmo--surface {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  body[data-view="upload-flow"] .upload-flow-lang-panel,
  body[data-view="upload-flow"] .upload-flow-page-bg {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* 处理页头部：百分比与文件名折行 */
  .processing-header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .processing-header > .text-right {
    flex: 1 1 100%;
    width: 100%;
    text-align: left;
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 0.5rem;
  }

  .processing-header > .text-right .text-2xl {
    font-size: 1.35rem;
  }

  /* 草稿表：横向滑动区跟手 */
  .drafts-page .overflow-x-auto {
    overscroll-behavior-x: contain;
    touch-action: pan-x;
  }
  
  /* Editor mobile */
  .editor-shell {
    flex-direction: column;
    height: auto;
    min-height: min(100dvh, 100vh);
    max-width: 100% !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  
  .editor-main {
    flex-direction: column;
  }
  
  .editor-panel {
    width: 100% !important;
    max-width: 100%;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .timeline-container {
    height: auto;
    min-height: 200px;
  }

  /* 编辑页顶栏标签过多时横向滑动，避免挤出视口 */
  body[data-view="editor"] .editor-tabs-shell {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap !important;
    overscroll-behavior-x: contain;
    max-width: 100%;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  body[data-view="editor"] .editor-tabs-shell .tab-pill {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  body[data-view="editor"] .editor-toolbar > .flex.flex-wrap {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.5rem;
    padding-bottom: 2px;
  }

  /* 处理页主卡片：减轻左右挤压 */
  body[data-view="processing"] .processing-atmo .rounded-2xl.p-6 {
    padding: 1rem !important;
  }

  body[data-view="processing"] .processing-atmo {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* iOS：认证 / 上传等表单输入字号 ≥16px，避免聚焦时整页被缩放 */
  .auth-page-wrap input[type="text"],
  .auth-page-wrap input[type="email"],
  .auth-page-wrap input[type="password"],
  .auth-page-wrap input[type="search"],
  .upload-flow input[type="text"],
  .upload-flow input[type="search"],
  .upload-flow input[type="url"] {
    font-size: 16px;
  }

  /* AI Agent mobile */
  .ai-agent-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    max-height: 60vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(calc(100% - 48px));
    transition: transform 0.3s ease;
    z-index: 100;
  }
  
  .ai-agent-panel.expanded {
    transform: translateY(0);
  }
  
  .ai-agent-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    cursor: pointer;
  }
  
  /* Modal mobile */
  .modal-box {
    width: 95%;
    max-width: 95%;
    margin: 16px auto;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .modal-header {
    padding: 16px;
  }
  
  .modal-body {
    padding: 16px;
  }
  
  /* Toast mobile */
  .toast-container {
    left: 8px;
    right: 8px;
    bottom: 8px;
  }
  
  .toast {
    padding: 12px 16px;
    font-size: 13px;
  }
}

/* ========================================
   Small Mobile (< 480px)
   ======================================== */

@media (max-width: 479px) {
  .header-free-beta-pill {
    display: none;
  }

  .hero-title {
    font-size: 24px;
  }
  
  .hero-subtitle {
    font-size: 14px;
  }
  
  .landing-page {
    --lp-section-title-size: 22px;
  }

  .lp-section-header h2,
  .orbvop-compare-header h2,
  .demo-header h2,
  .compare-container h2,
  .langs-container h2,
  .cta-container h2 {
    font-size: var(--lp-section-title-size, 22px);
  }
  
  .lp-section-header p,
  .demo-header p,
  .compare-container > p,
  .langs-subtitle,
  .cta-container p {
    font-size: 13px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .stat-number {
    font-size: 32px;
  }
  
  /* Theme toggle compact */
  .theme-toggle-btn {
    padding: 6px 8px;
  }
  
  .theme-toggle-text {
    display: none;
  }
  
  .theme-selector {
    display: none;
  }
  
  /* Language switcher compact */
  .lang-switcher .lang-code {
    display: none;
  }
  
  .lang-trigger {
    padding: 6px 8px;
  }
}

/* ========================================
   Tablet Styles (768px - 1024px)
   ======================================== */

@media (min-width: 768px) and (max-width: 1023px) {
  .lp-section {
    padding: 80px 24px;
  }
  
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .compare-grid {
    grid-template-columns: 1fr;
    max-width: 600px;
    margin: 0 auto;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    max-width: 600px;
    margin: 0 auto;
  }
  
  .hero-title {
    font-size: 40px;
  }
}

/* ========================================
   Touch Device Optimizations
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  button,
  .nav-item,
  .feature-card,
  .upload-zone {
    min-height: 44px;
  }
  
  /* Remove hover effects on touch */
  .feature-card:hover,
  .glass-card:hover {
    transform: none;
  }
  
  /* Active state instead of hover */
  .feature-card:active,
  .glass-card:active {
    transform: scale(0.98);
  }
  
  /* Upload zone touch feedback */
  .upload-zone:active {
    background: rgba(99, 102, 241, 0.1);
  }
  
  /* Button touch feedback */
  .grad-btn:active {
    transform: scale(0.98);
  }
  
  .ghost-btn:active {
    background: rgba(99, 102, 241, 0.1);
  }
}

/* ========================================
   Safe Area Insets (iPhone X+)
   ======================================== */

@supports (padding: max(0px)) {
  .app-header {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  
  .landing-footer {
    padding-bottom: max(32px, env(safe-area-inset-bottom));
  }
  
  .ai-agent-wrapper {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
  }
  
  .ai-agent-panel {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  
  .toast-container {
    bottom: max(8px, env(safe-area-inset-bottom));
  }
  
  .modal-box {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ========================================
   Landscape Mobile
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .hero-section {
    padding: 32px 16px;
    min-height: auto;
  }
  
  .hero-title {
    font-size: 24px;
    margin-bottom: 8px;
  }
  
  .hero-subtitle {
    font-size: 13px;
    margin-bottom: 16px;
  }
  
  .hero-cta-group {
    flex-direction: row;
  }
  
  .hero-cta-group .grad-btn,
  .hero-cta-group .ghost-btn {
    width: auto;
    padding: 10px 20px;
  }
  
  .lp-section {
    padding: 48px 16px;
  }
}

/* ========================================
   High DPI Screens
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Sharper borders */
  .glass-card,
  .feature-card,
  .upload-zone,
  .modal-box {
    border-width: 0.5px;
  }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
  .app-header,
  .ai-agent-panel,
  .toast-container,
  .theme-toggle,
  .lang-switcher {
    display: none !important;
  }
  
  .landing-page {
    background: white;
    color: black;
  }
  
  .glass-card,
  .feature-card {
    background: white;
    border: 1px solid #ccc;
    box-shadow: none;
  }
}

/* ========================================
   Accessibility - Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .landing-page::after {
    animation: none;
  }
  
  .sr {
    opacity: 1;
    transform: none;
  }
}
