/**
 * 移动端三栏布局适配
 * 极简版 - 只做Tab切换和对齐
 */

/* ===================================
   移动端适配样式（≤ 768px）
   =================================== */

@media (max-width: 768px) {
  
  /* 1. Tab 导航栏样式 */
  .mobile-tab-nav {
    display: flex;
    background: #ffffff;
    border-bottom: 2px solid #f0f0f0;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  }
  
  .mobile-tab-item {
    flex: 1;
    text-align: center;
    padding: 16px 10px;
    font-size: 15px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background: #fff;
    border: none;
    outline: none;
  }
  
  .mobile-tab-item:active {
    transform: scale(0.98);
  }
  
  .mobile-tab-item.active {
    color: #1890ff;
    font-weight: 600;
  }
  
  /* Tab 激活状态下划线 */
  .mobile-tab-item.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 3px;
    background: linear-gradient(90deg, #1890ff, #40a9ff);
    border-radius: 3px 3px 0 0;
  }
  
  /* 2. 确保main-context是relative定位，让子元素可以相对它定位 */
  .main-context {
    position: relative !important;
  }
  
  /* 3. 隐藏非激活的板块 */
  .main-context .left,
  .main-context .image,
  .main-context .right {
    display: none !important;
  }
  
  /* 4. 显示激活的板块 - 对齐main-context左上角 */
  .main-context .left.active,
  .main-context .image.active,
  .main-context .right.active {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }
  
  /* 4.1 预览区域和左侧表单区域允许滚动 */
  .main-context .left.active {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x pan-y !important;
    padding-bottom: 150px !important; /* 增加底部留白 */
  }
  
  /* 预览区域允许缩放和滚动 */
  .main-context .image.active {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pinch-zoom pan-x pan-y !important; /* 允许双指缩放 */
    padding-bottom: 150px !important;
  }
  
  /* 确保参数面板内的listMainContext也有足够的底部空间 */
  .main-context .left.active .listMainContext {
    padding-bottom: 80px !important;
    margin-bottom: 20px !important;
  }
  
  /* 4.2 移动端模板Tab：显示参数，隐藏编辑菜单，允许滚动 */
  .main-context .right.active {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    padding-bottom: 100px !important;
  }
  
  /* 隐藏编辑菜单（第二个子元素） */
  .main-context .right.active > *:first-child > *:nth-child(2) {
    display: none !important;
  }
  
  /* 参数部分占满宽度（第一个子元素） */
  .main-context .right.active > *:first-child > *:first-child {
    width: 100% !important;
  }
  
  /* 5. resizableDiv位置设置 - 保留原生功能 */
  .main-context .image.active #resizableDiv,
  .main-context .image.active .resizable-div {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    transform-origin: top left !important;
    touch-action: pinch-zoom pan-x pan-y !important;
    overflow: hidden !important; /* 裁掉内部 fixed 元素溢出到容器外 */
  }
  
  /* 确保图片内容也允许触摸交互 */
  .main-context .image.active #resizableDiv *,
  .main-context .image.active .resizable-div * {
    touch-action: inherit !important;
  }
  
  /* 6. 修复showImage第一个子元素高度被inline style限制的问题 */
  .main-context .image.active #showImage > div:first-child {
    height: auto !important;
    min-height: 100% !important;
    position: relative !important;
    z-index: 1 !important;
  }
  
  /* 7. 第二个子元素（底部导航栏）覆盖在第一个元素上面 */
  .main-context .image.active #showImage {
    position: relative !important;
  }
  
  .main-context .image.active #showImage > div:nth-child(2) {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9999 !important;
    pointer-events: auto !important;
  }
  
  /* 8. 隐藏桌面版底部工具栏（图片复位、固定滚动等按钮），但保留#showImage内的fixed元素 */
  .main-context .image.active div[style*="position: fixed"][style*="bottom: 0px"]:not(#showImage div[style*="position: fixed"]) {
    display: none !important;
  }
  
  /* 修复 #showImage 内 fixed 底部元素：完全还原，不受我们的CSS影响 */
  #showImage div[style*="position: fixed"][style*="bottom: 0px"] {
    all: revert !important;
    position: fixed !important;
    bottom: 0px !important;
    width: 100% !important;
    z-index: 99 !important;
  }
  
  #showImage div[style*="position: fixed"][style*="bottom: 0px"] img {
    all: revert !important;
    width: 100% !important;
    display: block !important;
  }
  
  /* 9. 浮动菜单球样式 */
  .mobile-floating-menu {
    position: fixed;
    right: 15px;
    bottom: 80px;
    z-index: 10000;
    display: none; /* 默认隐藏 */
  }
  
  /* 只在有main-context时显示（P图界面） */
  body:has(.main-context) .mobile-floating-menu {
    display: block;
  }
  
  /* 10. 缩放提示按钮 */
  .mobile-zoom-hint {
    position: fixed;
    left: 50%;
    top: 80px;
    transform: translateX(-50%);
    z-index: 9998;
    display: none;
    background: rgba(24, 144, 255, 0.95);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    animation: pulseHint 2s infinite;
  }
  
  /* 只在预览Tab激活且移动端时显示 */
  body:has(.main-context) .main-context .image.active ~ .mobile-zoom-hint {
    display: block;
  }
  
  @keyframes pulseHint {
    0%, 100% {
      transform: translateX(-50%) scale(1);
    }
    50% {
      transform: translateX(-50%) scale(1.05);
    }
  }
  
  .mobile-zoom-hint:active {
    transform: translateX(-50%) scale(0.95);
  }
  
  /* 隐藏状态 */
  .mobile-zoom-hint.hidden {
    display: none !important;
  }
  
  /* 11. 缩放滑块控制器 - 独立显示在菜单球左侧 */
  .mobile-zoom-slider-container {
    position: fixed;
    right: 75px; /* 在菜单球左侧 */
    bottom: 80px;
    z-index: 10000;
    display: none; /* 默认隐藏 */
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }
  
  /* 显示状态 */
  .mobile-zoom-slider-container.show {
    display: flex !important;
  }
  
  /* 查看图片按钮 */
  .mobile-view-image-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  
  .mobile-view-image-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  
  .mobile-zoom-slider {
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 160px;
  }
  
  .mobile-zoom-slider .zoom-label {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
  }
  
  .mobile-zoom-slider input[type="range"] {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, #667eea 0%, #667eea 25%, #e0e0e0 25%, #e0e0e0 100%);
    outline: none;
    -webkit-appearance: none;
  }
  
  .mobile-zoom-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
  
  .mobile-zoom-slider input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
  
  .mobile-zoom-slider .zoom-value {
    font-size: 11px;
    font-weight: 600;
    color: #667eea;
    min-width: 35px;
    text-align: right;
  }
  
  /* 12. 浮动菜单球样式继续 */
  .mobile-floating-menu .menu-ball {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.3s ease;
    touch-action: none;
  }
  
  .mobile-floating-menu .menu-ball:active {
    cursor: grabbing;
  }
  
  .mobile-floating-menu .menu-ball span {
    font-size: 20px;
  }
  
  .mobile-floating-menu .menu-panel {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: auto;
    min-width: 180px;
    max-width: 220px;
    max-height: 60vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    overflow: hidden;
  }
  
  .mobile-floating-menu .menu-content {
    height: 100%;
    overflow: hidden;
    padding: 8px;
  }
  
  /* 编辑菜单内部的滚动 */
  .mobile-floating-menu .menuMian {
    max-height: 60vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  /* ant-menu滚动和拖拽 */
  .mobile-floating-menu .ant-menu {
    max-height: 55vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    padding-bottom: 20px !important;
  }
  
  /* ant-menu滚动条样式 */
  .mobile-floating-menu .ant-menu::-webkit-scrollbar {
    width: 4px;
  }
  
  .mobile-floating-menu .ant-menu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
  }
  
  /* 图片预览弹窗样式 */
  .image-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
  }
  
  /* 图片加载动画 */
  .image-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
  }
  
  .loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  .loading-text {
    color: white;
    font-size: 16px;
    margin-top: 20px;
    font-weight: 500;
  }
  
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  
  .image-preview-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    position: relative;
  }
  
  .image-preview-modal .modal-title {
    color: white;
    font-size: 18px;
    font-weight: 600;
  }
  
  .image-preview-modal .modal-close {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease;
  }
  
  .image-preview-modal .modal-close:active {
    background: rgba(255, 255, 255, 0.3);
  }
  
  .image-preview-modal .modal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
  }
  
  .image-preview-modal .modal-tips {
    background: rgba(76, 175, 80, 0.15);
    border-left: 4px solid #4CAF50;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
  }
  
  .image-preview-modal .tip-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
  }
  
  .image-preview-modal .tip-item:last-child {
    margin-bottom: 0;
  }
  
  .image-preview-modal .tip-number {
    color: #4CAF50;
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
  }
  
  .image-preview-modal .tip-text {
    color: white;
    font-size: 16px;
    font-weight: 600;
  }
  
  .image-preview-modal .tip-desc {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    margin-left: 0;
    line-height: 1.6;
    margin-top: 5px;
  }
  
  .image-preview-modal .image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    min-height: 300px;
  }
  
  .image-preview-modal .image-container img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    -webkit-user-select: auto !important;
    user-select: auto !important;
    -webkit-touch-callout: default !important;
    pointer-events: auto !important;
  }
  
  .image-preview-modal .modal-actions {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    margin-top: 20px;
  }
  
  .image-preview-modal .share-button {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 25px;
    padding: 14px 20px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  
  .image-preview-modal .share-button:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
  }
  
  .image-preview-modal .share-icon {
    font-size: 20px;
  }
  
  .image-preview-modal .modal-close-bottom {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 15px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    margin: 15px;
    border-radius: 12px;
    transition: background 0.3s ease;
  }
  
  .image-preview-modal .modal-close-bottom:active {
    background: rgba(255, 255, 255, 0.25);
  }
  
  /* 调试提示消息样式 */
  .debug-message-toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    z-index: 99999;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 80%;
    text-align: center;
    white-space: nowrap;
  }
  
  .debug-message-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ===================================
   桌面端样式（> 768px）
   =================================== */

@media (min-width: 769px) {
  /* 隐藏移动端Tab导航 */
  .mobile-tab-nav {
    display: none !important;
  }
  
  /* 隐藏浮动菜单球 */
  .mobile-floating-menu {
    display: none !important;
  }
  
  /* 隐藏图片预览弹窗 */
  .image-preview-modal {
    display: none !important;
  }
  
  /* 确保桌面端三栏正常显示 */
  .main-context .left,
  .main-context .image,
  .main-context .right {
    display: block !important;
  }
}
