/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f6fa;
  color: #2d3436;
  line-height: 1.5;
}

/* === Login Screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.login-card {
  background: #fff;
  padding: 48px 40px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-card h1 {
  font-size: 28px;
  color: #1a1a2e;
  margin-bottom: 8px;
}
.login-subtitle {
  color: #636e72;
  margin-bottom: 24px;
}
.login-error {
  background: #ffeef0;
  color: #d63031;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}
.google-signin-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  background: #fff;
  font-size: 15px;
  font-weight: 500;
  color: #3c4043;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.google-signin-btn:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* === Layout === */
#admin-panel {
  display: flex;
  min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: 240px;
  background: #1a1a2e;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}
.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.sidebar-subtitle {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.nav-list {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
}
.nav-link.active {
  color: #fff;
  background: rgba(99,102,241,0.3);
  border-right: 3px solid #6366f1;
}
.nav-icon { font-size: 16px; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.admin-name {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Main Content === */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 32px;
  min-height: 100vh;
}
.page { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  color: #1a1a2e;
}

/* === Stat Cards === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: #1a1a2e;
}
.stat-card .stat-label {
  font-size: 13px;
  color: #636e72;
  margin-top: 4px;
}
.stat-card.warning { border-left: 4px solid #fdcb6e; }
.stat-card.danger { border-left: 4px solid #e17055; }
.stat-card.info { border-left: 4px solid #6366f1; }

/* === Default Background Manager === */
.background-manager-card {
  overflow: visible;
}
.background-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.background-status-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid #eee;
  color: #636e72;
  font-size: 13px;
}
.background-status-row > span:not(.badge) {
  padding: 4px 8px;
  border-radius: 4px;
  background: #f3f4f6;
}
.background-manager-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 20px;
  padding: 20px;
}
.background-manager-grid h4 {
  font-size: 13px;
  font-weight: 700;
  color: #636e72;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.background-list,
.background-pool {
  display: grid;
  gap: 10px;
}
.background-row,
.background-pool-item {
  display: grid;
  grid-template-columns: 28px 84px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid #eee;
  border-radius: 8px;
  background: #fff;
}
.background-pool-item {
  grid-template-columns: 76px minmax(0, 1fr) auto;
}
.background-order {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-weight: 700;
}
.background-thumb {
  width: 84px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
  background: #e5e7eb;
  display: block;
}
.background-pool-item .background-thumb {
  width: 76px;
  height: 58px;
}
.background-row-body {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.background-row-body strong {
  font-size: 13px;
  color: #2d3436;
}
.background-row-body span,
.background-row-body code {
  min-width: 0;
  color: #636e72;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.background-row-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: transparent;
}
.background-row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.background-row-with-meta {
  display: block;
}
.background-row-main {
  display: grid;
  grid-template-columns: 28px minmax(160px, 210px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.background-thumb-frame {
  position: relative;
  width: 100%;
  aspect-ratio: var(--scene-aspect, 1 / 1);
  min-height: 140px;
  overflow: hidden;
  border-radius: 6px;
  background: #e5e7eb;
  touch-action: none;
}
.background-thumb-frame .background-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  object-fit: fill;
}
.background-placement-overlay {
  position: absolute;
  border: 2px solid #10b981;
  background: rgba(16, 185, 129, 0.16);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.8);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}
.background-placement-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #059669;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.background-placement-handle-nw {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}
.background-placement-handle-n {
  left: 50%;
  top: -7px;
  transform: translateX(-50%);
  cursor: ns-resize;
}
.background-placement-handle-ne {
  right: -7px;
  top: -7px;
  cursor: nesw-resize;
}
.background-placement-handle-e {
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}
.background-placement-handle-se {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}
.background-placement-handle-s {
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  cursor: ns-resize;
}
.background-placement-handle-sw {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}
.background-placement-handle-w {
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}
.background-row-body small {
  min-width: 0;
  color: #4b5563;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.background-image-note {
  color: #047857 !important;
  font-weight: 700;
}
.background-image-input {
  display: none;
}
.background-meta-editor {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  align-items: end;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #f3f4f6;
}
.background-meta-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.background-meta-field span {
  color: #636e72;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.background-meta-field input {
  width: 100%;
  min-width: 0;
}
.empty-state-sm {
  padding: 28px 16px;
}

/* === Tables === */
.table-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
  margin-bottom: 24px;
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  flex-wrap: wrap;
  gap: 12px;
}
.table-header h3 {
  font-size: 16px;
  font-weight: 600;
}
.section-subtitle {
  color: #636e72;
  font-size: 13px;
  margin-top: 4px;
}
.table-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: #636e72;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #fafbfc;
  border-bottom: 1px solid #eee;
}
td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
tr:hover { background: #fafbfc; }
tr.expanded-parent { background: #f0f4ff; }

/* === Detail Row === */
.detail-row td {
  padding: 0;
  background: #f8f9ff;
}
.detail-content {
  padding: 20px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.detail-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #636e72;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.detail-field span, .detail-field p {
  font-size: 14px;
  color: #2d3436;
}
.detail-snapshot {
  margin-top: 16px;
  padding: 16px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #eee;
}
.detail-snapshot img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 6px;
  object-fit: cover;
}
.detail-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

/* === Badges === */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-pending { background: #ffeaa7; color: #856404; }
.badge-reviewed { background: #bee5eb; color: #0c5460; }
.badge-resolved { background: #d4edda; color: #155724; }
.badge-artwork { background: #e8daff; color: #5b21b6; }
.badge-user { background: #ffe0cc; color: #c2410c; }
.badge-comment { background: #ccfbf1; color: #115e59; }
.badge-flagged { background: #fecaca; color: #991b1b; }
.badge-suspended { background: #1a1a2e; color: #fff; }
.badge-subscribed { background: #d4edda; color: #155724; }
.badge-hidden { background: #e5e7eb; color: #374151; }

/* === Buttons === */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #6366f1; color: #fff; }
.btn-success { background: #10b981; color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* === Form Controls === */
select, input[type="text"], input[type="number"] {
  padding: 7px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  outline: none;
  transition: border 0.15s;
}
select:focus, input[type="text"]:focus, input[type="number"]:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
input[type="text"] { min-width: 200px; }

/* === Loading === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: #636e72;
  font-size: 14px;
}
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e5e7eb;
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: #1a1a2e;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.toast-error { background: #ef4444; }
.toast.toast-success { background: #10b981; }

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #636e72;
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* === Tabs === */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #eee;
  margin-bottom: 20px;
}
.tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #636e72;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.tab:hover { color: #2d3436; }
.tab.active {
  color: #6366f1;
  border-bottom-color: #6366f1;
}

/* === Art Grid (Content page) === */
.art-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.art-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: box-shadow 0.15s;
}
.art-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.art-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}
.art-card-body {
  padding: 10px 12px;
}
.art-card-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.art-card-artist {
  font-size: 12px;
  color: #636e72;
}
.art-card-actions {
  padding: 8px 12px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  gap: 6px;
}

/* === Modal overlay === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #636e72;
  padding: 4px 8px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header h2, .sidebar-subtitle, .nav-link span:not(.nav-icon), .admin-name { display: none; }
  .nav-link { justify-content: center; padding: 12px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .background-manager-grid { grid-template-columns: 1fr; padding: 16px; }
  .background-row { grid-template-columns: 28px 72px minmax(0, 1fr); }
  .background-row-main { grid-template-columns: 28px minmax(120px, 1fr); }
  .background-row-main .background-row-body,
  .background-row-main .background-row-actions {
    grid-column: 1 / -1;
  }
  .background-pool-item { grid-template-columns: 64px minmax(0, 1fr); }
  .background-thumb {
    width: 72px;
    height: 54px;
  }
  .background-thumb-frame {
    width: 100%;
    height: auto;
    min-height: 120px;
  }
  .background-pool-item .background-thumb {
    width: 64px;
    height: 48px;
  }
  .background-row-actions,
  .background-pool-item .btn {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
  .background-meta-editor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
