/**
 * UX增强样式 - 提升操作跟手感和交互反馈
 * 解决"快的时候很快，缺乏操作跟手"的问题
 */

/* ============================================
   1. 按钮点击即时反馈（关键：:active状态）
   ============================================ */

/* 所有按钮的即时点击反馈 */
.btn {
    position: relative;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* 点击时的即时反馈（关键！） */
.btn:active {
    transform: scale(0.97);
    transition: transform 0.05s ease;
}

/* 悬停效果（保持） */
.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* 禁用状态更明显 */
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* 加载状态按钮 */
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   2. 表单控件交互反馈
   ============================================ */

/* 输入框聚焦反馈 */
.form-control:focus,
.form-select:focus {
    transform: scale(1.01);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* 输入框输入时的微反馈 */
.form-control:not(:disabled):active {
    transform: scale(1.005);
}

/* ============================================
   3. 表格行交互反馈
   ============================================ */

.table tbody tr {
    transition: background-color 0.15s ease;
    /* 移除transform动画，避免点击时抖动 */
    transform: none !important;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
    transform: none !important;
}

.table tbody tr:active {
    background-color: #e9ecef;
    transform: none !important;
}

/* ============================================
   4. 卡片和容器交互反馈
   ============================================ */

.card,
.panel,
.content-section {
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.card:hover,
.panel:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* 可点击的卡片 */
.card.clickable {
    cursor: pointer;
}

.card.clickable:active {
    transform: scale(0.98);
}

/* ============================================
   5. 模态框和弹窗优化
   ============================================ */

.modal {
    transition: opacity 0.2s ease;
}

.modal.show {
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-backdrop {
    transition: opacity 0.2s ease;
}

/* ============================================
   6. 加载状态统一化
   ============================================ */

/* 全局加载遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.2s ease;
}

.loading-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 加载动画 */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(37, 99, 235, 0.1);
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* 内联加载指示器 */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #fff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
}

/* ============================================
   7. Toast通知优化（操作反馈）
   ============================================ */

.toast {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease;
    animation: toastSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   8. 链接和可点击元素
   ============================================ */

a:not(.btn) {
    transition: color 0.15s ease, transform 0.1s ease;
}

a:not(.btn):active {
    transform: scale(0.98);
}

/* ============================================
   9. 复选框和单选框反馈
   ============================================ */

.form-check-input {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.form-check-input:active {
    transform: scale(0.9);
}

.form-check-input:checked {
    transform: scale(1.05);
}

/* ============================================
   10. 标签页切换优化
   ============================================ */

.nav-tabs .nav-link {
    transition: all 0.2s ease;
}

.nav-tabs .nav-link:active {
    transform: scale(0.95);
}

/* ============================================
   11. 下拉菜单优化
   ============================================ */

.dropdown-menu {
    animation: dropdownFadeIn 0.2s ease;
}

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

.dropdown-item {
    transition: background-color 0.15s ease, transform 0.1s ease;
}

.dropdown-item:active {
    transform: scale(0.98);
    background-color: #e9ecef;
}

/* ============================================
   12. 分页按钮优化
   ============================================ */

.page-link {
    transition: all 0.15s ease;
}

.page-link:active {
    transform: scale(0.95);
}

/* ============================================
   13. 表格操作按钮优化
   ============================================ */

.table .btn-sm {
    transition: all 0.15s ease;
}

.table .btn-sm:active {
    transform: scale(0.9);
}

/* ============================================
   14. 平滑滚动优化
   ============================================ */

html {
    scroll-behavior: smooth;
}

/* ============================================
   15. 禁用不必要的动画（性能优化）
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   16. 焦点可见性优化（无障碍）
   ============================================ */

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* ============================================
   17. 操作成功反馈（微动画）
   ============================================ */

.success-feedback {
    animation: successPulse 0.4s ease;
}

@keyframes successPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.2);
    }
    100% {
        transform: scale(1);
    }
}

/* ============================================
   18. 数据更新时的平滑过渡
   ============================================ */

.table tbody tr {
    animation: rowFadeIn 0.3s ease;
}

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

/* ============================================
   19. 输入验证反馈
   ============================================ */

.form-control.is-invalid {
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.form-control.is-valid {
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

/* ============================================
   20. 工具提示优化
   ============================================ */

.tooltip {
    animation: tooltipFadeIn 0.2s ease;
}

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

/* ============================================
   21. 编辑/修改模式光晕效果（全局）
   ============================================ */

/* 编辑模式光晕效果 - 适用于表单、卡片、模态框等容器 */
.editing-glow {
    position: relative;
    animation: editingGlowPulse 2s ease-in-out infinite;
}

/* 光晕动画 */
@keyframes editingGlowPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4),
                    0 0 0 0 rgba(37, 99, 235, 0.3),
                    0 0 0 0 rgba(37, 99, 235, 0.2);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.4),
                    0 0 0 8px rgba(37, 99, 235, 0.3),
                    0 0 0 12px rgba(37, 99, 235, 0.2);
    }
}

/* 编辑模式光晕效果 - 静态版本（不闪烁） */
.editing-glow-static {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.5),
                0 0 0 4px rgba(37, 99, 235, 0.3),
                0 0 0 6px rgba(37, 99, 235, 0.1);
    transition: box-shadow 0.3s ease;
}

/* 编辑模式光晕效果 - 强光版本 */
.editing-glow-strong {
    animation: editingGlowStrong 1.5s ease-in-out infinite;
}

@keyframes editingGlowStrong {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6),
                    0 0 0 0 rgba(37, 99, 235, 0.4),
                    0 0 0 0 rgba(37, 99, 235, 0.2);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.6),
                    0 0 0 12px rgba(37, 99, 235, 0.4),
                    0 0 0 18px rgba(37, 99, 235, 0.2);
    }
}

/* 编辑模式光晕效果 - 成功状态（绿色） */
.editing-glow-success {
    animation: editingGlowSuccess 2s ease-in-out infinite;
}

@keyframes editingGlowSuccess {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4),
                    0 0 0 0 rgba(5, 150, 105, 0.3),
                    0 0 0 0 rgba(5, 150, 105, 0.2);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.4),
                    0 0 0 8px rgba(5, 150, 105, 0.3),
                    0 0 0 12px rgba(5, 150, 105, 0.2);
    }
}

/* 编辑模式光晕效果 - 警告状态（橙色） */
.editing-glow-warning {
    animation: editingGlowWarning 2s ease-in-out infinite;
}

@keyframes editingGlowWarning {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4),
                    0 0 0 0 rgba(245, 158, 11, 0.3),
                    0 0 0 0 rgba(245, 158, 11, 0.2);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.4),
                    0 0 0 8px rgba(245, 158, 11, 0.3),
                    0 0 0 12px rgba(245, 158, 11, 0.2);
    }
}

/* 编辑模式光晕效果 - 危险状态（红色） */
.editing-glow-danger {
    animation: editingGlowDanger 2s ease-in-out infinite;
}

@keyframes editingGlowDanger {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4),
                    0 0 0 0 rgba(239, 68, 68, 0.3),
                    0 0 0 0 rgba(239, 68, 68, 0.2);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.4),
                    0 0 0 8px rgba(239, 68, 68, 0.3),
                    0 0 0 12px rgba(239, 68, 68, 0.2);
    }
}

/* 编辑模式光晕效果 - 禁用动画（性能优化） */
@media (prefers-reduced-motion: reduce) {
    .editing-glow,
    .editing-glow-strong,
    .editing-glow-success,
    .editing-glow-warning,
    .editing-glow-danger {
        animation: none;
        box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.5);
    }
}

