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

/* 基础和通用样式 */
:root {
  /* 主色调 - 基于 stats.html 的配色 */
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --danger-color: #ef4444;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --info-color: #06b6d4;
  --purple-color: #8b5cf6;

  /* 更轻盈的灰色系 - Tailwind CSS 灰色 */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* 统计颜色 - 匹配 stats.html */
  --stats-green: #10b981;
  --stats-red: #ef4444;
  --stats-blue: #3b82f6;
  --stats-purple: #8b5cf6;
  --stats-orange: #f59e0b;
  --stats-yellow: #eab308;
  --stats-pink: #ec4899;
  --stats-cyan: #06b6d4;

  /* 徽章背景色 - 基于 stats.html */
  --badge-blue-bg: #dbeafe;
  --badge-blue-text: #1e40af;
  --badge-purple-bg: #e0e7ff;
  --badge-purple-text: #4338ca;
  --badge-yellow-bg: #fef3c7;
  --badge-yellow-text: #92400e;
  --badge-pink-bg: #fce7f3;
  --badge-pink-text: #be185d;
  --badge-violet-bg: #ede9fe;
  --badge-violet-text: #6b21a8;
  --badge-cyan-bg: #f0f9ff;
  --badge-cyan-text: #0369a1;

  /* 更轻盈的阴影 */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--gray-50);
  color: var(--gray-700);
  margin: 0;
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 加载动画 */
#initialLoader {
  position: fixed;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease-out;
}
#initialLoader.fade-out {
  opacity: 0;
}
.loading-spinner {
  text-align: center;
}
.spinner-icon {
  width: 2.5rem;
  height: 2.5rem;
  animation: rotate 1.5s linear infinite;
}
.spinner-circle {
  stroke: var(--primary-color);
  stroke-linecap: round;
  animation: dash 1.5s ease-in-out infinite;
}
@keyframes rotate { 100% { transform: rotate(360deg); } }
@keyframes dash {
  0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
  50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
  100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

/* 登录页面 */
#loginPage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--stats-cyan) 100%);
}
.login-card {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px);
  padding: 2.5rem;
  border-radius: 1.25rem;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-title {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
  letter-spacing: -0.5px;
}
.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-200);
  border-radius: 0.625rem;
  font-size: 0.9375rem;
  transition: all 0.2s;
  background-color: var(--gray-50);
}
.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  background-color: white;
}

/* 按钮样式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  border-radius: 0.625rem;
  font-weight: 500;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background-color: var(--primary-color);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: translateY(-0.5px);
}
.btn-outline {
  background-color: rgba(255, 255, 255, 0.9);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-outline:hover:not(:disabled) {
  background-color: white;
  border-color: var(--gray-300);
}
.btn-danger {
  background-color: var(--danger-color);
  color: white;
}
.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
}

/* 主应用界面 */
.hidden { display: none !important; }

/* 导航栏 */
.navbar {
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 1rem 0;
  box-shadow: 0 0.5px 0 0 rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.navbar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.navbar-brand {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
  letter-spacing: -0.5px;
}
.navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* 用户信息样式 */
.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background-color: var(--gray-100);
  border-radius: 0.5rem;
  font-weight: 500;
  color: var(--gray-700);
  font-size: 0.8125rem;
}

/* 主内容区域 */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* 统计概览 */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.overview-card {
  background: white;
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all 0.2s ease;
}

.overview-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.overview-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.overview-content {
  flex: 1;
}

.overview-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.overview-label {
  font-size: 0.8125rem;
  color: var(--gray-500);
  font-weight: 400;
}

/* 集成代码弹出层 */
.integration-wrapper {
  position: relative;
}

.integration-popover {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 1001;
  width: 680px;
  max-width: calc(100vw - 2rem);
  background: white;
  border-radius: 0.875rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-100);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.integration-popover-content {
  padding: 1.5rem;
}

.code-block {
  background-color: #1f2937;
  border-radius: 0.625rem;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1rem;
  background-color: #111827;
  border-bottom: 1px solid #374151;
}

.code-title {
  color: var(--gray-400);
  font-size: 0.8125rem;
  font-weight: 400;
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background-color: #374151;
  color: #f3f4f6;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.btn-copy:hover {
  background-color: #4b5563;
}

.btn-copy.copied {
  background-color: var(--success-color);
  color: white;
}

.code-content {
  padding: 1rem;
  margin: 0;
  overflow-x: auto;
  color: #f3f4f6;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Consolas', monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre;
}

.integration-tips {
  background-color: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 0.625rem;
  padding: 1rem;
}

.integration-tips h4 {
  margin: 0 0 0.5rem 0;
  color: var(--gray-900);
  font-size: 0.875rem;
  font-weight: 600;
}

.integration-tips ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--gray-600);
}

.integration-tips li {
  margin-bottom: 0.375rem;
  line-height: 1.4;
  font-size: 0.8125rem;
}

.integration-tips code {
  background-color: var(--gray-200);
  color: var(--gray-800);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-family: monospace;
}

/* 图表区域 */
.charts-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-section {
  min-width: 0;
}

.chart-card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
  overflow: hidden;
  transition: all 0.2s ease;
}

.chart-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.chart-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--gray-100);
  background-color: white;
}

.chart-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-900);
  margin: 0;
  display: flex;
  align-items: center;
}

.chart-body {
  padding: 1.25rem;
  position: relative;
  min-height: 280px;
}

.chart-wrapper {
  position: relative;
  height: 280px;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.9);
}

/* 表格样式 */
.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 0.875rem;
  font-weight: 600;
  color: var(--gray-500);
  background-color: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.data-table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* URL 样式 */
.url-cell {
  max-width: 350px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-cell a {
  color: var(--gray-700);
  text-decoration: none;
  font-weight: 400;
}

.url-cell a:hover {
  color: var(--danger-color);
}

/* 进度条 */
.progress {
  height: 20px;
  background-color: var(--gray-100);
  border-radius: 0.25rem;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  background: var(--danger-color);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 20px;
  color: white;
  text-align: center;
  transition: width 0.6s ease;
}

/* 徽章样式 */
.views-badge {
  display: inline-block;
  padding: 0.2em 0.4em;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--badge-purple-bg);
  color: var(--badge-purple-text);
  border-radius: 0.25rem;
}

.source-badge {
  display: inline-block;
  padding: 0.2em 0.4em;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 70px;
  text-align: center;
  border-radius: 0.25rem;
}

.source-direct {
  background: var(--badge-yellow-bg);
  color: var(--badge-yellow-text);
}

.source-search {
  background: var(--badge-blue-bg);
  color: var(--badge-blue-text);
}

.source-social {
  background: var(--badge-violet-bg);
  color: var(--badge-violet-text);
}

.source-referral {
  background: var(--badge-pink-bg);
  color: var(--badge-pink-text);
}

/* 统计总计行 */
.table-info {
  background-color: var(--badge-cyan-bg) !important;
}

.table-info td {
  color: var(--badge-cyan-text);
  font-weight: 600;
  border-top: 2px solid var(--gray-200);
  padding: 0.875rem;
}

/* 空状态和错误 */
.error-message {
  background-color: #fef2f2;
  border: 1px solid #fee2e2;
  color: var(--danger-color);
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  margin: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
}

/* 全宽区域 */
.full-width-section {
  margin-top: 1.5rem;
}

/* 注册相关样式 */
.auth-switch {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-200);
  text-align: center;
  color: var(--gray-500);
  font-size: 0.8125rem;
}

.auth-link {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.auth-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.form-hint {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--gray-500);
}

.success-message {
  text-align: center;
  padding: 1.5rem;
}

.success-icon {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto 0.875rem;
  color: var(--success-color);
}

.success-message h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 0.375rem;
}

.success-message p {
  color: var(--gray-600);
  margin-bottom: 0;
  font-size: 0.875rem;
}

/* 按钮加载状态 */
.btn.loading {
  position: relative;
  color: transparent;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 0.875rem;
  height: 0.875rem;
  top: 50%;
  left: 50%;
  margin-left: -0.4375rem;
  margin-top: -0.4375rem;
  border: 2px solid #ffffff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: button-loading-spinner 0.8s linear infinite;
}

@keyframes button-loading-spinner {
  from { transform: rotate(0turn); }
  to { transform: rotate(1turn); }
}

/* 通知 */
#notificationContainer {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notification {
  background-color: white;
  padding: 0.875rem 1.25rem;
  border-radius: 0.625rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  min-width: 280px;
  max-width: 450px;
  font-size: 0.875rem;
}

.notification.show {
  transform: translateX(0);
}

.notification-icon {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

.notification-success {
  border-left: 3px solid var(--success-color);
}

.notification-success .notification-icon {
  color: var(--success-color);
}

.notification-error {
  border-left: 3px solid var(--danger-color);
}

.notification-error .notification-icon {
  color: var(--danger-color);
}

/* 新增的样式 - 匹配 stats.html */
.bg-custom-success {
  background: var(--success-color);
}
.bg-custom-danger {
  background: var(--danger-color);
}
.card {
  overflow: hidden;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}
.card-header {
  font-weight: 600;
}
.card-body {
  padding: 1rem;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .charts-container {
    grid-template-columns: 1fr;
  }
  .stats-overview {
    grid-template-columns: repeat(2, 1fr);
  }

  .integration-popover {
    width: 560px;
  }
}

@media (max-width: 768px) {
  /* 登录页 */
  .login-card {
    padding: 1.75rem;
  }

  /* 导航栏 */
  .navbar-container {
    padding: 0 0.875rem;
  }

  .navbar-brand {
    font-size: 1.125rem;
  }

  .navbar-actions {
    flex-wrap: wrap;
    gap: 0.375rem;
  }

  .integration-wrapper {
    display: none;
  }

  .user-info {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }

  /* 主容器 */
  .main-container {
    padding: 1.25rem 0.875rem;
  }

  /* 统计卡片 */
  .stats-overview {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .overview-card {
    padding: 1rem;
  }

  .overview-value {
    font-size: 1.375rem;
  }

  /* 图表 */
  .chart-header {
    padding: 1rem;
  }

  .chart-body {
    padding: 1rem;
  }

  .chart-wrapper {
    height: 240px;
  }

  /* 表格 */
  .data-table {
    font-size: 0.75rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.625rem 0.5rem;
  }

  .url-cell {
    max-width: 180px;
    font-size: 0.75rem;
  }

  /* 集成代码弹出层 - 移动端全屏 */
  .integration-popover {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    max-height: 100vh;
  }

  .integration-popover-content {
    padding: 1.25rem 1rem;
    height: 100vh;
    overflow-y: auto;
  }

  .code-content {
    font-size: 0.625rem;
    padding: 0.875rem;
  }

  .integration-tips {
    font-size: 0.75rem;
  }

  /* 按钮调整 */
  .btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
  }
}

@media (max-width: 480px) {
  .overview-card {
    flex-direction: column;
    text-align: center;
    padding: 1.25rem 0.875rem;
  }

  .overview-icon {
    margin-bottom: 0.625rem;
  }

  #notificationContainer {
    left: 0.75rem;
    right: 0.75rem;
  }

  .notification {
    min-width: auto;
    width: 100%;
  }
}

/* 工具类 */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-500); }
.text-primary { color: var(--primary-color); text-decoration: none; }
.text-gray-500 { color: var(--gray-500); }
.hover\:underline:hover { text-decoration: underline; }
.mt-8 { margin-top: 2rem; }
.me-2 { margin-right: 0.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-3 { margin-bottom: 0.75rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }

/* 打印样式 */
@media print {
  .navbar,
  .btn,
  .integration-wrapper,
  #notificationContainer {
    display: none !important;
  }

  body {
    background-color: white;
  }

  .main-container {
    max-width: 100%;
    padding: 0;
  }

  .chart-card,
  .overview-card {
    box-shadow: none;
    border: 1px solid var(--gray-300);
    page-break-inside: avoid;
  }
}
