/* Slim rail (floating mode) */
.traven-slim-rail {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--accent, #475569);
  background: var(--rail-bg, transparent);
}

.traven-rail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 0;
  border-radius: 4px;
  color: var(--text-secondary, #475569);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.traven-rail-btn:hover {
  background: var(--rail-btn-hover, rgba(0, 0, 0, 0.05));
  color: var(--text-primary, #0f172a);
}

.traven-rail-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  display: block;
}

.traven-rail-btn svg rect:not([stroke]) {
  stroke: none;
}

.cm-wysiwym-dark .traven-rail-btn {
  color: var(--text-secondary-dark, #94a3b8);
}

.cm-wysiwym-dark .traven-rail-btn:hover {
  background: var(--rail-btn-hover-dark, rgba(255, 255, 255, 0.08));
  color: var(--text-primary-dark, #f8fafc);
}

/* Stats widget */
.traven-toolbar-stats {
  margin-left: auto;
  font-size: 11px;
  color: rgba(0, 0, 0, 0.5);
  font-family: inherit;
  white-space: nowrap;
  padding: 0 8px;
  align-self: center;
}

.cm-wysiwym-dark .traven-toolbar-stats {
  color: rgba(255, 255, 255, 0.5);
}

/* Selection bubble */
.traven-bubble-menu {
  --bubble-bg: #ffffff;
  --bubble-fg: #1f2937;
  --bubble-border: rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--bubble-bg);
  color: var(--bubble-fg);
  border: 1px solid var(--bubble-border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.cm-wysiwym-dark .traven-bubble-menu {
  --bubble-bg: #1e293b;
  --bubble-fg: #e2e8f0;
  --bubble-border: rgba(255, 255, 255, 0.12);
}

/* Tablet Strategy: render selection bubble as a sticky bottom bar */
.traven-bubble-menu.is-tablet-bottom-bar {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  border-radius: 0 !important;
  border-top: 1px solid var(--bubble-border, rgba(0, 0, 0, 0.12)) !important;
  border-left: 0 !important;
  border-right: 0 !important;
  border-bottom: 0 !important;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
  z-index: 9999 !important;
  justify-content: center !important;
  padding: 8px 16px !important;
  box-sizing: border-box !important;
}

.traven-bubble-menu .toolbar-btn {
  width: 26px;
  height: 26px;
}

.traven-bubble-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: var(--bubble-border, rgba(0, 0, 0, 0.12));
  margin: 0 4px;
  align-self: center;
  flex-shrink: 0;
}

.cm-wysiwym-dark .traven-bubble-sep {
  background: var(--bubble-border, rgba(255, 255, 255, 0.12));
}


/* ── Gutter inserter: zero-width overlay ──
   The gutter column itself takes no layout space.  The "+" button
   is absolutely positioned so it floats into the .cm-content left-
   padding zone (24 px) – visible without shifting content right. */

.cm-traven-gutter {
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
}

.cm-traven-gutter .cm-gutterElement {
  width: 0;
  overflow: visible;
  position: relative;
}

/* The + button overlays into the content's left padding area */
.cm-traven-gutter .traven-gutter-plus-btn {
  position: absolute;
  /* Place it to the right of the gutter (into the content padding) */
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, color 120ms ease, background-color 120ms ease;
  color: #94a3b8;
  /* slate-400 (gray) */
  user-select: none;
  z-index: 2;
  font-size: 14px;
}

/* Always display it when the cursor is on the line (active line gutter) */
.cm-activeLineGutter .traven-gutter-plus-btn {
  opacity: 1;
  color: #94a3b8;
}

/* Hover state: turn it to a darker slate or black */
.cm-traven-gutter .traven-gutter-plus-btn:hover {
  opacity: 1;
  color: #0f172a;
  /* slate-900 (darker slate/black) */
  background: var(--gutter-btn-hover, rgba(0, 0, 0, 0.05));
}

/* Dark mode overrides */
.cm-wysiwym-dark .cm-traven-gutter .traven-gutter-plus-btn {
  color: #64748b;
  /* slate-500 (gray in dark mode) */
}

.cm-wysiwym-dark .cm-activeLineGutter .traven-gutter-plus-btn {
  color: #64748b;
}

.cm-wysiwym-dark .cm-traven-gutter .traven-gutter-plus-btn:hover {
  color: #f8fafc;
  /* slate-50 (light slate/white) */
  background: var(--gutter-btn-hover-dark, rgba(255, 255, 255, 0.08));
}

/* Gutter popover */
.traven-gutter-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  max-height: 60vh;
  overflow: visible;
  width: 192px;
  box-sizing: border-box;
}

.traven-gutter-menu .toolbar-btn {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  border-radius: 6px;
}

.traven-gutter-menu button.btn-heading,
.traven-gutter-menu button.btn-blockquote,
.traven-gutter-menu button.btn-snippet {
  width: 32px;
  padding: 0;
}

.traven-gutter-menu .toolbar-btn:hover {
  background: #f8fafc;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.cm-wysiwym-dark .traven-gutter-menu {
  background: rgba(30, 41, 59, 0.5);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.cm-wysiwym-dark .traven-gutter-menu .toolbar-btn {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.cm-wysiwym-dark .traven-gutter-menu .toolbar-btn:hover {
  background: #334155;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* Hide subscript and superscript buttons from floating menus */
.traven-bubble-menu .btn-subscript,
.traven-bubble-menu .btn-superscript,
.traven-gutter-menu .btn-subscript,
.traven-gutter-menu .btn-superscript {
  display: none !important;
}