/* ===== 鸟类照片管理 - 全局样式 ===== */
/* 温暖浅色生态绿系 */
:root {
  --primary: #2F855A;
  --primary-light: #38A169;
  --primary-dark: #276749;
  --bg: #F7FAF7;
  --bg-card: #FFFFFF;
  --bg-soft: #EDF2E7;
  --text: #1A202C;
  --text-2: #4A5568;
  --text-3: #718096;
  --danger: #E53E3E;
  --warn: #D69E2E;
  --info: #2B6CB0;
  --success: #38A169;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(47, 133, 90, 0.08);
  --shadow-lg: 0 8px 30px rgba(39, 103, 73, 0.15);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

.app-bg {
  background:
    radial-gradient(1200px 400px at 20% -10%, rgba(56, 161, 105, 0.08), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(43, 108, 176, 0.06), transparent 50%),
    var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
}

/* ---- 顶部栏 ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(47, 133, 90, 0.08);
  z-index: 20;
}

.logo-badge {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.app-title { font-size: 22px; font-weight: 600; margin: 0; color: var(--primary-dark); }
.app-subtitle { font-size: 12px; color: var(--text-3); margin: 2px 0 0; }

.stat-chip {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-soft);
  color: var(--text-2);
}
.stat-pending { background: #FEF3C7; color: #92400E; }
.stat-confirm { background: #FEEBC8; color: #7B341E; }

/* ---- 编辑模式开关 ---- */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  color: var(--text-2);
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--bg-soft);
  border-radius: 999px;
  transition: background 0.2s ease;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 0.2s ease;
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ---- 按钮 ---- */
.btn {
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 2px 8px rgba(47, 133, 90, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(47, 133, 90, 0.4); }
.btn-ai {
  background: linear-gradient(135deg, #7F9CF5, #5A67D8);
  color: #fff;
  box-shadow: 0 2px 8px rgba(90, 103, 216, 0.3);
}
.btn-ai:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(90, 103, 216, 0.4); }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid rgba(113, 128, 150, 0.2);
}
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---- 进度条 ---- */
.progress-wrap {
  position: sticky; top: 0; z-index: 30;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid rgba(47, 133, 90, 0.1);
  display: flex; align-items: center; gap: 12px;
}
.progress-bar {
  flex: 1;
  height: 10px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-text { font-size: 12px; color: var(--text-2); white-space: nowrap; }

/* ---- 布局 ---- */
.sidebar {
  width: 220px;
  min-width: 200px;
  background: rgba(255, 255, 255, 0.75);
  border-right: 1px solid rgba(47, 133, 90, 0.08);
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-title {
  font-size: 13px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 4px 8px; margin-bottom: 8px;
}
.species-search { padding: 0 4px 8px; }
.species-search .input { width: 100%; font-size: 13px; }
.sidebar-body { display: flex; flex: 1; overflow: hidden; }
.species-index {
  display: flex; flex-direction: column;
  gap: 1px;
  width: 20px; flex-shrink: 0;
  overflow-y: auto;
  padding: 2px 2px 2px 0;
  border-right: 1px solid rgba(47, 133, 90, 0.10);
  scrollbar-width: none;
}
.species-index::-webkit-scrollbar { display: none; }
.species-index span {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: var(--text-2);
  border-radius: 4px;
  cursor: pointer; user-select: none;
}
.species-index span:hover { background: rgba(56, 161, 105, 0.12); }
.species-index span.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 0 0 2px rgba(56, 161, 105, 0.25);
}
.species-index span.active:hover { background: var(--primary-dark); }
.tree-scroll {
  flex: 1; overflow-y: auto;
  margin: 0 -4px; padding: 0 4px;
}
.tree-item.dim { opacity: 0.35; }
.tree-item.hit {
  background: var(--primary-light);
  box-shadow: inset 3px 0 0 var(--primary);
}
.tree-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-2);
  transition: all 0.15s ease;
  margin-bottom: 2px;
}
.tree-item:hover { background: var(--bg-soft); }
.tree-item.active {
  background: linear-gradient(135deg, rgba(56, 161, 105, 0.15), rgba(56, 161, 105, 0.05));
  color: var(--primary-dark);
  font-weight: 600;
}
.tree-count {
  font-size: 11px; color: var(--text-3);
  background: var(--bg-soft);
  padding: 1px 7px; border-radius: 999px;
}

/* ---- 主区 ---- */
.main-area { flex: 1; padding: 16px 20px; overflow-y: auto; }
.edit-mode .main-area { padding-top: 0; }
.grid-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; flex-wrap: wrap; gap: 10px;
}
/* 编辑模式：筛选标签与全选/反选等工具条在主区内吸顶，
   滚动浏览照片时始终贴住主区顶部（AI 搜索栏正下方），照片不会从上方露出 */
.edit-mode .grid-toolbar {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 10px 20px 12px;
  margin-bottom: 14px;
  background: #fff;
  border-bottom: 1px solid rgba(47, 133, 90, 0.08);
  box-shadow: 0 4px 12px rgba(39, 103, 73, 0.06);
}
.grid-title { font-size: 16px; font-weight: 500; color: var(--text); }
.filter-chip {
  padding: 4px 12px; border-radius: 999px; font-size: 12px;
  background: var(--bg-soft); color: var(--text-2);
  border: 1px solid transparent; cursor: pointer; transition: all 0.15s;
}
.filter-chip.active { background: var(--primary); color: #fff; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.photo-card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}
.photo-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.photo-card.needs_confirmation { background: #FFFBEB; }
.photo-card.failed { background: #FFF5F5; }
.photo-card.selected { border-color: var(--primary); }
.photo-card.batch-checked { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.card-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}
.thumb-wrap { position: relative; }
.card-tags {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.tag-chip {
  font-size: 10px;
  line-height: 1.5;
  padding: 0 5px;
  border: 1px solid var(--text-3);
  border-radius: 3px;
  color: var(--text-3);
  white-space: nowrap;
}
.thumb {
  width: 100%;
  aspect-ratio: 3 / 4;  /* 高4宽3 */
  object-fit: cover;
  display: block;
  background: var(--bg-soft);
}
.card-body { padding: 8px 10px; }
.card-name {
  font-size: 12px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-species { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.badge {
  display: inline-block;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}
.badge.pending { background: #FEF3C7; color: #92400E; }
.badge.generated { background: #C6F6D5; color: #22543D; }
.badge.needs_confirmation { background: #FEEBC8; color: #7B341E; }
.badge.failed { background: #FED7D7; color: #822727; }

.empty-state {
  text-align: center; padding: 80px 20px; color: var(--text-3);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ---- 抽屉（挤压式布局：滑出时把照片列表往左挤） ---- */
.settings-mask {
  position: fixed; inset: 0;
  background: rgba(26, 32, 44, 0.4);
  backdrop-filter: blur(2px);
  z-index: 40;
}
.drawer {
  height: 100%;
  width: min(440px, 88vw);
  flex-shrink: 0;
  /* 默认用负 margin 完全收起，不占布局空间 */
  margin-right: calc(-1 * min(440px, 88vw));
  background: var(--bg);
  border-left: 1px solid rgba(47, 133, 90, 0.1);
  box-shadow: -8px 0 30px rgba(39, 103, 73, 0.2);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: margin-right 0.28s ease;
}
.drawer.open { margin-right: 0; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid rgba(47, 133, 90, 0.1);
}
.drawer-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 0; }
.drawer-subtitle { font-size: 12px; color: var(--text-3); margin: 2px 0 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

.preview-wrap { position: relative; margin-bottom: 14px; }
.drawer-img {
  width: 100%; height: auto;
  border-radius: var(--radius);
  background: var(--bg-soft);
}
.toggle-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(26, 32, 44, 0.7); color: #fff;
  border: none; backdrop-filter: blur(4px);
}
.toggle-btn:hover { background: rgba(26, 32, 44, 0.9); }

.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-3);
  margin: 16px 0 8px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.ai-field {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; margin-bottom: 8px;
  background: var(--bg-card); border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow);
}
.ai-field .label { color: var(--text-3); min-width: 60px; }
.ai-field .value { color: var(--text); font-weight: 500; }

.desc-text { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.auth-label { margin-top: 14px !important; }
.auth-error { color: var(--danger); font-size: 12px; margin: 10px 0 0; }

/* ---- md 内容 ---- */
.md-content {
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-2);
  background: var(--bg-card);
  border: 1px solid rgba(47, 133, 90, 0.1);
  border-radius: 10px;
  padding: 12px;
  margin: 0;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- 全屏高清图 ---- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.93);
  z-index: 80;
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease;
}
.lightbox img {
  max-width: 96vw; max-height: 96vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6);
}
.lightbox-close {
  position: fixed; top: 18px; right: 26px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s;
  z-index: 81;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.3); }

/* ---- 编辑表单 ---- */
.edit-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-label {
  display: block; font-size: 12px; color: var(--text-3);
  margin: 10px 0 4px;
}
.input {
  width: 100%; padding: 8px 10px;
  border: 1px solid rgba(113, 128, 150, 0.25);
  border-radius: 8px; font-size: 13px;
  background: var(--bg-card); color: var(--text);
  transition: border-color 0.15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(56, 161, 105, 0.15); }
.textarea { resize: vertical; }
.drawer-footer {
  flex-shrink: 0;
  padding: 12px 20px;
  border-top: 1px solid rgba(47, 133, 90, 0.08);
  background: var(--bg);
  display: flex;
  justify-content: flex-end;
}
.inline-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid rgba(47, 133, 90, 0.15);
  border-radius: 6px;
}
.inline-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 161, 105, 0.1);
}
select.inline-input { height: 30px; }

/* ---- 设置弹窗 ---- */
.settings-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 460px; max-width: 92vw; max-height: 85vh;
  background: var(--bg); border-radius: 16px;
  box-shadow: var(--shadow-lg); z-index: 60;
  display: flex; flex-direction: column;
  animation: fadeIn 0.2s ease;
}
.settings-modal.small { width: 380px; }
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; } }
.settings-body { flex: 1; overflow-y: auto; padding: 8px 20px 20px; }
.settings-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid rgba(47, 133, 90, 0.1);
  background: var(--bg-card); border-radius: 0 0 16px 16px;
}

.hidden { display: none !important; }

/* 滚动条美化 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(47, 133, 90, 0.2); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== AI 自然语言检索栏（管理员登录态显示，固定不随照片列表滚动） ===== */
.ai-searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid rgba(47, 133, 90, 0.08);
  flex-shrink: 0;
  z-index: 30;
}
.ai-search-label {
  font-size: 13px; font-weight: 600; color: var(--primary-dark); white-space: nowrap;
}
.ai-search-inner {
  position: relative;
  flex: 1;
  max-width: 620px;
}
.ai-query-input { padding-right: 36px; }
.ai-clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-3); font-size: 13px; line-height: 1;
  border-radius: 6px; cursor: pointer;
  transition: all 0.15s;
}
.ai-clear:hover { background: var(--bg-soft); color: var(--danger); }
#btn-ai-search { flex-shrink: 0; white-space: nowrap; }

/* ===== AI 检索等待遮罩（转圈期间整页不可点击） ===== */
.ai-loading {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(26, 32, 44, 0.45);
  backdrop-filter: blur(2px);
}
.ai-loading-box {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 30px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: 14px;
  min-width: 260px;
}
.ai-spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--bg-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ai-spin 0.9s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

/* AI 检索结果信息条 */
.ai-result-tip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; margin-bottom: 12px;
  font-size: 13px; color: var(--primary-dark);
  background: rgba(47, 133, 90, 0.08);
  border: 1px solid rgba(47, 133, 90, 0.15);
  border-radius: 10px;
}
