/**
 * UI 增强样式
 * 提升用户体验的视觉效果和交互反馈
 */

/* ==================== 加载动画 ==================== */

/* 旋转加载器 */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(245, 158, 11, 0.2);
    border-radius: 50%;
    border-top-color: var(--color-primary);
    animation: spin 0.8s linear infinite;
}

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

/* 脉冲加载器 */
.loading-pulse {
    display: inline-block;
    width: 40px;
    height: 40px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* 骨架屏 */
.skeleton {
    background: linear-gradient(90deg, #F3E8D2 25%, #F8F0E8 50%, #F3E8D2 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==================== 按钮增强 ==================== */

.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* 按钮波纹效果 */
.btn-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: ripple 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* 按钮悬停提升 */
.btn-primary:hover,
.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-primary:active,
.btn-secondary:active {
    transform: translateY(0);
}

/* ==================== 卡片增强 ==================== */

.card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* 卡片高亮 */
.card.highlight {
    border: 2px solid var(--color-primary);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.2);
}

/* 卡片进入动画 */
.card-enter {
    animation: cardEnter 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ==================== 列表项增强 ==================== */

.list-item {
    transition: all 0.2s ease;
}

.list-item:hover {
    background: var(--bg-grouped);
}

.list-item:active {
    background: var(--border-light);
}

/* 列表项滑动删除 */
.list-item.swipe-delete {
    position: relative;
    overflow: hidden;
}

.list-item.delete-action {
    transform: translateX(-80px);
    transition: transform 0.3s ease;
}

.list-item .delete-btn {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    background: #EF4444;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* ==================== 输入框增强 ==================== */

.input-field {
    transition: all 0.3s ease;
}

.input-field:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
    background: white;
}

.input-field.error {
    border-color: #EF4444;
    animation: shake 0.4s ease;
}

.input-field.success {
    border-color: #10B981;
}

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

/* 输入框标签浮动 */
.input-group {
    position: relative;
}

.input-group label {
    position: absolute;
    left: 12px;
    top: 12px;
    color: var(--text-tertiary);
    transition: all 0.2s ease;
    pointer-events: none;
    background: transparent;
    padding: 0 4px;
}

.input-group input:focus ~ label,
.input-group input:not(:placeholder-shown) ~ label {
    top: -8px;
    left: 8px;
    font-size: 12px;
    color: var(--color-primary);
    background: white;
}

/* ==================== 提示框增强 ==================== */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #332A22;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: #10B981;
}

.toast.error {
    background: #EF4444;
}

.toast.warning {
    background: #F59E0B;
}

/* ==================== 徽章增强 ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.badge-pulse {
    animation: badgePulse 2s infinite;
}

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

/* ==================== 进度条增强 ==================== */

.progress-bar {
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-ai));
    border-radius: 2px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: progressShine 2s infinite;
}

@keyframes progressShine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ==================== 空状态增强 ==================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ==================== 标签页增强 ==================== */

.tab-item {
    position: relative;
    transition: all 0.3s ease;
}

.tab-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 3px;
    background: var(--color-primary);
    transform: translateX(-50%);
    transition: width 0.3s ease;
}

.tab-item.active::after {
    width: 24px;
}

/* ==================== 下拉刷新 ==================== */

.pull-to-refresh {
    overflow: hidden;
}

.pull-indicator {
    height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: height 0.3s ease;
}

.pull-indicator.show {
    height: 60px;
}

.pull-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ==================== 模态框增强 ==================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.show .modal-content {
    transform: scale(1) translateY(0);
}

/* ==================== 工具提示 ==================== */

.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: #332A22;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 100;
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

/* ==================== 滚动条美化 ==================== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-ai);
}

/* ==================== 页面过渡动画 ==================== */

.page-transition {
    animation: pageEnter 0.3s ease;
}

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

/* ==================== 数字滚动动画 ==================== */

.count-up {
    display: inline-block;
}

.count-up-animate {
    animation: countUp 0.5s ease;
}

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

/* ==================== 图标动画 ==================== */

.icon-bounce {
    display: inline-block;
    animation: iconBounce 0.6s ease;
}

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

.icon-rotate {
    display: inline-block;
    animation: iconRotate 0.6s ease;
}

@keyframes iconRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== 暗色模式支持 ==================== */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-page: #1A1A1A;
        --bg-card: #2A2A2A;
        --bg-grouped: #333333;
        --text-primary: #FFFFFF;
        --text-secondary: #CCCCCC;
        --text-tertiary: #999999;
        --border-light: #444444;
        --border-base: #555555;
    }
    
    .card:hover {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    }
}

/* ==================== 减少动画 ==================== */

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