.editor-container {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.codemirror-host {
  height: 100%;
}

.codemirror-host .cm-editor {
  height: 100%;
  outline: none;
}

.editor-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: 15px;
  pointer-events: none;
  z-index: 1;
}

.editor-empty p {
  margin: 0;
}

.editor-empty-hint {
  font-size: 12px;
  opacity: 0.6;
}

/* ── CodeMirror search panel ──────────────────────────────────── */

.cm-panels-top {
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.cm-panel.cm-search {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 8px;
  padding: 7px 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--sidebar-bg);
}

/* Hide the <br> CM inserts — we handle the row break via ::after */
.cm-search br { display: none; }

/* ::after creates a full-width flex item that forces the replace
   row (order ≥ 10) onto a new line                               */
.cm-panel.cm-search::after {
  content: '';
  flex-basis: 100%;
  height: 0;
  order: 9;
}

/* Close button pinned to the top-right corner of the panel       */
.cm-panel.cm-search {
  position: relative;
  padding-right: 36px;
}

/* ── Replace row (order 10–12) ── */
.cm-search input[name="replace"]     { order: 10; }
.cm-search button[name="replace"]    { order: 11; }
.cm-search button[name="replaceAll"] { order: 12; }

.cm-search .cm-textfield {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 3px 8px;
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  min-width: 160px;
}

.cm-search .cm-textfield:focus {
  border-color: var(--accent);
}

.cm-search .cm-button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  padding: 3px 9px;
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.cm-search .cm-button:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
  border-color: var(--accent);
}

.cm-search label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.cm-search label input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* Close button — pinned top-right */
.cm-search button[name="close"] {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
}

.cm-search button[name="close"]:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

/* Search match highlights in the document */
.cm-searchMatch {
  background: rgba(167, 139, 95, 0.25);
  border-radius: 2px;
  outline: 1px solid rgba(167, 139, 95, 0.4);
}

.cm-searchMatch.cm-searchMatch-selected {
  background: rgba(167, 139, 95, 0.55);
  outline: 1px solid var(--accent);
}

/* ── Annotation hover tooltip ─────────────────────────────────── */

/* Strip CodeMirror's default tooltip chrome */
.cm-tooltip.cm-tooltip-hover {
  border: none;
  background: transparent;
  padding: 0;
  box-shadow: none;
  transform: translateX(-50%);
}

.annotation-tooltip {
  position: relative;
  background: var(--message-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  max-width: 320px;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Invisible bridge that extends CodeMirror's isInTooltip() hit-area into the
   gap between the card and the annotation text, preventing the card from
   dismissing while the mouse travels between them. */
.annotation-tooltip > .cm-tooltip-arrow {
  position: absolute;
  bottom: -12px;
  left: 0;
  right: 0;
  height: 12px;
  pointer-events: none;
  background: transparent;
  border: none;
}

.annotation-tooltip-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.annotation-tooltip-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.annotation-tooltip-dismiss {
  float: right;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 0 0 8px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
}

.annotation-tooltip-dismiss:hover {
  opacity: 1;
  color: var(--text-primary);
}

.annotation-tooltip-body {
  color: var(--text-primary);
  word-break: break-word;
}

.annotation-tooltip-body p {
  margin: 0 0 8px;
}
.annotation-tooltip-body p:last-child {
  margin-bottom: 0;
}
.annotation-tooltip-body strong {
  font-weight: 600;
}
.annotation-tooltip-body em {
  color: var(--text-secondary);
}
.annotation-tooltip-body code {
  font-family: monospace;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 3px;
  padding: 1px 4px;
}
.annotation-tooltip-body blockquote {
  border-left: 2px solid var(--accent);
  margin: 4px 0;
  padding: 1px 8px;
  color: var(--text-secondary);
  font-style: italic;
}
.annotation-tooltip-body ul,
.annotation-tooltip-body ol {
  margin: 2px 0 4px;
  padding-left: 16px;
}
.annotation-tooltip-body li {
  margin-bottom: 2px;
}

.annotation-tooltip-loading {
  color: var(--text-muted);
  font-style: italic;
}

.annotation-tooltip-apply {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 5px 10px;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.annotation-tooltip-apply:hover {
  background: var(--accent);
  color: var(--bg-base);
}

/* ── Comment input modal ───────────────────────────────── */
.comment-modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
}

.comment-modal {
  background: var(--message-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.comment-modal-excerpt {
  font-family: var(--font-serif);
  font-size: 12px;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.5;
  border-left: 2px solid rgba(240, 100, 180, 0.65);
  padding-left: 8px;
}

.comment-modal-input {
  background: var(--input-bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.55;
  padding: 7px 10px;
  resize: vertical;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.comment-modal-input:focus {
  border-color: rgba(240, 100, 180, 0.65);
}

.comment-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.comment-modal-cancel {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 12px;
  cursor: pointer;
  transition: color 0.15s;
}

.comment-modal-cancel:hover {
  color: var(--text-primary);
}

.comment-modal-save {
  background: rgba(240, 100, 180, 0.85);
  border: none;
  border-radius: 4px;
  color: #1a0a12;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.comment-modal-save:hover:not(:disabled) {
  opacity: 0.85;
}

.comment-modal-save:disabled {
  opacity: 0.35;
  cursor: default;
}
