/**
 * UX Enhancements v1.0
 * 
 * Comprehensive micro-interaction polish, better focus states,
 * smoother transitions, improved form UX, and visual refinements.
 */

/* ==================== Global Transition Smoothness ==================== */

/* Ensure all interactive elements have smooth transitions */
button,
a,
input,
textarea,
select,
[role="button"],
[tabindex] {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease,
        box-shadow 0.2s ease, opacity 0.2s ease, transform 0.15s ease;
}

/* ==================== Better Focus States ==================== */

/* Modern focus ring for all focusable elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--luca-primary, #3b82f6);
    outline-offset: 2px;
    border-radius: inherit;
}

/* Remove default outline for mouse users */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
    outline: none;
}

/* ==================== Enhanced Input Fields ==================== */

/* Smooth focus glow on inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
textarea,
select {
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.2s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
textarea:focus,
select:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Dark mode input focus */
.dark input:focus,
[data-dark-mode="true"] input:focus,
.dark textarea:focus,
.dark select:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

/* Placeholder animation */
input::placeholder,
textarea::placeholder {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

input:focus::placeholder,
textarea:focus::placeholder {
    opacity: 0.5;
    transform: translateX(4px);
}

/* ==================== Better Button Interactions ==================== */

/* Subtle press feedback for all buttons */
button:not(:disabled):active,
[role="button"]:not(:disabled):active {
    transform: scale(0.97);
}

/* Disabled button styling */
button:disabled,
[role="button"][aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.3);
}

/* Primary action button glow on hover */
button[class*="bg-blue-"] {
    transition: all 0.2s ease, box-shadow 0.3s ease;
}

button[class*="bg-blue-"]:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.35);
}

/* Amber/warning button glow */
button[class*="bg-amber-"]:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

/* Success button glow */
button[class*="bg-emerald-"]:hover:not(:disabled),
button[class*="bg-green-"]:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

/* Danger button glow */
button[class*="bg-red-"]:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

/* ==================== Card & Panel Improvements ==================== */

/* Smooth border highlight on hover for bordered cards */
div[class*="border"][class*="rounded"] {
    transition: border-color 0.2s ease, box-shadow 0.25s ease, transform 0.2s ease;
}

/* ==================== Modal Enhancements ==================== */

/* Smoother modal backdrop */
div[class*="fixed"][class*="inset-0"][class*="bg-black"] {
    transition: opacity 0.25s ease;
}

/* Modal content spring animation */
@keyframes modal-spring-in {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }
    60% {
        transform: translateY(-3px) scale(1.005);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-spring {
    animation: modal-spring-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==================== Chat-Specific Enhancements ==================== */

/* Smoother message action buttons - fade in on hover */
.chat-actions {
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Show actions on message hover */
.chat-message-wrapper:hover .chat-actions,
.chat-actions:focus-within {
    opacity: 1;
    transform: translateY(0);
}

/* Always show actions on mobile (no hover) */
@media (hover: none) {
    .chat-actions {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Better code block styling in chat */
.prose pre {
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: border-color 0.2s ease;
}

.prose pre:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

/* Inline code better visibility */
.prose code:not(pre code) {
    padding: 0.15em 0.4em;
    border-radius: 0.3em;
    font-size: 0.875em;
    font-weight: 500;
}

/* ==================== Sidebar Enhancements ==================== */

/* Better session item interaction */
.session-item {
    position: relative;
    overflow: hidden;
}

.session-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--luca-primary, #3b82f6);
    transform: scaleY(0);
    transition: transform 0.2s ease;
    border-radius: 0 2px 2px 0;
}

.session-item:hover::before,
.session-item[data-active="true"]::before {
    transform: scaleY(1);
}

/* ==================== Header Enhancements ==================== */

/* Profile avatar ring animation */
@keyframes avatar-ring-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0);
    }
}

.avatar-online {
    animation: avatar-ring-pulse 3s ease-in-out infinite;
}

/* ==================== Toast/Notification Improvements ==================== */

/* Better toast entrance with spring */
@keyframes toast-spring-in {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    60% {
        transform: translateY(3px) scale(1.01);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toast-enter {
    0% {
        opacity: 0;
        transform: translateX(24px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.toast-spring {
    animation: toast-spring-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==================== Loading State Improvements ==================== */

/* Better skeleton shimmer */
@keyframes enhanced-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton-enhanced {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04) 0%,
        rgba(255, 255, 255, 0.08) 20%,
        rgba(255, 255, 255, 0.12) 40%,
        rgba(255, 255, 255, 0.08) 60%,
        rgba(255, 255, 255, 0.04) 100%
    );
    background-size: 200% 100%;
    animation: enhanced-shimmer 1.8s ease-in-out infinite;
    border-radius: 8px;
}

/* Spinner with better visual */
@keyframes spin-smooth {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-smooth {
    animation: spin-smooth 0.8s linear infinite;
    border: 2px solid transparent;
    border-top-color: var(--luca-primary, #3b82f6);
    border-right-color: var(--luca-primary, #3b82f6);
    border-radius: 50%;
}

/* ==================== Selection & Text Improvements ==================== */

/* Better text selection colors */
::selection {
    background: rgba(59, 130, 246, 0.3);
    color: inherit;
}

.dark ::selection {
    background: rgba(96, 165, 250, 0.35);
}

/* ==================== Smooth Page/Section Transitions ==================== */

/* Fade transition for tab content */
@keyframes tab-fade-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tab-content-enter {
    animation: tab-fade-in 0.25s ease-out;
}

/* ==================== Tooltip Improvements ==================== */

/* Better tooltip appearance */
[title] {
    position: relative;
}

/* ==================== Badge & Chip Polish ==================== */

/* Subtle pulse for notification badges */
@keyframes badge-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

.badge-pulse {
    animation: badge-pulse 2s ease-in-out infinite;
}

/* ==================== Responsive Touch Improvements ==================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets on mobile */
    button,
    [role="button"],
    a {
        min-height: 44px;
        min-width: 44px;
    }

    /* Exception for inline/icon buttons that are already in a larger container */
    button[class*="p-1"],
    button[class*="p-0"],
    .inline-btn {
        min-height: unset;
        min-width: unset;
    }

    /* Better active states for touch */
    button:active:not(:disabled),
    [role="button"]:active:not(:disabled) {
        transform: scale(0.95);
        opacity: 0.85;
    }
}

/* ==================== Smooth Number Transitions ==================== */

/* For token counts, XP, etc. */
.number-transition {
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: inline-block;
}

/* ==================== Empty State Polish ==================== */

@keyframes empty-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

.empty-state-icon {
    animation: empty-float 3s ease-in-out infinite;
    opacity: 0.6;
}

/* ==================== Smoother Modal Backdrops ==================== */

/* Ensure modal backdrops transition smoothly */
.modal-backdrop-enter {
    animation: backdrop-fade-in 0.25s ease-out;
}

@keyframes backdrop-fade-in {
    from { opacity: 0; backdrop-filter: blur(0px); }
    to { opacity: 1; backdrop-filter: blur(8px); }
}

/* Modal content with spring entrance */
.modal-content-enter {
    animation: modal-content-spring 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-content-spring {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==================== Smooth View Transitions ==================== */

/* Page-level content fade for route/view changes */
.view-transition-enter {
    animation: view-enter 0.3s ease-out;
}

@keyframes view-enter {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== Better Hover States ==================== */

/* Subtle lift effect for interactive cards */
.interactive-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.interactive-card:hover {
    transform: translateY(-1px);
}

.interactive-card:active {
    transform: translateY(0);
}

/* ==================== Improved Skeleton Loading ==================== */

/* Refined skeleton pulse for content placeholders */
.skeleton-pulse {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.03) 0%,
        rgba(255, 255, 255, 0.07) 50%,
        rgba(255, 255, 255, 0.03) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-wave 1.5s ease-in-out infinite;
    border-radius: 6px;
}

@keyframes skeleton-wave {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==================== Smooth Sidebar Transitions ==================== */

/* Sidebar slide with GPU acceleration */
.sidebar-transition {
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.2s ease;
    will-change: transform;
}

/* ==================== Better Scroll Behavior ==================== */

/* Smooth scroll for chat and content areas */
.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Overscroll glow prevention */
.no-overscroll {
    overscroll-behavior: contain;
}

/* ==================== Reduced Motion ==================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.1ms !important;
    }

    .chat-actions {
        opacity: 1;
        transform: none;
    }
}
