*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --sidebar-bg: #1e293b;
  --sidebar-w: 220px;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #3b82f6;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #6366f1;
  --ok-bg: #ecfdf5; --ok-border: #6ee7b7; --ok-text: #065f46;
  --hi-bg: #fef2f2; --hi-border: #fca5a5; --hi-text: #991b1b;
  --lo-bg: #eff6ff; --lo-border: #93c5fd; --lo-text: #1e40af;
  --nd-bg: #f9fafb; --nd-border: #d1d5db; --nd-text: #374151;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Mobile Header ── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--sidebar-bg);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.mobile-logo { color: #fff; font-size: 16px; font-weight: 700; }

/* ── Mobile Bottom Nav ── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--sidebar-bg);
  border-top: 1px solid rgba(255,255,255,.08);
  z-index: 100;
}
.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #64748b;
  font-size: 11px;
  cursor: pointer;
  transition: color .2s;
  padding: 6px 0;
}
.mobile-nav-item span:first-child { font-size: 20px; }
.mobile-nav-item.active { color: #60a5fa; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-icon { font-size: 28px; }
.logo-title { color: #fff; font-size: 15px; font-weight: 700; }
.logo-sub { color: #94a3b8; font-size: 11px; margin-top: 1px; }

.sidenav { flex: 1; padding: 12px 8px; }
.sidenav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  font-size: 14px;
  transition: all .2s;
  margin-bottom: 2px;
  user-select: none;
}
.sidenav-item:hover { background: rgba(255,255,255,.07); color: #e2e8f0; }
.sidenav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: #64748b;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.status-dot {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; } 50% { opacity: .4; }
}

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

/* ── Page ── */
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Card ── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Capture grid ── */
.capture-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 860px) { .capture-grid { grid-template-columns: 1fr; } }

/* ── Source switch ── */
.source-switch { display: flex; gap: 6px; margin-bottom: 14px; }
.switch-btn {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: all .2s;
}
.switch-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ── Video ── */
.video-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #0f172a;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
#camera-feed { width: 100%; height: 100%; object-fit: cover; display: none; }
#cam-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: #94a3b8;
}

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 12px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}
.drop-text { font-size: 14px; font-weight: 500; color: var(--text); margin: 8px 0 4px; }
.drop-hint { font-size: 12px; color: var(--text-muted); }

/* ── Preview ── */
.preview-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }
.preview-img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f9fafb;
  margin-bottom: 10px;
  display: block;
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: #2563eb; }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled)  { background: #059669; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #dc2626; }
.btn-ghost    { background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover { background: var(--border); }
.btn-ai       { background: #6366f1; color: #fff; }
.btn-ai:hover { background: #4f46e5; }
.btn-submit   { width: 100%; padding: 12px; font-size: 15px; background: var(--primary); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-weight: 700; margin-top: 8px; transition: background .15s; }
.btn-submit:hover { background: #2563eb; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Fields ── */
.field-group { margin-bottom: 14px; }
.field-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.field {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.field-row { display: flex; gap: 8px; }
.field-sel { flex: 0 0 140px; }

/* ── Temp big input ── */
.temp-input-wrap { position: relative; }
.temp-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 48px 14px 16px;
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  transition: border-color .2s;
}
.temp-input:focus { outline: none; border-color: var(--primary); }
.temp-unit {
  position: absolute;
  right: 14px; top: 50%;
  transform: translateY(-50%);
  font-size: 16px; font-weight: 700;
  color: var(--text-muted);
}

/* ── AI banner ── */
.ai-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  font-size: 13px;
}
.ai-banner-title { font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.ai-loading {
  display: flex; flex-direction: column; align-items: center;
  padding: 30px; gap: 12px; color: var(--text-muted);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.submit-ok {
  margin-top: 12px;
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  color: var(--ok-text);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  font-weight: 600;
}

/* ── Stat row ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 700px) { .stat-row { grid-template-columns: repeat(3,1fr); } }
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card.ok { border-top: 3px solid var(--success); }
.stat-card.hi { border-top: 3px solid var(--danger); }
.stat-card.lo { border-top: 3px solid var(--primary); }
.stat-card.nd { border-top: 3px solid #9ca3af; }
.stat-n { font-size: 36px; font-weight: 800; color: var(--text); }
.stat-card.ok .stat-n { color: var(--success); }
.stat-card.hi .stat-n { color: var(--danger); }
.stat-card.lo .stat-n { color: var(--primary); }
.stat-card.nd .stat-n { color: #9ca3af; }
.stat-l { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ── Point Grid ── */
.point-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.pt-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border-left: 4px solid #e5e7eb;
  transition: transform .15s, box-shadow .15s;
}
.pt-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.1); }
.pt-card.ok { border-left-color: var(--success); background: linear-gradient(135deg,#fff 60%,#ecfdf5); }
.pt-card.hi { border-left-color: var(--danger);  background: linear-gradient(135deg,#fff 60%,#fef2f2); }
.pt-card.lo { border-left-color: var(--primary); background: linear-gradient(135deg,#fff 60%,#eff6ff); }
.pt-card.nd { border-left-color: #d1d5db; }

.pt-name { font-size: 15px; font-weight: 700; color: var(--text); }
.pt-desc { font-size: 12px; color: var(--text-muted); margin: 2px 0 12px; }
.pt-temp { font-size: 42px; font-weight: 900; letter-spacing: -1px; line-height: 1; }
.pt-card.ok .pt-temp { color: var(--success); }
.pt-card.hi .pt-temp { color: var(--danger); }
.pt-card.lo .pt-temp { color: var(--primary); }
.pt-card.nd .pt-temp { color: #d1d5db; }

.pt-std { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.pt-diff { font-size: 13px; font-weight: 600; margin-top: 4px; }
.pt-card.ok .pt-diff { color: var(--success); }
.pt-card.hi .pt-diff { color: var(--danger); }
.pt-card.lo .pt-diff { color: var(--primary); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 10px;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-border); }
.badge-hi { background: var(--hi-bg); color: var(--hi-text); border: 1px solid var(--hi-border); }
.badge-lo { background: var(--lo-bg); color: var(--lo-text); border: 1px solid var(--lo-border); }
.badge-nd { background: var(--nd-bg); color: var(--nd-text); border: 1px solid var(--nd-border); }

.pt-mini { height: 44px; margin-top: 12px; }
.pt-time { font-size: 11px; color: #9ca3af; margin-top: 8px; }

/* ── Chart ── */
.chart-wrap { height: 300px; position: relative; }

/* ── Data Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f3f4f6;
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.empty-row { text-align: center; color: var(--text-muted); padding: 32px !important; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.tag-ok { background: var(--ok-bg); color: var(--ok-text); }
.tag-hi { background: var(--hi-bg); color: var(--hi-text); }
.tag-lo { background: var(--lo-bg); color: var(--lo-text); }
.tag-nd { background: var(--nd-bg); color: var(--nd-text); }

.conf-high { color: var(--success); font-weight: 600; }
.conf-mid  { color: var(--warning); font-weight: 600; }
.conf-low  { color: var(--danger);  font-weight: 600; }

/* ── Form card ── */
.form-card { border-top: 3px solid var(--primary); }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Misc ── */
.auto-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer; }

/* ── History Layout ── */
.history-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 700px) { .history-layout { grid-template-columns: 1fr; } }

.history-sidebar {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 24px;
}
.history-sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.history-point-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  transition: background .15s;
  gap: 8px;
}
.history-point-item:last-child { border-bottom: none; }
.history-point-item:hover { background: #f8fafc; }
.history-point-item.active {
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  padding-left: 13px;
}
.history-point-item.active .hpi-name { color: var(--primary); font-weight: 700; }

.hpi-name { font-size: 14px; font-weight: 500; color: var(--text); }
.hpi-count {
  font-size: 11px;
  background: var(--bg);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}
.history-point-item.active .hpi-count { background: #dbeafe; color: var(--primary); }

.hpi-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-ok  { background: var(--success); }
.dot-hi  { background: var(--danger); }
.dot-lo  { background: var(--primary); }
.dot-nd  { background: #d1d5db; }

/* ── History Detail ── */
.history-detail { min-width: 0; }

.history-detail-header {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.history-detail-name { font-size: 20px; font-weight: 800; color: var(--text); }
.history-detail-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.history-detail-stats { display: flex; gap: 20px; }
.hds-item { text-align: center; }
.hds-val { font-size: 22px; font-weight: 800; }
.hds-lbl { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.history-chart-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  height: 200px;
  position: relative;
}

/* ── Modal ── */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--card-bg);
  border-radius: 14px;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  animation: slide-up .2s ease;
}
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.modal-close:hover { background: var(--bg); }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 14px 14px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.toast.ok { background: var(--success); }
.toast.err { background: var(--danger); }

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .mobile-nav { display: flex; }
  .sidebar { display: none; }

  .main {
    margin-left: 0;
    padding: 12px;
    padding-top: 64px;
    padding-bottom: 72px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
  }
  .page-header h1 { font-size: 17px; }
  .page-header p  { font-size: 12px; }

  /* 采集页 */
  .capture-grid { grid-template-columns: 1fr; gap: 12px; }

  .source-switch { gap: 6px; }
  .switch-btn { font-size: 12px; padding: 7px 8px; }

  .video-box { aspect-ratio: 4/3; }

  .temp-input { font-size: 22px; padding: 12px 40px 12px 12px; }
  .temp-unit  { font-size: 14px; }

  .field-row { flex-direction: column; }
  .field-sel  { flex: none; width: 100%; }

  .btn-submit { font-size: 14px; padding: 11px; }

  /* 仪表盘 */
  .dashboard-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .stat-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-n   { font-size: 26px; }
  .stat-l   { font-size: 11px; }

  .point-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .pt-card    { padding: 12px; }
  .pt-temp    { font-size: 30px; }
  .pt-name    { font-size: 13px; }
  .pt-std     { font-size: 11px; }
  .badge      { font-size: 11px; padding: 2px 7px; }
  .pt-mini    { height: 36px; }

  .chart-wrap { height: 220px; }

  /* 历史记录 */
  .history-layout { grid-template-columns: 1fr; }
  .history-sidebar { position: static; }
  .history-point-item { padding: 10px 14px; }

  .history-detail-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .history-detail-name   { font-size: 16px; }
  .history-detail-stats  { gap: 14px; width: 100%; justify-content: space-around; }
  .hds-val { font-size: 18px; }

  .history-chart-wrap { height: 160px; }

  /* 表格横向滚动 */
  .table-wrapper, .card { overflow-x: auto; }
  .data-table { min-width: 500px; font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 10px; }

  /* 点位管理 */
  .form-grid { grid-template-columns: 1fr; }
  .points-mgmt-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .points-mgmt-header h2 { font-size: 17px; }

  /* 模态框 */
  .modal-box { width: calc(100vw - 24px); }
  .modal-body { padding: 14px; }
  .modal-footer { padding: 10px 14px; }

  /* Toast */
  .toast { bottom: 72px; right: 12px; left: 12px; text-align: center; }
}
