/* ---------- RESET & BASE ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Adwaita-dark inspired palette */
  --bg-headerbar: #1e1e1e;
  --bg-window: #242424;
  --bg-card: #2d2d2d;
  --bg-hover: #383838;
  --bg-active: #3d3d3d;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text-primary: rgba(255, 255, 255, 0.96);
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-tertiary: rgba(255, 255, 255, 0.4);
  --accent: #62a0ea;
  --accent-strong: #3584e4;
  --accent-glow: rgba(53, 132, 228, 0.35);
  --danger: #e56a6a;
  --radius-window: 12px;
  --radius-card: 10px;
  --radius-sm: 7px;
  --radius-pill: 999px;
  --shadow-window: 0 20px 60px rgba(0, 0, 0, 0.55);
  --shadow-card: 0 2px 10px rgba(255, 255, 255, 0.15);
  --transition: 0.18s cubic-bezier(0.3, 0, 0.2, 1);
  --font: system-ui, -apple-system, "Segoe UI", Cantarell, Roboto, sans-serif;
  --page-bg: #131313;
  --scrim-top: rgba(15, 15, 20, 0.55);
  --scrim-mid: rgba(15, 15, 20, 0.72);
  --scrim-bottom: rgba(15, 15, 20, 0.88);
  --glass-headerbar: rgba(30, 30, 30, 0.4);
  --glass-queue: rgba(24, 24, 28, 0.55);
}

:root[data-theme="light"] {
  --bg-headerbar: #f6f6f6;
  --bg-window: #f6f6f6;
  --bg-card: #ffffff;
  --bg-hover: #e6e6e6;
  --bg-active: #dadada;
  --border: rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text-primary: rgba(0, 0, 0, 0.88);
  --text-secondary: rgba(0, 0, 0, 0.58);
  --text-tertiary: rgba(0, 0, 0, 0.38);
  --danger: #c01c28;
  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.35);
  --page-bg: #e5e5e8;
  --scrim-top: rgba(255, 255, 255, 0.55);
  --scrim-mid: rgba(240, 240, 244, 0.75);
  --scrim-bottom: rgba(230, 230, 235, 0.92);
  --glass-headerbar: rgba(255, 255, 255, 0.5);
  --glass-queue: rgba(255, 255, 255, 0.65);
}

html,
body {
  height: 100%;
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
}

button {
  font-family: inherit;
}

/* ---------- APP WINDOW ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background: var(--bg-window);
  overflow: hidden;
  position: relative;
}

/* Blurred, oversized copy of the current cover art sitting behind everything */
.art-backdrop {
  position: absolute;
  inset: -5%;
  background-color: #17171f;
  background-size: cover;
  background-position: center;
  filter: blur(70px) saturate(1.3);
  transform: scale(1.1);
  transition: background-image 0.5s ease;
  z-index: 0;
}
.art-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--scrim-top) 0%, var(--scrim-mid) 55%, var(--scrim-bottom) 100%);
  transition: background var(--transition);
  z-index: 0;
}

/* ---------- HEADERBAR ---------- */
.headerbar {
  flex-shrink: 0;
  height: 50px;
  background: var(--glass-headerbar);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 16px;
  position: relative;
  z-index: 2;
  transition: background var(--transition), border-color var(--transition);
}

.headerbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.app-icon {
  display: flex;
  color: var(--accent);
}

.headerbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn[aria-pressed="true"] {
  background: var(--bg-hover);
  color: var(--accent);
}

.btn-upload {
  position: relative;
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-upload:hover {
  background: var(--bg-active);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- BODY AREA ---------- */
.body-area {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
  z-index: 1;
}

/* ---------- PLAYER VIEW (now playing) ---------- */
.player-view {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 32px 28px;
}

.cover-wrap {
  width: min(38vh, 230px);
  aspect-ratio: 1;
}

.album-art {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-card);
  background: transparent;
  display: block;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
}
.album-art.has-fallback {
  background: linear-gradient(145deg, #8f8fff, #40a475);
}
.album-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 2;
}
.album-art svg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  display: block;
  z-index: 1;
}
.album-art img[hidden],
.album-art svg[hidden] {
  display: none !important;
}
.album-art img:not([hidden]) ~ svg {
  display: none !important;
}

.track-details {
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.track-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.progress-slider {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
}
.progress-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) calc(var(--fill, 0%)),
    var(--border-strong) calc(var(--fill, 0%))
  );
}
.progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.progress-slider::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
}
.progress-slider::-moz-range-progress {
  height: 4px;
  border-radius: 4px;
  background: var(--accent);
}
.progress-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- TRANSPORT ---------- */
.transport {
  display: flex;
  align-items: center;
  gap: 22px;
}
.ctrl-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform 0.12s;
}
.ctrl-btn:hover {
  background: var(--bg-hover);
}
.ctrl-btn:active {
  transform: scale(0.92);
}
.play-btn {
  width: 56px;
  height: 56px;
  background: var(--accent-strong);
  color: #fff;
  box-shadow: 0 4px 18px var(--accent-glow);
}
.play-btn:hover {
  background: var(--accent);
}

.icon-hidden {
  display: none;
}

#albumFallback {
  stroke: rgba(255, 255, 255, 0.4);
}

.volume-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 160px;
  max-width: 100%;
  margin: 0 auto;
  color: var(--text-secondary);
}
.vol-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}
.volume-slider {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
}
.volume-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) calc(var(--fill, 80%)),
    var(--border-strong) calc(var(--fill, 80%))
  );
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.volume-slider::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
}
.volume-slider::-moz-range-progress {
  height: 4px;
  border-radius: 4px;
  background: var(--accent);
}
.volume-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- QUEUE / PLAYLIST SIDEBAR ---------- */
.queue-panel {
  flex-shrink: 0;
  width: 0;
  overflow: hidden;
  background: var(--glass-queue);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border-left: 1px solid transparent;
  display: flex;
  flex-direction: column;
  transition: width var(--transition), border-color var(--transition), background var(--transition);
}
.queue-panel.open {
  width: 300px;
  border-left: 1px solid var(--border);
}

.queue-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.queue-title {
  font-weight: 600;
  font-size: 14px;
}
.song-count {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.playlist-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 12px 8px;
  width: 300px;
}

.playlist-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 220px;
  color: var(--text-tertiary);
  text-align: center;
  gap: 12px;
  padding: 0 24px;
}
.playlist-empty svg {
  opacity: 0.5;
}
.playlist-empty p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.playlist-empty strong {
  color: var(--text-primary);
}

.playlist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  cursor: pointer;
}
.playlist-item:hover {
  background: var(--bg-hover);
}
.playlist-item.active {
  background: var(--bg-active);
}
.playlist-item .thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  background: linear-gradient(145deg, #35354a, #23233a);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  overflow: hidden;
}
.playlist-item .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.playlist-item .thumb svg {
  width: 16px;
  height: 16px;
}
.playlist-item .info {
  flex: 1;
  overflow: hidden;
}
.playlist-item .info .name {
  font-weight: 500;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.playlist-item.active .info .name {
  color: var(--accent);
}
.playlist-item .info .meta {
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.playlist-item .duration {
  font-size: 11.5px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.playlist-item .delete-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
}
.playlist-item:hover .delete-btn {
  opacity: 1;
}
.playlist-item .delete-btn:hover {
  color: var(--danger);
  background: rgba(229, 106, 106, 0.12);
}

.queue-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 720px) {
  .queue-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 86vw;
    max-width: 320px;
    transform: translateX(100%);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
    transition: transform var(--transition);
  }
  .queue-panel.open {
    width: 86vw;
    max-width: 320px;
    transform: translateX(0);
  }
  .playlist-container {
    width: 100%;
  }
  .queue-backdrop.open {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
  .player-view {
    padding: 24px 20px;
    gap: 18px;
  }
  .headerbar-actions .btn-upload span {
    display: none;
  }
  .btn-upload {
    width: 34px;
    padding: 0;
    justify-content: center;
  }
}

/* ---------- ADD MUSIC MODAL ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 380px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-window);
  box-shadow: var(--shadow-window);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 0 16px;
}
.modal-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.modal-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.modal-tab.active {
  background: var(--bg-active);
  color: var(--accent);
}

.modal-body {
  padding: 16px 20px 20px 20px;
}
.modal-pane[hidden] {
  display: none;
}

.modal-hint {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 14px;
}
.modal-hint-tight {
  margin-top: -6px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field-input {
  width: 100%;
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 14px;
  transition: border-color var(--transition), background var(--transition);
}
.field-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-card);
}

.modal-primary-btn {
  width: 100%;
  background: var(--accent-strong);
  color: #fff;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--transition);
}
.modal-primary-btn:hover {
  background: var(--accent);
}

.modal-note {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.modal-note[hidden] {
  display: none;
}

/* ---------- LOGIN / ADMIN (APPENDED) ---------- */
.login-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.login-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}
.login-btn:hover {
  background: var(--bg-active);
}
.admin-btn {
  background: var(--accent-strong);
  color: #fff;
  border: none;
  padding: 0 12px;
  height: 30px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  cursor: pointer;
}
.admin-btn:hover {
  background: var(--accent);
}
.admin-panel {
  max-width: 500px;
}
.admin-panel .user-list {
  list-style: none;
  margin: 10px 0;
}
.admin-panel .user-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.admin-panel .add-user-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.admin-panel .add-user-form input {
  flex: 1;
  min-width: 120px;
}
.admin-panel .add-user-form label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
.admin-panel .add-user-form button {
  background: var(--accent-strong);
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

/* ---------- PLAYLIST DRAG & DROP AND PLAYING INDICATOR ---------- */
.playlist-item {
  position: relative;
  user-select: none;
}

.playlist-item.dragging {
  opacity: 0.4;
  background: var(--bg-hover);
}

.playlist-item.drag-over {
  border-top: 2px solid var(--accent);
}

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  cursor: grab;
  padding: 0 2px;
  flex-shrink: 0;
}
.drag-handle:active {
  cursor: grabbing;
}
.playlist-item:hover .drag-handle {
  color: var(--text-secondary);
}

/* Playing Indicator Animation */
.playlist-item .playing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.playlist-item .playing-indicator span {
  flex: 1;
  background-color: var(--accent);
  border-radius: 1px;
  height: 100%;
  transform-origin: bottom;
  animation: eq-bounce 0.8s ease-in-out infinite alternate;
}
.playlist-item .playing-indicator span:nth-child(1) { animation-delay: 0.1s; }
.playlist-item .playing-indicator span:nth-child(2) { animation-delay: 0.3s; }
.playlist-item .playing-indicator span:nth-child(3) { animation-delay: 0.2s; }

.playlist-item:not(.is-playing) .playing-indicator span {
  animation-play-state: paused;
  height: 30%;
}

@keyframes eq-bounce {
  0% { transform: scaleY(0.2); }
  100% { transform: scaleY(1); }
}

/* Ensure the wrapper tight-fits the input field with no margin contamination */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  margin-bottom: 0; /* Clear any inherited bottom margins */
  margin-bottom: 14px;
}

/* Ensure the input fills the wrapper and reserves space on the right */
.input-wrapper .field-input {
  width: 100%;
  padding-right: 42px; /* Leaves space so text doesn't slide under the icon */
  margin-bottom: 0;    /* Removes bottom margin from the input itself */
  box-sizing: border-box;
}

/* Lock the toggle button precisely to the vertical center of the input */
.toggle-password-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);

  /* Reset button styles */
  background: none;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
  height: 18px; /* Match SVG height */
  width: 18px;  /* Match SVG width */

  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-tertiary, #8e8e93);
}

.toggle-password-btn:hover {
  color: var(--text-primary, #ffffff);
}

/* Ensure SVG icons don't introduce unexpected line-height spacing */
.toggle-password-btn svg {
  display: block;
  pointer-events: none;
}
