/* EditorJS Styles */

/* ─── Message body display ────────────────────────────────────────────────
   Replaces prose/trix-content for message rendering.
   All block elements flush, no extra margins.
   ─────────────────────────────────────────────────────────────────────── */
.message-body { line-height: 1.4; }
/* ActionText wraps body in <div class="trix-content"> — reset it */
.message-body .trix-content { display: contents; }
.message-body p  { margin: 0; }
.message-body p + p { margin-top: 0.5em; }
.message-body h1, .message-body h2, .message-body h3 { font-weight: 600; margin: 0.4em 0 0.1em; }
.message-body ul, .message-body ol { margin: 0.25em 0; padding-left: 1.2em; }
.message-body li { margin: 0; }
.message-body strong { font-weight: 600; }
.message-body em { font-style: italic; }
.message-body a { color: #4f46e5; text-decoration: underline; }
.dark .message-body a { color: #818cf8; }
/* ─────────────────────────────────────────────────────────────────────────── */

/* ─── Editor gutter padding ───────────────────────────────────────────────
   Gives space on the left for EditorJS + button and drag handle.
   ─────────────────────────────────────────────────────────────────────── */
[data-editor-target="editor"] {
  padding: 8px 16px 8px 56px;
}
[data-editor-target="editor"] .ce-block__content {
  padding-left: 0 !important;
}

/* ─── Top Toolbar ─────────────────────────────────────────────────────────── */
.editor-toolbar-toggle-wrapper {
  display: none;
}

.editor-toolbar-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: #111827;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
  user-select: none;
}

.editor-toolbar-toggle-btn svg {
  width: 19px;
  height: 19px;
}

.editor-toolbar-toggle-btn:hover {
  color: #6b7280;
  background: #f3f4f6;
}

.editor-toolbar-toggle-btn--active {
  color: #4f46e5;
  background: #eef2ff;
}

.editor-toolbar-toggle-btn--active:hover {
  background: #e0e7ff;
}

.dark .editor-toolbar-toggle-btn {
  color: #f9fafb;
}

.dark .editor-toolbar-toggle-btn:hover {
  color: #9ca3af;
  background: #374151;
}

.dark .editor-toolbar-toggle-btn--active {
  color: #a5b4fc;
  background: #312e81;
}

.dark .editor-toolbar-toggle-btn--active:hover {
  background: #3730a3;
}

.editor-top-toolbar.hidden {
  display: none;
}

.editor-top-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 4rem;
  z-index: 10;
  overflow: visible;
}

.dark .editor-top-toolbar {
  background: #1f2937;
  border-color: #374151;
}

.editor-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.editor-toolbar-divider {
  width: 1px;
  height: 20px;
  background: #e5e7eb;
  margin: 0 4px;
  flex-shrink: 0;
}

.dark .editor-toolbar-divider {
  background: #374151;
}

.editor-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.1s;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.editor-toolbar-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.editor-toolbar-btn:hover {
  background: #f3f4f6;
}

.dark .editor-toolbar-btn {
  color: #d1d5db;
}

.dark .editor-toolbar-btn:hover {
  background: #374151;
}

.editor-toolbar-btn--active {
  background: #eef2ff;
  color: #4f46e5;
}

.dark .editor-toolbar-btn--active {
  background: #312e81;
  color: #a5b4fc;
}

.editor-toolbar-btn[data-command="marker"].editor-toolbar-btn--active {
  background: #fefce8;
  color: #713f12;
}

.dark .editor-toolbar-btn[data-command="marker"].editor-toolbar-btn--active {
  background: #422006;
  color: #fef08a;
}

/* Link input row */
.editor-toolbar-link-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.editor-toolbar-link-input.hidden {
  display: none;
}

.editor-toolbar-url-input {
  font-size: 12px;
  padding: 3px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  outline: none;
  width: 180px;
  color: #111827;
  background: #ffffff;
}

.editor-toolbar-url-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.dark .editor-toolbar-url-input {
  background: #111827;
  border-color: #4b5563;
  color: #f9fafb;
}

.dark .editor-toolbar-url-input:focus {
  border-color: #818cf8;
}

.editor-toolbar-link-confirm {
  width: 32px;
  font-size: 16px;
}

/* Color palette dropdown — matches editorjs-color-picker inline toolbar style */
.editor-toolbar-color-palette {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.editor-toolbar-color-palette.hidden {
  display: none;
}

.dark .editor-toolbar-color-palette {
  background: #1f2937;
  border-color: #374151;
}

.editor-toolbar-color-swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
  padding: 4px;
}

.editor-toolbar-color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 100%;
  border: none;
  cursor: pointer;
  padding: 0;
  display: block;
  transition: transform 0.2s ease;
}

.editor-toolbar-color-swatch:hover {
  transform: scale(1.1);
}

.editor-toolbar-color-clear {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 4px 0;
  font-size: 11px;
  text-align: center;
  color: #6b7280;
  background: none;
  border: none;
  border-top: 1px solid #e5e7eb;
  cursor: pointer;
}

.editor-toolbar-color-clear:hover {
  color: #111827;
  background: #f3f4f6;
}

.dark .editor-toolbar-color-clear {
  color: #9ca3af;
  border-top-color: #374151;
}

.dark .editor-toolbar-color-clear:hover {
  color: #f9fafb;
  background: #374151;
}
/* ─────────────────────────────────────────────────────────────────────────── */

/* ─── Rendered EditorJS content (read-only views) ─────────────────────────
   Used wherever body_as_html is rendered: lesson preview, client show, etc.
   Replaces Tailwind Typography (prose) which is not installed.
   ─────────────────────────────────────────────────────────────────────────── */
.editorjs-content {
  font-size: 0.9375rem;
  line-height: 1.7;
  color: #111827;
}

.dark .editorjs-content {
  color: #f3f4f6;
}

.editorjs-content h1,
.editorjs-content h2,
.editorjs-content h3,
.editorjs-content h4,
.editorjs-content h5,
.editorjs-content h6 {
  font-weight: 700;
  line-height: 1.25;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

.editorjs-content h1 { font-size: 2em; }
.editorjs-content h2 { font-size: 1.5em; }
.editorjs-content h3 { font-size: 1.25em; }
.editorjs-content h4 { font-size: 1.125em; }
.editorjs-content h5,
.editorjs-content h6 { font-size: 1em; }

.editorjs-content p {
  margin-top: 0;
  margin-bottom: 0.6em;
}

.editorjs-content ul,
.editorjs-content ol {
  margin-top: 0;
  margin-bottom: 1em;
  padding-left: 1.1em;
}

.editorjs-content ul { list-style-type: disc; }
.editorjs-content ol { list-style-type: decimal; }

.editorjs-content li {
  margin-bottom: 0.25em;
}

.editorjs-content a {
  color: #4f46e5;
  text-decoration: underline;
}

.dark .editorjs-content a {
  color: #818cf8;
}

.editorjs-content strong { font-weight: 700; }
.editorjs-content em { font-style: italic; }

.editorjs-content figure {
  margin: 1.25em 0;
}

.editorjs-content img {
  max-width: 100%;
  border-radius: 0.375rem;
}

.editorjs-content figcaption {
  font-size: 0.875em;
  color: #6b7280;
  margin-top: 0.5em;
  text-align: center;
}

.dark .editorjs-content figcaption {
  color: #9ca3af;
}

/* Remove top margin from first child */
.editorjs-content > *:first-child {
  margin-top: 0;
}

/* Remove bottom margin from last child */
.editorjs-content > *:last-child {
  margin-bottom: 0;
}

/* Editor.js Table Styles */
.tc-cell:first-child {
  border-left: 1px solid var(--color-border, #ccc);
}

/* Editor.js Header Styles */
.ce-header {
  padding: .6em 0 3px;
  margin: 0;
  line-height: 1.25em;
  outline: none;
  font-weight: 700;
}

h1.ce-header { font-size: 2em; }
h2.ce-header { font-size: 1.5em; }
h3.ce-header { font-size: 1.25em; }
h4.ce-header { font-size: 1.125em; }

/* Space above header blocks so sections breathe */
.ce-block + .ce-block:has(> .ce-block__content > .ce-header) {
  margin-top: 1.25em;
}

/* Editor.js Layout - Full Width with Left Padding */
.ce-block__content {
  max-width: none !important;
  margin: 0 !important;
  padding-left: 0;
}

.ce-toolbar__content {
  max-width: none !important;
  margin: 0 !important;
  margin-left: 0 !important;
}

/* Remove padding for read-only note content */
.note-content .ce-block__content {
  padding-left: 0 !important;
}

/* Editor Title Field - Notion-like */
.editor-title-container {
  margin-bottom: 20px;
}

.editor-title {
  width: 100%;
  font-size: 2.5rem;
  font-weight: 700;
  border: none;
  outline: none;
  padding: 8px 0;
  font-family: inherit;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-height: 56px;
  color: #111827;
}

.dark .editor-title {
  color: #f9fafb;
}

.editor-title:empty:before {
  content: attr(data-placeholder);
  color: #9CA3AF;
  opacity: 0.6;
}

.editor-title-placeholder {
  color: #9CA3AF;
  opacity: 0.5;
}

.editor-container {
  margin-bottom: 30px;
}

/* EditorJS Paragraph styles */
.ce-paragraph {
  line-height: 1.6em;
  outline: none;
}

.dark .ce-paragraph,
.dark .ce-header,
.dark .cdx-list__item,
.dark .cdx-block {
  color: #f3f4f6;
}

/* EditorJS List - reduce indent */
.cdx-list {
  padding-left: 1.1em !important;
}

/* EditorJS inline toolbar adjustments */
.ce-inline-toolbar {
  background: white;
  border: 1px solid #e5e7eb;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark .ce-inline-toolbar {
  background: #1f2937 !important;
  border-color: #374151 !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5) !important;
  color: #d1d5db !important;
}

.dark .ce-inline-toolbar__toggler-and-button-wrapper {
  color: #d1d5db !important;
}

.dark .ce-inline-tool {
  color: #d1d5db !important;
}

.dark .ce-inline-tool:hover {
  background: #374151 !important;
  color: #f9fafb !important;
}

.dark .ce-inline-tool--active {
  color: #a5b4fc !important;
}

.dark .ce-inline-toolbar__dropdown {
  color: #d1d5db !important;
  border-right-color: #374151 !important;
}

.dark .ce-inline-toolbar__dropdown:hover {
  background: #374151 !important;
}

/* Hide inline toolbar when empty to prevent gray dot */
.ce-inline-toolbar:empty {
  display: none !important;
}

/* EditorJS conversion toolbar */
.ce-conversion-toolbar {
  background: white;
  border: 1px solid #e5e7eb;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark .ce-conversion-toolbar {
  background: #1f2937;
  border-color: #374151;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

.dark .ce-conversion-toolbar__label {
  color: #6b7280;
}

.dark .ce-conversion-tool {
  color: #d1d5db;
}

.dark .ce-conversion-tool:hover {
  background: #374151;
}

.dark .ce-conversion-tool--focused {
  background: #374151 !important;
}

.dark .ce-conversion-tool__icon {
  background: #374151;
  border-color: #4b5563;
  color: #d1d5db;
}

/* EditorJS block type popover (+ menu) and inline popover */
.dark .ce-popover,
.dark .ce-popover__container {
  background: #1f2937 !important;
  border-color: #374151 !important;
  box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.6) !important;
  color: #d1d5db !important;
}

.dark .cdx-search-field {
  background: #111827 !important;
  border-color: #374151 !important;
}

.dark .cdx-search-field__icon {
  color: #6b7280 !important;
}

.dark .cdx-search-field__input {
  background: #111827 !important;
  color: #f9fafb !important;
  caret-color: #f9fafb;
}

.dark .cdx-search-field__input::placeholder {
  color: #6b7280 !important;
}

.dark .ce-popover-item {
  color: #d1d5db !important;
}

.dark .ce-popover-item:hover,
.dark .ce-popover-item--focused {
  background: #374151 !important;
}

.dark .ce-popover-item__icon {
  background: #374151 !important;
  border-color: #4b5563 !important;
  color: #d1d5db !important;
}

.dark .ce-popover-item__title {
  color: #d1d5db !important;
}

.dark .ce-popover-item__secondary-title {
  color: #6b7280 !important;
}

.dark .ce-popover-item-separator__line {
  background: #374151 !important;
}

.dark .ce-popover__nothing-found-message {
  color: #6b7280 !important;
}

.dark .ce-popover-header__text {
  color: #d1d5db !important;
}

.dark .ce-popover-header__back-button {
  color: #d1d5db !important;
}

/* EditorJS settings button */
.ce-settings {
  background: transparent;
  border: none;
}

.dark .ce-settings {
  background: transparent;
  border: none;
}

/* EditorJS toolbox */
.ce-toolbox {
  background: transparent;
  border: none;
}

.dark .ce-toolbox {
  background: transparent;
  border: none;
}

/* Link Tool card */
.link-tool__content {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.dark .link-tool__content {
  background: #1f2937;
  border-color: #374151;
}

.dark .link-tool__title {
  color: #f9fafb;
}

.dark .link-tool__description {
  color: #9ca3af;
}

.dark .link-tool__anchor {
  color: #6b7280;
}

.dark .link-tool__input {
  background: #111827;
  border-color: #374151;
  color: #f9fafb;
}

.dark .link-tool__input::placeholder {
  color: #6b7280;
}

.dark .link-tool__input-holder--error .link-tool__input {
  border-color: #ef4444;
}

.dark .link-tool__content--rendered {
  background: #1f2937;
  border-color: #374151;
}

.dark .link-tool__image {
  background: #374151;
}

/* EditorJS block selected state */
.ce-block--selected .ce-block__content {
  background: rgba(79, 70, 229, 0.05);
}

.dark .ce-block--selected .ce-block__content {
  background: rgba(99, 102, 241, 0.1);
}

/* Hide the separator line in the toolbar */
.ce-toolbar__plus::before,
.ce-toolbar__settings-btn::before {
  display: none !important;
}

/* Make toolbar buttons white in dark mode */
.dark .ce-toolbar__plus,
.dark .ce-toolbar__settings-btn {
  color: white !important;
}

.dark .ce-toolbar__plus svg,
.dark .ce-toolbar__settings-btn svg {
  fill: white !important;
  stroke: white !important;
}

/* Adjust hover state in dark mode to be less bright */
.dark .ce-toolbar__plus:hover,
.dark .ce-toolbar__settings-btn:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

/* Text selection highlight color in dark mode */
.dark .editor-container ::selection,
.dark .editor-title ::selection,
.dark [data-editor-target="editor"] ::selection,
.dark [data-controller="editor"] ::selection {
  background-color: rgba(99, 102, 241, 0.35);
  color: #f9fafb;
}

/* Hide block toolbar (+ button and drag handle) on mobile — inline selection toolbar is unaffected */
@media (max-width: 767px) {
  .ce-toolbar {
    display: none !important;
  }
}

/* EditorJS Attaches Tool */
.dark .cdx-attaches {
  --color-line: #374151;
  --color-bg: #1f2937;
  --color-bg-secondary: #374151;
  --color-bg-secondary--hover: #4b5563;
  --color-text-secondary: #9ca3af;
}

.dark .cdx-attaches__title {
  color: #f3f4f6 !important;
}

.dark .cdx-attaches__download-button {
  color: #9ca3af;
}

/* Rendered attaches block in read-only / email views */
.editorjs-attaches {
  margin: 0.75em 0;
}

.editorjs-attaches__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  color: #111827;
  text-decoration: none;
  transition: background 0.1s;
}

.editorjs-attaches__link:hover {
  background: #f3f4f6;
}

.editorjs-attaches__icon {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: #e5e7eb;
  color: #374151;
  border-radius: 4px;
  padding: 4px 6px;
  text-transform: uppercase;
}

.editorjs-attaches__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.editorjs-attaches__title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editorjs-attaches__meta {
  font-size: 0.8125rem;
  color: #6b7280;
}

.editorjs-attaches__arrow {
  flex-shrink: 0;
  color: #9ca3af;
  font-size: 1rem;
}

/* Dark mode for rendered attaches */
.dark .editorjs-attaches__link {
  background: #1f2937;
  border-color: #374151;
  color: #f3f4f6;
}

.dark .editorjs-attaches__link:hover {
  background: #374151;
}

.dark .editorjs-attaches__icon {
  background: #374151;
  color: #d1d5db;
}

.dark .editorjs-attaches__title {
  color: #f3f4f6;
}

.dark .editorjs-attaches__meta {
  color: #9ca3af;
}

.dark .editorjs-attaches__arrow {
  color: #6b7280;
}

/* EditorJS Image Tool */
.image-tool {
  --bg-color: #f9fafb;
  --front-color: #374151;
  --border-color: #e5e7eb;
}

.dark .image-tool {
  --bg-color: #1f2937;
  --front-color: #f3f4f6;
  --border-color: #374151;
}

.image-tool__image {
  border-radius: 6px;
  overflow: hidden;
}

.image-tool__image-picture {
  max-width: 100%;
  vertical-align: bottom;
  display: block;
}

.image-tool__caption {
  padding: 6px 0 0;
  font-size: 0.875rem;
  color: #6b7280;
  outline: none;
}

.dark .image-tool__caption {
  color: #9ca3af;
}

/* Upload button state */
.image-tool__image--loading {
  background: var(--bg-color);
  border: 2px dashed var(--border-color);
  border-radius: 6px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Stretched variant */
.image-tool--stretched .image-tool__image-picture {
  width: 100%;
}

/* With border variant */
.image-tool--withBorder .image-tool__image-picture {
  border: 1px solid var(--border-color);
}

/* With background variant */
.image-tool--withBackground .image-tool__image {
  background: var(--bg-color);
  padding: 10px;
}

/* File input overlay button */
.cdx-button {
  padding: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  background: var(--bg-color, #f9fafb);
  color: var(--front-color, #374151);
  font-size: 0.875rem;
  cursor: pointer;
  width: 100%;
  text-align: center;
}

.cdx-button:hover {
  background: #f3f4f6;
}

.dark .cdx-button:hover {
  background: #374151;
}

@media (max-width: 767px) {
  .editor-top-toolbar {
    gap: 2px;
    padding: 4px 8px;
  }

  .editor-toolbar-btn {
    width: 26px;
    height: 26px;
  }

  .editor-toolbar-btn svg {
    width: 17px;
    height: 17px;
  }

  .editor-toolbar-divider {
    margin: 0 2px;
  }
}
