/**
 * Animated Gradient Borders - PharmAssist
 * Reusable CSS classes for animated gradient borders
 * 
 * Apply to: focused inputs, active cards, selected menu items, modal dialogs
 */

/* Gradient border animation keyframes */
@keyframes gradientRotate {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

@keyframes gradientSpin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Base animated gradient border */
.animated-border {
    position: relative;
    background: var(--surface, #ffffff);
    border-radius: 8px;
}

.animated-border::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, #667eea, #764ba2, #667eea, #764ba2);
    background-size: 400% 400%;
    border-radius: inherit;
    z-index: -1;
    animation: gradientRotate 8s ease infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.animated-border:hover::before,
.animated-border:focus-within::before,
.animated-border.active::before {
    opacity: 1;
}

/* Variant: Spinning border */
.animated-border-spin {
    position: relative;
    background: var(--surface, #ffffff);
    border-radius: 8px;
}

.animated-border-spin::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: conic-gradient(from 0deg, #667eea, #764ba2, #667eea);
    border-radius: inherit;
    z-index: -1;
    animation: gradientSpin 3s linear infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.animated-border-spin:hover::before,
.animated-border-spin:focus-within::before,
.animated-border-spin.active::before {
    opacity: 1;
}

/* Input field focus animation */
input.animated-input,
textarea.animated-input,
select.animated-input {
    position: relative;
    border: 2px solid var(--border, #dadce0);
    border-radius: 6px;
    transition: all 0.3s ease;
    background: var(--surface, #ffffff);
}

input.animated-input:focus,
textarea.animated-input:focus,
select.animated-input:focus {
    outline: none;
    border-color: transparent;
    box-shadow: 0 0 0 2px transparent;
    background: linear-gradient(var(--surface, #ffffff), var(--surface, #ffffff)) padding-box,
                linear-gradient(135deg, #667eea, #764ba2) border-box;
    border: 2px solid transparent;
    animation: gradientRotate 8s ease infinite;
    background-size: 400% 400%;
}

/* Active card/widget animation */
.card-animated,
.widget-animated {
    position: relative;
    background: var(--surface, #ffffff);
    border-radius: 12px;
    padding: 2px;
    transition: transform 0.2s ease;
}

.card-animated::before,
.widget-animated::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #667eea, #764ba2, #ff6b6b, #48c774);
    background-size: 400% 400%;
    border-radius: inherit;
    z-index: -1;
    animation: gradientRotate 8s ease infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.card-animated:hover::before,
.card-animated.active::before,
.widget-animated:hover::before,
.widget-animated.active::before {
    opacity: 1;
}

.card-animated:hover,
.widget-animated:hover {
    transform: translateY(-2px);
}

/* Menu item selection animation */
.menu-item-animated {
    position: relative;
    padding: 12px 20px;
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.menu-item-animated::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, #667eea, #764ba2);
    background-size: 100% 200%;
    border-radius: 4px 0 0 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
    animation: gradientRotate 4s ease infinite;
}

.menu-item-animated:hover::before,
.menu-item-animated.selected::before,
.menu-item-animated.active::before {
    opacity: 1;
}

.menu-item-animated.selected,
.menu-item-animated.active {
    background: rgba(102, 126, 234, 0.1);
}

/* Modal dialog animation */
.modal-animated {
    position: relative;
    background: var(--surface, #ffffff);
    border-radius: 16px;
    padding: 3px;
}

.modal-animated::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient, linear-gradient(135deg, #00d4ff, #7c3aed));
    background-size: 400% 400%;
    border-radius: inherit;
    z-index: -1;
    animation: gradientRotate 6s ease infinite;
    opacity: 1;
}

.modal-animated-content {
    background: var(--bg-card, #141414);
    border-radius: 14px;
    padding: 24px;
    position: relative;
    z-index: 1;
}

/* Button with animated border */
.btn-animated {
    position: relative;
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    overflow: hidden;
    transition: all 0.3s ease;
}

.btn-animated::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: linear-gradient(135deg, #00d4ff, #7c3aed, #00d4ff);
    background-size: 400% 400%;
    border-radius: inherit;
    z-index: -1;
    animation: gradientRotate 4s ease infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-animated:hover::before {
    opacity: 1;
}

.btn-animated:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 212, 255, 0.3);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .animated-border,
    .animated-border-spin,
    .card-animated,
    .widget-animated,
    .modal-animated-content {
        background: var(--surface-dark, #1e293b);
    }
    
    input.animated-input:focus,
    textarea.animated-input:focus,
    select.animated-input:focus {
        background: linear-gradient(var(--surface-dark, #1e293b), var(--surface-dark, #1e293b)) padding-box,
                    linear-gradient(135deg, #667eea, #764ba2) border-box;
    }
}

body.dark-mode .animated-border,
body.dark-mode .animated-border-spin,
body.dark-mode .card-animated,
body.dark-mode .widget-animated,
body.dark-mode .modal-animated-content {
    background: var(--surface-dark, #1e293b);
}

body.dark-mode input.animated-input:focus,
body.dark-mode textarea.animated-input:focus,
body.dark-mode select.animated-input:focus {
    background: linear-gradient(var(--surface-dark, #1e293b), var(--surface-dark, #1e293b)) padding-box,
                linear-gradient(135deg, #667eea, #764ba2) border-box;
}

/* Accessibility: Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .animated-border::before,
    .animated-border-spin::before,
    .card-animated::before,
    .widget-animated::before,
    .menu-item-animated::before,
    .modal-animated::before,
    .btn-animated::before {
        animation: none;
    }
    
    input.animated-input:focus,
    textarea.animated-input:focus,
    select.animated-input:focus {
        animation: none;
    }
}
