/* PlaylisTube - composants : boutons, recherche, champs, puces, badges, menus, fenetre, messages. */

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: background-color .15s, opacity .15s;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  background: var(--surface-3);
}

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

.btn > .icon:first-child {
  margin-left: -4px;
}

.btn-primary,
.btn-primary:active {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: var(--surface-1);
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

/* Bouton en attente : le texte laisse place a un indicateur qui tourne. */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 16px;
  height: 16px;
  margin: auto;
  border: 2px solid var(--on-accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  transition: background-color .15s;
}

.icon-btn:hover {
  background: var(--surface-1);
}

.icon-btn:active {
  background: var(--surface-2);
}

.icon-btn:disabled {
  opacity: .4;
  pointer-events: none;
}

.icon-btn-sm {
  width: 32px;
  height: 32px;
}

.link-btn {
  width: fit-content;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ---------- Recherche principale ---------- */
.search {
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-field {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 4px 0 16px;
  border: 1px solid var(--border-strong);
  border-right: 0;
  border-radius: 40px 0 0 40px;
  background: var(--field-bg);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .05);
}

.search-field:focus-within {
  border-color: var(--focus);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1), 0 0 0 1px var(--focus);
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
}

.search-input:focus-visible {
  outline: none;
}

.search-input::placeholder {
  color: var(--text-3);
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-calendar-picker-indicator {
  display: none !important;
  -webkit-appearance: none;
  appearance: none;
}

.search-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 0 40px 40px 0;
  background: var(--surface-1);
  color: var(--text);
}

.search-btn:hover {
  background: var(--surface-2);
}

/* ---------- Barre d'outils (filtre, tri, affichage) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar-spacer {
  flex: 1;
}

.filter {
  position: relative;
  display: flex;
  align-items: center;
}

.filter > .icon {
  position: absolute;
  left: 10px;
  color: var(--text-2);
  pointer-events: none;
}

.filter-input {
  width: 220px;
  height: 32px;
  padding: 0 10px 0 34px;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  outline: none;
  background: var(--surface-1);
  font-size: 14px;
}

.filter-input::placeholder {
  color: var(--text-2);
}

.filter-input:focus {
  border-color: var(--focus);
  background: var(--field-bg);
}

.select-wrap {
  position: relative;
  display: inline-flex;
}

.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 13px;
  width: 6px;
  height: 6px;
  margin-top: -5px;
  border-right: 2px solid var(--text-2);
  border-bottom: 2px solid var(--text-2);
  transform: rotate(45deg);
  pointer-events: none;
}

.select {
  height: 32px;
  padding: 0 34px 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  background: var(--surface-1);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.select:hover {
  background: var(--surface-2);
}

.select option {
  background: var(--bg-raised);
  color: var(--text);
}

/* ---------- Puces ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-m);
  background: var(--surface-1);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .15s, color .15s;
}

.chip:hover {
  background: var(--surface-2);
}

.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.chip > .icon:first-child {
  margin-left: -2px;
}

.chip-count {
  font-weight: 400;
  opacity: .75;
}

.chip-recent {
  gap: 0;
  padding: 0;
  overflow: hidden;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--card-border);
}

.chip-recent:hover {
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.chip-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  max-width: 260px;
  padding: 0 4px 0 10px;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 500;
}

.chip-main > .icon {
  color: var(--text-2);
}

.chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-remove {
  display: grid;
  place-items: center;
  width: 30px;
  height: 100%;
  border: 0;
  background: none;
  color: var(--text-2);
}

.chip-remove:hover {
  color: var(--text);
}

/* ---------- Choix d'affichage (miniatures / tableau) ---------- */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-m);
  background: var(--surface-1);
}

.segmented button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-2);
}

.segmented button:hover {
  color: var(--text);
}

.segmented button[aria-pressed="true"] {
  background: var(--control-active);
  color: var(--text);
  box-shadow: var(--shadow-control);
}

/* ---------- Badges de statut ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-s);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.badge-public { color: var(--ok-fg); background: var(--ok-bg); }
.badge-unlisted { color: var(--warn-fg); background: var(--warn-bg); }
.badge-private,
.badge-unknown { color: var(--muted-fg); background: var(--muted-bg); }
.badge-deleted,
.badge-unavailable { color: var(--danger-fg); background: var(--danger-bg); }

.id-pill {
  padding: 1px 6px;
  border-radius: var(--radius-s);
  background: var(--surface-1);
  color: var(--text);
  font-size: 12px;
  user-select: all;
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-s);
  background: var(--field-bg);
  font-size: 12px;
  text-align: center;
}

/* ---------- Menu des parametres ---------- */
.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 150;
  min-width: 248px;
  padding: 8px 0;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow-menu);
  animation: pop .14s ease-out;
}

.menu-label {
  padding: 8px 16px 4px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  height: 40px;
  padding: 0 16px;
  border: 0;
  background: none;
  font-size: 14px;
  text-align: left;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--menu-hover);
  outline: none;
}

.menu-item:disabled {
  opacity: .45;
  pointer-events: none;
}

.menu-check {
  margin-left: auto;
  visibility: hidden;
}

.menu-item[aria-checked="true"] .menu-check {
  visibility: visible;
}

.menu-sep {
  height: 1px;
  margin: 8px 0;
  background: var(--border);
}

/* ---------- Fenetre (cle API) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--backdrop);
  animation: fade .15s ease-out;
}

.modal-card {
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 24px;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow-menu);
  animation: pop .18s ease-out;
}

.modal-title {
  margin-bottom: 8px;
  font-size: 20px;
  font-weight: 700;
}

.modal-text {
  margin-bottom: 20px;
  color: var(--text-2);
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.field-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-m);
  outline: none;
  background: var(--field-bg);
  font-family: var(--font-mono);
  font-size: 14px;
}

.field-input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 1px var(--focus);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 14px;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--link);
  cursor: pointer;
}

.hint {
  margin-top: 6px;
  padding-left: 28px;
  color: var(--text-2);
  font-size: 12px;
}

.modal-tip {
  margin-top: 16px;
  padding: 10px 12px;
  border-left: 3px solid var(--info-fg);
  border-radius: var(--radius-m);
  background: var(--info-bg);
  color: var(--text-2);
  font-size: 12px;
}

.field-error {
  margin-top: 12px;
  color: var(--danger-fg);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* ---------- Messages ---------- */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-l);
  font-size: 14px;
}

.banner-info {
  border: 1px solid var(--card-border);
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.banner-error {
  border: 1px solid color-mix(in srgb, var(--danger-fg) 30%, transparent);
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.banner-text {
  flex: 1;
  min-width: 0;
}

.banner-error .btn {
  background: transparent;
  color: inherit;
  box-shadow: inset 0 0 0 1px currentColor;
}

.note {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 13px;
}

.empty-note {
  padding: 24px;
  color: var(--text-2);
  text-align: center;
}

.spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.snackbar {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 250;
  max-width: min(480px, calc(100vw - 48px));
  padding: 14px 16px;
  border-radius: var(--radius-m);
  background: var(--inverse-bg);
  color: var(--inverse-text);
  font-size: 14px;
  box-shadow: var(--shadow-menu);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .2s ease, transform .2s ease;
}

.snackbar.is-visible {
  opacity: 1;
  transform: none;
}

/* ---------- Chargement ---------- */
.skeleton {
  border-radius: var(--radius-m);
  background: linear-gradient(90deg, var(--surface-1) 0%, var(--surface-2) 50%, var(--surface-1) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.sk-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sk-thumb {
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-l);
}

.sk-line {
  height: 12px;
}

.sk-short {
  width: 60%;
}

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

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@keyframes fade {
  from { opacity: 0; }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
}
