:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --card-subtle: #14171d;
  --accent: #1db954;
  --accent-hover: #1ed760;
  --accent2: #3b82f6;
  --accent2-hover: #60a5fa;
  --text: #e8eaed;
  --text-dim: #cfd4da;
  --muted: #9aa0a6;
  --border: #2a2e37;
  --border-light: #363b46;
  --error: #ff5252;
  --error-bg: rgba(255, 82, 82, 0.12);
  --warning: #fbbf24;
  --success: #1db954;
  --success-bg: rgba(29, 185, 84, 0.12);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2030, var(--bg));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
}

/* --- Cartes de conteneur ------------------------------------------------ */
.card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.card.wide { max-width: 860px; }
.card.main-card { padding: 24px 28px 32px; }

h1 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { margin: 24px 0 12px; font-size: 1.05rem; color: var(--text-dim); font-weight: 600; }
.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 0.95rem; }

/* --- Barre supérieure de navigation ------------------------------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.nav-back {
  color: var(--accent2);
  text-decoration: none;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.08);
  transition: background 0.15s ease;
}
.nav-back:hover { background: rgba(59, 130, 246, 0.16); text-decoration: none; }
.brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.nav-external {
  color: var(--text-dim);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--card-subtle);
  border: 1px solid var(--border);
  transition: border-color 0.15s ease, color 0.15s ease;
}
.nav-external:hover { border-color: var(--accent); color: var(--text); }
.nav-logout, .logout {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}
.nav-logout:hover, .logout:hover { color: var(--error); text-decoration: underline; }
.hello { color: var(--muted); }

/* --- Onglets de navigation ---------------------------------------------- */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: var(--card-subtle);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
}
.tab-icon { font-size: 1.05rem; }
.tab-badge {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #04210f;
  font-weight: 700;
}

/* --- Formulaire d'ajout ------------------------------------------------- */
.add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}
.input-group {
  display: flex;
  gap: 10px;
  width: 100%;
}
.input-group input[type="text"] {
  flex: 1;
  background: var(--card-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 13px 16px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.input-group input[type="text"]:focus {
  border-color: var(--accent);
}
.hint-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.pill {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--card-subtle);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
}

/* --- Boutons généraux --------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.btn-primary {
  background: var(--accent);
  color: #04210f;
}
.btn-secondary {
  background: var(--card-subtle);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent2); }
.btn-secondary.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent2);
  color: #93c5fd;
}
.btn-danger {
  background: var(--error);
  color: #fff;
}
.btn-danger-outline {
  background: transparent;
  color: var(--error);
  border: 1px solid rgba(255, 82, 82, 0.4);
}
.btn-danger-outline:hover {
  background: var(--error-bg);
  border-color: var(--error);
}
.btn-subtle {
  background: var(--card-subtle);
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-subtle:hover { color: var(--text); border-color: var(--border-light); }
.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
  border-radius: 8px;
}
.btn-xs {
  padding: 4px 8px;
  font-size: 0.75rem;
  border-radius: 6px;
}
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}
.btn-icon:hover { border-color: var(--text-dim); }
.btn-icon-danger {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s ease;
}
.btn-icon-danger:hover {
  background: var(--error-bg);
  border-color: rgba(255, 82, 82, 0.4);
}
.btn-icon-xs {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
}
.btn-icon-xs:hover { color: var(--error); background: var(--error-bg); }

/* --- Header de section -------------------------------------------------- */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 28px 0 12px;
}
.section-header h2 { margin: 0; }

/* --- Suivi des tâches (Jobs) -------------------------------------------- */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.job-card {
  background: var(--card-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  transition: border-color 0.15s ease;
}
.job-status-running { border-color: rgba(59, 130, 246, 0.4); }
.job-status-done { border-color: rgba(29, 185, 84, 0.3); }
.job-status-error { border-color: rgba(255, 82, 82, 0.3); }
.job-status-cancelled { border-color: rgba(154, 160, 166, 0.25); opacity: 0.85; }

.job-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.job-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.job-kind-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  flex-shrink: 0;
}
.job-query {
  font-weight: 600;
  font-size: 0.95rem;
  word-break: break-all;
}
.job-top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.job-message {
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--text-dim);
}
.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* Badges de statut */
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-queued { background: #333; color: #ccc; }
.badge-running {
  background: var(--info-bg);
  color: #93c5fd;
  animation: pulse-border 2s infinite ease-in-out;
}
.badge-done { background: var(--success-bg); color: #7ee2a8; }
.badge-error { background: var(--error-bg); color: #ffb3b3; }
.badge-cancelled { background: rgba(154, 160, 166, 0.15); color: #cfd4da; }

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0); }
}

.tracks-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.tracks-list li {
  word-break: break-all;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px 8px;
  border-radius: 6px;
}
.more-tracks summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* Logs */
.job-log-details {
  margin-top: 10px;
  font-size: 0.82rem;
}
.job-log-details summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
.job-log-details summary:hover { color: var(--text-dim); }
.job-log-pre {
  background: #06080c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.76rem;
  color: #b9c0cc;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  margin: 8px 0 0;
}

/* --- Barre d'outils bibliothèque --------------------------------------- */
.lib-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.search-icon {
  position: absolute;
  left: 14px;
  font-size: 0.95rem;
  pointer-events: none;
  color: var(--muted);
}
.search-box input {
  width: 100%;
  background: var(--card-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 38px 11px 40px;
  color: var(--text);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.search-box input:focus { border-color: var(--accent2); }
.btn-clear {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
}
.btn-clear:hover { color: var(--text); }

.lib-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.select-input {
  background: var(--card-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.85rem;
  outline: none;
}

/* Barre de sélection par lot */
.batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.batch-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #93c5fd;
}
.batch-actions {
  display: flex;
  gap: 8px;
}

.lib-status {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Liste des pistes */
.lib-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lib-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.lib-row:hover {
  background: #181c24;
  border-color: var(--border-light);
}
.lib-row.selected {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.4);
}
.lib-row-check {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.lib-row-check input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent2);
  cursor: pointer;
}
.lib-row-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.lib-row-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  word-break: break-word;
}
.lib-row-artist {
  font-size: 0.82rem;
  color: var(--text-dim);
}
.lib-row-info {
  font-size: 0.74rem;
  color: var(--muted);
}
.lib-row-action {
  flex-shrink: 0;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.pg-indicator {
  font-size: 0.85rem;
  color: var(--muted);
}

/* États vides */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--muted);
  text-align: center;
}
.empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.6; }
.empty-state p { margin: 0; font-size: 0.9rem; }

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: #04210f;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Modals ------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9999;
}
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: modal-pop 0.15s ease-out;
}
@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
  padding: 0 10px;
}
.modal-icon { font-size: 1.3rem; }
.btn-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}
.btn-close:hover { color: var(--text); }
.modal-body {
  padding: 20px 22px;
  font-size: 0.92rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.modal-body p { margin: 0 0 10px; }
.modal-sub { font-size: 0.8rem; color: var(--muted); margin-top: 10px !important; }
.file-preview-list {
  max-height: 160px;
  overflow-y: auto;
  background: #06080c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 10px 0;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.file-preview-single {
  background: #06080c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.88rem;
  color: var(--text);
  word-break: break-word;
}
.preview-more { color: var(--muted); font-style: italic; margin-top: 4px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  background: var(--card-subtle);
  border-top: 1px solid var(--border);
}

/* --- Toasts ------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10000;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.fade-out { opacity: 0; transform: translateY(6px); }
.toast-success { border-color: rgba(29, 185, 84, 0.4); }
.toast-success .toast-icon { color: var(--accent); }
.toast-error { border-color: rgba(255, 82, 82, 0.4); }
.toast-error .toast-icon { color: var(--error); }
.toast-info { border-color: rgba(59, 130, 246, 0.4); }
.toast-info .toast-icon { color: var(--accent2); }

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

/* --- Pages d'accueil (choice.html) & Connexion (login.html) ------------- */
.form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="password"] {
  background: #0e1016;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
}
input:focus { border-color: var(--accent2); }
.error { color: var(--error); min-height: 1em; margin: 0; font-size: 0.9rem; }

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-top: 10px;
}
.choice {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  background: #0e1016;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 16px;
  text-align: center;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.choice:hover { transform: translateY(-2px); border-color: var(--accent); }
.choice.lib:hover { border-color: var(--warning); }
.choice.open:hover { border-color: var(--accent2); }
.choice .emoji { font-size: 2rem; margin-bottom: 2px; }
.choice-title { font-weight: 600; font-size: 0.95rem; }
.choice-sub { font-size: 0.8rem; color: var(--muted); }

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 640px) {
  body { padding: 16px 10px; }
  .card { padding: 20px 16px; }
  .card.main-card { padding: 18px 14px; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .tab-btn { font-size: 0.85rem; padding: 8px 10px; }
  .input-group { flex-direction: column; }
  .lib-controls { flex-direction: column; align-items: stretch; }
  .lib-controls > * { width: 100%; }
  .toast-container { left: 16px; right: 16px; bottom: 16px; }
}
