@import "../../theme.css";

*, *::before, *::after { box-sizing: border-box; }
input, textarea, button, select { font-family: inherit; }

body { 
    margin: 0; padding: 16px; 
    background-color: var(--bg-main); 
    -webkit-font-smoothing: antialiased; 
    color: var(--text-primary); 
    height: 100vh; height: 100dvh; 
    overflow: hidden; letter-spacing: -0.01em; 
    width: 100%; max-width: 100%; overflow-x: hidden;
}

*:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }
input:focus, select:focus, button:focus { outline: none !important; }

.tool-wrapper { display: flex; flex-direction: column; height: 100%; gap: 12px; animation: fadeIn 0.3s ease; width: 100%; max-width: 100%; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: translateY(0); } }

.tool-header { display: flex; justify-content: space-between; align-items: center; }
.header-main h2 { font-size: 16px; font-weight: 600; margin: 0 0 4px 0; display: flex; align-items: center; gap: 8px;}
.header-main p { margin: 0; font-size: 12px; color: var(--text-secondary); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.workspace-grid { flex: 1; display: grid; grid-template-columns: 360px 1fr; gap: 14px; min-height: 0; width: 100%; }

.pane { 
    background-color: var(--bg-card) !important; 
    border: 1px solid var(--border-color); 
    border-radius: 12px; 
    padding: 16px; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    position: relative; 
    transition: border-color var(--transition-smooth), box-shadow var(--transition-smooth); 
    min-height: 0; 
    width: 100%; box-sizing: border-box;
}
.pane:focus-within { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--accent-tint); }
.pane-header { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }
.pane-title { font-size: 13px; font-weight: 600; color: var(--text-primary); flex: 1; }
.pane-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.config-pane { overflow-y: auto; padding-right: 8px; background-color: #F8FAFC; }
.config-pane::-webkit-scrollbar { width: 6px; }
.config-pane::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.1); border-radius: 3px; }
.config-form { display: flex; flex-direction: column; gap: 12px; flex: 1; width: 100%; }

.config-block { background-color: #FFF; border: 1px solid var(--border-color); border-radius: 8px; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.01); width: 100%; box-sizing: border-box; }
.block-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.param-desc { font-size: 11px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 2px; display: block; }
.ai-block { border-color: rgba(79, 70, 229, 0.3); background: linear-gradient(180deg, #F8FAFC 0%, #EEF2FF 100%); }

.form-row { display: flex; gap: 10px; width: 100%; }
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.form-group label { font-size: 11px; font-weight: 500; color: var(--text-secondary); }

.mode-selector { display: grid; grid-template-columns: repeat(3, 1fr); background-color: rgba(15, 23, 42, 0.03); border: 1px solid var(--border-color); padding: 2px; border-radius: 8px; gap: 2px; width: 100%; }
.mode-btn { background: none; border: none; padding: 8px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); border-radius: 6px; cursor: pointer; transition: all var(--transition-smooth); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; white-space: nowrap; }
.mode-btn:hover { color: var(--text-primary); }
.mode-btn.active { background-color: #FFFFFF; color: var(--accent-color); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

.tab-switcher { display: flex; background-color: rgba(15, 23, 42, 0.03); border: 1px solid var(--border-color); padding: 2px; border-radius: 8px; gap: 2px; width: 100%; }
.tab-btn { background: none; border: none; padding: 6px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); border-radius: 6px; cursor: pointer; transition: all var(--transition-smooth); display: flex; align-items: center; justify-content: center; flex: 1; white-space: nowrap; }
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { background-color: #FFFFFF; color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

.color-picker-wrap { display: flex; align-items: center; gap: 8px; background-color: #F8FAFC; border: 1px solid var(--border-color); border-radius: 6px; padding: 0 8px; height: 34px; box-sizing: border-box; }
.color-picker-wrap input[type="color"] { -webkit-appearance: none; border: none; width: 18px; height: 18px; border-radius: 4px; cursor: pointer; padding: 0; background: none; flex-shrink: 0; }
.color-picker-wrap input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker-wrap input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,0.15); border-radius: 4px; }
.color-val { font-size: 11px; color: var(--text-secondary); font-family: ui-monospace, monospace; text-transform: uppercase; font-weight: 500; }

.custom-input { background-color: #F8FAFC; border: 1px solid var(--border-color); border-radius: 6px; padding: 0 12px; font-size: 12px; color: var(--text-primary); height: 34px; transition: all var(--transition-smooth); width: 100%; box-sizing: border-box; font-family: inherit !important; }
.custom-input:focus { background-color: #FFF; border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--accent-tint); }

/* 💡 修复：补全坐标系统与绝对尺寸，确保下拉箭头不被拉伸变形 */
select.custom-input { 
    cursor: pointer; 
    -webkit-appearance: none; appearance: none; 
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='14' height='14' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); 
    background-repeat: no-repeat; background-position: right 12px center; 
    padding-right: 36px !important; 
}

.slider-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.slider-val { font-size: 11px; font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; color: var(--accent-color); font-weight: 600; background: var(--accent-tint); padding: 2px 6px; border-radius: 4px; }
input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; margin: 6px 0; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 14px; width: 14px; border-radius: 50%; background: var(--accent-color); cursor: pointer; margin-top: -5px; box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: transform 0.1s; }
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.2); }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: var(--border-color); border-radius: 2px; }

.btn { box-sizing: border-box; border: 1px solid var(--border-color); border-radius: 6px; cursor: pointer; font-weight: 500; transition: all var(--transition-smooth); background-color: #FFF; color: var(--text-primary); display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap; font-family: inherit !important; overflow: hidden; text-overflow: ellipsis; }
.btn-sm { height: 26px; padding: 0 10px; font-size: 11px; }
.btn-md { height: 32px; padding: 0 14px; font-size: 12px; }
.btn-muted { border-color: var(--border-color); color: var(--text-secondary); }
.btn-muted:hover { background-color: var(--bg-active-hover); color: var(--text-primary); }
.btn-primary { background-color: var(--accent-color); color: #FFF; border-color: var(--accent-color); }
.btn-primary:hover { opacity: 0.95; transform: translateY(-1px); }
.btn:active { transform: scale(0.97); }

.btn-generate-action {
    width: 100% !important;
    height: 46px !important; 
    font-size: 14px !important; 
    font-weight: 600 !important;
    letter-spacing: 0.8px !important;
    border-radius: 8px !important;
    border: none !important;
    background-color: var(--accent-color) !important;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.18) !important;
    transition: all var(--transition-smooth) !important;
    margin-top: auto !important;
    margin-bottom: 4px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; 
}
.btn-generate-action:hover { box-shadow: 0 6px 20px rgba(79, 70, 229, 0.3) !important; transform: translateY(-1px); background-color: #4338CA !important; }
.btn-generate-action:active { transform: scale(0.985); }
.btn-generate-action:disabled { background-color: var(--text-muted) !important; box-shadow: none !important; cursor: not-allowed; transform: none; }

.badge { font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; letter-spacing: 0.05em; }
.badge-slate { background-color: var(--bg-active); color: var(--text-secondary); }
.badge-indigo { background-color: var(--accent-tint); color: var(--accent-color); }

.preview-pane { padding: 0; overflow: hidden; border: 2px dashed transparent; transition: border-color var(--transition-smooth), background-color var(--transition-smooth); width: 100%; box-sizing: border-box; }
.preview-pane.drag-over { border-color: var(--accent-color); background-color: var(--accent-tint); }

.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 20px; pointer-events: none; z-index: 5; }
.empty-icon { color: var(--text-muted); opacity: 0.6; margin-bottom: 16px; }
.empty-state h3 { margin: 0 0 8px 0; font-size: 14px; color: var(--text-primary); font-weight: 600; }
.empty-state p { margin: 0; font-size: 12px; color: var(--text-secondary); max-width: 300px; line-height: 1.6; }

.checkerboard { 
    background-color: #F8FAFC; 
    background-image: linear-gradient(45deg, #E2E8F0 25%, transparent 25%), linear-gradient(-45deg, #E2E8F0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #E2E8F0 75%), linear-gradient(-45deg, transparent 75%, #E2E8F0 75%); 
    background-size: 20px 20px; 
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px; 
}

.stitch-workspace { display: flex; height: 100%; width: 100%; padding-top: 48px; box-sizing: border-box; }
.sortable-list-container { width: 280px; display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; border-right: 1px solid var(--border-color); padding: 0 12px 16px 16px; }
.sortable-list-container::-webkit-scrollbar { width: 6px; }
.sortable-list-container::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.1); border-radius: 3px; }

.sortable-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.list-item { background: #FFF; border: 1px solid var(--border-color); border-radius: 8px; padding: 8px; display: flex; align-items: center; gap: 10px; cursor: grab; transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.02); width: 100%; box-sizing: border-box; }
.list-item:hover { border-color: var(--accent-color); box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1); }
.list-item.dragging { opacity: 0.8; box-shadow: 0 8px 24px rgba(0,0,0,0.15); transform: scale(1.02); z-index: 10; border-color: var(--accent-color); }
.item-drag-handle { color: var(--text-muted); cursor: grab; padding: 0 2px; }
.item-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid rgba(0,0,0,0.05); background: #F8FAFC; flex-shrink: 0; }
.item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.item-name { font-size: 12px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 10px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.item-remove { background: none; border: none; color: #EF4444; cursor: pointer; padding: 6px; border-radius: 6px; display: flex; align-items: center; justify-content: center; opacity: 0.6; transition: opacity 0.2s, background 0.2s; flex-shrink: 0; }
.item-remove:hover { opacity: 1; background: #FEF2F2; }

.canvas-preview-area { flex: 1; overflow: auto; display: flex; padding: 20px; align-items: flex-start; justify-content: center; border-radius: 0 0 12px 0; -webkit-overflow-scrolling: touch; }
.canvas-wrapper { box-shadow: 0 4px 24px rgba(0,0,0,0.1); transition: transform 0.2s; position: relative; }
#stitchCanvas { display: block; max-width: none; }

.grid-preview-box { position: relative; max-width: 90%; max-height: 90%; }
.grid-preview-box img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; border-radius: 6px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); }
.grid-lines-overlay { position: absolute; inset: 0; pointer-events: none; border-radius: 6px; overflow: hidden; }
.grid-line-h { position: absolute; left: 0; right: 0; height: 1px; background: rgba(255,255,255,0.9); box-shadow: 0 0 4px rgba(0,0,0,0.6); z-index: 2; transition: top 0.3s; }
.grid-line-v { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.9); box-shadow: 0 0 4px rgba(0,0,0,0.6); z-index: 2; transition: left 0.3s; }

.processing-overlay { position: absolute; inset: 0; background-color: rgba(255,255,255,0.85); backdrop-filter: blur(2px); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 200; gap: 12px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border-color); border-top-color: var(--accent-color); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-text { font-size: 13px; font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }

.toast-notification { 
    position: fixed; top: -50px; left: 50%; transform: translateX(-50%); 
    background-color: rgba(15, 23, 42, 0.95); color: #FFF; padding: 10px 20px; 
    border-radius: 8px; font-size: 13px; font-weight: 500; 
    box-shadow: 0 6px 20px rgba(0,0,0,0.15); z-index: 9999; display: flex; 
    align-items: center; gap: 8px; opacity: 0; transition: top 0.4s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.4s ease; 
    pointer-events: none; max-width: 85vw; white-space: normal; word-break: break-all; line-height: 1.5;
}
.toast-notification.show { top: 20px; opacity: 1; }

@media (max-width: 850px) {
    body { padding: 8px; overflow-y: auto; height: auto; overflow-x: hidden; }
    /* 锁定字体防缩放 */
    input, textarea, select { font-size: 16px !important; }
    
    .tool-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .header-main h2 { font-size: 15px; }

    .header-actions { display: flex; flex-direction: row; flex-wrap: wrap; width: 100%; margin-top: 4px; gap: 8px; }
    .header-actions .btn { flex: 1; height: 38px; font-size: 12px; min-width: calc(33.33% - 8px); padding: 0 6px; }

    .workspace-grid { grid-template-columns: 1fr; height: auto; gap: 10px; display: flex; flex-direction: column-reverse; } 
    
    .config-pane { min-height: auto; padding: 16px; border-radius: 12px; }
    .preview-pane { min-height: 480px; height: 60vh; border-radius: 12px; }
    
    .pane-header { flex-direction: column; align-items: flex-start; gap: 10px; height: auto; }
    .pane-actions { width: 100%; flex-wrap: wrap; justify-content: flex-start; }
    .pane-actions .btn { flex: 1; height: 38px; font-size: 12px; min-width: calc(33.33% - 6px); white-space: nowrap; padding: 0 4px; }
    
    .custom-input { height: 44px; padding: 0 14px; font-size: 15px !important; }
    .form-group label { font-size: 12px; margin-bottom: 2px; }

    .btn-generate-action { height: 46px !important; font-size: 14px !important; }

    .stitch-workspace { flex-direction: column; }
    .sortable-list-container { width: 100%; height: 220px; border-right: none; border-bottom: 1px solid var(--border-color); padding: 0 16px 16px 16px; margin-bottom: 16px; }
}