:root {
  color-scheme: light;
  --bg: #f6f4f1;
  --surface: #ffffff;
  --border: #d8d2c8;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --accent: #1f4d3a;
  --accent-hover: #163828;
  --accent-fg: #f4faf7;
  --error: #b42318;
  --ok: #1f7a4d;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #e4ebe6 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

button:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

button.secondary:hover {
  background: var(--bg);
}

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

.nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

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

.nav a.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-right: auto;
}

.nav-logout {
  margin-left: auto;
}

.content {
  padding: 1.5rem;
  max-width: 1100px;
}

.content--wide {
  max-width: none;
  padding: 1.5rem 2rem;
}

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  box-shadow: 0 12px 40px rgba(26, 26, 26, 0.06);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  letter-spacing: -0.03em;
}

.login-card label,
.form-card label {
  display: block;
  margin-bottom: 1rem;
}

label:has(> input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.login-card input:not([type="checkbox"]),
.form-card input:not([type="checkbox"]),
.form-card textarea,
.form-card select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

input[type="checkbox"] {
  width: auto;
  margin: 0;
}

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

.page-header h1 {
  margin: 0;
  letter-spacing: -0.03em;
}

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

.error,
.flash-error {
  color: var(--error);
}

.flash-ok {
  color: var(--ok);
  padding: 0.5rem 0;
}

.inline-form {
  display: inline;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0 1.75rem;
}

.stat {
  min-width: 8rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  background: color-mix(in srgb, var(--bg) 70%, var(--surface));
}

.data-table tr:last-child td {
  border-bottom: none;
}

code {
  font-size: 0.9em;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.button-link {
  display: inline-block;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: var(--accent-fg);
  text-decoration: none;
  border-radius: 6px;
  font-weight: 600;
}

.button-link.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

.filter-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.filter-form input[type="search"] {
  flex: 1;
  max-width: 28rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  background: var(--border);
  flex-shrink: 0;
}

.thumb--empty {
  display: inline-block;
}

/* Profiles 3-pane workspace */
.profiles-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 500px) minmax(320px, 1fr);
  gap: 1rem;
  align-items: stretch;
  min-height: calc(100vh - 5.5rem);
}

.profiles-list-pane,
.profiles-gallery-pane,
.profiles-edit-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 0;
}

.profiles-list-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.profiles-list-head {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 0.4rem;
}

.profiles-search input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.profile-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.profile-list-empty {
  padding: 1rem 0.75rem;
}

.profile-list-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
}

.profile-list-row:hover {
  background: var(--bg);
}

.profile-list-row.is-active {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: inset 3px 0 0 var(--accent);
}

.profile-list-meta {
  min-width: 0;
  flex: 1;
  display: grid;
}

.profile-list-name {
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-list-count {
  flex-shrink: 0;
}

.profiles-gallery-pane {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow: auto;
}

.profiles-empty {
  display: grid;
  place-items: center;
  min-height: 16rem;
}

.profile-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.profile-nav-title {
  display: grid;
  text-align: center;
  min-width: 0;
}

.profile-nav-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-link.small {
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
}

.button-link.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

.profile-main {
  display: grid;
  gap: 0.65rem;
}

.profile-main > img {
  display: block;
  width: 100%;
  max-height: min(58vh, 520px);
  height: auto;
  object-fit: contain;
  object-position: center;
  border-radius: 8px;
  background: var(--bg);
}

.profile-main-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.profile-main-desc {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.4;
}

.profile-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 0.4rem;
}

.profile-thumb {
  position: relative;
  display: block;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--border);
}

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

.profile-thumb.is-active {
  border-color: var(--accent);
}

.profile-thumb-badge {
  position: absolute;
  left: 0.15rem;
  bottom: 0.15rem;
  z-index: 1;
  padding: 0 0.2rem;
  border-radius: 3px;
  font-size: 0.55rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #fff;
  background: color-mix(in srgb, #111 70%, transparent);
  border: none;
}

.profile-thumb-badge--primary {
  left: auto;
  right: 0.15rem;
  bottom: auto;
  top: 0.15rem;
  background: color-mix(in srgb, var(--accent) 85%, #000);
}

.profile-thumb-badge--sfw {
  background: color-mix(in srgb, var(--ok) 80%, #000);
}

.profile-thumb-badge--nsfw {
  background: color-mix(in srgb, var(--error) 85%, #000);
}

.profile-thumb-badge--unknown {
  background: color-mix(in srgb, #111 65%, transparent);
}

.profiles-edit-pane {
  padding: 1rem;
  overflow-y: auto;
}

.profiles-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.profiles-edit-form h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.profiles-edit-form h2:not(:first-of-type) {
  margin-top: 1.25rem;
}

.profiles-edit-form .loc-lang {
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.profiles-edit-form .loc-lang legend {
  padding: 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted, #888);
}

.profiles-edit-form label {
  display: block;
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
}

.profiles-edit-form input,
.profiles-edit-form textarea,
.profiles-edit-form select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.profiles-edit-form button[type="submit"] {
  width: 100%;
  margin-top: 0.25rem;
}

.profiles-edit-form .muted {
  margin-top: 0.85rem;
}

@media (max-width: 1100px) {
  .profiles-shell {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .profiles-edit-pane {
    grid-column: 1 / -1;
  }
}

@media (max-width: 800px) {
  .profiles-shell {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .profiles-list-pane {
    max-height: 40vh;
  }
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.split--edit {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 1.25rem;
}

@media (max-width: 800px) {
  .split,
  .split--edit {
    grid-template-columns: 1fr;
  }
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.form-card h2 {
  margin-top: 0;
}

.form-card hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

.danger-form {
  margin-top: 0.75rem;
}

button.danger {
  background: var(--error);
  color: #fff;
}

button.danger:hover {
  filter: brightness(0.95);
}

button.small {
  padding: 0.25rem 0.55rem;
  font-size: 0.85rem;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.meta-list {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.gallery-item {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  /* Keep overflow visible so description tips are not clipped */
  overflow: visible;
}

.gallery-media {
  position: relative;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--border);
}

.gallery-desc {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  margin: 0;
  border: 1px solid color-mix(in srgb, #fff 35%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, #111 55%, transparent);
  color: #fff;
  cursor: help;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 4px color-mix(in srgb, #000 35%, transparent);
}

.gallery-desc:hover,
.gallery-desc:focus-visible {
  background: color-mix(in srgb, #111 75%, transparent);
  outline: none;
}

.gallery-desc-icon {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
}

.gallery-desc-tip {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  width: max-content;
  max-width: min(14rem, 52vw);
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  background: #1a1a1a;
  color: #f5f5f5;
  font-size: 0.8rem;
  font-weight: 400;
  font-style: normal;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  box-shadow: 0 6px 18px color-mix(in srgb, #000 35%, transparent);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 3;
}

.gallery-desc:hover .gallery-desc-tip,
.gallery-desc:focus-visible .gallery-desc-tip {
  opacity: 1;
  visibility: visible;
}

.gallery-item figcaption {
  padding: 0.65rem;
  display: grid;
  gap: 0.35rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  width: fit-content;
}

.badge-pending,
.badge-running {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.job-status:not(:empty) {
  margin-bottom: 0.75rem;
}

/* Blinking activity dot inside the running badge (inherits badge color). */
.pulse-dot {
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: currentColor;
  vertical-align: baseline;
  animation: pulse-dot-blink 1.2s ease-in-out infinite;
}

@keyframes pulse-dot-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

.badge-completed {
  color: var(--ok);
}

.badge-failed,
.badge-nsfw {
  color: var(--error);
}

.badge-partial,
.badge-cancelled,
.badge-unknown {
  color: var(--muted);
}

.badge-sfw {
  color: var(--ok);
}

.small {
  font-size: 0.85rem;
}

.spaced-form {
  margin-top: 0.75rem;
}
