:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e2e4e9;
  --accent: #d43f3f;
  --accent-hover: #b83232;
  --error: #c0392b;
  --ok: #1e8e3e;
  --warn: #b7791f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1e2126;
    --text: #ecedf0;
    --muted: #9aa0aa;
    --border: #2c3038;
    --accent: #e05353;
    --accent-hover: #ef6b6b;
    --error: #ff6b5e;
    --ok: #4ade80;
    --warn: #f2c94c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
}

.topbar a {
  color: var(--muted);
  text-decoration: none;
}

.topbar a:hover {
  color: var(--text);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

h1, h2 {
  color: var(--text);
}

h2 {
  font-size: 1rem;
  margin-top: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

textarea, input[type="password"], input[type="search"], input[type="text"] {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  appearance: none;
  -webkit-appearance: none;
}

input[type="search"]::-webkit-search-cancel-button {
  filter: grayscale(1) opacity(0.6);
}

textarea:focus, input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  margin-top: 0.75rem;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.action-buttons form {
  display: inline-flex;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.85rem;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-download {
  background: rgba(30, 142, 62, 0.12);
  color: var(--ok);
  border-color: rgba(30, 142, 62, 0.3);
}

.btn-download:hover {
  background: var(--ok);
  color: #fff;
}

.btn-retry {
  background: rgba(183, 121, 31, 0.12);
  color: var(--warn);
  border-color: rgba(183, 121, 31, 0.3);
}

.btn-retry:hover {
  background: var(--warn);
  color: #fff;
}

.btn-stop {
  background: rgba(192, 57, 43, 0.12);
  color: var(--error);
  border-color: rgba(192, 57, 43, 0.3);
}

.btn-stop:hover {
  background: var(--error);
  color: #fff;
}

.btn-delete {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-delete:hover {
  background: rgba(192, 57, 43, 0.12);
  color: var(--error);
  border-color: rgba(192, 57, 43, 0.3);
}

#search-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

#search-form label {
  display: none;
}

#search-form input {
  flex: 1;
}

#search-form button {
  margin-top: 0;
  white-space: nowrap;
}

.search-results {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}

.search-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.search-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.search-card-info {
  padding: 0.6rem 0.75rem 0.3rem;
  flex: 1;
}

.search-card-title {
  margin: 0 0 0.25rem;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-card-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.search-card .btn-add {
  margin: 0.5rem 0.75rem 0.75rem;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.search-card .btn-add:hover {
  background: var(--accent-hover);
}

.search-card .btn-add:disabled {
  opacity: 0.6;
  cursor: default;
}

#artist-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

#artist-form label {
  display: none;
}

#artist-form input {
  flex: 1;
}

#artist-form button {
  margin-top: 0;
  white-space: nowrap;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chip {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  margin: 0;
}

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

.chip-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.subsection-title {
  margin: 1.25rem 0 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.loading-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.album-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.9rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}

.album-card:hover {
  border-color: var(--accent);
}

.album-card.chip-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.album-card-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.album-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.album-tracks-header {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.album-tracks-title {
  margin: 0;
  font-weight: 600;
}

.album-tracks-header .btn-add {
  margin: 0;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.album-tracks-header .btn-add:hover {
  background: var(--accent-hover);
}

.album-tracks-header .btn-add:disabled {
  opacity: 0.6;
  cursor: default;
}

.track-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.track-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.88rem;
}

.btn-add-track {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.btn-add-track:hover {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn-add-track:disabled {
  opacity: 0.6;
  cursor: default;
}

.error {
  color: var(--error);
  font-size: 0.9rem;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: normal;
  overflow-wrap: break-word;
  vertical-align: middle;
}

/* Colonnes de #history-table : case | titre | statut | date | taille | actions */
#history-table th:nth-child(1), #history-table td:nth-child(1) { width: 8%; }
#history-table th:nth-child(2), #history-table td:nth-child(2) { width: 32%; }
#history-table th:nth-child(3), #history-table td:nth-child(3) { width: 18%; }
#history-table th:nth-child(4), #history-table td:nth-child(4) { width: 16%; }
#history-table th:nth-child(5), #history-table td:nth-child(5) { width: 9%; }
#history-table th:nth-child(6), #history-table td:nth-child(6) { width: 17%; }

@media (max-width: 640px) {
  #history-table th:nth-child(4), #history-table td:nth-child(4) {
    display: none;
  }
  #history-table th:nth-child(2), #history-table td:nth-child(2) { width: 38%; }
  #history-table th:nth-child(3), #history-table td:nth-child(3) { width: 20%; }
  #history-table th:nth-child(5), #history-table td:nth-child(5) { width: 12%; }
  #history-table th:nth-child(6), #history-table td:nth-child(6) { width: 22%; }

  .action-buttons .btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.72rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

td .error {
  display: inline-block;
  white-space: normal;
  overflow-wrap: break-word;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--border);
  color: var(--muted);
}

.status-done {
  background: rgba(30, 142, 62, 0.15);
  color: var(--ok);
}

.status-error {
  background: rgba(192, 57, 43, 0.15);
  color: var(--error);
}

.status-processing {
  background: rgba(183, 121, 31, 0.15);
  color: var(--warn);
}

.status-cancelled {
  background: var(--border);
  color: var(--muted);
}

.spinner {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.hint {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.meta {
  color: var(--muted);
}

.queue-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: rgba(183, 121, 31, 0.12);
  color: var(--warn);
  font-size: 0.85rem;
}

.queue-status[hidden] {
  display: none;
}

.queue-status .spinner {
  flex-shrink: 0;
}

#progress-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.progress-item {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.9rem;
}

.progress-item.status-error {
  color: var(--error);
}

.progress-item.status-done {
  color: var(--ok);
}

.selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

#bulk-action {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 1.8rem 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--bg);
  color: var(--text);
  color-scheme: dark light;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1rem) center, calc(100% - 0.65rem) center;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
}

#bulk-action:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chevron {
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  border-style: solid;
  border-width: 0 2px 2px 0;
  border-color: currentColor;
  vertical-align: middle;
}

.chevron-left {
  transform: rotate(135deg);
}

.chevron-right {
  transform: rotate(-45deg);
}

.btn-select {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  margin: 0;
}

.btn-select:hover {
  border-color: var(--accent);
}

.btn-select:disabled,
.selection-bar .btn-add:disabled {
  opacity: 0.5;
  cursor: default;
}

#history-table th:first-child,
#history-table td:first-child {
  width: 2.75rem;
  white-space: nowrap;
  text-align: center;
}

.switch {
  position: relative;
  display: inline-block;
  width: 2.2rem;
  height: 1.2rem;
  vertical-align: middle;
  cursor: pointer;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s ease;
}

.switch-track::before {
  content: '';
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::before {
  transform: translateX(1rem);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.title-cell {
  cursor: pointer;
}

.title-cell:hover {
  color: var(--accent);
}

.preview-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  margin: 0 0.4rem 0 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-size: 0.6rem;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  opacity: 1;
}

.preview-btn:hover {
  color: var(--accent);
  opacity: 1;
}

.preview-btn.playing {
  background: var(--accent);
  color: #fff;
  opacity: 1;
}

.title-text {
  vertical-align: middle;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.pager[hidden] {
  display: none;
}

#pager-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 360px;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

#confirm-modal-message {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.modal-actions .btn {
  margin: 0;
}

.intro-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (max-width: 640px) {
  .intro-grid {
    grid-template-columns: 1fr;
  }
}

.intro-block {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
}

.intro-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.intro-block h3 {
  margin: 0.5rem 0 0.3rem;
  font-size: 0.95rem;
  color: var(--text);
}

.intro-block p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}
