* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #eef1f5;
    --sidebar-bg: #ffffff;
    --border: #e2e5ea;
    --primary: #4f6ef7;
    --primary-hover: #6b85f9;
    --primary-light: #eef1ff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-hint: #9ca3af;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.07);
}

html { height: 100%; }

body {
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

/* 外层容器限制最大宽度 */
.app-wrapper {
    display: flex;
    width: 100%;
    max-width: 960px;
    height: 100%;
    background: var(--sidebar-bg);
    box-shadow: 0 0 40px rgba(0,0,0,0.06);
    padding-top: 44px;
}

/* ===== 左侧面板 ===== */
.sidebar {
    width: 380px;
    min-width: 320px;
    max-width: 420px;
    height: 100%;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    -webkit-overflow-scrolling: touch;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #b0b5bd; }

h1 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text);
    letter-spacing: -0.3px;
}

/* ===== 标签 ===== */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 14px;
    background: #f3f4f6;
    border-radius: var(--radius);
    padding: 3px;
}

.tab {
    flex: 1;
    padding: 7px 0;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.tab:hover { color: var(--text); }
.tab.active {
    background: #fff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

/* ===== 面板 ===== */
.panel { display: none; }
.panel.active { display: flex; flex-direction: column; gap: 2px; }

/* ===== 表单 ===== */
.form-group { margin-bottom: 8px; flex: 1; min-width: 0; }

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group label input[type="checkbox"] {
    margin-right: 4px;
    vertical-align: middle;
    accent-color: var(--primary);
}

.form-row { display: flex; gap: 8px; }

/* 兼容旧浏览器 flex-wrap */
@supports not (gap: 8px) {
    .form-row > * { margin-right: 8px; }
    .form-row > *:last-child { margin-right: 0; }
}

input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
    color: var(--text);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

textarea { resize: vertical; }

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,110,247,0.1);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M3 4.5L6 8l3-3.5H3z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

input[type="color"] {
    width: 100%;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
    background: #fff;
}

input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    margin-top: 6px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="file"] {
    width: 100%;
    font-size: 12px;
    padding: 4px 0;
    color: var(--text-secondary);
}

input[type="file"]::-webkit-file-upload-button {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #f9fafb;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    margin-right: 8px;
    transition: background 0.15s;
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: #f3f4f6;
}

/* 自定义文件选择按钮 */
.file-hidden { display: none; }

.file-btn {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f9fafb;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-btn:hover {
    background: #f3f4f6;
    border-color: var(--primary);
}

.file-btn.has-file {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}

fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 6px;
}

fieldset legend {
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
    padding: 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hint {
    display: block;
    font-size: 11px;
    color: var(--primary);
    margin-top: 3px;
    line-height: 1.3;
}

/* ===== 按钮 ===== */
.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--sidebar-bg) 80%, transparent);
    padding: 14px 0 4px;
    z-index: 2;
}

.btn {
    flex: 1;
    padding: 9px 0;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--primary);
    color: #fff;
}

.btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(79,110,247,0.3); }
.btn:active { transform: translateY(0); }

.btn-secondary {
    background: #fff;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-secondary:hover { background: var(--primary-light); box-shadow: none; }

/* ===== 右侧预览区 ===== */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: #f8f9fb;
    border-left: 1px solid var(--border);
    overflow: auto;
}

.preview-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.preview {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 160px;
    min-height: 160px;
}

.preview canvas, .preview svg, .preview img {
    display: block;
    max-width: 100%;
    height: auto;
}

.hidden { display: none !important; }

/* ===== 响应式 ===== */
@media (max-width: 860px) {
    body {
        flex-direction: column;
        height: auto;
        overflow: auto;
    }
    .app-wrapper {
        flex-direction: column;
        max-width: none;
        height: auto;
    }
    .sidebar {
        width: 100%;
        min-width: 0;
        max-width: none;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .preview-area {
        padding: 24px 16px;
        min-height: 280px;
        border-left: none;
    }
    .preview-card {
        padding: 24px;
        width: 100%;
        max-width: 400px;
    }
}

@media (max-width: 480px) {
    .sidebar { padding: 14px; }
    .form-row { flex-direction: column; gap: 0; }
    .preview-area { padding: 16px; }
    .preview-card { padding: 16px; border-radius: 12px; }
}
