/* 物种识别工作台：交互来自 ai.guandie.cn，配色跟观蝶翡翠绿。 */
#ai-app {
  --wb-brand: var(--accent);
  --wb-brand-2: #2ec4b6;
  --wb-brand-deep: var(--accent-hover);
  --wb-soft: #e8f8f1;
  --wb-glow: rgba(0, 171, 107, 0.18);
  --wb-grad: linear-gradient(135deg, #00c27a 0%, #00ab6b 100%);
  --wb-grad-h: linear-gradient(135deg, #2ec4b6 0%, #00925b 100%);
  --wb-amber: #f59e0b;
  --wb-amber-soft: #fffbeb;
  --wb-radius-sm: 8px;
  --wb-radius-md: 12px;
  --wb-radius-lg: 18px;
  padding-bottom: 64px;
}

.workbench-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--wb-radius-lg);
  box-shadow: 0 10px 30px -4px rgba(25, 27, 38, 0.05), 0 2px 6px -1px rgba(25, 27, 38, 0.02);
  overflow: hidden;
}
.wb-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-wrap: wrap;
}
.wb-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 700;
}
.wb-title-wrap svg { color: var(--wb-brand); }

.model-capsule {
  display: inline-flex;
  background: var(--canvas);
  padding: 3px;
  border-radius: var(--pill);
  border: 1px solid var(--line);
}
.model-capsule button {
  height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--pill);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.model-capsule button.on {
  background: var(--surface);
  color: var(--wb-brand-deep);
  box-shadow: 0 1px 2px rgba(25, 27, 38, 0.04);
}
.model-capsule button:disabled { cursor: not-allowed; opacity: 0.4; }

.upload-box { padding: 22px; }
.workbench-card .dropzone {
  position: relative;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  border: 1.5px dashed #cbd5e1;
  border-radius: var(--wb-radius-md);
  background: var(--canvas);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.workbench-card .dropzone:hover,
.workbench-card .dropzone.on {
  border-color: var(--wb-brand);
  background: var(--wb-soft);
  border-style: solid;
}
.workbench-card .dropzone:focus-visible {
  outline: none;
  border-color: var(--wb-brand);
  box-shadow: 0 0 0 3px var(--wb-glow);
}
.workbench-card .drop-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--wb-brand);
  margin: 0 auto 14px;
  box-shadow: 0 4px 12px var(--wb-glow);
  font-size: inherit;
}
.workbench-card .drop-icon svg { width: 24px; height: 24px; }
.workbench-card .dropzone h3 {
  margin: 0 0 6px;
  font-size: 16.5px;
  font-weight: 700;
}
.workbench-card .dropzone p {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: 13px;
}
.drop-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.wb-btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--wb-radius-sm);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.wb-btn svg { width: 15px; height: 15px; }
.wb-btn:hover {
  border-color: rgba(0, 171, 107, 0.4);
  background: var(--canvas);
  color: var(--wb-brand-deep);
}
.wb-btn.primary {
  background: var(--wb-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px -2px rgba(0, 171, 107, 0.32);
}
.wb-btn.primary:hover { background: var(--wb-grad-h); color: #fff; }
.wb-btn.active-amber {
  background: var(--wb-amber);
  color: #fff;
  border-color: var(--wb-amber);
}
.wb-btn:disabled { cursor: not-allowed; opacity: 0.4; }

#resultSlot { border-top: 1px solid var(--line); background: var(--surface); }
.result-placeholder {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.state-panel { padding: 44px 20px; text-align: center; }
.state-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--canvas);
  border-top-color: var(--wb-brand);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: wb-spin 0.75s linear infinite;
}
@keyframes wb-spin { to { transform: rotate(360deg); } }
.state-panel h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.state-panel p { margin: 0; color: var(--ink-2); font-size: 13.5px; }
.state-actions { margin-top: 18px; display: flex; justify-content: center; gap: 10px; }

.result-view { padding: 26px 22px; animation: wb-fade 0.25s ease both; }
@keyframes wb-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.result-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.result-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.result-header .meta-tag {
  font-size: 12px;
  color: var(--ink-2);
  background: var(--canvas);
  padding: 2px 8px;
  border-radius: 4px;
}
.result-disclaimer {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: 13px;
}
.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 24px;
  align-items: start;
}
.stage-wrap { display: flex; flex-direction: column; align-items: center; width: 100%; min-width: 0; }
.stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  border-radius: var(--wb-radius-md);
  overflow: hidden;
  background: #191b26;
  user-select: none;
  touch-action: pan-y;
  border: 1px solid var(--line);
}
.stage.arm { cursor: crosshair; touch-action: none; }
.stage img {
  display: block;
  max-width: 100%;
  max-height: min(72vh, 860px);
  object-fit: contain;
  -webkit-user-drag: none;
}
.corner-bracket {
  position: absolute;
  width: 12px;
  height: 12px;
  pointer-events: none;
  border-color: var(--wb-brand-2);
  border-style: solid;
  opacity: 0.85;
  z-index: 2;
}
.corner-tl { top: 8px; left: 8px; border-width: 2px 0 0 2px; }
.corner-tr { top: 8px; right: 8px; border-width: 2px 2px 0 0; }
.corner-bl { bottom: 8px; left: 8px; border-width: 0 0 2px 2px; }
.corner-br { bottom: 8px; right: 8px; border-width: 0 2px 2px 0; }
.latency-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--pill);
  background: rgba(25, 27, 38, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
}
.latency-pill .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--wb-brand);
}
.target-box {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none;
  border-radius: 4px;
  z-index: 2;
}
.target-box.main {
  border: 2px solid var(--wb-brand-2);
  background: rgba(0, 171, 107, 0.16);
}
.target-box.alt {
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.08);
}
.target-box.manual {
  border: 2px dashed var(--wb-amber);
  background: rgba(245, 158, 11, 0.18);
}
.target-box[data-target] { pointer-events: auto; cursor: pointer; }
.box-label {
  position: absolute;
  left: -1px;
  top: -22px;
  padding: 1px 7px;
  border-radius: 4px;
  color: #fff;
  background: var(--wb-brand);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}
.stage-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
  width: 100%;
}
.hint-text {
  min-height: 16px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.candidate-box { min-width: 0; }
.cautious-banner {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #fef3c7;
  border-radius: var(--wb-radius-sm);
  background: var(--wb-amber-soft);
  text-align: left;
  font-size: 12.5px;
  line-height: 1.5;
  color: #92400e;
}
.cautious-banner svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--wb-amber); }
.candidate-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.candidate-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--wb-radius-md);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.candidate-item:hover {
  border-color: rgba(0, 171, 107, 0.4);
  transform: translateY(-1px);
}
.candidate-item:first-child {
  border-color: rgba(0, 171, 107, 0.35);
  background: #f4fbf8;
}
.rank-num {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  background: var(--canvas);
  font-size: 11px;
  font-weight: 700;
}
.candidate-item:first-child .rank-num { color: #fff; background: var(--wb-grad); }
.cand-info { min-width: 0; }
.cand-info strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cand-info em {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  color: var(--ink-2);
  font-style: italic;
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cand-info .latin-only { font-style: italic; font-weight: 700; font-size: 14.5px; }
.clade-tag {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: 4px;
  color: var(--wb-brand-deep);
  background: var(--wb-soft);
  font-size: 10.5px;
  font-weight: 600;
}
.cand-score { display: flex; flex-direction: column; align-items: flex-end; min-width: 68px; }
.score-val { color: var(--ink); font-size: 14.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.candidate-item:first-child .score-val { color: var(--wb-brand); font-size: 16px; }
.wb-score-bar {
  width: 58px;
  height: 4px;
  background: var(--canvas);
  border-radius: var(--pill);
  margin-top: 4px;
  overflow: hidden;
}
.wb-score-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--wb-brand), var(--wb-brand-2));
  border-radius: var(--pill);
}
.dimmed .candidate-item { opacity: 0.55; }

.recognize-mask {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(25, 27, 38, 0.65);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.recognize-mask[hidden],
#aiErrorModal[hidden] { display: none !important; }
.recognize-modal-card {
  width: min(320px, 88vw);
  background: var(--surface);
  border-radius: var(--wb-radius-lg);
  padding: 30px 22px 26px;
  box-shadow: 0 25px 60px -12px rgba(25, 27, 38, 0.25);
  border: 1px solid var(--line);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bio-scanner-wrap {
  position: relative;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
}
.bio-scanner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(0, 171, 107, 0.15);
  border-top-color: var(--wb-brand);
  border-right-color: var(--wb-brand-2);
  animation: wb-spin 0.9s linear infinite;
}
.bio-scanner-core {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--wb-grad);
  color: #fff;
  display: grid;
  place-items: center;
}
.bio-scanner-core svg { width: 22px; height: 22px; }
.mask-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--pill);
  background: var(--wb-soft);
  border: 1px solid rgba(0, 171, 107, 0.25);
  color: var(--wb-brand-deep);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 10px;
}
.mask-pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--wb-brand);
  animation: wb-pulse 1.5s infinite;
}
@keyframes wb-pulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 171, 107, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(0, 171, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 171, 107, 0); }
}
.recognize-modal-card h3 { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.recognize-modal-card p { margin: 0; color: var(--ink-2); font-size: 13px; line-height: 1.5; }
body.wb-modal-open { overflow: hidden; }

@media (max-width: 768px) {
  .result-grid { grid-template-columns: 1fr; }
  .wb-topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .model-capsule { width: 100%; }
  .model-capsule button { flex: 1; }
}
