:root {
  --bg: #f0f7ff;
  --bg-light: #f8fbff;
  --card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-light: #60a5fa;
  --primary-dark: #2563eb;
  --primary-bg: #dbeafe;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --dot: #3b82f6;
  --shadow: rgba(15, 23, 42, 0.08);
  --shadow-hover: rgba(15, 23, 42, 0.12);
}

* { 
  box-sizing: border-box; 
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 头部样式 */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px var(--shadow);
}

.app-header.floating { 
  position: fixed; 
  width: 100%; 
}

.app-header h1 { 
  font-size: 18px; 
  margin: 0; 
  font-weight: 600; 
  color: var(--text);
  letter-spacing: -0.01em;
}

/* 容器 */
.container { 
  max-width: 1200px; 
  margin: 0 auto; 
  padding: 24px 20px; 
}

.section-title { 
  font-size: 16px; 
  margin: 0 0 16px; 
  color: var(--text);
  font-weight: 600;
}

/* 按钮样式 */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  color: var(--text);
  background: var(--primary-bg);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.button:hover { 
  background: var(--primary-light);
  color: white;
  border-color: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.button:active {
  transform: translateY(0);
}

.button.primary { 
  background: var(--primary); 
  color: white;
  border-color: var(--primary); 
}

.button.primary:hover { 
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

/* 页脚 */
.footer { 
  text-align: center; 
  color: var(--muted); 
  padding: 32px 16px; 
  border-top: 1px solid var(--border-light);
  background: white;
  margin-top: 40px;
}

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

.message { 
  margin-top: 12px; 
  min-height: 24px; 
  font-size: 14px;
  color: var(--text-light);
}

/* 卡片样式 */
.card { 
  background: var(--card); 
  border: 1px solid var(--border-light); 
  border-radius: 16px; 
  padding: 20px; 
  box-shadow: 0 2px 8px var(--shadow);
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 4px 16px var(--shadow-hover);
}

/* 表单 */
.form-grid { 
  display: grid; 
  grid-template-columns: 1fr; 
  gap: 16px; 
}

.form-grid label { 
  display: grid; 
  gap: 8px; 
  font-size: 14px; 
  color: var(--text);
  font-weight: 500;
}

.form-grid input,
.form-grid select { 
  padding: 12px 16px; 
  border-radius: 10px; 
  border: 1px solid var(--border); 
  background: var(--bg-light); 
  color: var(--text);
  font-size: 14px;
  transition: all 0.2s ease;
}

.form-grid input:focus,
.form-grid select:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.row { 
  display: flex; 
  gap: 10px; 
  align-items: center; 
  flex-wrap: wrap;
}

/* 画廊 */
.gallery { 
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); 
  gap: 20px; 
}

.thumb {
  position: relative;
  border: 1px solid var(--border-light);
  border-radius: 16px;
  overflow: hidden;
  background: white;
  transition: all 0.3s ease;
  cursor: pointer;
}

.thumb:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--shadow-hover);
  border-color: var(--primary-light);
}

.thumb img { 
  width: 100%; 
  height: 200px; 
  object-fit: cover; 
  display: block;
  transition: transform 0.3s ease;
}

.thumb:hover img {
  transform: scale(1.05);
}

.thumb .thumb-title { 
  padding: 14px 16px; 
  font-size: 14px; 
  border-top: 1px solid var(--border-light); 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  gap: 8px;
  background: white;
}

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

.thumb .dot { 
  position: absolute; 
  width: 10px; 
  height: 10px; 
  border-radius: 50%; 
  transform: translate(-50%, -50%); 
  outline: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.empty-hint { 
  color: var(--text-light); 
  text-align: center; 
  padding: 48px 24px;
  background: white;
  border-radius: 16px;
  border: 1px dashed var(--border);
}

/* 查看器 */
.viewer-body { 
  padding-top: 0;
}

.viewer { 
  height: 100vh;
  overflow: hidden;
}

.viewer-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 280px auto 280px 1fr;
  gap: 0;
  background: var(--bg-light);
}

.viewer-container #factoryListPanel {
  grid-column: 1;
}

.viewer-container #factoryInfoPanel {
  grid-column: 2;
}

.viewer-container #factoryInfoPanel[style*="display: none"] {
  width: 0;
  min-width: 0;
  max-width: 0;
  overflow: hidden;
  padding: 0;
  border: none;
}

.viewer-container #factoryInfoPanel:not([style*="display: none"]) {
  width: 280px;
  min-width: 280px;
  max-width: 280px;
}

.viewer-container #pointListPanel {
  grid-column: 3;
}

.viewer-container #mapArea {
  grid-column: 4;
  min-width: 0; /* 允许 grid 项目缩小 */
  width: 100%;
}

.viewer-container img { 
  max-width: 100%; 
  max-height: 100%; 
  object-fit: contain; 
  position: absolute;
  transition: transform 0.1s ease-out;
}

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

.overlay * {
  pointer-events: auto;
}

/* 点位样式 */
.dot { 
  position: absolute; 
  width: 20px; 
  height: 20px; 
  border-radius: 50%; 
  transform: translate(-50%, -50%); 
  outline: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 8px var(--shadow), 0 0 0 2px rgba(59, 130, 246, 0.2);
  border: 2px solid white;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
}

.dot:hover {
  transform: translate(-50%, -50%) scale(1.2);
  z-index: 20;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4), 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.dot.pulse { 
  animation: pulse 2s infinite ease-in-out;
}

.dot.pulse-strong { 
  animation: pulseStrong 1s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { 
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4),
                0 2px 8px var(--shadow),
                0 0 0 2px rgba(59, 130, 246, 0.2);
  }
  50% { 
    box-shadow: 0 0 0 12px rgba(59, 130, 246, 0),
                0 2px 8px var(--shadow),
                0 0 0 2px rgba(59, 130, 246, 0.2);
  }
}

@keyframes pulseStrong {
  0%, 100% { 
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.6),
                0 4px 16px rgba(59, 130, 246, 0.3),
                0 0 0 4px rgba(59, 130, 246, 0.25);
  }
  50% { 
    box-shadow: 0 0 0 20px rgba(59, 130, 246, 0),
                0 4px 16px rgba(59, 130, 246, 0.3),
                0 0 0 4px rgba(59, 130, 246, 0.25);
  }
}

.dot.square { 
  border-radius: 6px; 
}

.dot.triangle { 
  width: 0; 
  height: 0; 
  border: none; 
  outline: none; 
  box-shadow: none; 
  border-left: 12px solid transparent; 
  border-right: 12px solid transparent; 
  border-bottom: 20px solid var(--dot);
  background: none;
  transform: translate(-50%, -50%);
}

.dot.star { 
  position: absolute; 
  width: 0; 
  height: 0; 
  color: var(--dot);
  background: none;
  border: none;
  outline: none;
}

.dot.star::before { 
  content: "★"; 
  font-size: 24px; 
  color: var(--dot); 
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.8));
}

/* 工具提示 */
.tooltip { 
  position: absolute; 
  min-width: 280px; 
  max-width: min(420px, 85vw); 
  background: white; 
  color: var(--text); 
  border: 2px solid var(--primary-light); 
  border-radius: 16px; 
  padding: 16px 20px; 
  font-size: 15px; 
  pointer-events: none; 
  box-shadow: 0 12px 32px var(--shadow-hover);
  animation: tooltip-pop 0.2s ease-out;
  z-index: 1000;
  backdrop-filter: blur(8px);
}

.tooltip h4 { 
  margin: 0 0 8px; 
  font-size: 16px; 
  font-weight: 600;
  color: var(--text);
}

.tooltip .muted { 
  font-size: 13px; 
  margin-top: 4px;
}

@keyframes tooltip-pop { 
  from { 
    transform: translateY(8px) scale(0.96); 
    opacity: 0; 
  } 
  to { 
    transform: translateY(0) scale(1); 
    opacity: 1; 
  } 
}

/* 控制面板 */
.control-panel { 
  position: absolute; 
  right: 16px; 
  top: 72px; 
  background: rgba(255, 255, 255, 0.98); 
  border: 1px solid var(--border-light); 
  border-radius: 12px; 
  padding: 12px; 
  box-shadow: 0 8px 24px var(--shadow-hover);
  display: grid; 
  gap: 12px; 
  min-width: 240px;
  backdrop-filter: blur(12px);
  z-index: 50;
}

/* 后台管理按钮 */
.admin-button {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 4px 12px var(--shadow-hover);
  backdrop-filter: blur(12px);
  z-index: 100;
  transition: all 0.2s ease;
  cursor: pointer;
}

.admin-button:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}

.admin-button:active {
  transform: scale(0.95);
}

.control-panel label { 
  color: var(--text); 
  font-size: 13px; 
  display: grid; 
  gap: 8px;
  font-weight: 500;
}

.control-panel select, 
.control-panel input[type="checkbox"] { 
  padding: 8px 12px; 
  border-radius: 8px; 
  border: 1px solid var(--border); 
  background: var(--bg-light);
  font-size: 13px;
}

.control-panel input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* 管理页面 */
.admin-grid { 
  display: grid; 
  grid-template-columns: 360px 1fr; 
  gap: 24px; 
}

.admin-topbar { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 16px; 
}

.admin-left, 
.admin-right { 
  background: var(--card); 
  border: 1px solid var(--border-light); 
  border-radius: 16px; 
  padding: 20px; 
  box-shadow: 0 2px 8px var(--shadow);
}

.admin-left h3,
.admin-right h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-light);
}

.editor { 
  display: grid; 
  grid-template-rows: auto auto auto 1fr; 
  gap: 16px; 
}

.editor-canvas { 
  position: relative; 
  width: 100%; 
  height: 70vh; 
  min-height: 400px;
  border: 2px dashed var(--border); 
  border-radius: 16px; 
  overflow: hidden; 
  background: var(--bg-light); 
  display: grid; 
  place-items: center;
  transition: border-color 0.2s ease;
}

.editor-canvas:hover {
  border-color: var(--primary-light);
}

.editor-canvas img { 
  max-width: 100%; 
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain; 
  position: absolute;
  transition: transform 0.1s ease-out;
}

.editor-canvas #editorOverlay {
  position: absolute;
  pointer-events: auto;
  z-index: 1;
}

.list { 
  list-style: none; 
  padding: 0; 
  margin: 12px 0 0; 
  display: grid; 
  gap: 10px; 
}

.list li { 
  border: 1px solid var(--border-light); 
  border-radius: 12px; 
  padding: 12px 14px; 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  gap: 12px;
  background: white;
  transition: all 0.2s ease;
}

.list li:hover {
  background: var(--bg-light);
  border-color: var(--primary-light);
  transform: translateX(2px);
}

.badge { 
  display: inline-flex; 
  align-items: center; 
  gap: 6px; 
  font-size: 12px; 
  color: var(--text-light);
  font-weight: 500;
}

.badge .swatch { 
  width: 12px; 
  height: 12px; 
  border-radius: 50%; 
  display: inline-block;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.poi-item { 
  cursor: pointer; 
  transition: all 0.2s ease;
}

.poi-item:hover { 
  background: var(--primary-bg);
  border-color: var(--primary-light);
}

.poi-item.active {
  background: var(--primary-bg);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* 旋转动画 */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .admin-grid { 
    grid-template-columns: 1fr; 
  }
  
  .viewer-container {
    grid-template-columns: 240px auto 240px 1fr;
  }
  
  #factoryInfoPanel {
    display: none !important;
  }
  
  .viewer-container #pointListPanel {
    grid-column: 3;
  }
  
  .viewer-container #mapArea {
    grid-column: 4;
  }
  
  .control-panel {
    min-width: 200px;
    right: 12px;
    top: 64px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 16px;
  }
  
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
  }
  
  .viewer-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr;
  }
  
  .viewer-container #factoryListPanel {
    grid-row: 1;
    max-height: 150px;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-light);
    border-radius: 0;
    border-right: none;
  }
  
  .viewer-container #factoryInfoPanel {
    grid-row: 2;
    max-height: 150px;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-light);
    border-radius: 0;
    border-right: none;
  }
  
  .viewer-container #pointListPanel {
    grid-row: 3;
    max-height: 200px;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-light);
    border-radius: 0;
    border-right: none;
  }
  
  .viewer-container #mapArea {
    grid-row: 4;
  }
  
  .legend-panel {
    position: fixed !important;
    top: 60px !important;
    right: 12px !important;
    left: auto !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 80px) !important;
  }
  
  .control-panel {
    position: fixed;
    bottom: 16px;
    right: 16px;
    top: auto;
    min-width: auto;
    max-width: calc(100vw - 32px);
    font-size: 12px;
  }
  
  .admin-button {
    width: 44px;
    height: 44px;
    left: 12px;
    bottom: 12px;
  }
  
  .admin-button svg {
    width: 18px;
    height: 18px;
  }
  
  .app-header {
    padding: 12px 16px;
  }
  
  .app-header h1 {
    font-size: 16px;
  }
  
  .button {
    padding: 8px 12px;
    font-size: 13px;
    touch-action: manipulation;
  }
  
  .card {
    padding: 16px;
  }
  
  .tooltip {
    min-width: 240px;
    max-width: calc(100vw - 32px);
    font-size: 14px;
    padding: 12px 16px;
    left: 50% !important;
    transform: translateX(-50%);
    right: auto !important;
  }
  
  .admin-left,
  .admin-right {
    padding: 16px;
  }
  
  .editor-canvas {
    height: 60vh;
    min-height: 300px;
  }
  
  .dot {
    width: 24px;
    height: 24px;
    touch-action: manipulation;
  }
  
  .zoom-hint {
    font-size: 11px;
    padding: 6px 10px;
  }
}

@media (max-width: 480px) {
  .gallery {
    grid-template-columns: 1fr;
  }
  
  .thumb img {
    height: 180px;
  }
  
  .viewer-container #factoryListPanel {
    max-height: 120px;
  }
  
  .viewer-container #factoryInfoPanel {
    max-height: 100px;
  }
  
  .viewer-container #pointListPanel {
    max-height: 150px;
  }
  
  .legend-panel {
    top: 60px !important;
    right: 8px !important;
    left: 8px !important;
    max-width: calc(100vw - 16px) !important;
    font-size: 11px;
    padding: 8px 10px;
  }
  
  .legend-panel h4 {
    font-size: 11px;
    margin-bottom: 6px;
  }
  
  .legend-panel #legendContent {
    gap: 8px 12px !important;
  }
  
  .control-panel {
    bottom: 12px;
    right: 12px;
    left: 12px;
    max-width: none;
    padding: 10px;
    gap: 8px;
  }
  
  .control-panel label {
    font-size: 12px;
  }
  
  .row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .row .button {
    width: 100%;
  }
  
  .tooltip {
    min-width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    font-size: 13px;
    padding: 10px 14px;
  }
  
  .app-header {
    padding: 10px 12px;
  }
  
  .app-header h1 {
    font-size: 15px;
  }
}

/* 加载动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}
