/**
 * CREATESONLINE Rich Text Editor - Comprehensive Styling
 * Professional design inspired by Wagtail and TinyMCE
 * Zero external dependencies
 */

/* ============================================================================
   Main Editor Container
   ============================================================================ */
.rte {
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  margin: 10px 0;
  transition: box-shadow 0.2s ease;
}

.rte:focus-within {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-color: #4a90e2;
}

/* ============================================================================
   Toolbar
   ============================================================================ */
.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid #e5e5e5;
  background: linear-gradient(to bottom, #fafafa, #f5f5f5);
  border-radius: 8px 8px 0 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.rte-toolbar button {
  border: 1px solid #d0d0d0;
  background: #ffffff;
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  transition: all 0.15s ease;
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.rte-toolbar button:hover {
  background: #e8f0fe;
  border-color: #4a90e2;
  color: #1a73e8;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.rte-toolbar button:active {
  background: #d2e3fc;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.rte-toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Toolbar button icons */
.rte-toolbar button b,
.rte-toolbar button i,
.rte-toolbar button u {
  font-style: normal;
  font-weight: 700;
}

.rte-toolbar button i {
  font-style: italic;
}

.rte-toolbar button u {
  text-decoration: underline;
}

/* Toolbar separators */
.rte-toolbar-separator {
  width: 1px;
  background: #e0e0e0;
  margin: 4px 2px;
  height: 28px;
}

/* ============================================================================
   Editor Area
   ============================================================================ */
.rte-editor {
  padding: 16px;
  min-height: 200px;
  max-height: 600px;
  overflow-y: auto;
  outline: none;
  line-height: 1.6;
  font-size: 14px;
  color: #333;
  background: #ffffff;
  border-radius: 0 0 8px 8px;
}

.rte-editor:empty:before {
  content: attr(data-placeholder);
  color: #999;
  font-style: italic;
  pointer-events: none;
}

/* Editor content styling */
.rte-editor h1 {
  font-size: 2em;
  font-weight: 700;
  margin: 0.67em 0;
  line-height: 1.2;
}

.rte-editor h2 {
  font-size: 1.5em;
  font-weight: 700;
  margin: 0.75em 0;
  line-height: 1.3;
}

.rte-editor h3 {
  font-size: 1.3em;
  font-weight: 600;
  margin: 0.83em 0;
  line-height: 1.4;
}

.rte-editor h4 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 1em 0;
  line-height: 1.4;
}

.rte-editor h5 {
  font-size: 0.9em;
  font-weight: 600;
  margin: 1.2em 0;
  line-height: 1.4;
}

.rte-editor h6 {
  font-size: 0.8em;
  font-weight: 600;
  margin: 1.33em 0;
  line-height: 1.4;
}

.rte-editor p {
  margin: 0.5em 0;
}

.rte-editor ul,
.rte-editor ol {
  margin: 0.5em 0;
  padding-left: 40px;
}

.rte-editor li {
  margin: 0.25em 0;
}

.rte-editor blockquote {
  margin: 1em 0;
  padding: 10px 20px;
  border-left: 4px solid #4a90e2;
  background: #f5f9fc;
  color: #555;
  font-style: italic;
}

.rte-editor a {
  color: #1a73e8;
  text-decoration: underline;
  cursor: pointer;
}

.rte-editor a:hover {
  color: #1557b0;
}

.rte-editor code {
  background: #f4f4f4;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9em;
  color: #d63384;
}

.rte-editor pre {
  background: #2d2d2d;
  color: #f8f8f2;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1em 0;
}

.rte-editor pre code {
  background: none;
  color: #f8f8f2;
  padding: 0;
}

.rte-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 0.5em 0;
}

.rte-editor hr {
  border: none;
  border-top: 2px solid #e0e0e0;
  margin: 1.5em 0;
}

/* ============================================================================
   Tables
   ============================================================================ */
.rte-editor table,
.rte-table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  background: #fff;
  border: 1px solid #ddd;
}

.rte-editor th,
.rte-table th {
  background: #f5f5f5;
  font-weight: 600;
  text-align: left;
  padding: 10px;
  border: 1px solid #ddd;
}

.rte-editor td,
.rte-table td {
  padding: 10px;
  border: 1px solid #ddd;
}

.rte-editor tr:nth-child(even) {
  background: #fafafa;
}

.rte-editor tr:hover {
  background: #f0f0f0;
}

/* ============================================================================
   Code Blocks
   ============================================================================ */
.rte-code-block {
  position: relative;
}

.rte-code-block code {
  display: block;
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 4;
}

/* ============================================================================
   Drag and Drop
   ============================================================================ */
.rte-dragover {
  border-color: #4a90e2;
  background: #f0f7ff;
}

.rte-dragover::after {
  content: 'Drop images here';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: 600;
  color: #4a90e2;
  pointer-events: none;
  z-index: 1000;
}

/* ============================================================================
   Source Mode
   ============================================================================ */
.rte-source-mode {
  font-family: 'Courier New', Courier, monospace;
  background: #1e1e1e;
  color: #d4d4d4;
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 2;
}

/* ============================================================================
   Fullscreen Mode
   ============================================================================ */
.rte-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

.rte-fullscreen .rte-editor {
  max-height: calc(100vh - 60px);
  border-radius: 0;
}

.rte-fullscreen .rte-toolbar {
  border-radius: 0;
}

/* ============================================================================
   Modals
   ============================================================================ */
.rte-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease;
}

.rte-modal {
  background: white;
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.3s ease;
}

.rte-modal h3 {
  margin: 0 0 20px 0;
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.rte-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rte-modal-body label {
  font-weight: 500;
  color: #555;
  font-size: 14px;
  margin-bottom: -8px;
}

.rte-modal-body input[type="text"],
.rte-modal-body input[type="url"],
.rte-modal-body input[type="number"],
.rte-modal-body textarea {
  padding: 10px 12px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.rte-modal-body input:focus,
.rte-modal-body textarea:focus {
  outline: none;
  border-color: #4a90e2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.rte-modal-body textarea {
  resize: vertical;
  font-family: 'Courier New', Courier, monospace;
}

.rte-modal-body input[type="checkbox"] {
  margin-right: 8px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.rte-modal-body input[type="color"] {
  height: 40px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  cursor: pointer;
}

.rte-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

.rte-btn-primary,
.rte-btn-secondary {
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.rte-btn-primary {
  background: #4a90e2;
  color: white;
}

.rte-btn-primary:hover {
  background: #357abd;
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.rte-btn-secondary {
  background: #f0f0f0;
  color: #555;
  border: 1px solid #d0d0d0;
}

.rte-btn-secondary:hover {
  background: #e0e0e0;
}

/* ============================================================================
   Color Picker
   ============================================================================ */
.rte-color-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.rte-color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #d0d0d0;
  transition: all 0.2s ease;
}

.rte-color-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

/* ============================================================================
   Font Picker
   ============================================================================ */
.rte-font-list,
.rte-size-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.rte-font-item,
.rte-size-item {
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.rte-font-item:hover,
.rte-size-item:hover {
  background: #f0f7ff;
}

.rte-font-item {
  font-size: 16px;
}

.rte-size-item {
  display: flex;
  align-items: center;
}

/* ============================================================================
   Notifications
   ============================================================================ */
.rte-notification {
  position: fixed;
  bottom: -100px;
  right: 20px;
  background: #333;
  color: white;
  padding: 14px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 10001;
  transition: bottom 0.3s ease;
  max-width: 300px;
}

.rte-notification-show {
  bottom: 20px;
}

.rte-notification-success {
  background: #4caf50;
}

.rte-notification-error {
  background: #f44336;
}

.rte-notification-warning {
  background: #ff9800;
}

.rte-notification-info {
  background: #2196f3;
}

/* ============================================================================
   Animations
   ============================================================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ============================================================================
   Hidden Output Textarea
   ============================================================================ */
.rte-output {
  display: none !important;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */
@media (max-width: 768px) {
  .rte-toolbar {
    gap: 2px;
    padding: 6px;
  }

  .rte-toolbar button {
    padding: 5px 8px;
    font-size: 12px;
    min-width: 28px;
    height: 28px;
  }

  .rte-editor {
    padding: 12px;
    font-size: 13px;
  }

  .rte-modal {
    width: 95%;
    padding: 16px;
  }

  .rte-color-palette {
    grid-template-columns: repeat(6, 1fr);
  }

  .rte-color-swatch {
    width: 28px;
    height: 28px;
  }
}

/* ============================================================================
   Print Styles
   ============================================================================ */
@media print {
  .rte-toolbar {
    display: none;
  }

  .rte {
    border: none;
    box-shadow: none;
  }

  .rte-editor {
    padding: 0;
    max-height: none;
  }
}

/* ============================================================================
   Dark Mode Support (Optional)
   ============================================================================ */
@media (prefers-color-scheme: dark) {
  .rte {
    background: #1e1e1e;
    border-color: #404040;
  }

  .rte-toolbar {
    background: linear-gradient(to bottom, #2d2d2d, #252525);
    border-bottom-color: #404040;
  }

  .rte-toolbar button {
    background: #2d2d2d;
    border-color: #404040;
    color: #e0e0e0;
  }

  .rte-toolbar button:hover {
    background: #3a3a3a;
    border-color: #4a90e2;
  }

  .rte-editor {
    background: #1e1e1e;
    color: #e0e0e0;
  }

  .rte-editor:empty:before {
    color: #666;
  }

  .rte-editor blockquote {
    background: #2d2d2d;
    border-left-color: #4a90e2;
    color: #b0b0b0;
  }

  .rte-editor code {
    background: #2d2d2d;
    color: #ff6b9d;
  }

  .rte-modal {
    background: #2d2d2d;
    color: #e0e0e0;
  }

  .rte-modal h3 {
    color: #e0e0e0;
  }

  .rte-modal-body input,
  .rte-modal-body textarea {
    background: #1e1e1e;
    border-color: #404040;
    color: #e0e0e0;
  }

  .rte-btn-secondary {
    background: #3a3a3a;
    color: #e0e0e0;
    border-color: #404040;
  }
}

/* ============================================================================
   Accessibility Improvements
   ============================================================================ */
.rte-toolbar button:focus-visible {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

.rte-editor:focus-visible {
  outline: 2px solid #4a90e2;
  outline-offset: -2px;
}

.rte-modal-body input:focus-visible,
.rte-modal-body textarea:focus-visible {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}