/* The gallery: the listing table, the publishing form, the terms and the like
   and dislike buttons in the player's header. The player itself is the courses
   tab's view (courses.css, courses--player). Theme tokens only, so light and
   dark need no rules of their own. */

.gallery-root {
  width: 100%;
  height: 100%;
}

.gallery {
  display: flex;
  flex-direction: column;
  gap: var(--theme-space-5);
  width: 100%;
  padding-bottom: var(--theme-space-8);
  color: var(--theme-text-primary);
}

/* --- heading ------------------------------------------------------------ */

.gallery-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--theme-space-4);
  padding-bottom: var(--theme-space-3);
  border-bottom: 2px solid var(--theme-color-primary);
}

.gallery-heading {
  display: flex;
  flex-direction: column;
  gap: var(--theme-space-1);
  min-width: 0;
}

.gallery-title {
  margin: 0;
  font-size: var(--theme-font-lg);
  font-weight: 700;
}

.gallery-lead {
  margin: 0;
  font-size: var(--theme-font-sm);
  line-height: 1.5;
  color: var(--theme-text-secondary);
}

.gallery-publish {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-2);
  padding: 10px var(--theme-space-4);
  border: 1px solid transparent;
  border-radius: var(--theme-radius-md);
  background: var(--theme-color-primary);
  color: var(--theme-text-inverse);
  font: inherit;
  font-weight: var(--theme-font-weight-medium);
  cursor: pointer;
  transition: filter 0.15s ease;
}

.gallery-publish:hover { filter: brightness(1.08); }

.gallery-empty {
  margin: 0;
  color: var(--theme-text-secondary);
  font-size: var(--theme-font-sm);
}

/* --- table -------------------------------------------------------------- */

/* A narrow screen scrolls the table sideways rather than squeezing it. */
.gallery-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-surface-raised);
}

.gallery-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: var(--theme-font-sm);
}

.gallery-head {
  padding: var(--theme-space-2) var(--theme-space-3);
  border-bottom: 1px solid var(--theme-border-subtle);
  background: var(--theme-bg-secondary);
  text-align: start;
  white-space: nowrap;
}

.gallery-head--icon { width: 1%; }

.gallery-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-1);
  padding: 0;
  border: none;
  background: none;
  color: var(--theme-text-secondary);
  font: inherit;
  font-weight: var(--theme-font-weight-semibold);
  cursor: pointer;
}

.gallery-sort:hover,
.gallery-sort.is-sorted {
  color: var(--theme-color-primary);
}

.gallery-sort-icon {
  display: inline-flex;
  min-width: 14px;
}

.gallery-filter-cell {
  padding: var(--theme-space-2) var(--theme-space-3);
  border-bottom: 1px solid var(--theme-border-subtle);
}

.gallery-filter {
  width: 100%;
  min-width: 90px;
  padding: 6px 10px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-sm, 6px);
  background: var(--theme-surface-base, transparent);
  color: var(--theme-text-primary);
  font: inherit;
  outline: none;
}

.gallery-filter:focus { border-color: var(--theme-color-primary); }

.gallery-row { cursor: pointer; }

.gallery-row:hover { background: var(--theme-bg-secondary); }

.gallery-row--empty { cursor: default; }

.gallery-row--empty:hover { background: none; }

.gallery-row:not(:last-child) .gallery-cell {
  border-bottom: 1px solid var(--theme-border-subtle);
}

.gallery-cell {
  padding: var(--theme-space-3);
  vertical-align: middle;
}

.gallery-cell--author {
  display: flex;
  align-items: center;
  gap: var(--theme-space-2);
  min-width: 160px;
}

.gallery-author-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--theme-radius-full);
  overflow: hidden;
  background: var(--theme-bg-tertiary);
  color: var(--theme-text-secondary);
  font-size: var(--theme-font-xs);
  font-weight: var(--theme-font-weight-semibold);
}

.gallery-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-open {
  padding: 0;
  border: none;
  background: none;
  color: var(--theme-text-primary);
  font: inherit;
  font-weight: var(--theme-font-weight-semibold);
  text-align: start;
  cursor: pointer;
}

.gallery-row:hover .gallery-open { color: var(--theme-color-primary); }

.gallery-cell--date {
  color: var(--theme-text-secondary);
  white-space: nowrap;
}

.gallery-cell--number {
  text-align: end;
  white-space: nowrap;
}

.gallery-count {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-1);
  color: var(--theme-text-secondary);
  font-variant-numeric: tabular-nums;
}

.gallery-cell--icon {
  padding-inline: var(--theme-space-1);
  text-align: center;
}

.gallery-icon-link {
  display: inline-flex;
  padding: var(--theme-space-1);
  border: none;
  border-radius: var(--theme-radius-md);
  background: none;
  color: var(--theme-text-secondary);
  cursor: pointer;
}

/* Fixed to the viewport, so the table's scrolling box does not clip it;
   galleryView.js places it by its icon. */
.gallery-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 260px;
  padding: var(--theme-space-2) var(--theme-space-3);
  border-radius: var(--theme-radius-md);
  background: var(--theme-text-primary);
  color: var(--theme-text-inverse);
  font-size: var(--theme-font-xs);
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.gallery-tooltip[hidden] { display: none; }

.gallery-icon-link:hover {
  background: var(--theme-bg-tertiary);
  color: var(--theme-color-primary);
}

.gallery-open:focus-visible,
.gallery-sort:focus-visible,
.gallery-icon-link:focus-visible,
.gallery-publish:focus-visible {
  outline: 2px solid var(--theme-color-primary);
  outline-offset: 2px;
}

.gallery-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- like and dislike, in the player's header ---------------------------- */

.gallery-vote {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-1);
  flex-shrink: 0;
}

.gallery-vote-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--theme-space-2);
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-md);
  background: var(--theme-surface-raised);
  color: var(--theme-text-secondary);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.gallery-vote-button:hover,
.gallery-vote-button.is-active {
  border-color: var(--theme-color-primary);
  color: var(--theme-color-primary);
}

.gallery-vote-button:focus-visible {
  outline: 2px solid var(--theme-color-primary);
  outline-offset: 2px;
}

/* --- the publishing form -------------------------------------------------- */

.gallery-form {
  display: flex;
  flex-direction: column;
  gap: var(--theme-space-4);
}

.gallery-form-intro {
  margin: 0;
  font-size: 0.92em;
  line-height: 1.5;
  color: var(--theme-text-secondary);
}

.gallery-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gallery-form-label {
  font-size: 0.88em;
  font-weight: var(--theme-font-weight-semibold);
  color: var(--theme-text-primary);
}

.gallery-form-input {
  padding: 8px 12px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: 8px;
  background: var(--theme-surface-base, transparent);
  color: var(--theme-text-primary);
  font: inherit;
  font-size: 0.95em;
  outline: none;
  transition: border-color 0.15s ease;
}

.gallery-form-input:focus { border-color: var(--theme-color-primary); }

.gallery-form-input.is-invalid { border-color: var(--theme-color-danger, #dc2626); }

.gallery-form-help,
.gallery-form-note {
  font-size: 0.8em;
  line-height: 1.4;
  color: var(--theme-text-secondary);
}

.gallery-form-note { font-weight: var(--theme-font-weight-semibold); }

.gallery-form-error {
  font-size: 0.8em;
  line-height: 1.4;
  color: var(--theme-color-danger, #dc2626);
}

.gallery-form-error:empty { display: none; }

.gallery-form-error--form { margin: 0; }

.gallery-form-cancel,
.gallery-form-save {
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  font-size: 0.88em;
  font-weight: 500;
  cursor: pointer;
}

.gallery-form-cancel {
  background: transparent;
  color: var(--theme-text-secondary);
}

.gallery-form-save {
  background: var(--theme-color-primary);
  color: var(--theme-text-inverse, #fff);
}

/* --- the terms ------------------------------------------------------------ */

.gallery-consent {
  max-height: 60vh;
  overflow-y: auto;
  padding-inline-end: var(--theme-space-2);
  font-size: 0.92em;
  line-height: 1.55;
}

.gallery-consent h2 {
  margin: 0 0 var(--theme-space-3);
  font-size: 1.15em;
}

.gallery-consent h3 {
  margin: var(--theme-space-4) 0 var(--theme-space-1);
  font-size: 1em;
}

.gallery-consent p { margin: 0 0 var(--theme-space-2); }

@media (max-width: 720px) {
  .gallery-header { align-items: stretch; }

  .gallery-publish { justify-content: center; width: 100%; }
}
