:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e5e9f0;
  --text: #17201c;
  --text-muted: #64748b;
  --accent: #14b8a6;
  --accent-strong: #0d9488;
  --sidebar-bg: #16211c;
  --sidebar-text: #e7f0eb;
  --sidebar-muted: #8aa397;
  --shadow: 0 10px 30px rgba(23, 32, 28, 0.06);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* ---------- 整体布局 ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  width: 100%;
  min-height: 74px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  padding: 12px 32px;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  flex: 0 0 auto;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 11px;
}

.brand strong {
  display: block;
  font-size: 17px;
  letter-spacing: 0.5px;
}

.brand span {
  display: block;
  font-size: 12px;
  color: var(--sidebar-muted);
  margin-top: 2px;
}

.nav-list {
  display: flex;
  flex-direction: row;
  gap: 6px;
  margin: 0;
  justify-content: center;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: auto;
  padding: 10px 16px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--sidebar-muted);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.18s ease, color 0.18s ease;
}

.nav-item svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-text);
}

.nav-item.active {
  background: rgba(20, 184, 166, 0.16);
  color: #5eead4;
}

.sidebar-footer {
  margin-top: 0;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 10px 4px;
  font-size: 12px;
  color: var(--sidebar-muted);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}

/* ---------- 主工作区 ---------- */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px 18px;
}

.topbar-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.access-control { display: flex; gap: 8px; align-items: center; }
.access-control input { width: 180px; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 10px; font: inherit; }
.token-button { flex: 0 0 auto; padding: 9px 12px; font-size: 12px; }

.api-badge {
  padding: 6px 12px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
  font-size: 12px;
  font-weight: 600;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.18s ease, border-color 0.18s ease;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  color: var(--accent-strong);
  border-color: var(--accent);
}

/* ---------- 页面切换 ---------- */
.page {
  display: none;
  padding: 0 32px 32px;
}

.page.active {
  display: block;
}

.page-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-intro h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.page-intro p {
  margin: 0;
  color: var(--text-muted);
}

/* ---------- 模式切换 ---------- */
.mode-switch {
  display: inline-flex;
  padding: 4px;
  background: #e9edf2;
  border-radius: 12px;
  gap: 4px;
}

.mode-button {
  padding: 8px 18px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.mode-button.active {
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(23, 32, 28, 0.08);
}

/* ---------- 面板 ---------- */
.workspace-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 22px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-eyebrow {
  display: block;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.panel-heading h3 {
  margin: 0;
  font-size: 17px;
}

/* ---------- 上传区 ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 34px 18px;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.dropzone svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 4px;
}

.dropzone strong {
  font-size: 15px;
}

.dropzone span {
  color: var(--text-muted);
  font-size: 12px;
}

.dropzone.dragging,
.dropzone:hover {
  border-color: var(--accent);
  background: #f0fdfa;
}

.file-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 14px;
  background: #fafbfc;
}

.file-meta svg {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-meta div {
  min-width: 0;
  flex: 1;
}

.file-meta strong {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta span {
  font-size: 12px;
  color: var(--text-muted);
}

.clear-button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.clear-button:hover {
  color: #ef4444;
}

.action-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.18s ease, transform 0.08s ease;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button.secondary {
  flex: 1;
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
}

.button.secondary:hover {
  border-color: var(--accent);
}

.button.primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.upload-note {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f1f5f9;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.upload-note p {
  margin: 0;
}

.info-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cbd5e1;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  margin-top: 1px;
}

/* ---------- 结果区 ---------- */
.result-panel {
  min-height: 480px;
}

.result-summary {
  display: flex;
  align-items: center;
  gap: 10px;
}

.domain-badge,
#countBadge {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.domain-badge {
  background: #eef2ff;
  color: #4338ca;
}

#countBadge {
  background: #fff7ed;
  color: #c2410c;
}

.result-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

.media-stage {
  position: relative;
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0f1411;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state {
  text-align: center;
  color: #9ca3af;
  padding: 40px 20px;
}

.empty-illustration svg {
  width: 52px;
  height: 52px;
  fill: none;
  stroke: #475569;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 14px;
}

.empty-state strong {
  display: block;
  color: #d1d5db;
  font-size: 15px;
  margin-bottom: 6px;
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

.loading-state {
  text-align: center;
  color: #d1d5db;
  padding: 40px 20px;
}

.loader {
  width: 38px;
  height: 38px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: #5eead4;
  animation: spin 0.8s linear infinite;
}

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

.loading-state strong {
  display: block;
  font-size: 15px;
  margin-bottom: 4px;
}

.loading-state span {
  font-size: 13px;
  color: #9ca3af;
}

.media-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 24px;
}

.media-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.media-element {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.overlay-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---------- 结果明细 ---------- */
.result-aside {
  min-width: 0;
}

.aside-placeholder {
  padding: 26px 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

.result-detail {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-item {
  padding: 12px;
  border-radius: 11px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.stat-item span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-item strong {
  font-size: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 12px;
  cursor: pointer;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.detection-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
}

.detection-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.detection-item-main {
  flex: 1;
  min-width: 0;
}

.detection-item-main strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.detection-item-main span {
  font-size: 11px;
  color: var(--text-muted);
}

.confidence {
  font-size: 13px;
  font-weight: 700;
}

.empty-table {
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- 地图 ---------- */
.map-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 22px;
  align-items: start;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.map-stage {
  position: relative;
  height: 460px;
  border-radius: 12px;
  background: #eef2f5;
  overflow: hidden;
}

.map-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(100, 116, 139, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 116, 139, 0.12) 1px, transparent 1px);
  background-size: 40px 40px;
}

.map-road {
  position: absolute;
  background: #d7dde3;
  border-radius: 999px;
}

.road-one {
  top: 50%;
  left: -5%;
  width: 110%;
  height: 22px;
  transform: translateY(-50%) rotate(-8deg);
}

.road-two {
  top: -5%;
  left: 30%;
  width: 22px;
  height: 110%;
  transform: rotate(12deg);
}

.map-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: transform 0.12s ease;
}

.map-marker:hover,
.map-marker.active {
  transform: translate(-50%, -50%) scale(1.35);
}

.detail-card h4 {
  margin: 0 0 12px;
  font-size: 16px;
  display: flex;
  align-items: center;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-row span:first-child {
  color: var(--text-muted);
}

/* ---------- 台账 ---------- */
.ledger-panel {
  padding: 0;
  overflow: hidden;
}

.ledger-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfc;
  min-width: 220px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-box input {
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
  width: 100%;
}

.table-wrap {
  overflow: auto;
}

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

.data-table th,
.data-table td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.domain-label {
  color: var(--text-muted);
}

.class-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1f5f9;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 16px);
  padding: 12px 20px;
  border-radius: 12px;
  background: #17201c;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .workspace-grid,
  .result-layout,
  .map-layout {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 680px) {
  .app-shell { display: block; min-width: 0; }
  .sidebar { width: 100%; min-height: auto; padding: 10px 12px; flex-direction: row; align-items: center; gap: 10px; overflow-x: auto; }
  .brand { flex: 0 0 auto; padding: 0; }
  .brand div:last-child { display: none; }
  .brand-mark { width: 38px; height: 38px; }
  .nav-list { flex: 1; flex-direction: row; margin: 0; gap: 4px; }
  .nav-item { flex: 1; min-width: 76px; justify-content: center; padding: 9px 6px; }
  .nav-item span { display: block; font-size: 12px; }
  .sidebar-footer { display: none; }
  .topbar { align-items: flex-start; gap: 14px; padding: 16px; }
  .topbar-actions { align-items: flex-end; flex-direction: column-reverse; }
  .access-control input { width: 146px; }
  .api-badge, .icon-button { display: none; }
  .page { padding: 0 16px 24px; }
  .page-intro, .ledger-toolbar { align-items: stretch; flex-direction: column; gap: 14px; }
  .page-intro .button { width: 100%; }
  .mode-switch { width: 100%; }
  .mode-button { flex: 1; padding: 9px 8px; }
  .panel { padding: 16px; border-radius: 13px; }
  .workspace-grid, .map-layout { gap: 16px; }
  .result-panel { min-height: 0; }
  .media-stage { min-height: 230px; }
  .media-wrap { padding: 12px; }
  .search-box { min-width: 0; width: 100%; }
  .map-stage { height: 320px; }
  .ledger-toolbar { padding: 14px; }
  .table-wrap { margin: 0 -16px; }
  .data-table th, .data-table td { padding: 11px 12px; }
}
