/* Admin + auth UI. Additive to soundboard.css — reuses its custom properties
   (--bg-color, --primary-color, --alt-color, --bold-color, --border-color,
   --corner-rounding, --standard-padding) and does not override base rules. */

/* ---- header: auth chip + add button ---- */

.auth-controls {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--standard-padding) * 0.5);
}

.auth-login-btn,
.admin-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  height: var(--control-height);
  padding: 0 calc(var(--standard-padding) * 0.75);
  border: 0;
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  line-height: 1;
}

.admin-add-btn {
  background-color: var(--primary-color);
}

.auth-login-btn:hover,
.admin-add-btn:hover {
  filter: brightness(1.15);
}

.auth-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  height: var(--control-height);
  padding: 0 calc(var(--standard-padding) * 0.5);
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  cursor: pointer;
  user-select: none;
  max-width: 12rem;
}

.auth-chip:hover {
  filter: brightness(1.15);
}

.auth-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  overflow: hidden;
  background-color: var(--primary-color);
  flex-shrink: 0;
  font-size: 0.8rem;
}

.auth-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.auth-username {
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.auth-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 120;
  min-width: 140px;
  background-color: var(--alt-color);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  padding: 4px 0;
}

.auth-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 16px;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
}

.auth-menu-item:hover {
  background-color: var(--primary-color);
}

/* ---- long-press (touch) ---- */

/* Suppress the iOS callout / text selection during a long-press so our own
   context menu can open instead. */
soundboard-button,
.group-button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---- context menu extras ---- */

.context-menu-separator {
  height: 1px;
  margin: 4px 0;
  background-color: var(--border-color);
}

.context-menu-item-danger {
  color: #ff6b6b;
}

.context-menu-item-danger:hover {
  background-color: var(--bold-color);
  color: white;
}

/* ---- admin modals (share .modal / .modal-overlay from soundboard.css) ---- */

.admin-modal-overlay {
  z-index: 300;
  padding: var(--standard-padding);
}

.admin-modal {
  background-color: var(--bg-color);
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: var(--standard-padding);
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-label {
  font-size: 0.85rem;
  opacity: 0.8;
}

.admin-input {
  height: var(--control-height);
  padding: 0 calc(var(--standard-padding) * 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  font-size: inherit;
  font-family: inherit;
  width: 100%;
}

.admin-input:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: -1px;
}

.admin-input:disabled {
  opacity: 0.6;
}

.admin-hint {
  font-size: 0.75rem;
  opacity: 0.6;
}

.admin-error {
  color: #ff8080;
  font-size: 0.85rem;
  word-break: break-word;
}

.admin-warning {
  margin: 0;
  line-height: 1.5;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: calc(var(--standard-padding) * 0.5);
  justify-content: flex-end;
  flex-wrap: wrap;
}

.admin-status {
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.8rem;
  opacity: 0.85;
}

.admin-spinner,
.trim-spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: admin-spin 0.7s linear infinite;
}

@keyframes admin-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- shared admin buttons ---- */

.trim-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: var(--control-height);
  padding: 0 calc(var(--standard-padding) * 0.75);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  line-height: 1;
}

.trim-btn:hover {
  filter: brightness(1.15);
}

.trim-btn:disabled {
  opacity: 0.55;
  cursor: default;
  filter: none;
}

.trim-btn-primary {
  background-color: var(--primary-color);
  border-color: transparent;
}

.trim-btn-danger {
  background-color: var(--bold-color);
  border-color: transparent;
}

.trim-btn-subtle {
  background: none;
  border-color: var(--border-color);
  opacity: 0.85;
}

.trim-btn-toggle.active {
  background-color: var(--primary-color);
}

/* ---- trim editor ---- */

.trim-editor.admin-modal {
  max-width: 760px;
  width: 100%;
}

.trim-source {
  margin-bottom: var(--standard-padding);
  font-size: 0.8rem;
  opacity: 0.75;
  word-break: break-word;
}

.trim-source a {
  color: inherit;
}

.trim-loading,
.trim-error {
  padding: calc(var(--standard-padding) * 2);
  text-align: center;
  opacity: 0.8;
}

.trim-error {
  color: #ff8080;
}

.trim-waveform {
  position: relative; /* anchors the hover time tooltip */
  width: 100%;
  min-height: 160px;
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  overflow: hidden;
  margin-bottom: var(--standard-padding);
}

/* Hover time tooltip (follows the mouse along the waveform). */
.trim-hover-time {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  z-index: 10;
  padding: 1px 6px;
  border-radius: var(--corner-rounding);
  background-color: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--border-color);
  color: white;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/*
 * WaveSurfer v7 renders into a shadow root and exposes ::part() hooks
 * (part="cursor" in the core; part="region-handle region-handle-left|right"
 * in the regions plugin). The plugin sets the handles' geometry as INLINE
 * styles (width: 6px; z-index: 2), so overrides need !important.
 */

/* The playhead line is display-only; never let it swallow pointer events
 * (the vendored build already sets this — kept as insurance). Dropping its
 * z-index below the regions container (z-index 3) keeps it from painting
 * over the region handles; it stays visible through the translucent fill. */
.trim-waveform ::part(cursor) {
  pointer-events: none;
  z-index: 2;
}

/* Region resize handles: keep the 12px HIT AREA (the fix for a region
 * starting at 0 — the handle extends inward, so there's something to grip
 * at the container's edge) but render only a slim [ ] bracket so short
 * sounds' waveforms aren't obscured. ::before/::after aren't allowed on
 * ::part(), so the bracket is drawn with layered background gradients:
 * a 3px vertical bar at the outer edge + 3px ticks top and bottom. */
.trim-waveform ::part(region-handle) {
  width: 12px !important;
  border: none !important;
  background-color: transparent;
  background-repeat: no-repeat;
  z-index: 4 !important;
  touch-action: none;
  --handle-ink: rgba(255, 255, 255, 0.55);
}

.trim-waveform ::part(region-handle):hover,
.trim-waveform ::part(region-handle):active {
  --handle-ink: rgba(255, 255, 255, 0.95);
}

.trim-waveform ::part(region-handle-left) {
  background-image:
    linear-gradient(var(--handle-ink), var(--handle-ink)),
    linear-gradient(var(--handle-ink), var(--handle-ink)),
    linear-gradient(var(--handle-ink), var(--handle-ink));
  background-position: left center, left top, left bottom;
  background-size: 3px 100%, 9px 3px, 9px 3px;
  border-radius: 2px 0 0 2px;
}

.trim-waveform ::part(region-handle-right) {
  background-image:
    linear-gradient(var(--handle-ink), var(--handle-ink)),
    linear-gradient(var(--handle-ink), var(--handle-ink)),
    linear-gradient(var(--handle-ink), var(--handle-ink));
  background-position: right center, right top, right bottom;
  background-size: 3px 100%, 9px 3px, 9px 3px;
  border-radius: 0 2px 2px 0;
}

.trim-transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--standard-padding) * 0.5);
  margin-bottom: var(--standard-padding);
}

/* Playhead + region-length readouts at the end of the transport row. */
.trim-readouts {
  display: inline-flex;
  align-items: center;
  gap: 0.75em;
  margin-left: auto;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.65;
  white-space: nowrap;
}

.trim-edges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: var(--standard-padding);
  margin-bottom: var(--standard-padding);
}

.trim-edge {
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  padding: calc(var(--standard-padding) * 0.75);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trim-edge-heading {
  font-size: 0.8rem;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trim-edge-input {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

.trim-number {
  width: 100%;
  height: var(--control-height);
  padding: 0 calc(var(--standard-padding) * 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  font-size: inherit;
  font-family: inherit;
}

.trim-unit {
  opacity: 0.6;
  font-size: 0.85rem;
}

.trim-nudges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.trim-nudge {
  flex: 1 1 auto;
  min-width: 3rem;
  min-height: 2.25rem;
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.trim-nudge:hover {
  filter: brightness(1.2);
}

.trim-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--standard-padding);
  align-items: center;
  margin-bottom: var(--standard-padding);
}

.trim-zoom,
.trim-volume {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.85rem;
  opacity: 0.9;
}

.trim-zoom {
  flex: 1 1 12rem;
}

.trim-zoom input[type="range"] {
  flex: 1;
  min-width: 6rem;
}

.trim-volume-select {
  height: var(--control-height);
  padding: 0 calc(var(--standard-padding) * 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  font-size: inherit;
  font-family: inherit;
}

.trim-footer {
  display: flex;
  align-items: center;
  gap: calc(var(--standard-padding) * 0.5);
  flex-wrap: wrap;
  margin-top: 4px;
}

.trim-footer-spacer {
  flex: 1 1 auto;
}

.trim-hint {
  margin-top: var(--standard-padding);
  font-size: 0.72rem;
  opacity: 0.55;
  line-height: 1.5;
}

/* ---- draft editor (add-sound, name-at-the-end) ---- */

.admin-explainer {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.8;
  line-height: 1.5;
}

.draft-banner {
  margin-bottom: var(--standard-padding);
  padding: calc(var(--standard-padding) * 0.5) calc(var(--standard-padding) * 0.75);
  border: 1px solid var(--primary-color);
  border-radius: var(--corner-rounding);
  background-color: rgba(66, 65, 179, 0.18);
  font-size: 0.85rem;
}

.draft-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: calc(var(--standard-padding) * 0.5);
}

.draft-name-field {
  width: 100%;
}

.draft-name-hint {
  min-height: 1.1em;
}

.draft-actions {
  margin-top: 0;
}

/* ---- mini video player (movable, resizable, persistent) ----
   z-index 90: above page content, BELOW context menus (100) and all modals
   (200 base / 300 admin) so the trim editor etc. layer over the player. */

.video-player {
  position: fixed;
  z-index: 90;
  display: flex;
  flex-direction: column;
  min-width: 240px;
  max-width: 95vw;
  max-height: 70vh;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--corner-rounding);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  outline: none;
}

.video-player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  padding: calc(var(--standard-padding) * 0.5) calc(var(--standard-padding) * 0.75);
  border-bottom: 1px solid var(--border-color);
  cursor: move;
  touch-action: none; /* pointer-event drag on touch must not scroll */
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

.video-player-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-player-close {
  border: 0;
  background: none;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25em;
  touch-action: auto; /* the ✕ is a tap target, not a drag handle */
}

.video-player-stage {
  position: relative;
  /* Intrinsic 16:9 before JS freezes an explicit height; flexes to fill the
     player once the wrapper has one. */
  aspect-ratio: 16 / 9;
  flex: 1 1 auto;
  min-height: 4rem;
  background-color: black;
}

.video-player-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  font-size: 0.85rem;
  opacity: 0.85;
}

.video-player:not(.video-ready):not(.video-error) .video-player-loading {
  display: flex;
}

.video-player-error {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--standard-padding);
  font-size: 0.85rem;
  color: #ff6b6b;
}

.video-player.video-error .video-player-error {
  display: flex;
}

.video-player-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
}

.video-player.video-ready .video-player-video {
  opacity: 1;
}

.video-player-footer {
  position: relative;
  height: 14px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  cursor: nwse-resize;
  touch-action: none; /* pointer-event resize on touch must not scroll */
}

/* Diagonal grip marker in the bottom-right corner. */
.video-player-footer::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--border-color);
  border-bottom: 2px solid var(--border-color);
}

.admin-modal.busy {
  pointer-events: none;
}

.admin-modal.busy .trim-btn-primary {
  cursor: progress;
}

/* ---- toasts ---- */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(6rem + var(--standard-padding));
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}

.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: var(--corner-rounding);
  background-color: var(--alt-color);
  color: white;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  max-width: 90vw;
  word-break: break-word;
  animation: toast-in 0.18s ease-out;
}

.toast-success {
  background-color: #1f7a4d;
  border-color: transparent;
}

.toast-error {
  background-color: var(--bold-color);
  border-color: transparent;
}

.toast-leaving {
  animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media screen and (min-width: 720px) {
  .toast-container {
    bottom: calc(var(--standard-padding) * 2);
  }
}
