/* ─── SHARED COMPONENTS ─────────────────────────────────────────
   Canonical, tokenized versions of UI patterns that used to be
   copy-pasted across chords.css, sheet_music.css and per-template
   <style> blocks. Loaded globally AFTER boilerplate/navbar and
   BEFORE page CSS (extra_css), so a page-level rule of equal
   specificity always wins until that page is migrated.

   Values are byte-identical to the previous dominant definition —
   this file must not change how any unmigrated page renders. */

/* ── Buttons ── */
.btn-primary-glow {
  background: var(--accent);
  color: #000;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-weight: bold;
  text-decoration: none;
  display: inline-block;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
  box-shadow: var(--glow-accent);
}

.btn-primary-glow:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary-glow {
  background: transparent;
  color: white;
  border: 2px solid var(--border-3);
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-weight: bold;
  text-decoration: none;
  display: inline-block;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-secondary-glow:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-weight: bold;
  text-decoration: none;
  display: inline-block;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: var(--glow-danger);
}

/* Size modifier for compact contexts (view-page toolbars, modals) */
.btn--sm {
  padding: 8px 18px;
}

/* Small round neutral icon button (inline row actions). From videos' .btn-icon. */
.btn-icon {
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.btn-icon:hover {
  background: var(--accent);
  color: black;
}

/* Round outlined icon button — destructive action.
   Canonical 42px (playlists); admin_users keeps a local 36px density override. */
.btn-icon-danger {
  background: transparent;
  border: 2px solid var(--danger);
  color: var(--danger);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-icon-danger:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 0 16px rgba(var(--danger-rgb), 0.5);
}

/* Round outlined icon button — caution action (e.g. password reset). */
.btn-icon-warn {
  background: transparent;
  border: 2px solid var(--warn);
  color: var(--warn);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-icon-warn:hover {
  background: rgba(var(--warn-rgb), 0.15);
  box-shadow: 0 0 16px rgba(var(--warn-rgb), 0.5);
}

/* ── Pills / chips (metadata badges) ── */
.pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.pill-accent {
  background: rgba(var(--accent-rgb), 0.15);
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  color: var(--accent);
}

.pill-neutral {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: rgba(255, 255, 255, 0.8);
}

.pill-warn {
  background: rgba(var(--warn-rgb), 0.15);
  border: 1px solid rgba(var(--warn-rgb), 0.5);
  color: var(--warn);
}

/* ── Chip (pill with an inline remove button) ──
   <span class="chip"><i class="uil ..."></i> label
     <button type="button" class="chip__remove" aria-label="Remove …">×</button></span>
   Normalized from videos' .tag-chip/.playlist-chip and upload's .tag-chip. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-pill);
  background: rgba(var(--accent-rgb), 0.15);
  border: 1px solid rgba(var(--accent-rgb), 0.5);
  color: var(--text);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.chip__remove {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 1em;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s;
}

.chip__remove:hover {
  color: var(--danger);
}

/* ── Pill toggle (label-wrapped checkbox/radio rendered as a pill) ──
   <label class="pill-toggle"><input type="checkbox" name="...">
     <span class="pill-label"><i class="uil ..."></i> Text</span></label>
   Normalized from create_user's .perm-pill and playlists' .visibility-toggle-pill:
   unchecked = neutral surface pill, checked = accent-tinted pill. */
.pill-toggle {
  display: inline-flex;
  cursor: pointer;
}

.pill-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill-toggle .pill-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-2);
  background: var(--surface-1);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  transition: all 0.2s;
}

.pill-toggle .pill-label i {
  color: rgba(var(--accent-rgb), 0.6);
}

.pill-toggle input:checked + .pill-label {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.15);
  color: var(--accent);
}

.pill-toggle input:checked + .pill-label i {
  color: var(--accent);
}

/* ── Toggle switch (label-wrapped hidden checkbox + track/thumb) ──
   <label class="toggle-switch"><input type="checkbox" ...>
     <span class="toggle-track"><span class="toggle-thumb"></span></span>
     <span>Label text</span></label>
   Moved verbatim from admin_users' flag switches. Named .toggle-switch
   (not .toggle) because navbar.css already uses bare .toggle for the
   hamburger label — a global .toggle rule here would un-hide it on desktop. */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  transition: background 0.25s;
}

.toggle-thumb {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  top: 3px;
  left: 3px;
  transition: transform 0.25s, background 0.25s;
}

.toggle-switch input:checked + .toggle-track {
  background: rgba(var(--accent-rgb), 0.38);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: var(--accent);
}

.toggle-switch input:disabled + .toggle-track {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Form controls ── */
/* Pill-shaped text input / select (filter bars, inline forms) */
.input-pill {
  background: rgba(var(--accent-rgb), 0.1);
  border: 2px solid rgba(var(--accent-rgb), 0.4);
  color: white;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-ctrl);
  outline: none;
  transition: all 0.3s;
}

.input-pill:focus {
  border-color: var(--accent);
  box-shadow: var(--glow-accent-soft);
}

.select-pill {
  background: rgba(var(--accent-rgb), 0.1);
  border: 2px solid rgba(var(--accent-rgb), 0.4);
  color: white;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-ctrl);
  outline: none;
  cursor: pointer;
  min-width: 120px;
}

.input-pill option,
.select-pill option,
.select-pill optgroup,
.input-block option {
  background: var(--select-option-bg);
  color: white;
}

/* Rectangular block input (forms, modals). 16px font prevents iOS zoom-on-focus. */
.input-block {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  width: 100%;
}

.input-block:focus {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.2);
}

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

@media (max-width: 768px) {
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar .input-pill,
  .filter-bar .select-pill {
    width: 100%;
    min-width: 0;
    flex: none;
  }
}

.filter-clear {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  font-size: var(--fs-sm);
  padding: 0.4rem 0.8rem;
  transition: color 0.2s;
}

.filter-clear:hover {
  color: var(--danger);
}

/* ── Alphabetical letter sections (list pages) ── */
.letter-section {
  font-size: var(--fs-lg);
  font-weight: bold;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(var(--accent-rgb), 0.5);
  padding: 0.7rem 0.5rem 0.3rem;
  margin-top: 0.75rem;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.2);
  letter-spacing: 2px;
}

.letter-section:first-child {
  margin-top: 0;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  padding: 3rem 1rem;
}

.empty-state i {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
}

/* ── Page shell ── */
.page-box {
  padding: var(--space-6) 2.5rem;
  box-sizing: border-box;
  width: min(1440px, calc(100vw - 80px));
  max-width: 1440px;
  margin: 24px auto;
}

/* When a page shell carries BOTH .transparent_box (narrow 600px shell) and
   .page-box, the wide page width must win. They're equal specificity, so a
   plain .page-box only beats .transparent_box by source order — fragile.
   This combined selector (0,2,0) makes .page-box authoritative regardless of
   load order. */
.transparent_box.page-box {
  width: min(1440px, calc(100vw - 80px));
  max-width: 1440px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

@media (max-width: 768px) {
  .page-box {
    padding: var(--space-4);
    width: calc(100vw - 20px);
    margin: 12px auto;
  }
}

/* ── Modal (<dialog class="modal">, opened via base.js openDialog) ── */
dialog.modal {
  background: var(--surface-solid);
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  border-radius: var(--radius-lg);
  color: var(--text);
  padding: 1.5rem;
  width: min(520px, 95vw);
  box-shadow: 0 30px 80px rgba(var(--accent-rgb), 0.25);
  /* The global `* { margin: 0 }` reset kills the UA `dialog { margin: auto }`
     that centers a showModal()'d dialog — without this, every modal pins to
     the top-left corner. Restores centering on desktop and, when it fits,
     mobile. */
  margin: auto;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(12px);
}

/* Lock page scroll while any dialog is open */
body:has(dialog[open]) {
  overflow: hidden;
}

/* Neutralize the global centered/shadowed h3 inside modals */
.modal-title {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  line-height: 1.3;
  text-align: left;
  text-shadow: none;
}

/* ── Pagination (shared pager macro) ── */
.pagination {
  margin: 2rem 0;
  display: flex;
  justify-content: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  min-width: 34px;
  padding: 0 .75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-2);
  color: #fff;
  text-decoration: none;
  background: var(--surface-1);
  line-height: 1;
  cursor: pointer;
  transition: .2s ease;
}

.page-btn:hover {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), .12);
}

.page-btn.is-current {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), .15);
  pointer-events: none;
}

.page-btn.is-disabled {
  opacity: .5;
  pointer-events: none;
}

.page-btn.is-ellipsis {
  cursor: default;
}

/* ── Spinner ──
   NOTE: @keyframes spin did not exist anywhere before this file; chords.css
   animates `spin` on its OCR spinner, so defining it here un-freezes that
   spinner (deliberate bug fix). */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(var(--accent-rgb), 0.2);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Validation banners (chord/sheet upload feedback) ── */
.validation-ok {
  background: rgba(var(--accent-rgb), 0.1);
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  color: var(--accent);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.validation-error {
  background: rgba(var(--danger-rgb), 0.1);
  border: 1px solid rgba(var(--danger-rgb), 0.4);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.validation-warn {
  background: rgba(255, 200, 0, 0.1);
  border: 1px solid rgba(255, 200, 0, 0.4);
  color: #ffc800;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.validation-error ul,
.validation-warn ul {
  margin: 0.4rem 0 0 1.2rem;
  padding: 0;
}

.validation-error li,
.validation-warn li {
  margin-bottom: 0.2rem;
}

/* ── Error pages (error.html) ── */
.error-box {
  max-width: 520px;
  margin: 6rem auto;
  text-align: center;
  padding: 3rem 2rem;
}

.error-box__icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  color: rgba(255, 100, 100, 0.8);
}

.error-box h2 {
  margin: 0 0 0.75rem;
  font-size: 1.6rem;
}

.error-box p {
  color: rgba(255, 255, 255, 0.6);
  margin: 0 0 2rem;
  line-height: 1.6;
}

.accent-link {
  color: var(--accent);
}

@media (max-width: 768px) {
  .error-box {
    margin: 3rem auto;
    padding: 2rem 1rem;
  }
}

/* ── Small utilities ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.inline-form {
  display: inline;
}

.code-block {
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: monospace;
  font-size: 13px;
  word-break: break-all;
}
