/* ===== 全局 CSS 变量 ===== */
:root {
  --bg-page: #f5f7fb;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #f3f5fa;
  --bg-active: #e6efff;
  --bg-tag: #f0f2f7;
  --border: #e5e8ef;
  --border-strong: #d6dae3;
  --text-primary: #1f2937;
  --text-secondary: #5b6473;
  --text-tertiary: #8a93a3;
  --text-inverse: #ffffff;
  --primary: #2b6ef0;
  --primary-hover: #1f5ad8;
  --primary-soft: #e6efff;
  --success: #10b981;
  --success-soft: #d1fae5;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --info: #6366f1;
  --info-soft: #e0e7ff;
  --neutral: #6b7280;
  --neutral-soft: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

[data-theme="dark"] {
  --bg-page: #0f172a;
  --bg-surface: #1a2236;
  --bg-elevated: #232c44;
  --bg-hover: #2b354f;
  --bg-active: #2b3a66;
  --bg-tag: #2b354f;
  --border: #2b354f;
  --border-strong: #3a4666;
  --text-primary: #e8ecf4;
  --text-secondary: #aab4cc;
  --text-tertiary: #7e8aa3;
  --text-inverse: #0f172a;
  --primary-soft: #1e2a4f;
  --success-soft: #14352a;
  --warning-soft: #3a2c0f;
  --danger-soft: #3a1c1c;
  --info-soft: #1f244a;
  --neutral-soft: #2b354f;
}

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

html, body {
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ===== 顶栏 ===== */
.topbar {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-logo {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-logo-icon {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 14px;
}
.topbar-search {
  flex: 0 0 320px;
  height: 36px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex; align-items: center; padding: 0 12px;
  color: var(--text-tertiary);
}
.topbar-spacer { flex: 1; }
.topbar-proj {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
}
.topbar-proj .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
}
.topbar-icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  position: relative;
}
.topbar-icon-btn:hover { background: var(--bg-hover); }
.topbar-icon-btn .badge {
  position: absolute;
  top: 4px; right: 4px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: 999px;
  cursor: pointer;
}
.topbar-user:hover { background: var(--bg-hover); }
.topbar-user .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #2b6ef0);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}

/* ===== 主区 ===== */
.page {
  padding: 24px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== 卡片 ===== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-title-actions { display: flex; gap: 8px; }

/* ===== KPI 卡 ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}
.kpi-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-meta .up { color: var(--success); }
.kpi-meta .down { color: var(--danger); }
.kpi-icon {
  position: absolute;
  top: 16px; right: 16px;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

/* ===== 徽章 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: var(--neutral-soft);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.online, .badge.success { background: var(--success-soft); color: var(--success); }
.badge.offline, .badge.neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge.recording, .badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.standby, .badge.info { background: var(--info-soft); color: var(--info); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.normal { background: var(--success-soft); color: var(--success); }
.badge.repair { background: var(--warning-soft); color: var(--warning); }
.badge.scrap { background: var(--neutral-soft); color: var(--neutral); }
.badge.scrap-pending { background: var(--danger-soft); color: var(--danger); }

/* ===== 按钮 ===== */
.btn {
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }

/* ===== 表格 ===== */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
table.data th {
  background: var(--bg-page);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  position: sticky;
  top: 0;
}
table.data tbody tr:hover { background: var(--bg-hover); }
table.data tbody tr:last-child td { border-bottom: none; }

/* ===== 工具栏 ===== */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-left, .toolbar-right {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.input, .select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-primary);
  min-width: 160px;
}
.input::placeholder { color: var(--text-tertiary); }

/* ===== 进度条 ===== */
.progress {
  width: 80px;
  height: 6px;
  background: var(--bg-tag);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--success);
}
.progress-bar.warn { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ===== 网格行 ===== */
.row {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}
.row.cols-2 { grid-template-columns: 1fr 1fr; }
.row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.row.cols-4 { grid-template-columns: repeat(4, 1fr); }
.row.cols-3-2 { grid-template-columns: 3fr 2fr; }
.row.cols-2-1 { grid-template-columns: 2fr 1fr; }

/* ===== 设备卡 ===== */
.device-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: relative;
  cursor: pointer;
  transition: all .15s;
}
.device-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}
.device-card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 12px;
}
.device-card-title {
  font-weight: 600;
  font-size: 15px;
}
.device-card-code {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.device-card-badges {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.device-card-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}
.device-card-progress {
  display: flex; align-items: center; gap: 8px;
}
.device-card-worker {
  display: flex; align-items: center; gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}
.mini-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: white;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}

/* ===== 视频播放器 ===== */
.player {
  background: #000;
  border-radius: var(--radius-md);
  aspect-ratio: 16/9;
  position: relative;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: white;
}
.player-live {
  position: absolute;
  top: 12px; left: 12px;
  background: var(--danger);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  display: flex; align-items: center; gap: 4px;
}
.player-live::before {
  content: ""; width: 6px; height: 6px;
  border-radius: 50%; background: white;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }
.player-time {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(0,0,0,.5);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
}
.player-controls {
  position: absolute;
  bottom: 12px; left: 12px; right: 12px;
  display: flex; gap: 8px; align-items: center;
}
.player-controls .btn {
  background: rgba(255,255,255,.15);
  color: white;
  border-color: rgba(255,255,255,.2);
  backdrop-filter: blur(8px);
}

/* ===== 货物卡 ===== */
.cargo-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all .15s;
}
.cargo-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}
.cargo-thumb {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  color: var(--text-tertiary);
  font-size: 32px;
}
.cargo-thumb .badge {
  position: absolute;
  top: 8px; right: 8px;
}
.cargo-thumb .count {
  position: absolute;
  bottom: 8px; right: 8px;
  background: rgba(0,0,0,.6);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}
.cargo-meta {
  padding: 10px 12px;
}
.cargo-meta-row {
  display: flex; justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== 时间线 ===== */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.timeline-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-top: 6px;
  flex-shrink: 0;
}
.timeline-dot.warn { background: var(--warning); }
.timeline-time {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: 50px;
}
.timeline-content {
  font-size: 13px;
  flex: 1;
}

/* ===== 图表占位 ===== */
.chart-placeholder {
  height: 240px;
  background: var(--bg-page);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
  position: relative;
  overflow: hidden;
}
.chart-svg { width: 100%; height: 100%; }

/* ===== 抽屉/抽屉 trigger ===== */
.demo-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  background: var(--bg-tag);
  padding: 4px 10px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ===== 抽屉式注释标签 ===== */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-tag);
  color: var(--text-secondary);
  font-size: 12px;
}
.tag.primary { background: var(--primary-soft); color: var(--primary); }

/* ===== 维修工单卡 ===== */
.workorder-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
}
.workorder-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}
.workorder-id {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-tertiary);
}
.workorder-row {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== 告警卡 ===== */
.alert-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: var(--bg-surface);
}
.alert-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--danger-soft);
  color: var(--danger);
}
.alert-icon.warning { background: var(--warning-soft); color: var(--warning); }
.alert-icon.info { background: var(--info-soft); color: var(--info); }
.alert-body { flex: 1; }
.alert-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.alert-desc { font-size: 12px; color: var(--text-secondary); }
.alert-meta { font-size: 11px; color: var(--text-tertiary); margin-top: 6px; }

/* ===== 项目切换器 ===== */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
}
.project-card:hover { border-color: var(--primary); }
.project-code {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}
.project-name { font-weight: 600; margin-bottom: 8px; }
.project-meta { font-size: 12px; color: var(--text-secondary); }
.project-stats {
  display: flex; gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

/* ===== 文本辅助 ===== */
.text-muted { color: var(--text-tertiary); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* ===== 实时预览网格 ===== */
.grid-screen {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: #000;
  padding: 8px;
  border-radius: var(--radius-md);
}
.grid-screen .player {
  aspect-ratio: 16/9;
}

/* ===== 抽屉弹出样式 ===== */
.popover {
  position: fixed;
  top: 80px;
  right: 24px;
  width: 480px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
}
.popover-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.popover-close {
  width: 24px; height: 24px;
  border-radius: 4px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
}
.popover-close:hover { background: var(--bg-hover); }
.popover-body { padding: 12px 16px; }
/* ===== Modal 弹窗（通用） ===== */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 90vw; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-surface);
}
.modal-close {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); font-size: 18px;
}
.modal-close:hover { background: var(--bg-hover); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--bg-page);
}
.form-row { margin-bottom: 16px; }
.form-row label {
  display: block; font-size: 13px; font-weight: 600;
  margin-bottom: 6px; color: var(--text-primary);
}
.form-row label input[type="checkbox"] { margin-right: 6px; }
.radio-card {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  cursor: pointer; font-size: 13px;
}
.radio-card input { margin-right: 6px; }
.radio-card:has(input:checked) {
  border-color: var(--primary); background: var(--primary-soft);
}
