@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 224 71.4% 4.1%;
    --card: 0 0% 100%;
    --card-foreground: 224 71.4% 4.1%;
    --popover: 0 0% 100%;
    --popover-foreground: 224 71.4% 4.1%;
    --primary: 262.1 83.3% 57.8%;
    --primary-foreground: 210 20% 98%;
    --secondary: 220 14.3% 95.9%;
    --secondary-foreground: 220.9 39.3% 11%;
    --muted: 220 14.3% 95.9%;
    --muted-foreground: 220 8.9% 46.1%;
    --accent: 220 14.3% 95.9%;
    --accent-foreground: 220.9 39.3% 11%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 20% 98%;
    --border: 220 13% 91%;
    --input: 220 13% 91%;
    --ring: 262.1 83.3% 57.8%;
    --radius: 0.5rem;
    --chart-1: 12 76% 61%;
    --chart-2: 173 58% 39%;
    --chart-3: 197 37% 24%;
    --chart-4: 43 74% 66%;
    --chart-5: 27 87% 67%;
    /* 热搜飞行动画变量 */
    --fly-x: 0px;
    --fly-y: 0px;
  }

  .dark {
    --background: 224 71.4% 4.1%;
    --foreground: 210 20% 98%;
    --card: 224 71.4% 4.1%;
    --card-foreground: 210 20% 98%;
    --popover: 224 71.4% 4.1%;
    --popover-foreground: 210 20% 98%;
    --primary: 263.4 70% 50.4%;
    --primary-foreground: 210 20% 98%;
    --secondary: 215 27.9% 16.9%;
    --secondary-foreground: 210 20% 98%;
    --muted: 215 27.9% 16.9%;
    --muted-foreground: 217.9 10.6% 64.9%;
    --accent: 215 27.9% 16.9%;
    --accent-foreground: 210 20% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 210 20% 98%;
    --border: 215 27.9% 16.9%;
    --input: 215 27.9% 16.9%;
    --ring: 263.4 70% 50.4%;
    --chart-1: 220 70% 50%;
    --chart-2: 160 60% 45%;
    --chart-3: 30 80% 55%;
    --chart-4: 280 65% 60%;
    --chart-5: 340 75% 55%;
  }
}

@layer base {
  * {
    @apply border-border;
  }
  body {
    @apply bg-background text-foreground;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%239C92AC' fill-opacity='0.1' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E");
  }
}

/* 毛玻璃效果样式 */
.glass {
  @apply backdrop-blur-md bg-white/30 dark:bg-black/30 border border-white/20 dark:border-gray-800/50;
}

.glass-card {
  @apply backdrop-blur-md bg-white/40 dark:bg-gray-900/40
         border border-white/20 dark:border-gray-800/30
         shadow-lg hover:shadow-xl transition-all duration-300;
}

/* 新增强化版毛玻璃效果 */
.glass-card-enhanced {
  @apply backdrop-blur-xl bg-white/50 dark:bg-gray-900/50
         border border-white/30 dark:border-gray-800/40
         shadow-lg hover:shadow-xl transition-all duration-300;
}

.glass-input {
  @apply backdrop-blur-sm bg-white/70 dark:bg-gray-900/70
         border border-white/30 dark:border-gray-800/40
         focus:border-primary/50 dark:focus:border-primary/50
         focus:ring-1 focus:ring-primary/30 dark:focus:ring-primary/30
         transition-all duration-300;
}

/* 页面动画 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes floatLeft {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-5px); }
}

@keyframes floatRight {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(5px); }
}

@keyframes blink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.8; }
}

/* 新增：打字光标闪烁动画效果 */
@keyframes cursorBlink {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

/* 新增：热搜飞入动画 */
@keyframes flyToInput {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  70% {
    transform: translate(var(--fly-x), var(--fly-y)) scale(0.8);
    opacity: 0.7;
  }
  100% {
    transform: translate(var(--fly-x), var(--fly-y)) scale(0);
    opacity: 0;
  }
}

/* 添加热搜下拉动画 */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(-0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 搜索进度组件样式 */
.search-progress-card {
  @apply glass-card rounded-xl overflow-hidden w-full max-w-3xl mx-auto;
  position: relative;
  z-index: 20;
  transition: all 0.3s ease;
  transform-origin: top center;
  animation: fadeSlideDown 0.3s ease;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 0 1px rgba(0, 0, 0, 0.1);
  width: 100%; /* 确保宽度与搜索框一致 */
  margin-bottom: 1rem; /* 添加底部边距，确保不遮挡内容 */
}

.search-progress-card.collapsed {
  z-index: 20;
  opacity: 0.95;
  max-width: calc(100% - 2rem);
  margin-left: auto;
  margin-right: auto;
  /* 移除position: absolute和top属性，使其不再固定在搜索框下方 */
}

@keyframes fadeSlideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 移动端适配 */
@media (max-width: 640px) {
  .search-progress-card {
    @apply mx-2;
    max-width: calc(100% - 1rem); /* 确保不超出屏幕，留出边距 */
  }

  /* 确保热搜下拉菜单适应移动端 */
  .hot-search-dropdown {
    width: calc(100% - 1rem);
    margin-left: auto;
    margin-right: auto;
  }

  /* 搜索位于顶部时，相应调整内容区域顶部边距 */
  .search-container-top + div + .flex-1 {
    padding-top: 1rem;
  }
}

/* 特别处理搜索位于顶部时的页面布局 */
.search-container-top + div {
  margin-top: 1rem;
  margin-bottom: 2rem;
}

/* 确保在移动设备上正确显示 */
@media (max-width: 480px) {
  .search-container-top {
    @apply top-2; /* Reduce top margin for mobile */
    width: calc(100% - 1rem); /* Give some space on the sides */
    max-width: calc(100% - 1rem); /* Consistent with width */
  }

  .search-progress-card {
    @apply mt-4 mb-4; /* Add more margin to separate from content */
    width: 100%; /* Full width on mobile */
  }

  .search-progress-card.collapsed {
    /* 移除position: fixed和top属性，使其不再固定在搜索框下方 */
    z-index: 15; /* Lower than search bar but above content */
    width: calc(100% - 1rem);
    max-width: calc(100% - 1rem);
  }

  /* 确保时间轴有足够的顶部边距不被搜索框遮挡 */
  .timeline-container {
    @apply mt-12 pt-4; /* 减少顶部边距，因为SearchProgress不再遮挡内容 */
  }

  /* 修复时间轴卡片在移动端的样式 */
  .event-card {
    margin-left: -8px; /* 调整在移动设备上卡片的位置，避免偏移 */
    width: calc(100% + 8px);
  }

  /* 优化卡片内间距 */
  .event-card .p-2 {
    padding: 0.375rem;
  }

  .event-card .text-xs {
    font-size: 0.7rem;
    line-height: 1.2;
  }

  /* 优化事件日期显示 */
  .event-date {
    max-width: 60px;
    padding: 0.25rem 0.5rem;
    font-size: 0.6rem;
  }
}

/* 确保在超小屏幕设备上也能正常显示 */
@media (max-width: 375px) {
  .search-container-top {
    @apply top-1;
  }

  .search-progress-card.collapsed {
    /* 移除top属性，使其不再固定在搜索框下方 */
  }

  .timeline-container {
    @apply mt-12 pt-4; /* 减少顶部边距，适应新布局 */
  }

  .event-card .p-2 {
    padding: 0.3rem;
  }
}

/* 优化影响评估组件在移动端的显示 */
@media (max-width: 640px) {
  .impact-assessment-container {
    @apply mt-14 pt-2 mb-0; /* 减少顶部边距和底部边距 */
  }

  /* 减少移动端上ImpactAssessment卡片的外边距 */
  .impact-assessment-container .glass-card {
    margin-bottom: 0;
  }

  /* 优化影响评估卡片的内边距 */
  .impact-assessment-container .p-3 {
    padding: 0.5rem;
  }
}

.fly-to-input {
  position: fixed;
  z-index: 100;
  animation: flyToInput 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: none;
}

.animate-cursor-blink {
  animation: cursorBlink 0.8s infinite;
}

.animate-fade-in {
  animation: fade-in 0.3s ease-out forwards;
}

.animate-slide-up {
  animation: slideUp 0.5s ease-out forwards;
}

.animate-slide-down {
  animation: slideDown 0.5s ease-out forwards;
}

.animate-pulse-slow {
  animation: pulse 3s infinite;
}

.animate-float-left {
  animation: floatLeft 8s ease-in-out infinite;
}

.animate-float-right {
  animation: floatRight 8s ease-in-out infinite;
}

/* 输入框动画 */
.search-container-center {
  @apply fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-full max-w-3xl z-10
         transition-all duration-700 ease-in-out;
  padding-bottom: var(--hot-search-height, 0);
}

.search-container-top {
  @apply fixed top-4 left-1/2 transform -translate-x-1/2 w-full max-w-3xl z-10
         transition-all duration-700 ease-in-out;
}

/* 时间轴相关样式 */
.timeline-container {
  @apply mt-24 opacity-0 transition-opacity duration-700 w-full;
}

.timeline-container-visible {
  @apply opacity-100;
}

/* 时间轴卡片样式优化 */
.event-card {
  @apply glass-card-enhanced rounded-xl overflow-hidden transform transition-all duration-300;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

.event-card:hover {
  @apply shadow-xl -translate-y-1;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}

/* 更新时间轴日期标识样式 - 现在在卡片内部 */
.timeline-date-badge {
  @apply backdrop-blur-sm text-xs sm:text-sm
         px-2 sm:px-3 py-0.5 sm:py-1 rounded-full;
  background-color: rgba(var(--primary), 0.1);
  color: hsl(var(--primary));
  border-left: 3px solid hsl(var(--primary));
  box-shadow: 0 0 10px rgba(var(--primary), 0.1);
  transition: all 0.3s ease;
}

.dark .timeline-date-badge {
  background-color: rgba(var(--primary), 0.15);
}

/* 优化时间轴中的AI分析按钮 */
.event-card .ai-analysis-btn {
  font-size: 0.75rem; line-height: 1rem;
  @apply sm:text-sm rounded-full h-7 sm:h-8
         px-2 sm:px-3 ml-1 gap-1.5
         backdrop-blur-sm transition-colors;
  background-color: rgba(var(--primary), 0.08);
  border: 1px solid rgba(var(--primary), 0.2);
}

.event-card .ai-analysis-btn:hover {
  background-color: rgba(var(--primary), 0.15);
}

/* 标题卡片样式 */
.timeline-title-card {
  @apply mb-4;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.1);
}

/* 卡片样式优化（保留原 event-date 以兼容旧代码） */
.event-date {
  @apply glass text-xs sm:text-sm text-muted-foreground whitespace-nowrap
         mb-1 sm:mb-2 px-2 sm:px-3 py-1 sm:py-1.5 rounded-full;
  font-size: 0.65rem;
  max-width: 70px;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

/* 搜索进度组件样式 */
.loading-dot {
  @apply rounded-full bg-primary/60;
  animation: blink 1.5s infinite;
}

/* 热搜榜样式 */
.hot-item {
  @apply relative transition-all duration-300;
}

.hot-item:hover {
  @apply bg-primary/10 dark:bg-primary/20 rounded-lg -translate-y-0.5;
}

.hot-rank {
  @apply inline-flex items-center justify-center text-xs font-semibold w-6 h-6 rounded-lg;
}

.hot-title {
  @apply truncate;
}

.hot-value {
  font-size: 0.75rem; line-height: 1rem; @apply opacity-70;
}

/* 热搜下拉组件样式 */
.hot-search-dropdown .hot-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.25rem;
}

.hot-search-dropdown .hot-rank.top-1 {
  background-color: #ff4d4f;
  color: white;
}

.hot-search-dropdown .hot-rank.top-2 {
  background-color: #ff7a45;
  color: white;
}

.hot-search-dropdown .hot-rank.top-3 {
  background-color: #ffa940;
  color: white;
}

/* 热搜下拉组件样式优化 */
.hot-search-dropdown {
  max-height: 60vh; /* 减少最大高度，确保底部有空间 */
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding-bottom: env(safe-area-inset-bottom, 16px); /* 添加安全区域内边距，兼容全面屏手机 */
}

@media (max-width: 640px) {
  .hot-search-dropdown {
    max-height: 50vh; /* 在手机上进一步减少高度 */
  }
}

/* 确保搜索结果框和热搜不重叠 */
.search-container-center .hot-search-dropdown {
  margin-bottom: 1rem;
}

/* 渐变背景装饰 */
.bg-gradient-purple {
  @apply fixed -z-10 blur-3xl opacity-20 dark:opacity-10 animate-float-left;
  background: radial-gradient(circle at center,
    rgba(var(--primary), 0.3) 0%,
    rgba(var(--primary), 0.1) 50%,
    transparent 70%);
  width: 50vw;
  height: 50vw;
  top: -10%;
  right: -10%;
}

.bg-gradient-blue {
  @apply fixed -z-10 blur-3xl opacity-20 dark:opacity-10 animate-float-right;
  background: radial-gradient(circle at center,
    rgba(59, 130, 246, 0.3) 0%,
    rgba(59, 130, 246, 0.1) 50%,
    transparent 70%);
  width: 40vw;
  height: 40vw;
  bottom: -5%;
  left: -5%;
}

/* 自定义滚动条 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  @apply bg-transparent;
}

::-webkit-scrollbar-thumb {
  @apply bg-primary/20 hover:bg-primary/40 rounded-full transition-colors;
}

/* 标题悬停效果 */
.page-title {
  @apply text-transparent bg-clip-text bg-gradient-to-r from-primary to-primary/70
         hover:to-primary transition-all duration-500;
}

/* 加载动画 */
.loading-spinner {
  @apply h-4 w-4 border-2 border-white/30 border-t-white rounded-full animate-spin;
}

/* 流式输出打字光标样式 */
.stream-cursor {
  @apply inline-block h-4 w-2 bg-primary/80 align-middle ml-1 animate-cursor-blink;
}

/* 媒体查询修改 */
@media (max-width: 640px) {
  /* 时间轴容器在移动端的边距调整 */
  .timeline-container {
    @apply mt-8 pt-2;
  }

  /* 优化标题在移动端的显示 */
  .timeline-title-card {
    @apply mb-3;
  }

  /* 修复时间轴卡片在移动端的样式 */
  .event-card {
    @apply w-full;
  }

  /* 优化卡片内间距 */
  .event-card .p-2 {
    padding: 0.5rem;
  }

  .timeline-date-badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
}
