/* ============================================================
   ADMIN LAYOUT
   ============================================================ */
.admin-shell {
  min-height: 100vh;
  padding-left: 16rem;
}

/* --- Sidebar --- */
.admin-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 16rem;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-lg) 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
}
.admin-brand {
  padding: 0 var(--space-lg);
  margin-bottom: var(--space-xl);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
  color: var(--color-text);
}
.admin-brand svg {
  width: 2rem;
  height: auto;
  flex-shrink: 0;
}
.admin-brand-text {
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.3;
}

.admin-nav {
  flex: 1;
}
.admin-nav-section {
  padding: 0 var(--space-sm);
  margin-bottom: var(--space-lg);
}
.admin-nav-label {
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-muted);
  padding: 0 var(--space-sm);
  margin-bottom: var(--space-xs);
}
.admin-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-base);
  transition: background 0.15s ease;
}
.admin-nav a:hover {
  background: var(--color-border);
  color: var(--color-text);
}
.admin-nav a.active {
  background: var(--color-accent);
  color: var(--color-bg);
}
.admin-nav-icon {
  width: 1rem;
  height: 1rem;
  opacity: 0.6;
}
.admin-nav a.active .admin-nav-icon {
  opacity: 1;
}

.admin-user {
  padding: var(--space-sm) var(--space-lg);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
  font-size: var(--text-sm);
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.admin-user-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-accent);
}

/* --- Top bar --- */
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.admin-topbar h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0;
}
.admin-topbar-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

/* --- Save/Cancel UX --- */
.admin-topbar-actions .btn {
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.admin-topbar-dirty {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: slide-in 0.25s ease;
}
.admin-topbar-dirty .admin-dirty-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-warm);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(0.5rem); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.admin-topbar-left {
  display: flex;
  align-items: center;
}
.admin-topbar-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin-left: -2rem;
  color: var(--color-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}
.admin-topbar-chevron:hover {
  color: var(--color-text);
  background: var(--color-surface);
}
.arrow-left {
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-left: 0.1em;
}

/* --- Content --- */
.admin-content {
  padding: var(--space-xl);
  overflow-y: auto;
}

/* ============================================================
   ADMIN COMPONENTS
   ============================================================ */

/* --- Stats row --- */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}
.admin-stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}
.admin-stat-value {
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1;
  margin-bottom: var(--space-xs);
}
.admin-stat-label {
  font-size: var(--text-xs);
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* --- Table --- */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.admin-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  border-bottom: 2px solid var(--color-border);
}
.admin-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.admin-table tr:hover td {
  background: var(--color-surface);
}
.admin-table--clickable tr {
  cursor: pointer;
}
.admin-table--clickable tr:active td {
  background: var(--color-border);
}
.admin-table-thumb {
  width: 3.5rem;
  height: 2.5rem;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--color-border);
  display: block;
}
.admin-table-thumb-col {
  width: 3.5rem;
}
.admin-table-title {
  font-weight: 500;
}
.admin-table-actions {
  white-space: nowrap;
}
.admin-table-actions a {
  font-size: var(--text-sm);
  margin-right: var(--space-sm);
  color: var(--color-muted);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.admin-table-actions a:hover {
  color: var(--color-accent);
}
.admin-table-actions a.destructive {
  color: #b54a32;
}
.admin-table-actions a.destructive:hover {
  color: #943d28;
}

/* --- Badge --- */
.badge {
  display: inline-block;
  font-size: var(--text-xs);
  padding: 0.1em 0.5em;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-muted);
}
.badge--featured {
  background: var(--color-warm-soft);
  border-color: var(--color-warm);
  color: var(--color-warm);
}

/* --- Empty state --- */
.admin-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-muted);
}
.admin-empty p {
  margin: 0 auto var(--space-md);
}
.admin-empty-title {
  font-size: var(--text-2xl);
}

/* ============================================================
   FORM COMPONENTS
   ============================================================ */
.form-section {
  margin-bottom: var(--space-xl);
  max-width: 40rem;
}
.form-section--wide {
  max-width: 100%;
}
.form-section-title {
  font-size: var(--text-sm);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-border);
}
.form-row {
  margin-bottom: var(--space-md);
}
.form-row label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: var(--space-xs);
}
.form-row input[type="text"],
.form-row textarea,
.form-row select {
  max-width: 100%;
  width: 100%;
}
.form-row textarea {
  min-height: 6rem;
}
.form-row-inline {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.form-row-inline label {
  margin: 0;
  font-weight: 400;
}
.form-hint {
  font-size: var(--text-xs);
  color: var(--color-muted);
  margin-top: var(--space-xs);
}

/* Tag input */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  min-height: 2.5rem;
  align-items: center;
  cursor: text;
}
.tag-input .tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
}
.tag-remove {
  cursor: pointer;
  opacity: 0.5;
  font-size: 0.8em;
}
.tag-remove:hover {
  opacity: 1;
}
.tag-input input {
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--space-xs) 0;
  flex: 1;
  min-width: 6rem;
}

/* Image grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.image-card {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.image-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}
.image-card-actions {
  display: flex;
  justify-content: space-between;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-xs);
}
.image-card-actions a {
  color: var(--color-muted);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.image-card-actions a:hover {
  color: var(--color-accent);
}
.image-card-actions a.destructive {
  color: #b54a32;
}
.image-card-actions a.destructive:hover {
  color: #943d28;
}
.image-card-current {
  font-size: var(--text-xs);
  color: var(--color-accent);
  font-weight: 500;
}

/* Delete confirm state */
.image-card--confirm {
  position: relative;
}
.image-card-confirm-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  pointer-events: none;
}
[data-theme="dark"] .image-card-confirm-overlay {
  background: rgba(26, 23, 20, 0.75);
}
.image-card-confirm-overlay p {
  font-size: var(--text-sm);
  font-weight: 500;
  color: #b54a32;
  margin: 0;
}
.image-card--confirm .image-card-actions {
  position: relative;
  z-index: 2;
}
.image-card-cancel {
  color: var(--color-muted);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.image-card-cancel:hover {
  color: var(--color-text);
}

.image-card--cover {
  border-color: var(--color-accent);
  border-width: 2px;
}
.image-card-badge {
  position: absolute;
  top: var(--space-xs);
  left: var(--space-xs);
  font-size: var(--text-xs);
  background: var(--color-accent);
  color: var(--color-bg);
  padding: 0.1em 0.4em;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

/* Processing state */
.image-card--processing {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.image-card--processing::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    transparent 30%,
    rgba(255, 255, 255, 0.15) 50%,
    transparent 70%
  );
  animation: shimmer 1.8s ease-in-out infinite;
}
.image-card-processing-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-xs);
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.image-card-processing-label::before {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  text-align: center;
  color: var(--color-muted);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.upload-zone:hover {
  border-color: var(--color-accent);
  background: var(--color-warm-soft);
}
.upload-zone p {
  margin: 0;
}
.upload-zone-cta {
  color: var(--color-accent);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
.upload-zone-hint {
  font-size: var(--text-xs);
  margin-top: var(--space-xs);
}

/* Upload progress */
.upload-file-input {
  display: none;
}
.upload-progress {
  display: none;
}
.upload-progress-track {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: var(--space-sm);
}
.upload-progress-bar {
  width: 0%;
  height: 100%;
  background: var(--color-accent);
  transition: width 0.3s;
}

/* Form actions */
.form-actions {
  display: flex;
  gap: var(--space-sm);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
  max-width: 40rem;
}

/* --- Tag merge mode --- */
.admin-table .merge-check {
  width: 0;
  overflow: hidden;
  padding: 0;
  opacity: 0;
  transition: width 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
}
.merge-active .merge-check {
  width: 2.5rem;
  padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
  opacity: 1;
}
.merge-check input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--color-accent);
  cursor: pointer;
}
.admin-table tr.merge-selected td {
  background: var(--color-warm-soft);
}
.tag-count-cell {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.tag-count-bar {
  height: 4px;
  background: var(--color-accent);
  border-radius: 2px;
  opacity: 0.4;
}
.tag-count-num {
  font-variant-numeric: tabular-nums;
  min-width: 1.5rem;
}

/* --- Merge resolve dialog --- */
.merge-resolve {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--color-overlay);
  align-items: center;
  justify-content: center;
}
.merge-resolve.open {
  display: flex;
}
.merge-resolve-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  max-width: 28rem;
  width: 90vw;
  animation: slide-up 0.25s ease;
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}
.merge-resolve-card h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-xs);
}
.merge-resolve-card p {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-bottom: var(--space-lg);
}
.merge-choices {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}
.merge-choice {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.merge-choice:hover {
  border-color: var(--color-accent);
  background: var(--color-surface);
}
.merge-choice.selected {
  border-color: var(--color-accent);
  background: var(--color-warm-soft);
}
.merge-choice input[type="radio"] {
  accent-color: var(--color-accent);
  width: 1rem;
  height: 1rem;
}
.merge-choice-name {
  font-weight: 500;
  flex: 1;
}
.merge-choice-count {
  font-size: var(--text-xs);
  color: var(--color-muted);
}
.merge-choice-absorbed {
  font-size: var(--text-xs);
  color: var(--color-muted);
  font-style: italic;
}
.merge-resolve-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .admin-shell {
    padding-left: 0;
  }
  .admin-sidebar {
    position: static;
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-md);
    height: auto;
    overflow-y: visible;
  }
  .admin-nav-section {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
  }
  .admin-nav-label {
    display: none;
  }
  .admin-user {
    display: none;
  }
  .admin-content {
    padding: var(--space-md);
  }
}
