/* =========================================================
   READER MARK WORKSPACE
   Right-handed Mark access beside AI / Notes.
   This file changes placement and access only. The existing
   bv.underline.js Mark engine and palette remain authoritative.
========================================================= */

html body #bvReaderMarkLauncher[hidden] {
  display: none !important;
}

html body #bvSideLaunchers #bvReaderMarkLauncher {
  order: 3 !important;
}

/* The Mark drawer opens inward from the right launcher rail. */
html body #bvReaderToolDock[data-active-tool="mark"]
  #bvReaderToolPanelMark:not([hidden]) {
  position: absolute !important;
  left: calc(100vw - 350px) !important;
  right: auto !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translateY(-50%) !important;

  width: min(var(--bv-dock-panel-width, 272px), calc(100vw - 92px)) !important;
  max-height: calc(100dvh - 92px) !important;

  border-radius: 8px 0 0 8px !important;
  z-index: 3 !important;
}

/* Mark is no longer a left-rail command. Keep the source rail compact. */
html body #bvReaderToolDock .bv-reader-tool-rail {
  align-content: center !important;
}

/* Single-page canvas tools only, matching existing Mark capability. */
html body.bv-scroll-reader-active #bvReaderMarkLauncher {
  display: none !important;
}

/* Avoid allowing the document to sit beneath a wide open Mark drawer. */
@media (min-width: 1101px) {
  html body.bv-reader-mark-workspace-open #viewer .viewer-stack {
    width: min(1480px, calc(100% - 360px)) !important;
    margin-left: 0 !important;
    margin-right: 340px !important;
  }
}

@media (max-width: 700px) {
  html body #bvReaderToolDock[data-active-tool="mark"]
    #bvReaderToolPanelMark:not([hidden]) {
    left: 10px !important;
    right: auto !important;
    top: auto !important;
    bottom: 52px !important;
    transform: none !important;

    width: min(360px, calc(100vw - 20px)) !important;
    max-height: min(60dvh, 520px) !important;
    border-radius: 8px !important;
  }
}

/* =========================================================
   COMPACT MARK CONTROLS
   Direct underline choices and a visual-only marker palette.
========================================================= */

html body #bvReaderToolPanelMark .bv-reader-dock-mark #viewerCanvasToolsLeft {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 7px !important;
  width: 100% !important;
  align-items: stretch !important;
}

html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnHighlight,
html body #bvReaderToolPanelMark .bv-reader-dock-mark .bv-marker-mode-row,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #underlineModeLabel,
html body #bvReaderToolPanelMark .bv-reader-dock-mark .bv-marker-colours,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #toggleMarkersBtn {
  grid-column: 1 / -1 !important;
}

html body #bvReaderToolPanelMark .bv-marker-mode-row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 7px !important;
  width: 100% !important;
}

html body #bvReaderToolPanelMark .bv-marker-mode-row .bv-btn {
  width: 100% !important;
  min-width: 0 !important;
  padding-inline: 7px !important;
  white-space: normal !important;
}

html body #bvReaderToolPanelMark #underlineModeLabel {
  min-height: 18px !important;
  margin: 0 !important;
  padding: 2px 3px !important;
  color: #6c746f !important;
  font-size: 10px !important;
  line-height: 1.25 !important;
}

html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colours {
  display: grid !important;
  grid-template-columns: repeat(3, 42px) !important;
  justify-content: center !important;
  justify-items: center !important;
  align-items: center !important;
  gap: 8px !important;
  margin: 0 !important;
  padding: 9px !important;
  border-radius: 7px !important;
}

html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colours__label {
  grid-column: 1 / -1 !important;
  margin: 0 0 1px !important;
  justify-self: stretch !important;
}

/* Active Marker modes use the same tactile key language as the Reader rail.
   The controls keep their task-specific width, but share PAGE's face, lip,
   border, typography contrast, hover lift, and pressed depth. */
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnHighlight.is-active,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnUnderlineBasic.is-active,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnUnderlineSmart.is-active {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.12), rgba(0,0,0,0.16)),
    #4b68df !important;
  color: #ffffff !important;
  border-color: #2d47aa !important;
  border-bottom-color: #203783 !important;
  border-bottom-width: 3px !important;
  border-radius: 4px !important;
  box-shadow: var(--btn-shadow, none) !important;
  text-shadow: none !important;
}

html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnHighlight.is-active:hover,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnUnderlineBasic.is-active:hover,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnUnderlineSmart.is-active:hover {
  filter: brightness(1.08) !important;
  transform: translateY(-1px) !important;
}

html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnHighlight.is-active:active,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnUnderlineBasic.is-active:active,
html body #bvReaderToolPanelMark .bv-reader-dock-mark #btnUnderlineSmart.is-active:active {
  transform: translateY(2px) !important;
  border-bottom-width: 1px !important;
}

html body #bvReaderToolPanelMark #underlineModeLabel.is-active {
  padding: 6px 8px !important;
  border-left: 3px solid #4167d8 !important;
  border-radius: 3px !important;
  color: #244b9a !important;
  background: rgba(81, 113, 220, 0.13) !important;
  font-weight: 700 !important;
}

html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colour {
  width: 42px !important;
  min-width: 42px !important;
  max-width: 42px !important;
  height: 42px !important;
  min-height: 42px !important;
  padding: 4px !important;
  gap: 0 !important;
  justify-content: center !important;
  border-radius: 7px !important;
  font-size: 0 !important;
  line-height: 0 !important;
}

html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colour__swatch {
  width: 100% !important;
  height: 100% !important;
  border-radius: 5px !important;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.34), transparent 42%),
    var(--marker-soft) !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    inset 0 -2px 0 color-mix(in srgb, var(--marker-accent) 62%, transparent) !important;
}

html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colour.is-active,
html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colour[aria-pressed="true"] {
  outline: 2px solid #27384f !important;
  outline-offset: 1px !important;
}

@media (max-width: 700px) {
  html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colours {
    grid-template-columns: repeat(3, 40px) !important;
  }

  html body #bvReaderToolPanelMark #viewerCanvasToolsLeft .bv-marker-colour {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
  }
}

/* =========================================================
   READER SAVE EMPHASIS
   Keep Save obvious at rest without changing save behaviour.
========================================================= */
html body #bvReaderToolDock #bvReaderToolDirectSave.bv-reader-tool-direct-save {
  background: #f7b8b8 !important;
  border-color: #e88f8f !important;
  border-bottom-color: #d87878 !important;
  color: #7a2525 !important;
}

html body #bvReaderToolDock #bvReaderToolDirectSave.bv-reader-tool-direct-save:hover,
html body #bvReaderToolDock #bvReaderToolDirectSave.bv-reader-tool-direct-save:focus-visible {
  background: #f29d9d !important;
  border-color: #df7f7f !important;
  border-bottom-color: #cf6f6f !important;
  color: #7a2525 !important;
}
