/* ============================================
   Mobile APP-like Experience
   统一移动端样式 - 所有页面共用
   ============================================ */

/* ============================================
   1. 基础移动端优化
   ============================================ */
@media (max-width: 768px) {
  /* 安全的全屏高度 */
  .full-height {
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* 触摸友好的可点击元素 */
  button,
  .btn,
  a.btn,
  input[type="submit"],
  input[type="button"],
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    font-size: 15px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* 表单输入框优化 */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important; /* 防止 iOS 缩放 */
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 10px;
    touch-action: manipulation;
  }

  /* 防止双击缩放 */
  * {
    touch-action: manipulation;
  }

  /* 平滑滚动 */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  /* 禁止文本选择（APP感觉） */
  .no-select {
    -webkit-user-select: none;
    user-select: none;
  }

  /* 隐藏滚动条（更像APP） */
  .hide-scrollbar {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .hide-scrollbar::-webkit-scrollbar {
    display: none;
  }
}

/* ============================================
   2. 页面容器统一样式
   ============================================ */
@media (max-width: 768px) {
  .page-container,
  .account-container,
  .checkout-container {
    padding: 80px 16px 32px;
    max-width: 100%;
  }

  .page-header {
    margin-bottom: 24px;
    text-align: center;
  }

  .page-header h1 {
    font-size: 24px;
    line-height: 1.3;
    margin-bottom: 8px;
  }

  .page-header p {
    font-size: 14px;
    line-height: 1.5;
  }
}

/* ============================================
   3. 卡片网格 - APP风格
   ============================================ */
@media (max-width: 768px) {
  /* 家族圈、圈子等卡片网格 */
  .family-grid,
  .circle-grid,
  .card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .family-card,
  .circle-card {
    padding: 20px;
    border-radius: 16px;
  }

  .family-card.create,
  .circle-card.create {
    min-height: 120px;
    padding: 24px;
  }

  .family-card.create svg,
  .circle-card.create svg {
    width: 40px;
    height: 40px;
  }

  .family-avatar,
  .circle-avatar {
    width: 60px;
    height: 60px;
    font-size: 24px;
  }

  .family-name,
  .circle-name {
    font-size: 18px;
  }

  .family-desc,
  .circle-desc {
    font-size: 13px;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .family-stats,
  .circle-stats {
    gap: 16px;
    padding: 12px 0;
  }

  .family-stat-num,
  .circle-stat-num {
    font-size: 18px;
  }

  .family-stat-label,
  .circle-stat-label {
    font-size: 11px;
  }

  .family-actions,
  .circle-actions {
    gap: 8px;
  }

  .family-actions .btn,
  .circle-actions .btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 13px;
  }
}

/* ============================================
   4. 账户页面优化
   ============================================ */
@media (max-width: 768px) {
  .account-card {
    padding: 20px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
  }

  .account-card-title {
    font-size: 12px;
    margin-bottom: 16px;
  }

  .profile-row {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .profile-avatar {
    width: 72px;
    height: 72px;
    font-size: 28px;
  }

  .profile-info h3 {
    font-size: 18px;
  }

  .profile-info p {
    font-size: 13px;
  }

  .info-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .info-item {
    padding: 12px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .info-label {
    font-size: 13px;
  }

  .info-value {
    font-size: 14px;
    text-align: right;
  }

  .sub-status {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .sub-plan {
    font-size: 18px;
  }

  .sub-detail {
    font-size: 13px;
  }
}

/* ============================================
   5. 写作页面优化
   ============================================ */
@media (max-width: 768px) {
  .page-nav {
    padding: 10px 16px;
  }

  .page-nav-title {
    display: none;
  }

  .page-nav-badge {
    font-size: 10px;
    padding: 3px 8px;
  }

  .letter {
    padding: 80px 16px 100px;
  }

  .letter-header {
    margin-bottom: 32px;
  }

  .letter-header h1 {
    font-size: 22px;
    letter-spacing: 1px;
  }

  .letter-header p {
    font-size: 13px;
  }

  .letter-body {
    padding: 32px 20px;
    border-radius: 4px 10px 10px 4px;
  }

  .letter-body::after {
    left: 20px;
  }

  .letter-bookmark {
    right: 24px;
    width: 16px;
    height: 40px;
  }

  .form-section h2 {
    font-size: 16px;
  }

  .form-section p {
    font-size: 13px;
  }

  .form-section label {
    font-size: 14px;
  }

  .form-section textarea {
    font-size: 15px;
    min-height: 120px;
  }

  /* 底部操作栏 */
  .letter-footer,
  .form-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0,0,0,0.1);
    z-index: 100;
  }

  .letter-footer .btn,
  .form-footer .btn {
    width: 100%;
  }
}

/* ============================================
   6. 弹窗/模态框优化
   ============================================ */
@media (max-width: 768px) {
  [id$="-modal"] > div,
  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 20px 20px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    margin: 0 !important;
    animation: slideUp 0.3s ease;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .modal-content h2 {
    font-size: 20px;
    margin-bottom: 20px;
  }

  .form-field {
    margin-bottom: 16px;
  }

  .form-field label {
    font-size: 14px;
    margin-bottom: 6px;
  }
}

/* ============================================
   7. 空状态优化
   ============================================ */
@media (max-width: 768px) {
  .empty-state {
    padding: 48px 24px;
    border-radius: 16px;
  }

  .empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
  }

  .empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
  }

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

/* ============================================
   8. 底部导航栏（APP风格可选）
   ============================================ */
@media (max-width: 768px) {
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(255,255,255,0.98);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0,0,0,0.08);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 1000;
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: var(--text-muted, #666);
    text-decoration: none;
    font-size: 10px;
    gap: 4px;
    transition: color 0.2s;
  }

  .bottom-nav-item svg {
    width: 24px;
    height: 24px;
  }

  .bottom-nav-item.active {
    color: var(--primary, #7a4f26);
  }

  /* 有底部导航时，页面需要额外底部间距 */
  body.has-bottom-nav {
    padding-bottom: 64px;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0));
  }
}

/* ============================================
   9. 结账/支付页面
   ============================================ */
@media (max-width: 768px) {
  .checkout-container {
    padding: 80px 16px 120px;
  }

  .checkout-summary {
    padding: 20px;
    border-radius: 14px;
    margin-bottom: 20px;
  }

  .checkout-item {
    padding: 12px 0;
  }

  .checkout-total {
    font-size: 20px;
    padding-top: 12px;
  }

  .payment-methods {
    gap: 12px;
  }

  .payment-method {
    padding: 16px;
    border-radius: 12px;
  }

  .payment-method img {
    height: 24px;
  }

  /* 固定底部支付按钮 */
  .checkout-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
    background: #fff;
    border-top: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  }

  .checkout-footer .btn {
    width: 100%;
    font-size: 16px;
    padding: 16px;
  }
}

/* ============================================
   10. 列表和详情页
   ============================================ */
@media (max-width: 768px) {
  .detail-header {
    padding: 24px 16px;
  }

  .detail-avatar {
    width: 80px;
    height: 80px;
  }

  .detail-title {
    font-size: 22px;
  }

  .detail-subtitle {
    font-size: 14px;
  }

  .detail-content {
    padding: 20px 16px;
  }

  .detail-section {
    margin-bottom: 24px;
  }

  .detail-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
  }

  .detail-section p {
    font-size: 14px;
    line-height: 1.7;
  }

  /* 列表项 */
  .list-item {
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
  }

  .list-item:active {
    background: rgba(0,0,0,0.02);
  }

  .list-item-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .list-item-content {
    flex: 1;
    min-width: 0;
  }

  .list-item-title {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 2px;
  }

  .list-item-desc {
    font-size: 13px;
    color: var(--text-muted, #666);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .list-item-arrow {
    color: var(--text-muted, #999);
  }
}

/* ============================================
   11. 图片和媒体
   ============================================ */
@media (max-width: 768px) {
  /* 图片网格 */
  .photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .photo-grid img {
    aspect-ratio: 1;
    object-fit: cover;
    width: 100%;
    border-radius: 4px;
  }

  /* 单张大图 */
  .photo-single {
    border-radius: 12px;
    overflow: hidden;
  }

  .photo-single img {
    width: 100%;
    height: auto;
  }

  /* 相册滑动 */
  .photo-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 8px;
    padding: 0 16px;
    scrollbar-width: none;
  }

  .photo-carousel::-webkit-scrollbar {
    display: none;
  }

  .photo-carousel img {
    flex: 0 0 85%;
    scroll-snap-align: center;
    border-radius: 12px;
    object-fit: cover;
    aspect-ratio: 4/3;
  }
}

/* ============================================
   12. 辅助工具类
   ============================================ */
@media (max-width: 768px) {
  /* 安全区域适配 */
  .safe-area-top {
    padding-top: env(safe-area-inset-top, 0);
  }

  .safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* 固定底部按钮容器 */
  .fixed-bottom-action {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
    background: #fff;
    border-top: 1px solid rgba(0,0,0,0.08);
    z-index: 100;
  }

  /* 页面需要底部间距 */
  .has-fixed-bottom {
    padding-bottom: 100px;
  }

  /* 触摸反馈 */
  .touch-feedback:active {
    opacity: 0.7;
    transform: scale(0.98);
  }

  /* 禁用hover效果（移动端） */
  .no-hover:hover {
    transform: none !important;
    box-shadow: inherit !important;
  }
}

/* ============================================
   13. 减少动画（尊重用户偏好）
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
