/* ============================================
   MD转微信公众号格式免费在线转换器 - Main Stylesheet
   ============================================ */

/* --- CSS Custom Properties (Theme System) --- */
:root,
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --bg-hover: #f0f0f0;
  --bg-active: #e5e7eb;
  --bg-editor: #ffffff;
  --bg-preview: #ffffff;
  --bg-sidebar: #f9fafb;
  --bg-header: #ffffff;
  --bg-toolbar: #ffffff;
  --bg-modal: #ffffff;
  --bg-overlay: rgba(0, 0, 0, 0.5);
  --bg-code: #f6f8fa;
  --bg-dropdown: #ffffff;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-inverse: #ffffff;
  --text-link: #2563eb;
  --text-code: #e74c3c;

  --border-light: #e5e7eb;
  --border-medium: #d1d5db;
  --border-strong: #9ca3af;

  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --accent-primary-light: #dbeafe;
  --accent-secondary: #22d3ee;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-2xl: 16px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Menlo", "Courier New", monospace;
  --font-size-base: 14px;
  --font-size-sm: 12px;
  --font-size-lg: 16px;
  --font-size-xl: 18px;
  --font-size-2xl: 24px;

  --editor-font-size: 15px;
  --editor-line-height: 1.7;
  --editor-font-family: var(--font-sans);

  --preview-font-size: 15px;
  --preview-line-height: 1.8;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s ease;

  --sidebar-width: 48px;
  --header-height: 48px;
  --panel-header-height: 36px;
  --panel-footer-height: 28px;

  scrollbar-color: #d1d5db transparent;
  scrollbar-width: thin;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-hover: #334155;
  --bg-active: #475569;
  --bg-editor: #0f172a;
  --bg-preview: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-header: #1e293b;
  --bg-toolbar: #1e293b;
  --bg-modal: #1e293b;
  --bg-overlay: rgba(0, 0, 0, 0.7);
  --bg-code: #1e293b;
  --bg-dropdown: #1e293b;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --text-inverse: #0f172a;
  --text-link: #60a5fa;
  --text-code: #f472b6;

  --border-light: #334155;
  --border-medium: #475569;
  --border-strong: #64748b;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #60a5fa;
  --accent-primary-light: #1e3a5f;
  --accent-secondary: #22d3ee;
  --accent-success: #34d399;
  --accent-warning: #fbbf24;
  --accent-danger: #f87171;

  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -4px rgba(0,0,0,0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.4);

  scrollbar-color: #475569 transparent;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-hover: #334155;
    --bg-active: #475569;
    --bg-editor: #0f172a;
    --bg-preview: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-header: #1e293b;
    --bg-toolbar: #1e293b;
    --bg-modal: #1e293b;
    --bg-overlay: rgba(0, 0, 0, 0.7);
    --bg-code: #1e293b;
    --bg-dropdown: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-inverse: #0f172a;
    --text-link: #60a5fa;
    --text-code: #f472b6;

    --border-light: #334155;
    --border-medium: #475569;
    --border-strong: #64748b;

    --accent-primary: #3b82f6;
    --accent-primary-hover: #60a5fa;
    --accent-primary-light: #1e3a5f;

    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -2px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -4px rgba(0,0,0,0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.4);

    scrollbar-color: #475569 transparent;
  }
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: var(--font-size-base); }

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* --- App Layout --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  gap: 8px;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
}
.logo:hover { text-decoration: none; }
.logo svg { width: 26px; height: 26px; flex-shrink: 0; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.toolbar-btn:active, .toolbar-btn.active {
  background: var(--bg-active);
  color: var(--accent-primary);
}
.toolbar-btn .btn-label { display: none; }
@media (min-width: 900px) {
  .toolbar-btn .btn-label { display: inline; margin-left: 2px; }
}

.toolbar-btn.btn-primary {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}
.toolbar-btn.btn-primary:hover {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

.toolbar-btn.btn-sm {
  padding: 3px 6px;
  font-size: 12px;
}
.toolbar-btn.btn-sm i { font-style: italic; }
.toolbar-btn.btn-sm b { font-weight: 700; }

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-light);
  margin: 0 4px;
}

/* Status Bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  white-space: nowrap;
}
.status-sep { color: var(--border-light); }
.status-save.saving { color: var(--accent-warning); }
.status-save.saved { color: var(--accent-success); }
.status-save.error { color: var(--accent-danger); }

/* --- Sidebar --- */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  flex-shrink: 0;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  position: relative;
}
.sidebar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-btn.active { background: var(--accent-primary-light); color: var(--accent-primary); }
.sidebar-btn svg { width: 20px; height: 20px; }

.sidebar-spacer { flex: 1; }

/* --- Content Area --- */
.app-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* --- Panels --- */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-light);
}
.panel:last-child { border-right: none; }

.panel.panel-editor {
  flex: 1;
  min-width: 300px;
}

.panel.panel-preview {
  flex: 1;
  min-width: 300px;
  display: none;
}
.panel.panel-preview.visible { display: flex; }

.panel-header {
  display: flex;
  align-items: center;
  height: var(--panel-header-height);
  padding: 0 10px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary);
  flex-shrink: 0;
  gap: 4px;
}
.panel-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.panel-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.panel-footer {
  display: flex;
  align-items: center;
  height: var(--panel-footer-height);
  padding: 0 10px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-tertiary);
  gap: 12px;
}

.editor-info { margin-right: auto; }
.word-wrap-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.word-wrap-toggle input { accent-color: var(--accent-primary); }

/* --- Editor --- */
.editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.editor-line-numbers {
  width: 44px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  padding: 12px 8px 12px 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  color: var(--text-tertiary);
  overflow: hidden;
  user-select: none;
  padding-top: 12px;
}
.editor-line-numbers span {
  display: block;
  line-height: var(--editor-line-height);
}

.editor-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 12px 16px;
  font-family: var(--editor-font-family);
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  color: var(--text-primary);
  background: var(--bg-editor);
  tab-size: 4;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.editor-input::placeholder { color: var(--text-tertiary); }
.editor-input.word-wrap-off { white-space: pre; overflow-x: auto; }

/* --- Preview --- */
.preview-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg-preview);
  scroll-behavior: smooth;
}
.preview-container .preview-content {
  max-width: 677px;
  margin: 0 auto;
}

/* Mobile Frame */
.preview-container.mobile-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--bg-tertiary);
}
.mobile-frame {
  width: 375px;
  min-height: 667px;
  max-height: 85vh;
  background: var(--bg-preview);
  border-radius: 40px;
  border: 2px solid var(--border-medium);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  margin: 20px auto;
}
.mobile-frame .mobile-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-preview);
  flex-shrink: 0;
}
.mobile-frame .mobile-status-bar .mobile-icons {
  display: flex;
  gap: 4px;
  align-items: center;
}
.mobile-frame .mobile-status-bar svg { width: 14px; height: 14px; }
.mobile-frame .mobile-notch {
  width: 150px;
  height: 24px;
  background: var(--text-primary);
  border-radius: 0 0 16px 16px;
  margin: 0 auto;
  flex-shrink: 0;
}
.mobile-frame .mobile-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 24px;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-primary);
}
.mobile-frame .mobile-content::-webkit-scrollbar { width: 2px; }
.mobile-frame .mobile-bottom-bar {
  height: 34px;
  flex-shrink: 0;
  background: var(--bg-preview);
  border-top: 1px solid var(--border-light);
}

/* Preview Typography */
.preview-content { font-size: var(--preview-font-size); line-height: var(--preview-line-height); }
.preview-content h1, .preview-content h2, .preview-content h3,
.preview-content h4, .preview-content h5, .preview-content h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}
.preview-content h1 { font-size: 1.8em; border-bottom: 1px solid var(--border-light); padding-bottom: 0.3em; }
.preview-content h2 { font-size: 1.5em; border-bottom: 1px solid var(--border-light); padding-bottom: 0.2em; }
.preview-content h3 { font-size: 1.25em; }
.preview-content h4 { font-size: 1.1em; }
.preview-content h5, .preview-content h6 { font-size: 1em; }
.preview-content p { margin: 0.8em 0; }
.preview-content a { color: var(--text-link); }
.preview-content a:hover { text-decoration: underline; }
.preview-content blockquote {
  margin: 1em 0;
  padding: 0.5em 1em;
  border-left: 4px solid var(--accent-primary);
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.preview-content blockquote p { margin: 0.3em 0; }
.preview-content ul, .preview-content ol { margin: 0.8em 0; padding-left: 2em; }
.preview-content li { margin: 0.3em 0; }
.preview-content li > ul, .preview-content li > ol { margin: 0.2em 0; }
.preview-content hr { border: none; border-top: 2px solid var(--border-light); margin: 2em 0; }
.preview-content img { max-width: 100%; height: auto; border-radius: var(--radius-md); margin: 1em 0; }
.preview-content table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 0.9em; }
.preview-content th, .preview-content td {
  border: 1px solid var(--border-medium);
  padding: 8px 12px;
  text-align: left;
}
.preview-content th { background: var(--bg-secondary); font-weight: 600; }
.preview-content tr:nth-child(even) { background: var(--bg-secondary); }
.preview-content pre {
  position: relative;
  margin: 1em 0;
  border-radius: var(--radius-lg);
  background: var(--bg-code);
  border: 1px solid var(--border-light);
  overflow: hidden;
}
.preview-content pre code {
  display: block;
  padding: 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
}
.preview-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-code);
}
.preview-content pre code { background: transparent; padding: 16px; }
.preview-content .copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.preview-content pre:hover .copy-code-btn { opacity: 1; }
.preview-content .copy-code-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.preview-content .katex-block { text-align: center; margin: 1em 0; overflow-x: auto; overflow-y: hidden; }
.preview-content .mermaid-container {
  text-align: center;
  margin: 1.5em 0;
  padding: 1em;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
}
.preview-content .mermaid-container svg { max-width: 100%; }

/* --- Dialogs --- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.dialog {
  background: var(--bg-modal);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 90vw;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: scaleIn 0.25s ease;
}
.dialog-sm { width: 400px; }
.dialog-md { width: 560px; }
.dialog-lg { width: 720px; }
.dialog-xl { width: 900px; }
.dialog-full { width: 95vw; height: 90vh; }

.dialog-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.dialog-title {
  font-size: 16px;
  font-weight: 700;
  flex: 1;
}
.dialog-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}
.dialog-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.dialog-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-light);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}
.btn-primary:hover { background: var(--accent-primary-hover); }
.btn-success { background: var(--accent-success); color: white; border-color: var(--accent-success); }
.btn-danger { background: var(--accent-danger); color: white; border-color: var(--accent-danger); }
.btn-warning { background: var(--accent-warning); color: white; border-color: var(--accent-warning); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Template Selector Dropdown --- */
.dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 200;
  background: var(--bg-dropdown);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  max-height: 400px;
  overflow-y: auto;
  display: none;
}
.dropdown.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.active { background: var(--accent-primary-light); color: var(--accent-primary); }
.dropdown-header {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-modal);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
.toast-success { border-left: 3px solid var(--accent-success); }
.toast-error { border-left: 3px solid var(--accent-danger); }
.toast-info { border-left: 3px solid var(--accent-primary); }
.toast-warning { border-left: 3px solid var(--accent-warning); }

/* --- Tabs --- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
}
.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-primary); border-bottom-color: var(--accent-primary); }

/* --- Switch --- */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.switch-track {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--border-medium);
  transition: background var(--transition-fast);
  position: relative;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .switch-track { background: var(--accent-primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

/* --- Error Page --- */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  text-align: center;
  padding: 20px;
}
.error-page h1 { font-size: 72px; color: var(--accent-primary); margin: 0; }
.error-page p { color: var(--text-secondary); font-size: 16px; }

/* --- Loading Screen --- */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s ease, visibility 0.4s;
}
.loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-logo { margin-bottom: 20px; }
.loading-logo svg { width: 64px; height: 64px; }
.loading-title { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.loading-bar {
  width: 200px;
  height: 3px;
  background: var(--bg-tertiary);
  border-radius: 999px;
  margin-top: 24px;
  overflow: hidden;
}
.loading-bar-progress {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 999px;
  animation: loadingProgress 1.5s infinite ease-in-out;
}

/* --- Template Grid --- */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.template-card {
  border: 2px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}
.template-card:hover { border-color: var(--accent-primary); box-shadow: var(--shadow-md); }
.template-card.active { border-color: var(--accent-primary); background: var(--accent-primary-light); }
.template-card-preview {
  height: 120px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--text-tertiary);
  overflow: hidden;
  position: relative;
}
.template-card-preview .tpl-line {
  position: absolute;
  height: 4px;
  border-radius: 2px;
  opacity: 0.7;
}
.template-card-preview .tpl-line:nth-child(1) { width: 60%; top: 24px; left: 16px; }
.template-card-preview .tpl-line:nth-child(2) { width: 40%; top: 36px; left: 16px; }
.template-card-preview .tpl-line:nth-child(3) { width: 80%; top: 56px; left: 16px; }
.template-card-preview .tpl-line:nth-child(4) { width: 30%; top: 68px; left: 16px; }
.template-card-preview .tpl-line:nth-child(5) { width: 70%; top: 88px; left: 16px; }
.template-card-preview .tpl-block {
  position: absolute;
  width: 12px; height: 12px;
  border-radius: 3px;
  top: 16px; right: 16px;
  opacity: 0.25;
}
.template-card-preview .tpl-block2 {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 2px;
  top: 16px; right: 34px;
  opacity: 0.15;
}
.template-card-preview .tpl-accent {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 0;
}
.template-card-preview .tpl-head-accent {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.template-card-name { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.template-card-category { font-size: 10px; color: var(--text-tertiary); margin-top: 2px; }

/* --- Image Upload Area --- */
.upload-zone {
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-light);
}
.upload-zone-icon { font-size: 32px; color: var(--text-tertiary); margin-bottom: 8px; }
.upload-zone-text { color: var(--text-secondary); font-size: 13px; }

/* --- Outline Panel --- */
.outline-container { padding: 12px; }
.outline-item {
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition-fast);
}
.outline-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.outline-item.h1 { font-weight: 700; font-size: 14px; padding-left: 8px; }
.outline-item.h2 { font-weight: 600; padding-left: 20px; }
.outline-item.h3 { padding-left: 32px; }
.outline-item.h4 { padding-left: 44px; }
.outline-item.h5 { padding-left: 56px; }
.outline-item.h6 { padding-left: 68px; }

/* --- Help Page --- */
.help-container { padding: 24px; max-width: 720px; margin: 0 auto; }
.help-container h2 { font-size: 20px; margin-top: 24px; margin-bottom: 12px; }
.help-container h3 { font-size: 16px; margin-top: 16px; margin-bottom: 8px; }
.help-container p { margin: 8px 0; line-height: 1.7; color: var(--text-secondary); }
.help-container ul, .help-container ol { margin: 8px 0; padding-left: 20px; }
.help-container li { margin: 4px 0; color: var(--text-secondary); }
.help-container kbd {
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.help-container .shortcut-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}

/* --- Color Swatches --- */
.color-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  max-width: 40px;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--text-primary); }

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes loadingProgress {
  0% { left: -40%; }
  100% { left: 100%; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .panel.panel-editor { min-width: 0; }
  .editor-line-numbers { display: none; }
  .dialog { max-width: 100vw; max-height: 100vh; border-radius: 0; width: 100% !important; }
  .template-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .status-bar { display: none; }
  .header-actions .toolbar-btn .btn-label { display: none; }
  .app-header { padding: 0 8px; gap: 4px; }
}
