/* Phase 13: UI/UX Polish - Global Styles
 * Loading states, animations, and responsive improvements
 */

/* ==================== Loading States ==================== */

/* Skeleton Loading Placeholder */
.skeleton {
    background: linear-gradient(90deg, 
        rgba(255,255,255,0.1) 25%, 
        rgba(255,255,255,0.2) 50%, 
        rgba(255,255,255,0.1) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 70%;
}

.skeleton-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-card {
    padding: 1.5rem;
    border-radius: 8px;
    min-height: 120px;
}

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

/* Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: var(--accent-color, #00d4ff);
    animation: spin 1s ease-in-out infinite;
}

.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 48px; height: 48px; border-width: 4px; }

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

/* Button Loading State */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.8;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s ease-in-out infinite;
}

.btn-loading span {
    visibility: hidden;
}

/* Page Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-content .spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
}


/* ==================== Error States ==================== */

.error-state {
    text-align: center;
    padding: 3rem;
    color: rgba(255,255,255,0.7);
}

.error-state .error-icon {
    font-size: 3rem;
    color: #ff6b6b;
    margin-bottom: 1rem;
}

.error-state h3 {
    color: white;
    margin-bottom: 0.5rem;
}

.error-state p {
    margin-bottom: 1.5rem;
}

.error-state .btn-retry {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.2s;
}

.error-state .btn-retry:hover {
    transform: translateY(-2px);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: rgba(255,255,255,0.6);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    color: white;
    margin-bottom: 0.5rem;
}


/* ==================== Toast Notifications ==================== */

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    min-width: 280px;
    max-width: 400px;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: toast-in 0.3s ease-out;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.toast.toast-success { background: linear-gradient(135deg, #00b09b, #96c93d); }
.toast.toast-error { background: linear-gradient(135deg, #ff416c, #ff4b2b); }
.toast.toast-warning { background: linear-gradient(135deg, #f7971e, #ffd200); color: #1a1a2e; }
.toast.toast-info { background: linear-gradient(135deg, #667eea, #764ba2); }

.toast-icon { font-size: 1.25rem; }
.toast-message { flex: 1; }
.toast-close {
    background: none;
    border: none;
    color: inherit;
    opacity: 0.7;
    cursor: pointer;
    font-size: 1.25rem;
}
.toast-close:hover { opacity: 1; }

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

.toast.removing {
    animation: toast-out 0.3s ease-in forwards;
}

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


/* ==================== Micro-animations ==================== */

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

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

.slide-up {
    animation: slideUp 0.3s ease-out;
}

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

.scale-in {
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from { 
        opacity: 0; 
        transform: scale(0.9); 
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}

/* Hover lift effect */
.hover-lift {
    transition: transform 0.2s, box-shadow 0.2s;
}

.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

/* Pulse animation for notifications */
.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}


/* ==================== Responsive Improvements ==================== */

/* Mobile-first improvements */
@media (max-width: 768px) {
    /* Stack sidebar content */
    .sidebar {
        width: 100% !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto !important;
        height: auto !important;
        flex-direction: row;
        justify-content: space-around;
        padding: 0.5rem;
        z-index: 100;
    }
    
    .sidebar a {
        padding: 0.5rem;
        flex: 1;
        text-align: center;
        font-size: 0.75rem;
    }
    
    .sidebar a span { display: none; }
    .sidebar a i { font-size: 1.25rem; }
    
    /* Main content padding for bottom nav */
    .main-content {
        padding-bottom: 80px !important;
        margin-left: 0 !important;
    }
    
    /* Table responsiveness */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Card grid adjustments */
    .dashboard-grid,
    .card-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    /* Modal full-screen on mobile */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
        border-radius: 12px 12px 0 0;
        max-height: 90vh;
    }
    
    /* Form improvements */
    input, select, textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    /* Button full-width */
    .btn-mobile-full {
        width: 100%;
        justify-content: center;
    }
    
    /* Header adjustments */
    .dashboard-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start !important;
    }
    
    /* Stats cards */
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .sidebar {
        width: 80px !important;
    }
    
    .sidebar a span {
        display: none;
    }
    
    .main-content {
        margin-left: 80px !important;
    }
}

/* Large desktop */
@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }
    
    .dashboard-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}


/* ==================== Dark Mode Enhancements ==================== */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: rgba(255,255,255,0.05);
    --text-primary: #ffffff;
    --text-secondary: rgba(255,255,255,0.7);
    --accent-color: #00d4ff;
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-color: #00b09b;
    --warning-color: #ffd200;
    --error-color: #ff416c;
    --border-color: rgba(255,255,255,0.1);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --bg-card: rgba(255,255,255,0.1);
        --text-secondary: rgba(255,255,255,0.9);
        --border-color: rgba(255,255,255,0.3);
    }
}

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


/* ==================== Utility Classes ==================== */

.text-gradient {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.glass-effect {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.gap-4 { gap: 1.5rem; }

.m-auto { margin: auto; }
.mt-auto { margin-top: auto; }
.mb-0 { margin-bottom: 0; }
