/* ===== Reset & Variables ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0a0a0a;
  --surface: #0f0f0f;
  --surface-raised: #141414;
  --surface-dark: #050505;
  --border: rgba(255,255,255,0.08);
  --border-light: rgba(255,255,255,0.05);
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --primary: #6366f1;
  --primary-light: rgba(99, 102, 241, 0.15);
  --primary-hover: #818cf8;
  --primary-shadow: rgba(99, 102, 241, 0.35);
  --hover-bg: rgba(255,255,255,0.06);
  --hover-bg-strong: rgba(255,255,255,0.1);
  --btn-secondary-bg: rgba(255,255,255,0.1);
  --btn-secondary-border: rgba(255,255,255,0.15);
  --btn-outline-color: rgba(255,255,255,0.75);
  --btn-outline-border: rgba(255,255,255,0.15);
  --select-bg: rgba(255,255,255,0.06);
  --radius: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);
  --shadow-phone: 0 20px 40px rgba(0,0,0,0.5);
  --transition: 0.15s ease;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-raised: #f8f8f8;
  --surface-dark: #f0f0f0;
  --border: rgba(0,0,0,0.08);
  --border-light: rgba(0,0,0,0.05);
  --text: #171717;
  --text-secondary: #525252;
  --text-tertiary: #737373;
  --primary: #6366f1;
  --primary-light: rgba(99, 102, 241, 0.12);
  --primary-hover: #4f46e5;
  --primary-shadow: rgba(99, 102, 241, 0.25);
  --hover-bg: rgba(0,0,0,0.04);
  --hover-bg-strong: rgba(0,0,0,0.08);
  --btn-secondary-bg: rgba(0,0,0,0.06);
  --btn-secondary-border: rgba(0,0,0,0.12);
  --btn-outline-color: rgba(0,0,0,0.65);
  --btn-outline-border: rgba(0,0,0,0.15);
  --select-bg: rgba(0,0,0,0.04);
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
  --shadow-phone: 0 20px 40px rgba(0,0,0,0.15);
}

/* ===== Layout ===== */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.app { display: flex; flex-direction: column; height: 100vh; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 44px;
  background: var(--surface);
  flex-shrink: 0;
  gap: 16px;
  position: relative;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}
.toolbar-left { display: flex; align-items: center; gap: 18px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  text-decoration: none;
}
.logo svg { opacity: 0.9; flex-shrink: 0; }

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.1);
}

/* ===== Selectors ===== */
.format-selector, .template-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  font-weight: 500;
}
.format-selector select, .template-selector select {
  padding: 5px 26px 5px 9px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  font-size: 12px;
  background: rgba(255,255,255,0.06) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23ffffff88' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 7px center;
  cursor: pointer;
  outline: none;
  color: #fff;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition), background var(--transition);
  font-family: inherit;
}
.format-selector select:hover, .template-selector select:hover {
  border-color: rgba(255,255,255,0.2);
  background-color: rgba(255,255,255,0.1);
}
.format-selector select:focus, .template-selector select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-shadow);
}
.format-selector option, .template-selector option {
  color: #e0e0ee;
  background: #1a1a36;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  font-family: inherit;
}
.btn svg { flex-shrink: 0; opacity: 0.85; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-shadow);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px var(--primary-shadow);
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.22);
}

.btn-outline {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.75);
}
.btn-outline:hover {
  border-color: rgba(255,255,255,0.3);
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.btn-small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  font-size: 11.5px;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--transition);
  font-family: inherit;
  font-weight: 500;
}
.btn-small svg { opacity: 0.6; flex-shrink: 0; }
.btn-small:hover {
  border-color: var(--text-tertiary);
  color: var(--text);
  background: rgba(255,255,255,0.04);
}
.btn-small.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 1px 4px var(--primary-shadow);
}
.btn-small.active svg { opacity: 1; }

/* ===== Menu Bar ===== */
.menu-bar {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 32px;
  background: var(--surface-dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 2px;
  user-select: none;
}
.menu-item {
  padding: 4px 10px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition), color var(--transition);
}
.menu-item:hover, .menu-item.active {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

/* Menu Dropdown */
.menu-dropdown {
  position: fixed;
  top: 86px;
  left: 0;
  z-index: 200;
}
.menu-dropdown-inner {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 4px 0;
  overflow: hidden;
}
.menu-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.menu-dropdown-item:hover {
  background: var(--primary-light);
  color: var(--text);
}
.menu-dropdown-item .menu-shortcut {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: 24px;
}
.menu-dropdown-item:hover .menu-shortcut { color: var(--text-secondary); }
.menu-dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ===== Activity Bar ===== */
.activity-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 40px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 6px 0;
  gap: 2px;
}
.activity-bar-spacer { flex: 1; }
.activity-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: background var(--transition), color var(--transition);
  position: relative;
  font-size: 15px;
}
.activity-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}
.activity-btn.active {
  color: var(--primary);
  background: rgba(99,102,241,0.1);
}
.activity-btn.active::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--primary);
  border-radius: 1px;
}

/* ===== Side Panel ===== */
.side-panel {
  width: 280px;
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.side-panel.open {
  display: flex;
}
.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.side-panel-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.side-panel-close:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.side-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.side-panel-content::-webkit-scrollbar { width: 4px; }
.side-panel-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Side panel article items */
.sp-article-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition);
  gap: 8px;
}
.sp-article-item:hover { background: rgba(255,255,255,0.04); }
.sp-article-item.active { background: var(--primary-light); color: var(--text); }
.sp-article-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-article-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  transition: opacity var(--transition), color var(--transition);
}
.sp-article-item:hover .sp-article-delete { opacity: 1; }
.sp-article-delete:hover { color: #f87171; }

/* Side panel section */
.sp-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 12px 0 6px;
  padding: 0 2px;
}
.sp-section-title:first-child { margin-top: 0; }

/* Side panel list items */
.sp-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.sp-list-item:hover { background: rgba(255,255,255,0.04); }
.sp-list-item.active { background: var(--primary-light); color: var(--primary-hover); }

/* Side panel buttons */
.sp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  background: none;
  color: var(--text-tertiary);
  font-size: 13px;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.sp-btn:hover {
  border-color: var(--primary);
  color: var(--primary-hover);
  background: var(--primary-light);
}

/* Side panel search */
.sp-search {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-dark);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  margin-bottom: 8px;
  transition: border-color var(--transition);
}
.sp-search:focus { border-color: var(--primary); }
.sp-search::placeholder { color: var(--text-tertiary); }

/* Side panel settings form */
.sp-setting-row {
  margin-bottom: 14px;
}
.sp-setting-label {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}
.sp-setting-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-dark);
  color: var(--text);
  font-size: 12px;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition);
}
.sp-setting-input:focus { border-color: var(--primary); }
.sp-setting-input::placeholder { color: var(--text-tertiary); }

.sp-storage-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-dark);
  padding: 10px;
  margin-top: 8px;
}
.sp-storage-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.sp-storage-line:last-child {
  margin-bottom: 0;
}
.sp-storage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.sp-storage-danger {
  border-color: rgba(248, 113, 113, 0.45) !important;
  color: #f87171 !important;
}

/* ===== Command Palette ===== */
.command-palette {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
}
.command-palette-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
}
.command-palette-box {
  position: relative;
  width: 480px;
  max-width: 90vw;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.command-palette-box input {
  width: 100%;
  padding: 14px 18px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  outline: none;
  font-family: inherit;
}
.command-palette-box input::placeholder { color: var(--text-tertiary); }
.command-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 4px 0;
}
.command-list::-webkit-scrollbar { width: 4px; }
.command-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.command-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.command-item:hover, .command-item.selected {
  background: var(--primary-light);
  color: var(--text);
}
.command-item .cmd-icon {
  width: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--text-tertiary);
}
.command-item .cmd-label { flex: 1; }
.command-item .cmd-shortcut {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 2px 6px;
  background: var(--surface-dark);
  border-radius: 3px;
}

/* ===== Editor Container ===== */
.editor-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding: 0;
  gap: 0;
  background: var(--bg);
}

.editor-panel, .preview-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border-radius: 0;
  border: none;
  box-shadow: none;
  overflow: hidden;
}
.editor-panel {
  position: relative;
  border-right: 1px solid var(--border);
}
.preview-panel {
  border-left: none;
}
.preview-panel.hidden {
  flex: 0 0 auto;
  min-width: 0;
}
.preview-panel.hidden .preview-wrapper { display: none; }
.editor-container.preview-hidden .editor-panel {
  flex: 1 1 auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  letter-spacing: 0.4px;
  font-weight: 600;
  text-transform: uppercase;
}

.panel-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-header-left svg { opacity: 0.5; }
.panel-header-right { display: flex; align-items: center; gap: 12px; }
.panel-header-right .btn-small {
  white-space: nowrap;
}

.compat-status {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.compat-status.ok {
  background: var(--primary-light);
  color: var(--primary);
}
.compat-status.warn {
  background: rgba(255, 200, 50, 0.12);
  color: #f0c040;
}
.compat-status:empty { display: none; }

/* ===== Markdown Toolbar ===== */
.md-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}
.md-toolbar::-webkit-scrollbar { height: 0; }
.md-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.md-toolbar button:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.md-toolbar button:active {
  transform: scale(0.92);
}
.md-toolbar-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* ===== Find Bar (dark) ===== */

/* ===== Find Bar ===== */
.find-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.find-bar input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
  min-width: 80px;
  flex: 1;
}
.find-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-shadow);
}
.find-bar button {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--transition);
  font-family: inherit;
  flex-shrink: 0;
}
.find-bar button:hover {
  border-color: var(--text-tertiary);
  color: var(--text-secondary);
}
.find-bar button#btnCloseFind {
  padding: 4px 6px;
  font-size: 13px;
}

/* ===== Editor (Monaco) ===== */
#monaco-editor {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border-radius: 0;
}
#monaco-editor .monaco-editor {
  background: var(--surface) !important;
}
/* fallback textarea */
#editor {
  flex: 1;
  padding: 20px 24px;
  border: none;
  resize: none;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 14px;
  line-height: 1.75;
  outline: none;
  background: var(--surface);
  color: var(--text);
  tab-size: 2;
}
#editor::-webkit-scrollbar { width: 5px; }
#editor::-webkit-scrollbar-thumb { background: #3a3a5c; border-radius: 3px; }
#editor::-webkit-scrollbar-thumb:hover { background: #4a4a6c; }
#editor::-webkit-scrollbar-track { background: transparent; }

/* ===== Preview ===== */
.preview-wrapper {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  gap: 16px;
}

/* ===== Outline Panel ===== */
.outline-panel {
  width: 160px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: none;
  max-height: 100%;
  overflow-y: auto;
  display: none;
}
.outline-panel.open {
  display: block;
}
.outline-header {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  letter-spacing: 0.5px;
}
.outline-list {
  padding: 8px 0;
}
.outline-item {
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid transparent;
}
.outline-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}
.outline-item.active {
  color: var(--primary);
  background: var(--primary-light);
  border-left-color: var(--primary);
}
.outline-item.level-1 { padding-left: 14px; }
.outline-item.level-2 { padding-left: 24px; }
.outline-item.level-3 { padding-left: 34px; }
.preview-wrapper::-webkit-scrollbar { width: 5px; }
.preview-wrapper::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.preview-wrapper::-webkit-scrollbar-track { background: transparent; }

.preview-content {
  background: #fff;
  color: #1A1A2E;
  width: var(--device-width, 375px);
  max-width: 100%;
  min-height: 300px;
  padding: 20px 16px;
  border-radius: var(--radius-xl);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-phone);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), border-radius 0.4s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.4s;
  position: relative;
  flex-shrink: 0;
}

.preview-content.desktop-mode {
  width: 100%;
  background: #fff;
  color: #1A1A2E;
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
  padding: 24px;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
}
.preview-placeholder svg {
  margin-bottom: 16px;
  opacity: 0.4;
}

.editor-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

.device-selector {
  display: flex;
  align-items: center;
  gap: 6px;
}
.device-selector select {
  padding: 4px 22px 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 11px;
  background: var(--surface-dark) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 6px center;
  cursor: pointer;
  outline: none;
  color: var(--text-secondary);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition);
  font-family: inherit;
  font-weight: 500;
}
.device-selector select:hover {
  border-color: var(--text-tertiary);
}
.device-selector select:focus {
  border-color: var(--primary);
}

/* Device frame styling for mobile preview */
.preview-content.device-mobile {
  max-width: var(--device-width, 375px);
  border-radius: var(--radius-xl);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-phone);
}
.preview-content.device-tablet {
  max-width: var(--device-width, 744px);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  animation: modalFadeIn 0.2s ease;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 720px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid var(--border-light);
}
@keyframes modalSlideUp {
  from { transform: translateY(24px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-close {
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all var(--transition);
  color: var(--text-tertiary);
}
.modal-close::after {
  content: '';
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b92a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}
.modal-close:hover {
  background: var(--surface-raised);
}

.modal-body {
  flex: 1;
  overflow: hidden;
  padding: 20px 22px;
}
#htmlOutput {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 12px;
  line-height: 1.6;
  resize: none;
  outline: none;
  background: var(--surface-dark);
  color: var(--text);
  transition: border-color var(--transition);
}
#htmlOutput:focus { border-color: var(--primary); }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 22px;
  border-top: 1px solid var(--border-light);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 28px;
  background: var(--surface-dark);
  color: #fff;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.9); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ===== Monaco Editor Scrollbar Overrides ===== */
.monaco-editor .scrollbar.vertical .slider {
  background: rgba(255,255,255,0.08) !important;
  border-radius: 4px !important;
}
.monaco-editor .scrollbar.vertical .slider:hover {
  background: rgba(255,255,255,0.15) !important;
}
.monaco-editor .scrollbar.horizontal .slider {
  background: rgba(255,255,255,0.08) !important;
  border-radius: 4px !important;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-light);
}
.history-item:last-child {
  border-bottom: none;
}
.history-item:hover {
  background: rgba(255,255,255,0.04);
}
.history-item-info {
  flex: 1;
  min-width: 0;
}
.history-item-time {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.history-item-title {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-actions {
  display: flex;
  gap: 6px;
}
.history-item-actions button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--transition);
  font-family: inherit;
}
.history-item-actions button:hover {
  border-color: var(--text-tertiary);
  color: var(--text-secondary);
}

/* ===== Drag Overlay ===== */
.drag-overlay {
  position: absolute;
  inset: 0;
  background: rgba(99, 102, 241, 0.08);
  border: 2px dashed var(--primary);
  border-radius: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drag-overlay-content {
  text-align: center;
  color: var(--primary);
}
.drag-overlay-content svg {
  margin-bottom: 12px;
}
.drag-overlay-content p {
  font-size: 14px;
  font-weight: 500;
}

/* ===== Status Bar Extensions ===== */
.status-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.save-indicator {
  font-size: 11px;
  color: var(--primary);
  opacity: 0;
  transition: opacity 0.3s;
}
.save-indicator.show {
  opacity: 1;
}
.target-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.target-wrap label {
  font-size: 11px;
  color: var(--text-tertiary);
}
.target-wrap input {
  width: 56px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
  text-align: center;
}
.target-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-shadow);
}
#targetProgress {
  font-size: 11px;
  color: var(--primary);
  min-width: 40px;
  text-align: right;
  font-weight: 600;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.85);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
}
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.compat-status.ok {
  background: var(--primary-light);
  color: var(--primary);
}
.code-copy-btn {
  padding: 2px 8px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  line-height: 1.4;
}
.code-copy-btn:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-color: rgba(255,255,255,0.35);
}

/* ===== AI Assistant Modal ===== */
.ai-modal-content {
  max-width: 620px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ai-modal-content .modal-body { display: none; }

/* Tabs */
.ai-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
}
.ai-tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-tab:hover { color: var(--text); }
.ai-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Tab panes */
.ai-tab-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Error banner */
.ai-error-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(245, 158, 11, 0.1);
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  font-size: 13px;
}
.ai-error-btn {
  padding: 3px 12px;
  border-radius: 4px;
  border: 1px solid #f59e0b;
  background: none;
  color: #f59e0b;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ai-error-btn:hover { background: rgba(245, 158, 11, 0.15); }

/* Function cards grid */
.ai-func-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px 18px 8px;
}
.ai-func-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.ai-func-card:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.06);
  transform: translateY(-1px);
}
.ai-func-card:active { transform: translateY(0); }
.ai-func-card.disabled {
  opacity: 0.4;
  pointer-events: none;
}
.ai-func-icon { font-size: 22px; line-height: 1; }
.ai-func-label { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }

/* Stream toggle row */
.ai-stream-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 18px 10px;
}
.ai-stream-label { font-size: 12px; color: var(--text-tertiary); }

/* Toggle switch */
.ai-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
}
.ai-switch input { opacity: 0; width: 0; height: 0; }
.ai-switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: 0.2s;
}
.ai-switch-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.ai-switch input:checked + .ai-switch-slider { background: var(--primary); }
.ai-switch input:checked + .ai-switch-slider::before { transform: translateX(16px); }

/* Chat messages */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 18px;
  min-height: 80px;
  max-height: 35vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-chat-messages:empty { display: none; }
.ai-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-radius: 12px 12px 2px 12px;
  max-width: 70%;
}
.ai-msg-ai {
  align-self: flex-start;
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 12px 12px 12px 2px;
  border: 1px solid var(--border);
}
.ai-msg-system {
  align-self: center;
  background: none;
  color: var(--text-tertiary);
  font-size: 12px;
  max-width: 100%;
  padding: 4px 0;
}
.ai-msg-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}
.ai-msg-actions .btn-small {
  font-size: 11px;
  padding: 3px 10px;
}

/* Chat footer */
.ai-chat-footer {
  padding: 10px 18px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-chat-footer textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
  min-height: 36px;
  max-height: 100px;
}
.ai-chat-footer textarea:focus { border-color: var(--primary); }
.ai-chat-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Typing indicator */
.ai-typing {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}
.ai-typing span {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: ai-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ===== Settings Tab ===== */
.ai-settings-body {
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: 60vh;
}
.ai-setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.ai-setting-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-setting-select {
  flex: 1;
  max-width: 220px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.ai-setting-input {
  flex: 1;
  max-width: 220px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.ai-setting-input:focus, .ai-setting-select:focus { border-color: var(--primary); }
.ai-setting-range-wrap {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}
.ai-setting-range {
  width: 100%;
  accent-color: var(--primary);
}
.ai-settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}
.ai-config-status {
  font-size: 12px;
  color: var(--text-tertiary);
}
.ai-config-status.error { color: #e53e3e; }
.ai-config-status.ok { color: var(--primary); }

/* AI assistant refinement */
.ai-modal-content {
  max-width: 640px;
  max-height: 88vh;
}
.ai-tabs {
  margin: 0 22px;
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-dark);
}
.ai-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border-bottom: 0;
  color: var(--text-secondary);
}
.ai-tab.active {
  color: var(--text);
  border-bottom-color: transparent;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
}
.ai-tab-icon {
  font-size: 13px;
  line-height: 1;
}
.ai-pane-intro {
  margin: 14px 18px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-pane-intro strong {
  font-size: 14px;
  color: var(--text);
}
.ai-pane-intro span {
  font-size: 12px;
  color: var(--text-tertiary);
}
.ai-func-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 18px 10px;
}
.ai-func-card {
  align-items: flex-start;
  min-height: 88px;
  padding: 12px;
  border-radius: 9px;
  background: var(--surface-raised);
}
.ai-func-card:hover,
.ai-func-card.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
}
.ai-func-icon {
  font-size: 18px;
}
.ai-func-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: normal;
}
.ai-func-desc {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ai-stream-row {
  margin: 4px 18px 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.ai-stream-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ai-stream-copy span {
  color: var(--text-tertiary);
  font-size: 11px;
}
.ai-stream-copy .ai-stream-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}
.ai-chat-footer {
  margin: 0 18px 18px;
  padding: 0;
  border-top: 0;
}
.ai-input-label {
  color: var(--text-secondary);
  font-size: 12px;
}
.ai-chat-footer textarea {
  min-height: 96px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface);
}
.ai-chat-actions {
  justify-content: stretch;
}
.ai-chat-actions .btn {
  flex: 1;
  justify-content: center;
}
.ai-error-banner {
  margin: 14px 18px 0;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.1);
}
.ai-settings-body {
  padding: 14px 22px 0;
  gap: 12px;
  max-height: 68vh;
}
.ai-settings-note {
  padding: 10px 12px;
  border: 1px solid rgba(99, 102, 241, 0.22);
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.08);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.6;
}
.ai-setting-item {
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.ai-setting-label {
  min-width: 96px;
  padding-top: 7px;
}
.ai-setting-input,
.ai-setting-select {
  max-width: none;
  min-height: 34px;
  background: var(--surface-dark);
}
.ai-provider-hint {
  margin: -4px 0 2px 108px;
  color: #22c55e;
  font-size: 11px;
  line-height: 1.5;
}
.ai-key-input-wrap {
  flex: 1;
  display: flex;
  gap: 6px;
}
.ai-key-input-wrap .ai-setting-input {
  flex: 1;
}
.ai-key-toggle {
  width: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-dark);
  color: var(--text-secondary);
  cursor: pointer;
}
.ai-key-toggle:hover {
  color: var(--text);
  border-color: var(--primary);
}
.ai-setting-range-wrap {
  padding: 10px 0;
}
.ai-setting-range-wrap .ai-setting-label {
  display: flex;
  justify-content: space-between;
  min-width: 0;
  padding-top: 0;
}
.ai-setting-range-wrap small {
  color: var(--text-tertiary);
  font-size: 11px;
}
.ai-settings-footer {
  position: sticky;
  bottom: 0;
  padding: 12px 0 14px;
  background: var(--surface);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .ai-modal-content {
    width: 94%;
    max-height: 90vh;
  }
  .ai-tabs {
    margin: 0 16px;
  }
  .ai-pane-intro,
  .ai-error-banner,
  .ai-stream-row,
  .ai-chat-footer {
    margin-left: 16px;
    margin-right: 16px;
  }
  .ai-func-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-left: 16px;
    padding-right: 16px;
  }
  .ai-chat-actions {
    flex-wrap: wrap;
  }
  .ai-settings-body {
    padding-left: 16px;
    padding-right: 16px;
  }
  .ai-setting-item {
    flex-direction: column;
    gap: 6px;
  }
  .ai-setting-label {
    min-width: 0;
    padding-top: 0;
  }
  .ai-provider-hint {
    margin-left: 0;
  }
  .editor-container {
    flex-direction: column;
    padding: 0;
  }
  .panel-header {
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
  }
  .panel-header-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }
  .panel-header-right .btn-small {
    padding: 4px 7px;
    font-size: 10px;
  }
  .device-selector {
    max-width: 100%;
  }
  .device-selector select {
    max-width: 150px;
  }
  .editor-panel {
    max-height: 45vh;
  }
  .toolbar {
    padding: 8px 12px;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
  }
  .toolbar-left { flex-wrap: wrap; }
  .toolbar-right { flex-wrap: wrap; }
  .menu-bar { display: none; }
  .activity-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 60;
    width: auto;
    height: 48px;
    flex-direction: row;
    justify-content: space-around;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(19, 21, 28, 0.92);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(16px);
  }
  .activity-bar-spacer { display: none; }
  .activity-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }
  .activity-btn.active::before { display: none; }
  .side-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 68px;
    z-index: 59;
    width: auto;
    max-height: min(66vh, 560px);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: translateY(14px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.18s ease, opacity 0.18s ease;
  }
  .side-panel.open {
    display: flex;
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .side-panel-header {
    min-height: 42px;
    padding: 10px 14px;
  }
  .side-panel-content {
    max-height: calc(min(66vh, 560px) - 42px);
  }
  .preview-panel {
    padding-bottom: 62px;
  }
  [data-theme="light"] .activity-bar {
    background: rgba(255, 255, 255, 0.94);
  }
}

/* Reverse layout for preview position toggle */
.editor-container.reverse {
  flex-direction: row-reverse;
}
.editor-container.reverse .activity-bar {
  order: 1;
}
.editor-container.reverse .side-panel {
  order: 2;
}
.editor-container.reverse .preview-panel {
  border-right: none;
}
.editor-container.reverse .editor-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

/* ===== Template Grid ===== */
.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.template-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface-raised);
  text-align: center;
}
.template-card:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.15);
}
.template-card-icon {
  font-size: 28px;
  margin-bottom: 8px;
}
.template-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.template-card-desc {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* ===== Template Gallery (Side Panel) ===== */
.tpl-gallery-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.tpl-search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition);
}
.tpl-search-wrap:focus-within {
  border-color: var(--primary);
}
.tpl-search-wrap svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.tpl-search {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  padding: 0;
  font-family: inherit;
}
.tpl-search::placeholder {
  color: var(--text-tertiary);
}
.tpl-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.tpl-new-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.tpl-categories {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.tpl-categories::-webkit-scrollbar {
  display: none;
}
.tpl-category-tab {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  font-family: inherit;
}
.tpl-category-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.tpl-category-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tpl-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tpl-empty {
  text-align: center;
  color: var(--text-tertiary);
  padding: 32px 0;
  font-size: 13px;
}
.tpl-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-raised);
  transition: all var(--transition);
}
.tpl-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(99,102,241,0.12);
  transform: translateY(-1px);
}
.tpl-card-cover {
  position: relative;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tpl-card-icon {
  font-size: 32px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}
.tpl-fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.35);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(4px);
}
.tpl-fav-btn:hover {
  background: rgba(0,0,0,0.5);
  transform: scale(1.1);
}
.tpl-fav-btn.active {
  color: #fbbf24;
}
.tpl-del-btn {
  position: absolute;
  top: 8px;
  right: 38px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.35);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(4px);
}
.tpl-del-btn:hover {
  background: rgba(239,68,68,0.8);
  transform: scale(1.1);
}
.tpl-card-body {
  padding: 10px 12px 12px;
}
.tpl-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.4;
}
.tpl-card-desc {
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tpl-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tpl-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.tpl-card-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10px;
  font-weight: 600;
}
.tpl-use-btn {
  padding: 5px 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}
.tpl-use-btn:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 8px var(--primary-shadow);
}
.tpl-preview-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.tpl-preview-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.template-preview-body {
  background: var(--bg);
  max-height: 62vh;
  overflow: auto;
  padding: 18px;
}
.template-preview-paper {
  background: #fff;
  color: #1A1A2E;
  width: min(430px, 100%);
  margin: 0 auto;
  padding: 20px 16px;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-phone);
}

/* Refined template gallery */
.tpl-gallery-header { margin-bottom: 10px; }
.tpl-categories {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
  margin-bottom: 12px;
  overflow: visible;
  padding-bottom: 0;
}
.tpl-category-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 9px;
  background: var(--surface-raised);
  font-size: 12px;
}
.tpl-category-tab span { font-size: 13px; }
.tpl-create-btn {
  width: 100%;
  min-height: 36px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.tpl-create-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.12);
}
.tpl-card {
  border-radius: 8px;
  animation: tplCardIn 0.28s ease both;
}
.tpl-card-cover {
  height: 132px;
  overflow: hidden;
  isolation: isolate;
}
.tpl-card-cover::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.88), rgba(255,255,255,0.18)),
    radial-gradient(circle at 18% 16%, rgba(255,255,255,0.75), transparent 28%);
  z-index: 0;
}
.tpl-cover-education { background: linear-gradient(135deg, #dbeafe, #eef2ff); }
.tpl-cover-tech { background: linear-gradient(135deg, #d1fae5, #dbeafe); }
.tpl-cover-business { background: linear-gradient(135deg, #e5e7eb, #eff6ff); }
.tpl-cover-festival { background: linear-gradient(135deg, #fff7ed, #fee2e2); }
.tpl-cover-life { background: linear-gradient(135deg, #ecfccb, #fef3c7); }
.tpl-cover-custom { background: linear-gradient(135deg, #f5f3ff, #e0f2fe); }
.tpl-card-icon {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 3;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255,255,255,0.7);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
  font-size: 20px;
}
.tpl-illustration {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.tpl-shape {
  position: absolute;
  display: block;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(15,23,42,0.08);
  box-shadow: 0 10px 28px rgba(15,23,42,0.1);
  animation: tplFloat 5s ease-in-out infinite;
}
.tpl-shape-a {
  left: 28px;
  top: 28px;
  width: 82px;
  height: 58px;
  border-radius: 8px;
}
.tpl-shape-b {
  left: 44px;
  top: 44px;
  width: 92px;
  height: 5px;
  border-radius: 99px;
  background: currentColor;
  opacity: 0.28;
  animation-delay: 0.3s;
}
.tpl-shape-c {
  right: 42px;
  top: 28px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  animation-delay: 0.6s;
}
.tpl-shape-d {
  left: 44px;
  bottom: 20px;
  width: 148px;
  height: 12px;
  border-radius: 999px;
  opacity: 0.55;
  animation-delay: 0.9s;
}
.tpl-illustration-education { color: #2563eb; }
.tpl-illustration-education .tpl-shape-a { transform: skewY(-4deg); border-radius: 4px 14px 14px 4px; }
.tpl-illustration-tech { color: #0f766e; }
.tpl-illustration-tech .tpl-shape-a { width: 96px; height: 54px; border-radius: 10px; }
.tpl-illustration-tech .tpl-shape-b,
.tpl-illustration-tech .tpl-shape-d { height: 4px; }
.tpl-illustration-business { color: #475569; }
.tpl-illustration-business .tpl-shape-a { width: 66px; height: 74px; }
.tpl-illustration-business .tpl-shape-c { border-radius: 10px; }
.tpl-illustration-festival { color: #dc2626; }
.tpl-illustration-festival .tpl-shape-a,
.tpl-illustration-festival .tpl-shape-c { transform: rotate(45deg); border-radius: 10px; }
.tpl-illustration-life { color: #16a34a; }
.tpl-illustration-life .tpl-shape-a { border-radius: 22px 22px 10px 10px; }
.tpl-illustration-custom { color: #7c3aed; }
.tpl-card:hover .tpl-shape { animation-duration: 2.6s; }
@keyframes tplFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(0.5deg); }
}
@keyframes tplCardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Custom style panel */
.style-panel-head {
  position: sticky;
  top: -12px;
  z-index: 5;
  padding: 0 0 10px;
  background: var(--surface);
}
.style-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.style-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  border-radius: 9px;
  background: var(--surface-dark);
  border: 1px solid var(--border);
}
.style-tab {
  min-height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}
.style-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
}
.style-group-title {
  margin: 14px 0 8px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}
.style-preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.style-preset-card {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-raised);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}
.style-preset-card:hover,
.style-preset-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
}
.style-preset-card span:last-child {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.style-preset-card strong { font-size: 13px; }
.style-preset-card small {
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.35;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.style-swatch {
  width: 48px;
  height: 26px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 7px;
  border: 1px solid rgba(0,0,0,0.08);
  background: linear-gradient(90deg, var(--c1) 0 25%, var(--c2) 25% 50%, var(--c3) 50% 75%, var(--c4) 75% 100%);
}
.style-control-row {
  display: grid;
  grid-template-columns: 58px 34px 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.style-control-row label {
  color: var(--text-secondary);
  font-size: 12px;
}
.style-control-row input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-dark);
}
.style-range-row { margin-bottom: 12px; }
.style-range-row label {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 12px;
}
.style-range-row input {
  width: 100%;
  accent-color: var(--primary);
}
.style-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.style-actions .sp-btn { flex: 1; }
.style-actions .danger {
  border-color: rgba(248, 113, 113, 0.5);
  color: #f87171;
}
.style-css-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.style-css-editor {
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  background: var(--surface-dark);
  color: var(--text);
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  outline: none;
}
.style-css-editor:focus { border-color: var(--primary); }

/* ===== Shortcut List ===== */
.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.shortcut-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.shortcut-item span {
  margin-left: auto;
  color: var(--text);
  font-weight: 500;
}
.shortcut-item kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-family: inherit;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  font-weight: 600;
}

/* ===== Print ===== */
@media print {
  body { background: #fff !important; }
  .toolbar, .editor-panel, .outline-panel,
  .modal, .toast, .drag-overlay,
  #toast { display: none !important; }
  .app { height: auto !important; }
  .editor-container { padding: 0 !important; gap: 0 !important; background: #fff !important; }
  .preview-panel {
    flex: 1 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: #fff !important;
  }
  .preview-wrapper {
    background: #fff !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  .preview-content {
    max-width: 100% !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 20px !important;
  }
  .panel-header { display: none !important; }
  .preview-placeholder { display: none !important; }
}

/* ===== Monaco Editor Overrides ===== */
.monaco-editor,
.monaco-editor-background {
  background: #0B0D12 !important;
}
.monaco-editor .margin {
  background: #0B0D12 !important;
}
.monaco-editor .minimap {
  background: #0B0D12 !important;
}
.monaco-editor .overflow-guard {
  border-radius: 0 !important;
}
/* Ensure editor fills panel */
.editor-panel .panel-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ===== Dark Theme Form Elements ===== */
input, textarea, select {
  color-scheme: dark;
}
input::placeholder, textarea::placeholder {
  color: var(--text-tertiary);
}
input[type="number"] {
  color: var(--text);
}
/* Selection highlight */
::selection {
  background: rgba(99, 102, 241, 0.3);
  color: #fff;
}

/* ===== Light Theme Overrides ===== */
[data-theme="light"] input,
[data-theme="light"] textarea,
[data-theme="light"] select {
  color-scheme: light;
}
[data-theme="light"] ::selection {
  background: rgba(99, 102, 241, 0.2);
  color: var(--text);
}

[data-theme="light"] .toolbar-divider {
  background: var(--border);
}
[data-theme="light"] .format-selector,
[data-theme="light"] .template-selector {
  color: var(--text-tertiary);
}
[data-theme="light"] .format-selector select,
[data-theme="light"] .template-selector select {
  background: var(--select-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2300000088' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 7px center;
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .format-selector select:hover,
[data-theme="light"] .template-selector select:hover {
  background-color: var(--hover-bg-strong);
  border-color: var(--text-tertiary);
}
[data-theme="light"] .format-selector option,
[data-theme="light"] .template-selector option {
  color: var(--text);
  background: var(--surface);
}

[data-theme="light"] .btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--text);
  border-color: var(--btn-secondary-border);
}
[data-theme="light"] .btn-secondary:hover {
  background: var(--hover-bg-strong);
  border-color: var(--text-tertiary);
}
[data-theme="light"] .btn-outline {
  border-color: var(--btn-outline-border);
  color: var(--btn-outline-color);
}
[data-theme="light"] .btn-outline:hover {
  border-color: var(--text-secondary);
  color: var(--text);
  background: var(--hover-bg);
}

[data-theme="light"] .menu-item:hover,
[data-theme="light"] .menu-item.active {
  background: var(--hover-bg);
  color: var(--text);
}
[data-theme="light"] .menu-dropdown-inner {
  box-shadow: var(--shadow-lg);
}

[data-theme="light"] .activity-btn:hover {
  background: var(--hover-bg);
  color: var(--text-secondary);
}
[data-theme="light"] .activity-btn.active {
  background: rgba(99,102,241,0.1);
}
[data-theme="light"] .activity-btn.active::before {
  background: var(--primary);
}

[data-theme="light"] .side-panel-close:hover {
  background: var(--hover-bg);
  color: var(--text);
}
[data-theme="light"] .sp-article-item:hover { background: var(--hover-bg); }
[data-theme="light"] .sp-list-item:hover { background: var(--hover-bg); }
[data-theme="light"] .history-item:hover { background: var(--hover-bg); }
[data-theme="light"] .sp-btn:hover {
  background: var(--primary-light);
}

[data-theme="light"] .command-palette-backdrop {
  background: rgba(0,0,0,0.35);
}
[data-theme="light"] .command-item:hover,
[data-theme="light"] .command-item.selected {
  background: var(--primary-light);
  color: var(--text);
}
[data-theme="light"] .command-item .cmd-shortcut {
  background: var(--surface-dark);
  color: var(--text-tertiary);
}

[data-theme="light"] .md-toolbar button:hover {
  background: var(--hover-bg);
  color: var(--text);
}
[data-theme="light"] .md-toolbar button:active {
  color: var(--text);
}

[data-theme="light"] .find-bar {
  background: var(--surface);
  border-color: var(--border);
}
[data-theme="light"] .find-bar input {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .find-bar button {
  border-color: var(--border);
  color: var(--text-tertiary);
}
[data-theme="light"] .find-bar button:hover {
  border-color: var(--text-tertiary);
  color: var(--text-secondary);
}

[data-theme="light"] .compat-status.warn {
  background: rgba(234, 179, 8, 0.12);
  color: #a16207;
}
[data-theme="light"] .target-wrap input {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .target-wrap input:focus {
  border-color: var(--primary);
}
[data-theme="light"] #targetProgress {
  color: var(--primary);
}

[data-theme="light"] #editor {
  background: var(--surface);
  color: var(--text);
}
[data-theme="light"] .editor-statusbar {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-tertiary);
}
[data-theme="light"] .save-indicator {
  color: var(--primary);
}

[data-theme="light"] .drag-overlay {
  background: rgba(99, 102, 241, 0.05);
}
[data-theme="light"] .loading-overlay {
  background: rgba(245, 245, 245, 0.85);
}
[data-theme="light"] .loading-spinner {
  border-color: var(--border);
}

[data-theme="light"] .monaco-editor,
[data-theme="light"] .monaco-editor-background,
[data-theme="light"] .monaco-editor .margin,
[data-theme="light"] .monaco-editor .minimap {
  background: #fafafa !important;
}
[data-theme="light"] .monaco-editor .scrollbar.vertical .slider,
[data-theme="light"] .monaco-editor .scrollbar.horizontal .slider {
  background: rgba(0,0,0,0.12) !important;
}
[data-theme="light"] .monaco-editor .scrollbar.vertical .slider:hover,
[data-theme="light"] .monaco-editor .scrollbar.horizontal .slider:hover {
  background: rgba(0,0,0,0.2) !important;
}

[data-theme="light"] .code-copy-btn {
  background: var(--hover-bg);
  border-color: var(--border);
  color: var(--text-secondary);
}
[data-theme="light"] .code-copy-btn:hover {
  background: var(--hover-bg-strong);
  color: var(--text);
  border-color: var(--text-tertiary);
}

[data-theme="light"] .ai-error-banner {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.15);
  color: #b45309;
}
[data-theme="light"] .ai-func-card {
  background: var(--surface);
  border-color: var(--border);
}
[data-theme="light"] .ai-func-card:hover {
  background: rgba(99, 102, 241, 0.04);
}
[data-theme="light"] .ai-msg-ai {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border);
}
[data-theme="light"] .ai-chat-footer textarea {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .ai-chat-footer textarea:focus {
  border-color: var(--primary);
}
[data-theme="light"] .ai-switch-slider {
  background: var(--border);
}
[data-theme="light"] .ai-switch-slider::before {
  background: #fff;
}

[data-theme="light"] .device-selector select {
  background: var(--surface-dark) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2300000088' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 6px center;
  border-color: var(--border);
  color: var(--text-secondary);
}
[data-theme="light"] .device-selector select:hover {
  border-color: var(--text-tertiary);
}
[data-theme="light"] .device-selector select:focus {
  border-color: var(--primary);
}

[data-theme="light"] .template-card {
  background: var(--surface-raised);
}
[data-theme="light"] .template-card:hover {
  background: var(--primary-light);
}
[data-theme="light"] .tpl-search-wrap {
  background: var(--surface-dark);
}
[data-theme="light"] .tpl-new-btn {
  background: var(--surface-dark);
}
[data-theme="light"] .tpl-card {
  background: var(--surface-raised);
}
[data-theme="light"] .tpl-card:hover {
  box-shadow: 0 4px 16px rgba(99,102,241,0.1);
}
[data-theme="light"] .tpl-fav-btn,
[data-theme="light"] .tpl-del-btn {
  background: rgba(0,0,0,0.25);
}
[data-theme="light"] .shortcut-item kbd {
  background: var(--hover-bg);
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}
[data-theme="light"] #htmlOutput {
  background: var(--surface-dark);
  color: var(--text);
  border-color: var(--border);
}
[data-theme="light"] .preview-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
}
[data-theme="light"] .side-panel-content::-webkit-scrollbar-thumb {
  background: var(--border);
}
[data-theme="light"] .command-list::-webkit-scrollbar-thumb {
  background: var(--border);
}
[data-theme="light"] .outline-item:hover {
  background: var(--hover-bg);
  color: var(--text);
}
[data-theme="light"] .outline-item.active {
  background: var(--primary-light);
}
[data-theme="light"] .modal-content {
  border-color: var(--border-light);
}
[data-theme="light"] .modal-header {
  border-color: var(--border-light);
}
[data-theme="light"] .modal-footer {
  border-color: var(--border-light);
}
[data-theme="light"] .modal-body {
  color: var(--text);
}
[data-theme="light"] .ai-tabs {
  border-color: var(--border);
}
[data-theme="light"] .ai-tabs,
[data-theme="light"] .ai-setting-input,
[data-theme="light"] .ai-setting-select,
[data-theme="light"] .ai-key-toggle {
  background: var(--surface-dark);
}
[data-theme="light"] .ai-tab.active {
  background: var(--surface);
}
[data-theme="light"] .ai-settings-body {
  color: var(--text);
}
[data-theme="light"] .ai-settings-footer {
  border-color: var(--border-light);
}
[data-theme="light"] .ai-config-status.ok {
  color: var(--primary);
}
[data-theme="light"] .ai-config-status.error {
  color: #dc2626;
}
[data-theme="light"] .toast {
  background: var(--surface-dark);
  color: #fff;
  box-shadow: var(--shadow-lg);
}
[data-theme="light"] .sp-search {
  background: var(--surface-dark);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .sp-setting-input {
  background: var(--surface-dark);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .sp-setting-input:focus {
  border-color: var(--primary);
}

/* ===== Toolbar Dropdown ===== */
.toolbar-more-wrap {
  position: relative;
}
.toolbar-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 300;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  padding: 6px 0;
  overflow: hidden;
}
.toolbar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  user-select: none;
}
.toolbar-dropdown-item:hover {
  background: var(--primary-light);
  color: var(--text);
}
.toolbar-dropdown-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}
.toolbar-dropdown-item:hover svg {
  opacity: 1;
}
.toolbar-dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}
.toolbar-kbd {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 1px 5px;
  background: var(--surface-dark);
  border-radius: 3px;
  font-family: inherit;
  font-weight: 500;
}
.toolbar-dropdown-item:hover .toolbar-kbd {
  color: var(--text-secondary);
}

/* ===== Publish Modal ===== */
.publish-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
}
.publish-tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.publish-tab:hover { color: var(--text); }
.publish-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.publish-pane {
  padding: 20px 22px;
}
.publish-pane h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.publish-pane ol {
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 16px;
}
.publish-preview-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg);
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 16px;
}
.publish-preview-box::-webkit-scrollbar { width: 4px; }
.publish-preview-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.publish-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.publish-export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.publish-export-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition);
}
.publish-export-card:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.publish-export-card svg {
  opacity: 0.7;
}
.publish-export-card span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.publish-export-card:hover span {
  color: var(--text);
}
