/**
 * Apple-Inspired Modern Analytics Dashboard
 * 灵感来源：Apple Music、Linear、Vercel Dashboard
 */

/* === 变量定义 === */
:root {
  /* 色彩系统 */
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-elevated: #141414;
  --bg-card: #1a1a1a;
  --bg-hover: #242424;
  --bg-active: #2a2a2a;
  
  --text-primary: #ffffff;
  --text-secondary: #86868b;
  --text-tertiary: #6e6e73;
  
  --accent-blue: #0a84ff;
  --accent-green: #30d158;
  --accent-orange: #ff9f0a;
  --accent-red: #ff453a;
  --accent-purple: #bf5af2;
  --accent-pink: #ff375f;
  
  --border-subtle: rgba(255,255,255,0.06);
  --border-default: rgba(255,255,255,0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  
  --sidebar-width: 220px;
  --transition: cubic-bezier(0.4, 0, 0.2, 1);
}

/* === 基础重置 === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === 登录页面 === */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 40px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-subtle);
  animation: fadeIn 0.5s var(--transition);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-icon {
  font-size: 48px;
  text-align: center;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 30px;
}

.input-group {
  margin-bottom: 16px;
}

.input-group input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  transition: all 0.2s var(--transition);
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent-blue);
  background: var(--bg-hover);
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

.btn-login {
  width: 100%;
  padding: 14px;
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--transition);
}

.btn-login:hover {
  background: #0070e0;
  transform: translateY(-1px);
}

.btn-login:active {
  transform: translateY(0);
}

.error-text {
  color: var(--accent-red);
  font-size: 13px;
  text-align: center;
  margin-top: 16px;
  display: none;
}

/* === 主布局 === */
.main-wrapper {
  display: flex;
  min-height: 100vh;
}

/* === 侧边栏 === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
  font-size: 20px;
  color: var(--accent-blue);
}

.brand-text {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.site-picker {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.site-picker select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2386868b'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.site-picker select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.nav-menu {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all 0.15s var(--transition);
  font-size: 13px;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-bottom {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}

.btn-new {
  width: 100%;
  padding: 10px;
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 8px;
  transition: all 0.2s var(--transition);
}

.btn-new:hover {
  background: #0070e0;
}

.user-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s var(--transition);
}

.action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === 主内容区 === */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === 顶部栏 === */
.top-bar {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-left h1 {
  font-size: 18px;
  font-weight: 600;
}

.site-token {
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: 'SF Mono', Monaco, monospace;
  display: block;
  margin-top: 2px;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.time-selector {
  display: flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.time-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--transition);
}

.time-btn:hover {
  color: var(--text-primary);
}

.time-btn.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.update-time {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* === 内容区域 === */
.content-wrapper {
  flex: 1;
  padding: 24px;
}

.view {
  display: none;
  animation: viewIn 0.3s var(--transition);
}

.view.active {
  display: block;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === 指标卡片网格 === */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all 0.2s var(--transition);
}

.metric-card:hover {
  background: var(--bg-hover);
  transform: translateY(-2px);
}

.metric-card.primary {
  background: linear-gradient(135deg, var(--accent-blue), #0056b3);
  border-color: transparent;
}

.metric-card.primary .metric-value {
  font-size: 36px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.metric-card.primary .metric-label {
  color: rgba(255,255,255,0.7);
}

.metric-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.metric-trend {
  font-size: 12px;
  color: var(--accent-green);
  margin-top: 4px;
}

.metric-trend.down {
  color: var(--accent-red);
}

.metric-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* === 图表卡片 === */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

.chart-card.large {
  margin-bottom: 24px;
}

.chart-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.chart-header h3 {
  font-size: 14px;
  font-weight: 500;
}

.chart-body {
  padding: 20px;
  height: 280px;
}

.chart-card.large .chart-body {
  height: 350px;
}

/* === 详情卡片 === */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.detail-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.detail-header h3 {
  font-size: 14px;
  font-weight: 500;
}

.badge {
  padding: 4px 10px;
  background: var(--bg-elevated);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-secondary);
}

.detail-list {
  max-height: 400px;
  overflow-y: auto;
}

.detail-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.15s var(--transition);
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-item:hover {
  background: var(--bg-hover);
}

.detail-rank {
  width: 24px;
  height: 24px;
  background: var(--bg-elevated);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 12px;
  flex-shrink: 0;
}

.detail-rank.top {
  background: var(--accent-blue);
  color: white;
}

.detail-info {
  flex: 1;
  min-width: 0;
}

.detail-url {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.detail-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-blue);
  margin-left: 12px;
  flex-shrink: 0;
}

/* === 数据表格 === */
.data-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-header h3 {
  font-size: 14px;
  font-weight: 500;
}

.data-table-wrap {
  overflow-x: auto;
}

.data-table-wrap.scroll {
  max-height: 600px;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table th {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
}

.data-table tbody tr {
  transition: background 0.15s var(--transition);
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.data-table td {
  font-size: 13px;
}

.data-table .url-cell {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
}

.data-footer {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-subtle);
}

.logs-info {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* === 筛选栏 === */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.date-picker {
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
}

.filter-sep {
  color: var(--text-tertiary);
}

.search-input {
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  width: 160px;
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.btn-filter {
  padding: 8px 16px;
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--transition);
}

.btn-filter:hover {
  background: #0070e0;
}

.btn-filter.secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.btn-filter.secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === 分页 === */
.pagination {
  display: flex;
  gap: 4px;
}

.pagination button {
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s var(--transition);
}

.pagination button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === 弹窗 === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  animation: modalIn 0.25s var(--transition);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.modal-body input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-body input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--transition);
}

.btn-primary:hover {
  background: #0070e0;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  opacity: 0;
  transition: all 0.3s var(--transition);
  z-index: 2000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: var(--accent-green);
}

.toast.error {
  border-color: var(--accent-red);
}

/* === 骨架屏 === */
.skeleton-list {
  padding: 8px 20px;
}

.skeleton-item {
  height: 44px;
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.skeleton-item:last-child {
  margin-bottom: 0;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === 空状态 === */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state-text {
  font-size: 14px;
}

/* === 响应式 === */
@media (max-width: 1400px) {
  .metrics-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1200px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
  
  .split-layout {
    display: block;
  }
  
  .chart-card.half,
  .data-card.half {
    width: 100%;
    margin-bottom: 20px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  
  .brand-text,
  .nav-link span,
  .site-picker select,
  .btn-new,
  .action-btn span {
    display: none;
  }
  
  .main-content {
    margin-left: 60px;
  }
  
  .nav-link {
    justify-content: center;
    padding: 12px;
  }
  
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .top-bar {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  
  .content-wrapper {
    padding: 16px;
  }
}

/* === 辅助类 === */
.split-layout {
  display: flex;
  gap: 20px;
}

/* === 来源/设备网格布局 === */
.sources-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.sources-grid .chart-card,
.sources-grid .data-card {
  margin-bottom: 0;
}

/* === 追踪代码 === */
.tracker-code {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  font-size: 12px;
}

.tracker-code.show {
  display: flex;
}

.tracker-code code {
  font-family: 'SF Mono', Monaco, monospace;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === 站点操作按钮 === */
.site-actions {
  display: flex;
  gap: 6px;
}

.action-btn {
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}

.action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.action-btn.danger:hover {
  background: rgba(255, 69, 58, 0.2);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* === 确认弹窗 === */
.confirm-modal .modal-body {
  text-align: center;
}

.confirm-text {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.confirm-text strong {
  color: var(--accent-blue);
}

.confirm-warning {
  font-size: 13px;
  color: var(--accent-red);
  margin-bottom: 24px;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-cancel {
  padding: 12px 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}

.btn-cancel:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  padding: 12px 24px;
  background: var(--accent-red);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: #e04030;
}

/* === 修复表格行高 === */
.data-table tbody tr td {
  padding: 14px 16px;
}

.data-table tbody tr:hover td {
  background: var(--bg-hover);
}

