/**
 * 移动端优化样式
 * 专门针对手机和平板设备的优化
 */

/* 移动端下拉刷新禁用 - 温和设置 */
html, body {
    overscroll-behavior-y: none;
    -webkit-overscroll-behavior-y: none;
    /* 保持正常的触摸行为，不限制过度 */
}

/* 移动端专用滚动容器 */
@media (max-width: 1023px) {
    /* 确保移动端主体不产生下拉刷新 */
    html {
        height: 100%;
        position: relative;
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
    }
    
    body {
        height: 100%;
        position: relative;
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
        touch-action: pan-x pan-y pinch-zoom;
    }
}

/* ===== 移动端布局优化 - 新增 ===== */
/* 工具类 - 显示隐藏控制 */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

/* 桌面端隐藏移动端搜索栏 */
.mobile-search-bar {
    display: none;
}

@media (max-width: 1023px) {
    .desktop-only {
        display: none !important;
    }
    
    .mobile-only {
        display: block !important;
    }
    
    /* 移动端显示移动端搜索栏 */
    .mobile-search-bar {
        display: block !important;
    }
    
    /* 主要布局容器 */
    #app {
        display: flex;
        flex-direction: column;
        height: 100dvh;
        overflow: hidden;
        /* 禁用下拉刷新 */
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
    }

    [data-theme="dark"] #app{
        background-color: #1f2937;
    }
    
    /* 主内容区域重新布局 */
    main {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
        position: relative;
        /* 禁用下拉刷新 */
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
    }
    
    /* 移动端标题栏固定定位 */
    nav {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        /* 保持原有的背景色: bg-white dark:bg-gray-800 */
        background-color: var(--bg-secondary) !important;
        backdrop-filter: blur(8px);
    }
    
    [data-theme="dark"] nav {
        background-color: #1f2937 !important; /* dark:bg-gray-800 */
    }
    
    /* 移动端专用搜索栏样式 */
    .mobile-search-bar {
        background-color: var(--bg-secondary) !important; /* 统一背景色与标题栏一致 */
        border-bottom: 1px solid var(--border-light, #e5e7eb);
        padding: 0px 12px 12px 12px;
        position: fixed !important;
        top: 64px; /* 标题栏高度 */
        left: 0;
        right: 0;
        z-index: 99;
        backdrop-filter: blur(8px);
    }
    
    [data-theme="dark"] .mobile-search-bar {
        background-color: #1f2937 !important; /* 统一背景色与标题栏一致 */
        /* border-color: var(--border-light, #374151); */
        border-color: #252c36;
    }
    
    /* 移动端搜索控制栏布局 */
    .mobile-search-controls {
        display: flex;
        align-items: center;
        gap: 0;
    }
    
    .mobile-search-bar .search-container {
        flex: 1;
        max-width: none;
        margin: 0;
    }
    
    .mobile-search-bar .search-input-wrapper {
        background-color: var(--bg-white, #ffffff);
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 8px;
        padding: 0 12px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    [data-theme="dark"] .mobile-search-bar .search-input-wrapper {
        background-color: var(--bg-secondary, #374151);
        border-color: var(--border-light, #4b5563);
    }
    
    .mobile-search-bar .search-input {
        flex: 1;
        border: none;
        background: transparent;
        padding: 12px 0;
        font-size: 16px;
        color: var(--text-primary, #1f2937);
        outline: none;
    }

    @media (max-width: 1023px) {
        #mobileSearchInput {
            border: none !important;
            box-shadow: none !important;
            background: transparent;
        }
    }
    
    [data-theme="dark"] .mobile-search-bar .search-input {
        color: var(--text-primary, #f9fafb);
    }
    
    .mobile-search-bar .search-input::placeholder {
        color: var(--text-secondary, #6b7280);
    }
    
    .mobile-search-bar .search-icon,
    .mobile-search-bar .search-clear {
        color: var(--text-secondary, #6b7280);
        font-size: 18px;
        cursor: pointer;
    }
    
    .mobile-search-bar .search-clear {
        background: none;
        border: none;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    @media (max-width: 1023px) {
        #topNav {
            border: none !important;
            padding: 0 8px;
        }
    }
    
    /* 主内容区域调整 */
    .mobile-main-content {
        flex: 1;
        overflow: hidden !important; /* 不在这里滚动，滚动移到knowledge-grid-container */
        margin-top: 119px;
        margin-bottom: 95px;
        /* 禁用下拉刷新 */
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
        position: relative !important; /* 确保布局稳定 */
    }
    
    /* 移动端专用分页栏样式 */
    .mobile-pagination-bar {
        background-color: white !important; /* 统一背景色与标题栏一致 */
        border-top: 1px solid var(--border-light, #e5e7eb);
        /* padding: 8px 16px 4px 16px; */
        position: fixed !important;
        bottom: 30px; /* 备案栏高度 */
        left: 0;
        right: 0;
        z-index: 98;
        backdrop-filter: blur(8px);
    }
    
    [data-theme="dark"] .mobile-pagination-bar {
        background-color: #1f2937 !important; /* 统一背景色与标题栏一致 */
        /* border-color: var(--border-light, #374151); */
        border-color: #252c36;
    }
    
    .mobile-pagination-bar .pagination-container {
        display: flex;
        justify-content: center;
        align-items: center;
        /* gap: 8px; */
    }
    
    /* 移动端专用备案栏样式 */
    .mobile-beian-bar {
        background-color: white !important; /* 统一背景色与标题栏一致 */
        color: var(--text-secondary, #6b7280);
        border-top: 1px solid var(--border-light, #e5e7eb);
        text-align: center;
        font-size: 0.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 30px;
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 97;
        backdrop-filter: blur(8px);
    }
    
    [data-theme="dark"] .mobile-beian-bar {
        background-color: #1f2937 !important; /* 统一背景色与标题栏一致 */
        color: var(--text-secondary, #9ca3af);
        /* border-color: var(--border-light, #374151); */
        border-color: #252c36;
    }
    
    .mobile-beian-bar a {
        color: inherit;
        text-decoration: none;
        transition: color 0.2s ease;
    }
    
    .mobile-beian-bar a:hover {
        color: var(--text-primary, #1f2937);
    }
    
    [data-theme="dark"] .mobile-beian-bar a:hover {
        color: var(--text-primary, #f9fafb);
    }
    
    /* 确保知识库列表容器占满剩余空间，移除嵌套滚动 */
    .knowledge-area {
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important; /* 防止自身滚动 */
        position: relative !important; /* 确保不跟随滚动 */
    }
    
    .knowledge-list {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important; /* 防止自身滚动 */
        height: 100% !important;
        width: 100% !important; /* 覆盖styles/index.css中的width设置 */
        border-right: none !important;
        border-bottom: none !important;
        position: relative !important; /* 确保不跟随滚动 */
    }
    
    .list-content {
        flex: 1;
        overflow: hidden !important; /* 防止自身滚动 */
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        position: relative !important; /* 确保不跟随滚动 */
    }
    
    .knowledge-grid-container {
        padding: 12px !important;
        /* padding-bottom: 20px !important; 增加底部间距，与顶部间距保持一致 */
        height: 100% !important; /* 占满父容器 */
        overflow-y: auto !important; /* 只在这里滚动 */
        flex: 1 !important; /* 占满可用空间 */
        position: relative !important; /* 确保不跟随滚动 */
        /* 优化滚动体验 - 保留弹性效果 */
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        /* 允许滚动容器的弹性效果，但禁用下拉刷新 */
        overscroll-behavior-y: contain;
        -webkit-overscroll-behavior-y: contain;
    }
    
    /* 确保列表内容有足够的滚动空间 */
    .list-content .knowledge-grid {
        margin-bottom: 16px; /* 额外的底部间距 */
    }
    
    /* 调整知识库网格布局 */
    .knowledge-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
        overflow: visible;
    }
    
    /* 确保详情区域不影响布局 */
    .knowledge-detail {
        display: none; /* 移动端隐藏侧边详情区域 */
    }
}

/* ===== 手势管理相关样式 ===== */
/* 当弹出对话框时禁用滑动手势 */
body.gesture-disabled {
    /* 防止用户在有弹框时滑动屏幕 */
    overflow: hidden !important; /* 添加!important确保优先级 */
    /* 禁用下拉刷新 */
    overscroll-behavior-y: none !important;
    -webkit-overscroll-behavior-y: none !important;
    /* 增加明显的指示器，用于调试 */
    position: relative;
}

/* 禁用滑动手势时，确保弹框内部可以滚动 */
body.gesture-disabled .utils-dialog .overflow-y-auto,
body.gesture-disabled .ios-dialog-overlay .overflow-y-auto,
body.gesture-disabled #category-dialog-content, /* 添加标签对话框滚动支持 */
body.gesture-disabled div[id*="dialog"] .overflow-y-auto {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    /* 为弹框滚动区域保留弹性效果 */
    overscroll-behavior-y: contain !important;
    -webkit-overscroll-behavior-y: contain !important;
    /* max-height: 70dvh !important; 确保有最大高度，避免超过屏幕 */
}

/* 确保弹框在手势禁用时不会移动 */
body.gesture-disabled .utils-dialog,
body.gesture-disabled .ios-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
}

/* 针对自定义标签对话框的特殊处理 */
#category-dialog-content {
    overflow-y: auto;
    max-height: 60dvh;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    -webkit-overscroll-behavior-y: contain;
}

/* ===== 移动端基础优化 ===== */
@media (max-width: 1023px) {
    /* 触摸优化 */
    body {
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
        overflow-x: hidden;
        overflow-y: hidden; /* 移动端禁用body滚动，使用容器化滚动 */
        /* 禁用下拉刷新 */
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
    }
    
    /* 确保滑动手势在移动设备上正常工作 */
    body:not(.gesture-disabled) {
        /* 确保非禁用状态下触摸滑动正常 */
        overflow-x: hidden;
        overflow-y: hidden; /* 移动端禁用body滚动，使用容器化滚动 */
        /* 禁用下拉刷新 */
        overscroll-behavior-y: none;
        -webkit-overscroll-behavior-y: none;
    }
    
    /* 防止移动端下知识库内容区滚动与body滚动冲突 */
    #knowledgeContainer {
        overflow: visible;
    }
    
    /* 防止在滚动区域内嵌套滚动区域 */
    #knowledgeContainer .knowledge-section {
        overflow: visible;
    }
    
    /* 防止内部元素滚动冲突 */
    #knowledgeListContainer {
        overflow: visible;
    }
    
    /* 防止横屏缩放 */
    @viewport {
        width: device-width;
        zoom: 1.0;
        user-zoom: fixed;
    }
    
    /* 按钮最小尺寸 */
    .btn,
    .btn-icon,
    button {
        min-height: 32px;
        min-width: 32px;
        touch-action: manipulation;
    }
    
    /* 输入框优化 */
    input,
    textarea,
    select {
        font-size: 16px; /* 防止iOS缩放 */
        min-height: 44px;
    }
    
    /* 链接优化 */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    
    /* 移动端：禁用导览按钮hover效果，确保选中状态优先 */
    .btn-nav:hover {
        background: transparent !important;
    }
    
    /* 移动端：确保导览按钮选中状态优先级更高 */
    .btn-nav.active,
    .btn-nav.bg-blue-50 {
        background: rgb(239, 246, 255) !important;
    }
    
    [data-theme="dark"] .btn-nav.active,
    [data-theme="dark"] .btn-nav.bg-blue-900\/30,
    .dark .btn-nav.active,
    .dark .btn-nav.bg-blue-900\/30 {
        background: rgba(30, 58, 138, 0.3) !important;
    }
    
    /* 移动端：禁用标签按钮hover效果，确保选中状态优先 */
    .category-item:hover {
        background-color: transparent !important;
    }
    
    /* 标签样式已移至 styles/sidebar.css 统一管理 */
    
    /* ===== 移动端导航栏布局 ===== */
    /* 导航栏基础布局 */
    nav .flex.items-center.h-16 {
        position: relative;
    }
    
    /* 标题容器绝对居中 */
    nav .flex-1.flex.items-center.justify-center {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: auto;
        pointer-events: none;
        z-index: 1;
    }
    
    /* 标题文本样式 */
    nav #currentPageTitle {
        font-size: 1.125rem;
        font-weight: 600;
        max-width: calc(100vw - 120px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        pointer-events: auto;
        text-align: center;
    }
    
    /* 右侧按钮组定位 */
    nav .flex.items-center.gap-2 {
        position: relative;
        z-index: 2;
        margin-left: auto;
        gap: 0.25rem;
    }
    
    /* 移动端标签新增按钮 - 与主样式保持一致 */
    #categoryAdd,
    button#categoryAdd,
    #categoryAdd[style],
    button#categoryAdd[style] {
        display: inline-block !important;
        width: 40px !important;
        height: 24px !important;
        line-height: 24px !important;
        font-size: 12px !important;
    }
}

/* ===== 头部移动端优化 ===== */
@media (max-width: 1023px) {
    .header {
        padding: var(--spacing-xs) var(--spacing-sm);
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.95);
    }
    
    /* 深色模式支持 */
    [data-theme="dark"] .header {
        background: rgba(15, 23, 42, 0.95);
    }
    
    .header__container {
        gap: var(--spacing-xs);
    }
    
    .header__title {
        font-size: 18px;
        display: none; /* 在小屏幕隐藏标题 */
    }
    
    .header__center {
        flex: 1;
        order: 2;
    }
    
    .header__right {
        order: 3;
    }
    
    .header__left {
        order: 1;
    }
    

    
    /* 搜索框移动端优化 */
    .search-container {
        width: 100%;
        max-width: none;
    }
    
    .search-box {
        padding: var(--spacing-xs);
    }
    
    .search-box__input {
        font-size: 16px;
        padding: var(--spacing-xs) var(--spacing-sm);
    }
    
    .search-controls {
        display: none; /* 在移动端隐藏高级搜索按钮 */
    }
    
    /* 头部按钮优化 */
    .header__actions {
        gap: var(--spacing-xs);
    }
    
    .header__actions .btn__text {
        display: none;
    }
    
    .header__user span {
        display: none;
    }
    
    .header__divider {
        display: none;
    }
}

/* ===== 侧边栏移动端优化 ===== */
@media (max-width: 1023px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 9999;
        background: var(--color-surface);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar__header {
        padding: var(--spacing-md);
        border-bottom: 1px solid var(--color-border);
    }
    
    .sidebar__nav {
        padding: var(--spacing-sm);
        height: calc(100dvh - 80px);
        overflow-y: auto;
    }
    
    /* 侧边栏遮罩 */
    .sidebar-overlay,
    #sidebarOverlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        display: none;
    }
    
    .sidebar-overlay.show,
    #sidebarOverlay.show {
        opacity: 1;
        visibility: visible;
        display: block !important;
    }
    
    /* 确保遮罩层在移动端正确显示 */
    #sidebarOverlay:not(.hidden) {
        display: block;
    }
    
    #sidebarOverlay.hidden {
        display: none !important;
    }
    
    /* 导航项目优化 */
    .nav-link {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 16px;
    }
    
    .nav-link__icon {
        width: 20px;
        height: 20px;
    }
    
    /* 主内容区域调整 */
    .main {
        margin-left: 0;
        padding-top: 0;
    }
    
    .content {
        padding: var(--spacing-sm);
    }
}

/* ===== 内容区域移动端优化 ===== */
@media (max-width: 1023px) {
    .content-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-md);
    }
    
    .content-title {
        font-size: 24px;
        margin-bottom: var(--spacing-xs);
    }
    
    .content-subtitle {
        font-size: 14px;
    }
    
    .content-actions {
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }
    
    /* 视图切换移动端优化 */
    .view-toggle {
        order: 1;
        flex: 1;
        justify-content: center;
    }
    
    .view-toggle__btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* 操作按钮优化 */
    .content-actions .btn {
        flex: 1;
        min-height: 44px;
        justify-content: center;
    }
    
    .content-actions .btn__text {
        display: block;
    }
}

/* ===== 知识卡片移动端优化 ===== */
@media (max-width: 1023px) {
    .knowledge-list {
        gap: var(--spacing-sm);
    }
    
    /* 网格视图优化 */
    .knowledge-list.view-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }
    
    .knowledge-card {
        padding: var(--spacing-md);
        border-radius: var(--border-radius-md);
    }
    
    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-sm);
    }
    
    .card-title {
        font-size: 18px;
        line-height: 1.4;
        word-break: break-all;
        overflow-wrap: break-word;
    }
    
    .card-actions {
        justify-content: space-between;
        align-self: stretch;
    }
    
    .card-meta {
        flex-wrap: wrap;
        gap: var(--spacing-xs);
    }
    
    .card-content p {
        font-size: 14px;
        line-height: 1.5;
        word-break: break-all;
        overflow-wrap: break-word;
    }
    
    /* 列表视图优化 */
    .knowledge-list.view-list .knowledge-list-item {
        flex-direction: column;
        padding: var(--spacing-md);
    }
    
    .list-item-actions {
        justify-content: space-around;
        border-top: 1px solid var(--color-border-light);
        padding-top: var(--spacing-sm);
        margin-top: var(--spacing-sm);
    }
    
    /* 紧凑视图优化 */
    .knowledge-list.view-compact {
        gap: var(--spacing-xs);
    }
    
    .knowledge-compact-item {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* ===== 搜索结果移动端优化 ===== */
@media (max-width: 1023px) {
    .search-result-item {
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-sm);
    }
    
    .search-result-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-xs);
    }
    
    .search-result-title {
        font-size: 16px;
    }
    
    .search-result-meta {
        flex-wrap: wrap;
        gap: var(--spacing-xs);
    }
    
    .search-result-actions {
        justify-content: space-around;
        margin-top: var(--spacing-sm);
        padding-top: var(--spacing-sm);
        border-top: 1px solid var(--color-border-light);
    }
    
    .search-result-actions .btn {
        flex: 1;
        margin: 0 var(--spacing-xs);
    }
}

/* ===== 高级搜索面板移动端优化 ===== */
@media (max-width: 1023px) {
    .advanced-search-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        border-radius: 0;
        z-index: 300;
        overflow-y: auto;
        background: var(--color-surface);
    }
    
    .advanced-search-title {
        position: sticky;
        top: 0;
        background: var(--color-surface);
        padding: var(--spacing-md);
        border-bottom: 1px solid var(--color-border);
        margin-bottom: 0;
    }
    
    .filter-grid {
        grid-template-columns: 1fr;
        padding: var(--spacing-md);
        gap: var(--spacing-md);
    }
    
    .sort-options {
        padding: var(--spacing-md);
        border-top: 1px solid var(--color-border);
        margin-top: 0;
    }
    
    /* 关闭按钮 */
    .advanced-search-panel::before {
        content: '×';
        position: fixed;
        top: var(--spacing-md);
        right: var(--spacing-md);
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--color-background);
        border: 1px solid var(--color-border);
        border-radius: 50%;
        font-size: 24px;
        color: var(--color-text);
        cursor: pointer;
        z-index: 10;
    }
}

/* ===== 模态框移动端优化 ===== */
@media (max-width: 1023px) {
    .modal-content {
        margin: 0;
        width: 100%;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border-radius: 0;
        overflow-y: auto;
    }
    
    .modal-header {
        position: sticky;
        top: 0;
        background: var(--color-surface);
        z-index: 10;
        border-bottom: 1px solid var(--color-border);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--spacing-md);
    }

    /* 优化模态框关闭按钮在移动端的触摸区域 */
    .modal-close {
        padding: 0.75rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 8px !important;
        flex-shrink: 0;
    }

    /* 优化对话框关闭按钮 */
    .dialog-header .text-gray-400 {
        padding: 0.75rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    .modal-body {
        padding: var(--spacing-md);
        min-height: calc(100dvh - 120px);
    }
    
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        padding: var(--spacing-md);
    }
    
    .modal-footer .btn {
        flex: 1;
        min-height: 48px;
    }
}

/* ===== 编辑器移动端优化 ===== */
@media (max-width: 1023px) {
    .editor-container {
        flex-direction: column;
        /* height: calc(100dvh - 60px); */
    }
    
    .editor-toolbar {
        flex-wrap: wrap;
        padding: var(--spacing-xs);
        gap: var(--spacing-xs);
        justify-content: center;
    }
    
    .editor-toolbar .btn {
        min-width: 44px;
        min-height: 44px;
        padding: var(--spacing-xs);
    }
    
    .editor-content {
        flex-direction: column;
    }
    
    .editor-pane {
        min-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
    
    .editor-pane:last-child {
        border-bottom: none;
    }
    
    .editor-textarea {
        font-size: 16px;
        line-height: 1.5;
    }
    
    /* 编辑器视图切换 */
    .editor-view-toggle {
        display: flex;
        position: sticky;
        top: 0;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        z-index: 10;
    }
    
    .editor-view-toggle .btn {
        flex: 1;
        border-radius: 0;
        border: none;
        border-right: 1px solid var(--color-border);
    }
    
    .editor-view-toggle .btn:last-child {
        border-right: none;
    }
}

/* ===== 表单移动端优化 ===== */
@media (max-width: 1023px) {
    .form-group {
        margin-bottom: var(--spacing-md);
    }
    
    .form-label {
        font-size: 16px;
        margin-bottom: var(--spacing-xs);
    }
    
    .form-input,
    .form-textarea,
    .form-select {
        font-size: 16px;
        /* padding: var(--spacing-sm); */
        min-height: 48px;
    }
    
    .form-textarea {
        min-height: 120px;
    }
    
    /* 禁用摘要输入框的拖拽调整大小功能 */
    .editor-excerpt-input {
        resize: none !important;
    }
    
    .form-row {
        flex-direction: column;
        gap: var(--spacing-md);
    }
    
    .form-actions {
        flex-direction: column;
        gap: var(--spacing-sm);
        position: sticky;
        bottom: 0;
        background: var(--color-surface);
        padding: var(--spacing-md);
        border-top: 1px solid var(--color-border);
        margin: 0 calc(-1 * var(--spacing-md));
    }
    
    .form-actions .btn {
        min-height: 48px;
        font-size: 16px;
    }
}

/* ===== 标签移动端优化 ===== */
@media (max-width: 1023px) {
    .tag-editor {
        flex-direction: column;
    }
    
    .tag-input-container {
        margin-bottom: var(--spacing-sm);
    }
    
    .tag-input {
        font-size: 16px;
        min-height: 44px;
    }
    
    .tag-list {
        max-height: 200px;
        overflow-y: auto;
    }
    
    .tag {
        margin: var(--spacing-xs);
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 14px;
        min-height: 32px;
    }
    
    .tag-remove {
        min-width: 24px;
        min-height: 24px;
    }
}

/* ===== 通知移动端优化 ===== */
@media (max-width: 1023px) {
    .notification {
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        width: auto;
        margin-top: var(--spacing-sm);
    }
    
    .notification-content {
        padding: var(--spacing-md);
    }
    
    .notification-title {
        font-size: 16px;
    }
    
    .notification-message {
        font-size: 14px;
    }
    
    .notification-close {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem;
        border-radius: 8px;
    }
}

/* ===== 工具提示移动端优化 ===== */
@media (max-width: 1023px) {
    [data-tooltip]:hover::before,
    [data-tooltip]:hover::after {
        display: none; /* 在移动端隐藏工具提示 */
    }
}

/* ===== 手势支持 ===== */
@media (max-width: 1023px) {
    .swipeable {
        touch-action: pan-y;
    }
    
    .knowledge-card,
    .search-result-item,
    .list-item {
        position: relative;
        overflow: hidden;
    }
    
    /* 滑动操作指示器 */
    .swipe-actions {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 200px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--color-danger);
        color: white;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    
    .swipe-actions.show {
        transform: translateX(0);
    }
}

/* ===== 横屏适配 ===== */
@media (max-width: 1023px) and (orientation: landscape) {
    .header {
        padding: var(--spacing-xs);
    }
    
    .modal-content {
        height: 100dvh;
    }
    
    .editor-container {
        /* height: calc(100dvh - 50px); */
    }
    
    .advanced-search-panel {
        padding: var(--spacing-sm);
    }
}



/* ===== iOS Safari 优化 ===== */
@supports (-webkit-touch-callout: none) {
    .header {
        padding-top: env(safe-area-inset-top);
    }
    
    .modal-content {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .form-actions {
        padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom));
    }
}

/* ===== PWA 优化 ===== */
@media (display-mode: standalone) {
    .header {
        padding-top: var(--spacing-md);
    }
    
    body {
        overscroll-behavior: none;
    }
}

/* ===== PWA横屏模式优化 ===== */
/* 修复iOS PWA横屏模式下的状态栏区域和安全区域问题 */
@media (display-mode: standalone) and (orientation: landscape) and (max-width: 1023px) {
    /* 隐藏顶部多余的状态栏区域 */
    body {
        padding-top: 0 !important;
    }
    
    html {
        padding-top: 0 !important;
    }
    
    /* 导航栏横屏safe-area处理 - 添加左右安全区域 */
    nav, #topNav {
        padding-left: max(8px, env(safe-area-inset-left)) !important;
        padding-right: max(8px, env(safe-area-inset-right)) !important;
        padding-top: 0 !important;
        z-index: 100 !important;
        position: fixed !important;
    }
    
    /* 搜索栏安全区域 */
    .mobile-search-bar {
        padding-left: max(12px, env(safe-area-inset-left)) !important;
        padding-right: max(12px, env(safe-area-inset-right)) !important;
        z-index: 99 !important;
    }
    
    /* 分页栏安全区域 */
    .mobile-pagination-bar {
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
        z-index: 98 !important;
    }
    
    /* 备案栏安全区域 */
    .mobile-beian-bar {
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
        z-index: 97 !important;
    }
    
    /* 确保主内容区域不会被遮挡 */
    .mobile-main-content {
        margin-top: 119px !important;
    }
    
    /* 知识库网格容器安全区域 */
    .knowledge-grid-container {
        padding-left: max(12px, env(safe-area-inset-left)) !important;
        padding-right: max(12px, env(safe-area-inset-right)) !important;
    }
}

/* ===== 高DPI屏幕优化 ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .icon,
    .btn-icon i {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== 减少动画（移动端） ===== */
@media (max-width: 1023px) and (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }
    
    .modal-content {
        transition: none;
    }
    
    .notification {
        transition: none;
    }
}

/* ===== 对话框组件移动端优化 ===== */
@media (max-width: 1023px) {
    /* 优化所有对话框关闭按钮的触摸区域 */
    .dialog-header button[aria-label="关闭"] {
        padding: 0.75rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 8px !important;
    }
    
    /* 优化模态框和通用关闭按钮 */
    button[data-action="close"],
    .modal__close,
    .notification__close {
        padding: 0.75rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 8px !important;
    }
} 