/* CodeMirror editor */
#editor-panel .CodeMirror {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  width: 100%;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.625;
  background: #111827;
  color: #f9fafb;
}

.dark #editor-panel .CodeMirror {
  background: #030712;
}

#editor-panel .CodeMirror-scroll {
  min-height: 100%;
  padding-bottom: 1rem;
}

#editor-panel .CodeMirror-gutters {
  background: #0f172a;
  border-right: 1px solid #1f2937;
}

.dark #editor-panel .CodeMirror-gutters {
  background: #020617;
  border-right-color: #111827;
}

#editor-panel .CodeMirror-linenumber {
  color: #6b7280;
  padding: 0 8px 0 4px;
}

#editor-panel .CodeMirror-cursor {
  border-left-color: #e5e7eb;
}

#editor-panel .CodeMirror-selected {
  background: rgba(99, 102, 241, 0.35);
}

#editor-panel .CodeMirror-focused .CodeMirror-selected {
  background: rgba(99, 102, 241, 0.45);
}

#editor-panel .CodeMirror-line {
  padding-left: 0.75rem;
}

#editor-panel .cm-header {
  color: #a5b4fc;
  font-weight: 600;
}

#editor-panel .cm-header-1 { font-size: 1.25em; }
#editor-panel .cm-header-2 { font-size: 1.15em; }

#editor-panel .cm-strong { color: #fbbf24; font-weight: 600; }
#editor-panel .cm-em { color: #f9a8d4; font-style: italic; }
#editor-panel .cm-link,
#editor-panel .cm-url { color: #60a5fa; }
#editor-panel .cm-comment { color: #9ca3af; }
#editor-panel .cm-quote { color: #86efac; }
#editor-panel .cm-keyword { color: #c084fc; }
#editor-panel .cm-string { color: #86efac; }
#editor-panel .cm-atom { color: #fbbf24; }
#editor-panel .cm-number { color: #fdba74; }
#editor-panel .cm-meta,
#editor-panel .cm-tag { color: #67e8f9; }
#editor-panel .cm-attribute { color: #fcd34d; }
#editor-panel .cm-hr { color: #6b7280; }
#editor-panel .cm-formatting { color: #818cf8; opacity: 0.85; }
#editor-panel .cm-formatting-list,
#editor-panel .cm-formatting-task { color: #a78bfa; }
#editor-panel .cm-strikethrough { text-decoration: line-through; color: #9ca3af; }

#editor-panel .CodeMirror-matchingbracket {
  color: #34d399 !important;
  outline: 1px solid rgba(52, 211, 153, 0.4);
}

/* Toolbar buttons */
.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
  border-radius: 0.5rem;
  color: #4b5563;
  transition: background-color 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
}

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

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

.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.dark .toolbar-btn:hover {
  background-color: #1f2937;
}

/* Settings textareas */
.settings-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #d1d5db;
  background-color: #f9fafb;
  font-size: 0.875rem;
  outline: none;
  resize: vertical;
}

.dark .settings-textarea {
  border-color: #4b5563;
  background-color: #1f2937;
  color: #f3f4f6;
}

.settings-textarea:focus {
  ring: 2px;
  border-color: transparent;
  box-shadow: 0 0 0 2px #6366f1;
}

/* Context menu items */
.context-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
  transition: background-color 0.15s, color 0.15s;
}

.context-item:hover {
  background-color: #eef2ff;
  color: #4338ca;
}

.dark .context-item:hover {
  background-color: rgba(49, 46, 129, 0.3);
  color: #a5b4fc;
}

.context-item code {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
  color: #4f46e5;
}

.context-divider {
  height: 1px;
  margin: 0.25rem 0.75rem;
  background-color: #e5e7eb;
}

.dark .context-divider {
  background-color: #374151;
}

.dark .context-item code {
  color: #818cf8;
}

/* Fullscreen preview mode */
.fullscreen-preview #editor-panel,
.fullscreen-preview #split-resizer {
  display: none;
}

.fullscreen-preview #preview-panel {
  width: 100% !important;
  height: 100% !important;
  flex: 1 1 100%;
}

/* Split resizer */
.split-resizer {
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  background-color: #e5e7eb;
  touch-action: none;
  user-select: none;
}

.dark .split-resizer {
  background-color: #374151;
}

@media (min-width: 768px) {
  .split-resizer {
    width: 5px;
    cursor: col-resize;
  }

  .split-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 2.5rem;
    border-radius: 9999px;
    background-color: #9ca3af;
    opacity: 0;
    transition: opacity 0.15s;
  }

  .split-resizer:hover::after,
  .split-resizer.is-dragging::after,
  .split-resizer:focus-visible::after {
    opacity: 1;
  }
}

@media (max-width: 767px) {
  .split-resizer {
    width: 100%;
    height: 5px;
    cursor: row-resize;
  }
}

.split-resizer:hover,
.split-resizer.is-dragging {
  background-color: #6366f1;
}

.dark .split-resizer:hover,
.dark .split-resizer.is-dragging {
  background-color: #818cf8;
}

body.split-dragging {
  cursor: col-resize;
  user-select: none;
}

/* AI panel */
.ai-panel {
  position: fixed;
  top: 49px;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  z-index: 40;
  background: #fff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
}

.dark .ai-panel {
  background: #030712;
  border-left-color: #374151;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
}

.ai-panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1rem;
}

.ai-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.ai-auth-banner {
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  border-radius: 0.5rem;
  background: #fef3c7;
  color: #92400e;
}

.dark .ai-auth-banner {
  background: rgba(146, 64, 14, 0.2);
  color: #fde68a;
}

.ai-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  font-size: 0.875rem;
}

.dark .ai-select {
  border-color: #4b5563;
  background: #1f2937;
  color: #f3f4f6;
}

.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.ai-action-btn {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  border-radius: 9999px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.dark .ai-action-btn {
  border-color: #374151;
  background: #111827;
  color: #e5e7eb;
}

.ai-action-btn:hover:not(:disabled) {
  border-color: #818cf8;
  background: #eef2ff;
}

.dark .ai-action-btn:hover:not(:disabled) {
  background: rgba(49, 46, 129, 0.3);
}

.ai-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-output {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.dark .ai-output {
  border-color: #374151;
  background: #0a0a0a;
}

.ai-status {
  min-height: 1.25rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: #6b7280;
}

.ai-status[data-type="success"] { color: #059669; }
.ai-status[data-type="warn"] { color: #d97706; }
.ai-status[data-type="error"] { color: #dc2626; }

.ai-input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #d1d5db;
  background: #fff;
  font-size: 0.875rem;
  resize: vertical;
  outline: none;
}

.dark .ai-input {
  border-color: #4b5563;
  background: #1f2937;
  color: #f3f4f6;
}

.ai-input:focus {
  box-shadow: 0 0 0 2px #6366f1;
}

.ai-panel-footer {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ai-primary-btn,
.ai-secondary-btn {
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  border-radius: 0.5rem;
  cursor: pointer;
  border: none;
}

.ai-primary-btn {
  background: #4f46e5;
  color: #fff;
}

.ai-primary-btn:hover:not(:disabled) {
  background: #4338ca;
}

.ai-secondary-btn {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

.dark .ai-secondary-btn {
  background: #1f2937;
  color: #e5e7eb;
  border-color: #4b5563;
}

.ai-primary-btn:disabled,
.ai-secondary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toolbar-btn-ai {
  color: #4f46e5;
}

.dark .toolbar-btn-ai {
  color: #818cf8;
}

@media (max-width: 767px) {
  body.split-dragging {
    cursor: row-resize;
  }
}

/* Prose preview styles */
.prose-preview {
  line-height: 1.75;
  color: inherit;
}

.prose-preview h1 { font-size: 1.875rem; font-weight: 700; margin-top: 1.5rem; margin-bottom: 1rem; }
.prose-preview h2 { font-size: 1.5rem; font-weight: 700; margin-top: 1.25rem; margin-bottom: 0.75rem; }
.prose-preview h3 { font-size: 1.25rem; font-weight: 600; margin-top: 1rem; margin-bottom: 0.5rem; }
.prose-preview h4 { font-size: 1.125rem; font-weight: 600; margin-top: 0.75rem; margin-bottom: 0.5rem; }

.prose-preview p { margin-bottom: 1rem; }
.prose-preview a { color: #4f46e5; text-decoration: underline; }
.dark .prose-preview a { color: #818cf8; }

.prose-preview ul { list-style-type: disc; padding-left: 1.5rem; margin-bottom: 1rem; }
.prose-preview ol { list-style-type: decimal; padding-left: 1.5rem; margin-bottom: 1rem; }
.prose-preview li { margin-bottom: 0.25rem; }

.prose-preview blockquote {
  border-left: 4px solid #818cf8;
  padding-left: 1rem;
  font-style: italic;
  color: #4b5563;
  margin: 1rem 0;
}

.dark .prose-preview blockquote {
  color: #9ca3af;
}

.prose-preview hr { margin: 1.5rem 0; border-color: #d1d5db; }
.dark .prose-preview hr { border-color: #374151; }

.prose-preview table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.prose-preview th,
.prose-preview td {
  border: 1px solid #d1d5db;
  padding: 0.5rem 0.75rem;
}

.dark .prose-preview th,
.dark .prose-preview td {
  border-color: #374151;
}

.prose-preview th {
  background-color: #f3f4f6;
  font-weight: 600;
}

.dark .prose-preview th {
  background-color: #1f2937;
}

.prose-preview img { max-width: 100%; border-radius: 0.5rem; margin: 1rem 0; }

.prose-preview pre {
  border-radius: 0.5rem;
  margin: 1rem 0;
  overflow-x: auto;
  font-size: 0.875rem;
}

.prose-preview code:not([class*="language-"]) {
  background-color: #f3f4f6;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
}

.dark .prose-preview code:not([class*="language-"]) {
  background-color: #1f2937;
}

.prose-preview input[type="checkbox"] {
  margin-right: 0.5rem;
  accent-color: #4f46e5;
}

/* Shortcode: Note boxes */
.sc-note {
  border-radius: 0.5rem;
  padding: 1rem;
  margin: 1rem 0;
  border-left: 4px solid;
}

.sc-note-info {
  background-color: #eff6ff;
  border-color: #3b82f6;
  color: #1e3a8a;
}

.dark .sc-note-info {
  background-color: rgba(30, 58, 138, 0.2);
  color: #bfdbfe;
}

.sc-note-success {
  background-color: #f0fdf4;
  border-color: #22c55e;
  color: #14532d;
}

.dark .sc-note-success {
  background-color: rgba(20, 83, 45, 0.2);
  color: #bbf7d0;
}

.sc-note-danger {
  background-color: #fef2f2;
  border-color: #ef4444;
  color: #7f1d1d;
}

.dark .sc-note-danger {
  background-color: rgba(127, 29, 29, 0.2);
  color: #fecaca;
}

.sc-note-warning {
  background-color: #fefce8;
  border-color: #eab308;
  color: #713f12;
}

.dark .sc-note-warning {
  background-color: rgba(113, 63, 18, 0.2);
  color: #fef08a;
}

/* Shortcode: Columns */
.sc-columns {
  display: grid;
  gap: 1rem;
  margin: 1rem 0;
}

/* Shortcode: Color */
.sc-color-red { color: #ef4444; }
.sc-color-blue { color: #3b82f6; }
.sc-color-green { color: #22c55e; }
.sc-color-yellow { color: #eab308; }
.sc-color-purple { color: #a855f7; }
.sc-color-orange { color: #f97316; }

/* Shortcode: Alignment */
.sc-justify { text-align: justify; }
.sc-center { text-align: center; }
.sc-left { text-align: left; }
.sc-right { text-align: right; }

/* Shortcode: YouTube embed */
.sc-youtube {
  position: relative;
  width: 100%;
  margin: 1rem 0;
  overflow: hidden;
  border-radius: 0.5rem;
  aspect-ratio: 16 / 9;
}

.sc-youtube iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Mermaid diagrams */
.prose-preview .mermaid {
  margin: 1rem 0;
  display: flex;
  justify-content: center;
}

/* Preview header & footer — visible in preview and print */
.preview-header:empty,
.preview-footer:empty {
  display: none;
}

.preview-header:not(:empty),
.preview-footer:not(:empty) {
  padding: 1rem 1.5rem;
}

.preview-header:not(:empty) {
  border-bottom: 1px solid #e5e7eb;
}

.dark .preview-header:not(:empty) {
  border-bottom-color: #374151;
}

.preview-footer:not(:empty) {
  border-top: 1px solid #e5e7eb;
  margin-top: 1rem;
}

.dark .preview-footer:not(:empty) {
  border-top-color: #374151;
}
