/* leaf notes — rich text editor (TipTap) presented as a calm, centered writing page. */
.notes-editor-v2 { display: none; position: relative; flex: 1; flex-direction: column; min-height: 0; background: var(--editor-paper); }

.editor-v2-enabled #notes-input { display: none; }
.editor-v2-enabled .notes-editor-v2 { display: flex; }
body:not(.editor-v2-enabled) .editor-v2-only { display: none !important; }
.notes-focus-mode .notes-layout .panel-left { width: 100% !important; }
.notes-focus-mode .notes-layout .panel-right,
.notes-focus-mode .notes-layout .splitter { display: none; }

/* Toolbar: floating pill, centered over the page */
.notes-editor-toolbar {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 2px;
  align-self: center;
  max-width: calc(100% - 24px);
  min-height: 44px;
  margin: 12px auto 0;
  padding: 4px 6px;
  overflow-x: auto;
  flex-shrink: 0;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  box-shadow: var(--shadow-toolbar);
  scrollbar-width: none;
  animation: rise-in var(--leaf-motion-slow) var(--leaf-ease-arrive) backwards .05s;
}
.notes-editor-toolbar::-webkit-scrollbar { display: none; }

.notes-editor-toolbar-group { display: flex; align-items: center; gap: 1px; }
.notes-editor-separator { flex: 0 0 1px; width: 1px; height: 20px; margin: 0 5px; background: var(--color-rule-strong); }
.notes-editor-image-tools { padding-left: 6px; margin-left: 4px; border-left: 1px solid var(--color-rule-strong); animation: fade-in var(--motion-fast) backwards; }

.notes-editor-toolbar button,
.notes-editor-more > summary {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  background: transparent;
  font-family: var(--type-ui);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
  transition: background-color var(--motion-fast), color var(--motion-fast), transform var(--leaf-motion-instant);
}
.notes-editor-toolbar .tb-text { font-size: 13px; letter-spacing: -.01em; }
.notes-editor-toolbar .tb-text strong { font-weight: 800; }
.notes-editor-toolbar .tb-text em { font-family: var(--type-display); font-size: 15px; font-style: italic; }
.notes-editor-toolbar button:hover:not(:disabled),
.notes-editor-more > summary:hover { color: var(--color-text-primary); background: var(--color-hover); }
.notes-editor-toolbar button:active:not(:disabled) { transform: scale(.94); }
.notes-editor-toolbar button.is-active { color: var(--color-action-primary); background: var(--color-action-primary-tint-strong); }
.notes-editor-toolbar button:disabled { opacity: .32; cursor: default; }
.notes-editor-more[open] > summary { color: var(--color-action-on-primary); background: var(--color-action-primary); }
.notes-editor-more > summary .i { transition: transform var(--motion-normal); }
.notes-editor-more[open] > summary .i { transform: rotate(45deg); }

.btn-mic.active { color: var(--color-action-on-primary) !important; background: var(--color-feedback-error) !important; animation: flash-ring 1.4s ease-out infinite; }

.notes-editor-more { position: relative; }
.notes-editor-more-panel {
  position: fixed;
  z-index: var(--leaf-z-menu);
  display: grid;
  gap: 12px;
  width: min(340px, calc(100vw - 24px));
  padding: 12px;
  transform-origin: top right;
}
.notes-editor-more-section { display: grid; gap: 6px; }
.notes-editor-more-label { color: var(--color-text-faint); font-size: 11.5px; font-weight: 600; }
.notes-editor-more-panel .notes-editor-toolbar-group { flex-wrap: wrap; gap: 4px; }
.notes-editor-more-panel button {
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-primary);
  background: var(--color-surface);
  font-size: 12.5px;
  font-weight: 500;
}
.notes-editor-more-panel button:hover:not(:disabled) { border-color: var(--color-rule-strong); }
.notes-editor-tools-group select {
  min-height: 32px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-sm);
  font-size: 12.5px;
  cursor: pointer;
}
.notes-editor-find-group { width: 100%; }
.notes-editor-find-group input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-primary);
  background: var(--color-canvas-soft);
  font-size: 12.5px;
  outline: none;
}
.notes-editor-find-group input:focus-visible { border-color: var(--color-action-primary); box-shadow: 0 0 0 3px var(--color-action-primary-tint-strong); }
.notes-editor-file-input { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.notes-editor-marker { padding: 0 2px; box-shadow: inset 0 -.55em 0 var(--editor-highlight); }

/* Page */
.notes-editor-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-padding: 80px 0 120px; }
.notes-page { width: min(100%, calc(var(--reading-max) + 96px)); margin: 0 auto; padding: 36px 48px 0; }
.notes-page-hd { margin-bottom: 18px; }
.notes-page-eyebrow { margin-bottom: 6px; }
.notes-title-input {
  width: 100%;
  padding: 0;
  border: 0;
  outline: none;
  color: var(--color-text-primary);
  background: transparent;
  font-family: var(--type-display);
  font-size: clamp(30px, 3.4vw, 40px);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -.02em;
}
.notes-title-input::placeholder { color: color-mix(in srgb, var(--color-text-faint) 70%, transparent); }

.notes-editor-outline { display: none; gap: 6px; margin: 0 0 18px; overflow-x: auto; scrollbar-width: none; }
.notes-editor-outline.is-visible { display: flex; animation: fade-in var(--motion-normal) backwards; }
.notes-editor-outline-item {
  flex: 0 0 auto;
  max-width: 200px;
  padding: 4px 10px;
  overflow: hidden;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  background: var(--color-surface);
  font-size: 11.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color var(--motion-fast), color var(--motion-fast);
}
.notes-editor-outline-item:hover { border-color: var(--color-rule-strong); color: var(--color-text-primary); }
.notes-editor-outline-item.level-1 { color: var(--color-action-primary); font-weight: 650; }
.notes-editor-outline-item.level-3 { opacity: .78; }

.notes-editor-surface { min-height: 50vh; cursor: text; }
.notes-editor-surface .tiptap {
  min-height: 55vh;
  padding: 0 0 40vh;
  outline: none;
  color: var(--editor-text);
  caret-color: var(--color-action-primary);
  font-family: var(--type-notes-editor-body);
  font-size: var(--editor-body-size);
  line-height: var(--editor-body-leading);
  overflow-wrap: break-word;
}
.notes-editor-surface .tiptap:focus-visible { outline: none; }

.notes-editor-surface .tiptap > *:first-child { margin-top: 0; }
.notes-editor-surface .tiptap p { margin: 0 0 .85em; }
.notes-editor-surface .tiptap h1,
.notes-editor-surface .tiptap h2,
.notes-editor-surface .tiptap h3 { color: var(--color-text-primary); line-height: 1.2; letter-spacing: -.01em; }
.notes-editor-surface .tiptap h1 { margin: 1.3em 0 .45em; font-size: 1.75em; font-weight: 550; }
.notes-editor-surface .tiptap h2 { margin: 1.2em 0 .4em; color: var(--color-action-primary); font-size: 1.38em; font-weight: 560; }
.notes-editor-surface .tiptap h3 { margin: 1em 0 .35em; font-size: 1.15em; font-weight: 620; }
.notes-editor-surface .tiptap ul,
.notes-editor-surface .tiptap ol { padding-left: 1.35em; }
.notes-editor-surface .tiptap li::marker { color: var(--color-text-faint); }
.notes-editor-surface .tiptap li p { margin: .14em 0; }
.notes-editor-surface .tiptap blockquote { margin: 1.2em 0; padding-left: 1em; border-left: 3px solid color-mix(in srgb, var(--color-action-primary) 55%, transparent); color: var(--color-text-muted); }
.notes-editor-surface .tiptap pre { padding: 16px; overflow-x: auto; border-radius: var(--leaf-radius-md); color: var(--editor-code-fg); background: var(--editor-code-bg); font: 12.5px/1.6 var(--type-data); }
.notes-editor-surface .tiptap code:not(pre code) { padding: .1em .3em; border-radius: var(--leaf-radius-xs); background: var(--color-surface-alt); font-size: .84em; }
.notes-editor-surface .tiptap mark { padding: .02em .08em; border-radius: var(--leaf-radius-xs); background: var(--editor-highlight); }
.notes-editor-surface .tiptap hr { margin: 2em 0; border: 0; border-top: 1px solid var(--color-rule-strong); }
.notes-editor-surface .tiptap figure[data-leaf-image] { width: min(var(--leaf-image-width, 100%), 960px); max-width: 100%; margin: 1.25em auto; }
.notes-editor-surface .tiptap figure[data-leaf-image][data-align='left'] { margin-left: 0; margin-right: auto; }
.notes-editor-surface .tiptap figure[data-leaf-image][data-align='right'] { margin-left: auto; margin-right: 0; }
.notes-editor-surface .tiptap figure[data-leaf-image] img { display: block; width: 100%; max-width: 100%; height: auto; border: 1px solid var(--color-rule); border-radius: var(--leaf-radius-md); box-shadow: var(--card-shadow); }
.notes-editor-surface .tiptap figure[data-leaf-image] figcaption { margin-top: 7px; color: var(--color-text-muted); font: 12px/1.45 var(--type-ui); text-align: center; }
.notes-editor-surface .tiptap figure[data-leaf-image] figcaption:empty { display: none; }
.notes-editor-surface .tiptap figure[data-leaf-image].ProseMirror-selectednode { outline: 2px solid var(--color-action-primary); outline-offset: 4px; border-radius: var(--leaf-radius-md); }
.notes-editor-surface .tiptap a { color: var(--color-action-primary); text-decoration: underline; text-underline-offset: 2px; }
.notes-editor-surface .tiptap table { width: 100%; margin: 1.2em 0; border-collapse: collapse; table-layout: fixed; }
.notes-editor-surface .tiptap th,
.notes-editor-surface .tiptap td { min-width: 90px; padding: 8px 10px; border: 1px solid var(--color-rule-strong); vertical-align: top; }
.notes-editor-surface .tiptap th { color: var(--color-action-primary); background: var(--color-surface-alt); font-weight: 650; text-align: left; }
.notes-editor-surface .tiptap .selectedCell { background: color-mix(in srgb, var(--leaf-color-sage-200) 35%, transparent); }
.notes-editor-surface .tiptap .tiptap-mathematics-render { cursor: pointer; }
.notes-editor-surface .tiptap div.tiptap-mathematics-render { margin: 1em 0; padding: 12px; overflow-x: auto; border-radius: var(--leaf-radius-sm); background: var(--color-surface-alt); text-align: center; }
.notes-editor-surface .tiptap .inline-math-error,
.notes-editor-surface .tiptap .block-math-error { color: var(--color-feedback-error); font-family: var(--type-data); }
.notes-editor-surface .tiptap p.is-editor-empty:first-child::before { content: attr(data-placeholder); float: left; height: 0; color: var(--color-text-faint); font-style: italic; pointer-events: none; }
.notes-editor-surface .tiptap ul[data-type='taskList'] { padding: 0; list-style: none; }
.notes-editor-surface .tiptap ul[data-type='taskList'] li { display: flex; gap: 10px; align-items: flex-start; }
.notes-editor-surface .tiptap ul[data-type='taskList'] label { padding-top: .3em; }
.notes-editor-surface .tiptap ul[data-type='taskList'] input { width: 16px; height: 16px; accent-color: var(--color-action-primary); }
.notes-editor-surface .tiptap ul[data-type='taskList'] li[data-checked='true'] > div { color: var(--color-text-faint); text-decoration: line-through; transition: color var(--motion-normal); }
.notes-editor-surface .tiptap ul[data-type='taskList'] div { flex: 1; }

/* Footer status bar */
.notes-editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 34px;
  flex-shrink: 0;
  padding: 0 16px;
  border-top: 1px solid var(--color-rule);
  color: var(--color-text-faint);
  background: color-mix(in srgb, var(--color-canvas) 70%, var(--color-canvas-soft));
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.draft-save-control { display: inline-flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; text-align: right; }
#notes-editor-save-state { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: color var(--motion-normal); }
#notes-editor-save-state::before {
  content: '';
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-border);
  transition: background-color var(--motion-normal);
}
.notes-editor-footer [data-state='saving'],
.notes-editor-footer [data-state='local'],
.notes-editor-footer [data-state='offline'] { color: var(--status-saving-fg); }
.notes-editor-footer [data-state='saving']::before { background: var(--status-saving-fg); animation: pulse-dot 1s ease-in-out infinite; }
.notes-editor-footer [data-state='local']::before,
.notes-editor-footer [data-state='offline']::before { background: var(--status-saving-fg); }
.notes-editor-footer [data-state='cloud'],
.notes-editor-footer [data-state='saved'] { color: var(--color-action-primary); }
.notes-editor-footer [data-state='cloud']::before,
.notes-editor-footer [data-state='saved']::before { background: var(--color-action-primary); }
.notes-editor-footer [data-state='error'] { color: var(--color-feedback-error); }
.notes-editor-footer [data-state='error']::before { background: var(--color-feedback-error); }
.draft-save-control button {
  min-height: 26px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-action-primary);
  background: var(--color-action-primary-tint);
  font-size: 11.5px;
  font-weight: 650;
  cursor: pointer;
}
.draft-save-control button:hover { background: var(--color-action-primary-tint-strong); }

@media (max-width: 900px) {
  .notes-editor-toolbar { margin-top: 10px; }
  .notes-page { padding: 24px 28px 0; }
}

@media (max-width: 600px) {
  .notes-editor-toolbar { max-width: calc(100% - 16px); margin-top: 8px; }
  .notes-editor-toolbar button,
  .notes-editor-more > summary { min-width: 38px; height: 38px; }
  .notes-page { padding: 20px 18px 0; }
  .notes-editor-surface .tiptap { font-size: 16.5px; padding-bottom: 30vh; }
  .notes-editor-footer { padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); flex-wrap: wrap; gap: 2px 10px; }
}
