:root {
    --radius: 8px;
    --transition: 0.2s ease;
    --error: #f44;
}
/* 默认暗色（Black/theme1） */
[data-theme="dark"], :root {
    --bg: #1e1e1e;
    --panel-bg: #252525;
    --border: #3a3a3a;
    --text: #ddd;
    --text-dim: #999;
    --accent: #4f8ff7;
    --accent-hover: #6aa2ff;
    --accent-bg: rgba(79, 143, 247, 0.16);
    --bg-preview: #2a2a2a;
    --border-dashed: #4a4a4a;
    --text-placeholder: #777;
    --border-light: #555;
    --input-bg: #1a1a1a;
    --hover: #333;
}
/* 亮色（Silver/theme0） */
[data-theme="light"] {
    --bg: #e8e8e8;
    --panel-bg: #f5f5f5;
    --border: #d0d0d0;
    --text: #2a2a2a;
    --text-dim: #777;
    --accent: #2561c0;
    --accent-hover: #1e50a8;
    --accent-bg: rgba(53, 120, 229, 0.15);
    --bg-preview: #ddd;
    --border-dashed: #c4c4c4;
    --text-placeholder: #aaa;
    --border-light: #ccc;
    --input-bg: #fff;
    --hover: #e2e2e2;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }

/* ── 主布局 ── */
.layout {
    display: flex;
    width: 100%; height: 100%;
}

/* ── Photopea 区域 ── */
.main-area {
    flex: 1;
    min-width: 0;
    position: relative;
    background: var(--bg);
}
#photopea-frame {
    width: 100%; height: 100%;
    border: none;
    display: block;
}

/* ── 加载遮罩 ── */
.loading-overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); z-index: 10;
    transition: opacity 0.4s;
}
.loading-overlay.hidden {
    opacity: 0; pointer-events: none;
}
.loading-spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── AI 面板（浮动弹出窗）── */
.ai-panel {
    position: fixed;
    top: 10%; bottom: 10%; right: 16px;
    width: 360px;
    min-width: 280px;
    max-width: 600px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.45);
    display: flex;
    flex-direction: column;
    transition: opacity 0.25s, transform 0.25s, box-shadow 0.25s;
    overflow: hidden;
    z-index: 1000;
}
.ai-panel.collapsed {
    opacity: 0; pointer-events: none;
    transform: scale(0.92);
    box-shadow: none;
}

/* ── 面板标题栏 ── */
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 52px;
    cursor: grab;
    user-select: none;
}
.panel-header:active { cursor: grabbing; }
.panel-header h2 {
    font-size: 15px; font-weight: 600;
    display: flex; align-items: center; gap: 8px;
}
.panel-header h2 .icon { font-size: 18px; }
.panel-header .badge {
    font-size: 10px; background: var(--accent-bg);
    color: var(--accent); padding: 3px 8px; border-radius: 10px;
    font-weight: 600; opacity: 0.85;
}
.panel-close-btn {
    width: 28px; height: 28px; border-radius: 6px;
    border: none; background: transparent;
    color: var(--text-dim); font-size: 14px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: color var(--transition), background var(--transition);
}
.panel-close-btn:hover { color: var(--text); background: var(--hover); }

/* ── 本地上传按钮（优雅的圆形 + 号）── */
.local-upload-btn {
    width: 36px; height: 36px; border-radius: 50%;
    border: 2px dashed var(--border);
    background: transparent;
    color: var(--text-dim);
    font-size: 20px; line-height: 1;
    cursor: pointer; display: inline-flex;
    align-items: center; justify-content: center;
    transition: all 0.2s;
}
.local-upload-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(99,102,241,0.08);
}

/* ── 面板拉伸手柄 ── */
.rsz-handle {
    position: absolute; z-index: 2;
    transition: background 0.15s;
}
.rsz-r {
    right: 0; top: 0; width: 5px; height: 100%;
    cursor: ew-resize;
}
.rsz-r:hover, .rsz-r:active {
    background: var(--accent); opacity: 0.5;
}
.rsz-b {
    left: 0; bottom: 0; width: 100%; height: 5px;
    cursor: ns-resize;
}
.rsz-b:hover, .rsz-b:active {
    background: var(--accent); opacity: 0.5;
}
.rsz-br {
    right: 0; bottom: 0; width: 14px; height: 14px;
    cursor: nwse-resize;
}
.rsz-br:hover, .rsz-br:active {
    background: var(--accent); opacity: 0.5;
    border-radius: 0 0 10px 0;
}

/* ── 标签切换 ── */
.tabs {
    display: flex; flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    padding: 0;
    overflow-x: auto; overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
.tabs:hover { scrollbar-color: var(--border-light) transparent; }
.tabs::-webkit-scrollbar { height: 3px; }
.tabs::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.tabs:hover::-webkit-scrollbar-thumb { background: var(--border-light); }
.tab {
    padding: 10px 14px; font-size: 13px; color: var(--text-dim);
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition);
    white-space: nowrap; flex-shrink: 0;
}
.tab:first-child { margin-left: 16px; }
.tab:last-child { margin-right: 16px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── 面板内容区 ── */
.panel-body {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 16px;
}

/* ── AI 面板底部 ── */
.panel-footer {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--panel-bg);
    font-size: 12px;
    display: flex; flex-wrap: wrap; gap: 4px 6px;
    justify-content: center; align-items: center;
}
.panel-footer-info {
    display: flex; flex-wrap: wrap; gap: 4px 6px;
    justify-content: center;
}
.panel-footer-info a {
    color: var(--text-dim); text-decoration: none;
    cursor: pointer; transition: color 0.2s;
    white-space: nowrap;
}
.panel-footer-info a:hover { color: var(--accent); }
.panel-footer-info .divider {
    color: var(--border-dashed); user-select: none;
}
.panel-footer-copy {
    color: var(--text-dim);
    font-size: 11px; letter-spacing: 0.5px;
    white-space: nowrap;
}

/* ── 信息内容弹窗 ── */
.info-popup-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 400;
    align-items: center; justify-content: center;
}
.info-popup-overlay.show { display: flex; }
.info-popup {
    background: var(--panel-bg); border: 1px solid var(--border);
    border-radius: 12px; width: 420px; max-width: 92vw;
    max-height: 80vh; display: flex; flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: confirmIn 0.2s ease;
}
.info-popup-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px 10px; border-bottom: 1px solid var(--border);
}
.info-popup-header h4 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.info-popup-close {
    background: none; border: none; color: var(--text-dim);
    font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.info-popup-close:hover { color: var(--text); }
.info-popup-body {
    padding: 16px 20px 20px; overflow-y: auto; flex: 1;
    font-size: 13px; color: var(--text); line-height: 1.7;
    white-space: pre-wrap; word-break: break-word;
}
.tab-content { display: none; }
.tab-content.active { display: flex; flex-direction: column; gap: 16px; }

/* ── 表单元素 ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 12px; color: var(--text-dim);
    font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group textarea, .form-group input, .form-group select {
    background: var(--input-bg); border: 1px solid var(--border);
    color: var(--text); padding: 10px 12px; border-radius: var(--radius);
    font-size: 13px; outline: none; font-family: inherit;
    resize: vertical;
    transition: border-color var(--transition);
}
.form-group textarea:focus, .form-group input:focus, .form-group select:focus {
    border-color: var(--accent);
}
.form-group textarea { min-height: 80px; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

/* 公开/私密切换开关 */
.visibility-row {
    display: flex; align-items: center; gap: 8px;
    margin-top: 8px; font-size: 12px;
    color: var(--text-dim);
}
.vis-label { user-select: none; }
.toggle-switch {
    position: relative; display: inline-block;
    width: 40px; height: 22px; flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--border); border-radius: 22px;
    cursor: pointer; transition: background 0.2s;
}
.toggle-slider::before {
    content: ''; position: absolute;
    width: 16px; height: 16px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

.svc-desc {
    font-size: 12px; color: var(--text-dim); line-height: 1.6;
    background: rgba(255,255,255,0.03); border: 1px dashed var(--border);
    border-radius: var(--radius); padding: 10px 14px;
    white-space: pre-wrap; word-break: break-word;
}

/* ── 按钮 ── */
.btn {
    padding: 10px 18px; border: none; border-radius: var(--radius);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background var(--transition), transform 0.1s;
    display: flex; align-items: center; justify-content: center;
    gap: 6px;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
    opacity: 0.5; cursor: not-allowed;
}
.btn-outline {
    background: transparent; color: var(--accent);
    border: 1px solid var(--accent);
}
.btn-outline:hover { background: var(--accent-bg); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* ── 结果展示 ── */
.result-area {
    display: none;
    flex-direction: column; gap: 10px;
}
.result-area.show { display: flex; }
.result-img {
    max-width: 100%; max-height: 260px;
    width: auto; border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer; object-fit: contain;
    display: block; margin: 0 auto;
}
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── 选区信息 ── */
.selection-info {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.info-row span:first-child {
    color: var(--text-dim);
}
.info-row span:last-child {
    color: var(--accent);
    font-weight: 600;
    font-family: "SF Mono", "Cascadia Code", monospace;
}
.no-selection-hint {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.8;
}
.no-selection-hint .icon-big {
    font-size: 36px;
    display: block;
    margin-bottom: 10px;
}
.sel-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.sel-status.active {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
}
.sel-status.empty {
    background: rgba(255, 152, 0, 0.15);
    color: #ff9800;
}

/* ── 图像参考区（source-preview 布局，参考 tutu_Aiedit-53）── */
.source-preview {
    width: 100%;
    min-height: 90px;
    background: var(--bg-preview);
    border: 1px dashed var(--border-dashed);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    overflow: hidden;
    position: relative;
    transition: border-color 0.15s;
}
.source-preview:hover { border-color: var(--accent); }
.source-preview .placeholder {
    color: var(--text-placeholder);
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    padding: 12px;
    line-height: 1.5;
}

/* ── 缩略图列表 ── */
.thumb-list { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; width: 100%; }
.thumb-list:empty { display: none; }
.thumb-item {
    position: relative;
    width: 66px;
    height: 90px;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid var(--border);
    flex-shrink: 0;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    user-select: none;
    background: var(--bg-preview);
}
.thumb-item:hover { border-color: var(--border-light); }
.thumb-item.active {
    border: 2px solid var(--accent);
    box-shadow: 0 0 8px rgba(79,143,247,0.45);
}
.thumb-item img { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--input-bg); pointer-events: none; }
.thumb-item .thumb-idx {
    position: absolute;
    top: 2px; left: 2px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 11px; font-weight: 600;
    border-radius: 2px;
    padding: 1px 4px;
    pointer-events: none;
    line-height: 16px;
}
.thumb-item .thumb-del {
    position: absolute;
    top: 2px; right: 2px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    border-radius: 2px;
    width: 18px; height: 18px;
    font-size: 11px; font-weight: bold;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 3;
    transition: background 0.15s;
}
.thumb-item:hover .thumb-del,
.thumb-item .thumb-del:hover { display: flex; }
.thumb-item .thumb-del:hover { background: rgba(200,60,60,0.8); }
.thumb-item .thumb-move {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    opacity: 0;
    transition: opacity 0.15s;
}
.thumb-item:hover .thumb-move { opacity: 1; }
.thumb-item .thumb-up,
.thumb-item .thumb-down {
    width: 18px; height: 18px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    font-size: 11px; font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    padding: 0;
    transition: background 0.15s;
}
.thumb-item .thumb-up:hover,
.thumb-item .thumb-down:hover { background: rgba(90,143,199,0.8); }
.thumb-add {
    width: 66px; height: 90px;
    border-radius: 4px;
    border: 1px dashed var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    background: var(--bg-preview);
    transition: all 0.15s;
    font-size: 18px;
    color: var(--text-placeholder);
    user-select: none;
}
.thumb-add:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.thumb-add:disabled { opacity: 0.3; cursor: not-allowed; }

.thumb-gallery-actions {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}
.thumb-gallery-actions .btn-mini {
    font-size: 10px;
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
}
.thumb-gallery-actions .btn-mini:hover {
    color: var(--error);
    border-color: var(--error);
}


/* ── 参考图状态提示 ── */
.section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── 余额 ── */
.balance-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--accent-bg);
    border-radius: var(--radius);
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.balance-label {
    font-size: 12px;
    color: var(--text-dim);
}
.balance-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    min-width: 36px;
    text-align: right;
}
.balance-unit {
    font-size: 12px;
    color: var(--text-dim);
}
.balance-recharge {
    display: none;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
}
.balance-recharge.show {
    display: flex;
}
.recharge-input {
    width: 70px;
    padding: 4px 8px;
    font-size: 13px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    text-align: center;
}
.recharge-pin {
    width: 80px;
    padding: 4px 8px;
    font-size: 13px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    text-align: center;
}
.btn-recharge {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    white-space: nowrap;
    transition: background var(--transition);
}
.btn-recharge:hover {
    background: var(--accent-hover);
}
.btn-recharge-toggle {
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    white-space: nowrap;
    margin-left: auto;
}
.btn-recharge-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── 状态提示 ── */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    padding: 10px 20px; border-radius: 20px; font-size: 13px;
    background: var(--panel-bg); color: var(--text); z-index: 100;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}
.toast.show { opacity: 1; }
.toast.error { background: #522; color: #f88; }

/* ── 自定义滚动条 ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-dashed); }

/* ── 响应式 ── */
@media (max-width: 768px) {
    .ai-panel { width: 100%; max-width: 100%; position: fixed; right: 0; top: 0; bottom: 0; z-index: 50; }
    .ai-panel.collapsed { width: 0; }
}

/* ── 模板选择区 ── */
.template-section {
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    padding: 0;
    max-height: 450px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.template-section.collapsed {
    max-height: 32px;
}
.template-section:not(.collapsed) {
    overflow: hidden;
}
.template-section:not(.collapsed) #templateCards {
    max-height: 400px;
    overflow-y: auto;
}
.template-section-header {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; margin-bottom: 8px;
    user-select: none;
}
.template-section-title {
    font-size: 12px; color: var(--text-dim);
    font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex; align-items: center; gap: 6px;
}
.template-section-toggle {
    font-size: 11px; color: var(--text-dim);
    transition: transform 0.3s;
}
.template-section.collapsed .template-section-toggle {
    transform: rotate(-90deg);
}
.template-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    padding-bottom: 6px;
}
.template-cards::-webkit-scrollbar { height: 4px; }
.template-cards::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }
.template-card {
    flex-shrink: 0; width: 80px;
    cursor: pointer; border-radius: 6px;
    overflow: hidden; border: 2px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--input-bg);
}
.template-card:hover {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(79,143,247,0.25);
}
.template-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(79,143,247,0.4);
}
.template-card-img {
    width: 100%; height: 107px;
    object-fit: cover; display: block;
    background: var(--bg-preview);
}
.tpl-card-hover-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.2s;
    pointer-events: none; z-index: 1;
}
.tpl-card-hover-overlay span {
    color: #fff; font-size: 12px; font-weight: 500;
    padding: 4px 12px; border: 1px solid rgba(255,255,255,0.6);
    border-radius: 4px;
}
.template-card:hover .tpl-card-hover-overlay { opacity: 1; }
.template-card-img-placeholder {
    width: 100%; height: 107px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; background: var(--bg-preview);
    color: var(--text-dim);
}
.template-card-name {
    font-size: 10px;
    color: var(--text);
    text-align: center;
    padding: 3px 2px;
    line-height: 1.3;
    max-height: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-all;
}
.tpl-card-badge {
    position: absolute; left: 2px;
    font-size: 9px; padding: 1px 5px; border-radius: 3px;
    line-height: 1.4; pointer-events: none;
    z-index: 2;
}
.badge-official { 
    top: 2px; 
    background: #4dabf7; color: #fff; 
}
.badge-pending { 
    top: 18px; 
    background: #f0ad4e; color: #fff; 
}
.badge-rejected { 
    top: 18px; 
    background: #d9534f; color: #fff; 
}
.badge-share { 
    top: 2px; 
    background: #51cf66; color: #fff; 
}
.tpl-card-edit {
    position: absolute; top: 0; right: 0;
    width: 22px; height: 22px; font-size: 13px; line-height: 22px;
    text-align: center; background: rgba(52,152,219,0.85); color: #fff;
    border-radius: 0 4px 0 0; cursor: pointer;
    z-index: 2; display: none;
}
.edit-mode .tpl-card-edit { display: block; }
.edit-mode .tpl-card-edit:hover { background: rgba(52,152,219,1); }
.tpl-card-del {
    position: absolute; top: 22px; right: 0;
    width: 22px; height: 22px; font-size: 16px; line-height: 22px;
    text-align: center; background: rgba(220,53,69,0.85); color: #fff;
    border-radius: 0 0 4px 0; cursor: pointer;
    z-index: 2; display: none;
}
.edit-mode .tpl-card-del { display: block; }
.edit-mode .tpl-card-del:hover { background: rgba(220,53,69,1); }
.template-cat-tabs {
    display: flex; gap: 4px; margin-bottom: 8px;
    overflow-x: auto; padding-bottom: 2px;
}
.template-cat-tabs::-webkit-scrollbar { height: 3px; }
.template-cat-tab {
    flex-shrink: 0; padding: 3px 10px;
    font-size: 11px; border-radius: 10px;
    cursor: pointer; white-space: nowrap;
    color: var(--text-dim); background: var(--input-bg);
    border: 1px solid var(--border);
    transition: all 0.2s;
}
.template-cat-tab:hover { border-color: var(--accent); color: var(--text); }
.template-cat-tab.active {
    background: var(--accent-bg); color: var(--accent);
    border-color: var(--accent);
}
.template-section-empty {
    text-align: center; color: var(--text-dim);
    font-size: 12px; padding: 12px 0;
}
.template-section-add {
    width: 24px; height: 24px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px; cursor: pointer; border: 1px dashed var(--border);
    color: var(--text-dim); font-size: 16px; line-height: 1;
    background: transparent; padding: 0;
    transition: all var(--transition);
    user-select: none; font-family: inherit;
}
.template-section-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.template-section-edit-mode {
    width: 24px; height: 24px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px; cursor: pointer; border: 1px dashed var(--border);
    color: var(--text-dim); font-size: 13px; line-height: 1;
    background: transparent; padding: 0;
    transition: all var(--transition);
    user-select: none; font-family: inherit;
}
.template-section-edit-mode:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.template-section-edit-mode.active {
    border-color: var(--accent); color: #fff; background: var(--accent);
}

/* ── 添加模板弹窗 ── */
.tpl-modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 250; align-items: center; justify-content: center;
}
.tpl-modal-overlay.show { display: flex; }
.tpl-modal {
    background: var(--panel-bg); border: 1px solid var(--border);
    border-radius: 12px; width: 360px; max-width: 90vw;
    padding: 20px; display: flex; flex-direction: column; gap: 14px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.tpl-modal h4 { font-size: 15px; font-weight: 600; margin: 0; }
.tpl-modal label {
    font-size: 12px; color: var(--text-dim); margin-bottom: -10px;
}
.tpl-modal input, .tpl-modal textarea, .tpl-modal select {
    width: 100%; padding: 8px 10px; border-radius: 6px;
    border: 1px solid var(--border); background: var(--input-bg);
    color: var(--text); font-size: 13px; outline: none;
}
.tpl-modal textarea { resize: vertical; min-height: 60px; max-height: 150px; }
.tpl-modal select { cursor: pointer; }
.tpl-modal input:focus, .tpl-modal textarea:focus, .tpl-modal select:focus { border-color: var(--accent); }
.tpl-modal-btns { display: flex; gap: 8px; justify-content: flex-end; }
.tpl-modal .btn-cancel {
    padding: 7px 18px; border-radius: 6px; font-size: 13px; cursor: pointer;
    border: 1px solid var(--border); background: transparent; color: var(--text-dim);
    transition: all var(--transition);
}
.tpl-modal .btn-cancel:hover { color: var(--text); border-color: var(--text-dim); }
.tpl-modal .btn-save {
    padding: 7px 18px; border-radius: 6px; font-size: 13px; cursor: pointer;
    border: none; background: var(--accent); color: #fff; font-weight: 600;
    transition: all var(--transition);
}
.tpl-modal .btn-save:hover { background: var(--accent-hover); }
.tpl-modal .tpl-error {
    font-size: 12px; color: var(--error); text-align: center; display: none;
}
.tpl-upload-area {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
}
.btn-upload-img {
    padding: 5px 12px; font-size: 12px; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--border); background: var(--input-bg);
    color: var(--text); transition: all var(--transition);
}
.btn-upload-img:hover { border-color: var(--accent); color: var(--accent); }

/* ── 用户区域（面板右上角）── */
.header-right {
    display: flex; align-items: center; gap: 8px; position: relative;
}
.header-user-icon {
    cursor: pointer; color: var(--text-dim); padding: 4px;
    border-radius: 50%; display: flex; align-items: center;
    transition: color var(--transition), background var(--transition);
}
.header-user-icon:hover { color: var(--accent); background: var(--accent-bg); }
.header-user-icon.logged-in { color: var(--accent); }
.header-user-name {
    font-size: 12px; color: var(--accent); font-weight: 600; cursor: pointer;
    max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-user-dropdown {
    display: none; position: absolute; top: 38px; right: 0;
    background: var(--panel-bg); border: 1px solid var(--border);
    border-radius: var(--radius); min-width: 150px; z-index: 100;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25); overflow: hidden;
}
.header-user-dropdown.show { display: block; }
.header-user-dropdown .dd-item {
    padding: 10px 16px; font-size: 13px; cursor: pointer; color: var(--text);
    transition: background var(--transition); display: flex; align-items: center; gap: 8px;
}
.header-user-dropdown .dd-item:hover { background: var(--hover); }
.header-user-dropdown .dd-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── 登录模态框 ── */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55);
    z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--panel-bg); border: 1px solid var(--border);
    border-radius: 12px; width: 380px; max-width: 90vw;
    padding: 24px; display: flex; flex-direction: column; gap: 18px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.modal h3 { font-size: 16px; font-weight: 600; text-align: center; margin-bottom: 4px; }
.modal .modal-tabs {
    display: flex; border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.modal .modal-tab {
    flex: 1; text-align: center; padding: 8px; font-size: 13px; cursor: pointer;
    color: var(--text-dim); border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition);
}
.modal .modal-tab:hover { color: var(--text); }
.modal .modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.modal .form-group { margin-bottom: 2px; }
.modal .form-group input {
    width: 100%; padding: 10px 12px; border-radius: 8px;
}
.modal .btn-full { margin-top: 6px; }
/* ── 自定义确认对话框 ── */
.confirm-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55);
    z-index: 300; align-items: center; justify-content: center;
}
.confirm-overlay.show { display: flex; }
.confirm-dialog {
    background: var(--panel-bg); border: 1px solid var(--border);
    border-radius: 12px; width: 320px; max-width: 90vw;
    padding: 28px 24px 20px; text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: confirmIn 0.2s ease;
}
@keyframes confirmIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.confirm-dialog .confirm-icon {
    width: 48px; height: 48px; margin: 0 auto 14px;
    border-radius: 50%; background: rgba(220,53,69,0.12);
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; color: #dc3545;
}
.confirm-dialog .confirm-msg {
    font-size: 14px; color: var(--text); margin-bottom: 20px;
    line-height: 1.5;
}
.confirm-dialog .confirm-btns {
    display: flex; gap: 10px; justify-content: center;
}
.confirm-dialog .confirm-btns button {
    padding: 8px 24px; border-radius: 8px; font-size: 13px;
    cursor: pointer; border: none; transition: all 0.2s;
}
.confirm-btn-cancel {
    background: var(--input-bg); color: var(--text);
}
.confirm-btn-cancel:hover { background: var(--border); }
.confirm-btn-danger {
    background: #dc3545; color: #fff;
}
.confirm-btn-danger:hover { background: #c82333; }

.modal .modal-footer-text {
    text-align: center; font-size: 12px; color: var(--text-dim);
}
.modal .modal-footer-text a {
    color: var(--accent); cursor: pointer; text-decoration: none;
}
.modal .modal-footer-text a:hover { text-decoration: underline; }
.modal .modal-close {
    position: absolute; top: 12px; right: 16px; cursor: pointer;
    font-size: 20px; color: var(--text-dim); background: none; border: none;
    line-height: 1;
}
.modal .modal-close:hover { color: var(--text); }
.modal .error-msg {
    font-size: 12px; color: var(--error); text-align: center; display: none;
}
.modal .error-msg.show { display: block; }
