/* ========================================
   Rich Text Editor Styles (Quill.js)
   ======================================== */

/* 富文本编辑器容器 */
.rich-editor-container {
  display: none;
  flex-direction: column;
  height: 100%;
  background: var(--bg-primary);
  border-radius: 8px;
  overflow: hidden;
}

.rich-editor-container.active {
  display: flex;
}

/* ========================================
   固定工具栏样式
   ======================================== */
.rich-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  min-height: 44px;
}

.rich-toolbar .toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  border-right: 1px solid var(--border-color);
}

.rich-toolbar .toolbar-group:last-child {
  border-right: none;
}

.rich-toolbar .toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.rich-toolbar .toolbar-btn:hover {
  background: var(--bg-hover);
}

.rich-toolbar .toolbar-btn.active {
  background: var(--primary-color);
  color: #fff;
}

.rich-toolbar .toolbar-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 标题按钮 */
.rich-toolbar .toolbar-btn.heading-btn {
  font-weight: 700;
  font-size: 12px;
}

/* 对齐按钮图标 */
.rich-toolbar .toolbar-btn .align-icon {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 14px;
}

.rich-toolbar .toolbar-btn .align-icon span {
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.rich-toolbar .toolbar-btn .align-icon.align-left span:nth-child(1) { width: 100%; }
.rich-toolbar .toolbar-btn .align-icon.align-left span:nth-child(2) { width: 70%; }
.rich-toolbar .toolbar-btn .align-icon.align-left span:nth-child(3) { width: 85%; }

.rich-toolbar .toolbar-btn .align-icon.align-center span:nth-child(1) { width: 80%; margin: 0 auto; }
.rich-toolbar .toolbar-btn .align-icon.align-center span:nth-child(2) { width: 100%; }
.rich-toolbar .toolbar-btn .align-icon.align-center span:nth-child(3) { width: 70%; margin: 0 auto; }

.rich-toolbar .toolbar-btn .align-icon.align-right span:nth-child(1) { width: 85%; margin-left: auto; }
.rich-toolbar .toolbar-btn .align-icon.align-right span:nth-child(2) { width: 100%; }
.rich-toolbar .toolbar-btn .align-icon.align-right span:nth-child(3) { width: 70%; margin-left: auto; }

/* 颜色选择器 */
.color-picker-container {
  position: relative;
}

.color-picker-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.15s ease;
  position: relative;
}

.color-picker-trigger:hover {
  background: var(--bg-hover);
}

.color-picker-trigger .color-indicator {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 3px;
  border-radius: 1px;
  background: currentColor;
}

.color-picker-trigger.text-color .color-indicator {
  background: var(--current-text-color, #000);
}

.color-picker-trigger.bg-color .color-indicator {
  background: var(--current-bg-color, #ffeb3b);
}

.color-picker-trigger.underline-color .color-indicator {
  background: var(--current-underline-color, #f56c6c);
}

.color-picker-panel {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 4px;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: none;
}

.color-picker-panel.visible {
  display: block;
  z-index: 10001;
}

.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 24px);
  gap: 4px;
}

.color-picker-grid .color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s ease;
}

.color-picker-grid .color-swatch:hover {
  transform: scale(1.1);
  border-color: var(--primary-color);
}

.color-picker-grid .color-swatch.no-color {
  background: linear-gradient(135deg, #fff 45%, #f56c6c 45%, #f56c6c 55%, #fff 55%);
  border: 1px solid var(--border-color);
}

/* 字体选择器 */
.font-selector {
  position: relative;
}

.font-selector-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  height: 32px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 12px;
  min-width: 100px;
  transition: all 0.15s ease;
}

.font-selector-btn:hover {
  border-color: var(--primary-color);
}

.font-selector-btn .arrow {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.6;
}

.font-selector-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 150px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: none;
}

.font-selector-dropdown.visible {
  display: block;
  z-index: 10001;
}

.font-selector-dropdown .font-option {
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.font-selector-dropdown .font-option:hover {
  background: var(--bg-hover);
}

.font-selector-dropdown .font-option.active {
  background: var(--primary-color);
  color: #fff;
}

/* 链接输入框 */
.link-input-popup {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 4px;
  padding: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: none;
  min-width: 280px;
}

.link-input-popup.visible {
  display: block;
}

.link-input-popup .link-input-group {
  display: flex;
  gap: 8px;
}

.link-input-popup input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
}

.link-input-popup input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.link-input-popup .link-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  background: var(--primary-color);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s ease;
}

.link-input-popup .link-btn:hover {
  background: var(--primary-color-dark);
}

/* ========================================
   浮动工具栏样式
   ======================================== */
.rich-floating-toolbar {
  position: fixed;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  transform: translateX(-50%);
}

.rich-floating-toolbar.visible {
  display: flex;
}

.rich-floating-toolbar::before {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  transform: translateX(-50%) rotate(45deg);
}

.rich-floating-toolbar .toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.rich-floating-toolbar .toolbar-btn:hover {
  background: var(--bg-hover);
}

.rich-floating-toolbar .toolbar-btn.active {
  background: var(--primary-color);
  color: #fff;
}

.rich-floating-toolbar .toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}

/* 浮动工具栏颜色选择器 */
.rich-floating-toolbar .color-picker-container {
  position: relative;
}

.rich-floating-toolbar .color-picker-panel {
  bottom: 100%;
  top: auto;
  margin-bottom: 8px;
  margin-top: 0;
}

.rich-floating-toolbar .color-picker-panel::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--bg-primary);
}

/* ========================================
   Quill 编辑器覆盖样式
   ======================================== */
.rich-editor-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.rich-editor-wrapper .ql-container {
  height: 100%;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 18px;
  line-height: 1.8;
  border: none;
}

.rich-editor-wrapper .ql-editor {
  padding: 32px 48px;
  color: var(--text-primary);
  background: var(--bg-primary);
}

/* 确保Quill内联样式颜色优先级高于主题 - 不覆盖内联style */
.rich-editor-wrapper .ql-editor p,
.rich-editor-wrapper .ql-editor h1,
.rich-editor-wrapper .ql-editor h2,
.rich-editor-wrapper .ql-editor h3 {
  color: var(--text-primary);
}

/* 内联样式span元素保留原有样式，让style属性生效 */

/* Grammar Check 错误标记样式（红色波浪线 - 使用 SVG 背景图片实现，最可靠的跨浏览器方案） */
.rich-editor-wrapper .ql-editor .quill-error-mark,
.ql-editor .quill-error-mark,
span.quill-error-mark {
  /* SVG 波浪线背景 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='6' height='3' viewBox='0 0 6 3'%3E%3Cpath d='M0 3 Q 1.5 0, 3 3 T 6 3' stroke='%23f56c6c' fill='none' stroke-width='1'/%3E%3C/svg%3E") !important;
  background-repeat: repeat-x !important;
  background-position: bottom !important;
  background-size: 6px 3px !important;
  padding-bottom: 3px !important;
  background-color: rgba(245, 108, 108, 0.1) !important;
  cursor: pointer !important;
  position: relative;
  border-radius: 2px;
  /* 移除 text-decoration 避免冲突 */
  text-decoration: none !important;
}

.rich-editor-wrapper .ql-editor .quill-error-mark:hover,
.ql-editor .quill-error-mark:hover,
span.quill-error-mark:hover {
  background-color: rgba(245, 108, 108, 0.25) !important;
}

/* Grammar Check 提示气泡 */
.quill-error-tooltip {
  position: fixed;
  z-index: 10002;
  display: none;
  max-width: 300px;
  padding: 10px 14px;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 13px;
  line-height: 1.5;
  transform: translateX(-50%);
  pointer-events: none;
}

.quill-error-tooltip::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: var(--bg-primary, #fff);
}

.quill-error-tooltip .tooltip-suggestion {
  color: var(--text-primary, #333);
  margin-bottom: 4px;
}

.quill-error-tooltip .tooltip-suggestion strong {
  color: #67c23a;
}

.quill-error-tooltip .tooltip-reason {
  color: var(--text-secondary, #666);
  font-size: 12px;
}

.quill-error-tooltip .tooltip-reason strong {
  color: #e6a23c;
}

/* 暗色主题提示气泡 */
[data-theme="dark"] .quill-error-tooltip,
.dark .quill-error-tooltip {
  background: #252526;
  border-color: #3c3c3c;
}

[data-theme="dark"] .quill-error-tooltip::before,
.dark .quill-error-tooltip::before {
  border-bottom-color: #252526;
}

.rich-editor-wrapper .ql-editor:focus {
  outline: none;
}

/* 标题样式 */
.rich-editor-wrapper .ql-editor h1 {
  font-size: 2em;
  font-weight: 700;
  margin: 1em 0 0.5em;
  color: var(--text-primary);
}

.rich-editor-wrapper .ql-editor h2 {
  font-size: 1.5em;
  font-weight: 600;
  margin: 0.8em 0 0.4em;
  color: var(--text-primary);
}

.rich-editor-wrapper .ql-editor h3 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0.6em 0 0.3em;
  color: var(--text-primary);
}

/* 段落样式 */
.rich-editor-wrapper .ql-editor p {
  margin: 0.5em 0;
}

/* 链接样式 */
.rich-editor-wrapper .ql-editor a {
  color: var(--primary-color);
  text-decoration: underline;
}

.rich-editor-wrapper .ql-editor a:hover {
  opacity: 0.8;
}

/* 对齐 */
.rich-editor-wrapper .ql-editor .ql-align-center {
  text-align: center;
}

.rich-editor-wrapper .ql-editor .ql-align-right {
  text-align: right;
}

.rich-editor-wrapper .ql-editor .ql-align-justify {
  text-align: justify;
}

/* 隐藏 Quill 默认工具栏 */
.rich-editor-wrapper .ql-toolbar {
  display: none !important;
}

/* 占位符 */
.rich-editor-wrapper .ql-editor.ql-blank::before {
  color: var(--text-secondary);
  font-style: italic;
  left: 48px;
  right: 48px;
  top: 40px;
}

/* ========================================
   暗色主题适配
   ======================================== */
[data-theme="dark"] .rich-toolbar,
.dark .rich-toolbar {
  background: #1e1e1e;
  border-color: #3c3c3c;
}

[data-theme="dark"] .rich-toolbar .toolbar-btn,
.dark .rich-toolbar .toolbar-btn {
  color: #e0e0e0;
}

[data-theme="dark"] .rich-toolbar .toolbar-btn:hover,
.dark .rich-toolbar .toolbar-btn:hover {
  background: #333;
}

[data-theme="dark"] .color-picker-panel,
.dark .color-picker-panel,
[data-theme="dark"] .font-selector-dropdown,
.dark .font-selector-dropdown,
[data-theme="dark"] .link-input-popup,
.dark .link-input-popup {
  background: #252526;
  border-color: #3c3c3c;
}

[data-theme="dark"] .rich-floating-toolbar,
.dark .rich-floating-toolbar {
  background: #252526;
  border-color: #3c3c3c;
}

[data-theme="dark"] .rich-floating-toolbar::before,
.dark .rich-floating-toolbar::before {
  background: #252526;
  border-color: #3c3c3c;
}

[data-theme="dark"] .rich-editor-wrapper .ql-editor,
.dark .rich-editor-wrapper .ql-editor {
  background: #1e1e1e;
  color: #e0e0e0;
}

[data-theme="dark"] .font-selector-btn,
.dark .font-selector-btn {
  background: #333;
  border-color: #3c3c3c;
  color: #e0e0e0;
}

[data-theme="dark"] .link-input-popup input,
.dark .link-input-popup input {
  background: #333;
  border-color: #3c3c3c;
  color: #e0e0e0;
}

/* ========================================
   响应式调整
   ======================================== */
@media (max-width: 768px) {
  .rich-toolbar {
    padding: 6px 8px;
    gap: 2px;
  }
  
  .rich-toolbar .toolbar-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .rich-toolbar .toolbar-group {
    padding: 0 4px;
  }
  
  .rich-editor-wrapper .ql-editor {
    padding: 20px 24px;
    font-size: 16px;
  }
  
  .font-selector-btn {
    min-width: 80px;
    font-size: 11px;
  }
}

