:root {
  --blue: #3b5998;
  --blue-dark: #2d4373;
  --border: #dde1e6;
  --bg: #f4f6f8;
  --text: #1c1e21;
}

* {
  box-sizing: border-box;
}

/* Garantit que l'attribut HTML "hidden" cache toujours l'élément, même si
   une règle plus bas dans la feuille (ex. "display: flex" sur .cover-placeholder)
   a la même spécificité et gagnerait sinon la cascade (bug constaté : image
   ET placeholder visibles en même temps malgré placeholder.hidden = true). */
[hidden] {
  display: none !important;
}

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

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

nav.topbar {
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1.5rem;
}

nav.topbar > div {
  display: flex;
  align-items: center;
}

nav.topbar a {
  color: #fff;
  margin-right: 1.25rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}

nav.topbar a.brand {
  display: inline-flex;
  align-items: center;
}

nav.topbar a.brand img {
  display: block;
}

nav.topbar a:hover {
  text-decoration: underline;
}

nav.topbar form {
  display: inline;
}

nav.topbar button.link {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

main.container {
  max-width: 1350px;
  margin: 1.5rem auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem 2rem;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.auth-box {
  width: 100%;
  max-width: 360px;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-box h1 {
  margin-top: 0;
  font-size: 1.4rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.field {
  position: relative;
}

.field-hint {
  font-size: 0.8rem;
  color: #666;
  margin-top: 0.25rem;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-field input[type="checkbox"] {
  width: auto;
}

.autocomplete-list {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 2px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.autocomplete-item {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--bg);
}

.field input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}

button.primary {
  width: 100%;
  padding: 0.6rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
}

button.primary:hover {
  background: var(--blue-dark);
}

.error {
  background: #fdecea;
  color: #a4262c;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.auth-links {
  margin-top: 1rem;
  font-size: 0.9rem;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--blue);
  color: #fff;
}

.alphabet {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.alphabet a, .alphabet span {
  padding: 0.15rem 0.4rem;
}

.alphabet .current {
  background: var(--bg);
  border-radius: 4px;
  font-weight: bold;
}

.folder-columns {
  columns: 4;
  column-gap: 2rem;
}

.folder-columns li {
  break-inside: avoid;
}

.actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.actions-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-form input[type="search"] {
  width: 9rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
}

.search-form input[type="search"]:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
}

.search-summary {
  color: #666;
}

.search-results {
  margin: 0 0 1.5rem;
  padding-left: 1.25rem;
}

.search-results li {
  margin-bottom: 0.4rem;
}

.search-meta {
  color: #666;
  font-size: 0.9rem;
}

.search-meta a {
  color: inherit;
}

.btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}

.btn:hover {
  background: var(--blue-dark);
  text-decoration: none;
}

.btn.danger {
  background: #a4262c;
}

.btn.secondary {
  background: #6c757d;
}

.breadcrumb {
  color: #666;
  margin-bottom: 1rem;
}

.folder-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.folder-table-col {
  flex: 1 1 55%;
  min-width: 0;
}

.folder-cover-col {
  flex: 1 1 45%;
  min-width: 0;
  position: relative;
  /* Réserve toujours au moins la hauteur max d'une grande couverture
     (.cover-focus-img) : sans ça, sur un dossier avec peu d'items (galerie
     courte), la couverture flottante dépasserait le bas de la page et ferait
     apparaître/disparaître une scrollbar au survol. */
  min-height: 640px;
  /* Aligne le haut de la galerie sur la 2e ligne du tableau (sous l'entête),
     dont la hauteur est fixe (padding + une seule ligne de texte). */
  margin-top: 2.4rem;
}

@media (max-width: 700px) {
  .folder-layout {
    flex-direction: column;
  }
}

.items-table th:first-child,
.items-table td:first-child {
  width: 3rem;
}

.items-table th.col-bedetheque,
.items-table td.col-bedetheque,
.items-table th.col-status,
.items-table td.col-status {
  width: 1.5rem;
}

.items-table th.col-owners,
.items-table td.col-owners {
  /* 2 badges (1.4rem) + le gap entre eux (0.25rem) : assez pour au plus
     2 badges cote a cote, au-dela ils passeraient a la ligne. */
  width: calc(2 * 1.4rem + 0.25rem);
  white-space: nowrap;
}

.owner-badges {
  display: flex;
  gap: 0.25rem;
}

.owner-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  color: var(--blue);
  background: none;
  border: 1px solid var(--border);
  padding: 0;
}

.owner-badge.owned {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

button.owner-badge-self {
  cursor: pointer;
}

button.owner-badge-self:hover {
  border-color: var(--blue);
}

button.owner-badge-self.owned:hover {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.icon-status-btn {
  display: inline-flex;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #b0b5bb;
}

.icon-status-btn:hover {
  color: #8a9099;
}

.icon-status-btn.has-status {
  color: var(--blue);
}

.icon-status-btn.has-status:hover {
  color: var(--blue-dark);
}

.icon-status-btn .icon-filled {
  display: none;
}

.icon-status-btn.has-status .icon-outline {
  display: none;
}

.icon-status-btn.has-status .icon-filled {
  display: inline;
}

.icon-status-remove-btn {
  display: inline-flex;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #b0b5bb;
}

.icon-status-remove-btn:hover {
  color: #c0392b;
}

.status-dialog {
  border: none;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  min-width: 280px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.status-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.status-dialog select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.status-dialog .dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.icon-bedetheque-link {
  display: inline-flex;
  color: inherit;
  opacity: 0.6;
}

.icon-bedetheque-link:hover {
  opacity: 1;
}

.topbar-account {
  gap: 1rem;
}

.item-edit-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.item-form-col {
  flex: 1 1 45%;
  min-width: 0;
}

.item-cover-col {
  flex: 1 1 55%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.cover-full {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.item-cover-col .field-hint {
  margin-top: 0.75rem;
}

.item-actions-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

@media (max-width: 700px) {
  .item-edit-layout {
    flex-direction: column;
  }
}

.discreet-link {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: #666;
}

.item-authors {
  color: #555;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.item-authors a {
  color: inherit;
}

.cover-gallery {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.cover-thumb {
  width: 96px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.cover-thumb-placeholder {
  background: var(--bg);
  border: 1px dashed var(--border);
  box-shadow: none;
}

.recent-items {
  display: flex;
  flex-wrap: nowrap;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  margin-bottom: 0.5rem;
}

.recent-item {
  flex: 0 0 auto;
  width: 96px;
  color: inherit;
  text-decoration: none;
}

.recent-item:hover {
  text-decoration: none;
}

.recent-item:hover .cover-thumb {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.recent-item-folder {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-item-title {
  font-size: 0.75rem;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cover-focus {
  position: absolute;
  left: 0;
  right: 0;
  /* top fixé dynamiquement par cover-gallery.js, à la hauteur de la ligne
     survolée : la galerie reste affichée en permanence, la couverture flotte
     par-dessus au survol sans jamais affecter la mise en page. */
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.cover-focus-img {
  display: block;
  max-width: 480px;
  max-height: 640px;
  width: auto;
  height: auto;
  padding: 16px;
  border-radius: 4px;
  background: #fff;
  /* Épouse les bords réels de l'image (pas d'aspect-ratio forcé + object-fit :
     ça créait un cadre en "letterbox" avec un espace entre l'ombre et le
     visuel pour les couvertures dont le ratio diffère legèrement de 2/3). Le
     padding blanc forme un cadre autour de la couverture, l'ombre porte sur
     ce cadre (border-box) et non sur l'image seule. */
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.icon-refresh {
  vertical-align: -2px;
  margin-right: 4px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: #333;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -2px;
  animation: cover-refresh-spin 0.8s linear infinite;
}

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