/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== App Layout ===== */
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar {
  width: 220px;
  background: #161b22;
  border-right: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid #30363d;
}
.sidebar-header h1 { font-size: 18px; color: #58a6ff; margin-bottom: 2px; }
.sidebar-header small { color: #8b949e; font-size: 11px; }
.sidebar-nav { flex: 1; padding: 12px 8px; }
.nav-item {
  display: block;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 6px;
  color: #c9d1d9;
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s;
}
.nav-item:hover { background: #21262d; }
.nav-item.active { background: #1f6feb22; color: #58a6ff; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid #30363d; }

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  background: #0d1117;
}

/* ===== Mobile Header ===== */
.mobile-header { display: none; }

/* ===== Pages ===== */
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 22px; color: #f0f6fc; margin-bottom: 20px; }

/* ===== Cards ===== */
.card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}
.card h3 { color: #f0f6fc; margin-bottom: 16px; font-size: 16px; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.stat-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
}
.stat-value { font-size: 32px; font-weight: 700; color: #58a6ff; }
.stat-label { font-size: 13px; color: #8b949e; margin-top: 4px; }

/* ===== Photo Grid ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.photo-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
  position: relative;
}
.photo-card:hover { border-color: #58a6ff; }
.photo-card .photo-thumb {
  width: 100%;
  height: 150px;
  object-fit: cover;
  cursor: pointer;
  background: #21262d;
  display: block;
}
.photo-card .photo-info {
  padding: 10px 12px;
  position: relative;
}
.photo-card .photo-title {
  font-size: 13px;
  color: #f0f6fc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.photo-card .photo-slide {
  font-size: 11px;
  color: #8b949e;
}
.photo-card .photo-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.photo-card .photo-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 20px;
  height: 20px;
  accent-color: #58a6ff;
  cursor: pointer;
}

/* ===== Page Header ===== */
.page-header { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; }
.page-header .page-title { margin-bottom: 0; }
.search-box { flex: 1; min-width: 200px; max-width: 400px; }

/* ===== Batch Bar ===== */
.batch-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: #30363d;
  border-radius: 8px;
  margin-bottom: 16px;
}
.batch-bar span { color: #c9d1d9; font-weight: 600; }

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #21262d;
  color: #c9d1d9;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #30363d; }
.btn-primary { background: #238636; border-color: #2ea043; color: #fff; }
.btn-primary:hover { background: #2ea043; }
.btn-danger { background: #da3633; border-color: #f85149; color: #fff; }
.btn-danger:hover { background: #f85149; }
.btn-secondary { background: #1f6feb; border-color: #388bfd; color: #fff; }
.btn-secondary:hover { background: #388bfd; }
.btn-ghost { background: transparent; border-color: transparent; color: #8b949e; }
.btn-ghost:hover { background: #21262d; color: #c9d1d9; }
.btn-full { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== Inputs ===== */
.input-full {
  width: 100%;
  padding: 8px 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.input-full:focus { border-color: #58a6ff; }
textarea.input-full { resize: vertical; font-family: inherit; }

/* ===== Form ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; color: #8b949e; font-size: 13px; margin-bottom: 6px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ===== Modals ===== */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 28px;
  max-width: 95%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-small { width: 360px; }
.modal-medium { width: 500px; }
.modal-content h2 { color: #f0f6fc; margin-bottom: 16px; font-size: 20px; }
.modal-content p { color: #8b949e; margin-bottom: 16px; }

/* ===== Error ===== */
.error-msg { color: #f85149; font-size: 13px; margin-bottom: 12px; min-height: 20px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #238636;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: opacity 0.3s;
}
.toast.error { background: #da3633; }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
}
.lightbox-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 95vw;
  max-height: 95vh;
}
.lightbox-content img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  font-size: 28px;
  padding: 16px 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}
.lightbox-nav:hover { background: rgba(0,0,0,0.8); }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }
.lightbox-info {
  color: #fff;
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
}
.lightbox-info span { margin: 0 12px; }

/* ===== Upload ===== */
.upload-area {
  border: 2px dashed #30363d;
  border-radius: 12px;
  padding: 60px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: #161b22;
}
.upload-area:hover, .upload-area.dragover {
  border-color: #58a6ff;
  background: #1c2129;
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-area p { color: #8b949e; margin-bottom: 16px; }
.upload-progress {
  margin-top: 20px;
  padding: 16px;
  background: #161b22;
  border-radius: 8px;
  border: 1px solid #30363d;
}
.progress-bar {
  width: 100%;
  height: 8px;
  background: #30363d;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: #58a6ff;
  width: 0%;
  transition: width 0.3s;
}
.upload-log {
  margin-top: 16px;
  max-height: 300px;
  overflow-y: auto;
}
.upload-log-item {
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 4px;
  font-size: 13px;
}
.upload-log-item.success { background: #122d1a; color: #3fb950; }
.upload-log-item.error { background: #2d1212; color: #f85149; }
.upload-log-item.info { background: #1c2129; color: #8b949e; }

/* ===== Data Page ===== */
.action-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.backups-list { margin-top: 16px; }
.backup-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #21262d;
  font-size: 13px;
}
.backup-item:last-child { border-bottom: none; }
.backup-item span { color: #c9d1d9; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #8b949e;
}


/* ===== Dashboard Charts ===== */
.dashboard-charts { margin-top: 24px; }
.chart-row { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.chart-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 20px;
  flex: 1;
  min-width: 280px;
}
.chart-card h3 { color: #f0f6fc; margin-bottom: 16px; font-size: 15px; }

/* Bar Chart */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  padding-top: 8px;
}
.bar {
  flex: 1;
  min-width: 3px;
  border-radius: 2px 2px 0 0;
  transition: height 0.3s;
}
.bar:hover { opacity: 0.8; }
.bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 10px;
  color: #8b949e;
}
.bar-labels span { flex: 1; text-align: center; }

/* Pie Chart */
.pie-wrapper { display: flex; align-items: center; gap: 20px; }
.pie-chart {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pie-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; color: #c9d1d9; font-size: 13px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* Storage Stats */
.storage-stats { display: flex; gap: 24px; flex-wrap: wrap; }
.storage-item { display: flex; flex-direction: column; gap: 4px; }
.storage-label { color: #8b949e; font-size: 13px; }
.storage-value { color: #58a6ff; font-size: 20px; font-weight: 600; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    max-width: 80vw;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  /* Sidebar overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }
  .sidebar.open ~ .sidebar-overlay { display: block; }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 50;
    min-height: 52px;
  }
  .mobile-header h2 { font-size: 16px; color: #58a6ff; }
  .menu-toggle {
    background: none;
    border: none;
    color: #c9d1d9;
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .main-content { padding: 64px 12px 16px; }

  /* Stats grid 2 columns */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card { padding: 14px 10px; }
  .stat-value { font-size: 24px; }

  /* Photo grid 2 columns */
  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .photo-card { border-radius: 6px; }
  .photo-card .photo-thumb { height: 100px; }
  .photo-card .photo-info { padding: 6px 8px; }
  .photo-card .photo-title { font-size: 12px; }
  .photo-card .photo-slide { font-size: 10px; }
  .photo-card .photo-checkbox {
    width: 24px;
    height: 24px;
    top: 4px;
    left: 4px;
  }
  .photo-card .photo-actions {
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
  }
  .photo-card .photo-actions .btn-sm {
    padding: 6px 8px;
    font-size: 11px;
    min-height: 32px;
  }

  /* Batch bar stacked */
  .batch-bar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
  }
  .batch-bar .btn {
    flex: 1 1 calc(50% - 6px);
    min-width: 100px;
    justify-content: center;
    min-height: 40px;
  }

  /* Modals full-screen-ish */
  .modal-small, .modal-medium {
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px 16px;
  }
  .form-group input,
  .form-group textarea {
    width: 100%;
  }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1; justify-content: center; min-height: 44px; }

  /* Upload area */
  .upload-area { padding: 30px 16px; }
  .upload-icon { font-size: 36px; }

  /* Lightbox */
  .lightbox-content img {
    max-width: 100vw;
    max-height: 70vh;
  }
  .lightbox-nav {
    width: 44px;
    height: 44px;
    font-size: 22px;
    padding: 10px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .lightbox-prev { left: 6px; }
  .lightbox-next { right: 6px; }
  .lightbox-close {
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Data page actions stacked */
  .action-grid {
    flex-direction: column;
  }
  .action-grid .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  /* Page header stacked */
  .page-header {
    flex-direction: column;
  }
  .search-box { max-width: 100%; }
  .filter-box { width: 100%; }
  .filter-box .input-full { width: 100%; }

  /* Storage stats */
  .storage-info { font-size: 12px; }

  /* Backup items */
  .backup-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Login modal */
  #loginModal .modal-content { padding: 24px 16px; }
  #loginModal .modal-content h2 { font-size: 18px; }
}

/* Extra-small screens */
@media (max-width: 400px) {
  .photo-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .main-content { padding: 64px 8px 12px; }
  .batch-bar .btn { flex: 1 1 100%; }
}

/* ===== Tag System ===== */
.tag-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin: 1px;
  line-height: 1.4;
  white-space: nowrap;
}
.tag-filter {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  margin: 2px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  user-select: none;
}
.tag-filter:hover { opacity: 0.85; }
.tag-filter.active { border-color: currentColor; box-shadow: 0 0 0 1px currentColor; }
.tag-已审核 { background: #d1fae5; color: #065f46; }
.tag-需要替换 { background: #fee2e2; color: #991b1b; }
.tag-精选 { background: #fef3c7; color: #92400e; }
.tag-历史重要 { background: #dbeafe; color: #1e40af; }
.tag-需裁剪 { background: #f3e8ff; color: #6b21a8; }
.tag-待确认 { background: #f1f5f9; color: #475569; }

.photo-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 4px;
  min-height: 18px;
}
.tag-edit-section {
  margin-top: 8px;
}
.tag-edit-section label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}
.tag-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag-checkboxes label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f6f8fa;
}
.tag-checkboxes label:hover { background: #e8eaed; }
.tag-filter-bar {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e5e7eb;
}
.tag-filter-bar .tag-filter-label {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}


/* ===== 地图撒点 ===== */
.map-layout {
  display: flex;
  gap: 16px;
  height: 65vh;
}
.map-container {
  flex: 1;
  border-radius: 8px;
  border: 1px solid #30363d;
  min-height: 400px;
}
.map-sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.map-photo-list {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #30363d;
  border-radius: 8px;
  background: #161b22;
}
.map-photo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid #21262d;
  cursor: pointer;
  transition: background 0.2s;
}
.map-photo-item:hover { background: #1c2129; }
.map-photo-item.active { background: #1f6feb22; }
.map-photo-thumb {
  width: 40px; height: 40px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}
.map-photo-info { flex: 1; min-width: 0; }
.map-photo-title {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-photo-coords { font-size: 11px; color: #888; }
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== 留言管理 ===== */
.msg-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.messages-list { margin-top: 16px; }
.msg-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: box-shadow 0.2s;
}
.msg-card:hover { border-color: #58a6ff; }
.msg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.msg-card-nickname { font-weight: 600; color: #58a6ff; font-size: 14px; }
.msg-card-meta { font-size: 12px; color: #8b949e; }
.msg-card-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: #1f6feb22;
  color: #58a6ff;
  margin-right: 6px;
}
.msg-card-content {
  font-size: 13px;
  color: #c9d1d9;
  line-height: 1.6;
  margin-bottom: 8px;
}
.msg-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}


/* ===== 返回展厅按钮 ===== */
.back-to-gallery {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  margin: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  color: #8b949e;
  text-decoration: none;
  transition: all 0.2s;
}
.back-to-gallery:hover {
  color: #58a6ff;
  background: rgba(88,166,255,0.1);
}
@media (max-width: 768px) {
  .back-to-gallery {
    font-size: 11px;
    padding: 4px 8px;
  }
  /* 地图撒点 - 上下分布 */
  .map-layout {
    flex-direction: column !important;
    height: auto !important;
  }
  .map-container {
    width: 100% !important;
    height: 55vh !important;
    min-height: 300px !important;
    border-radius: 8px !important;
  }
  .map-sidebar {
    width: 100% !important;
    max-height: 35vh !important;
  }
  .map-toolbar {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
}


/* ===== 备份管理 ===== */
.backup-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.backup-item {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 16px; background: #161b22; border: 1px solid #30363d;
  border-radius: 8px; flex-wrap: wrap;
}
.backup-info { flex: 1; min-width: 0; }
.backup-name { font-size: 14px; font-weight: 500; color: #e6edf3; word-break: break-all; }
.backup-date { font-size: 12px; color: #8b949e; margin-top: 2px; }
.backup-tags { margin-top: 4px; }
.backup-tag {
  display: inline-block; padding: 1px 6px; border-radius: 8px;
  font-size: 10px; background: rgba(56,139,253,0.15); color: #58a6ff; margin-right: 4px;
}
.backup-size { font-size: 13px; color: #8b949e; white-space: nowrap; }
.backup-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.backups-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
