/* 加载方正仿宋字体 */
@font-face {
    font-family: 'FZFangSong';
    src: url('fonts/FZFangSong-Z02.woff2') format('woff2'),
         url('fonts/FZFangSong-Z02.woff') format('woff'),
         url('fonts/FZFangSong-Z02.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap; /* 优化字体加载性能 */
}

@font-face {
    font-family: 'FZFangSong';
    src: url('fonts/FZFangSong-Z02S.woff2') format('woff2'),
         url('fonts/FZFangSong-Z02S.woff') format('woff'),
         url('fonts/FZFangSong-Z02S.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;

    padding-top: 15px; /* 为固定顶栏留出空间 */
}

/* 只影响页面内容区域的 header，不影响 base.html 的顶栏 */
.container header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 只影响页面内容区域的 header h1，不影响 base.html 的顶栏 */
.container header h1 {
    font-size: 24px;
    color: #2c3e50;
}

/* 只影响页面内容区域的 nav，不影响 base.html 的导航栏 */
.container nav {
    display: flex;
    gap: 15px;
}

.container nav a {
    padding: 8px 16px;
    text-decoration: none;
    color: #555;
    border-radius: 4px;
    transition: all 0.2s;
}

.container nav a:hover {
    background: #f0f0f0;
}

.container nav a.active {
    background: #007bff;
    color: white;
}

.main-content {
    display: flex;
    gap: 20px;
    position: relative;
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
    position: relative; /* 默认相对定位，在正常文档流中 */
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent; /* 背景透明，让 control-panel 显示背景 */
    /* 隐藏滚动条但保持滚动功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 和 Edge */
    transition: position 0.1s ease; /* 平滑过渡 */
}

/* 隐藏侧边栏滚动条 - Chrome/Safari */
.sidebar::-webkit-scrollbar {
    display: none;
}

/* 当滚动到内容区域后，侧边栏变为固定定位 */
.sidebar.sidebar-fixed {
    position: fixed;
    top: 64px; /* 下移一个顶栏的高度 (h-16 = 64px) */
    bottom: 0;
    z-index: 40; /* 低于模态框（z-50）和其他重要元素 */
}

.sidebar-left.sidebar-fixed {
    left: calc(256px + 20px); /* 左侧导航栏宽度 (md:ml-64 = 256px) + 容器padding */
}

.sidebar-right.sidebar-fixed {
    right: 20px; /* 与容器padding对齐 */
}

.control-panel {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    /* 隐藏滚动条但保持滚动功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 和 Edge */
}

/* 隐藏控制面板滚动条 - Chrome/Safari */
.control-panel::-webkit-scrollbar {
    display: none;
}

.sidebar-left .control-panel {
    /* 去掉高度限制和滚动条，展开所有内容 */
}

.sidebar-right .control-panel {
    /* 右侧样式配置不限制高度，可以往下撑开 */
}

.control-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.control-section:last-child {
    border-bottom: none;
}

.control-section h3 {
    font-size: 16px;
    color: #2c3e50;
    margin-bottom: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: #555;
    margin-bottom: 5px;
}

.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
}

.form-group input[type="range"] {
    width: 100%;
}

.form-group input[type="color"] {
    width: 100%;
    height: 35px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.form-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.form-group input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.form-group input[type="number"]:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.form-group input[type="checkbox"] {
    margin-right: 8px;
}

.btn {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.preview-area {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    /* 移除固定边距，因为侧边栏现在是相对定位 */
}

.preview-header {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
    position: relative; /* 默认相对定位 */
    background: white; /* 确保背景是白色 */
    z-index: 10;
    transition: position 0.1s ease; /* 平滑过渡 */
}

/* 当滚动到内容区域后，预览信息栏变为固定定位 */
.preview-header.preview-header-fixed {
    position: fixed;
    top: 64px; /* 下移一个顶栏的高度 (h-16 = 64px) */
    z-index: 39; /* 低于侧边栏（z-40），确保层级正确 */
    margin-bottom: 0;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    background: white;
    /* left 和 width 由 JavaScript 动态设置，以考虑侧边栏宽度 */
}

/* 当预览信息栏固定时，需要为预览区域添加顶部边距（由JavaScript动态设置） */
.preview-area.has-fixed-header {
    /* padding-top 由 JavaScript 动态计算设置 */
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 4px;
}

.zoom-controls button {
    width: 28px;
    height: 28px;
    border: none;
    background: #f5f5f5;
    border-radius: 3px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

.zoom-controls button:hover {
    background: #e9ecef;
}

.zoom-controls span {
    min-width: 50px;
    text-align: center;
    font-size: 13px;
}

.stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 13px;
    color: #555;
}

.stats span {
    white-space: nowrap;
}

.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    overflow: auto;
    background: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 20px;
    width: 100%;
    min-width: 0; /* 允许 flex 子元素缩小 */
}

#previewCanvas {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: block;
    flex-shrink: 0; /* 防止被压缩 */
}

/* 滚动条样式 - 仅用于canvas容器 */
.canvas-container::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.canvas-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.canvas-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.canvas-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 图形按钮样式 */
.shape-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

/* 兼容旧样式：如果使用 grid 布局 */
.shape-buttons.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.shape-btn {
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 兼容旧样式：如果使用 aspect-ratio */
.shape-buttons.grid .shape-btn {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
}

.shape-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    border-color: #007bff;
}

/* 兼容旧样式 */
.shape-buttons.grid .shape-btn:hover {
    transform: none;
    box-shadow: none;
    border-color: #007bff;
    background: #f0f7ff;
}

.shape-btn.active {
    border-color: #007bff !important;
    border-width: 3px !important;
    background: #e7f3ff !important;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.shape-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.shape-preview {
    display: block;
}

/* 兼容旧样式 */
.shape-buttons.grid .shape-preview {
    width: 100%;
    height: 100%;
}

/* 按钮组样式 */
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.operation-group {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.format-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.range-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    min-width: 60px;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    color: #333;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.toggle-btn:hover {
    border-color: #007bff;
    background: #f0f7ff;
}

.toggle-btn.active {
    background: white;
    color: #007bff;
    border: 3px solid #007bff;
    font-weight: 700;
}

.toggle-btn.active:hover {
    border-color: #0056b3;
    color: #0056b3;
}

/* 模式切换 Tab 按钮样式 */
.mode-tabs {
    display: flex;
    gap: 0;
    border: 2px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    background: #f8f9fa;
}

.mode-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.mode-tab:hover {
    background: #e9ecef;
    color: #333;
}

.mode-tab.active {
    background: white;
    color: #007bff;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mode-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #007bff;
}

/* ==================== 移动端适配 ==================== */
@media (max-width: 768px) {
    /* 生成器页面隐藏头部和脚部 */
    body.generator-page header,
    body.generator-page footer,
    body.generator-page #sideNavigation,
    body.generator-page .fixed.left-8,
    body.generator-page .fixed.right-8,
    body.generator-page .container > .page-footer,
    body.generator-page .resource-navigation,
    body.generator-page .sidebar-toggle-right,
    body.generator-page .mobile-action-buttons {
        display: none !important;
    }
    
    body.generator-page main {
        margin-top: 0 !important;
        margin-left: 0 !important;
    }
    
    .container {
        padding: 0;
        max-width: 100%;
    }

    .main-content {
        position: relative;
        display: block;
    }

    /* 预览区域在移动端占满 */
    .preview-area {
        width: 100%;
        padding: 0;
        padding-bottom: 80px;
        order: 1;
        margin: 0;
        background: transparent;
        box-shadow: none;
        border-radius: 0;
    }

    /* 侧边栏默认隐藏，可以侧滑展开 */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        background: white;
        box-shadow: 2px 0 8px rgba(0,0,0,0.15);
        overflow-y: auto;
    }

    .sidebar-left {
        left: 0;
    }

    .sidebar-right {
        right: 0;
        transform: translateX(100%);
    }

    /* 侧边栏展开状态 */
    .sidebar.open {
        transform: translateX(0);
    }

    /* 遮罩层 */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* 侧滑菜单触发按钮 */
    .sidebar-toggle {
        position: fixed;
        bottom: 100px;
        z-index: 998;
        min-width: 90px;
        height: 44px;
        padding: 0 14px;
        background: rgba(255, 255, 255, 0.98);
        color: #555;
        border: 1.5px solid #d0d0d0;
        border-radius: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        cursor: pointer;
        box-shadow: 0 3px 10px rgba(0,0,0,0.12);
        transition: all 0.2s;
        font-size: 13px;
        font-weight: 500;
        backdrop-filter: blur(10px);
        pointer-events: auto;
    }

    .sidebar-toggle:hover {
        background: rgba(255, 255, 255, 1);
        border-color: #bbb;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        transform: translateY(-1px);
    }

    .sidebar-toggle-left {
        left: 12px;
    }

    .sidebar-toggle-right {
        right: 12px;
    }

    .sidebar-toggle svg {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
        stroke: #555;
        stroke-width: 2.5;
    }

    .sidebar-toggle-text {
        white-space: nowrap;
        font-size: 13px;
        color: #555;
        font-weight: 500;
    }

    /* 移动端隐藏左侧栏中的操作按钮（因为要悬浮在底部） */
    .sidebar-left .control-section:last-child {
        display: none;
    }
    
    /* 移动端隐藏左侧栏中的下载和打印按钮 */
    .sidebar-left #exportPDF,
    .sidebar-left #printBtn {
        display: none !important;
    }

    /* 底部悬浮按钮区域 */
    .mobile-action-buttons {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 12px 16px;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 997;
        display: flex;
        gap: 12px;
        pointer-events: auto;
    }

    .mobile-action-buttons button {
        flex: 1;
        padding: 14px 20px;
        border: none;
        border-radius: 8px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
    }
    
    /* 移动端只有一个按钮时，让它占满宽度 */
    .mobile-action-buttons #exportPDFMobile {
        flex: 1;
        width: 100%;
    }

    .mobile-action-buttons #exportPDF {
        background: #007bff;
        color: white;
    }

    .mobile-action-buttons #exportPDF:hover {
        background: #0056b3;
    }

    .mobile-action-buttons #printBtn,
    .mobile-action-buttons #printBtnMobile {
        display: none !important;
    }


    /* 标题和统计信息在移动端优化 */
    .container .desktop-title {
        display: block !important;
        font-size: 20px !important;
        margin: 20px 0 8px 0 !important;
        word-wrap: break-word;
        word-break: break-word;
        max-width: 20em; /* 最多显示10个中文字符，超过换行 */
        margin-left: auto !important;
        margin-right: auto !important;
    }

    .container .mobile-title {
        display: none !important;
    }

    .container h2 {
        display: none !important;
    }

    .stats {
        font-size: 11px;
        gap: 10px;
    }

    .stats span {
        font-size: 11px;
    }

    .preview-header {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    /* Canvas容器在移动端优化 */
    .canvas-container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
        background: transparent;
        border: none;
        border-radius: 0;
    }

    /* Canvas在移动端自适应宽度 */
    #previewCanvas {
        max-width: 100%;
        width: 100% !important;
        height: auto;
        display: block;
        box-shadow: none;
    }

    /* 确保canvas不会超出容器 */
    .canvas-container canvas {
        max-width: 100% !important;
        width: auto !important;
        height: auto !important;
    }
    
    /* 预览区域在移动端 */
    .preview-area {
        overflow: hidden;
    }

    /* 预览信息栏在移动端隐藏 */
    .preview-header {
        display: none;
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    /* 隐藏移动端按钮和侧边栏 */
    .sidebar-toggle,
    .mobile-action-buttons,
    .sidebar-overlay,
    .sidebar {
        display: none !important;
    }
    
    /* 打印时恢复预览区的padding */
    .preview-area {
        padding-bottom: 20px !important;
    }
    
    /* 确保canvas正常打印 */
    .canvas-container {
        overflow: visible !important;
    }
    
    #previewCanvas {
        max-width: 100% !important;
        height: auto !important;
    }
}

