/* TipTap Editor Styles */

/* ProseMirror Base Styles - Required for TipTap */
.ProseMirror {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

.ProseMirror:focus {
  outline: none !important;
  border: none !important;
}

.ProseMirror-focused {
  outline: none !important;
}

/* Remove selection highlight on YouTube embeds and images */
.ProseMirror-selectednode {
  outline: 2px solid var(--sage, #a3b899) !important;
  border-radius: 0.5rem;
}

/* Override any red border that might be applied */
.tiptap-editor .ProseMirror,
.tiptap-editor-public .ProseMirror,
.tiptap-editor [contenteditable],
.tiptap-editor-public [contenteditable] {
  outline: none !important;
  border: none !important;
}

/* YouTube video wrapper in editor */
.ProseMirror div[data-youtube-video] {
  outline: none !important;
  border: none !important;
}

.ProseMirror div[data-youtube-video].ProseMirror-selectednode {
  outline: 2px solid var(--sage, #a3b899) !important;
  border-radius: 0.5rem;
}

/* Editor Container - Admin Theme */
.tiptap-editor {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--admin-border-subtle, #e5e7eb);
  border-top: none;
  border-radius: 0 0 0.5rem 0.5rem;
  background: var(--admin-bg-secondary, #fff);
  outline: none;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--admin-text-primary, #1f2937);
}

.tiptap-editor:focus {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Editor Container - Public Theme */
.tiptap-editor-public {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  padding: 1rem;
  border: 2px solid var(--cream-dark, #e7e5e4);
  border-top: none;
  border-radius: 0 0 0.75rem 0.75rem;
  background: white;
  outline: none;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink, #1c1917);
}

.tiptap-editor-public:focus {
  border-color: var(--sage, #a3b899);
  box-shadow: 0 0 0 3px rgba(163, 184, 153, 0.2);
}

/* Prose Styles */
.tiptap-editor p,
.tiptap-editor-public p {
  margin-bottom: 0.75rem;
}

.tiptap-editor p:last-child,
.tiptap-editor-public p:last-child {
  margin-bottom: 0;
}

.tiptap-editor h2,
.tiptap-editor-public h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.tiptap-editor h2:first-child,
.tiptap-editor-public h2:first-child {
  margin-top: 0;
}

.tiptap-editor h3,
.tiptap-editor-public h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.tiptap-editor h3:first-child,
.tiptap-editor-public h3:first-child {
  margin-top: 0;
}

.tiptap-editor ul,
.tiptap-editor ol,
.tiptap-editor-public ul,
.tiptap-editor-public ol {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.tiptap-editor ul,
.tiptap-editor-public ul {
  list-style-type: disc;
}

.tiptap-editor ol,
.tiptap-editor-public ol {
  list-style-type: decimal;
}

.tiptap-editor li,
.tiptap-editor-public li {
  margin-bottom: 0.25rem;
}

.tiptap-editor blockquote,
.tiptap-editor-public blockquote {
  border-left: 3px solid var(--admin-accent-blue, #3b82f6);
  padding-left: 1rem;
  margin-left: 0;
  margin-bottom: 0.75rem;
  color: var(--admin-text-muted, #6b7280);
  font-style: italic;
}

.tiptap-editor-public blockquote {
  border-left-color: var(--terracotta, #c77b5a);
}

.tiptap-editor strong,
.tiptap-editor-public strong {
  font-weight: 600;
}

.tiptap-editor em,
.tiptap-editor-public em {
  font-style: italic;
}

.tiptap-editor a,
.tiptap-editor-public a {
  color: var(--admin-accent-blue, #3b82f6);
  text-decoration: underline;
  cursor: pointer;
}

.tiptap-editor-public a {
  color: var(--forest, #3d5a3d);
}

/* Images */
.tiptap-editor img,
.tiptap-editor-public img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1rem 0;
}

/* YouTube Embeds */
.tiptap-editor div[data-youtube-video],
.tiptap-editor-public div[data-youtube-video] {
  margin: 1rem 0;
}

.tiptap-editor iframe,
.tiptap-editor-public iframe {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 0.5rem;
  border: none;
}

/* Placeholder */
.tiptap-editor p.is-editor-empty:first-child::before,
.tiptap-editor-public p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--admin-text-muted, #9ca3af);
  pointer-events: none;
  height: 0;
}

/* Toolbar - Admin Theme */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--admin-bg-tertiary, #f9fafb);
  border: 1px solid var(--admin-border-subtle, #e5e7eb);
  border-radius: 0.5rem 0.5rem 0 0;
}

.tiptap-toolbar button {
  padding: 0.375rem 0.625rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--admin-text-secondary, #374151);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
}

.tiptap-toolbar button:hover {
  background: var(--admin-bg-secondary, #fff);
  color: var(--admin-text-primary, #111827);
}

.tiptap-toolbar button.is-active {
  background: var(--admin-accent-blue, #3b82f6);
  color: white;
}

.tiptap-toolbar button svg {
  width: 1rem;
  height: 1rem;
}

.tiptap-toolbar .separator {
  width: 1px;
  height: 1.5rem;
  background: var(--admin-border-subtle, #e5e7eb);
  margin: 0 0.25rem;
  align-self: center;
}

/* Toolbar - Public Theme */
.tiptap-toolbar-public {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--cream-warm, #faf8f5);
  border: 2px solid var(--cream-dark, #e7e5e4);
  border-bottom: none;
  border-radius: 0.75rem 0.75rem 0 0;
}

.tiptap-toolbar-public button {
  padding: 0.375rem 0.625rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink, #1c1917);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
}

.tiptap-toolbar-public button:hover {
  background: white;
  color: var(--forest, #3d5a3d);
}

.tiptap-toolbar-public button.is-active {
  background: var(--sage, #a3b899);
  color: white;
}

.tiptap-toolbar-public button svg {
  width: 1rem;
  height: 1rem;
}

.tiptap-toolbar-public .separator {
  width: 1px;
  height: 1.5rem;
  background: var(--cream-dark, #e7e5e4);
  margin: 0 0.25rem;
  align-self: center;
}

/* Modal Styles */
.tiptap-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.tiptap-modal-overlay.hidden {
  display: none !important;
}

.tiptap-modal {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  width: 100%;
  max-width: 28rem;
  margin: 1rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.tiptap-modal h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--admin-text-primary, #1f2937);
}

.tiptap-modal input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--admin-border-subtle, #d1d5db);
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  margin-bottom: 1rem;
}

.tiptap-modal input:focus {
  outline: none;
  border-color: var(--admin-accent-blue, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.tiptap-modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.tiptap-modal-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tiptap-modal-btn-primary {
  background: var(--admin-accent-blue, #3b82f6);
  color: white;
  border: none;
}

.tiptap-modal-btn-primary:hover {
  background: #2563eb;
}

.tiptap-modal-btn-secondary {
  background: transparent;
  color: var(--admin-text-secondary, #6b7280);
  border: 1px solid var(--admin-border-subtle, #d1d5db);
}

.tiptap-modal-btn-secondary:hover {
  background: var(--admin-bg-tertiary, #f3f4f6);
}

.tiptap-modal-btn-danger {
  background: transparent;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.tiptap-modal-btn-danger:hover {
  background: #fef2f2;
}

/* Loading Overlay */
.tiptap-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.9);
  z-index: 10;
  font-size: 0.875rem;
  color: var(--admin-text-muted, #6b7280);
}

.tiptap-loading-spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--admin-border-subtle, #e5e7eb);
  border-top-color: var(--admin-accent-blue, #3b82f6);
  border-radius: 50%;
  animation: tiptap-spin 0.8s linear infinite;
}

@keyframes tiptap-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Container wrapper for relative positioning */
.tiptap-container {
  position: relative;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .tiptap-toolbar,
  .tiptap-toolbar-public {
    gap: 0.125rem;
    padding: 0.375rem;
  }

  .tiptap-toolbar button,
  .tiptap-toolbar-public button {
    padding: 0.375rem 0.5rem;
    min-width: 1.75rem;
  }

  .tiptap-editor,
  .tiptap-editor-public {
    min-height: 150px;
    padding: 0.75rem;
  }
}
