<template>
  <Transition name="fade">
    <div class="settings-overlay" v-if="isLoaded">
      <div class="settings-container">
        <!-- Header -->
        <div class="settings-header">
          <h1 class="settings-title">设置</h1>
          <button class="close-btn" @click="$emit('close')">
            <Icon icon="lucide:x" class="close-icon" />
          </button>
        </div>

        <div class="settings-body">
          <!-- Left Sidebar -->
          <nav class="settings-nav">
            <div
              v-for="category in categories"
              :key="category.id"
              class="nav-item"
              :class="{ active: activeCategory === category.id }"
              @click="activeCategory = category.id"
            >
              <Icon :icon="category.icon" class="nav-icon" />
              <span>{{ category.name }}</span>
            </div>
          </nav>

          <!-- Right Content -->
          <div class="settings-content">
            <!-- 外观设置 -->
            <div v-if="activeCategory === 'appearance'" class="section">
              <h2 class="section-title">外观设置</h2>

              <!-- 亮暗模式 -->
              <div class="setting-item">
                <div class="setting-info">
                  <div class="setting-label">主题模式</div>
                  <div class="setting-desc">选择深色或浅色主题</div>
                </div>
                <div class="setting-control">
                  <div class="theme-toggle">
                    <button 
                      class="theme-btn" 
                      :class="{ active: appearance.theme === 'dark' }"
                      @click="setTheme('dark')"
                    >
                      <Icon icon="lucide:moon" />
                      深色
                    </button>
                    <button 
                      class="theme-btn" 
                      :class="{ active: appearance.theme === 'light' }"
                      @click="setTheme('light')"
                    >
                      <Icon icon="lucide:sun" />
                      浅色
                    </button>
                  </div>
                </div>
              </div>

              <!-- 主题色 -->
              <div class="setting-item">
                <div class="setting-info">
                  <div class="setting-label">主题色</div>
                  <div class="setting-desc">选择你喜欢的强调色</div>
                </div>
                <div class="setting-control">
                  <div class="color-swatches">
                    <button
                      v-for="color in accentColors"
                      :key="color.value"
                      class="color-swatch"
                      :class="{ active: appearance.accentColor === color.value }"
                      :style="{ '--swatch-color': color.value }"
                      :title="color.name"
                      @click="setAccentColor(color.value)"
                    >
                      <Icon v-if="appearance.accentColor === color.value" icon="lucide:check" class="check-icon" />
                    </button>
                  </div>
                </div>
              </div>
            </div>

            <!-- 播放设置 -->
            <div v-else-if="activeCategory === 'playback'" class="section">
              <h2 class="section-title">播放设置</h2>
              
              <!-- 列表添加模式 -->
              <div class="setting-item">
                <div class="setting-info">
                  <div class="setting-label">列表添加模式</div>
                  <div class="setting-desc">选择点击歌曲时的播放行为</div>
                </div>
                <div class="setting-control">
                  <div class="radio-group">
                    <label class="radio-option">
                      <input type="radio" value="replace" v-model="playerStore.addListMode">
                      <span class="radio-label">替换当前列表</span>
                    </label>
                    <label class="radio-option">
                      <input type="radio" value="append" v-model="playerStore.addListMode">
                      <span class="radio-label">添加到列表末尾</span>
                    </label>
                  </div>
                </div>
              </div>

              <div class="placeholder-content">
                <Icon icon="lucide:headphones" class="placeholder-icon" />
                <p>更多设置即将推出</p>
              </div>
            </div>

            <!-- 音源管理 -->
            <div v-else-if="activeCategory === 'plugins'" class="section">
              <h2 class="section-title">音源管理</h2>
              
              <!-- 当前已安装的音源 -->
              <div class="plugin-list-section">
                <h3 class="subsection-title">已安装音源</h3>
                <div class="plugin-list">
                  <div 
                    v-for="plugin in installedPlugins" 
                    :key="plugin.id"
                    class="plugin-card"
                    :class="{ active: plugin.id === activePluginId }"
                  >
                    <div class="plugin-icon">
                      <Icon icon="lucide:music" />
                    </div>
                    <div class="plugin-info">
                      <div class="plugin-name">{{ plugin.name }}</div>
                      <div class="plugin-desc">{{ plugin.description || '暂无描述' }}</div>
                      <div class="plugin-meta">
                        <span class="version" v-if="plugin.version">v{{ plugin.version }}</span>
                        <span class="author" v-if="plugin.author">by {{ plugin.author }}</span>
                      </div>
                      <div class="quality-tags" v-if="plugin.quality && plugin.quality.length > 0">
                        <span class="quality-tag" v-for="q in plugin.quality" :key="q.id">{{ q.ui }}</span>
                      </div>
                    </div>
                    <div class="plugin-actions">
                      <button 
                        class="action-btn activate"
                        :class="{ active: plugin.id === activePluginId }"
                        @click="activatePlugin(plugin.id)"
                        :title="plugin.id === activePluginId ? '当前使用中' : '设为默认'"
                      >
                        <Icon :icon="plugin.id === activePluginId ? 'lucide:check-circle' : 'lucide:circle'" />
                        {{ plugin.id === activePluginId ? '使用中' : '设为默认' }}
                      </button>
                      <button 
                        v-if="plugin.source === 'user'"
                        class="action-btn delete"
                        @click="removePlugin(plugin.id)"
                        title="删除音源"
                      >
                        <Icon icon="lucide:trash-2" />
                      </button>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 添加音源 -->
              <div class="add-plugin-section">
                <h3 class="subsection-title">添加音源</h3>
                
                <!-- 方式1：在线导入 -->
                <div class="add-method">
                  <div class="method-title">
                    <Icon icon="lucide:link" />
                    在线导入
                  </div>
                  <div class="method-desc">输入音源插件的URL地址进行导入</div>
                  <div class="input-group">
                    <input 
                      type="text" 
                      v-model="pluginUrl"
                      placeholder="https://example.com/plugin.json"
                      class="plugin-input"
                    />
                    <button class="add-btn" @click="importFromUrl" :disabled="!pluginUrl">
                      <Icon icon="lucide:download" />
                      导入
                    </button>
                  </div>
                </div>

                <!-- 方式2：本地文件 -->
                <div class="add-method">
                  <div class="method-title">
                    <Icon icon="lucide:upload" />
                    本地文件
                  </div>
                  <div class="method-desc">上传 PC/Android 版的音源插件文件（.js）</div>
                  <div class="file-upload">
                    <input 
                      type="file" 
                      ref="fileInput"
                      accept=".js,.json"
                      @change="handleFileUpload"
                      class="file-input"
                    />
                    <button class="upload-btn" @click="triggerFileUpload">
                      <Icon icon="lucide:file-up" />
                      选择文件
                    </button>
                    <span class="file-name" v-if="selectedFile">{{ selectedFile.name }}</span>
                  </div>
                </div>

                <!-- 方式3：代码导入 -->
                <div class="add-method">
                  <div class="method-title">
                    <Icon icon="lucide:code" />
                    代码导入
                  </div>
                  <div class="method-desc">粘贴 PC/Android 版插件的 JS 代码（module.exports 格式）</div>
                  <textarea 
                    v-model="pluginCode"
                    placeholder="module.exports = {
  pluginInfo: {
    info: { id: 'my-plugin', name: '我的音源', ... },
    quality: [...]
  },
  musicSearch: { search: (query, page, limit) => {...} },
  getUrl: (id, quality) => '...',
  getLyric: (id) => '...'
}"
                    class="code-textarea"
                    rows="8"
                  ></textarea>
                  <button class="add-btn full-width" @click="importFromCode" :disabled="!pluginCode">
                    <Icon icon="lucide:play" />
                    运行导入
                  </button>
                </div>
              </div>
            </div>

            <!-- 关于 -->
            <div v-else-if="activeCategory === 'about'" class="section">
              <h2 class="section-title">关于</h2>
              <div class="about-content">
                <div class="app-logo">🎶</div>
                <h3>QZ Music Web</h3>
                <p class="version">版本 1.0.0</p>
                <p class="copyright">©2026 QZ Music</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </Transition>
</template>

<script setup lang="ts">
import { ref, reactive, onBeforeMount, nextTick } from 'vue';
import { Icon } from '@iconify/vue';
import { usePlayerStore } from '../stores/player';
import { pluginManager } from '../plugins/index';
import type { PluginFullInfo } from '../types';

const playerStore = usePlayerStore();

defineEmits(['close']);

const categories = [
  { id: 'appearance', name: '外观', icon: 'lucide:palette' },
  { id: 'playback', name: '播放', icon: 'lucide:headphones' },
  { id: 'plugins', name: '音源', icon: 'lucide:plug' },
  { id: 'about', name: '关于', icon: 'lucide:info' },
];

const accentColors = [
  { name: '红色', value: '#ec4141' },
  { name: '橙色', value: '#f97316' },
  { name: '金色', value: '#eab308' },
  { name: '绿色', value: '#22c55e' },
  { name: '青色', value: '#06b6d4' },
  { name: '蓝色', value: '#3b82f6' },
  { name: '紫色', value: '#8b5cf6' },
  { name: '粉色', value: '#ec4899' },
];

const activeCategory = ref('appearance');
const isLoaded = ref(false);
const enableTransition = ref(false);

const appearance = reactive({
  theme: 'dark' as 'dark' | 'light',
  accentColor: '#ec4141',
});

// 插件管理相关
const installedPlugins = ref<PluginFullInfo[]>([]);
const activePluginId = ref('');
const pluginUrl = ref('');
const pluginCode = ref('');
const fileInput = ref<HTMLInputElement | null>(null);
const selectedFile = ref<File | null>(null);

const refreshPlugins = () => {
  installedPlugins.value = pluginManager.getAll();
  activePluginId.value = pluginManager.getActivePluginId();
};

const activatePlugin = (id: string) => {
  pluginManager.setActivePlugin(id);
  refreshPlugins();
};

const removePlugin = (id: string) => {
  if (confirm('确定要删除这个音源吗？')) {
    pluginManager.removeUserPlugin(id);
    pluginManager.unregister(id);
    refreshPlugins();
  }
};

const importFromUrl = async () => {
  if (!pluginUrl.value) return;
  try {
    const response = await fetch(pluginUrl.value);
    const code = await response.text();
    importPluginCode(code);
    pluginUrl.value = '';
  } catch (e) {
    alert('导入失败：' + (e as Error).message);
  }
};

const triggerFileUpload = () => {
  fileInput.value?.click();
};

const handleFileUpload = async (event: Event) => {
  const target = event.target as HTMLInputElement;
  const file = target.files?.[0];
  if (!file) return;
  
  selectedFile.value = file;
  
  try {
    const code = await file.text();
    importPluginCode(code);
    selectedFile.value = null;
    target.value = '';
  } catch (e) {
    alert('文件读取失败：' + (e as Error).message);
  }
};

const importFromCode = () => {
  if (!pluginCode.value) return;
  importPluginCode(pluginCode.value);
  pluginCode.value = '';
};

/** 导入插件代码（兼容 PC/Android 版 CommonJS / webpack bundle 格式） */
const importPluginCode = (code: string) => {
  const result = pluginManager.loadFromCode(code, undefined, 'user');
  if (!result.success) {
    alert('插件加载失败：' + (result.error || '请检查代码格式是否正确（需要 module.exports = { pluginInfo, ... }）'));
    return;
  }

  refreshPlugins();

  const info = result.module?.pluginInfo?.info;
  alert(`音源 "${info?.name || result.pluginId}" 导入成功！`);
};

const applyTheme = (theme: 'dark' | 'light') => {
  document.documentElement.setAttribute('data-theme', theme);
  localStorage.setItem('qz-theme', theme);
};

const applyAccentColor = (color: string) => {
  document.documentElement.style.setProperty('--color-accent', color);
  localStorage.setItem('qz-accent-color', color);
};

const setTheme = (theme: 'dark' | 'light') => {
  appearance.theme = theme;
  applyTheme(theme);
};

const setAccentColor = (color: string) => {
  appearance.accentColor = color;
  applyAccentColor(color);
};

const loadAppearance = () => {
  const savedTheme = localStorage.getItem('qz-theme') as 'dark' | 'light';
  const savedAccentColor = localStorage.getItem('qz-accent-color');
  
  if (savedTheme) {
    appearance.theme = savedTheme;
  }
  if (savedAccentColor) {
    appearance.accentColor = savedAccentColor;
  }
  
  applyTheme(appearance.theme);
  applyAccentColor(appearance.accentColor);
};

// Load settings BEFORE mount to avoid visual flicker
onBeforeMount(async () => {
  loadAppearance();
  refreshPlugins();
  isLoaded.value = true;
  // Enable transition after initial render
  nextTick(() => {
    setTimeout(() => {
      enableTransition.value = true;
    }, 50);
  });
});
</script>

<style scoped>
/* Fade transition */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-container {
  width: 100%;
  height: 100%;
  background-color: var(--color-bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.settings-title {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--color-text-primary);
}

.close-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
}

.close-btn:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border-color: var(--color-text-muted);
}

.close-icon {
  width: 20px;
  height: 20px;
}

.settings-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Left Navigation */
.settings-nav {
  width: 200px;
  padding: 20px 12px;
  background-color: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 4px;
  border-radius: var(--radius-lg);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
}

.nav-item:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.nav-item.active {
  background-color: var(--color-accent-soft);
  color: var(--color-accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Right Content */
.settings-content {
  flex: 1;
  padding: 32px 48px;
  overflow-y: auto;
}

.section-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}

/* Setting Item */
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--color-border);
}

.setting-info {
  flex: 1;
}

.setting-label {
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  margin-bottom: 6px;
}

.setting-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.setting-control {
  margin-left: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Placeholder */
.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--color-text-muted);
}

.placeholder-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* About */
.about-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;
  text-align: center;
}

.app-logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #ec4141, #ff6b6b);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-lg);
}

.about-content h3 {
  font-size: var(--font-size-2xl);
  color: var(--color-text-primary);
  margin-bottom: 8px;
}

.version {
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.copyright {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* Scrollbar */
.settings-content::-webkit-scrollbar {
  width: 6px;
}

.settings-content::-webkit-scrollbar-track {
  background: transparent;
}

.settings-content::-webkit-scrollbar-thumb {
  background: var(--color-border-light);
  border-radius: 3px;
}

.settings-content::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  gap: 8px;
  background-color: var(--color-bg-tertiary);
  padding: 4px;
  border-radius: var(--radius-md);
}

.theme-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: all 0.2s ease;
}

.theme-btn:hover {
  color: var(--color-text-primary);
}

.theme-btn.active {
  background-color: var(--color-bg-primary);
  color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}

/* Color Swatches */
.color-swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: 3px solid transparent;
  background-color: var(--swatch-color);
  cursor: pointer;
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.color-swatch.active {
  box-shadow: 0 0 16px var(--swatch-color);
}

.check-icon {
  width: 18px;
  height: 18px;
  color: white;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

/* Radio Group */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

.radio-option input[type="radio"] {
  accent-color: var(--color-accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ===== 插件管理样式 ===== */
.subsection-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 16px;
  margin-top: 24px;
}

.plugin-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.plugin-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  border: 2px solid transparent;
  transition: all 0.2s ease;
}

.plugin-card:hover {
  background: var(--color-bg-tertiary);
}

.plugin-card.active {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.plugin-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
  flex-shrink: 0;
}

.plugin-info {
  flex: 1;
  min-width: 0;
}

.plugin-name {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 4px;
}

.plugin-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plugin-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.version {
  background: var(--color-bg-tertiary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.author {
  color: var(--color-text-secondary);
}

.quality-tags {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.quality-tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 500;
  letter-spacing: 0.5px;
}

.plugin-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: all 0.2s ease;
}

.action-btn.activate {
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
}

.action-btn.activate:hover {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.action-btn.activate.active {
  background: var(--color-accent);
  color: white;
}

.action-btn.delete {
  background: transparent;
  color: var(--color-text-muted);
  padding: 8px;
}

.action-btn.delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* 添加插件区域 */
.add-plugin-section {
  margin-top: 32px;
}

.add-method {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.method-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 4px;
}

.method-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.input-group {
  display: flex;
  gap: 8px;
}

.plugin-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  outline: none;
  transition: border-color 0.2s ease;
}

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

.plugin-input::placeholder {
  color: var(--color-text-muted);
}

.add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.add-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.add-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.add-btn.full-width {
  width: 100%;
  justify-content: center;
  margin-top: 12px;
}

/* 文件上传 */
.file-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-input {
  display: none;
}

.upload-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: all 0.2s ease;
}

.upload-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.file-name {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* 代码文本框 */
.code-textarea {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  font-size: 13px;
  font-family: 'Courier New', monospace;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

.code-textarea:focus {
  border-color: var(--color-accent);
}

.code-textarea::placeholder {
  color: var(--color-text-muted);
}
</style>
