* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle, #003e43 0%, #012227 100%);
  min-height: 100vh;
  padding: 20px;
}

.matrix_container {
  width: 100%;
  margin: 0 auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 40px);
}

/* ---------- Header ---------- */
.matrix_header {
  background: linear-gradient(135deg, #1a3a3a 0%, #2a5a4a 100%);
  color: white;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1000;
}
.matrix_header .logo {
  display: flex; align-items: center;
}
.matrix_header img {
  width: 32px; height: 32px;flex: 0 0 32px; margin-right: 8px;
}
.matrix_header h1 {
  font-size: 22px;
  font-weight: 600;
}

.matrix_header h1 sup {
  font-size: 12px;
}

/* 页面切换点（logo 区域内）：点击字母跳转另一矩阵生图页
   - duomi_matrix.html：显示 A → 跳 Agnes 免费页
   - matrix.html     ：显示 D → 跳 多米收费页 */
.page_switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 12px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.45);
  transition: all 0.2s ease;
  flex: 0 0 26px;
}
.page_switch:hover {
  background: rgba(255, 255, 255, 0.35);
  border-color: rgba(255, 255, 255, 0.8);
  transform: scale(1.08);
  text-decoration: none;
  color: #fff;
}
.page_switch:active {
  transform: scale(0.96);
}

.header_center {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header_actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.header_actions .v2_btn {
  padding: 6px 14px;
  font-size: 12px;
}

.save_path_input {
  width: 180px;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12px;
  outline: none;
}
.save_path_input::placeholder {
  color: rgba(255,255,255,0.4);
}
.save_path_input:focus {
  border-color: #7a9e1a;
}

/* 保存路径历史下拉 */
.save_path_wrap {
  position: relative;
  display: flex;
  align-items: center;
}
/* 批次模式：顶部路径选择器失效（按各 case 目录分别保存） */
.save_path_wrap.batch_disabled .save_path_input {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(0,0,0,0.25);
}
.save_path_wrap.batch_disabled .save_path_toggle {
  opacity: 0.4;
  cursor: not-allowed;
}
.save_path_wrap.batch_disabled::after {
  content: "";
}
/* 批次模式标签（含退出按钮） */
.batch_mode_tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  color: #ffd76a;
  background: rgba(255,215,106,0.12);
  border: 1px solid rgba(255,215,106,0.4);
  border-radius: 4px;
  white-space: nowrap;
}
.batch_exit {
  cursor: pointer;
  color: #fff;
  background: #d9534f;
  border: none;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 11px;
  line-height: 1.4;
}
.batch_exit:hover { background: #c9302c; }

/* 顶部下拉（命名模式 / 保存格式）：深色背景，沿用引擎下拉尺寸 */
.header_select {
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.header_select:focus {
  border-color: #7a9e1a;
}

/* 保存格式下拉（PNG/JPG） */
.save_format_wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.save_format_label {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
}
.name_mode_wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.name_mode_label {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
}
.save_path_input {
  width: 160px;
}
.save_path_pick {
  margin-left: -1px;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-left: none;
  border-radius: 0;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
}
.save_path_pick:hover {
  background: rgba(255,255,255,0.22);
}
.save_path_pick:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.save_path_toggle {
  margin-left: -1px;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-left: none;
  border-radius: 0 4px 4px 0;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}
.save_path_toggle:hover {
  background: rgba(255,255,255,0.22);
}
.save_path_dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 240px;
  overflow-y: auto;
  background: #2b2f3a;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  z-index: 9999;
  padding: 4px;
}
.save_path_dropdown.open {
  display: block;
}
.save_path_item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 3px;
  font-size: 12px;
  color: #e8e8e8;
}
.save_path_item:hover {
  background: rgba(255,255,255,0.08);
}
.save_path_text {
  flex: 1;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.save_path_del {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: #c0392b;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.save_path_del:hover {
  background: #c0392b;
  color: white;
}
.save_path_empty {
  padding: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  text-align: center;
}

.tree_btn {
  background: linear-gradient(135deg, #5a8eda 0%, #3a6eba 100%) !important;
  color: white !important;
  box-shadow: 0 3px 10px rgba(58,110,186,0.3) !important;
}
.tree_btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(58,110,186,0.45) !important;
}

.size_selector {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.1);
  padding: 6px 14px;
  border-radius: 8px;
}

.engine_selector {
  display: flex;
  align-items: center;
  gap: 6px;
}
.engine_selector label {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
}
.engine_select {
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: white;
  color: #333;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
.engine_select:focus {
  border-color: #7a9e1a;
}

.size_preset {
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: white;
  color: #333;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  max-width: 170px;
  position: relative;
  z-index: 9999;
}
.size_preset option {
  background: white;
  color: #333;
}
.size_preset optgroup {
  background: white;
  color: #333;
  font-weight: 600;
  font-style: normal;
}
.size_preset:focus {
  border-color: #7a9e1a;
}

/* png 透明底开关（位于尺寸选择器左侧） */
.png_transparent_wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.png_transparent_wrap input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.size_child {
  display: flex;
  align-items: center;
  gap: 10px;
}
.size_child label {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  gap: 4px;
}
.size_child input {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 13px;
  text-align: center;
}
.size_child input:focus {
  outline: none;
  border-color: #7a9e1a;
}

/* 比例下拉（档位模式显示） */
.ratio_selector {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ratio_selector label {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  gap: 4px;
}
.ratio_selector select {
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: white;
  color: #333;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
.ratio_selector select:focus {
  border-color: #7a9e1a;
}

.header_right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.login_info {
  font-size: 14px;
  color: rgba(255,255,255,0.7);
}

.settings_btn {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}
.settings_btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ---------- Main Layout ---------- */
.matrix_main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ---------- Left Panel ---------- */
.matrix_left {
  width: 50%;
  min-width: 360px;
  border-right: 1px solid #d0d0c0;
  background: #fafaf5;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  gap: 16px;
  transition: all 0.3s ease;
}
.matrix_left.hidden {
  width: 0;
  min-width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
}

/* ---------- Matrix Tabs ---------- */
.matrix_tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 2px solid #d0d0c0;
  padding-bottom: 0;
}

.matrix_tabs_list {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 1px;
}
.matrix_tabs_list::-webkit-scrollbar {
  height: 4px;
}
.matrix_tabs_list::-webkit-scrollbar-thumb {
  background: #c0c0b0;
  border-radius: 2px;
}

.matrix_tab {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 8px 12px;
  border: 1px solid #d0d0c0;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: #efefe6;
  color: #666;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  margin-bottom: -2px;
}
.matrix_tab:hover {
  background: #f5f5ec;
  color: #5a7e0a;
}
.matrix_tab.active {
  background: white;
  color: #5a7e0a;
  border-color: #7a9e1a;
  border-bottom: 2px solid white;
}

.tab_name {
  white-space: nowrap;
}

.tab_badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #7a9e1a;
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.tab_del {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  color: #bbb;
  transition: all 0.15s ease;
}
.matrix_tab:hover .tab_del {
  color: #888;
}
.tab_del:hover {
  background: #d9534f;
  color: white;
}

.matrix_tabs_ops {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-bottom: 6px;
}

.tab_add_btn,
.tab_clear_btn {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: white;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.tab_add_btn {
  border: 1px solid #7a9e1a;
  color: #5a7e0a;
}
.tab_add_btn:hover {
  background: #7a9e1a;
  color: white;
}
.tab_clear_btn {
  border: 1px solid #c0392b;
  color: #c0392b;
}
.tab_clear_btn:hover {
  background: #c0392b;
  color: white;
}

/* ---------- Matrix Panels ---------- */
.matrix_panels {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.matrix_panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel_head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: white;
  border: 1px solid #d0d0c0;
  border-radius: 8px;
}
.panel_title {
  font-size: 15px;
  font-weight: 700;
  color: #5a7e0a;
}
.panel_head_right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
/* 面板内的尺寸选择器：浅色底，区别于顶部深色导航 */
.panel_head_right .size_selector {
  background: #f4f4ea;
  border: 1px solid #e0e0d0;
  padding: 5px 10px;
}
.panel_head_right .size_child label {
  color: #666;
}
.panel_head_right .size_child input {
  background: white;
  border-color: #d0d0c0;
  color: #333;
}

/* 并发上限选择器 */
.concurrency_wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.concurrency_label {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
}

/* 队列状态 */
.queue_status {
  font-size: 12px;
  color: #999;
  white-space: nowrap;
}
.queue_status.active {
  color: #5a7e0a;
  font-weight: 600;
}

/* 排队中的单元 */
.item_image.item_queued {
  background: #f6f6ee;
}
.queue_badge {
  font-size: 12px;
  color: #a0a090;
  border: 1px dashed #c8c8b8;
  border-radius: 12px;
  padding: 3px 12px;
  user-select: none;
}
.grid_item.queued {
  opacity: 0.85;
}

/* AI Chat Box */
.ai_chat_box {
  background: white;
  border: 1px solid #d0d0c0;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai_chat_box textarea {
  width: 100%;
  padding: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  transition: border-color 0.3s ease;
}
.ai_chat_box textarea:focus {
  outline: none;
  border-color: #7a9e1a;
}

.ai_chat_actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.btn_ai_target {
  padding: 6px 12px;
  border: 1px solid #7a9e1a;
  border-radius: 6px;
  background: white;
  color: #5a7e0a;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.btn_ai_target:hover {
  background: #f0f5e8;
}
.btn_ai_target:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Matrix Box */
.matrix_box {
  background: white;
  border: 1px solid #d0d0c0;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.box_tit {
  display: flex;
  align-items: center;
  gap: 8px;
}
.box_tit h2 {
  font-size: 28px;
  font-weight: 700;
  color: rgba(122,158,26,0.25);
  line-height: 1;
  min-width: 28px;
  text-align: center;
}
.box_tit span {
  flex: 1;
  font-size: 13px;
  color: #666;
}

.clear_all_btn {
  flex-shrink: 0;
  padding: 4px 12px;
  border: 1px solid #c0392b;
  border-radius: 4px;
  background: white;
  color: #c0392b;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.clear_all_btn:hover {
  background: #c0392b;
  color: white;
}

.material_btn {
  padding: 4px 12px;
  border: 1px solid #7a9e1a;
  border-radius: 4px;
  background: white;
  color: #5a7e0a;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.material_btn:hover {
  background: #f0f5e8;
}

.matrix_box textarea {
  width: 100%;
  padding: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.3s ease;
  line-height: 1.5;
}
.matrix_box textarea:focus {
  outline: none;
  border-color: #7a9e1a;
  background: #fafef8;
}
.matrix_box textarea.ai_loading {
  border-color: #7a9e1a;
  background: #fafef8;
  animation: ai_pulse 1.2s ease-in-out infinite;
}

@keyframes ai_pulse {
  0%, 100% { border-color: #7a9e1a; }
  50% { border-color: #c0d88a; }
}

/* Image Zone */
.image_zone {
  border: 2px dashed #d0d0c0;
  border-radius: 8px;
  padding: 10px;
  background: #fafaf5;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
}
.image_zone:focus,
.image_zone:hover {
  border-color: #7a9e1a;
  background: #f0f5e8;
}
.image_zone.dragover {
  border-color: #7a9e1a;
  background: #e8f0d8;
}

.image_slots {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 60px;
}

.image_slot {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  border: 2px solid #d0d0c0;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background: white;
  flex-shrink: 0;
}
.image_slot.dragging {
  opacity: 0.5;
  cursor: grabbing;
}
.image_slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image_slot .slot_delete {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.image_slot:hover .slot_delete {
  display: flex;
}
.image_slot .slot_delete:hover {
  background: #e05555;
}

.image_zone_hint {
  text-align: center;
  font-size: 12px;
  color: #bbb;
  padding: 4px 0 0;
}

/* Matrix Row */
.matrix_row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Toggle Arrow */
.toggle_arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  width: 28px;
  height: 56px;
  background: #7a9e1a;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.toggle_arrow:hover {
  background: #5a7e0a;
  width: 32px;
}
.matrix_main.full_width .toggle_arrow {
  left: 8px;
  transform: translate(0, -50%);
}

/* ---------- Right Panel ---------- */
.matrix_right {
  width: 50%;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
}
.matrix_main.full_width .matrix_right {
  width: 100%;
}

.right_tit {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: #fafaf5;
  border-bottom: 1px solid #d0d0c0;
  flex-shrink: 0;
}

.matrix_count {
  font-size: 14px;
  margin-right: auto;
  color: #666;
  font-weight: 500;
}

/* Grid */
.matrix_grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  align-content: start;
}

.grid_placeholder {
  color: #bbb;
  text-align: center;
  padding: 60px 0;
  grid-column: 1 / -1;
}

.grid_item {
  background: white;
  border: 1px solid #d0d0c0;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.3s ease;
  position: relative;
}
.grid_item:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.item_coords {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(90,126,10,0.3);
  z-index: 2;
  pointer-events: none;
  user-select: none;
}

.item_image {
  flex: 1;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0e8;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.3s ease;
}
.item_image:hover {
  background: #e8e8d8;
}
.item_image.has_image {
  background: #fff;
}

.item_image .image_placeholder {
  color: #ccc;
  font-size: 28px;
  user-select: none;
}

.item_image .image_loading {
  display: none;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(122,158,26,0.2);
  border-top-color: #7a9e1a;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.grid_item.generating .image_loading {
  display: block;
}
.grid_item.generating .image_placeholder {
  display: none;
}

.item_img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  inset: 0;
}

.btn_regen {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 3;
  font-size: 11px;
  padding: 4px 10px;
  background: rgba(122,158,26,0.85);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s ease;
}
.btn_regen:hover {
  background: #7a9e1a;
}

/* ---------- Modals ---------- */
.modal_overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal_content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  animation: modalIn 0.25s ease;
  position: relative;
}

.modal_close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(0,0,0,0.08);
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease;
  z-index: 10;
}
.modal_close:hover {
  background: rgba(0,0,0,0.15);
}

/* Material Modal */
.material_modal {
  width: 80vw;
  max-width: 1400px;
  height: 70vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.material_modal h2 {
  font-size: 18px;
  padding: 16px 20px;
  border-bottom: 2px solid #7a9e1a;
  color: #333;
}

.material_tip {
  margin: 0;
  padding: 0 20px 12px;
  font-size: 13px;
  color: #999;
}

.material_body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.material_items {
  width: 200px;
  border-right: 1px solid #e0e0e0;
  overflow-y: auto;
  padding: 8px 0;
  flex-shrink: 0;
  background: #fafaf5;
}
.material_items_empty {
  color: #999;
  text-align: center;
  padding: 30px 10px;
  font-size: 12px;
}
.material_item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 8px 30px 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: #444;
  transition: background 0.15s ease;
  border-left: 3px solid transparent;
}
.material_item:hover {
  background: #f0f5e8;
}
.material_item.active {
  background: #f0f5e8;
  color: #5a7e0a;
  border-left-color: #7a9e1a;
  font-weight: 600;
}
.material_item_title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.material_item_del {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  font-size: 11px;
  color: #bbb;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.material_item:hover .material_item_del {
  opacity: 1;
}
.material_item_del:hover {
  color: #fff;
  background: #d9534f;
}

.material_center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}
.material_center textarea {
  flex: 1;
  width: 100%;
  padding: 16px 20px;
  border: none;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  line-height: 1.8;
  color: #333;
  outline: none;
}
.material_center textarea:focus {
  background: #fafef8;
}
.material_center_actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid #e0e0e0;
  background: #fafaf5;
  flex-shrink: 0;
}
.material_center_actions .v2_btn {
  padding: 8px 24px;
}

.material_right {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #e0e0e0;
  background: #fafaf5;
}
.material_form {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px;
  gap: 10px;
}
.material_form input[type="text"] {
  padding: 8px 10px;
  border: 1px solid #d0d0c0;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  flex-shrink: 0;
}
.material_form input[type="text"]:focus {
  border-color: #7a9e1a;
}
.material_form textarea {
  flex: 1;
  padding: 10px;
  border: 1px solid #d0d0c0;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.6;
}
.material_form textarea:focus {
  border-color: #7a9e1a;
  background: #fff;
}
.material_form_actions {
  display: flex;
  justify-content: center;
  padding: 0 14px 14px 14px;
  flex-shrink: 0;
}
.material_form_actions .v2_btn {
  padding: 8px 24px;
  width: 100%;
}

/* Image Detail Modal */
.image_detail_modal {
  width: 90vw;
  max-width: 1200px;
  height: 85vh;
  display: flex;
  flex-direction: column;
}

.detail_image_wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0e8;
  overflow: hidden;
  padding: 20px;
  position: relative;
}
.detail_image_wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.detail_arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  z-index: 10;
}
.detail_arrow:hover {
  background: rgba(0, 0, 0, 0.6);
}
.detail_arrow_left {
  left: 16px;
}
.detail_arrow_right {
  right: 16px;
}

.detail_info_bar {
  padding: 6px 20px;
  background: #fafaf5;
  border-top: 1px solid #e0e0e0;
  text-align: center;
  font-size: 13px;
  color: #888;
}

.detail_prompt {
  padding: 12px 20px;
  background: #fafaf5;
  border-top: 1px solid #d0d0c0;
  font-size: 13px;
  line-height: 1.6;
  color: #333;
  max-height: 120px;
  overflow-y: auto;
}

.detail_actions {
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid #e0e0e0;
}

/* Slot Preview Modal */
.slot_preview_modal {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.slot_preview_modal img {
  max-width: 80vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 4px;
}

/* Settings Modal (reuse v2) */
.v2_modal {
  background: white;
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 420px;
  max-width: 520px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  animation: modalIn 0.25s ease;
}
.v2_modal h2 {
  font-size: 20px;
  color: #333;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid #7a9e1a;
}

.modal_form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal_field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.modal_field label {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}
.modal_field input,
.modal_field select {
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.3s ease;
}
.modal_field input:focus,
.modal_field select:focus {
  outline: none;
  border-color: #7a9e1a;
}

.modal_actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* Buttons */
.v2_btn {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.v2_btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action_btn {
  background: linear-gradient(135deg, #7a9e1a 0%, #5a7e0a 100%);
  color: white;
  box-shadow: 0 3px 10px rgba(122,158,26,0.3);
}
.action_btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(122,158,26,0.45);
}
.action_btn.loading {
  opacity: 0.7;
  cursor: wait;
}

.action_danger {
  background: linear-gradient(135deg, #e05555 0%, #c0392b 100%);
  color: white;
  box-shadow: 0 3px 10px rgba(192,57,43,0.3);
}
.action_danger:hover:not(:disabled) {
  box-shadow: 0 5px 16px rgba(192,57,43,0.45);
}

.btn_clear_cache {
  background: #ff6b6b;
  color: white;
  border: none;
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-right: auto;
}
.btn_clear_cache:hover {
  background: #e05555;
}

.btn_save_settings {
  background: linear-gradient(135deg, #7a9e1a 0%, #5a7e0a 100%);
  color: white;
}

.btn_cancel {
  background: #e0e0e0;
  color: #333;
  border: none;
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn_cancel:hover {
  background: #d0d0d0;
}

/* Toast */
.v2_toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  left: auto;
  transform: none;
  background: #333;
  color: white;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 200;
  animation: toastIn 0.3s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.v2_toast.success {
  background: #5a7e0a;
}
.v2_toast.error {
  background: #d04040;
}

/* Animations */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Matrix Tree Modal ---------- */
.tree_modal {
  width: 70vw;
  max-width: 900px;
  height: 78vh;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tree_modal h2 {
  font-size: 18px;
  padding: 16px 20px;
  border-bottom: 2px solid #5a8eda;
  color: #333;
  flex-shrink: 0;
}

.tree_body {
  flex: 1;
  overflow: auto;
  padding: 24px 32px;
  background: #fafaf8;
}

.tree_empty {
  text-align: center;
  color: #bbb;
  padding: 60px 0;
  font-size: 14px;
}

/* Tree nodes */
.tree_node_list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tree_node_list > li:last-child {
  padding-bottom: 0;
}

.tree_node {
  position: relative;
  padding-left: 28px;
  padding-bottom: 16px;
  margin: 0;
}

.tree_node::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #c0c0c0;
}
.tree_node:last-child::before {
  height: 18px;
}

.tree_node::after {
  content: '';
  position: absolute;
  left: 10px;
  top: 18px;
  width: 18px;
  height: 1px;
  background: #c0c0c0;
}

.tree_node_root {
  padding-left: 0;
  padding-bottom: 30px;
}
.tree_node_root::before,
.tree_node_root::after {
  display: none;
}

.tree_node_content {
  display: inline-block;
  max-width: calc(100% - 20px);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  margin: 2px 0;
}

.tree_node_root > .tree_node_content {
  background: #e8f0fe;
  border: 2px solid #5a8eda;
  font-weight: 600;
  font-size: 14px;
  max-width: 100%;
  display: block;
}

.tree_level_image > .tree_node_content {
  background: #fef3e0;
  border: 1px solid #e0a040;
  
  display: flex;
  align-items: center;
  gap: 8px;
}
.tree_level_image > .tree_node_content .tree_img_thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid #ddd;
  flex-shrink: 0;
}

.tree_level_box3 > .tree_node_content {
  background: #f0f8e8;
  border: 1px solid #8ab040;
  font-weight: 500;
}
.tree_level_box3 {
  padding-bottom: 22px;
}

.tree_level_box4 > .tree_node_content {
  background: #f8f4f8;
  border: 1px solid #b090c0;
  font-size: 12px;
}

.tree_node_label {
  display: inline-block;
  font-size: 11px;
  color: #888;
  margin-right: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.tree_node_root .tree_node_label {
  color: #5a8eda;
}
.tree_level_image .tree_node_label {
  color: #e0a040;
}
.tree_level_box3 .tree_node_label {
  color: #6a8a20;
}
.tree_level_box4 .tree_node_label {
  color: #9070a0;
}

.tree_count {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
}

/* 多矩阵：总览 + 每个矩阵一块 */
.tree_grand_total {
  font-size: 13px;
  color: #444;
  background: #eef4ff;
  border: 1px solid #c8d8f0;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 18px;
  line-height: 1.6;
}
.tree_grand_total strong {
  color: #3a6eba;
}

.tree_matrix_block {
  border: 1px solid #e0e0d8;
  border-radius: 8px;
  background: white;
  padding: 14px 18px;
  margin-bottom: 16px;
}
.tree_matrix_block.active {
  border-color: #7a9e1a;
  box-shadow: 0 0 0 2px rgba(122,158,26,0.12);
}

.tree_matrix_head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 2px solid #f0f0e8;
}
.tree_matrix_head h3 {
  font-size: 15px;
  color: #5a7e0a;
}

.tree_matrix_head_left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tree_matrix_queue {
  font-size: 12px;
  color: #5a7e0a;
  background: #f0f5e8;
  border-radius: 10px;
  padding: 3px 10px;
}
.tree_matrix_queue.idle {
  color: #aaa;
  background: #f4f4f0;
}

.tree_matrix_empty {
  font-size: 13px;
  color: #bbb;
  padding: 14px 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  body { padding: 8px; }
  .matrix_container {
    border-radius: 0;
    height: calc(100vh - 16px);
  }
  .matrix_header {
    padding: 12px 16px;
  }
  .matrix_header h1 {
    font-size: 16px;
  }
  .header_center {
    display: flex;
    gap: 8px;
  }
  .header_center .size_selector {
    display: none;
  }
  .header_actions .v2_btn {
    padding: 5px 10px;
    font-size: 11px;
  }
  .matrix_main {
    flex-direction: column;
  }
  .toggle_arrow {
    display: none;
  }
  .matrix_left {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid #d0d0c0;
    max-height: 45vh;
  }
  .matrix_left.hidden {
    max-height: 0;
    min-height: 0;
    padding: 0;
    border-bottom: none;
  }
  .matrix_right {
    width: 100%;
    min-height: 0;
  }
  .matrix_row {
    grid-template-columns: 1fr;
  }
  .matrix_grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .right_tit {
    justify-content: center;
  }
  .material_modal {
    flex-direction: column;
    width: 95vw;
    height: 85vh;
  }
  .material_body {
    flex-direction: column;
  }
  .material_items {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
    max-height: 30%;
  }
  .material_center {
    flex: 1;
  }
  .material_center textarea {
    font-size: 13px;
    padding: 12px 16px;
  }
  .material_right {
    width: 100%;
    border-left: none;
    border-top: 1px solid #e0e0e0;
  }
  .v2_modal {
    min-width: auto;
    width: 90vw;
    margin: 20px;
    padding: 20px;
  }
  .tree_modal {
    width: 95vw;
    height: 90vh;
  }
  .tree_body {
    padding: 16px;
  }
}

/* ---------- 矩阵关系树：维度A/A+配对、维度B ---------- */
.tree_node.tree_level_a {
  background: #f4f9ff;
}
.tree_node.tree_level_a .tree_img_thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  margin-right: 8px;
  vertical-align: middle;
}
.tree_node.tree_level_a .tree_a_plus {
  display: inline-block;
  margin-left: 8px;
  color: #444;
  font-size: 12px;
  vertical-align: middle;
}
.tree_a_empty {
  display: inline-block;
  padding: 2px 8px;
  margin-right: 8px;
  background: #ffecec;
  color: #c0392b;
  border-radius: 4px;
  font-size: 12px;
}
.tree_node.tree_level_group > .tree_node_content {
  padding: 5px 0 0;
  font-weight: 600;
  color: #1a3a3a;
}
.tree_node.tree_level_group > .tree_node_content .tree_node_label {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid #c9d4d4;
  border-radius: 12px;
}
.tree_node.tree_level_box4 {
  background: #fff6f0;
}
.tree_node.tree_node_root > .tree_node_content {
  font-weight: 600;
  color: #1a3a3a;
}
