/* Account-backed bookmarks UI — warm carbon theme.
 *
 * Three surfaces styled here:
 *  1. Sidebar Bookmarks pane (folder tree, DnD, folder CRUD).
 *  2. Anon CTA card (replaces the empty state for non-logged-in visitors).
 *  3. Star button anon popover (re-parented to body, see bookmarks.js).
 *
 * All colors come from --bg-* / --text-* / --accent — no hard-coded grays.
 */

/* ─── Pane header ─────────────────────────────────────────────────────── */
.rvt-bm-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--bg-2);
}
.rvt-bm-new-folder {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--bg-2);
  color: var(--text-1);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.rvt-bm-new-folder:hover {
  background: var(--bg-2);
  color: var(--accent);
  border-color: var(--accent);
}
.rvt-bm-header-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.rvt-bm-new-folder-form {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--bg-2);
  align-items: center;
}
.rvt-bm-new-folder-form[hidden] { display: none; }
.rvt-bm-new-folder-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-0);
  border: 1px solid var(--bg-2);
  color: var(--text-0);
  padding: 4px 8px;
  font-size: 13px;
  border-radius: 4px;
  outline: none;
}
.rvt-bm-new-folder-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.rvt-bm-new-folder-input.has-error {
  border-color: #d9534f;
  box-shadow: 0 0 0 2px rgba(217, 83, 79, 0.2);
}
.rvt-bm-new-folder-save,
.rvt-bm-new-folder-cancel {
  background: var(--bg-2);
  border: 1px solid var(--bg-2);
  color: var(--text-1);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}
.rvt-bm-new-folder-save { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 600; }
.rvt-bm-new-folder-cancel { width: 28px; padding: 0; line-height: 1; font-size: 16px; }

/* ─── Folder list ─────────────────────────────────────────────────────── */
.rvt-bm-folders {
  padding: 4px 0;
}
.rvt-bm-folder {
  border-bottom: 1px solid transparent;
}
/* Dark-gray hairline between sibling folders so the boundary reads as a
 * deliberate divider, not just a margin gap. Uses --bg-3 (the deepest
 * surface token) so the line is visible against the panel without going
 * black. The first folder doesn't get a top border (separator is between
 * folders, not before the first one). */
.rvt-bm-folder + .rvt-bm-folder {
  margin-top: 2px;
  border-top: 1px solid var(--bg-3);
  padding-top: 2px;
}
.rvt-bm-folder-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
  transition: background 100ms ease;
}
.rvt-bm-folder-summary::-webkit-details-marker { display: none; }
.rvt-bm-folder-summary:hover {
  background: var(--bg-2);
  color: var(--text-0);
}
.rvt-bm-folder-chev {
  display: inline-block;
  width: 10px;
  font-size: 10px;
  color: var(--text-3);
  transition: transform 120ms ease;
}
.rvt-bm-folder[open] > summary .rvt-bm-folder-chev {
  transform: rotate(90deg);
}
/* Folder icon — colored outline when closed, colored fill when open.
 * The color comes from --rvt-bm-folder-color, set by the [data-color]
 * selectors below. The path inside the SVG receives the fill only when
 * the <details> is open, giving a hollow → filled visual on expansion. */
.rvt-bm-folder-icon {
  color: var(--rvt-bm-folder-color, var(--text-3));
  flex-shrink: 0;
  transition: color 120ms ease;
}
.rvt-bm-folder[data-color] .rvt-bm-folder-icon { color: var(--rvt-bm-folder-color, var(--accent)); }
.rvt-bm-folder[open] > summary .rvt-bm-folder-icon { color: var(--rvt-bm-folder-color, var(--accent)); }
.rvt-bm-folder[open] > summary .rvt-bm-folder-icon-path {
  fill: var(--rvt-bm-folder-color, var(--accent));
  fill-opacity: 0.22;
}
/* The default folder gets a subtler fill so it doesn't look "selected"
 * when open — its gray is meant to fade into the background. */
.rvt-bm-folder[data-is-default="1"][open] > summary .rvt-bm-folder-icon-path {
  fill-opacity: 0;
}

/* Color palette. The folder element gets a `data-color` attribute via
 * renderFolder; we read it here to populate the CSS variable that drives
 * the folder icon's color AND the folder-name tint. Two vars on purpose:
 *  - --rvt-bm-folder-color drives the icon (always set, falls back to gray
 *    for the default folder / colorless folders so the icon stays visible).
 *  - --rvt-bm-folder-name-color drives the title text (only set for real
 *    colors — for default/colorless folders the title falls back to
 *    --text-1 so it stays readable, otherwise a gray-on-gray name would
 *    fade into the panel background). */
.rvt-bm-folder[data-color=""]       { --rvt-bm-folder-color: var(--text-3); }
/* The default folder is always gray regardless of whatever value the
 * `color` field may carry — defense in depth against a buggy migration. */
.rvt-bm-folder[data-is-default="1"] { --rvt-bm-folder-color: var(--text-3); }
.rvt-bm-folder[data-color="red"]    { --rvt-bm-folder-color: #ef4444; --rvt-bm-folder-name-color: #ef4444; }
.rvt-bm-folder[data-color="orange"] { --rvt-bm-folder-color: #f97316; --rvt-bm-folder-name-color: #f97316; }
.rvt-bm-folder[data-color="amber"]  { --rvt-bm-folder-color: #f59e0b; --rvt-bm-folder-name-color: #f59e0b; }
.rvt-bm-folder[data-color="green"]  { --rvt-bm-folder-color: #10b981; --rvt-bm-folder-name-color: #10b981; }
.rvt-bm-folder[data-color="teal"]   { --rvt-bm-folder-color: #14b8a6; --rvt-bm-folder-name-color: #14b8a6; }
.rvt-bm-folder[data-color="blue"]   { --rvt-bm-folder-color: #3b82f6; --rvt-bm-folder-name-color: #3b82f6; }
.rvt-bm-folder[data-color="purple"] { --rvt-bm-folder-color: #a855f7; --rvt-bm-folder-name-color: #a855f7; }
.rvt-bm-folder[data-color="pink"]   { --rvt-bm-folder-color: #ec4899; --rvt-bm-folder-name-color: #ec4899; }
/* The default folder ignores any stored color value for the name too — it
 * always stays at the muted base color (defense in depth, matches the icon
 * lock above). */
.rvt-bm-folder[data-is-default="1"] .rvt-bm-folder-name { color: var(--text-1); }
.rvt-bm-folder-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Tint the folder name to match the folder color so closed folders are
   * easy to scan at a glance. Falls back to --text-1 for default /
   * colorless folders so they stay readable (the icon stays gray via its
   * own var). The hover/active stronger states still come from the
   * summary's own color rules above. */
  color: var(--rvt-bm-folder-name-color, var(--text-1));
  font-weight: 600;
}
.rvt-bm-folder-rename-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-0);
  border: 1px solid var(--accent);
  color: var(--text-0);
  padding: 2px 6px;
  font-size: 13px;
  border-radius: 3px;
  outline: none;
}
.rvt-bm-folder-count {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}

.rvt-bm-folder-body {
  padding: 2px 0 6px 26px;
  min-height: 6px;
  border-radius: 4px;
}
/* Drop-target highlight applies to the WHOLE folder (summary + body) so a
 * collapsed folder still gives visual feedback when hovered while dragging. */
.rvt-bm-folder.is-drop-target {
  background: var(--accent-glow);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.rvt-bm-folder-empty {
  font-size: 11px;
  color: var(--text-3);
  font-style: italic;
  padding: 6px 12px;
  line-height: 1.4;
}

/* ─── Bookmark rows ───────────────────────────────────────────────────── */
.rvt-bm-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 10px;
  font-size: 12.5px;
  color: var(--text-1);
  text-decoration: none;
  cursor: grab;
  transition: background 100ms ease, color 100ms ease;
}
.rvt-bm-item:hover {
  background: var(--bg-2);
  color: var(--text-0);
}
.rvt-bm-item.is-dragging {
  opacity: 0.5;
}
/* Type-letter chip ([C]/[M]/[P]/...). Reuses the global .type-icon styling
 * from modern-sidebar.css (same colors, same fonts) so the chips here stay
 * in lockstep with the navigation tree. Tighten the size a touch so the
 * row height matches the rest of the pane. */
.rvt-bm-item-type {
  width: 14px;
  height: 14px;
  font-size: 9px;
}
/* .is-blank = no known page_type (Extras / Members listings). Leaves the
 * fixed-width slot in place so titles align across rows. */
.rvt-bm-item-type.is-blank {
  background: transparent;
  visibility: hidden;
}
/* Code-snippet chip: the </> marker needs more room than a single letter,
 * so it widens and drops to a tighter glyph. Accent fill marks it as code. */
.rvt-bm-item-type.snip {
  width: auto;
  min-width: 14px;
  padding: 0 3px;
  background: var(--accent);
  color: var(--bg-0);
  font-size: 8px;
  letter-spacing: -0.5px;
}
.rvt-bm-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rvt-bm-item-year {
  font-size: 10px;
  color: var(--text-3);
  background: var(--bg-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.rvt-bm-item-remove {
  background: transparent;
  border: none;
  color: var(--text-3);
  width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 14px;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 100ms ease, color 100ms ease, background 100ms ease;
  flex-shrink: 0;
}
.rvt-bm-item:hover .rvt-bm-item-remove { opacity: 0.7; }
.rvt-bm-item-remove:hover {
  color: #d9534f;
  background: var(--bg-1);
  opacity: 1;
}

/* ─── Pane layout: scrollable folders + pinned footer ────────────────── */
/* Scoped to .active so the sidebar's default `.sidebar-pane { display: none }`
 * still wins when the Bookmarks tab is NOT the active tab — otherwise an
 * id-level `display: flex` would force the pane visible alongside the
 * Navigation tree, leaking the folder list into the docs view. */
#bookmarks-content.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.rvt-bm-pane-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.rvt-bm-footer {
  flex-shrink: 0;
  padding: 6px 12px 8px;
  border-top: 1px solid var(--bg-2);
  background: var(--bg-0);
  font-size: 10.5px;
  color: var(--text-3);
  text-align: center;
  letter-spacing: 0.01em;
  user-select: none;
}

/* ─── Loading + empty states ──────────────────────────────────────────── */
.rvt-bm-loading {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
}
.rvt-bm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 16px;
  color: var(--text-2);
}
.rvt-bm-empty p { margin: 6px 0 0; font-size: 13px; }
.rvt-bm-empty .rvt-bm-hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }

/* ─── Anon CTA (sidebar pane) ────────────────────────────────────────── */
.rvt-bm-anon {
  margin: 16px;
  padding: 22px 16px 16px;
  background:
    radial-gradient(120% 70% at 50% 0%, var(--accent-glow) 0%, transparent 55%),
    var(--bg-1);
  border: 1px solid var(--bg-3);
  border-radius: 12px;
  text-align: center;
}
.rvt-bm-anon-icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  color: var(--accent);
}
.rvt-bm-anon-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-0);
}
.rvt-bm-anon-body {
  margin: 0 0 14px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
}
.rvt-bm-anon-actions {
  display: flex;
  gap: 6px;
}
.rvt-bm-anon-actions .rvt-bm-anon-cta {
  flex: 1;
  text-align: center;
}
.rvt-bm-anon-cta {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid var(--bg-3);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-1);
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.rvt-bm-anon-cta:hover {
  background: var(--bg-2);
  color: var(--text-0);
  border-color: var(--accent);
}
.rvt-bm-anon-cta--primary {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}
.rvt-bm-anon-cta--primary:hover {
  filter: brightness(1.1);
  background: var(--accent);
  color: #1a1a1a;
}

/* ─── Star-button anon popover ───────────────────────────────────────── */
.rvt-bm-popover {
  position: absolute;
  z-index: 9999;
  width: 280px;
  background: var(--bg-1);
  border: 1px solid var(--bg-2);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  padding: 14px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}
.rvt-bm-popover.is-shown {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.rvt-bm-popover-arrow {
  position: absolute;
  top: -6px;
  right: 14px;
  width: 12px;
  height: 12px;
  background: var(--bg-1);
  border-left: 1px solid var(--bg-2);
  border-top: 1px solid var(--bg-2);
  transform: rotate(45deg);
}
.rvt-bm-popover-body strong {
  display: block;
  font-size: 13px;
  color: var(--text-0);
  margin-bottom: 4px;
}
.rvt-bm-popover-body p {
  font-size: 12px;
  color: var(--text-2);
  margin: 0 0 10px;
  line-height: 1.45;
}
.rvt-bm-popover-actions {
  display: flex;
  gap: 6px;
}
.rvt-bm-popover-actions .rvt-bm-anon-cta { flex: 1; text-align: center; padding: 6px 10px; }

/* ─── Headline "Saved" pill ──────────────────────────────────────────── */
/* Sits to the left of the bookmark star button (top-right of the card).
   Anchored to the same .headline-card containing block. The [hidden]
   attribute hides it when the page isn't bookmarked. */
.rvt-bm-saved-pill {
  position: absolute;
  top: 20px;
  right: 56px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  padding: 2px 9px;
  border-radius: 999px;
  cursor: default;
  z-index: 2;
}
.rvt-bm-saved-pill[hidden] { display: none; }
.rvt-bm-saved-pill svg { flex-shrink: 0; }

/* ─── Folder context menu + color picker ─────────────────────────────── */
.rvt-bm-ctx-menu {
  position: absolute;
  z-index: 10000;
  min-width: 170px;
  background: var(--bg-1);
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  padding: 4px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 100ms ease, transform 100ms ease;
  pointer-events: none;
  font-size: 12.5px;
  user-select: none;
}
.rvt-bm-ctx-menu.is-shown {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.rvt-bm-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  background: transparent;
  border: none;
  color: var(--text-1);
  text-align: left;
  border-radius: 5px;
  cursor: pointer;
  transition: background 80ms ease, color 80ms ease;
}
.rvt-bm-ctx-item:hover:not(.is-disabled) {
  background: var(--bg-2);
  color: var(--text-0);
}
.rvt-bm-ctx-item.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.rvt-bm-ctx-item--danger:hover:not(.is-disabled) { color: #ef4444; }
.rvt-bm-ctx-item svg { flex-shrink: 0; opacity: 0.8; }
.rvt-bm-ctx-arrow { margin-left: auto; font-size: 11px; color: var(--text-3); }

/* Submenu (color picker). Sits to the right of the parent item on hover. */
.rvt-bm-ctx-submenu-wrap { position: relative; }
.rvt-bm-ctx-submenu {
  /* Sits flush against the parent item — no gap — so the cursor can
   * cross from the parent into the submenu without leaving the hover
   * tree (which would auto-close the submenu). The visual breathing
   * room comes from box-shadow + border, not margin. */
  position: absolute;
  left: 100%;
  top: -4px;
  display: none;
  flex-wrap: wrap;
  width: 144px;
  padding: 6px;
  gap: 4px;
  background: var(--bg-1);
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}
.rvt-bm-ctx-submenu-wrap:hover > .rvt-bm-ctx-submenu,
.rvt-bm-ctx-submenu-wrap:focus-within > .rvt-bm-ctx-submenu {
  display: flex;
}
.rvt-bm-ctx-swatch {
  background: transparent;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  transition: border-color 80ms ease, transform 80ms ease;
}
.rvt-bm-ctx-swatch:hover { transform: scale(1.08); }
.rvt-bm-ctx-swatch.is-selected { border-color: var(--text-0); }
.rvt-bm-ctx-swatch.is-default { color: var(--text-2); }
.rvt-bm-ctx-swatch-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
}
.rvt-bm-ctx-swatch-dot[data-color="red"]    { background: #ef4444; }
.rvt-bm-ctx-swatch-dot[data-color="orange"] { background: #f97316; }
.rvt-bm-ctx-swatch-dot[data-color="amber"]  { background: #f59e0b; }
.rvt-bm-ctx-swatch-dot[data-color="green"]  { background: #10b981; }
.rvt-bm-ctx-swatch-dot[data-color="teal"]   { background: #14b8a6; }
.rvt-bm-ctx-swatch-dot[data-color="blue"]   { background: #3b82f6; }
.rvt-bm-ctx-swatch-dot[data-color="purple"] { background: #a855f7; }
.rvt-bm-ctx-swatch-dot[data-color="pink"]   { background: #ec4899; }

/* ─── Tree-row saved-marker (sidebar tree) ───────────────────────────── */
/* Applied to .tree-label spans on rows whose page_id is bookmarked. */
.tree-row.is-bookmarked .tree-bookmark-star {
  display: inline-block;
  margin-left: 4px;
  color: var(--accent);
  font-size: 10px;
  flex-shrink: 0;
  opacity: 0.9;
}
.tree-bookmark-star {
  display: none;
}
