/* Rich Text Editor Styles */
.rich-text-editor {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  margin-bottom: 1rem;
  overflow: hidden;
}

.rich-text-toolbar {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  gap: 0;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px;
  margin-right: 4px;
}

.toolbar-group.all-tools-group {
  gap: 0;
  padding: 1px 2px;
  border: 1px solid var(--primary-color);
  background: var(--bg-primary);
  border-radius: 6px;
}

.toolbar-select {
  padding: 2px 4px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  margin: 0 2px;
  min-width: 60px;
  height: 22px;
}

.toolbar-select:hover {
  border-color: var(--primary-color);
  background: var(--bg-secondary);
}

.toolbar-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.2);
}

.dropdown-btn {
  position: relative;
  font-weight: bold;
  font-size: 12px;
}

.dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  min-width: 40px;
  padding: 2px;
}

.dropdown-option {
  display: block;
  width: 100%;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  border-radius: 2px;
  transition: all 0.15s ease;
}

.dropdown-option:hover {
  background: var(--primary-color);
  color: white;
}

.toolbar-btn {
  padding: 4px 6px;
  border: none;
  background: transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  transition: all 0.15s ease;
  min-width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 1px;
}

.toolbar-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: scale(1.05);
}

.toolbar-btn.active {
  background: var(--primary-color);
  color: white;
}

.toolbar-btn:focus {
  outline: 1px solid var(--primary-color);
  outline-offset: 1px;
}

/* Compact color picker styles */
.highlight-wrapper.compact {
  position: relative;
  display: inline-block;
}

.color-picker.compact {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  min-width: 80px;
}

.color-option.compact {
  width: 16px;
  height: 16px;
  border: 1px solid #fff;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  font-size: 10px;
}

.color-option.compact:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Highlight Color Picker */
.highlight-wrapper {
  position: relative;
  display: inline-block;
}

.highlight-btn {
  position: relative;
}

.color-picker {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  min-width: 120px;
}

.color-option {
  width: 24px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.color-option:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.color-option:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 4px;
}

.rich-text-content {
  padding: 16px 20px;
  min-height: 150px;
  max-height: 400px;
  overflow-y: auto;
  outline: none;
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: none;
  resize: none;
}

.rich-text-content:empty::before {
  content: attr(placeholder);
  color: var(--text-secondary);
  opacity: 0.7;
  font-style: italic;
}

.rich-text-content p {
  margin: 0 0 8px 0;
}

.rich-text-content p:last-child {
  margin-bottom: 0;
}

.rich-text-content ul,
.rich-text-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.rich-text-content li {
  margin-bottom: 4px;
}

.rich-text-content a {
  color: var(--primary-color);
  text-decoration: underline;
}

.rich-text-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 8px 0;
}

.rich-text-content strong,
.rich-text-content b {
  font-weight: 600;
}

.rich-text-content em,
.rich-text-content i {
  font-style: italic;
}

.rich-text-content u {
  text-decoration: underline;
}

.char-counter {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  min-width: 80px;
  text-align: center;
}

.char-counter.over-limit {
  color: var(--error-color);
  font-weight: 600;
}

/* Dark theme adjustments */
[data-theme="dark"] .rich-text-editor {
  border-color: var(--border-color);
}

[data-theme="dark"] .rich-text-toolbar {
  background: var(--bg-secondary);
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .rich-text-content {
  background: var(--bg-primary);
  color: var(--text-primary);
}

[data-theme="dark"] .char-counter {
  background: var(--bg-secondary);
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .rich-text-toolbar {
    padding: 6px 8px;
    gap: 2px;
  }
  
  .toolbar-btn {
    padding: 4px 6px;
    font-size: 12px;
    min-width: 28px;
    height: 28px;
  }
  
  .toolbar-separator {
    height: 20px;
    margin: 0 2px;
  }
  
  .rich-text-content {
    padding: 10px 12px;
    font-size: 13px;
  }
  
  .char-counter {
    font-size: 11px;
    padding: 2px 6px;
    min-width: 70px;
  }
}

/* Focus states for accessibility */
.rich-text-content:focus {
  box-shadow: 0 0 0 2px var(--primary-color);
}

.rich-text-editor:focus-within {
  border-color: var(--primary-color);
}

/* Error state */
.rich-text-editor.error {
  border-color: var(--error-color);
}

.rich-text-editor.error .rich-text-content:focus {
  box-shadow: 0 0 0 2px var(--error-color);
}

/* Selection styling */
.rich-text-content ::selection {
  background: var(--primary-color);
  color: white;
}

/* Placeholder styling for better visibility */
.rich-text-content:empty:focus::before {
  opacity: 0.5;
}

/* Image upload preview styling */
.rich-text-content img {
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .rich-text-content img {
  border-color: var(--border-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}