/* ==========================================================================
   WeaveArt - CSS Design System & Layout Stylesheet
   ========================================================================== */

/* 核心变量定义 */
:root {
  --bg-app: #090d16;
  --bg-panel: rgba(18, 24, 38, 0.8);
  --bg-panel-solid: #121826;
  --bg-input: #1b2336;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-active: rgba(59, 130, 246, 0.5);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  
  --accent-blue: #3b82f6;
  --accent-indigo: #6366f1;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  --accent-glow: rgba(99, 102, 241, 0.3);
  
  --danger: #ef4444;
  --success: #10b981;
  
  --font-display: 'Outfit', 'Noto Sans SC', system-ui, sans-serif;
  --font-sans: 'Noto Sans SC', system-ui, sans-serif;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-panel: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --shadow-glow: 0 0 16px var(--accent-glow);
  --glass-blur: blur(16px);
  --border-radius: 12px;
}

/* 基础重置与重构 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* 隐藏滚动条但保留滚动属性 */
.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* 应用大容器 */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ==========================================================================
   1. 头部导航栏 (Header)
   ========================================================================== */
.app-header {
  height: 64px;
  background-color: var(--bg-panel-solid);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  z-index: 10;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  background: var(--accent-gradient);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.logo-text h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
}

.logo-text span {
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* ==========================================================================
   2. 通用按钮与控制项 (Buttons & Controls)
   ========================================================================== */
.btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition-fast);
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background-color: var(--bg-input);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   3. 布局与双侧边栏 (Layout & Sidebars)
   ========================================================================== */
.app-main {
  display: flex;
  flex: 1;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 320px;
  background-color: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 28px;
  overflow-y: auto;
  z-index: 5;
  box-shadow: var(--shadow-panel);
}

.sidebar-right {
  width: 340px;
  border-right: none;
  border-left: 1px solid var(--border-color);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.panel-title svg {
  width: 16px;
  height: 16px;
  color: var(--accent-blue);
}

/* ==========================================================================
   4. 左侧上传模块与图层 (Uploads & Layers)
   ========================================================================== */
.upload-box-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layer-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.upload-drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius);
  background-color: rgba(255, 255, 255, 0.01);
  aspect-ratio: 16/10;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-normal);
}

.upload-drop-zone:hover,
.upload-drop-zone.dragover {
  border-color: var(--accent-indigo);
  background-color: rgba(99, 102, 241, 0.03);
}

.upload-drop-zone.active {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.15);
}

.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.upload-preview.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.upload-preview.has-image p,
.upload-preview.has-image svg {
  opacity: 0; /* 上传图片后隐藏字，但保留预览 */
}

.upload-drop-zone:hover .upload-preview.has-image {
  filter: brightness(0.6);
}
.upload-drop-zone:hover .upload-preview.has-image p,
.upload-drop-zone:hover .upload-preview.has-image svg {
  opacity: 1; /* 悬浮时显现覆盖 */
  color: #fff;
}

.upload-icon {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.upload-preview p {
  font-size: 12px;
  color: var(--text-secondary);
}

/* 经纬度模式切换 */
.toggle-container {
  display: flex;
  background-color: var(--bg-input);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  width: 100%;
}

.toggle-btn {
  flex: 1;
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.toggle-btn.active {
  background-color: var(--bg-panel-solid);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* 颜色选择器 */
.color-picker-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  transition: opacity var(--transition-normal);
}

.color-picker-container.hidden {
  display: none;
}

.color-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-preset {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
}

.color-preset:hover {
  transform: scale(1.1);
}

.color-preset.active {
  border-color: #fff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.custom-color-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

#input-weft-color {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: none;
}

#input-weft-color::-webkit-color-swatch {
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

#label-weft-color {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--text-primary);
}

/* 样例图片列表 */
.preset-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preset-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition-fast);
}

.preset-card:hover {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateX(4px);
}

.preset-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.preset-card span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.preset-card:hover span {
  color: var(--text-primary);
}

/* ==========================================================================
   5. 画布工作区 (Workspace Canvas)
   ========================================================================== */
.workspace {
  flex: 1;
  background-color: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  /* 经典的透明网格底纹 */
  background-image: 
    linear-gradient(45deg, rgba(255,255,255,0.015) 25%, transparent 25%), 
    linear-gradient(-45deg, rgba(255,255,255,0.015) 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.015) 75%), 
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.015) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.canvas-wrapper:active {
  cursor: grabbing;
}

.canvas-container {
  position: relative;
  flex-shrink: 0;
  flex: none;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  overflow: hidden;
  transition: transform 0.05s ease-out; /* 顺滑的缩放拖拽效果 */
}

#weave-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: transparent;
}

/* 工作区信息叠加 */
.workspace-info {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background-color: rgba(18, 24, 38, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  gap: 16px;
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
}

/* 浮动缩放控制面板 */
.floating-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background-color: rgba(18, 24, 38, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  display: flex;
  padding: 4px;
  border-radius: 30px;
  gap: 4px;
}

.floating-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.floating-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.floating-btn svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   6. 右侧控制器模块 (Weaving Controls)
   ========================================================================== */
/* 编织类型按钮 */
.weave-type-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.type-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: var(--transition-normal);
}

.type-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.rotate-90 {
  transform: rotate(90deg);
}

.type-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.type-meta strong {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}

.type-meta span {
  font-size: 11px;
  color: var(--text-muted);
}

.type-btn:hover {
  background-color: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.15);
}

.type-btn.active {
  background-color: rgba(59, 130, 246, 0.05);
  border-color: var(--accent-blue);
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.15);
}

.type-btn.active svg {
  color: var(--accent-blue);
}

/* 滑块控制器 */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group.hidden {
  display: none;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-header label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.control-value {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-blue);
}

/* 自定义滑块 */
.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border-color);
  transition: var(--transition-fast);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent-blue);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: var(--transition-fast);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background-color: var(--text-primary);
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent-blue);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* 复选框 checkbox */
.checkbox-container {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 28px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  transition: var(--transition-fast);
}

.checkbox-container:hover input ~ .checkmark {
  border-color: rgba(255, 255, 255, 0.2);
}

.checkbox-container input:checked ~ .checkmark {
  background: var(--accent-gradient);
  border-color: transparent;
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
}

.checkbox-container .checkmark:after {
  left: 6px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* 自定义下拉选择器 */
.custom-select {
  font-family: var(--font-sans);
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  width: 100%;
  transition: var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position-x: calc(100% - 10px);
  background-position-y: 50%;
}

.custom-select:hover,
.custom-select:focus {
  border-color: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   7. 响应式布局优化
   ========================================================================== */
@media (max-width: 1024px) {
  .app-main {
    flex-direction: column;
    overflow-y: auto;
  }
  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
  .sidebar-right {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }
  .workspace {
    height: 500px;
    min-height: 400px;
  }
}

/* 全宽操作按钮 */
.btn-full-width {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 10px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

/* ==========================================
   局部区域处理 (ROI) 样式
   ========================================== */
.roi-selector {
  position: absolute;
  border: 2px dashed var(--accent-color);
  box-sizing: border-box;
  cursor: move;
  z-index: 10;
  /* 使用超大外阴影实现遮罩暗化非选区效果 */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s;
}

.roi-selector:hover {
  border-color: #818cf8; /* 悬浮时变亮 */
}

.roi-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: var(--accent-color);
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  z-index: 11;
}

.roi-handle-nw {
  top: -5px;
  left: -5px;
  cursor: nwse-resize;
}

.roi-handle-ne {
  top: -5px;
  right: -5px;
  cursor: nesw-resize;
}

.roi-handle-se {
  bottom: -5px;
  right: -5px;
  cursor: nwse-resize;
}

.roi-handle-sw {
  bottom: -5px;
  left: -5px;
  cursor: nesw-resize;
}

.roi-label {
  position: absolute;
  top: -22px;
  left: 0;
  background-color: var(--accent-color);
  color: #ffffff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  white-space: nowrap;
  user-select: none;
}

.roi-controls-container {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.roi-buttons-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.roi-buttons-row .btn {
  flex: 1;
  font-size: 11px;
  padding: 6px 8px;
}

.roi-coords-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.coord-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.coord-input-group label {
  font-size: 10px;
  color: var(--text-muted);
}

.coord-input {
  background-color: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-color);
  padding: 6px 8px;
  font-size: 12px;
  font-family: monospace;
  outline: none;
  transition: border-color 0.2s;
}

.coord-input:focus {
  border-color: var(--accent-color);
}

.roi-help-text {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* 通用隐藏工具类 */
.hidden {
  display: none !important;
}
