/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #667eea;
  --primary-light: #a5b4fc;
  --primary-dark: #4f46e5;
  --accent: #764ba2;
  --bg: #f0f2f5;
  --panel-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-secondary: #718096;
  --toolbar-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --font-mono: 'Menlo', 'Consolas', 'Monaco', monospace;
  /* WeChat theme colors */
  --wechat-heading: #667eea;
  --wechat-quote-border: #667eea;
  --wechat-quote-bg: #f6f8ff;
  --wechat-link: #576b95;
  --wechat-code-bg: #f6f8fa;
  --wechat-hr: linear-gradient(to right, transparent, #667eea, transparent);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 20px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 100;
  position: relative;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.toolbar-center, .toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.15);
}

.tool-btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border-color: transparent;
}

.tool-btn.primary:hover {
  opacity: 0.9;
  box-shadow: 0 2px 10px rgba(102, 126, 234, 0.35);
  color: white;
}

.tool-btn.sync-on {
  color: var(--primary);
  border-color: var(--primary-light);
  background: #f0f0ff;
}

.tool-btn.sync-off {
  color: var(--text-secondary);
  border-color: var(--border);
  background: white;
}

.tool-btn .icon {
  font-size: 15px;
}

/* ===== Dropdown Panels ===== */
.dropdown-panel {
  position: absolute;
  top: 56px;
  right: 20px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  z-index: 200;
  min-width: 280px;
}

.dropdown-panel.hidden {
  display: none;
}

.dropdown-panel h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

/* Theme Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.theme-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.theme-item:hover {
  background: var(--bg);
}

.theme-item.active {
  background: var(--bg);
  outline: 2px solid var(--primary);
}

.theme-preview {
  width: 48px;
  height: 32px;
  border-radius: 6px;
}

.theme-item span {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Settings */
.setting-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--bg);
}

.setting-group:last-child {
  border-bottom: none;
}

.setting-group label {
  font-size: 13px;
  color: var(--text);
}

.setting-group select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: white;
  color: var(--text);
  cursor: pointer;
}

/* ===== Main Layout ===== */
.main-container {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 300px;
}

.editor-panel {
  flex: 1;
  border-right: none;
}

.preview-panel {
  flex: 1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  min-height: 42px;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Editor Toolbar */
.editor-toolbar {
  display: flex;
  gap: 2px;
}

.edit-btn {
  width: 30px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.edit-btn:hover {
  background: var(--bg);
  color: var(--primary);
}

.edit-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 3px;
  align-self: center;
  display: inline-block;
}

/* Textarea */
#editor {
  flex: 1;
  padding: 20px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  background: #fafbfc;
  tab-size: 2;
}

#editor::placeholder {
  color: #cbd5e0;
}

/* ===== Resize Handle ===== */
.resize-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.2s;
  flex-shrink: 0;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--primary);
}

/* ===== Preview ===== */
.preview-wrapper {
  flex: 1;
  overflow-y: auto;
  background: #e9ecef;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

.preview-content {
  width: 100%;
  max-width: 375px;
  background: white;
  padding: 24px 16px;
  min-height: calc(100vh - 56px - 42px - 40px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  border-radius: 4px;
  transition: max-width 0.3s ease;
}

.preview-content.full-width {
  max-width: 100%;
  padding: 30px 40px;
}

/* Preview Mode Buttons */
.preview-toolbar {
  display: flex;
  gap: 4px;
}

.preview-mode-btn {
  width: 30px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}

.preview-mode-btn.active {
  background: var(--bg);
  border-color: var(--border);
}

/* ===== WeChat Article Styles ===== */
.wechat-style {
  font-size: 15px;
  line-height: 1.75;
  color: #333;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.wechat-style h1 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin: 24px 0 16px;
  padding-bottom: 12px;
  color: var(--wechat-heading);
  border-bottom: 2px solid var(--wechat-heading);
  line-height: 1.4;
}

.wechat-style h2 {
  font-size: 19px;
  font-weight: 700;
  margin: 24px 0 12px;
  padding: 4px 0 4px 12px;
  color: var(--wechat-heading);
  border-left: 4px solid var(--wechat-heading);
  line-height: 1.4;
}

.wechat-style h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 20px 0 10px;
  color: var(--wechat-heading);
  line-height: 1.4;
}

.wechat-style h3::before {
  content: '# ';
  color: var(--wechat-heading);
  opacity: 0.5;
}

.wechat-style h4, .wechat-style h5, .wechat-style h6 {
  font-size: 15px;
  font-weight: 700;
  margin: 16px 0 8px;
  color: #555;
}

.wechat-style p {
  margin: 0 0 1em 0;
  line-height: inherit;
}

.wechat-style strong {
  color: var(--wechat-heading);
  font-weight: 700;
}

.wechat-style em {
  font-style: italic;
  color: #555;
}

.wechat-style blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  background: var(--wechat-quote-bg);
  border-left: 4px solid var(--wechat-quote-border);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #666;
  font-size: 14px;
}

.wechat-style blockquote p {
  margin: 0;
  text-indent: 0 !important;
}

.wechat-style a {
  color: var(--wechat-link);
  text-decoration: none;
  border-bottom: 1px solid var(--wechat-link);
  word-break: break-all;
}

.wechat-style ul, .wechat-style ol {
  margin: 12px 0;
  padding-left: 2em;
}

.wechat-style li {
  margin: 6px 0;
  line-height: inherit;
}

.wechat-style ul li {
  list-style-type: disc;
}

.wechat-style ul li::marker {
  color: var(--wechat-heading);
}

.wechat-style ol li::marker {
  color: var(--wechat-heading);
  font-weight: 600;
}

.wechat-style code {
  background: var(--wechat-code-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--wechat-heading);
  word-break: break-all;
}

/* Code block: light theme with line numbers */
.wechat-style .code-block-wrapper {
  border: 1px solid #ddd5c2;
  border-radius: 6px;
  margin: 16px 0;
  overflow: hidden;
  font-size: 13px;
  background: #fdf6e3;
}

.wechat-style .code-header {
  background: #ece4d4;
  padding: 5px 14px;
  color: #999;
  font-size: 12px;
  font-family: var(--font-mono);
  border-bottom: 1px solid #ddd5c2;
  line-height: 1.8;
}

.wechat-style .code-scroll-area {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.wechat-style .code-table {
  border-collapse: collapse;
  min-width: 100%;
  background: #fdf6e3;
}

.wechat-style .code-lines {
  padding: 12px 10px;
  color: #c5b89a;
  text-align: right;
  vertical-align: top;
  border-right: 1px solid #ddd5c2;
  background: #f6efe0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  user-select: none;
  -webkit-user-select: none;
  width: 1%;
}

.wechat-style .code-content {
  padding: 12px 16px;
  vertical-align: top;
}

/* Override atom-one-light defaults inside the new code block */
.wechat-style .code-content .hljs {
  background: transparent !important;
  padding: 0 !important;
  overflow-x: visible;
  display: block;
  white-space: pre;
  tab-size: 4;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.6;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #383a42;
}

.wechat-style img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 12px 0;
  display: block;
}

.wechat-style hr {
  border: none;
  height: 2px;
  background: var(--wechat-hr);
  margin: 24px 0;
}

.wechat-style table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid #e2e8f0;
}

.wechat-style thead {
  background: var(--wechat-heading);
  color: white;
}

.wechat-style th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
}

.wechat-style td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf2f7;
}

.wechat-style tbody tr:nth-child(even) {
  background: #f7fafc;
}

.wechat-style tbody tr:hover {
  background: var(--wechat-quote-bg);
}

/* ===== Modal Dialog ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: white;
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal-box h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text);
}

.modal-box p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.6;
}

.modal-hint {
  font-size: 12px !important;
  color: #a0aec0 !important;
  background: var(--bg);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 16px !important;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: white;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ===== Theme Overrides ===== */
.theme-green {
  --wechat-heading: #11998e;
  --wechat-quote-border: #11998e;
  --wechat-quote-bg: #f0fdf9;
  --wechat-link: #0e7c6b;
  --wechat-hr: linear-gradient(to right, transparent, #11998e, transparent);
}

.theme-orange {
  --wechat-heading: #e8590c;
  --wechat-quote-border: #e8590c;
  --wechat-quote-bg: #fff5f0;
  --wechat-link: #c2410c;
  --wechat-hr: linear-gradient(to right, transparent, #e8590c, transparent);
}

.theme-blue {
  --wechat-heading: #2563eb;
  --wechat-quote-border: #2563eb;
  --wechat-quote-bg: #eff6ff;
  --wechat-link: #1d4ed8;
  --wechat-hr: linear-gradient(to right, transparent, #2563eb, transparent);
}

.theme-dark {
  --wechat-heading: #555;
  --wechat-quote-border: #555;
  --wechat-quote-bg: #f5f5f5;
  --wechat-link: #333;
  --wechat-hr: linear-gradient(to right, transparent, #555, transparent);
}

.theme-red {
  --wechat-heading: #dc2626;
  --wechat-quote-border: #dc2626;
  --wechat-quote-bg: #fef2f2;
  --wechat-link: #b91c1c;
  --wechat-hr: linear-gradient(to right, transparent, #dc2626, transparent);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .toolbar {
    padding: 0 10px;
    gap: 4px;
  }

  .tool-btn span:not(.icon) {
    display: none;
  }

  .tool-btn {
    padding: 7px 10px;
  }

  .main-container {
    flex-direction: column;
  }

  .resize-handle {
    width: 100%;
    height: 6px;
    cursor: row-resize;
  }

  .panel {
    min-width: unset;
    min-height: 200px;
  }
}
