/* ============================================================
 * 智慧宫 - 动效 & UI 增强
 * 视图切换、微交互、骨架屏、加载态
 * ============================================================ */

/* ========== View 切换动画 ========== */
.view {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  will-change: opacity, transform;
}

.view.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* 深色模式下稍慢过渡 */
.dark-mode .view {
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== 卡片交错入场 (class on container) ========== */
.stagger-enter > * {
  opacity: 0;
  transform: translateY(16px);
  animation: staggerFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.stagger-enter > *:nth-child(1) { animation-delay: 0ms; }
.stagger-enter > *:nth-child(2) { animation-delay: 50ms; }
.stagger-enter > *:nth-child(3) { animation-delay: 100ms; }
.stagger-enter > *:nth-child(4) { animation-delay: 150ms; }
.stagger-enter > *:nth-child(5) { animation-delay: 200ms; }
.stagger-enter > *:nth-child(6) { animation-delay: 250ms; }
.stagger-enter > *:nth-child(7) { animation-delay: 300ms; }
.stagger-enter > *:nth-child(8) { animation-delay: 350ms; }
.stagger-enter > *:nth-child(9) { animation-delay: 400ms; }
.stagger-enter > *:nth-child(10) { animation-delay: 450ms; }

@keyframes staggerFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========== 侧边栏展开/收起动画 ========== */
.collapsible-sidebar {
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease;
}

.collapsible-sidebar .sidebar-item {
  transition: background 0.15s ease, color 0.15s ease, padding 0.25s ease;
}

.collapsible-sidebar.collapsed .sidebar-item span {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.collapsible-sidebar .section-header {
  transition: opacity 0.2s ease;
}

/* ========== 按钮微交互 ========== */
button, .btn, [role="button"] {
  transition: background 0.15s ease,
              color 0.15s ease,
              border-color 0.15s ease,
              box-shadow 0.15s ease,
              transform 0.1s ease;
}

button:active, .btn:active {
  transform: scale(0.97);
}

/* ========== 链接悬停效果 ========== */
a {
  transition: color 0.15s ease;
}

/* ========== 模态框动画 ========== */
.modal-overlay {
  animation: modalOverlayIn 0.2s ease;
}

.modal-content, .dialog {
  animation: modalSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========== Toast 通知滑入 ========== */
.toast {
  animation: toastSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.removing {
  animation: toastSlideOut 0.2s ease forwards;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastSlideOut {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* ========== 下拉菜单展开 ========== */
.dropdown-menu {
  animation: dropdownIn 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: top center;
}

@keyframes dropdownIn {
  from {
    opacity: 0;
    transform: scaleY(0.9) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: scaleY(1) translateY(0);
  }
}

/* ========== 骨架屏闪烁 ========== */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg, #e8eaed 25%, #f0f2f5 50%, #e8eaed 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.dark-mode .skeleton {
  background: linear-gradient(90deg, #1a1d2e 25%, #252940 50%, #1a1d2e 75%);
  background-size: 200% 100%;
}

/* ========== Spin loader ========== */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: #6c8cff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ========== 淡入脉冲 ========== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ========== 标签颜色交替 ========== */
@keyframes colorCycle {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ========== Tab 下划线过渡 ========== */
.tab::after {
  content: '';
  display: block;
  width: 0;
  height: 2px;
  background: var(--dm-accent, #6c8cff);
  transition: width 0.2s ease;
  margin-top: 2px;
}

.tab.active::after {
  width: 100%;
}

/* ========== 输入框 focus 环 ========== */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #6c8cff;
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(108, 140, 255, 0.15);
  transition: box-shadow 0.15s ease;
}

/* ========== 卡片悬浮提升 ========== */
.card-hover-lift {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

.dark-mode .card-hover-lift:hover {
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ========== 路由切换导航高亮动画 ========== */
.nav-links a,
.nav-links .nav-btn,
.nav-item {
  transition: color 0.15s ease,
              background 0.15s ease,
              border-color 0.15s ease;
}

/* ========== Logo Hover 旋转 ========== */
.nav-logo:hover {
  animation: logoWiggle 0.5s ease;
}

@keyframes logoWiggle {
  0%, 100% { transform: rotate(0); }
  25%      { transform: rotate(-5deg); }
  75%      { transform: rotate(5deg); }
}

/* ========== 减少动画 (无障碍) ========== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
