.canvas.has-layout-rulers { padding-top: 40px; }

.layout-ruler-workspace {
  --ruler-edge: #a2adba;
  --ruler-active: #fff;
  --ruler-muted: #dbe0e6;
  --ruler-text: #344050;
  --ruler-handle: #355071;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  position: relative;
  min-width: 0;
  min-height: 0;
}

.layout-ruler-workspace > .canvas { grid-area: 1 / 2; min-width: 0; min-height: 0; }
.layout-ruler-gutter {
  grid-area: 1 / 1;
  position: relative;
  overflow: clip;
  width: 28px;
  border-inline-end: 1px solid var(--line);
  background: var(--canvas-surface, #ededed);
}

.layout-ruler-gutter[hidden] { display: none; }

.layout-rulers {
  position: absolute;
  z-index: 7;
  overflow: clip;
  pointer-events: none;
}

.layout-rulers, .layout-ruler-gutter {
  color: var(--ruler-text);
  user-select: none;
}

.layout-rulers[hidden], .layout-ruler-workspace [data-ruler-handle][hidden] { display: none; }

.layout-ruler { position: absolute; pointer-events: auto; }
.layout-ruler-horizontal { height: 34px; background: var(--canvas-surface, #ededed); cursor: crosshair; }
.layout-ruler-vertical { width: 22px; left: 50%; transform: translateX(-50%); }

.layout-ruler-track, .layout-ruler-ticks {
  position: absolute;
  pointer-events: none;
}

.layout-ruler-track {
  border: 1px solid var(--ruler-edge);
  border-radius: 2px;
  background: var(--ruler-muted);
}

.layout-ruler-horizontal .layout-ruler-track {
  inset: 6px 0 12px;
  background: linear-gradient(to right, var(--ruler-muted) var(--layout-ruler-start),
    var(--ruler-active) var(--layout-ruler-start) var(--layout-ruler-end), var(--ruler-muted) var(--layout-ruler-end));
}

.layout-ruler-vertical .layout-ruler-track {
  inset: 0 2px;
  background: linear-gradient(to bottom, var(--ruler-muted) var(--layout-ruler-start),
    var(--ruler-active) var(--layout-ruler-start) var(--layout-ruler-end), var(--ruler-muted) var(--layout-ruler-end));
}

.layout-ruler-horizontal .layout-ruler-ticks { inset: 6px 0 12px; }
.layout-ruler-vertical .layout-ruler-ticks { inset: 0 2px; }

.layout-ruler-ticks > span {
  position: absolute;
  font: 600 9px/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.layout-ruler-horizontal .layout-ruler-ticks > span {
  left: calc(var(--layout-ruler-start) + var(--layout-tick-position));
  bottom: 1px;
  width: 1px;
  height: 2px;
  background: currentColor;
}

.layout-ruler-horizontal .layout-ruler-ticks > .layout-ruler-tick-long { height: 4px; }
.layout-ruler-horizontal .layout-ruler-ticks > span > span {
  position: absolute;
  bottom: 5px;
  left: .5px;
  transform: translateX(-50%);
}

.layout-ruler-vertical .layout-ruler-ticks > span {
  top: calc(var(--layout-ruler-start) + var(--layout-tick-position));
  right: 1px;
  width: 2px;
  height: 1px;
  background: currentColor;
}

.layout-ruler-vertical .layout-ruler-ticks > .layout-ruler-tick-long { width: 4px; }
.layout-ruler-vertical .layout-ruler-ticks > span > span {
  position: absolute;
  right: 5px;
  top: .5px;
  transform: translateY(-50%);
}

.layout-ruler-handle,.layout-ruler-type {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  pointer-events: auto;
}

.layout-ruler-type {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  border: 1px solid var(--ruler-edge);
  background: var(--ruler-active);
  color: var(--ruler-handle);
  font: 700 15px/1 system-ui, sans-serif;
}

.layout-ruler-type:hover, .layout-ruler-type:focus-visible { background: #e1eaff; }
.layout-ruler-type[data-ruler-mixed] { border-bottom: 2px dashed #8a5b13; color: #8a5b13; }
.layout-ruler-handle {
  width: 14px;
  height: 11px;
  background: transparent;
  color: var(--ruler-handle);
  touch-action: none;
}

.layout-ruler-horizontal .layout-ruler-handle {
  left: var(--layout-handle-position);
  transform: translateX(-50%);
  cursor: ew-resize;
}

.layout-ruler-vertical .layout-ruler-handle {
  top: var(--layout-handle-position);
  transform: translateY(-50%);
  width: 22px;
  height: 12px;
  cursor: ns-resize;
}

.layout-ruler-handle::before {
  content: "";
  position: absolute;
  inset: 1px 2px;
  background: currentColor;
}

.layout-ruler-handle:hover, .layout-ruler-handle:focus-visible { color: var(--accent); background: #2457c527; z-index: 4; }
.layout-ruler-handle[data-ruler-mixed] { color: #8a5b13; }
.layout-ruler-handle[data-ruler-handle="first"] { top: 0; z-index: 1; }
.layout-ruler-handle[data-ruler-handle="first"]::before { clip-path: polygon(0 0,100% 0,50% 100%); }
.layout-ruler-handle[data-ruler-handle="left"], .layout-ruler-handle[data-ruler-handle="right"] { top: 15px; z-index: 1; }
.layout-ruler-handle:is([data-ruler-handle="left"], [data-ruler-handle="right"])::before { clip-path: polygon(0 100%,100% 100%,50% 0); }
.layout-ruler-handle[data-ruler-handle="left-group"] { top: 25px; height: 9px; z-index: 1; }
.layout-ruler-handle[data-ruler-handle="left-group"]::before { inset: 1px 2px 2px; border-radius: 1px; }

.layout-ruler-handle:is([data-ruler-handle="margin-left"],[data-ruler-handle="margin-right"]) {
  top: 8px;
  height: 8px;
  width: 11px;
  color: #556373;
}

.layout-ruler-handle:is([data-ruler-handle="margin-left"],[data-ruler-handle="margin-right"])::before { inset: 0 4px; }
.layout-ruler-vertical .layout-ruler-handle::before { inset: 5px 1px; }

.layout-ruler-stop {
  top: 22px;
  height: 12px;
  text-align: center;
  font: 750 11px/1 system-ui, sans-serif;
}
.layout-ruler-stop::before { content: none; }
.layout-ruler-guide { position: absolute; z-index: 5; width: 1px; border-left: 1px dashed #2457c5; }
.layout-ruler-guide.is-horizontal { height: 1px; border: 0; border-top: 1px dashed #2457c5; }
.layout-ruler-measure { position: absolute; z-index: 6; border-radius: 4px; background: #243246; color: #fff; padding: .25rem .45rem; font: 600 .72rem/1.25 system-ui,sans-serif; }

.layout-ruler-dialog { width: min(550px, calc(100% - 32px)); }
.layout-ruler-dialog fieldset { min-width: 0; margin: .5rem 0; padding: .35rem .65rem .15rem; border: 1px solid var(--line); border-radius: 6px; }
.layout-ruler-dialog legend { padding: 0 .3rem; font-weight: 600; font-size: .82rem; }
.layout-ruler-context { margin: .2rem 0 .75rem; font-size: .84rem; color: var(--muted); }
.layout-ruler-tab-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .65rem; }
#tabStopsDialog select[name="stops"] { width: 100%; padding: .3rem; min-height: 84px; margin-top: .3rem; }
#tabStopsDialog select[name="stops"] option { padding: .17rem .4rem; }

:is(#editor, .header-footer-piece) [data-brasa-tab] {
  position: relative;
  display: inline-block;
  width: 2ch;
  white-space: pre;
  tab-size: 0;
}

:is(#editor, .header-footer-piece) [data-brasa-tab]::after {
  content: "";
  position: absolute;
  inset: 0 1px .16em;
  pointer-events: none;
  background: var(--brasa-tab-leader);
  print-color-adjust: exact;
}

:is(#editor, .header-footer-piece) [data-brasa-tabs]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: var(--brasa-tab-bars);
  print-color-adjust: exact;
}

@media screen {
  body:has([data-paragraph="marks"][aria-pressed="true"]) :is(#editor, .brasa-band-editing) [data-brasa-tab]::before {
    content: "→";
    position: absolute;
    inset: 0;
    color: #5276a5;
    text-align: center;
    pointer-events: none;
  }
}

@media (pointer: coarse) {
  .layout-ruler-type { width: 24px; }
  .layout-ruler-handle { width: 18px; }
}

@media print {
  .layout-ruler-workspace { display: block; }
  .layout-rulers, .layout-ruler-gutter { display: none !important; }
  .canvas.has-layout-rulers { padding-top: 0; }
}
