/* ── Rich Text Editor ── */

.rte-wrap {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
  background: var(--surface-1);
  overflow: hidden;
  transition: border-color 0.15s;
}
.rte-wrap.rte-focused {
  border-color: rgba(0, 122, 255, 0.35);
}

/* ── Toolbar ── */

.rte-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: relative;
}
.rte-toolbar::-webkit-scrollbar { display: none; }

/* When toolbar is below the editor */
.rte-wrap > .rte-editor:first-child + .rte-toolbar {
  border-bottom: none;
  border-top: 1px solid var(--divider);
}

.rte-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.rte-btn:hover { background: var(--border); }
.rte-btn:active { background: var(--border-strong); }

.rte-btn svg {
  display: block;
  pointer-events: none;
}

.rte-sep {
  flex: 0 0 auto;
  width: 1px;
  height: 18px;
  margin: 0 2px;
  background: var(--divider);
}

/* ── Heading picker dropdown ── */

.rte-heading-picker {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  min-width: 150px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
  box-shadow: var(--shadow-1);
  padding: 4px;
  display: flex;
  flex-direction: column;
}

.rte-heading-option {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.1s;
}
.rte-heading-option:hover { background: var(--border); }

/* ── Editor area ── */

.rte-editor {
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: inherit;
  line-height: var(--lh-loose);
  outline: none;
  overflow-y: auto;
  word-wrap: break-word;
  -webkit-user-modify: read-write-plaintext-only; /* prevent paste styling on Safari — removed, we want rich paste */
}
/* override: allow rich editing */
.rte-editor {
  -webkit-user-modify: read-write;
}

.rte-editor:empty::before,
.rte-editor.rte-empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
  position: absolute;
}
/* Only show placeholder when truly empty */
.rte-editor:not(.rte-empty)::before {
  content: none;
}

/* ── Inline formatting ── */

.rte-editor h1 {
  font-size: 1.5em;
  font-weight: 700;
  line-height: var(--lh-tight);
  margin: 0.3em 0 0.2em;
}
.rte-editor h2 {
  font-size: 1.2em;
  font-weight: 600;
  line-height: var(--lh);
  margin: 0.3em 0 0.15em;
}
.rte-editor h3 {
  font-size: 1em;
  font-weight: 600;
  color: var(--muted);
  line-height: var(--lh);
  margin: 0.25em 0 0.1em;
}
.rte-editor p {
  margin: 0.15em 0;
}
.rte-editor ul,
.rte-editor ol {
  margin: 0.25em 0;
  padding-left: 1.5em;
}
.rte-editor li {
  margin: 0.1em 0;
}

/* ── Checklist ── */

.rte-editor ul.rte-checklist {
  list-style: none;
  padding-left: 0;
}
.rte-editor ul.rte-checklist li {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 2px 0;
}
.rte-editor ul.rte-checklist li input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 3px;
  accent-color: var(--accent);
  cursor: pointer;
}
.rte-editor ul.rte-checklist li[data-checked="true"] > span {
  text-decoration: line-through;
  color: var(--muted);
}

/* ── Rendered content (note cards, display contexts) ── */

.note-text ul.rte-checklist,
.reminder-notes ul.rte-checklist,
.health-grounding-history ul.rte-checklist {
  list-style: none;
  padding-left: 0;
}
.note-text ul.rte-checklist li,
.reminder-notes ul.rte-checklist li,
.health-grounding-history ul.rte-checklist li {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 2px 0;
}
.note-text ul.rte-checklist li input[type="checkbox"],
.reminder-notes ul.rte-checklist li input[type="checkbox"],
.health-grounding-history ul.rte-checklist li input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--accent);
  pointer-events: none;
}
.note-text ul.rte-checklist li[data-checked="true"] > span,
.reminder-notes ul.rte-checklist li[data-checked="true"] > span,
.health-grounding-history ul.rte-checklist li[data-checked="true"] > span {
  text-decoration: line-through;
  color: var(--muted);
}

/* Rendered headings in note cards */
.note-text h1 { font-size: 1.3em; font-weight: 700; margin: 0.2em 0; }
.note-text h2 { font-size: 1.1em; font-weight: 600; margin: 0.2em 0; }
.note-text h3 { font-size: 1em; font-weight: 600; color: var(--muted); margin: 0.15em 0; }
.note-text ul, .note-text ol { padding-left: 1.3em; margin: 0.15em 0; }

/* ── Mobile touch targets ── */
@media (pointer: coarse) {
  .rte-btn {
    width: 36px;
    height: 36px;
  }
  .rte-toolbar {
    gap: 1px;
    padding: 4px;
  }
}
