* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
body {
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
    padding: 10px;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.45;
    margin: 0;
    overflow-x: hidden;
    min-height: 100vh;
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
}
.container {
    max-width: calc(100vw - 20px);
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(380px, 1fr) minmax(380px, 1fr);
    gap: 10px;
    padding: 0 4px;
}
.panel {
    background: white;
    border-radius: 6px;
    padding: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.form-panel {
    overflow-y: auto;
    max-height: calc(100vh - 24px);
    scrollbar-width: thin;
    scrollbar-color: #d0d0d0 #f1f1f1;
}
/* 美化滚动条 */
.form-panel::-webkit-scrollbar {
    width: 8px;
}
.form-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}
.form-panel::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 4px;
}
.form-panel::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}
.preview-panel::-webkit-scrollbar {
    width: 8px;
}
.preview-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}
.preview-panel::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 4px;
}
.preview-panel::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}
.preview-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: sticky;
    top: 10px;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #d0d0d0 #f1f1f1;
}
.preview-toolbar {
    width: 100%;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    background: #f7faff;
    border: 1px solid #d7e8ff;
    color: #1d5fbf;
    font-weight: 600;
    margin-bottom: 0;
}
.checkbox-inline input {
    width: auto;
    margin: 0;
}
.secondary-btn {
    background-color: #f5f5f5;
    color: #333;
    border: 1px solid #d9d9d9;
    box-shadow: none;
    margin-top: 0;
    padding: 8px 14px;
    font-size: 14px;
}
.secondary-btn:hover {
    background-color: #ffffff;
    color: #1890ff;
    border-color: #91caff;
    box-shadow: 0 2px 6px rgba(24, 144, 255, 0.15);
}
.preview-meta {
    width: 100%;
    margin-bottom: 8px;
}
.editor-hint,
.selected-field-info,
.asset-status {
    width: 100%;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.4;
}
.editor-hint {
    background: #fffbe6;
    border: 1px solid #ffe58f;
    color: #8c6d1f;
    margin-bottom: 10px;
}
.selected-field-info {
    background: #f7faff;
    border: 1px solid #d7e8ff;
    color: #1d5fbf;
    margin-bottom: 8px;
}
.asset-status {
    background: #fafafa;
    border: 1px solid #ececec;
    color: #666;
}

/* Electron 窗口专属优化 */
@media (min-width: 1000px) and (max-width: 1600px) {
    .container {
        gap: 10px;
    }
    .panel {
        padding: 13px;
    }
}
h2 {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    color: #333;
    font-size: 1.2rem;
}
.form-group {
    margin-bottom: 9px;
}
label {
    display: block;
    margin-bottom: 3px;
    font-weight: bold;
    color: #555;
    font-size: 13px;
    line-height: 1.3;
}
input, select, textarea {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.3;
    transition: border-color 0.3s;
}
input, select {
    height: 34px;
}
input:focus, select:focus, textarea:focus {
    border-color: #1890ff;
    outline: none;
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}
textarea {
    min-height: 68px;
    padding-top: 7px;
    padding-bottom: 7px;
    resize: vertical;
}
.btn {
    background-color: #1890ff;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 6px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn:hover {
    background-color: #40a9ff;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(24, 144, 255, 0.3);
}
.btn:active {
    transform: translateY(0);
}
#resultCanvas {
    max-width: 100%;
    width: auto;
    height: auto;
    max-height: calc(100vh - 200px);
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: block;
    margin: 0 auto;
    object-fit: contain;
}
.hidden {
    display: none;
}
.download-btn {
    margin-top: 12px;
    width: 100%;
    background-color: #52c41a;
    font-size: 15px;
    font-weight: bold;
    padding: 10px 18px;
    box-shadow: 0 2px 4px rgba(82, 196, 26, 0.3);
}
.download-btn:hover {
    background-color: #73d13d;
    box-shadow: 0 4px 8px rgba(82, 196, 26, 0.4);
    transform: translateY(-1px);
}
.download-btn:active {
    transform: translateY(0);
}
.section-header {
    margin-top: 12px;
    margin-bottom: 8px;
    background-color: #f0f7ff;
    padding: 6px 12px;
    border-radius: 4px;
    border-left: 3px solid #1890ff;
    font-weight: bold;
    font-size: 15px;
}
.quick-fill {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    align-items: center;
}
.quick-fill button {
    padding: 7px 12px;
    background-color: #f0f7ff;
    border: 1px solid #d9e8ff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: #1890ff;
    transition: all 0.3s;
    font-weight: 500;
}
.quick-fill button:hover {
    background-color: #e6f2ff;
    border-color: #1890ff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(24, 144, 255, 0.2);
}
.quick-fill button:active {
    transform: translateY(0);
}
#randomTemplateBtn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
#randomTemplateBtn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
    transform: translateY(-2px);
}

/* Electron 窗口优化布局 */
@media (max-width: 1200px) {
    .container {
        max-width: 100%;
        grid-template-columns: minmax(350px, 1fr) minmax(350px, 1fr);
        gap: 10px;
    }
    body {
        padding: 10px;
    }
}

/* 窗口最小尺寸适配 (1000px) */
@media (max-width: 1100px) {
    .container {
        grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
        gap: 10px;
    }
    .panel {
        padding: 12px;
    }
    body {
        padding: 10px;
    }
    h2 {
        font-size: 1.1rem;
    }
    .form-group {
        margin-bottom: 9px;
    }
}

/* ====== 移动端适配 (<=900px) ====== */
@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .form-panel {
        max-height: unset;
        overflow-y: visible;
    }
    .preview-panel {
        position: relative;
        top: 0;
        max-height: unset;
    }
    .form-row {
        grid-template-columns: 1fr 1fr;
    }
    .form-col {
        min-width: 0;
    }
    .panel {
        padding: 12px;
    }
}

/* ====== 手机端 (<=600px) ====== */
@media (max-width: 600px) {
    body {
        padding: 6px;
    }
    .container {
        gap: 8px;
    }
    .panel {
        padding: 10px;
        border-radius: 4px;
    }
    h2 {
        font-size: 1rem;
        margin-bottom: 10px;
    }
    /* 表单单列布局 */
    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .form-group {
        margin-bottom: 8px;
    }
    label {
        font-size: 12px;
        margin-bottom: 2px;
    }
    input, select, textarea {
        font-size: 16px; /* 防止 iOS 自动缩放 */
        height: 40px;   /* 触控友好最小 40px */
        padding: 8px 10px;
    }
    textarea {
        min-height: 72px;
    }
    .btn {
        min-height: 44px; /* Apple HIG 推荐最小触控区域 */
        font-size: 15px;
        border-radius: 6px;
    }
    .download-btn {
        padding: 14px 16px;
        font-size: 16px;
        margin-top: 10px;
        position: sticky;
        bottom: 0;
        z-index: 100;
    }
    .quick-fill {
        gap: 6px;
    }
    .quick-fill button {
        flex: 1;
        font-size: 13px;
        padding: 10px 8px;
        min-height: 40px;
    }
    .preview-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    .checkbox-inline {
        justify-content: center;
        padding: 10px 12px;
    }
    .secondary-btn {
        min-height: 38px;
    }
    .section-header {
        margin-top: 10px;
        margin-bottom: 6px;
        font-size: 14px;
        padding: 5px 10px;
    }
    #resultCanvas {
        max-height: calc(100vh - 60px);
        touch-action: pan-x pan-y;
    }
    #attachmentFields .form-col {
        flex: 1 1 100%;
    }
    .editor-hint,
    .selected-field-info,
    .asset-status {
        font-size: 11px;
        padding: 6px 8px;
    }
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* 表单分组 */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    margin-bottom: 4px;
}
.form-col {
    min-width: 0;
}

#attachmentFields {
    align-items: end;
}

#attachmentFields .form-group {
    margin-bottom: 6px;
}

#attachmentFields .form-col {
    display: flex;
}

#attachmentFields .form-group {
    width: 100%;
}
