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

:root {
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --success: #10B981;
  --danger: #EF4444;
  --bg: #0F172A;
  --bg-card: #1E293B;
  --bg-input: #334155;
  --border: #475569;
  --text: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --radius: 12px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 24px; }
.login-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
  font-family: inherit;
}
.login-input:focus { border-color: var(--primary); }
.login-input::placeholder { color: var(--text-muted); }

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { font-size: 24px; }
.header-title { font-size: 18px; font-weight: 700; }

/* Stats */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  padding: 20px 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-number { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* Section */
.section {
  padding: 20px 24px;
}
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* Generate form */
.generate-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.form-row {
  margin-bottom: 14px;
}
.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-select, .form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.form-select:focus, .form-input:focus { border-color: var(--primary); }
.form-input::placeholder { color: var(--text-muted); }

.btn-generate {
  margin-top: 4px;
}

/* Generated result */
.generated-result {
  margin-top: 16px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius);
  padding: 16px;
}
.generated-result h3 {
  font-size: 14px;
  color: var(--success);
  margin-bottom: 12px;
}

.generated-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 8px;
}
.generated-item:last-child { margin-bottom: 0; }

.gen-info { flex: 1; min-width: 0; }
.gen-id { font-size: 13px; font-weight: 600; color: var(--primary); }
.gen-url {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-copy {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-copy:hover { border-color: var(--primary); color: var(--text); }
.btn-copy.copied { background: var(--success); color: white; border-color: var(--success); }

/* 已锁状态：链接已绑设备，禁止复制（防止一码多卡） */
.btn-locked {
  display: inline-block;
  padding: 6px 14px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted, #aaa);
  font-size: 12px;
  white-space: nowrap;
  cursor: not-allowed;
  user-select: none;
}

/* 删除按钮（仅 generated 状态显示） */
.btn-delete {
  padding: 6px 10px;
  border: 1px solid #e88;
  border-radius: 6px;
  background: transparent;
  color: #e88;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  margin-left: 6px;
}
.btn-delete:hover { background: #e88; color: white; }

/* 状态徽章 device_bound 颜色（新增） */
.status-badge.status-active {
  background: rgba(100, 180, 250, 0.15);
  color: #6cf;
  border: 1px solid rgba(100, 180, 250, 0.3);
}

/* 卡片元信息 */
.tag-song {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.tag-meta {
  font-size: 11px;
  color: var(--text-muted, #888);
  margin-top: 2px;
}

/* stats 卡片激活态 */
.stat-card-active {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* 列表上方筛选状态横条 */
.filter-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.filter-banner strong { color: var(--text); }
.btn-clear-filter {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.btn-clear-filter:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* ===== 数据分析 Dashboard ===== */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.analytics-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.analytics-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}
.empty-state-mini {
  font-size: 12px;
  color: var(--text-muted, #888);
  padding: 18px 0;
  text-align: center;
}

/* 漏斗 */
.funnel-row {
  display: grid;
  grid-template-columns: 90px 1fr 56px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}
.funnel-label { color: var(--text-secondary); }
.funnel-track {
  height: 22px;
  background: rgba(255,255,255,0.04);
  border-radius: 4px;
  overflow: hidden;
}
.funnel-bar {
  height: 100%;
  display: flex;
  align-items: center;
  padding-left: 8px;
  color: #fff;
  font-weight: 600;
  font-size: 11px;
  border-radius: 4px;
  min-width: 22px;
}
.funnel-conv {
  text-align: right;
  color: var(--text);
  font-size: 11px;
}
.funnel-foot {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

/* 地理 */
.geo-row {
  display: grid;
  grid-template-columns: 40px 1fr 30px;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.geo-country { color: var(--text); font-weight: 600; }
.geo-bar {
  height: 14px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
  overflow: hidden;
}
.geo-bar > div {
  height: 100%;
  background: linear-gradient(90deg, #6cf, #8c5);
  border-radius: 3px;
}
.geo-count { text-align: right; color: var(--text-secondary); }

/* 时间序列 legend */
.timeline-legend {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}
.timeline-legend span { display: flex; align-items: center; gap: 5px; }
.timeline-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.filter-bar .form-select { width: auto; min-width: 120px; }

/* Tag table */
.tag-table { overflow-x: auto; }

.tag-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.tag-id { font-weight: 600; font-size: 13px; color: var(--primary); min-width: 100px; }
.tag-project {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--bg-input);
  border-radius: 4px;
  color: var(--text-secondary);
}
.tag-url {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag-status {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
}
.tag-status.unused { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
.tag-status.used { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.tag-actions { display: flex; gap: 6px; }
.btn-small {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.btn-small:hover { border-color: var(--primary); color: var(--text); }
.btn-small.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-small.selected, .mbti-type-btn.selected { background: var(--primary); color: white; border-color: var(--primary); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--success);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 100;
  transition: transform 0.3s;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Tab navigation */
.tab-bar {
  display: flex;
  gap: 0;
  padding: 0 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Tab content */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Non-clickable stat cards */
.stats-display .stat-card {
  cursor: default;
  user-select: none;
  border-color: rgba(71,85,105,0.4);
  opacity: 0.9;
}
.stats-display .stat-card:hover {
  transform: none;
  box-shadow: none;
}

/* Collapsible toggle */
.collapse-toggle {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all 0.2s;
}
.collapse-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.collapse-toggle.open {
  border-style: solid;
  border-color: var(--primary);
  color: var(--primary);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
}
.collapse-panel {
  display: none;
  border: 1px solid var(--primary);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 16px;
  background: rgba(99,102,241,0.03);
}
.collapse-panel.open { display: block; }

/* Modal */
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%; max-width: 440px;
  padding: 24px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

