/*
 * 交互效果增强样式
 * 包含：边框动画、悬停效果、焦点效果、过渡动画
 */

/* ========================================
   0. 提示信息主题色
   ======================================== */

/* 淡主题色提示信息（替代默认蓝色） */
.alert-info {
  background: var(--theme-primary-faint) !important;
  border-color: var(--theme-primary-soft) !important;
  color: var(--theme-primary-dark) !important;
}

.alert-info .alert-link {
  color: var(--theme-primary-dark) !important;
  font-weight: 600;
}

.alert-info i,
.alert-info svg {
  color: var(--theme-primary) !important;
}

/* ========================================
   1. 边框交互效果
   ======================================== */

/* 输入框焦点发光效果 */
.form-control:focus,
.form-select:focus {
  box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.15);
}

/* 卡片悬停效果 - 顶部线条，从中间向两边展开 */
.card {
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--theme-primary);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
}

.card:hover::before {
  transform: scaleX(1);
}

/* 主题色卡片已有渐变头部，隐藏顶部线条避免重叠 */
.card-theme-primary::before,
.card-theme-secondary::before {
  display: none;
}

/* 表格行悬停边框效果 */
.table-hover tbody tr {
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 3px solid transparent;
}

.table-hover tbody tr:hover {
  border-left-color: var(--theme-primary);
  background-color: rgba(var(--theme-primary-rgb), 0.06);
  transform: translateX(3px);
}

/* ========================================
   2. 按钮交互效果
   ======================================== */

/* 按钮基础交互 */
.btn {
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 按钮点击缩放效果 */
.btn:active {
  transform: scale(0.96);
}

/* 按钮悬停上浮效果 */
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(var(--theme-primary-rgb), 0.25);
  filter: brightness(1.05);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.96);
  filter: brightness(0.95);
}

/* 按钮光晕效果 */
.btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s ease, height 0.6s ease;
}

.btn:active::after {
  width: 300px;
  height: 300px;
  opacity: 0;
}

/* 主按钮（primary）高级效果 */
.btn-primary {
  background: var(--theme-btn-gradient);
  border: none;
  color: white;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(var(--theme-primary-rgb), 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--theme-btn-hover-gradient);
  box-shadow: 0 6px 20px rgba(var(--theme-primary-rgb), 0.35);
}

/* 成功按钮（success）高级效果 */
.btn-success {
  background: linear-gradient(135deg, var(--theme-success) 0%, var(--theme-success-dark) 100%);
  border: none;
  color: white;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(var(--theme-success-rgb, 25, 135, 84), 0.2);
}

.btn-success:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--theme-success-dark) 0%, var(--theme-success) 100%);
  box-shadow: 0 6px 20px rgba(var(--theme-success-rgb, 25, 135, 84), 0.35);
}

/* 危险按钮（danger）高级效果 */
.btn-danger {
  background: linear-gradient(135deg, var(--theme-danger) 0%, var(--theme-danger-dark) 100%);
  border: none;
  color: white;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(var(--theme-danger-rgb, 220, 53, 69), 0.2);
}

.btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--theme-danger-dark) 0%, var(--theme-danger) 100%);
  box-shadow: 0 6px 20px rgba(var(--theme-danger-rgb, 220, 53, 69), 0.35);
}

/* 信息按钮（info）高级效果 */
.btn-info {
  background: linear-gradient(135deg, var(--theme-info) 0%, var(--theme-info-dark) 100%) !important;
  border: none !important;
  color: white !important;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(var(--theme-info-rgb, 13, 110, 253), 0.2) !important;
}

.btn-info:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--theme-info-dark) 0%, var(--theme-info) 100%) !important;
  box-shadow: 0 6px 20px rgba(var(--theme-info-rgb, 13, 110, 253), 0.35) !important;
}

/* 警告按钮（warning）高级效果
   文字用深色：橙底（#F59E0B ~ #D97706）配白字对比度仅 2.2:1，不满足 WCAG AA；
   改深色后达 4.9:1 ~ 7.1:1。灰色/黑白主题的 warning 为深色底，
   已在 theme.css 单独恢复为白字。 */
.btn-warning {
  background: linear-gradient(135deg, var(--theme-warning) 0%, var(--theme-warning-dark) 100%) !important;
  border: none !important;
  color: #212529 !important;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(var(--theme-warning-rgb, 255, 193, 7), 0.2) !important;
}

.btn-warning:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--theme-warning-dark) 0%, var(--theme-warning) 100%) !important;
  box-shadow: 0 6px 20px rgba(var(--theme-warning-rgb, 255, 193, 7), 0.35) !important;
}

/* 轮廓按钮（outline）高级效果 */
.btn-outline-primary {
  border: 2px solid var(--theme-primary);
  color: var(--theme-primary);
  background: transparent;
  transition: all 0.3s ease;
}

.btn-outline-primary:hover:not(:disabled) {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
  color: white;
  box-shadow: 0 4px 12px rgba(var(--theme-primary-rgb), 0.3);
}

/* btn-check 选中态 + active/pressed 态：统一使用主题色 */
.btn-check:checked + .btn-outline-primary,
.btn-outline-primary.active,
.btn-outline-primary:active {
  background: var(--theme-primary) !important;
  border-color: var(--theme-primary) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(var(--theme-primary-rgb), 0.35);
}

.btn-outline-secondary {
  border: 2px solid var(--theme-border-dark);
  color: var(--theme-dark);
  background: transparent;
  transition: all 0.3s ease;
}

.btn-outline-secondary:hover:not(:disabled) {
  background: var(--theme-border-dark);
  border-color: var(--theme-border-dark);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-check:checked + .btn-outline-secondary,
.btn-outline-secondary.active,
.btn-outline-secondary:active {
  background: var(--theme-border-dark) !important;
  border-color: var(--theme-border-dark) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 小按钮优化 */
.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.btn-xs {
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
}

/* 按钮加载状态 */
.btn.loading {
  pointer-events: none;
  opacity: 0.7;
}

.btn.loading::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* 按钮脉冲动画（用于重要操作） */
.btn-pulse {
  animation: btn-pulse-animation 2s ease-in-out infinite;
}

@keyframes btn-pulse-animation {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(var(--theme-primary-rgb), 0.4);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(var(--theme-primary-rgb), 0);
  }
}

/* 按钮发光效果 */
.btn-glow {
  position: relative;
}

.btn-glow::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: var(--theme-btn-gradient);
  border-radius: inherit;
  z-index: -1;
  filter: blur(8px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.btn-glow:hover::before {
  opacity: 0.6;
}

/* 按钮边框动画（从左到右） */
.btn-border-slide {
  position: relative;
  overflow: hidden;
}

.btn-border-slide::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: var(--theme-btn-gradient);
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-border-slide:hover::before {
  left: 0;
}

/* ========================================
   3. 导航交互效果
   ======================================== */

/* 侧边栏导航项激活指示器 */
.sidebar-nav .nav-item.active {
  position: relative;
  background: var(--theme-border-dark) !important;
  color: var(--theme-dark, #1e293b) !important;
}

.sidebar-nav .nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 70%;
  background: var(--theme-primary);
  border-radius: 0 3px 3px 0;
}

/* 顶部导航下划线效果 */
.nav-tabs .nav-link {
  position: relative;
  border: none;
  color: var(--theme-gray);
  transition: color 0.2s ease;
}

.nav-tabs .nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--theme-primary);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(-50%);
}

.nav-tabs .nav-link:hover {
  color: var(--theme-primary);
}

.nav-tabs .nav-link.active {
  color: var(--theme-primary);
  font-weight: 600;
}

.nav-tabs .nav-link.active::after {
  width: 100%;
}

/* 导航药丸（nav-pills）- 主题色 */
.nav-pills .nav-link {
  color: var(--theme-dark);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid transparent;
  font-weight: 500;
}

.nav-pills .nav-link:hover {
  color: var(--theme-primary);
  background: var(--theme-panel-bg);
}

.nav-pills .nav-link.active {
  background: var(--theme-btn-gradient);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(var(--theme-primary-rgb), 0.25);
}

.nav-pills .nav-link.active:hover {
  background: var(--theme-btn-hover-gradient);
  box-shadow: 0 4px 12px rgba(var(--theme-primary-rgb), 0.35);
}

/* ========================================
   4. 列表项交互效果
   ======================================== */

/* 列表项悬停滑动效果 */
.list-group-item {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 3px solid transparent;
}

.list-group-item:hover {
  transform: translateX(4px);
  border-left-color: var(--theme-primary);
  background-color: rgba(var(--theme-primary-rgb), 0.05);
}

/* ========================================
   5. 模态框交互效果
   ======================================== */

/* 模态框打开动画 */
.modal.fade .modal-dialog {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              opacity 0.3s ease;
  transform: scale(0.9);
}

.modal.show .modal-dialog {
  transform: scale(1);
}

/* 模态框边框高亮 */
.modal-content {
  border: 2px solid var(--theme-border);
  transition: border-color 0.3s ease;
}

.modal.show .modal-content {
  border-color: var(--theme-primary);
  box-shadow: 0 0 0 4px rgba(var(--theme-primary-rgb), 0.1);
}

/* ========================================
   6. 徽章和标签交互效果
   ======================================== */

/* 徽章悬停放大 */
.badge {
  transition: all 0.2s ease;
}

.badge:hover {
  transform: scale(1.1);
}

/* ========================================
   7. 分割线动画效果
   ======================================== */

/* 分割线渐变效果 */
hr {
  height: 1px;
  background: linear-gradient(90deg, 
    transparent, 
    var(--theme-divider), 
    transparent);
  border: none;
  margin: 1.5rem 0;
}

/* ========================================
   8. 加载动画效果
   ======================================== */

/* 旋转加载动画 */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading-spinner {
  animation: spin 1s linear infinite;
}

/* 脉冲加载动画 */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.05);
  }
}

.loading-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ========================================
   9. 工具提示交互效果
   ======================================== */

/* 工具提示边框高亮 */
.tooltip-inner {
  border: 1px solid var(--theme-border-dark);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ========================================
   10. 进度条交互效果
   ======================================== */

/* 进度条动画 */
.progress-bar {
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, 
    transparent, 
    rgba(255, 255, 255, 0.3), 
    transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* ========================================
   11. 交互动画全局开关
   ======================================== */

/*
 * 当 html[data-animations="off"] 时，禁用所有过渡和动画效果。
 * 由 theme-switcher.js 根据 localStorage('user-animations') 自动设置。
 * 不影响 :focus 焦点样式（保留无障碍可用性）。
 */
html[data-animations="off"] *,
html[data-animations="off"] *::before,
html[data-animations="off"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* 保留 :focus 焦点环（无障碍必须） */
html[data-animations="off"] *:focus,
html[data-animations="off"] *:focus-visible {
  outline-style: solid !important;
  outline-width: 2px !important;
}

/* ========================================
   11.1 系统级 prefers-reduced-motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   12. 特殊交互效果
   ======================================== */

/* 拖拽时的边框效果 */
.dragging {
  border: 2px dashed var(--theme-primary) !important;
  opacity: 0.7;
  transform: rotate(2deg);
}

/* 选中状态的边框 */
.selected {
  border-color: var(--theme-primary) !important;
  box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.2);
}

/* 验证状态边框 */
.is-valid {
  border-color: var(--theme-success) !important;
}

.is-valid:focus {
  box-shadow: 0 0 0 3px rgba(var(--theme-success-rgb, 16, 185, 129), 0.25) !important;
}

.is-invalid {
  border-color: var(--theme-danger) !important;
}

.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(var(--theme-danger-rgb, 239, 68, 68), 0.25) !important;
}
