/* A4 稿纸生成器样式 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content {
    flex: 1;
    padding: 1.5rem 2rem;
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* 返回链接 */
.back-link {
    margin-bottom: 0.8rem;
    margin-left: 4px;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    color: #666;
    text-decoration: none;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.back-btn:hover {
    color: #2c3e50;
    border-color: #2c3e50;
    transform: translateX(-3px);
}

/* 左右布局容器 */
.layout-container {
    display: flex;
    gap: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* 标题区 */
.tool-section {
    flex: 0 0 420px;
    min-width: 360px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    color: #2c3e50;
    flex-shrink: 0;
}

.page-subtitle {
    color: #7f8c8d;
    font-size: 0.85rem;
    margin-bottom: 0.8rem;
    flex-shrink: 0;
}

/* 控制面板 */
.control-panel {
    background: white;
    border-radius: 12px;
    padding: 1.2rem 1.4rem;
    box-shadow: 0 0 2px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.panel-controls {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-left: 0.5rem;
    padding-right: 0.6rem;
    padding-bottom: 0.5rem;
}

.panel-controls::-webkit-scrollbar {
    width: 6px;
}

.panel-controls::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.panel-controls::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.panel-controls::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.panel-footer-sticky {
    position: sticky;
    bottom: 0;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-top: 0.6rem;
    padding: 0.9rem 1rem;
    z-index: 2;
}

.control-group {
    margin-bottom: 1rem;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.6rem;
    color: #2c3e50;
    font-size: 0.85rem;
}

/* 按钮组 */
.button-group {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.5rem 1rem;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    color: #555;
}

.btn:hover {
    border-color: #3498db;
    color: #3498db;
}

.btn.btn-active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

/* 滑块 */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    margin: 0.6rem 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    transition: all 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    background: #2980b9;
    transform: scale(1.2);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: none;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #999;
}

/* 颜色选择器 */
.color-options {
    display: flex;
    gap: 0.6rem;
    padding: 0.2rem;
}

.color-btn {
    width: 36px;
    height: 36px;
    border: 3px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: #2c3e50;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #2c3e50;
}

/* 文本输入框 */
.text-input {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.85rem;
    transition: border-color 0.2s;
}

.text-input:focus {
    outline: none;
    border-color: #3498db;
}

.inline-inputs {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

/* 复选框 */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.page-number-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.page-number-position-label {
    font-size: 0.82rem;
    color: #666;
}

.page-number-position-group {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem;
    border: 1px solid #e6eaee;
    border-radius: 999px;
    background: #f7f9fb;
}

.page-number-position-group.is-disabled {
    opacity: 0.5;
}

.radio-pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.radio-pill input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-pill span {
    min-width: 2.1rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    text-align: center;
    font-size: 0.82rem;
    color: #607080;
    transition: all 0.18s ease;
}

.radio-pill input[type="radio"]:checked + span {
    background: #2f7fb9;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(47, 127, 185, 0.28);
}

.radio-pill input[type="radio"]:focus-visible + span {
    outline: 2px solid #2f7fb9;
    outline-offset: 1px;
}

/* 操作按钮 */
.action-buttons {
    display: flex;
    gap: 0.8rem;
    margin-top: 0;
}

.action-buttons .btn {
    border-width: 1px;
    border-radius: 6px;
    font-size: 0.9rem;
    padding: 0.65rem 1rem;
}

.btn-primary {
    flex: 1;
    background: #2c3e50;
    color: white;
    border-color: #2c3e50;
    font-weight: 500;
}

.btn-primary:hover {
    background: #1a252f;
    border-color: #1a252f;
    color: white;
}

.btn-secondary {
    flex: 1;
    background: white;
    color: #2c3e50;
    border-color: #dee2e6;
}

.btn-secondary:hover {
    background: #ffffff;
    border-color: #2c3e50;
    color: #2c3e50;
}

/* 提示框 */
.tip-box {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 0.8rem;
    margin-top: 0.8rem;
    font-size: 0.8rem;
    color: #666;
}

.tip-box strong {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    color: #2c3e50;
}

.tip-box ul {
    margin-left: 1.2rem;
    margin-top: 0.3rem;
}

.tip-box li {
    line-height: 1.6;
    margin-bottom: 0.2rem;
}

.tip-list {
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.tip-list.is-collapsed {
    max-height: 3.2em;
}

.tip-toggle-btn {
    margin-top: 0.45rem;
    border: none;
    background: transparent;
    color: #2f7fb9;
    font-size: 0.8rem;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
}

.tip-toggle-btn:hover {
    color: #1f5f8e;
}

/* 预览容器 */
.preview-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: #fafafa;
    border-radius: 12px;
    overflow: auto;
    min-height: 0;
    min-width: 0;
    position: relative;
}

#preview-area {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
    width: 100%;
    height: 100%;
    justify-content: center;
    position: relative;
}

/* 多页模式 */
#preview-area.multi-page .a4-page {
    position: absolute;
    opacity: 0;
    transition: opacity 0.25s ease-in-out;
    pointer-events: none;
}

#preview-area.multi-page .a4-page.active {
    position: relative;
    opacity: 1;
    pointer-events: auto;
}

/* 翻页按钮 */
.page-nav {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 1rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 10;
}

.page-nav-btn {
    background: #3498db;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
}

.page-nav-btn:hover:not(:disabled) {
    background: #2980b9;
    transform: scale(1.05);
}

.page-nav-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.5;
}

.page-nav-info {
    font-size: 0.9rem;
    color: #555;
    min-width: 60px;
    text-align: center;
    user-select: none;
}

/* A4 页面 */
.a4-page {
    width: 210mm;
    height: 297mm;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    position: relative;
    margin: 0 auto;
    page-break-after: always;
    page-break-inside: avoid;
    flex-shrink: 0;
    overflow: hidden;
}

.a4-page.landscape {
    width: 297mm;
    height: 210mm;
}

/* 页眉 */
.page-header {
    position: absolute;
    top: 10mm;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 14pt;
    color: #666;
    padding: 0 20mm;
}

/* 页脚 */
.page-footer {
    position: absolute;
    bottom: 10mm;
    left: 20mm;
    right: 20mm;
    font-size: 10pt;
    color: #999;
    min-height: 1.2em;
}

.page-footer span {
    position: absolute;
    white-space: nowrap;
}

.page-footer .footer-left {
    left: 0;
}

.page-footer .footer-center {
    left: 50%;
    transform: translateX(-50%);
}

.page-footer .footer-right {
    right: 0;
    text-align: right;
}

/* 画布容器 */
.canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.canvas-container svg {
    width: 100%;
    height: 100%;
}

/* 页脚 */
.footer {
    background: #2c3e50;
    color: white;
    text-align: center;
    padding: 1rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.footer p {
    margin: 0.3rem 0;
}

.footer a {
    color: #3498db;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* 打印样式 */
@media print {
    @page {
        margin: 0;
        size: auto;
    }
    
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    html, body {
        margin: 0;
        padding: 0;
        background: white;
        width: 100%;
        height: auto;
    }
    
    .no-print {
        display: none !important;
    }
    
    .container {
        height: auto !important;
        overflow: visible !important;
        display: block !important;
    }
    
    .content {
        padding: 0 !important;
        max-width: none !important;
        overflow: visible !important;
        display: block !important;
        flex: none !important;
    }
    
    .layout-container {
        display: block !important;
        overflow: visible !important;
        flex: none !important;
    }
    
    .preview-container {
        max-width: none !important;
        background: white !important;
        padding: 0 !important;
        overflow: visible !important;
        display: block !important;
        flex: none !important;
        margin: 0 !important;
    }
    
    #preview-area {
        display: block !important;
        overflow: visible !important;
        flex: none !important;
        position: static !important;
        height: auto !important;
    }

    .page-nav {
        display: none !important;
    }
    
    /* 打印时强制显示所有页面，无论是否在多页模式 */
    .a4-page {
        width: 210mm !important;
        height: 297mm !important;
        box-shadow: none !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
        page-break-after: always !important;
        page-break-inside: avoid !important;
        position: relative !important;
        display: block !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    
    .a4-page.landscape {
        width: 297mm !important;
        height: 210mm !important;
    }
    
    .a4-page:last-child {
        page-break-after: auto !important;
    }
    
    .canvas-container {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }
    
    .canvas-container svg {
        width: 100% !important;
        height: 100% !important;
    }
    
    .page-header {
        position: absolute !important;
        top: 10mm !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    .page-footer {
        position: absolute !important;
        bottom: 10mm !important;
        left: 20mm !important;
        right: 20mm !important;
    }
}

/* 响应式 */
@media (max-width: 1200px) {
    .layout-container {
        flex-direction: column;
        overflow-y: auto;
    }

    /* 小屏保留滚动能力，但隐藏内部滚动条 */
    .layout-container,
    .panel-controls,
    .preview-container {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .layout-container::-webkit-scrollbar,
    .panel-controls::-webkit-scrollbar,
    .preview-container::-webkit-scrollbar {
        display: none;
    }
    
    .tool-section {
        flex: none;
        width: 100%;
        min-width: auto;
        overflow: visible;
    }
    
    .control-panel {
        max-height: none;
        overflow: visible;
        padding: 1rem;
    }

    .panel-controls {
        overflow-y: visible;
        padding-right: 0;
    }

    .panel-footer-sticky {
        position: static;
        border-top: none;
        border: 1px solid #e9ecef;
        border-radius: 8px;
        margin-top: 0;
        padding: 0.9rem;
    }
    
    .preview-container {
        min-height: 400px;
        height: 500px;
    }
}

@media (max-width: 768px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .container {
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        overflow-x: clip;
    }

    .content {
        width: 100%;
        max-width: 100%;
        padding: 0.9rem;
        overflow: visible;
        overflow-x: clip;
        min-height: auto;
    }
    
    .layout-container {
        width: 100%;
        max-width: 100%;
        gap: 1rem;
        overflow: visible;
        overflow-x: clip;
        min-height: auto;
    }

    .tool-section,
    .control-panel,
    .panel-controls {
        width: 100%;
        max-width: 100%;
        overflow: visible;
        min-height: auto;
    }

    .panel-controls {
        padding-left: 0;
        padding-right: 0;
    }
    
    .page-title {
        font-size: 1.3rem;
    }
    
    .page-subtitle {
        font-size: 0.8rem;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .preview-container {
        width: 100%;
        max-width: 100%;
        min-height: 280px;
        height: auto;
        padding: 0.5rem;
        overflow: hidden;
    }

    #preview-area {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .a4-page {
        max-width: 100%;
    }

    .page-nav {
        bottom: 0.6rem;
        padding: 0.4rem 0.75rem;
        gap: 0.6rem;
    }

    .footer {
        padding: 0.75rem 1rem;
    }
    
    .control-label {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }
    
    .tip-box {
        font-size: 0.75rem;
        padding: 0.6rem;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 0.75rem;
    }

    .layout-container,
    .tool-section,
    .control-panel,
    .preview-container,
    #preview-area {
        overflow-x: clip;
    }

    .back-btn {
        padding: 6px 12px;
        font-size: 13px;
    }

    .page-title {
        font-size: 1.15rem;
    }

    .page-subtitle {
        font-size: 0.76rem;
    }

    .control-panel {
        padding: 0.85rem;
        border-radius: 10px;
    }

    .button-group {
        gap: 0.35rem;
    }

    .btn {
        padding: 0.45rem 0.7rem;
        font-size: 0.8rem;
        border-radius: 7px;
    }

    .color-options {
        gap: 0.45rem;
        flex-wrap: wrap;
    }

    .color-btn {
        width: 32px;
        height: 32px;
    }

    .text-input {
        font-size: 0.82rem;
        padding: 0.45rem 0.6rem;
    }

    .inline-inputs {
        flex-direction: column;
        gap: 0.45rem;
    }

    .slider {
        margin: 0.45rem 0;
    }

    .slider-labels {
        font-size: 0.74rem;
    }

    .panel-footer-sticky {
        padding: 0.75rem;
    }

    .preview-container {
        min-height: 240px;
    }

    .page-nav {
        bottom: 0.45rem;
        padding: 0.35rem 0.55rem;
    }

    .page-nav-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .page-nav-info {
        font-size: 0.8rem;
        min-width: 52px;
    }
}

@media (max-width: 390px) {
    .content {
        padding: 0.6rem;
    }

    .control-group {
        margin-bottom: 0.8rem;
    }

    .control-label {
        font-size: 0.76rem;
    }

    .btn {
        font-size: 0.76rem;
        padding: 0.4rem 0.62rem;
    }

    .action-buttons .btn {
        padding: 0.58rem 0.7rem;
    }

    .preview-container {
        min-height: 210px;
        border-radius: 10px;
    }

    .tip-box {
        font-size: 0.72rem;
        padding: 0.5rem;
    }
}
