:root {
  --bg: #080c12;
  --bg-elevated: #0f1419;
  --panel: rgba(26, 35, 50, 0.85);
  --panel-solid: #1a2332;
  --border: rgba(45, 58, 79, 0.9);
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  opacity: 0;
  transition: opacity 0.35s ease;
}

body.page-ready { opacity: 1; }
body.page-exit { opacity: 0; transition: opacity 0.2s ease; }

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #60a5fa; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* Header */
header.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

header.bar h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 600;
  background: linear-gradient(90deg, #e8edf4, #93c5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition), background var(--transition);
  position: relative;
  overflow: hidden;
}

.btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.15);
}

.btn:active { transform: translateY(0) scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover {
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-danger { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

.btn-pulse {
  animation: btnPulse 0.4s ease;
}

@keyframes btnPulse {
  0% { box-shadow: 0 0 0 0 var(--accent-glow); }
  70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

/* Cards */
.card {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
  border-color: rgba(59, 130, 246, 0.35);
}

.card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

/* Form */
input, select, textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.form-row label { min-width: 80px; color: var(--muted); font-size: 14px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  transition: transform 0.15s ease;
}

.badge-pending { background: #334155; color: #cbd5e1; }
.badge-annotated { background: #14532d; color: #86efac; }
.badge-empty { background: #422006; color: #fcd34d; }

.edit-hint { color: #60a5fa; font-size: 12px; }

/* Grid gallery */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.grid-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--panel-solid);
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  opacity: 0;
  transform: translateY(12px);
}

.grid-item.animate-in {
  animation: fadeSlideUp 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.grid-item:hover {
  border-color: var(--accent);
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 28px rgba(59, 130, 246, 0.2);
}

.grid-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: #000;
  display: block;
  transition: transform 0.35s ease;
}

.grid-item:hover img { transform: scale(1.04); }

.grid-item .meta { padding: 10px; font-size: 12px; }

.grid-item .thumb-wrap {
  position: relative;
  overflow: hidden;
}

.grid-item .thumb-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 50%, rgba(0,0,0,0.65));
  opacity: 0;
  transition: opacity var(--transition);
  display: flex;
  align-items: flex-end;
  padding: 8px;
  font-size: 11px;
  color: #93c5fd;
}

.grid-item .thumb-wrap.thumb-error::after {
  content: "加载失败，请重新登录";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  background: rgba(0,0,0,0.6);
}

.grid-item:hover .thumb-overlay { opacity: 1; }

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
}

.stat-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Toast stack */
#toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast-item {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  max-width: 360px;
}

.toast-item.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-success { border-left: 3px solid var(--success); }
.toast-warn { border-left: 3px solid var(--warn); }
.toast-error { border-left: 3px solid var(--danger); }

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(6px);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.loading-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.loading-card {
  text-align: center;
  padding: 28px 36px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 14px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.loading-text { margin: 0; color: var(--muted); font-size: 14px; }

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

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.login-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 400px;
  animation: fadeSlideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.login-card h2 {
  margin-top: 0;
  font-size: 1.5rem;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.login-card input { width: 100%; margin-bottom: 10px; }

.login-card .btn-primary { width: 100%; margin-top: 6px; padding: 11px; }

/* Annotate */
.annotate-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  height: calc(100vh - 52px);
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #111827 0%, #000 100%);
  cursor: crosshair;
}

.canvas-wrap canvas { display: block; }

.canvas-wrap.loaded {
  animation: canvasReveal 0.5s ease;
}

.canvas-wrap.space-pan,
.canvas-wrap.panning { cursor: grab; }
.canvas-wrap.panning { cursor: grabbing; }

@keyframes canvasReveal {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

.sidebar {
  border-left: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(10px);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar h3 { margin: 0 0 8px; font-size: 14px; color: #93c5fd; }

.kbd {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.7;
  padding: 10px;
  background: var(--bg-elevated);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.box-list { flex: 1; overflow-y: auto; }

.box-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform 0.15s ease;
}

.box-item:hover { transform: translateX(3px); border-color: rgba(59, 130, 246, 0.4); }

.box-item.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.box-num { color: #93c5fd; font-weight: 600; }
.empty-hint { color: var(--muted); font-size: 12px; margin: 0; }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 14px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.toolbar #imgInfo { flex: 1; min-width: 120px; font-size: 13px; color: var(--muted); }

/* Animations */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fadeSlideUp 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.stagger-item { opacity: 0; }

[data-animate] { opacity: 0; }

/* Skeleton */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.skeleton-card {
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #1a2332 25%, #243044 50%, #1a2332 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

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

/* Upload progress */
.upload-progress {
  height: 3px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
  display: none;
}

.upload-progress.show { display: block; }

.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #22c55e);
  transition: width 0.2s ease;
  border-radius: 2px;
}

/* Header extras */
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-back {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}

.header-back:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition), border-color var(--transition);
}

.user-menu-trigger:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.user-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.user-caret {
  font-size: 10px;
  color: var(--muted);
}

.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 160px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 100;
}

.user-menu-dropdown a,
.user-menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
  background: rgba(59, 130, 246, 0.12);
}

.user-menu-logout {
  color: #fca5a5 !important;
  border-top: 1px solid var(--border) !important;
  margin-top: 4px;
  border-radius: 0 0 6px 6px !important;
}

.toolbar-user {
  margin-left: auto;
}

.toolbar .user-menu-trigger {
  padding: 3px 6px 3px 3px;
}

.toolbar .user-avatar {
  width: 24px;
  height: 24px;
  font-size: 11px;
}

.toolbar .user-name { display: none; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.75);
  backdrop-filter: blur(4px);
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-title {
  margin: 0 0 10px;
  font-size: 16px;
}

.modal-body {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.modal-input {
  width: 100%;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-danger-solid {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: transparent;
  color: #fff;
}

.btn-danger-solid:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Grid delete */
.grid-item {
  position: relative;
}

.grid-item .item-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(15, 20, 25, 0.85);
  color: #fca5a5;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
}

.grid-item:hover .item-delete {
  opacity: 1;
}

.grid-item .item-delete:hover {
  background: rgba(239, 68, 68, 0.25);
  transform: scale(1.08);
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.dataset-settings {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.dataset-settings summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}

.dataset-settings summary:hover { color: var(--text); }

.dataset-settings .form-row { margin-top: 10px; margin-bottom: 0; }

/* Audit table */
.audit-table-wrap {
  overflow-x: auto;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.audit-table th,
.audit-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.audit-table th {
  color: var(--muted);
  font-weight: 500;
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
}

.audit-table td.detail-cell {
  max-width: 280px;
  word-break: break-all;
  color: var(--muted);
  font-size: 12px;
}

.audit-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}

@media (max-width: 768px) {
  .annotate-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { border-left: none; border-top: 1px solid var(--border); max-height: 200px; }
}
