* { margin: 0; padding: 0; box-sizing: border-box; }
:root { --bg-speed: 20s; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(-45deg, #4a6d7c, #8da383, #8a6a9c, #d18a66, #147a61);
    background-size: 400% 400%;
    animation: gradientBG var(--bg-speed) ease infinite;
    background-attachment: fixed;
    min-height: 100vh; 
    padding: 12px 20px 20px 20px; 
    display: flex; 
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: all 0.1s ease;
}

@keyframes gradientBG { 
    0% { background-position: 0% 50%; } 
    50% { background-position: 100% 50%; } 
    100% { background-position: 0% 50%; } 
}

.main-card {
    width: 100%; 
    max-width: 1050px;
    background: rgba(235, 230, 230, 0.75); 
    backdrop-filter: blur(15px); 
    border-radius: 12px; 
    padding: 40px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
    transition: all 0.1s ease;
}

.header { 
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.header h1 { 
    color: #2c3e50; 
    text-align: center; 
    font-size: 24px; 
    padding-bottom: 6px;
    margin-bottom: 12px; 
    letter-spacing: 2px; 
    font-weight: 600; 
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.home-btn, .invoice-btn, .help-btn {
    position: absolute;
    top: 0;
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(74, 109, 124, 0.3);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.home-btn:hover, .invoice-btn:hover, .help-btn:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}
.home-btn { right: 84px; }
.invoice-btn { right: 42px; }
.help-btn { right: 0; }

.top-layout { 
    display: flex; 
    gap: 12px; 
    margin-bottom: 12px; 
    align-items: stretch; 
}

.drop-zone-container { 
    flex: 1.2; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
}

.drop-zone {
    flex: 1; 
    border: 0.5px dashed #4a6d7c; 
    border-radius: 12px;
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    text-align: center; 
    padding: 25px; 
    cursor: pointer; 
    background: rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: all 0.1s ease;
}

.drop-zone:hover { 
    background: rgba(255, 255, 255, 0.5); 
    transform: translateY(-2px);
}

.upload-icon { font-size: 40px; color: #4a6d7c; margin-bottom: 10px; }
.upload-text { font-size: 18px; font-weight: 600; color: #2c3e50; margin-bottom: 8px; }
.upload-subtext { font-size: 14px; color: #576574; }
.upload-subtext span { color: #b97980; text-decoration: underline; }
.upload-limit { font-size: 12px; color: #576574; margin-top: 12px; }

#feedbackArea { display: none; text-align: center; }
.success-msg { color: #147a61; font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.reset-hint { 
    color: #e67e22; 
    font-size: 14px; 
    font-weight: 500; 
    margin-top: 4px;
}

.file-list-container { width: 100%; margin: 8px 0; }
.file-list-header { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: #2c3e50; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid rgba(0,0,0,0.1); }

.btn-add-more {
    background-color: #e67e22;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-add-more:hover {
    background-color: #d4731a;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.file-list-scroll { max-height: 180px; overflow-y: scroll; overflow-x: hidden; border: 1px solid rgba(74, 109, 124, 0.2); border-radius: 6px; background: rgba(255, 255, 255, 0.3); padding: 4px; }
.file-list { font-size: 12px; }
.file-item { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 2px 30px 2px 4px; margin: 1px 0; background: rgba(255, 255, 255, 0.5); border-radius: 4px; min-height: 20px; }
.file-index { font-size: 10px; color: #4a6d7c; font-weight: 600; padding-right: 8px; min-width: 28px; text-align: left; }
.file-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; font-size: 10px; max-width: 180px; text-align: center; }
.file-status { font-size: 9px; padding: 1px 4px; border-radius: 8px; background: #6b9c70; color: white; white-space: nowrap; }
.file-remove-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; background: rgba(74, 109, 124, 0.2); border: none; border-radius: 50%; color: #4a6d7c; font-size: 14px; line-height: 18px; text-align: center; cursor: pointer; }
.file-remove-btn:hover { background: #e67e22; color: white; }

.progress-wrapper { position: relative; height: 24px; background: rgba(0, 0, 0, 0.1); border-radius: 12px; overflow: hidden; display: none; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #77b282, #429852, #0c7820); transition: width 0.8s ease; }
.progress-text { position: absolute; width: 100%; height: 100%; top: 0; left: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 500; color: #ffffff; pointer-events: none; }

.settings-panel { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.setting-unit { background: rgba(170, 180, 180, 0.75); border-radius: 12px; padding: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(0,0,0,0.2); transition: transform 0.1s ease; }
.setting-unit:hover { transform: translateY(-2px); }
.unit-full { grid-column: span 2; }
.unit-header { font-size: 14px; font-weight: 600; color: #2c3e50; margin-bottom: 8px; }

.toggle-btn { width: 70%; height: 35px; border-radius: 12px; border: none; font-weight: 600; cursor: pointer; transition: all 0.1s ease; }
.btn-on { background: #6b9c70; color: white; }
.btn-off { background: #cbd5e1; color: #64748b; }
input[type="range"] { width: 100%; cursor: pointer; accent-color: #0066b2; }

.mode-group { display: flex; gap: 20px; width: 90%; }
.btn-mode { flex: 1; height: 38px; border-radius: 12px; border: 1px solid #cbd5e1; background: #cbd5e1; color: #4a6d7c; font-weight: 600; cursor: pointer; transition: all 0.1s ease; }
.btn-mode:hover { border-color: #4a6d7c; }
.btn-mode.active { background: #6b9c70; color: white; border-color: #4a6d7c; }

.toolbar { display: flex; gap: 20px; margin-top: 20px; }
.btn-large { flex: 1; height: 52px; border-radius: 12px; border: none; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; color: white; transition: all 0.1s ease; }
.btn-large:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
.btn-pdf { background: #94a3b8; }
.btn-print { background: #147a61; }
.btn-reset { background: white; color: #64748b; border: 1px solid #cbd5e1; }
.btn-reset:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-large:disabled { opacity: 0.3; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

#previewGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; margin-top: 20px; }
.preview-page { background: white; position: relative; box-shadow: 0 15px 35px rgba(0,0,0,0.2); margin: 0 auto; overflow: hidden; transition: transform 0.1s ease; }
.preview-page:hover { transform: translateY(-5px); box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.v-page { aspect-ratio: 210/297; width: 100%; } 
.h-page { aspect-ratio: 297/210; width: 100%; } 

.line-h, .line-v { position: absolute; pointer-events: none; z-index: 10; display: none; border: none;}
.line-h { border-top: 0.5px dashed #e67e22; top: 50%; left: 0; width: 100%;}
.line-v { border-left: 0.5px dashed #e67e22; left: 50%; top: 0; height: 100%;}
.show-lines .line-h { display: block;}
.show-lines.h-page .line-v { display: block;}

.slot { position: absolute; display: flex; align-items: center; justify-content: center; box-sizing: border-box;}
.slot img { width: 100%; height: 100%; object-fit: contain; display: block;}

.browser-warning { position: fixed; top: 0; left: 0; width: 100%; background: #ffcc00; color: #333; padding: 10px 15px; text-align: center; font-size: 14px; font-weight: 500; z-index: 9999; display: none; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
.browser-warning-content { max-width: 1050px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; }
.browser-warning-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #333; padding: 0 10px; }

.print-dialog { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); display: none; justify-content: center; align-items: center; z-index: 1000; }
.print-dialog-content { background: white; padding: 30px; border-radius: 12px; max-width: 500px; width: 90%; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.print-dialog h3 { color: #2c3e50; margin-bottom: 15px; font-size: 20px; text-align: center; }
.print-dialog p { color: #576574; margin-bottom: 10px; line-height: 1.5; }
.print-dialog strong { color: #e67e22; }
.print-dialog-buttons { display: flex; gap: 15px; margin-top: 25px; }
.print-dialog-btn { flex: 1; padding: 12px; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: all 0.2s ease; }
.print-dialog-confirm { background: #147a61; color: white; }
.print-dialog-confirm:hover { background: #0d5d49; }
.print-dialog-cancel { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }
.print-dialog-cancel:hover { background: #e2e8f0; }
.print-tip { margin-top: 10px; font-size: 13px; color: #94a3b8; font-style: italic; }

.help-dialog { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); display: none; justify-content: center; align-items: center; z-index: 1001; }
.help-dialog-content { background: white; padding: 30px; border-radius: 12px; max-width: 700px; width: 90%; max-height: 80vh; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,0.3); position: relative; }
.help-close { position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 28px; cursor: pointer; color: #64748b; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; }
.help-close:hover { background: #f1f5f9; color: #2c3e50; }
.help-dialog h2 { color: #2c3e50; margin-bottom: 20px; font-size: 24px; text-align: center; padding-right: 30px; }
.help-section { margin-bottom: 20px; }
.help-section h3 { color: #147a61; font-size: 18px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.help-section p { color: #576574; line-height: 1.6; margin-bottom: 8px; padding-left: 28px; }
.help-tip { background: rgba(20, 122, 97, 0.1); border-left: 3px solid #147a61; padding: 10px 15px; margin: 15px 0; border-radius: 0 6px 6px 0; font-size: 14px; }

.footer { width: 100%; max-width: 1050px; text-align: center; padding: 15px 0; color: #64748b; font-size: 14px; margin-top: 20px; }
.footer a { color: #147a61; text-decoration: none; font-weight: 600; transition: color 0.2s ease; }
.footer a:hover { color: #0d5d49; text-decoration: underline; }

/* Toast 通知样式 */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: white;
    border-radius: 8px;
    padding: 14px 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 280px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toastSlideIn 0.3s ease-out;
    pointer-events: auto;
    border-left: 4px solid #4a6d7c;
}

.toast.toast-success {
    border-left-color: #6b9c70;
}

.toast.toast-warning {
    border-left-color: #e67e22;
}

.toast.toast-error {
    border-left-color: #e74c3c;
}

.toast.toast-info {
    border-left-color: #3498db;
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
    font-size: 14px;
    color: #2c3e50;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    font-size: 18px;
    color: #94a3b8;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.toast-close:hover {
    color: #64748b;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.fade-out {
    animation: toastSlideOut 0.3s ease-in forwards;
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@media (max-width: 768px) {
    .file-name { max-width: 120px; font-size: 9px; }
    .file-status { font-size: 8px; padding: 1px 4px; }
    .help-dialog-content { padding: 20px; max-height: 85vh; }
    .header h1 { font-size: 20px; }
    .help-btn, .home-btn, .invoice-btn { width: 32px; height: 32px; font-size: 16px; }
    .home-btn { right: 76px; }
    .invoice-btn { right: 38px; }
    .toast-container { top: 10px; right: 10px; left: 10px; }
    .toast { min-width: auto; max-width: 100%; }
}

@media print {
    /* 1. 根环境重置: 强制清空 html 和 body 的所有空间占用 */
    html, body {
        padding: 0 !important;
        margin: 0 !important;
        background: white !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* 2. 物理隐藏: 用 display:none 彻底移除所有非打印元素 */
    .header, .top-layout, .toolbar, .footer, .print-dialog, .help-dialog, .browser-warning {
        display: none !important;
    }

    /* 3. 逐层清零: 将父容器的边距和内边距全部归零 */
    .main-card {
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: none !important;
        width: 100% !important;
        max-width: none !important;
    }

    /* 4. 打印主体: 确保 #previewGrid 是一个简单的块级元素 */
    #previewGrid {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    /* 5. 打印页面本身: 尺寸、分页和装饰 */
    .preview-page {
        margin: 0 auto !important; /* 页面居中 */
        border: none !important;
        box-shadow: none !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        overflow: hidden !important;
    }

    /* 6. 负向高度容错: 为浏览器渲染提供安全边际 */
    body.mode-2 .preview-page {
        width: 210mm !important;
        height: 296.5mm !important;
    }

    body.mode-4 .preview-page {
        width: 297mm !important;
        height: 209.5mm !important;
    }
    /* 7. 精准分页: 只在非最后一页后分页 */
.preview-page:not(:last-child) {
    page-break-after: always !important;
}

    /* 8. @page 规则: 通用设置（方向由 JavaScript 动态设置） */
    @page {
        margin: 0;
        size: A4 landscape;
    }
}