/* web/static/css/playlists.css */
html.pl-app-layout,
body.pl-app-layout {
  height: 100%;
  overflow: hidden;
}

.pl-scope-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pl-scope-toggle {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(0, 0, 0, 0.03);
}

.pl-scope-toggle button {
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
}

.pl-scope-toggle button.is-active {
  background: #0a7cff;
  border-color: #0a7cff;
  color: #fff;
}

.pl-scope-status {
  color: #567;
  font-size: 0.92em;
  min-height: 1.1em;
}

/* Layout */
.pl-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
  align-items: stretch;
}

/* Retired grid layouts
.pl-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 12px;
  align-items: start;
}

.pl-layout.pl-layout-folders {
  grid-template-columns: minmax(200px, 260px) minmax(220px, 320px) 1fr;
}
*/

.pl-panel {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;

  /* Mobile-first: do NOT force full height */
  height: auto;
}

@media (min-width: 981px) {

  /* Desktop-only: "app style" panels */
  .pl-panel {
    height: calc(100dvh - 140px - var(--player-offset, 80px));
  }
}

.pl-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
  flex: none;
}

.pl-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  padding-bottom: calc(var(--player-offset, 0px) + env(safe-area-inset-bottom, 0px));
}

/* Lists */
/* Lists */
.pl-list,
.pl-tree-list,
.pl-items,
.pl-modal-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Sidebar list items */
.pl-list li,
.pl-tree-list li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.pl-list li:hover,
.pl-tree-list li:hover {
  background: rgba(0, 0, 0, 0.04);
}

.pl-list li.is-active,
.pl-tree-list li.is-active {
  background: rgba(10, 124, 255, 0.12);
  color: #0a7cff;
  font-weight: 600;
}

.pl-list .pl-name,
.pl-tree-list .pl-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
}

.pl-icon_svg {
  width: 1.1em;
  height: 1.1em;
  margin-right: 6px;
  flex: none;
  opacity: 0.6;
}

#fldHeader.pl-drop-target {
  background: rgba(10, 124, 255, 0.15);
  outline: 2px dashed #0a7cff;
  outline-offset: -2px;
  border-radius: 6px;
}

.pl-list .pl-meta,
.pl-tree-list .pl-meta {
  flex: none;
  color: #789;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
}

/* Detail header */
.pl-detail-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
  flex: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  padding-bottom: 12px;
}

.pl-detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pl-detail-top h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.pl-detail-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.pl-detail-controls button {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #fff;
  cursor: pointer;
  font-size: 0.9em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pl-detail-controls button.primary {
  background: #0a7cff;
  border-color: #0a7cff;
  color: #fff;
}

.pl-detail-controls button.danger {
  color: #d00;
  border-color: rgba(200, 0, 0, 0.3);
}

/* Playlist item list */
.pl-items {
  width: 100%;
}

/* Playlist items (rows) */
.pl-items li {
  width: 100%;
  box-sizing: border-box;

  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 12px;
  align-items: center;

  padding: 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  margin-bottom: 4px;
  background: #fff;
  transition: background 0.1s;
}

.pl-items li:hover {
  background: rgba(0, 0, 0, 0.03);
}

/* Drag handle (only visible in edit mode) */
.pl-item-drag {
  cursor: grab;
  color: #999;
  font-size: 1.2em;
  padding: 0 4px;
  display: none;
  user-select: none;
}

/* Cover */
.pl-item-cover {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: #eee;
  object-fit: cover;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Text info */
.pl-item-info {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
}

.pl-item-title {
  font-weight: 600;
  font-size: 0.95em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pl-item-book {
  font-size: 0.85em;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right actions */
.pl-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.pl-item-dur {
  font-size: 0.85em;
  color: #888;
  font-variant-numeric: tabular-nums;
}

/* Icon buttons */
.pl-btn-icon {
  background: transparent;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  color: #555;
}

.pl-btn-icon:hover {
  background: rgba(0, 0, 0, 0.08);
}

.pl-btn-remove {
  color: #c00;
  display: none;
}

/* EDIT MODE */
.pl-items.is-editing li {
  border-color: rgba(0, 0, 0, 0.08);
  background: #fafafa;
}

.pl-items.is-editing .pl-item-drag {
  display: block;
}

.pl-items.is-editing .pl-btn-remove {
  display: block;
}

.pl-items.is-editing .pl-btn-menu {
  display: none;
}

/* Edit mode: Disable clicks on item info */
.pl-items.is-editing .pl-item-info {
  pointer-events: none;
  opacity: 0.85;
  cursor: default;
}

/* Move Up/Down buttons - only visible in edit mode */
.pl-btn-move {
  display: none;
  background: transparent;
  border: none;
  font-size: 1.1em;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  color: #555;
}

.pl-btn-move:hover {
  background: rgba(0, 0, 0, 0.08);
}

.pl-btn-move:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pl-items.is-editing .pl-btn-move {
  display: inline-block;
}

/* Drag Ghost (touch-based) */
.pl-drag-ghost {
  position: fixed;
  z-index: 300000;
  pointer-events: none;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0.95;
  transform: scale(1.02);
}

/* Drag Placeholder */
.pl-drag-placeholder {
  background: rgba(10, 124, 255, 0.12);
  border: 2px dashed #0a7cff;
  border-radius: 10px;
  min-height: 50px;
  margin-bottom: 4px;
}

/* Empty state */
.pl-empty-hint {
  padding: 40px 20px;
  text-align: center;
  color: #889;
  background: #f9f9f9;
  border-radius: 12px;
  border: 2px dashed rgba(0, 0, 0, 0.05);
}

/* Menu popover */
.pl-menu-popover {
  position: fixed;
  z-index: 220000;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 180px;
}

.pl-menu-item {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.95em;
  color: #333;
}

.pl-menu-item:hover {
  background: #f0f0f0;
}

/* ============================================
   MOBILE NAVIGATION STACK (≤980px)
   ============================================ */
@media (max-width: 980px) {

  /* Navigation container - sized to leave room for the player */
  .pl-layout {
    position: relative;
    /* Use 124px fallback: collapsed player (~100px) + 24px margin */
    height: calc(100dvh - var(--player-offset, 124px) - env(safe-area-inset-bottom, 0px)) !important;
    overflow: hidden !important;
  }

  /* Both panels: absolute, fill the layout container */
  #plSidebar,
  #plDetail {
    position: absolute !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    transition: transform 0.3s ease, opacity 0.3s ease;
    overflow-y: auto;
    box-sizing: border-box;
  }

  /* Library panel: starts visible */
  #plSidebar {
    z-index: 1;
    transform: translateX(0);
    flex: none !important;
  }

  /* Detail panel: starts off-screen right */
  #plDetail {
    z-index: 2;
    transform: translateX(100%);
  }

  /* When detail is active, slide it in */
  #plDetail.is-active {
    transform: translateX(0);
  }

  /* Push the library back when detail is active */
  #plSidebar.is-pushed {
    transform: translateX(-30%);
    opacity: 0.5;
    pointer-events: none;
  }

  /* Hide resize handle on mobile */
  #plResizeHandle {
    display: none !important;
  }

  /* Show breadcrumbs on mobile */
  .pl-breadcrumbs-nav {
    display: flex !important;
  }

  /* Panel heights for scrolling */
  .pl-panel {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .pl-scroll-area {
    flex: 1 1 0% !important;
    overflow-y: auto !important;
    min-height: 0 !important;
    /* Extra breathing room at bottom - needs to cover header offset (~50px) + visual spacing */
    padding-bottom: calc(50px + 16px) !important;
  }

  /* ============================================
     DRAG PEEK OVERLAY (mobile only)
     ============================================ */
  .pl-drag-peek {
    position: fixed;
    top: 0;
    left: 0;
    bottom: calc(var(--player-offset, 80px) + env(safe-area-inset-bottom, 0px));
    width: 80px;
    background: rgba(255, 255, 255, 0.98);
    border-right: 2px solid rgba(10, 124, 255, 0.3);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.2s ease, width 0.2s ease;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .pl-drag-peek.is-visible {
    transform: translateX(0);
  }

  .pl-drag-peek.is-expanded {
    width: 50%;
  }

  .pl-drag-peek .pl-tree-list {
    padding: 8px;
    font-size: 0.9em;
  }

  .pl-drag-peek .pl-tree-list li {
    padding: 8px 6px;
  }

  .pl-drag-peek .pl-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Dark mode drag peek */
  .dark-mode .pl-drag-peek {
    background: rgba(30, 30, 30, 0.98);
    border-right-color: rgba(102, 170, 255, 0.3);
  }
}

/* ============================================
   BREADCRUMB NAVIGATION (hidden on desktop)
   ============================================ */
.pl-breadcrumbs-nav {
  display: none;
  /* Hidden on desktop */
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  margin-bottom: 8px;
  flex: none;
  background: #fff;
  /* Override absolute positioning from mobile panel styles */
  position: relative !important;
  top: auto !important;
  left: auto !important;
  width: auto !important;
  height: auto !important;
  transform: none !important;
}

.pl-back-btn {
  background: none;
  border: none;
  font-size: 1.4em;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  color: #0a7cff;
}

.pl-back-btn:hover {
  background: rgba(10, 124, 255, 0.1);
}

/* Dark mode breadcrumbs */
.dark-mode .pl-breadcrumbs-nav {
  border-bottom-color: var(--border);
}

.dark-mode .pl-back-btn {
  color: #66aaff;
}

.dark-mode .pl-back-btn:hover {
  background: rgba(102, 170, 255, 0.15);
}

/* Resize Handle */
.pl-resize-handle {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex: none;
  z-index: 10;
  margin: 0 -2px;
  /* Visual overlap? Or just spacing */
  position: relative;
}

.pl-resize-handle:hover,
.pl-resize-handle.is-resizing {
  background: rgba(10, 124, 255, 0.3);
}

.dark-mode .pl-resize-handle:hover,
.dark-mode .pl-resize-handle.is-resizing {
  background: rgba(102, 170, 255, 0.3);
}

/* Folder tree chevrons and menu buttons */
.pl-folder-chevron {
  flex: none;
  width: 16px;
  font-size: 0.75em;
  text-align: center;
  user-select: none;
  color: #666;
}

.pl-folder-chevron:hover {
  color: #0a7cff;
}

.pl-folder-menu-btn {
  flex: none;
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 1em;
  padding: 2px 6px;
}

.pl-list li:hover .pl-folder-menu-btn,
.pl-tree-list li:hover .pl-folder-menu-btn {
  opacity: 0.6;
}

.pl-list li:hover .pl-folder-menu-btn:hover,
.pl-tree-list li:hover .pl-folder-menu-btn:hover {
  opacity: 1;
}

/* Folder drag-and-drop states */
.pl-list li.is-dragging,
.pl-tree-list li.is-dragging {
  opacity: 0.5;
}

.pl-list li.pl-drop-target,
.pl-tree-list li.pl-drop-target {
  background: rgba(10, 124, 255, 0.15);
  outline: 2px dashed #0a7cff;
  outline-offset: -2px;
}

/* Breadcrumb navigation */
.pl-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  font-size: 0.95em;
}

.pl-breadcrumb-sep {
  color: #999;
  user-select: none;
}

.pl-breadcrumb-item {
  padding: 2px 4px;
  border-radius: 4px;
}

.pl-breadcrumb-link {
  cursor: pointer;
  color: #0a7cff;
}

.pl-breadcrumb-link:hover {
  background: rgba(10, 124, 255, 0.1);
  text-decoration: underline;
}

.pl-breadcrumb-current {
  font-weight: 600;
  color: inherit;
}

/* Dark mode */
.dark-mode .pl-panel,
.dark-mode .pl-items li,
.dark-mode .pl-modal-dialog,
.dark-mode .pl-menu-popover {
  background: var(--bg-secondary);
  color: var(--fg-primary);
  border-color: var(--border);
}

.dark-mode .pl-scope-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.dark-mode .pl-scope-toggle button.is-active {
  background: #2b7cff;
  border-color: #2b7cff;
  color: #fff;
}

.dark-mode .pl-list li:hover,
.dark-mode .pl-tree-list li:hover {
  background: rgba(255, 255, 255, 0.04);
}

.dark-mode .pl-list li.is-active,
.dark-mode .pl-tree-list li.is-active {
  background: rgba(102, 170, 255, 0.14);
  color: var(--accent);
}

.dark-mode .pl-items li {
  background: var(--bg-card);
}

.dark-mode .pl-item-cover {
  border-color: rgba(255, 255, 255, 0.1);
  background: #222;
}

.dark-mode .pl-item-book {
  color: #aaa;
}

.dark-mode .pl-detail-controls button {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--fg-primary);
}

.dark-mode .pl-detail-controls button.primary {
  background: #2b7cff;
  border-color: #2b7cff;
  color: #fff;
}

.dark-mode .pl-btn-icon {
  color: #ccc;
}

.dark-mode .pl-btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.dark-mode .pl-menu-item {
  color: var(--fg-primary);
}

.dark-mode .pl-menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Dark mode: folder tree chevrons and buttons */
.dark-mode .pl-folder-chevron {
  color: #999;
}

.dark-mode .pl-folder-chevron:hover {
  color: #66aaff;
}

.dark-mode .pl-folder-menu-btn {
  color: #999;
}

/* Dark mode: drag-and-drop states */
.dark-mode .pl-list li.pl-drop-target,
.dark-mode .pl-tree-list li.pl-drop-target {
  background: rgba(102, 170, 255, 0.2);
  outline-color: #66aaff;
}

/* Dark mode: breadcrumbs */
.dark-mode .pl-breadcrumb-sep {
  color: #666;
}

.dark-mode .pl-breadcrumb-link {
  color: #66aaff;
}

.dark-mode .pl-breadcrumb-link:hover {
  background: rgba(102, 170, 255, 0.15);
}

/* Smooth modal step transitions */
#cimStepType,
#cimStepName {
  transition: opacity 0.15s ease-out;
}

#cimStepType[style*="display: none"],
#cimStepName[style*="display: none"] {
  opacity: 0;
}

/* Smart Playlist Builder */
.pl-smart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.pl-smart-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pl-smart-field label {
  font-size: 0.9em;
  color: #345;
}

.pl-smart-field input,
.pl-smart-field select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.pl-smart-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(10, 124, 255, 0.08);
  color: #0a7cff;
  font-size: 0.9em;
}

.pl-smart-section {
  margin: 12px 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed rgba(0, 0, 0, 0.08);
  background: #fafafa;
}

.pl-smart-section-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.pl-smart-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95em;
}

.pl-smart-seq {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pl-smart-seq-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pl-smart-seq-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: #fff;
}

.pl-smart-seq-item span {
  flex: 1 1 auto;
  min-width: 0;
}

.pl-smart-seq-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pl-smart-preview {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  max-height: 220px;
  overflow-y: auto;
}

.pl-smart-preview ul {
  margin: 0;
  padding-left: 18px;
}

.pl-smart-note {
  font-size: 0.85em;
  color: #567;
}

.pl-smart-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  margin-top: 12px;
}

.pl-smart-actions .primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#smartPlaylistModal[aria-hidden="false"] {
  display: flex;
  align-items: center;
  justify-content: center;
}

#smartPlaylistModal .pl-modal-dialog {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
}

.dark-mode .pl-smart-section {
  background: var(--bg-secondary);
  border-color: var(--border);
}

.dark-mode .pl-smart-field input,
.dark-mode .pl-smart-field select,
.dark-mode .pl-smart-preview,
.dark-mode .pl-smart-seq-item {
  background: var(--bg-input);
  color: var(--fg-primary);
  border-color: var(--border);
}

.dark-mode .pl-smart-pill {
  background: rgba(102, 170, 255, 0.15);
  color: #66aaff;
}