/*
 * app.css – PDB single-page application styles.
 *
 * Structure:
 *   1. Design tokens (light / dark / system themes)
 *   2. Base & typography
 *   3. Layout (top bar, main, footer)
 *   4. Controls (buttons, inputs, chips, badges, switches)
 *   5. Gallery (filters, cards, grid)
 *   6. Item detail
 *   7. Upload
 *   8. Account / admin / auth
 *   9. Feedback (toasts, dialogs, empty states, skeletons)
 *  10. Utilities & motion preferences
 *
 * Themes: <html data-theme="light|dark|system"> (set by js/theme.js).
 * All colours are custom properties; contrast pairs were chosen to meet
 * WCAG AA (4.5:1 for text) in both themes.
 */

/* ------------------------------------------------------------------ */
/* 1. Design tokens                                                    */
/* ------------------------------------------------------------------ */

:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e5e8ee;
  --text: #1b1f24;
  --text-muted: #545d6a;
  --border: #d9dde4;
  --border-strong: #aeb5c1;
  --accent: #3451d1;
  --accent-hover: #2940b0;
  --accent-contrast: #ffffff;
  --accent-soft: #e8ecfc;
  --accent-soft-text: #263b9e;
  --danger: #c0262d;
  --danger-hover: #a01f25;
  --danger-contrast: #ffffff;
  --danger-soft: #fdecec;
  --danger-soft-text: #9b1c22;
  --success: #1d7a46;
  --success-soft: #e3f4ea;
  --success-soft-text: #17623a;
  --warn-soft: #fff1d1;
  --warn-soft-text: #7a4f00;
  --focus: #3451d1;
  --overlay: rgba(14, 17, 22, 0.55);
  --media-bg: #e5e8ee;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10), 0 2px 4px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.18);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", "Liberation Sans", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --header-h: 64px;
  --sidebar-w: 288px;
  --page-max: 1480px;
  --measure: 70ch;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

/* Dark tokens, applied explicitly ... */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #161a21;
  --surface-2: #1d222b;
  --surface-3: #272d38;
  --text: #e7eaf0;
  --text-muted: #a3abb9;
  --border: #2c323d;
  --border-strong: #464f5e;
  --accent: #8ea3ff;
  --accent-hover: #a9b8ff;
  --accent-contrast: #0e1116;
  --accent-soft: #222a49;
  --accent-soft-text: #c5cfff;
  --danger: #ff8a8a;
  --danger-hover: #ffa3a3;
  --danger-contrast: #1a0b0c;
  --danger-soft: #3b1719;
  --danger-soft-text: #ffc2c2;
  --success: #62d398;
  --success-soft: #11301f;
  --success-soft-text: #a6ecc5;
  --warn-soft: #3a2e10;
  --warn-soft-text: #f5d37f;
  --focus: #a9b8ff;
  --overlay: rgba(0, 0, 0, 0.65);
  --media-bg: #0a0c10;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.6);
}

/* ... and when "system" is selected and the OS prefers dark. */
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --surface-3: #272d38;
    --text: #e7eaf0;
    --text-muted: #a3abb9;
    --border: #2c323d;
    --border-strong: #464f5e;
    --accent: #8ea3ff;
    --accent-hover: #a9b8ff;
    --accent-contrast: #0e1116;
    --accent-soft: #222a49;
    --accent-soft-text: #c5cfff;
    --danger: #ff8a8a;
    --danger-hover: #ffa3a3;
    --danger-contrast: #1a0b0c;
    --danger-soft: #3b1719;
    --danger-soft-text: #ffc2c2;
    --success: #62d398;
    --success-soft: #11301f;
    --success-soft-text: #a6ecc5;
    --warn-soft: #3a2e10;
    --warn-soft-text: #f5d37f;
    --focus: #a9b8ff;
    --overlay: rgba(0, 0, 0, 0.65);
    --media-bg: #0a0c10;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.6);
  }
}

/* ------------------------------------------------------------------ */
/* 2. Base & typography                                                */
/* ------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.no-scroll {
  overflow: hidden;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5em;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.85rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

p {
  margin: 0 0 0.75em;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent-hover);
}

img,
video {
  max-width: 100%;
}

code,
pre,
kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* ------------------------------------------------------------------ */
/* 3. Layout                                                           */
/* ------------------------------------------------------------------ */

.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  z-index: 100;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.5rem;
  color: var(--accent-contrast);
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

.topbar-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "brand . actions"
    "search search search"
    "nav nav nav";
  align-items: center;
  gap: 0.6rem 0.75rem;
}

.brand {
  grid-area: brand;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

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

.brand-mark rect {
  fill: var(--accent);
  stroke: none;
}

.brand-mark path {
  stroke: var(--accent-contrast);
  stroke-width: 2.4;
}

.brand-sub {
  display: none;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0;
}

.main-nav {
  grid-area: nav;
  min-width: 0;
}

.nav-list {
  display: flex;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-list::-webkit-scrollbar {
  display: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 550;
  font-size: 0.95rem;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.nav-link .icon {
  flex: none;
}

.search {
  grid-area: search;
  position: relative;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search .input {
  padding-left: 2.3rem;
  border-radius: 999px;
  background: var(--surface-2);
}

.top-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.account {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.account-btn .account-name {
  max-width: 12ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 13rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}

.menu-head {
  padding: 0.5rem 0.65rem 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.3rem;
  overflow-wrap: anywhere;
}

.menu-head strong {
  color: var(--text);
}

.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

@media (max-width: 479px) {
  .account-btn .account-name,
  .account-btn .chevron {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (min-width: 640px) {
  .topbar-inner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand search actions"
      "nav nav nav";
  }
}

@media (min-width: 1080px) {
  .topbar {
    position: sticky;
    top: 0;
  }

  .topbar-inner {
    min-height: var(--header-h);
    grid-template-columns: auto auto minmax(12rem, 1fr) auto;
    grid-template-areas: "brand nav search actions";
    gap: 1rem;
  }

  .search {
    max-width: 30rem;
    justify-self: end;
    width: 100%;
  }

  .brand-sub {
    display: inline;
  }
}

.main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.main:focus {
  outline: none;
}

@media (min-width: 640px) {
  .main {
    padding: 1.75rem 1.5rem 4rem;
  }
}

.footer {
  border-top: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer p {
  margin: 0;
}

.page-narrow {
  max-width: 52rem;
  margin: 0 auto;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  margin: 0;
}

.page-sub {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  max-width: var(--measure);
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .section {
    padding: 1.5rem;
  }
}

.section > h2 {
  margin-bottom: 0.25rem;
}

.section-sub {
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  max-width: var(--measure);
}

/* ------------------------------------------------------------------ */
/* 4. Controls                                                         */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 560;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease);
}

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

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

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

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-contrast);
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: var(--danger-contrast);
}

.btn-danger-outline {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger-soft);
  color: var(--danger-soft-text);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-sm {
  min-height: 2rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

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

.icon-btn-sm {
  width: 2rem;
  height: 2rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.icon {
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

/* Form fields */

.form {
  display: grid;
  gap: 1rem;
}

.form-narrow {
  max-width: 28rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.field-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.field-help {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.field-error,
.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 550;
}

.form-error {
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger-soft-text);
}


.input,
.select,
textarea.input {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
}

textarea.input {
  resize: vertical;
  min-height: 4.5rem;
}

.input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.input:focus-visible,
.select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.input-file {
  font: inherit;
  font-size: 0.9rem;
  max-width: 100%;
  color: var(--text-muted);
}

.fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.fieldset > legend {
  padding: 0;
  margin-bottom: 0.6rem;
  font-weight: 650;
}

/* Checkbox styled as a switch; still a native checkbox for a11y. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  font-weight: 550;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 2.6rem;
  height: 1.5rem;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}

.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s var(--ease), background-color 0.15s var(--ease);
}

.switch input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked::after {
  transform: translateX(1.1rem);
  background: var(--accent-contrast);
}

.switch input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Segmented radio group (theme picker) */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 550;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.segmented label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented label:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

/* Full-width variant with equal segments (gallery "Media type"). */
.segmented-fill {
  display: flex;
  flex-wrap: nowrap;
}

.segmented-fill label {
  flex: 1 1 0;
  justify-content: center;
  min-width: 0;
  padding-inline: 0.5rem;
}

/* Small variant for toolbars (gallery "Groups"). */
.segmented-compact {
  flex-wrap: nowrap;
  padding: 0.15rem;
}

.segmented-compact label {
  padding: 0.3rem 0.6rem;
  font-size: 0.88rem;
}

/* Tag chip editor */
.chip-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.5rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: text;
}

.chip-input:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}

.chip-input-field {
  flex: 1 1 8rem;
  min-width: 6rem;
  border: 0;
  outline: 0;
  padding: 0.3rem 0.3rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

.chip-input-field::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.chip-list {
  display: contents;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  max-width: 100%;
  padding: 0.15rem 0.2rem 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-size: 0.875rem;
  font-weight: 560;
  line-height: 1.4;
}

.chip-text {
  overflow-wrap: anywhere;
}

.chip-input-exclude .chip {
  background: var(--danger-soft);
  color: var(--danger-soft-text);
}

.chip-input-exclude .chip-text {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.chip-remove:hover {
  background: rgba(127, 127, 127, 0.22);
}

/* Read-only tag pills (cards, detail) */
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 540;
  line-height: 1.45;
  text-decoration: none;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent-soft-text);
  background: var(--accent-soft);
}

.tag-lg {
  font-size: 0.9rem;
  padding: 0.25rem 0.75rem;
}

.tag-more {
  font-size: 0.8rem;
  color: var(--text-muted);
  align-self: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.4;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn-soft-text);
}

.badge-info {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.badge-ok {
  background: var(--success-soft);
  color: var(--success-soft-text);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-soft-text);
}

.callout {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  max-width: var(--measure);
}

.callout p {
  margin: 0;
}

.callout-warn {
  background: var(--warn-soft);
  color: var(--warn-soft-text);
}

/* ------------------------------------------------------------------ */
/* 5. Gallery                                                          */
/* ------------------------------------------------------------------ */

.gallery-layout {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}

@media (min-width: 960px) {
  .gallery-layout {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
}

.gallery-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.gallery-title h1 {
  margin: 0;
}

.result-count {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

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

.sort-field .select {
  width: auto;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  padding: 0.2rem 0.3rem 0.2rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.filter-pill .chip-remove {
  color: var(--text-muted);
}

/* Filter panel: sidebar on desktop that grows with its content (never
 * an inner scrollbar; it scrolls with the page), drawer on mobile. */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem 0.5rem;
}

.filter-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.filter-head h2:focus {
  outline: none;
}

.filter-body {
  display: grid;
  gap: 1.1rem;
  padding: 0.5rem 1rem 1rem;
}

/* Saved filters (components/saved-filters.js), last in the filter
 * body: the save button / inline name form, then the list. */
.saved-filters {
  display: grid;
  gap: 0.6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.saved-save {
  justify-self: start;
}

.saved-form {
  display: grid;
  gap: 0.4rem;
}

.saved-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.saved-head {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.saved-list {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.saved-item {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

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

.saved-item.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.saved-apply {
  display: grid;
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.saved-apply:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.saved-name {
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-summary {
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-item.is-active .saved-name {
  color: var(--accent-soft-text);
}

.saved-delete {
  flex: none;
  color: var(--text-muted);
}

.filter-foot {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

.filter-foot .btn {
  flex: 1;
}

.filter-close,
.filter-apply,
.filter-collapse,
.filter-rail {
  display: none;
}

.filter-toggle .count,
.filter-rail .count {
  min-width: 1.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.75rem;
  line-height: 1.4rem;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 70;
}

@media (max-width: 959px) {
  .filter-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 80;
    width: min(22rem, 100vw - 2.5rem);
    display: flex;
    flex-direction: column;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    box-shadow: var(--shadow-lg);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.22s var(--ease), visibility 0s linear 0.22s;
  }

  .filter-panel.is-open {
    transform: none;
    visibility: visible;
    transition: transform 0.22s var(--ease);
  }

  .filter-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .filter-close,
  .filter-apply {
    display: inline-flex;
  }
}

@media (min-width: 960px) {
  /* Only the collapsed rail (always short) stays in view. */
  .filters-collapsed .filter-panel {
    position: sticky;
    top: calc(var(--header-h) + 1rem);
  }

  /* Collapsible sidebar: the grid column animates between the full
   * sidebar width and a slim rail holding the expand button. */
  .gallery-layout {
    transition: grid-template-columns 0.25s var(--ease);
  }

  .gallery-layout.filters-collapsed {
    grid-template-columns: 3rem minmax(0, 1fr);
  }

  .filter-collapse {
    display: inline-flex;
    margin-left: auto;
  }

  .filters-collapsed .filter-panel {
    overflow: hidden;
  }

  .filters-collapsed .filter-head,
  .filters-collapsed .filter-body,
  .filters-collapsed .filter-foot {
    display: none;
  }

  .filters-collapsed .filter-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.75rem 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: none;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
  }

  .filters-collapsed .filter-rail:hover {
    color: var(--accent);
    background: var(--surface-2);
  }

  .filters-collapsed .filter-rail:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
  }

  .filter-toggle,
  .drawer-backdrop {
    display: none !important;
  }
}

@media (min-width: 960px) and (max-width: 1079px) {
  .filters-collapsed .filter-panel {
    top: 1rem;
  }
}

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1rem;
  }
}

.card-cell {
  min-width: 0;
  display: flex;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-media-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--media-bg);
}

/* Pinned to the square box: the thumbnail's own proportions must not
 * grow it, so every card in a row has the same height. */
.card-media {
  position: absolute;
  inset: 0;
  display: block;
}

.card-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Stacks (gallery "Groups: Stacks"): the group's cover in front, up
 * to two more members fanned out behind it like a loose pile of
 * prints. The square box stays; the cover is inset to make room.
 * isolation keeps the layers below the card's stretched link. */
.card-media-wrap.is-stack {
  isolation: isolate;
  background: var(--surface-2);
}

.card-media-wrap.is-stack .card-media,
.stack-layer {
  inset: 13% 11% 7%;
  overflow: hidden;
  border: 3px solid var(--surface);
  border-radius: var(--radius-sm);
  background: var(--media-bg);
}

.card-media-wrap.is-stack .card-media {
  z-index: 3;
  box-shadow: var(--shadow-md);
}

.stack-layer {
  position: absolute;
  box-shadow: var(--shadow-sm);
  transform-origin: 50% 90%;
  transition: transform 0.2s var(--ease);
}

/* First preview: right behind the cover, tilted right. */
.stack-layer-1 {
  z-index: 2;
  transform: translate(5%, -4%) rotate(4deg);
}

/* Second preview: further back, tilted left. */
.stack-layer-2 {
  z-index: 1;
  transform: translate(-5%, -6%) rotate(-5deg);
}

.stack-layer .card-thumb {
  filter: brightness(0.88);
}

.stack-layer-2 .card-thumb {
  filter: brightness(0.76);
}

/* A video member without a thumbnail: a plain sheet with a play mark. */
.stack-blank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--text-muted);
  background: var(--surface-2);
}

.card:hover .stack-layer-1 {
  transform: translate(8%, -5%) rotate(7deg);
}

.card:hover .stack-layer-2 {
  transform: translate(-8%, -7%) rotate(-9deg);
}

.card-media-wrap.is-stack .card-badges,
.card-media-wrap.is-stack .play-badge {
  z-index: 4;
}

@media (prefers-reduced-motion: reduce) {
  .stack-layer {
    transition: none;
  }

  .card:hover .stack-layer-1 {
    transform: translate(5%, -4%) rotate(4deg);
  }

  .card:hover .stack-layer-2 {
    transform: translate(-5%, -6%) rotate(-5deg);
  }
}

.card-badges {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  right: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  pointer-events: none;
}

.card-badges .badge {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.play-badge {
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(10, 12, 16, 0.78);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* Video hover preview / scrub bar (card.js attachScrub). --scrub is
 * the position as a fraction (0..1). Decoration only: clicks pass
 * through to the card link. */
.scrub {
  position: absolute;
  inset: auto 0 0 0;
  height: 2.75rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}

.card-media-wrap.is-previewing .scrub {
  opacity: 1;
}

.card-media-wrap.is-scrubbing .scrub {
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
}

.scrub-track {
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: 0.55rem;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
  transition: height 0.12s var(--ease);
}

.scrub-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--scrub, 0) * 100%);
  border-radius: inherit;
  background: #ffffff;
}

.scrub-handle {
  position: absolute;
  top: 50%;
  left: calc(var(--scrub, 0) * 100%);
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  opacity: 0;
}

/* Kept inside the track at the ends. */
.scrub-time {
  position: absolute;
  bottom: 12px;
  left: clamp(1.4rem, calc(var(--scrub, 0) * 100%), calc(100% - 1.4rem));
  transform: translateX(-50%);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: rgba(10, 12, 16, 0.78);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
}

.card-media-wrap.is-scrubbing .scrub-track {
  height: 5px;
}

.card-media-wrap.is-scrubbing .scrub-handle,
.card-media-wrap.is-scrubbing .scrub-time {
  opacity: 1;
}

.play-badge {
  transition: opacity 0.15s var(--ease);
}

.card-media-wrap.is-previewing .play-badge {
  opacity: 0;
}

.card-body {
  display: grid;
  gap: 0.35rem;
  padding: 0.65rem 0.75rem 0.8rem;
  min-width: 0;
}

.card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 620;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-title a {
  color: var(--text);
  text-decoration: none;
}

/* Whole card clickable via the title link's pseudo-element. */
.card-title a::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.card-title a:focus-visible {
  outline: none;
}

.card:has(.card-title a:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.card-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Card tags: a single line. card.js hides the tags that do not fit
 * and shows "+N" instead, so all card bodies have the same height.
 * Tag buttons sit above the stretched title link. */
.card .tag-row {
  position: relative;
  z-index: 2;
  flex-wrap: nowrap;
  gap: 0.25rem;
  overflow: hidden;
}

.card .tag-row > li {
  flex: none;
  min-width: 0;
}

/* When only one tag remains and it is wider than the card, it is
 * shortened with an ellipsis (class set by card.js). */
.card .tag-row.is-single > li:first-child {
  flex: 0 1 auto;
}

.card .tag {
  display: block;
  max-width: 100%;
  padding: 0.1rem 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow-wrap: normal;
}

.card .tag-more {
  padding-left: 0.1rem;
}

.load-more {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}

/* ------------------------------------------------------------------ */
/* 6. Item detail                                                      */
/* ------------------------------------------------------------------ */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-weight: 550;
  text-decoration: none;
}

.back-link .icon {
  transform: rotate(90deg);
}

.detail-layout {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}

/* One column (narrow screens): media, then the side panel (title,
 * group strip, actions...), then the generation metadata - so the
 * strip is not pushed below a long metadata section. */
@media (max-width: 999px) {
  .detail-layout > .stack {
    display: contents;
  }

  .detail-layout .detail-media-wrap {
    order: 1;
  }

  .detail-layout .detail-side {
    order: 2;
  }

  .detail-layout > .stack > :not(.detail-media-wrap) {
    order: 3;
  }
}

@media (min-width: 1000px) {
  .detail-layout {
    grid-template-columns: minmax(0, 1.6fr) minmax(20rem, 1fr);
  }

  .detail-side {
    position: sticky;
    top: calc(var(--header-h) + 1rem);
  }
}

.detail-media-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--media-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 12rem;
}

.detail-media {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

video.detail-media {
  width: 100%;
}

.detail-title {
  margin-bottom: 0.35rem;
  overflow-wrap: anywhere;
}

.byline {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.description {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: var(--measure);
}

.facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.4rem 1rem;
  margin: 0;
  font-size: 0.92rem;
}

.facts dt {
  color: var(--text-muted);
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.side-block + .side-block {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.download-note {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.side-block h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.meta-list {
  display: grid;
  gap: 0.9rem;
  margin: 0;
}

.meta-row {
  display: grid;
  gap: 0.3rem;
}

.meta-row dt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 620;
  font-size: 0.9rem;
}

.meta-row dd {
  margin: 0;
}

.meta-value {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 22rem;
  overflow-y: auto;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr));
  gap: 0.9rem;
}

.meta-grid > legend {
  grid-column: 1 / -1;
}

.meta-grid .field-wide {
  grid-column: 1 / -1;
}

.edit-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ------------------------------------------------------------------ */
/* 7. Upload                                                           */
/* ------------------------------------------------------------------ */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.dropzone .icon {
  color: var(--accent);
}

.dropzone-hint {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.queue {
  display: grid;
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.queue-item {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

@media (min-width: 720px) {
  .queue-item {
    grid-template-columns: 9.5rem minmax(0, 1fr);
  }
}

.queue-preview {
  position: relative;
  aspect-ratio: 1 / 1;
  max-width: 9.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--media-bg);
}

.queue-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.queue-main {
  display: grid;
  gap: 0.85rem;
  min-width: 0;
}

.queue-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.queue-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 620;
  overflow-wrap: anywhere;
}

.queue-sub {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.queue-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.queue-status .status-text {
  color: var(--text-muted);
}

.queue-status .status-error {
  color: var(--danger);
  font-weight: 550;
}

.progress {
  width: 100%;
  height: 0.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
}

.progress::-webkit-progress-bar {
  background: var(--surface-3);
  border-radius: 999px;
}

.progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
}

.progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

.disclosure > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.25rem 0;
  color: var(--accent);
}

.disclosure[open] > summary {
  margin-bottom: 0.75rem;
}

.upload-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.upload-bar p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/* 8. Account / admin / auth                                           */
/* ------------------------------------------------------------------ */

.auth-card {
  max-width: 26rem;
  margin: 1.5rem auto;
  padding: 1.75rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.auth-card h1 {
  margin-bottom: 0.25rem;
}

.auth-alt {
  margin: 1.25rem 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.user-list {
  display: grid;
  gap: 0.85rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

/* ---- admin: tag list ---------------------------------------- */

.tag-admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.tag-admin-toolbar .field {
  flex: 1 1 14rem;
  margin: 0;
}

.tag-admin-list {
  list-style: none;
  margin: 0.5rem 0 1rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.tag-admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--border);
}

.tag-admin-row:first-child {
  border-top: 0;
}

.tag-admin-row.is-restricted {
  background: var(--warn-soft);
}

.tag-admin-row-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tag-admin-row-name {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tag-admin-row.is-restricted .tag-admin-row-name {
  color: var(--warn-soft-text);
}

.tag-admin-row-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tag-admin-row.is-restricted .tag-admin-row-meta {
  color: var(--warn-soft-text);
}

.tag-admin-row .switch {
  flex: none;
  font-size: 0.9rem;
}

.tag-admin-row-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
}

.tag-admin-row-empty {
  padding: 1rem;
  color: var(--text-muted);
}

/* ---- admin: white-list toggle chips --------------------------- */

.wl-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.wl-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 560;
  cursor: pointer;
}

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

.wl-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.wl-chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.wl-chip:disabled {
  opacity: 0.6;
  cursor: progress;
}

@media (max-width: 480px) {
  .tag-admin-row {
    padding: 0.6rem 0.75rem;
  }
}

.user-card {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.user-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.user-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.user-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.user-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.inline-form .field {
  flex: 1 1 14rem;
}

.settings-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
}

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.5rem 1.25rem;
  margin: 0;
}

.kv dt {
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ */
/* 9. Feedback                                                         */
/* ------------------------------------------------------------------ */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  width: min(26rem, 100%);
  padding: 0.75rem 0.5rem 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 0.2s var(--ease);
}

.toast > .icon {
  margin-top: 0.1rem;
  color: var(--accent);
}

.toast-success {
  border-left-color: var(--success);
}

.toast-success > .icon {
  color: var(--success);
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-error > .icon {
  color: var(--danger);
}

.toast-msg {
  flex: 1;
  margin: 0;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

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

.dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background: var(--overlay);
}

.dialog-title {
  font-size: 1.15rem;
}

.dialog-msg {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

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

/* ---- share dialog and shared page ------------------------------ */

.share-dialog {
  width: min(34rem, calc(100vw - 2rem));
}

.share-msg {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.share-link {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.share-url {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.share-create {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.share-created {
  margin-top: 1rem;
}

.share-list-head {
  margin: 1.25rem 0 0.25rem;
  font-size: 0.95rem;
}

.share-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.share-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.share-expiry {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.5rem 0 0;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn-soft-text);
  font-size: 0.85rem;
}

.share-facts {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 3rem 1rem;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.empty-state .icon {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.empty-title {
  font-size: 1.15rem;
  margin: 0;
}

.empty-text {
  max-width: 46ch;
  color: var(--text-muted);
  margin: 0.25rem 0 0.75rem;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.skeleton-thumb {
  aspect-ratio: 1 / 1;
  border-radius: 0;
}

.skeleton-line {
  height: 0.8rem;
}

.skeleton-line.short {
  width: 60%;
}

.skeleton-block {
  min-height: 20rem;
  border-radius: var(--radius-lg);
}

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

.clipboard-helper {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

/* ------------------------------------------------------------------ */
/* 10. Utilities & motion                                              */
/* ------------------------------------------------------------------ */

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

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

.mt-1 {
  margin-top: 1rem;
}

.stack {
  display: grid;
  gap: 1rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .chip,
  .badge,
  .tag {
    border: 1px solid CanvasText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-layout {
    transition: none;
  }
}

/* ------------------------------------------------------------------ */
/* Groups: card badge, selection mode, filmstrip, owner block          */
/* ------------------------------------------------------------------ */

.badge-group {
  background: rgba(10, 12, 16, 0.78);
  color: #ffffff;
}

/* Selection mode on the user's own page (gallery.js). The checkbox
 * sits above the stretched title link; a click anywhere on the card
 * toggles it. */
.select-box {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 3;
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.card-grid.is-selecting .card {
  cursor: pointer;
}

.card-grid.is-selecting .card-cell.is-selected .card {
  outline: 3px solid var(--accent);
  outline-offset: -1px;
}

.card-grid.is-selecting .card-cell.is-selected .card-thumb {
  opacity: 0.85;
}

.select-bar {
  position: sticky;
  bottom: 1rem;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.select-count {
  margin: 0;
  font-weight: 600;
}

/* Filmstrip in the item page's side panel, under the title block
 * (filmstrip.js; a side-block like its neighbours). */
.filmstrip {
  display: grid;
  gap: 0.5rem;
}

.side-block h2.strip-title {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
}

.strip-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.strip-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  margin: 0;
  font-size: 0.95rem;
}

.strip-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strip-pos {
  flex: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.strip-navs {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.strip-nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.strip-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.strip-list {
  display: flex;
  gap: 0.4rem;
  margin: 0;
  padding: 3px;
  list-style: none;
}

.strip-list > li {
  flex: none;
}

.strip-link {
  position: relative;
  display: block;
  width: 4.5rem;
  height: 4.5rem;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--media-bg);
  opacity: 0.7;
  transition: opacity 0.15s var(--ease);
}

.strip-link:hover,
.strip-link:focus-visible {
  opacity: 1;
}

.strip-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.strip-link[aria-current] {
  opacity: 1;
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.strip-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.strip-video {
  position: absolute;
  right: 0.2rem;
  bottom: 0.2rem;
  display: inline-flex;
  padding: 0.15rem;
  border-radius: 999px;
  background: rgba(10, 12, 16, 0.78);
  color: #ffffff;
}

/* Owner's "Group" block on the item page. */
.group-title-row {
  display: flex;
  gap: 0.4rem;
}

.group-title-row .input {
  flex: 1;
  min-width: 0;
}

.suggest-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 11rem;
  margin: 0.5rem 0;
  padding: 3px;
  overflow-y: auto;
  list-style: none;
}

.suggest {
  position: relative;
  display: block;
  width: 3.5rem;
  height: 3.5rem;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--media-bg);
  cursor: pointer;
}

.suggest input {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  z-index: 1;
  margin: 0;
  accent-color: var(--accent);
}

.suggest-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.suggest:has(input:not(:checked)) .suggest-thumb {
  opacity: 0.4;
}

.suggest:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

/* Item page: the media of the next group member fades in when the
 * page switches in place (item.js showInPlace). */
.detail-media.media-swap {
  animation: media-swap 0.18s var(--ease);
}

@keyframes media-swap {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

/* Custom upload-date range under the "Uploaded" select (gallery.js). */
.date-range {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.date-range .field {
  gap: 0.25rem;
}

/* "Delete all N items" sits apart from the reversible group actions. */
.group-danger {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.strip-downloads {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* "Share the whole group" (item page, owner's Group block). */
.group-share > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.group-share[open] > summary {
  margin-bottom: 0.6rem;
}

.share-member-title {
  margin: 0 0 0.3rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}
