/* ProseMirror Editor Styles */

/* Define DaisyUI-like CSS custom properties */
:root {
  --p: 259 94% 51%;     /* primary */
  --pf: 259 94% 44%;    /* primary-focus */
  --pc: 0 0% 100%;      /* primary-content */
  --b1: 0 0% 100%;      /* base-100 */
  --b2: 0 0% 95%;       /* base-200 */
  --b3: 0 0% 90%;       /* base-300 */
  --bc: 215 28% 17%;    /* base-content */
}

[data-theme="dark"] {
  --p: 259 94% 65%;     /* primary */
  --pf: 259 94% 70%;    /* primary-focus */
  --pc: 0 0% 13%;       /* primary-content */
  --b1: 222 84% 5%;     /* base-100 */
  --b2: 222 84% 8%;     /* base-200 */
  --b3: 222 84% 11%;    /* base-300 */
  --bc: 220 13% 69%;    /* base-content */
}

.prosemirror-toolbar {
  border-bottom: 1px solid hsl(var(--bc) / 0.2);
  background: hsl(var(--b2));
}

.editor-content-area {
  min-height: 400px;
  padding: 1rem;
  outline: none;
  font-family: inherit;
  line-height: 1.6;
}

.editor-content-area:focus {
  outline: none;
}

/* ProseMirror specific styles */
.ProseMirror {
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Unified styling for both editor and show contexts - using rem for consistent sizing */
.editor-content-area h1,
.editor-content-area .ProseMirror h1 {
  font-size: 2.25rem !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  margin-top: 2rem !important;
  margin-bottom: 1rem !important;
  border-bottom: 1px solid hsl(var(--bc) / 0.1) !important;
  padding-bottom: 0.3rem !important;
}

.editor-content-area h1:first-child,
.editor-content-area .ProseMirror h1:first-child {
  margin-top: 0 !important;
}

.editor-content-area h2,
.editor-content-area .ProseMirror h2 {
  font-size: 1.875rem !important;
  font-weight: 600 !important;
  line-height: 1.3 !important;
  margin-top: 1.5rem !important;
  margin-bottom: 0.75rem !important;
  border-bottom: 1px solid hsl(var(--bc) / 0.05) !important;
  padding-bottom: 0.2rem !important;
}

.editor-content-area h3,
.editor-content-area .ProseMirror h3 {
  font-size: 1.5rem !important;
  font-weight: 600 !important;
  line-height: 1.4 !important;
  margin-top: 1.25rem !important;
  margin-bottom: 0.5rem !important;
}

.editor-content-area h4,
.editor-content-area .ProseMirror h4 {
  font-size: 1.25rem !important;
  font-weight: 600 !important;
  margin-top: 1rem !important;
  margin-bottom: 0.5rem !important;
}

.editor-content-area h5,
.editor-content-area .ProseMirror h5 {
  font-size: 1.125rem !important;
  font-weight: 600 !important;
  margin-top: 1rem !important;
  margin-bottom: 0.5rem !important;
}

.editor-content-area h6,
.editor-content-area .ProseMirror h6 {
  font-size: 1rem !important;
  font-weight: 600 !important;
  margin-top: 1rem !important;
  margin-bottom: 0.5rem !important;
  color: hsl(var(--bc) / 0.7) !important;
}

/* Unified paragraph styling with proper spacing */
.editor-content-area p,
.editor-content-area .ProseMirror p {
  margin: 0 0 1rem 0 !important;
  line-height: 1.6 !important;
  font-size: 1rem !important;
  font-weight: 400 !important;
}

.editor-content-area p:first-child,
.editor-content-area .ProseMirror p:first-child {
  margin-top: 0 !important;
}

.editor-content-area p:last-child,
.editor-content-area .ProseMirror p:last-child {
  margin-bottom: 0 !important;
}

/* Apply first-child/last-child margin handling to all block elements */
.editor-content-area > *:first-child,
.editor-content-area .ProseMirror > *:first-child {
  margin-top: 0 !important;
}

.editor-content-area > *:last-child,
.editor-content-area .ProseMirror > *:last-child {
  margin-bottom: 0 !important;
}

/* Blockquote styling for both contexts */
.editor-content-area blockquote,
.editor-content-area .ProseMirror blockquote {
  border-left: 4px solid hsl(var(--bc) / 0.2) !important;
  padding: 0 0 0 1rem !important;
  margin: 1rem 0 !important;
  color: hsl(var(--bc) / 0.7) !important;
  font-style: italic !important;
}

.editor-content-area blockquote p,
.editor-content-area .ProseMirror blockquote p {
  margin: 0.5rem 0 !important;
}

/* Strong and emphasis styling */
.editor-content-area strong,
.editor-content-area .ProseMirror strong {
  font-weight: 600 !important;
}

.editor-content-area em,
.editor-content-area .ProseMirror em {
  font-style: italic !important;
}

/* Link styling */
.editor-content-area a,
.editor-content-area .ProseMirror a {
  color: hsl(var(--p)) !important;
  text-decoration: underline !important;
  text-underline-offset: 2px !important;
}

.editor-content-area a:hover,
.editor-content-area .ProseMirror a:hover {
  color: hsl(var(--pf)) !important;
  text-decoration: none !important;
}

/* Code styling using our defined custom properties */
.editor-content-area pre,
.editor-content-area .ProseMirror pre,
div.editor-content-area pre,
div.editor-content-area div.ProseMirror pre {
  background: hsl(var(--b2)) !important;
  border: 1px solid hsl(var(--b3)) !important;
  color: hsl(var(--bc)) !important;
  border-radius: 6px !important;
  padding: 1rem !important;
  margin: 1rem 0 !important;
  overflow-x: auto !important;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace !important;
  font-size: 0.875rem !important;
  line-height: 1.45 !important;
}

.editor-content-area code,
.editor-content-area .ProseMirror code {
  background: hsl(var(--b2)) !important;
  border: 1px solid hsl(var(--b3)) !important;
  color: hsl(var(--bc)) !important;
  padding: 0.2em 0.4em !important;
  border-radius: 3px !important;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace !important;
  font-size: 0.875rem !important;
}

/* Code inside pre blocks - reset inline code styling */
.editor-content-area pre code,
.editor-content-area .ProseMirror pre code {
  background: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  font-size: inherit !important;
}

/* List styling - unified for both contexts with explicit bullet/number styles */
.editor-content-area ul, .editor-content-area ol,
.editor-content-area .ProseMirror ul, .editor-content-area .ProseMirror ol {
  margin: 0 0 1rem 0 !important;
  padding-left: 2rem !important;
}

/* Explicit bullet list styling */
.editor-content-area ul,
.editor-content-area .ProseMirror ul {
  list-style-type: disc !important;
}

/* Explicit numbered list styling */
.editor-content-area ol,
.editor-content-area .ProseMirror ol {
  list-style-type: decimal !important;
}

.editor-content-area ul ul, .editor-content-area ol ol, .editor-content-area ul ol, .editor-content-area ol ul,
.editor-content-area .ProseMirror ul ul, .editor-content-area .ProseMirror ol ol, .editor-content-area .ProseMirror ul ol, .editor-content-area .ProseMirror ol ul {
  margin: 0 !important;
}

/* Nested list styles */
.editor-content-area ul ul,
.editor-content-area .ProseMirror ul ul {
  list-style-type: circle !important;
}

.editor-content-area ul ul ul,
.editor-content-area .ProseMirror ul ul ul {
  list-style-type: square !important;
}

.editor-content-area li,
.editor-content-area .ProseMirror li {
  margin: 0.25rem 0 !important;
  line-height: 1.6 !important;
  display: list-item !important;
}

.editor-content-area li p,
.editor-content-area .ProseMirror li p {
  margin: 0.25rem 0 !important;
  font-size: 1rem !important;
  font-weight: 400 !important;
}

/* HR styling - unified for both contexts */
.editor-content-area hr,
.editor-content-area .ProseMirror hr {
  border: none !important;
  border-top: 1px solid hsl(var(--bc) / 0.2) !important;
  margin: 2rem 0 !important;
}

/* Image styling - unified for both contexts */
.editor-content-area img,
.editor-content-area .ProseMirror img {
  max-width: 100% !important;
  height: auto !important;
  border-radius: 6px !important;
  margin: 1rem 0 !important;
}

/* Table styling - unified for both contexts */
.editor-content-area table,
.editor-content-area .ProseMirror table {
  border-collapse: collapse !important;
  margin: 1rem 0 !important;
  width: 100% !important;
}

.editor-content-area th, .editor-content-area td,
.editor-content-area .ProseMirror th, .editor-content-area .ProseMirror td {
  border: 1px solid hsl(var(--bc) / 0.2) !important;
  padding: 0.5rem !important;
  text-align: left !important;
}

.editor-content-area th,
.editor-content-area .ProseMirror th {
  background: hsl(var(--b2)) !important;
  font-weight: 600 !important;
}

/* Placeholder styles */
.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: hsl(var(--bc) / 0.4);
  pointer-events: none;
  height: 0;
}

/* Selection styles */
.ProseMirror-selectednode {
  outline: 2px solid hsl(var(--p));
  outline-offset: 2px;
}

/* Focus styles */
.ProseMirror-focused {
  outline: none;
}

/* Gapcursor */
.ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: absolute;
}

.ProseMirror-gapcursor:after {
  content: "";
  display: block;
  position: absolute;
  top: -2px;
  width: 20px;
  border-top: 1px solid hsl(var(--bc));
  animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}

@keyframes ProseMirror-cursor-blink {
  to {
    visibility: hidden;
  }
}

.ProseMirror-gapcursor.ProseMirror-gapcursor-left:after {
  border-left: 1px solid hsl(var(--bc));
  margin-left: -1px;
}

.ProseMirror-gapcursor.ProseMirror-gapcursor-right:after {
  border-right: 1px solid hsl(var(--bc));
  margin-right: -1px;
  right: 0;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .editor-content-area {
    padding: 0.75rem;
    min-height: 300px;
  }
  
  .editor-content-area h1,
  .editor-content-area .ProseMirror h1 {
    font-size: 1.75rem !important;
  }
  
  .editor-content-area h2,
  .editor-content-area .ProseMirror h2 {
    font-size: 1.375rem !important;
  }
  
  .editor-content-area h3,
  .editor-content-area .ProseMirror h3 {
    font-size: 1.125rem !important;
  }
}

