/* Noten's own styles, on top of Bootstrap 5 (static/vendor/bootstrap). Bootstrap does the
   general look (navbar, cards, buttons, forms) and the light/dark themes
   (data-bs-theme on <html>, see js/theme.js); this file only styles the app's own
   components, with Bootstrap's color variables so they follow the theme. The Noten app
   (client/) loads the same two files. */

:root {
  --noten-accent: #4f8cff;
  --noten-note: #e00000;
  --noten-shared-note: #1f5fd6;
  --noten-mark: #e08a00;
}

[data-bs-theme="dark"] {
  --noten-shared-note: #6f9dff;
}

body {
  min-height: 100vh;
}

main {
  padding-bottom: 3rem;
}

.navbar-brand .bi {
  color: var(--noten-accent);
}

.muted {
  color: var(--bs-secondary-color);
}

/* --- Overview tiles (home page, library) --- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  flex-wrap: wrap;
  margin: 2rem 0 0.75rem;
}

.section-head h2 {
  font-size: 1.25rem;
  margin: 0;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 1rem;
}

.tile {
  height: 100%;
  overflow: hidden;
  transition: border-color 0.15s;
}

.tile:hover {
  border-color: var(--noten-accent);
}

/* The top third of the piece's first page, always on white like paper. */
.tile-preview {
  display: block;
  aspect-ratio: 2 / 1;
  background: #fff;
  border-bottom: 1px solid var(--bs-border-color);
  overflow: hidden;
}

.tile-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.tile-preview.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-tertiary-bg);
  color: var(--bs-secondary-color);
  font-size: 2rem;
}

.tile .card-body {
  padding: 0.6rem 0.75rem 0.75rem;
}

.tile-title {
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 0.15rem;
}

.tile-title a {
  color: inherit;
  text-decoration: none;
}

.tile-sub {
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.voice-links .btn {
  --bs-btn-padding-y: 0.1rem;
  --bs-btn-padding-x: 0.45rem;
  --bs-btn-font-size: 0.8rem;
}

.setlist-tile .tile-preview {
  aspect-ratio: 3 / 1;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.filter-bar .form-control {
  max-width: 22rem;
}

/* --- Upload --- */

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--bs-border-color);
  border-radius: var(--bs-border-radius-lg);
  background: var(--bs-tertiary-bg);
  text-align: center;
  max-width: 520px;
  transition: border-color 0.15s, background 0.15s;
}

.drop-zone.drag-over {
  border-color: var(--noten-accent);
  background: color-mix(in srgb, var(--noten-accent) 12%, var(--bs-tertiary-bg));
}

.drop-zone-hint {
  margin: 0;
  color: var(--bs-secondary-color);
}

.selected-files {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 360px;
  text-align: left;
}

.selected-files li {
  padding: 0.2rem 0;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

#zoom-label {
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
  min-width: 3.5rem;
  text-align: center;
}

/* --- Sorting pages (upload_sort.js): unsorted pages left, pieces right --- */

#sort {
  --sort-thumb: 100px;
}

.sort-layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 1.25rem;
  align-items: start;
}

/* On a wide enough screen the page itself doesn't scroll: it fills the window, and each
   side (and the chat) scrolls on its own, so both stay in view while dragging between them
   and scrolling one never moves the others. */
.sort-panel {
  padding: 0 0.25rem 0.5rem;
}

@media (min-width: 801px) and (min-height: 480px) {
  body.sort-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.sort-page > main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: 0.75rem;
  }

  body.sort-page #sort {
    flex: 1;
    min-height: 0;
  }

  body.sort-page .sort-workspace,
  body.sort-page .sort-layout {
    height: 100%;
  }

  body.sort-page .sort-layout {
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }

  body.sort-page .sort-panel {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

.sort-panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0;
  margin-bottom: 0.5rem;
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
}

@media (max-width: 800px) {
  .sort-layout {
    grid-template-columns: minmax(0, 1fr);
  }

}

.sort-unsorted.drop-over {
  outline: 2px dashed var(--noten-accent);
  outline-offset: -2px;
}

.sort-group {
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  margin-bottom: 0.5rem;
}

.sort-group-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  min-width: 0;
}

.sort-group-toggle {
  min-width: 0;
}

.sort-group-toggle:disabled {
  opacity: 0.6;
}

.sort-grid,
.sort-zone-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--sort-thumb), 1fr));
  gap: 0.4rem;
}

.sort-grid {
  padding: 0 0.5rem 0.5rem;
}

.sort-thumb {
  position: relative;
  margin: 0;
  border: 2px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  padding: 0.15rem;
  background: #fff;
  color: #555;
  font-size: 0.72rem;
  min-width: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.sort-thumb:focus-visible {
  outline: 2px solid var(--noten-accent);
  outline-offset: 1px;
}

.sort-thumb.selected {
  border-color: var(--noten-accent);
  box-shadow: 0 0 0 2px var(--noten-accent) inset;
  background: color-mix(in srgb, var(--noten-accent) 12%, #fff);
}

.sort-thumb.dragging {
  opacity: 0.35;
}

/* Where the dragged pages would go: in front of this one. */
.sort-thumb.insert-before::before {
  content: "";
  position: absolute;
  left: -0.3rem;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--noten-accent);
}

.sort-thumb-img {
  position: relative;
}

.sort-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.414;
  object-fit: contain;
  background: #f4f4f4;
}

.sort-thumb img[src] {
  background: none;
}

/* ⤢ ↺ ↻ over the page: on hover, always on touch screens. */
.sort-thumb-tools {
  position: absolute;
  top: 0.15rem;
  right: 0.15rem;
  display: flex;
  gap: 0.1rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.sort-thumb-tools .btn {
  font-size: 0.7rem;
  line-height: 1.2;
}

.sort-thumb:hover .sort-thumb-tools,
.sort-thumb-tools:focus-within {
  opacity: 1;
}

@media (hover: none) {
  .sort-thumb-tools {
    opacity: 1;
  }
}

.sort-turned {
  position: absolute;
  left: 0.15rem;
  bottom: 0.15rem;
  font-size: 0.6rem;
}

.sort-thumb figcaption {
  display: flex;
  gap: 0.3rem;
  padding-top: 0.1rem;
  min-width: 0;
}

.sort-new-piece {
  flex: 1 1 14rem;
  max-width: 22rem;
}

.chip-field-sm {
  padding: 0.1rem 0.2rem;
}

.chip-field-sm input {
  font-size: 0.875rem;
  padding: 0.15rem 0.25rem;
}

.chip-field-sm .chips:not(:empty) {
  margin-bottom: 0.1rem;
}

.chip-field-sm .chip {
  font-size: 0.8rem;
  padding: 0.05rem 0.45rem;
}

.sort-piece.drop-over,
.sort-zone.drop-over,
.sort-new-target.drop-over,
.sort-dropped.drop-over {
  border-color: var(--noten-accent);
  box-shadow: 0 0 0 2px var(--noten-accent);
}

.sort-title {
  flex: 1 1 12rem;
  min-width: 10rem;
}

.sort-piece-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
}

.sort-tag {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 12rem;
  min-width: 0;
}

.sort-tag .chip-field {
  flex: 1;
  min-width: 0;
}

.sort-zones {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sort-zone {
  border: 1px dashed var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  padding: 0.35rem 0.45rem 0.45rem;
}

.sort-zone-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
  min-width: 0;
}

.sort-zone-voice {
  flex: 0 1 14rem;
}

.sort-zone-new {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.45rem;
}

.sort-zone-empty {
  grid-column: 1 / -1;
  color: var(--bs-secondary-color);
  font-size: 0.8rem;
  padding: 0.4rem 0;
  text-align: center;
}

.sort-zone-new .sort-zone-empty {
  padding: 0;
}

.sort-new-target {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 2px dashed var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  color: var(--bs-secondary-color);
  text-align: center;
  font-size: 0.9rem;
}

.sort-dropped .sort-zone-pages {
  min-height: 2.5rem;
}

/* While dragging: "Not kept" at the bottom of the window. */
.sort-trash-target {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 1500;
  transform: translateX(-50%);
  padding: 0.6rem 1.5rem;
  border: 2px dashed var(--bs-danger);
  border-radius: 999px;
  background: var(--bs-body-bg);
  color: var(--bs-danger-text-emphasis);
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.25);
}

body.sort-dragging .sort-trash-target {
  display: block;
}

.sort-trash-target.drop-over {
  background: var(--bs-danger-bg-subtle);
}

/* The pages being dragged, under the pointer. */
.sort-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2000;
  pointer-events: none;
  width: 60px;
}

.sort-ghost img {
  display: block;
  width: 100%;
  border: 2px solid var(--noten-accent);
  border-radius: var(--bs-border-radius);
  background: #fff;
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.3);
}

.sort-ghost .badge {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
}

body.sort-dragging,
body.sort-dragging * {
  cursor: grabbing !important;
  user-select: none;
}

/* The chat: a column on the right that slides in, the two lists making room for it. Its
   inside keeps its width while the column grows, so nothing reflows during the slide. */
.sort-workspace {
  --sort-chat-width: 380px;
  display: flex;
  align-items: stretch;
}

.sort-workspace > .sort-layout {
  flex: 1;
  min-width: 0;
}

.sort-chat {
  flex: 0 0 auto;
  width: 0;
  overflow: hidden;
  transition: width 0.35s ease, margin-left 0.35s ease;
}

.sort-chat-inner {
  width: var(--sort-chat-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s ease;
}

#sort.chat-open .sort-chat {
  width: var(--sort-chat-width);
  margin-left: 1.25rem;
}

#sort.chat-open .sort-chat-inner {
  transform: none;
}

@media (max-width: 1100px) {
  .sort-workspace {
    --sort-chat-width: 320px;
  }
}

/* Small screens: no room beside the lists, so it comes over them. */
@media (max-width: 800px) {
  .sort-chat,
  #sort.chat-open .sort-chat {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1040;
    width: min(100vw, 420px);
    height: 100vh;
    margin: 0;
    overflow: visible;
    pointer-events: none;
  }

  .sort-chat-inner {
    width: 100%;
    border-radius: 0;
    box-shadow: -0.5rem 0 1.5rem rgba(0, 0, 0, 0.3);
  }

  #sort.chat-open .sort-chat-inner {
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sort-chat,
  .sort-chat-inner {
    transition: none;
  }
}

.sort-chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* The AI at work: music notes going up and down in a wave. */
.sort-thinking {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sort-notes {
  display: inline-flex;
  gap: 0.15rem;
  height: 1.6rem;
  align-items: flex-end;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--noten-accent);
}

.sort-notes span {
  display: inline-block;
  animation: sort-note-wave 1.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.15s);
}

@keyframes sort-note-wave {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  50% {
    transform: translateY(-0.55rem);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sort-notes span {
    animation: sort-note-fade 1.6s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.2s);
  }

  @keyframes sort-note-fade {
    0%,
    100% {
      opacity: 0.4;
    }
    50% {
      opacity: 1;
    }
  }
}

.sort-msg {
  max-width: 90%;
  padding: 0.4rem 0.7rem;
  border-radius: var(--bs-border-radius-lg);
  white-space: pre-wrap;
}

.sort-msg-user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--noten-accent) 22%, var(--bs-body-bg));
}

.sort-msg-assistant {
  align-self: flex-start;
  background: var(--bs-secondary-bg);
}

.sort-msg-note {
  align-self: center;
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
}

/* The large view: full screen, like a gallery — the page as tall as the screen, what it is
   in a column beside it, ←/→ at the screen's edges. */
.sort-large {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #111;
  color: #eee;
}

.sort-large[open] {
  display: flex;
}

.sort-large::backdrop {
  background: #111;
}

.sort-large-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sort-large-stage img {
  display: block;
  height: 100vh;
  max-width: 100%;
  object-fit: contain;
  background: #fff;
}

.sort-large-stage img:not([src]) {
  aspect-ratio: 1 / 1.414;
  background: #2a2a2a;
}

.sort-large-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 3.5rem;
  height: 3.5rem;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}

.sort-large-arrow:hover,
.sort-large-arrow:focus-visible {
  background: rgba(0, 0, 0, 0.8);
}

.sort-large-arrow:disabled {
  opacity: 0;
  pointer-events: none;
}

.sort-large-prev {
  left: 1rem;
}

.sort-large-next {
  right: 1rem;
}

.sort-large-info {
  flex: 0 0 20rem;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: #1c1c1c;
  border-left: 1px solid #333;
  overflow-y: auto;
}

.sort-large-info .text-body-secondary {
  color: #aaa !important;
}

.sort-large-facts dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #999;
}

.sort-large-facts dd {
  margin-bottom: 0.9rem;
  overflow-wrap: anywhere;
}

/* Portrait screens: the page on top, what it is in a band below. */
@media (max-aspect-ratio: 1/1) {
  .sort-large[open] {
    flex-direction: column;
  }

  .sort-large-stage img {
    height: auto;
    max-height: calc(100vh - 11rem);
    width: auto;
  }

  .sort-large-info {
    flex: 0 0 auto;
    max-height: 11rem;
    border-left: 0;
    border-top: 1px solid #333;
    padding: 0.75rem 1rem;
  }

  .sort-large-info h2 {
    margin: 0.25rem 0 0.5rem !important;
    font-size: 1.1rem;
  }

  .sort-large-facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 0.75rem;
    margin: 0;
  }

  .sort-large-facts dd {
    margin-bottom: 0.2rem;
  }

  .sort-large-info > p:last-child {
    display: none;
  }
}

.chip .badge {
  font-size: 0.65rem;
}

/* --- Autocomplete / chips (chips.js) --- */

.chip-field {
  position: relative;
  border: var(--bs-border-width) solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  padding: 0.3rem;
  background: var(--bs-body-bg);
}

.chip-field:focus-within {
  border-color: var(--noten-accent);
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--noten-accent) 25%, transparent);
}

.chip-field input {
  border: none;
  outline: none;
  width: 100%;
  padding: 0.25rem;
  font-size: 1rem;
  background: transparent;
  color: var(--bs-body-color);
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0;
  margin: 0;
}

.chips:not(:empty) {
  margin-bottom: 0.25rem;
}

.chip {
  background: var(--bs-secondary-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.9rem;
}

.chip button {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  color: inherit;
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 1000;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  box-shadow: var(--bs-box-shadow);
  list-style: none;
  margin: 2px 0 0;
  padding: 0.2rem 0;
  max-height: 240px;
  overflow-y: auto;
}

.suggestions li {
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}

.suggestions li.active,
.suggestions li:hover {
  background: var(--bs-tertiary-bg);
}

/* --- Viewer --- */

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.viewer-page-count-controls,
.viewer-zoom-controls,
.viewer-annotate-controls,
.viewer-page-controls:not([hidden]) {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.page-count-btn.active,
.annotate-tool-btn.active {
  color: #fff;
}

.page-count-btn.active {
  background: var(--noten-accent);
  border-color: var(--noten-accent);
}

.annotate-tool-btn.active {
  background: var(--noten-note);
  border-color: var(--noten-note);
}

#page-label {
  min-width: 6rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#annotate-status {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}

#annotate-status.error {
  color: var(--bs-danger-text-emphasis);
}

/* Pages are centered with "safe" alignment throughout: centered while they fit, but
   start-aligned once zoomed past the frame — plain "center" would push the overflow past
   the left/top edge, where scrolling can't reach it. (The plain value is the fallback for
   browsers without "safe".) */
#viewer-canvas-wrap {
  display: flex;
  justify-content: center;
  justify-content: safe center;
  align-items: flex-start;
  gap: 1rem;
  overflow: auto;
  max-height: 82vh;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background: var(--bs-tertiary-bg);
  /* Horizontal swipes turn pages... */
  touch-action: pan-y;
}

/* ...unless a zoomed page is wider than the frame: then a finger pans it sideways, and
   swipes only turn the page from the edge (viewer.js updatePannable). */
#viewer-canvas-wrap.pannable-x {
  touch-action: pan-x pan-y;
}

#viewer-canvas-wrap.halves-mode {
  flex-direction: column;
  align-items: center;
  align-items: safe center;
  gap: 0;
}

/* Only shown when the top and bottom slots come from different pages — no seam needed
   when both halves belong to the same page. */
#page-canvas-2.half-divider {
  border-top: 1px solid var(--bs-border-color);
}

#page-canvas,
#page-canvas-2,
#page-canvas-3 {
  display: block;
}

#viewer:fullscreen {
  display: flex;
  flex-direction: column;
  background: #000;
  color: #fff;
  padding: 0.75rem;
}

#viewer:fullscreen .viewer-toolbar {
  flex: none;
  margin-bottom: 0.5rem;
}

#viewer:fullscreen #viewer-canvas-wrap {
  flex: 1;
  max-height: none;
  border: none;
  background: #000;
  display: flex;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  justify-content: safe center;
  gap: 1rem;
  /* Scrollable once zoomed in past the screen. */
  overflow: auto;
}

#viewer:fullscreen #viewer-canvas-wrap.halves-mode {
  flex-direction: column;
  gap: 0;
}

/* Touchscreen device (no hover, coarse pointer — i.e. phone/tablet, not mouse/trackpad)
   in fullscreen and rotated to landscape: put the toolbar in a sidebar on the left instead
   of a top bar, since a wide-short screen has little spare height for it up top. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #viewer:fullscreen {
    flex-direction: row;
  }

  #viewer:fullscreen .viewer-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    margin-bottom: 0;
    margin-right: 0.75rem;
    max-width: 140px;
    overflow-y: auto;
  }

  #viewer:fullscreen .viewer-zoom-controls,
  #viewer:fullscreen .viewer-page-count-controls {
    flex-wrap: wrap;
  }
}

/* Each page canvas sits in a slot with its notes SVG laid exactly over it (viewer.js wraps
   the canvases at startup). */
.page-slot {
  position: relative;
  flex: none;
  line-height: 0;
}

.page-slot > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

/* A drawing tool is active: the overlay takes the pointer (and touch, so a finger draws
   instead of scrolling/swiping). */
#viewer-canvas-wrap.drawing .page-slot > svg.annotatable {
  pointer-events: auto;
  touch-action: none;
  cursor: crosshair;
}

#viewer-canvas-wrap.drawing.erasing .page-slot > svg.annotatable {
  cursor: cell;
}

/* Switches for notes layers others shared (viewer.js fills them). */
.shared-notes-controls:not([hidden]) {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.6rem;
  font-size: 0.85rem;
  color: var(--noten-shared-note);
}

.shared-notes-controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.page-mark-btn.active {
  background: var(--noten-mark);
  border-color: var(--noten-mark);
  color: #fff;
}

/* Comments side panel (viewer.js); inside #viewer, so it also shows in fullscreen. */
.comments-panel:not([hidden]) {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1050;
  width: min(22rem, 90vw);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  overflow-y: auto;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border-left: 1px solid var(--bs-border-color);
  box-shadow: var(--bs-box-shadow-lg);
}

.comments-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.comments-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.comment {
  border-bottom: 1px solid var(--bs-border-color);
  padding-bottom: 0.5rem;
}

.comment-meta {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}

.comment-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comment-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.comment textarea {
  width: 100%;
}

.comments-hint {
  font-size: 0.8rem;
}

/* Shown when a notes save hits notes changed elsewhere (viewer.js askWhichNotes). */
.notes-conflict {
  max-width: min(36rem, calc(100vw - 2rem));
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius-lg);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}

.notes-conflict::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.notes-conflict-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
}

.notes-conflict-choices figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.notes-conflict-preview {
  position: relative;
  max-width: 100%;
  border: 1px solid var(--bs-border-color);
  background: #fff;
}

.notes-conflict-preview canvas,
.notes-conflict-preview svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* --- Setlists --- */

.setlist-add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.25rem;
}

.setlist-add #piece-field {
  width: min(100%, 340px);
}

.setlist-add #voice-field {
  width: min(100%, 280px);
}

.setlist-add #voice-field .suggestions {
  position: static;
  display: block;
}

.setlist-items {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: setlist-counter;
}

.setlist-items li {
  counter-increment: setlist-counter;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.setlist-items li:last-child {
  border-bottom: none;
}

.setlist-items li::before {
  content: counter(setlist-counter);
  font-weight: 600;
  color: var(--bs-secondary-color);
  min-width: 1.5rem;
}

.setlist-item-title {
  flex: 1;
}

.placeholder-item .setlist-item-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-style: italic;
}

.placeholder-name {
  font: inherit;
  flex: 0 1 20rem;
  min-width: 0;
  padding: 0.2rem 0.4rem;
  border: 1px dashed var(--bs-border-color);
  border-radius: var(--bs-border-radius-sm);
  background: transparent;
  color: inherit;
}

.placeholder-note {
  font-size: 0.85em;
  color: var(--bs-secondary-color);
  white-space: nowrap;
}

.setlist-item-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* --- Offline copies ("Save offline" toggle, /offline) --- */

.offline-controls:not([hidden]) {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.offline-items,
.download-list {
  list-style: none;
  padding: 0;
}

.offline-items li,
.download-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--bs-border-color);
}

.offline-item-name {
  font-weight: 600;
  flex: 1 1 12rem;
}

.download-hint {
  flex-basis: 100%;
}

/* --- Associations --- */

.how-it-works .bi {
  font-size: 1.5rem;
  color: var(--noten-accent);
}

.invite-link {
  font-family: var(--bs-font-monospace);
}

/* --- The Noten app's own pages (client/www), which share this file --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--bs-border-color);
  margin-bottom: 1rem;
  background: var(--bs-tertiary-bg);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.2rem;
  text-decoration: none;
  color: inherit;
}

.app-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 24rem;
}

/* --- Camera scan (upload/new.html, upload_scan.js) --- */
.scan-thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-tertiary-bg);
  border-radius: var(--bs-card-inner-border-radius) var(--bs-card-inner-border-radius) 0 0;
  overflow: hidden;
}

.scan-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
}

.scan-spinner {
  position: absolute;
}

.scan-number {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
}

/* --- Page order (page_order.js, on the Edit page) --- */

.page-order-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.page-order-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.page-order-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.25rem;
  border-bottom: 1px solid var(--bs-border-color-translucent);
  background: var(--bs-body-bg);
}

.page-order-row.pointed {
  background: color-mix(in srgb, var(--noten-accent) 15%, var(--bs-body-bg));
}

.page-order-row.dragging {
  position: relative;
  z-index: 1;
  box-shadow: 0 0.25rem 1rem rgb(0 0 0 / 0.35);
}

.page-order-handle {
  padding: 0.5rem 0.15rem;
  font-size: 1.25rem;
  color: var(--bs-secondary-color);
  cursor: grab;
  touch-action: none;
}

.page-order-thumb {
  flex: none;
  width: 3.5rem;
  aspect-ratio: 1 / 1.414;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.2rem;
}

.page-order-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.page-order-label {
  flex: 1;
  min-width: 0;
}

.page-order-moves {
  display: flex;
  gap: 0.3rem;
}

.page-order-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0 0.1rem;
  background: var(--bs-body-bg);
}

/* --- Profile pictures (avatars.py) --- */

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--bs-secondary-bg);
}

.avatar-sm {
  width: 1.5em;
  height: 1.5em;
  vertical-align: -0.4em;
}

.avatar-lg {
  width: 4.5rem;
  height: 4.5rem;
  flex: none;
}

i.avatar-lg {
  font-size: 4.5rem;
  line-height: 1;
}

/* --- Footer: the imprint --- */

.site-footer {
  padding: 2rem 0.75rem 1.5rem;
  font-size: 0.85rem;
  text-align: center;
}

.site-footer a {
  color: var(--bs-secondary-color);
}

/* The sorting page fills the window exactly. */
body.sort-page .site-footer {
  display: none;
}

.imprint {
  max-width: 36rem;
}

/* The navbar's EN | DE switch. */
.language-switch {
  display: flex;
}

.language-switch .nav-link {
  padding-left: 0.3rem;
  padding-right: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.language-switch .nav-link:not(.active) {
  opacity: 0.6;
}
