/* ============================================================
   Markdown Note Editor — split view, preview, outline
   ============================================================ */

.note-editor__md-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 24px;
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.md-tool-btn {
  padding: 5px 10px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  background: transparent;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.md-tool-btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}

.md-toolbar__hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.note-editor__view-modes {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.note-editor__view-btn {
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  border: none;
  cursor: pointer;
}

.note-editor__view-btn.is-active {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.note-editor__export-wrap {
  position: relative;
}

.note-editor__export-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 160px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  overflow: hidden;
}

.note-editor__export-menu.is-open {
  display: block;
}

.note-editor__export-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  font-size: var(--font-size-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-primary);
}

.note-editor__export-menu button:hover {
  background: var(--color-bg-hover);
}

/* Selection scope banner — shown when user highlights a note section */
.note-editor__selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 24px;
  background: color-mix(in srgb, var(--color-accent) 12%, var(--color-bg-elevated));
  border-bottom: 1px solid color-mix(in srgb, var(--color-accent) 28%, var(--color-border));
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.note-editor__selection-bar[hidden] {
  display: none !important;
}

.note-editor__selection-bar-icon {
  font-size: 1rem;
  line-height: 1;
}

.note-editor__selection-bar-text {
  flex: 1;
  min-width: 200px;
}

.note-editor__selection-bar-preview {
  max-width: min(420px, 100%);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Find bar */
.note-editor__find-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: var(--color-bg-elevated);
  border-bottom: 1px solid var(--color-border);
}

.note-editor__find-bar.is-visible {
  display: flex;
  flex-wrap: wrap;
}

.note-editor__find-bar input {
  flex: 1;
  min-width: 120px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
}

.md-find-close {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 4px 8px;
}

/* Workspace layout */
.note-editor__workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px 16px;
}

.note-editor__outline {
  width: 200px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  padding: 16px 12px 16px 0;
  overflow-y: auto;
  transition: width var(--duration-normal), opacity var(--duration-normal);
}

.note-editor--outline-closed .note-editor__outline {
  width: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  border: none;
}

.md-outline__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-tertiary);
  margin-bottom: 12px;
}

.md-outline__header button {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-secondary);
}

.md-outline__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.md-outline__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.35;
}

.md-outline__item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.md-outline__item--h1 { font-weight: var(--font-weight-bold); padding-left: 4px; }
.md-outline__item--h2 { padding-left: 12px; }
.md-outline__item--h3 { padding-left: 20px; font-size: 11px; }
.md-outline__item--h4 { padding-left: 28px; font-size: 11px; opacity: 0.85; }

.md-outline__empty {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin: 0;
}

.note-editor__panes {
  flex: 1;
  display: flex;
  min-width: 0;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-bg-elevated);
}

.note-editor__pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 280px;
}

.note-editor__pane--editor {
  border-right: 1px solid var(--color-border);
}

.note-editor__pane--preview {
  background: var(--color-bg);
  overflow: hidden;
}

/* View modes */
.note-editor--editor .note-editor__pane--preview {
  display: none;
}

.note-editor--editor .note-editor__pane--editor {
  border-right: none;
}

.note-editor--preview .note-editor__pane--editor {
  display: none;
}

.note-editor--preview .note-editor__pane--preview {
  flex: 1;
}

.note-editor--split .note-editor__pane {
  flex: 1;
}

.note-editor__body {
  max-width: none;
  padding: 0;
}

.note-editor__content--md {
  flex: 1;
  min-height: 240px;
  padding: 20px 24px;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  font-size: 0.9375rem;
  line-height: 1.65;
  resize: none;
  border: none;
  background: transparent;
}

/* Markdown preview typography — base fallbacks; beautiful-notes.css enhances reading view */
.md-preview:not(.beautiful-note) {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  max-width: 720px;
  margin: 0 auto;
  line-height: 1.75;
  font-size: 1.0625rem;
  color: var(--color-text-primary);
}

.beautiful-note.md-preview {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  max-width: none;
  margin: 0;
}

.md-preview.is-rendering {
  opacity: 0.7;
}

.md-preview .md-heading {
  font-family: var(--font-display, inherit);
  font-weight: var(--font-weight-bold);
  line-height: 1.25;
  margin: 1.5em 0 0.6em;
  letter-spacing: var(--letter-spacing-tight, -0.02em);
}

.md-preview .md-h1 { font-size: 2rem; margin-top: 0; }
.md-preview .md-h2 { font-size: 1.5rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3em; }
.md-preview .md-h3 { font-size: 1.25rem; }
.md-preview .md-h4 { font-size: 1.1rem; }

.md-preview p {
  margin: 0 0 1em;
}

.md-preview ul,
.md-preview ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
}

.md-preview li {
  margin: 0.35em 0;
}

.md-preview .md-task-item {
  list-style: none;
  margin-left: -1.5em;
}

.md-preview blockquote {
  margin: 1em 0;
  padding: 0.5em 0 0.5em 1em;
  border-left: 4px solid var(--color-accent);
  color: var(--color-text-secondary);
  background: color-mix(in srgb, var(--color-accent) 6%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.md-preview hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2em 0;
}

.md-preview .md-pre {
  margin: 1em 0;
  padding: 1rem 1.25rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
}

.md-preview code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.md-preview :not(pre) > code {
  padding: 0.15em 0.4em;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-sm);
}

.md-preview a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-preview table,
.md-preview .md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25em 0;
  font-size: 0.9375rem;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 1.25em 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}

.md-table-wrap .md-table {
  margin: 0;
}

.md-preview th,
.md-preview td {
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  text-align: left;
}

.md-preview thead th {
  position: sticky;
  top: 0;
  background: var(--color-bg-elevated);
  font-weight: var(--font-weight-semibold);
  z-index: 1;
}

.md-preview .md-table__row--alt {
  background: color-mix(in srgb, var(--color-bg-subtle) 80%, transparent);
}

.md-preview-error {
  color: var(--color-text-tertiary);
  font-style: italic;
}

.note-editor__meta {
  max-width: 1400px;
}

.note-editor__footer .note-editor__stats {
  max-width: 1400px;
}

@media (max-width: 900px) {
  .note-editor--split .note-editor__panes {
    flex-direction: column;
  }

  .note-editor--split .note-editor__pane--editor {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 45vh;
  }

  .note-editor__outline {
    display: none;
  }

  .note-editor__workspace {
    padding: 0 12px 12px;
  }

  .note-editor__md-toolbar {
    padding: 8px 12px;
  }

  .md-toolbar__hint {
    display: none;
  }
}

@media (max-width: 768px) {
  .note-editor__view-modes {
    display: none;
  }
}
