/* ===== 全局 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1976d2;
  --primary-dark: #1565c0;
  --success: #4caf50;
  --warning: #ff9800;
  --danger: #f44336;
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --text: #222;
  --text-muted: #999;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.04);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  max-width: 750px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 70px;
}
.hidden { display: none !important; }

/* ===== 顶部 ===== */
.app-header {
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(25,118,210,0.25);
}
.header-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 22px; }
.title { font-size: 17px; font-weight: 600; }
.header-right { display: flex; gap: 8px; }
.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,0.3); }

/* ===== 主区 ===== */
.app-main { padding: 16px; }
.view { animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.view-header { margin-bottom: 16px; }
.view-header h2 { font-size: 18px; margin-bottom: 12px; }
.filter-bar { display: flex; gap: 8px; }
.filter-select {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
}

/* ===== 列表 ===== */
.hazard-list { display: flex; flex-direction: column; gap: 12px; }
.hazard-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s;
}
.hazard-card:active { transform: scale(0.98); }
.hazard-card-row { display: flex; justify-content: space-between; align-items: flex-start; }
.hazard-card-title { font-size: 15px; font-weight: 600; flex: 1; margin-right: 10px; }
.hazard-card-meta { display: flex; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.hazard-card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ===== 标签 ===== */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.tag-red { background: #f44336; }
.tag-orange { background: #ff9800; }
.tag-blue { background: #2196f3; }
.tag-gray { background: #9e9e9e; }
.tag-green { background: #4caf50; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, #1976d2, #1565c0); color: #fff; }
.btn-warning { background: linear-gradient(135deg, #f57c00, #ff9800); color: #fff; }
.btn-success { background: linear-gradient(135deg, #43a047, #2e7d32); color: #fff; }
.btn-info { background: linear-gradient(135deg, #1976d2, #2196f3); color: #fff; }
.btn-purple { background: linear-gradient(135deg, #7b1fa2, #9c27b0); color: #fff; }
.btn-secondary { background: #f0f0f0; color: #555; }
.btn-full { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== 详情 ===== */
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 15px;
  cursor: pointer;
  margin-bottom: 12px;
  padding: 4px 0;
}
.hazard-detail { background: #fff; border-radius: 12px; padding: 16px; }
.detail-section { padding: 12px 0; border-top: 1px solid var(--border); }
.detail-section:first-child { border-top: none; padding-top: 0; }
.detail-section h3 { font-size: 15px; margin-bottom: 8px; color: var(--primary); }
.detail-section p { color: #555; line-height: 1.6; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.detail-row { display: flex; gap: 8px; }
.detail-key { color: var(--text-muted); min-width: 60px; }
.detail-val { color: var(--text); flex: 1; }
.regulation-box {
  background: #f8f9fa;
  border-left: 3px solid var(--primary);
  padding: 10px;
  border-radius: 4px;
  font-size: 13px;
  white-space: pre-wrap;
  font-family: "PingFang SC", "Microsoft YaHei", monospace;
}
.compare-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare-img-wrap { text-align: center; }
.compare-img-label { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.compare-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #f0f0f0; }

/* ===== 表单 ===== */
.form { background: #fff; border-radius: 12px; padding: 16px; }
.form-section { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px dashed var(--border); }
.form-section:last-child { border: none; margin-bottom: 0; }
.form-label { font-size: 14px; font-weight: 600; margin-bottom: 8px; display: block; }
.form-input, .form-textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.form-textarea { min-height: 100px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== 加载 ===== */
.loading { display: flex; flex-direction: column; align-items: center; padding: 40px 0; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid #e0e0e0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 12px; color: var(--text-muted); }

/* ===== 底部 Tab ===== */
.app-tabbar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  max-width: 750px;
  margin: 0 auto;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.tab-item {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  color: var(--text-muted);
  cursor: pointer;
}
.tab-item.active { color: var(--primary); }
.tab-icon { display: block; font-size: 22px; }
.tab-text { font-size: 11px; }

/* ===== 模态 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
}
.modal-content h3 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; padding: 10px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 300;
  animation: toastIn 0.3s;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== 统计 ===== */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card-num { font-size: 28px; font-weight: 700; }
.stat-card-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-red .stat-card-num { color: var(--danger); }
.stat-orange .stat-card-num { color: var(--warning); }
.stat-blue .stat-card-num { color: var(--primary); }
.stat-green .stat-card-num { color: var(--success); }

/* 统计页扩展 */
.stats-content { padding: 12px; }
.stats-section {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.stats-section h3 {
  font-size: 15px;
  margin: 0 0 12px 0;
  color: var(--text);
}
.stats-overview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.overview-item {
  text-align: center;
  padding: 8px;
  background: #f8f9fb;
  border-radius: 8px;
}
.overview-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.overview-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.level-bar { display: flex; flex-direction: column; gap: 10px; }
.level-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.level-bar-label {
  width: 80px;
  flex-shrink: 0;
  color: var(--text);
}
.level-bar-track {
  flex: 1;
  height: 22px;
  background: #f0f0f5;
  border-radius: 11px;
  overflow: hidden;
  position: relative;
}
.level-bar-fill {
  height: 100%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  font-weight: 600;
  transition: width 0.3s;
  border-radius: 11px;
  min-width: 24px;
}
.bar-red { background: var(--danger); }
.bar-orange { background: var(--warning); }
.bar-blue { background: var(--primary); }
.bar-gray { background: #999; }

.top-hazards {
  list-style: none;
  padding: 0;
  margin: 0;
}
.top-hazards li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid #f0f0f5;
  font-size: 13px;
}
.top-hazards li:last-child { border-bottom: none; }
.top-hazard-title { color: var(--text); }
.top-hazard-count {
  background: var(--danger);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

/* AI 识别页 */
.ai-result-card {
  background: #fff;
  border: 2px solid #4caf50;
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
}
.ai-result-card h3 {
  margin: 0 0 12px 0;
  color: #4caf50;
}
.ai-result-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px dashed #eee;
  font-size: 13px;
  align-items: flex-start;
}
.ai-result-row:last-child { border-bottom: none; }
.ai-label {
  width: 80px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.ai-value {
  flex: 1;
  color: var(--text);
  word-break: break-word;
}

.ai-hazard-item {
  background: #f8f9fb;
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  margin: 8px 0;
  border-radius: 6px;
}

/* ===== 上传占位 ===== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
}
.upload-area:hover { border-color: var(--primary); color: var(--primary); }
.photo-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.photo-preview img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #f0f0f0;
}

/* ===== 对比模式切换 ===== */
.mode-switcher { display: flex; gap: 8px; margin-bottom: 12px; }
.mode-btn {
  flex: 1;
  padding: 8px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.mode-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.slider-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 12px;
  overflow: hidden;
  background: #f0f0f0;
  user-select: none;
}
.slider-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.slider-after-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.slider-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 6px rgba(0,0,0,0.4);
  transform: translateX(-50%);
  cursor: ew-resize;
}
.slider-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.slider-tag {
  position: absolute;
  top: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}
.slider-tag.left { left: 8px; background: rgba(220,38,38,0.85); }
.slider-tag.right { right: 8px; background: rgba(21,128,61,0.85); }
