/* Note editor (Track E) — toolbar + contenteditable surface for "My notes".
   Everything sits on the theme tokens (--surface, --border, --text, …), so
   light and dark come for free; the few literal hexes here are content colors
   (swatches, recording red handled via --danger) that read fine on both. */

.ne-root { display: flex; flex-direction: column; min-width: 0; }

/* ---------- toolbar ---------- */
.ne-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
  padding: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ne-toolbar .ne-spacer { flex: 1; }

.ne-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 var(--sp-1);
  flex-shrink: 0;
}

.ne-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 var(--sp-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text); /* buttons don't inherit color — dark mode needs this */
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.ne-btn:hover { background: var(--surface-2); }
.ne-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.ne-btn:disabled { opacity: 0.45; cursor: default; }
.ne-btn:disabled:hover { background: transparent; }

.ne-btn-i { font-style: italic; }
.ne-btn-u { text-decoration: underline; }
.ne-btn-s { text-decoration: line-through; }

.ne-select {
  height: 30px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}
/* Sized to the longest font name, not the 100% every base select gets: a
   962px font select pushed the rest of the toolbar onto extra rows
   (issue #16 F-94). */
.ne-select { width: auto; max-width: 140px; }
.ne-select-size { width: 58px; }

/* Color / highlight buttons hint at what they do. */
.ne-colorbtn { box-shadow: inset 0 -3px 0 #e11d48; }
.ne-hilitebtn { box-shadow: inset 0 -8px 0 rgba(253, 224, 71, 0.55); }

/* ---------- swatch popover ---------- */
.ne-popwrap { position: relative; display: inline-flex; }

.ne-pop {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  width: max-content;
  max-width: calc(100vw - 12px);
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.15);
}

.ne-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}
.ne-swatch:hover { transform: scale(1.12); }

/* "no highlight" swatch: surface circle with a diagonal strike */
.ne-swatch-none {
  background: linear-gradient(135deg,
    transparent 44%, var(--danger) 44%, var(--danger) 56%, transparent 56%),
    var(--surface);
}

/* ---------- mic button ---------- */
.ne-mic.ne-recording {
  color: var(--danger);
  border-color: var(--danger);
  animation: ne-pulse 1.2s ease-in-out infinite;
}

@keyframes ne-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ---------- editable page ---------- */
/* Limitless: min-height plus generous bottom padding, never a max-height. */
.ne-editor {
  min-height: 55vh;
  /* Text sits in from the frame like the toolbar's buttons, and lines stop
     at a readable measure (issue #16 F-41). */
  padding: var(--sp-4) var(--sp-5) 30vh;
  outline: none;
  color: var(--text);
  font-size: var(--fs-lg);
  line-height: var(--lh-loose);
  overflow-wrap: break-word;
  cursor: text;
}

.ne-editor > * { max-width: var(--measure); }

.ne-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.ne-editor.ne-dropping {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  background: var(--accent-soft);
  border-radius: var(--radius);
}

/* Content typography inside the note */
.ne-editor h1 { font-size: var(--fs-2xl); margin: var(--sp-4) 0 var(--sp-2); }
/* The first line of a note is its title: a touch bigger, flush to the top. */
.ne-editor > h1:first-child { font-size: 1.75rem; margin-top: var(--sp-0); }
.ne-editor h2 { font-size: var(--fs-xl); margin: var(--sp-4) 0 var(--sp-2); }
.ne-editor h3 { font-size: var(--fs-lg); margin: var(--sp-3) 0 var(--sp-1); }
.ne-editor p { margin: 0 0 var(--sp-2); }
.ne-editor ul, .ne-editor ol { margin: var(--sp-2) 0; padding-left: var(--sp-6); }
.ne-editor li { margin: var(--sp-0) 0; }
/* Tab-indented sub-bullets. WebKit's "indent" nests the list as a SIBLING of
   the list items (<ul><li>a</li><ul><li>b</li></ul></ul>), so match both that
   shape and the li-wrapped one; a nested list is part of the line above it and
   must not open up a gap. The UA sheet already switches the marker glyph
   (disc → circle → square) by depth. */
.ne-editor ul ul, .ne-editor ul ol, .ne-editor ol ul, .ne-editor ol ol { margin: var(--sp-0) 0; }
.ne-editor blockquote {
  margin: var(--sp-2) 0;
  padding: var(--sp-1) var(--sp-3);
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}
.ne-editor pre, .ne-editor code {
  font-family: Menlo, Monaco, "Courier New", monospace;
  font-size: var(--fs-sm);
  background: var(--surface-2);
  border-radius: 6px;
}
.ne-editor pre { padding: var(--sp-3); overflow-x: auto; }
.ne-editor code { padding: 1px var(--sp-1); }
.ne-editor a { color: var(--accent); }

.ne-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: var(--sp-2) 0;
}

/* ---------- inline sketch blocks ----------
   One <div class="ne-sketch" data-sketch="…"> per drawing; the SVG inside it
   is hydrated by js/noteedit-sketches.js and never persisted. The frame is token-driven
   so both themes come for free, but the PAPER the ink sits on is a fixed white
   in both themes — stroke and text colors are stored as literal hex in the
   board JSON (default ink #10233b), so a --surface-tinted page would swallow
   a default-pen drawing in dark mode. Same trade-off, and the same fix, as
   .wb-stage in css/whiteboard.css. */
.ne-sketch {
  position: relative;
  display: block;
  margin: var(--sp-3) 0;
  padding: var(--sp-2);
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.ne-sketch:hover,
.ne-sketch.ne-sketch-open {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.ne-sketch-art {
  display: block;
  max-width: 100%;
  max-height: 320px;
  overflow: auto;
  background: #ffffff; /* fixed paper in BOTH themes — see the note above */
  border-radius: calc(var(--radius) - 3px);
}

.ne-sketch svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Sits ON the fixed white paper, so its color is fixed too. */
.ne-sketch-empty {
  display: block;
  padding: var(--sp-6) var(--sp-3);
  text-align: center;
  color: #5b6b7f;
  font-size: var(--fs-sm);
}

/* Hover toolbar — no caption, just the two actions. */
.ne-sketch-bar {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  gap: var(--sp-1);
}
.ne-sketch:hover .ne-sketch-bar,
.ne-sketch.ne-sketch-open .ne-sketch-bar { display: flex; }

.ne-sketch-act {
  height: 24px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}
.ne-sketch-act:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.ne-btn-sketch { letter-spacing: 0.5px; }

/* ---------- sketch editing modal ---------- */
.ne-sketch-modal { z-index: 1100; }

.ne-sketch-modal .modal-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1040px;
  max-height: 88vh;
  overflow: auto; /* the whiteboard has a 460px min-height — scroll, don't clip */
}

.ne-sketch-stage {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
}
.ne-sketch-stage > .wb-root { flex: 1; min-width: 0; }

.ne-sketch-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

/* Upload-in-flight placeholder chip */
.ne-uploading {
  display: inline-block;
  padding: var(--sp-0) var(--sp-3);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 600;
  animation: ne-pulse 1.2s ease-in-out infinite;
  user-select: none;
}

/* ---------- AI assist ----------
   Two surfaces, both position:fixed children of .ne-root (never <body> — the
   SPA caches page nodes rather than tearing them down), plus the marker on
   generated text inside the note itself. */

/* Generated text. The CLASS IS NOT PERSISTED — mynotes.sanitize_html keeps
   `class` only on div.ne-sketch — so the shape carries its own look: <em>
   supplies the italic and an inline color: survives as one of the five
   allowed style properties. These rules are the live-session polish on top. */
.ne-editor .ne-ai {
  font-style: italic;
  /* Beats the inline #64748b the saved shape carries, which reads 3.56:1 on
     the dark surface (issue #16 F-34). Saved notes lose the class, so they
     keep the inline colour. */
  color: var(--text-muted) !important;
}

/* The non-list landing spot. blockquote is already indented and muted by the
   rule above in this file; this only softens the accent rule for AI text. */
.ne-editor blockquote.ne-ai-sub { border-left-color: var(--border); }

/* Waiting on the model: inert, and stripped from getHTML() so a concurrent
   autosave cannot persist it. */
.ne-editor .ne-ai-pending {
  opacity: 0.6;
  user-select: none;
  -webkit-user-select: none;
  animation: ne-pulse 1.2s ease-in-out infinite;
}

/* Right-click menu on a selection. Same visual language as the note-card menu
   in css/notes.css, with its own classes — that file is not edited here. */
.ne-ai-menu {
  position: fixed;
  z-index: 70;
  min-width: 180px;
  max-width: 260px;
  padding: var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.15);
}
.ne-ai-menu-title {
  padding: var(--sp-1) var(--sp-3) var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.ne-ai-menu-div {
  height: 1px;
  margin: var(--sp-1) var(--sp-2);
  background: var(--border);
}
.ne-ai-item {
  display: block;
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text);
  background: none;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.ne-ai-item:hover { background: var(--surface-2); }

/* Suggestion chip under the caret. Not focusable, not selectable and
   pointer-events:none — it must never steal the caret it is pointing at. */
.ne-chip {
  position: fixed;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: min(440px, 90vw);
  padding: var(--sp-1) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.14);
  font-size: var(--fs-sm);
  line-height: var(--lh-tight);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.ne-chip-text {
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 760px) {
  .ne-chip-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}
.ne-chip-hint {
  flex-shrink: 0;
  padding: 1px var(--sp-2);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-2xs);
  font-weight: 600;
  white-space: nowrap;
}
